//    Login Form Validation

function checkLogin(thisform)
{
	
	if(thisform.txtLogin.value=="")
	{
		alert(loginID);
		thisform.txtLogin.focus();
		return false;
	}

	if(thisform.txtPassword.value=="")
	{
		alert(password);
		thisform.txtPassword.focus();
		return false;
	}
	return true;
}

function checkAge()   //This function is called from fiscalAjax.js
{
					//Checking age is above 18 years... 

						var birth_day =  document.getElementById("chooseDate").value;
						var birth_month= document.getElementById("chooseMonth").value;
						var birth_year = document.getElementById("chooseYear").value;
						var birth_date=new Date();
						birth_date.setFullYear(birth_year,birth_month,birth_day);
																	
						var sys_day=document.getElementById("sysDay").value;
						var sys_month=document.getElementById("sysMonth").value;
						var sys_year=document.getElementById("sysYear").value;
						var sys_date=new Date();
						sys_date.setFullYear(sys_year,sys_month,sys_day);

						difference = sys_date - birth_date;
						//years = Math.floor(difference/(1000*60*60*24*365));
						//years=years+1;
						//alert(years);	
						years=sys_year-birth_year;
						if(years<18)
						{
							alert(validAge);
							document.getElementById("chooseYear").focus();
							return false;
						}
						else if(years==18)
						{
							if(sys_month < birth_month)
							{
								alert(validAge);
								document.getElementById("chooseYear").focus();
								return false;
							}
							else if(sys_month==birth_month)
							{
								if(sys_day < birth_day)
								{
									alert(validAge);
									document.getElementById("chooseYear").focus();
									return false;
								}

							}

						}

}

function checkExpiryDate()
{
	//Expiry date validation with system date..............................................................
						var exp_day = document.getElementById("chooseIssueDate").value;
						var exp_month=document.getElementById("chooseIssueMonth").value;
						var exp_year =document.getElementById("chooseIssueYear").value;
			
						if(exp_day!="" && exp_month!="" && exp_year!="")
						{
									var exp_date=new Date();
									exp_date.setFullYear(exp_year,exp_month,exp_day);
																				
									var sys_day=document.getElementById("sysDay").value;
									var sys_month=document.getElementById("sysMonth").value;
									var sys_year=document.getElementById("sysYear").value;
									var sys_date=new Date();
									sys_date.setFullYear(sys_year,sys_month,sys_day);
										  
									if(sys_date > exp_date)
									{
										alert(expiryDate);
										document.getElementById("chooseIssueYear").focus();
										return false;
									}
						}
}

