//	$Id: nc_userValidation.js,v 1.2 2007/10/19 07:45:45 samiram Exp $

function checkAll(theForm,newreg,dealer)
{
	//Newreg value is Y then check password and login id validation value
	if(newreg  == "Y")
	{
		var msg=checkLogin(theForm.loginid.value);

		if(msg != 1)
		{
			document.getElementById('logid').className='highlight';
			document.getElementById('logidimg').className='hlightimage';
			alert(msg);
			theForm.loginid.focus();
			return false;
		}
		if(!checkPasswd(theForm.pass1.value))
		{
			document.getElementById('pass1').className='highlight';
			document.getElementById('pass1img').className='hlightimage';
			alert(msgPasswd);
			theForm.pass1.focus();
			return false;
		}
		else
		{
			if(theForm.pass1.value != theForm.pass2.value)
			{
				document.getElementById('pass2').className='highlight';
				document.getElementById('pass2img').className='hlightimage';
				alert(msgSamePasswd);
				theForm.pass2.focus();
				return false;
			}
		}
	}
	if(!checkName(theForm.fname.value) || !checkName(theForm.lname.value))
	{
		if(!checkName(theForm.fname.value))
		{
			document.getElementById('fname').className='highlight';
			document.getElementById('fnameimg').className='hlightimage';
			alert(msgFLnameBlank);
			theForm.fname.focus();
			return false;
		}
		else
		{
			document.getElementById('lname').className='highlight';
			document.getElementById('lnameimg').className='hlightimage';
			alert(msgFLnameBlank);
			theForm.lname.focus();
			return false;
		}
  	}
  	if(!checkAddContTime(theForm.address.value))
	{
		document.getElementById('address').className='highlight';
		document.getElementById('addressimg').className='hlightimage';
		alert(msgAddBlank);
		theForm.address.focus();
		return false;
  	}
  	if(!checkCity(theForm.city.value))
	{
		document.getElementById('city').className='highlight';
		document.getElementById('cityimg').className='hlightimage';
		alert(msgCityBlank);
		theForm.city.focus();
		return false;
  	}
  	if(theForm.id_domicile.value == '')
	{
		document.getElementById('domicile').className='highlight';
		document.getElementById('domicileimg').className='hlightimage';
		alert(msgDomicile);
		theForm.id_domicile.focus();
		return false;
	}
  	if(!(isblank(theForm.zip.value)))
	{
		if(!(checkZip(theForm.zip.value)))
		{
			document.getElementById('zipcode').className='highlight';
			document.getElementById('zipcodeimg').className='hlightimage';
			alert(msgZip);
			theForm.zip.focus();
			return false;
  		}
  		else if(theForm.id_domicile.value != 11)
  		{
  			if(theForm.zip.value.match(/^[0-9]{5,6}$/))
  			{
  				if(theForm.zip.value <= 0)
  				{
  					document.getElementById('zipcode').className='highlight';
					document.getElementById('zipcodeimg').className='hlightimage';
  					alert(msgCheckZip);
  					theForm.zip.focus();
  					return false;
  				}
  			}
  			else
  			{
  				document.getElementById('zipcode').className='highlight';
				document.getElementById('zipcodeimg').className='hlightimage';
  				alert(msgCheckZip);
  				theForm.zip.focus();
  				return false;
  			}
  		}
  	}
  	else
  	{
  		document.getElementById('zipcode').className='highlight';
		document.getElementById('zipcodeimg').className='hlightimage';
		alert(msgMandatoryFieldEmpty);
		theForm.zip.focus();
		return false;
	}
	//If dealer Y then check dealer validation of ADD/EDIT dealer.
	if(dealer == "Y")
	{
		if(isblank(theForm.company.value))
		{
			document.getElementById('company').className='highlight';
			document.getElementById('companyimg').className='hlightimage';
			alert(msgMandatoryFieldEmpty);
			theForm.company.focus();
	     	return false;
		}
    	if(theForm.url && !urlInvalid(theForm.url.value))
		{
			document.getElementById('url').className='highlight';
			document.getElementById('urlimg').className='hlightimage';
			alert(msgUrlFormat);
			theForm.url.focus();
			return false;
		}
		if(theForm.simple_url && !(theForm.simple_url.value.match(/^([a-zA-Z0-9-_~])*$/)))
		{
			document.getElementById('simple_url').className='highlight';
			document.getElementById('simple_urlimg').className='hlightimage';
			alert(msgSpecialChar);
			theForm.simple_url.focus();
			return false;
		}
		if(newreg == "Y" && !(theForm.id_sales_person.selectedIndex > 0))
		{
			document.getElementById('id_sales_person').className='highlight';
			document.getElementById('id_sales_personimg').className='hlightimage';
			alert(msgSalesPerson);
			theForm.id_sales_person.focus();
			return false;
		}
		if(newreg == "Y" && !(theForm.id_hoover_type.selectedIndex > 0))
		{
			document.getElementById('id_hoovertype').className='highlight';
			document.getElementById('id_hoovertypeimg').className='hlightimage';
			alert(msgHooverType);
			theForm.id_hoover_type.focus();
			return false;
		}
		//For dealer check email only if it is entered
		if(!(isblank(theForm.email.value)))
		{
			if(!emailInvalid(theForm.email.value))
			{
				document.getElementById('email').className='highlight';
				document.getElementById('emailimg').className='hlightimage';
				alert(msgInvalidEmail);
				theForm.email.focus();
				return false;
			}
		}
	}
	else
	{
	  	if(isblank(theForm.email.value))
		{
			document.getElementById('email').className='highlight';
			document.getElementById('emailimg').className='hlightimage';
			alert(msgBlankEmail);
			theForm.email.focus();
			return false;
		}
		else if(!emailInvalid(theForm.email.value))
		{
			document.getElementById('email').className='highlight';
			document.getElementById('emailimg').className='hlightimage';
			alert(msgInvalidEmail);
			theForm.email.focus();
			return false;
		}
	}
	if(!(isblank(theForm.phone.value)))
	{
		if(!(check(theForm.phone.value)))
		{
			document.getElementById('phonemobile').className='highlight';
			document.getElementById('phonemobileimg').className='hlightimage';
			alert(msgPhoneFormat);
			theForm.phone.focus();
			return false;
		}
	}
  	if(!(isblank(theForm.mobile.value)))
	{
		if(!(check(theForm.mobile.value)))
		{
			document.getElementById('phonemobile').className='highlight';
			document.getElementById('phonemobileimg').className='hlightimage';
			alert(msgMobileFormat);
			theForm.mobile.focus();
			return false;
		}
	}
	if(isblank(theForm.phone.value) && isblank(theForm.mobile.value))
	{
		document.getElementById('phonemobile').className='highlight';
		document.getElementById('phonemobileimg').className='hlightimage';
		alert(msgOneCont);
		theForm.phone.focus();
		return false;
	}
	if(!(isblank(theForm.fax.value)))
	{
		if(!(check(theForm.fax.value)))
		{
			document.getElementById('fax').className='highlight';
			document.getElementById('faximg').className='hlightimage';
			alert(msgFaxFormat);
			theForm.fax.focus();
			return false;
  		}
  	}
	if(theForm.id_age && theForm.id_age.value == '')
	{
		document.getElementById('id_age').className='highlight';
		document.getElementById('id_ageimg').className='hlightimage';
		alert(msgAge);
		theForm.id_age.focus();
		return false;
	}
	if(!(isblank(theForm.cont_time.value)))
	{
		if(!(checkAddContTime(theForm.cont_time.value)))
		{
			document.getElementById('cont_time').className='highlight';
			document.getElementById('cnt_timeimg').className='hlightimage';
			alert(msgContTime);
			theForm.cont_time.focus();
			return false;
		}
	}
	if(newreg == "Y" && dealer == "N")
	{
		if(theForm.allow_save.checked == false)
		{
			document.getElementById('allow_save').className='highlight';
			document.getElementById('allow_saveimg').className='hlightimage';
			alert(msgAllowSaveInDb);
		 	return false;
		}
	}
	return true;
}