function checkUserRegistrationForm(form2)
{
	with(form2)
	{
		
		
		//Personal Details
		if(txtLastName.value=="")
		{
			alert(lastName);
			txtLastName.focus();
			return false;
		}
		if(txtFirstName.value=="")
		{
			alert(userName);
			txtFirstName.focus();
			return false;
		}

		//Date & Place of Birth
		if(chooseDate.value=="")
		{
			alert(date);
			chooseDate.focus();
			return false;
		}
		if(chooseMonth.value=="")
		{
			alert(month);
			chooseMonth.focus();
			return false;
		}
		if(chooseYear.value=="")
		{
			alert(year);
			chooseYear.focus();
			return false;
		}
		//Checking age is above 18 years... 

						var birth_day = chooseDate.value;
						var birth_month=chooseMonth.value;
						var birth_year =chooseYear.value;
						var birth_date=new Date();
						birth_date.setFullYear(birth_year,birth_month,birth_day);
																	
						var sys_day=sysDay.value;
						var sys_month=sysMonth.value;
						var sys_year=sysYear.value;
						var sys_date=new Date();
						sys_date.setFullYear(sys_year,sys_month,sys_day);

						difference = sys_date - birth_date;
						//years = Math.floor(difference/(1000*60*60*24*365));
						years=sys_year-birth_year;
																  
						if(years<18)
						{
							alert(validAge);
							chooseYear.focus();
							return false;
						}
						else if(years==18)
						{
							if(sys_month < birth_month)
							{
								alert(validAge);
								chooseYear.focus();
								return false;
							}
							else if(sys_month==birth_month)
							{
								if(sys_day < birth_day)
								{
									alert(validAge);
									chooseYear.focus();
									return false;
								}

							}

						}

		if(chkNation.checked)
		{

				
				if(txtBornCity.value=="")
				{
					alert(city);
					txtBornCity.focus();
					return false;
				}
				if(chooseBornState.value=="")
				{
					alert(state);
					chooseBornState.focus();
					return false;
				}
				
		}
		else
		{
			    if(bornDetails.value=="")
			    {
					alert(birthDetails);
					bornDetails.focus();
					return false;
			    }
		}

		// Residency Details
		if(chkResident.checked)
		{

				if(txtAddress.value=="")
				{
					alert(address);
					txtAddress.focus();
					return false;
				}
				if(txtStreetNumber.value=="")
				{
					alert(streetNumber);
					txtStreetNumber.focus();
					return false;
				}
				/*else if(isNaN(txtStreetNumber.value))
				{
					alert(streetNumeric);
					txtStreetNumber.focus();
					return false;

				}*/
				if(chooseState.value=="")
				{
					alert(state);
					chooseState.focus();
					return false;
				}
				if(txtResidentCity.value=="")
				{
					alert(city);
					txtResidentCity.focus();
					return false;
				}

				if(txtZipCode.value=="")
				{
					alert(zipCode);
					txtZipCode.focus();
					return false;
				}
				/*else if(isNaN(txtZipCode.value))
				{
					alert(zipNumeric);
					txtZipCode.focus();
					return false;

				}*/

		}
		else
		{
			    if(residentDetails.value=="")
			    {
					alert(birthDetails);
					residentDetails.focus();
					return false;
			    }
		}

		// Information

		if(txtTele.value=="")
		{
				if(txtMobile.value=="")
				{
					alert(phone);
					txtMobile.focus();
					return false;
				}
				/*else if(isNaN(txtMobile.value))
				{
					alert(mobileNumeric);
					txtMobile.focus();
					return false;

				}*/
			
		}
		/*else if(isNaN(txtTele.value))
		{
			alert(teleNumeric);
			txtTele.focus();
			return false;

		}

		if((txtMobile.value!="")&&(isNaN(txtMobile.value)))
		{
			alert(mobileNumeric);
			txtMobile.focus();
		    return false;

		}*/

		/*if(txtFax.value=="")
		{
			alert(fax);
			txtFax.focus();
			return false;
		}*/
		/*else if(isNaN(txtFax.value))
		{
			alert(faxNumeric);
			txtFax.focus();
			return false;

		}*/


		if(txtMail.value=="")
		{
			alert(validEmail);
			txtMail.focus();
			return false;
		}
		else if(txtMail.value.indexOf("@")<1 || txtMail.value.indexOf(".")<1)
		{
			alert(validEmail);
			txtMail.focus();
			return false;
		}

		if(chooseUserCategory.value=="")
		{
			alert(userCat);
			chooseUserCategory.focus();
			return false;
		}
		if(chooseDeviceType.value=="")
		{
			alert(deviceCat);
			chooseDeviceType.focus();
			return false;
		}

		//Identification
		 if(chooseType.value=="")
		{
			alert(idCard);
			chooseType.focus();
			return false;

		}
		 if(txtNumber.value=="")
		{
			alert(idNumber);
			txtNumber.focus();
			return false;

		}
		 if(txtIssueBy.value=="")
		{
			alert(authName);
			txtIssueBy.focus();
			return false;

		}
		 if(chooseIssueDate.value=="")
		{
			alert(issueDay);
			chooseIssueDate.focus();
			return false;

		}
		 if(chooseIssueMonth.value=="")
		{
			alert(issueMonth);
			chooseIssueMonth.focus();
			return false;

		}

		if(chooseIssueYear.value=="")
		{
			alert(issueYear);
			chooseIssueYear.focus();
	     	return false;
		}
		
		//Expiry date validation with system date..............................................................
						var exp_day = chooseIssueDate.value;
						var exp_month=chooseIssueMonth.value;
						var exp_year =chooseIssueYear.value;
						var exp_date=new Date();
						exp_date.setFullYear(exp_year,exp_month,exp_day);
																	
						var sys_day=sysDay.value;
						var sys_month=sysMonth.value;
						var sys_year=sysYear.value;
						var sys_date=new Date();
						sys_date.setFullYear(sys_year,sys_month,sys_day);
						      
						if(sys_date > exp_date)
						{
							alert(expiryDate);
							chooseIssueYear.focus();
							return false;
						}
		

		if(txtCountry.value=="")
		{
			alert(country);
			txtCountry.focus();
			return false;

		}

		//Date Of Registration
     if(hidAction.value=='addUser')
	{
		 if(chooseRegistDate.value=="")
		{
			alert(registerDay);
			chooseRegistDate.focus();
			return false;

		}
		 if(chooseRegistMonth.value=="")
		{
			alert(registerMonth);
			chooseRegistMonth.focus();
			return false;

		}
		if(chooseRegistYear.value=="")
		{
			alert(registerYear);
			chooseRegistYear.focus();
			return false;

		}
	}
		if(!chkNewUsr.checked)
		{
			 alert(chkNewUser);
			 chkNewUsr.focus();
			 return false;

		}
		
		//Checkboxes
		if((hidAction.value=='addUser') || (document.getElementById('chk1')))
		{
			if((!chk1.checked) || !(chk2.checked) || (!chk3.checked) || (!chk4.checked) || (!chk5.checked) )
			{
				alert(checklist);
				chk1.focus();
				return false;

			}
		}


        if(hidAction.value=='updateUser')
		{
			var r=confirm(printmsg);
			 if (r==true)
			 {
			
			 }
			 else
			 {
			   hidAction.value='updateWithoutPrint';
			 }
		}
		/*else  if(hidAction.value=='addPreWilmaUser')
		{
			var r=confirm("Are you sure?");
			 if (r==true)
			 {
			   return true;
			 }
			 else
			 {
			   return false;
			 }
		}*/

		return true;

	}
}

//Function Used To validate Change Passwords form
function checkForm(passwordForm)
{
	
	with(passwordForm)
	{
		if(oldPassword.value=="")
		{
			alert(prevPassword);
			oldPassword.focus();
			return false;
		}
		if(newPassword.value=="")
		{
			alert(newPass);
			newPassword.focus();
			return false;
		}
		if(confirmPassword.value=="")
		{
			alert(confirmPass);
			confirmPassword.focus();
			return false;
		}
		if(dbPassword.value!=oldPassword.value)
		{
			alert(wrongPass);
			oldPassword.value="";
			oldPassword.focus();
			return false;

		}
		if(newPassword.value!=confirmPassword.value)
		{
			alert(wrongMatch);
			newPassword.value="";
			confirmPassword.value="";
			newPassword.focus();
			return false;

		}
		if(document.getElementById('frmUserChangePass'))
		{
			if(newPassword.value.length<6)
		    {
				alert(minPassword1);
				newPassword.value="";
			    confirmPassword.value="";
			    newPassword.focus();
				return false;
			}

		}
		else if(document.getElementById('frmOperatorChangePass'))
		{
			if(newPassword.value.length<8)
		    {
				alert(minPassword2);
				newPassword.value="";
			    confirmPassword.value="";
			    newPassword.focus();
				return false;
			}

		}
		
	   return true;
	}
	

}

function check(formPass)
{
	with(formPass)
	{
		if(txtUser.value=="")
		{
           alert(loginID);
		   txtUser.focus();
		   return false; 
		}
	}
}
function mobileFormCheck()
{
	//var myformValidator = new Validator("mobForm");
	//myformValidator.addValidation("txtUser","req",loginID);

	/*if(document.mobForm.onsubmit())
	{this check triggers the validations
		document.mobForm.submit();
	}*/
	
	if(document.getElementById('txtUser').value=="")
	{
		alert(loginID);
		document.getElementById('txtUser').focus();
	}
	else
	{
		document.getElementById('HypelinkPassRec').href="index.php?hidAction=sendPassword";
		document.mobForm.submit();
	}

}


/*function onKeyPress (e) 
{
	var keycode;
	if (window.event) 
		keycode = window.event.keyCode;
	else 
	{
		if (e) 
			keycode = e.which;
		else 
			return true;
	}
	if (keycode == 13) 
	{
		return false;
	}
	return true;
}




document.onkeypress = onKeyPress;*/