// JavaScript Document

// Coding for the validaion of the login.php page
function login_validation()
{
	if (document.frm_login.frm_username.value=="")
	{
		 alert("Please enter your Username");
		 document.frm_login.frm_username.focus();
		 return false
	}
	if (document.frm_login.frm_password.value=="")
	{
		 alert("Please enter your Password");
		 document.frm_login.frm_password.focus();
		 return false
	}
return true;
}
// end of login page validation coding

// Coding for the validation of the adding of country name in country.php page
function country_validation()
{
	if (document.frm_addcountry.frm_countryname.value=="" || document.frm_addcountry.frm_countryname.value.charAt(0)==" ")
	{
		 alert("Please enter country name");
		 document.frm_addcountry.frm_countryname.select();
		 return false
	}
	validRegExp = /^[a-z 0-9]+$/i;
	strName = trim(document.frm_addcountry.frm_countryname.value);
	if ( strName.search(validRegExp) == -1)
	{
		alert("Please enter valid country name");
		document.frm_addcountry.frm_countryname.select();
		return false
	}
	if (document.frm_addcountry.frm_vat.value==""  || document.frm_addcountry.frm_vat.value.charAt(0)==" ")
	{
		 alert("Please enter VAT");
		 document.frm_addcountry.frm_vat.select();
		 return false
	}
	var comm = document.frm_addcountry.frm_vat.value;
	var val=comm.substr(comm.length-3,1);
	if(val != "."){
		alert("Enter Proper VAT");
		document.frm_addcountry.frm_vat.select();
		return false;
	}
	if (document.frm_addcountry.frm_countrycode.value==""  || document.frm_addcountry.frm_countrycode.value.charAt(0)==" ")
	{
		 alert("Please enter Country Code");
		 document.frm_addcountry.frm_countrycode.select();
		 return false
	}
		validRegExp = /^[a-z 0-9 \-\_]+$/i;
	strName = trim(document.frm_addcountry.frm_countrycode.value);
	if ( strName.search(validRegExp) == -1)
	{
		alert("Please enter valid Country Code");
		document.frm_addcountry.frm_countrycode.select();
		return false
	}


}
// End of Country page validation coding

// Coding for the validation of the editting of country name in country.php page
function editcountry_validation()
{
	if (document.frm_editcountry.frm_editcountryname.value=="" || document.frm_editcountry.frm_editcountryname.value.charAt(0)==" ")
	{
		 alert("Please enter country name");
		 document.frm_editcountry.frm_editcountryname.select();
		 return false
	}
	validRegExp = /^[a-z ]+$/i;
	strName = trim(document.frm_editcountry.frm_editcountryname.value);
	if ( strName.search(validRegExp) == -1)
	{
		alert("Please enter valid country name");
		document.frm_editcountry.frm_editcountryname.select();
		return false
	}
	if (document.frm_editcountry.frm_editvat.value=="" || document.frm_editcountry.frm_editvat.value.charAt(0)==" ")
	{
		 alert("Please enter VAT");
		 document.frm_editcountry.frm_editvat.select();
		 return false
	}
	var comm = document.frm_editcountry.frm_editvat.value;
	var val=comm.substr(comm.length-3,1);
	if(val != "."){
		alert("Enter Proper VAT");
		document.frm_editcountry.frm_editvat.select();
		return false;
	} 
	if (document.frm_editcountry.frm_edit_countrycode.value=="" || document.frm_editcountry.frm_edit_countrycode.value.charAt(0)==" ")
	{
		 alert("Please enter Country Code");
		 document.frm_editcountry.frm_edit_countrycode.select();
		 return false
	}
	
	validRegExp = /^[a-z 0-9 \-\_]+$/i;
	strName = trim(document.frm_editcountry.frm_edit_countrycode.value);
	if ( strName.search(validRegExp) == -1)
	{
		alert("Please enter valid Country Code");
		document.frm_editcountry.frm_edit_countrycode.select();
		return false
	}

}
// End of edit country name in  Country page validation coding

// Function for triming the data
function trim(str) {
     str = str.replace(/^\s+/, ""); // beginning spaces are convert to an empty string

     str = str.replace(/\s+$/, ""); // ending spaces are convert to an empty string

     return(str);
}
// function for paging validations
function checkgoto(form,tot){
		if(form.goto.value==""){
			alert("You must enter the page number!.");
			form.goto.focus();
			return false;
		}else{
			goto = form.goto.value;
			if((!isNaN(goto)) && (goto > 0) && (goto <= tot)){}
			else{
				alert("You must enter a valid page number!.\nRange of (1 to "+tot+")");
				form.goto.value="";
				form.goto.focus();
				return false;
			}
		}
	}
	function setgoto(page){
		document.paging.goto.value=page;
	}
// Coding for the validation of the adding of region name in region.php page	
function region_validation()
{
	if(document.frm_addregion.frm_countryid.selectedIndex=="0")
	{
		alert("Please Select Countryname");
		document.frm_addregion.frm_countryid.focus();
		return false;
	}
	if(document.frm_addregion.frm_regionname.value=="" || document.frm_addregion.frm_regionname.value.charAt(0)==" ")
	{
		alert("Please Enter Region Name");
		document.frm_addregion.frm_regionname.focus();
		return false;
	}
	validRegExp = /^[a-z 0-9 \-\_\(\)\/]+$/i;
	strName = trim(document.frm_addregion.frm_regionname.value);
	if ( strName.search(validRegExp) == -1)
	{
		alert("Please enter valid Region Name");
		document.frm_addregion.frm_regionname.focus();
		return false
	}
	if(document.frm_addregion.frm_airportcode.value!=""){
		validRegExp = /^[a-z 0-9 \-\_\(\)]+$/i;
		strName = trim(document.frm_addregion.frm_airportcode.value);
		if ( strName.search(validRegExp) == -1)
		{
			alert("Please enter valid Region Name");
			document.frm_addregion.frm_airportcode.focus();
			return false
		}
	}
	return true;
}
// End of region page validation coding
// Coding for the validation of the editing of region name in region.php page
function editregion_validation()
{
	if(document.frm_editregion.frm_edit_countryid.selectedIndex=="0")
	{
		alert("Please Select Countryname");
		document.frm_editregion.frm_edit_countryid.focus();
		return false;
	}
	if(document.frm_editregion.frm_edit_regionname.value=="" || document.frm_editregion.frm_edit_regionname.value.charAt(0)==" ")
	{
		alert("Please Enter Regionname");
		document.frm_editregion.frm_edit_regionname.focus();
		return false;
	}
	validRegExp = /^[a-z 0-9 \-\_\(\)\/]+$/i;
	strName = trim(document.frm_editregion.frm_edit_regionname.value);
	if ( strName.search(validRegExp) == -1)
	{
		alert("Please enter valid Region Name");
		document.frm_editregion.frm_edit_regionname.focus();
		return false
	}
	if(document.frm_editregion.frm_edit_airportcode.value!=""){
		validRegExp = /^[a-z 0-9 \-\_\(\)]+$/i;
		strName = trim(document.frm_editregion.frm_edit_airportcode.value);
		if ( strName.search(validRegExp) == -1)
		{
			alert("Please enter valid Airport Code");
			document.frm_editregion.frm_edit_airportcode.focus();
			return false
		}
	}

	return true;
}
// End of editregion page validation coding
// Coding for the validation of the adding of town name in town.php page
function town_validation()
{
	if(document.frm_addtown.frm_countryid.selectedIndex=="0")
	{
		alert("Please Select Countryname");
		document.frm_addtown.frm_countryid.focus();
		return false;
	}
	if(document.frm_addtown.frm_regionid.selectedIndex=="0")
	{
		alert("Please Select Regionname");
		document.frm_addtown.frm_regionid.focus();
		return false;
	}
	if(document.frm_addtown.frm_townname.value=="")
	{
		alert("Please Enter Townname");
		document.frm_addtown.frm_townname.focus();
		return false;
	}
	return true;
}
// End of adding of town name page validation coding
// Coding for the validation of the editing of town name in town.php page
function edittown_validation()
{
	if(document.frm_edittown.frm_edit_countryid.selectedIndex==0)
	{
		alert("Please Select Countryname");
		document.frm_edittown.frm_edit_countryid.focus();
		return false;
	}
	if(document.frm_edittown.frm_edit_regionid.selectedIndex==-1)
	{
		alert("Please Select Regionname");
		document.frm_edittown.frm_edit_regionid.focus();
		return false;
	}
	if(document.frm_edittown.frm_edit_townname.value=="")
	{
		alert("Please Enter Townname");
		document.frm_edittown.frm_edit_townname.focus();
		return false;
	}
	return true;
}
// End of editing of town name page validation coding
// Coding for the validation of the adding of carclass name in region.php page	
function carclass_validation()
{
	if(document.frm_addcarclass.frm_countryid.selectedIndex=="0")
	{
		alert("Please Select Countryname");
		document.frm_addcarclass.frm_countryid.focus();
		return false;
	}
	if(document.frm_addcarclass.frm_carclassname.value=="" || document.frm_addcarclass.frm_carclassname.value.charAt(0)==" ")
	{
		alert("Please Enter Carclassname");
		document.frm_addcarclass.frm_carclassname.select();
		return false;
	}
	valid = " ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789()&_:-.\/";
	len1 = document.frm_addcarclass.frm_carclassname.value.length;
	vv = document.frm_addcarclass.frm_carclassname.value;
	pflag=false;char=0;num=0;wchar=0;
		for(ff=0;ff<len1;ff++){//For 3 Starts
		char = vv.charAt(ff);
			if(valid.indexOf(char) == -1){//If 8 Starts
				pflag=true;
				++wchar;
			}//If 8 Ends
		}//For 3 Ends
	if(wchar!=0){
		alert("Please Enter a valid Carclass Name");
		document.frm_addcarclass.frm_carclassname.focus();
		return false
	}
	
	return true;
}
// End of carclass page validation coding
// Coding for the validation of the editing of carclass name in region.php page
function editcarclass_validation()
{
	if(document.frm_editcarclass.frm_edit_countryid.selectedIndex=="0")
	{
		alert("Please Select Countryname");
		document.frm_editcarclass.frm_edit_countryid.focus();
		return false;
	}
	if(document.frm_editcarclass.frm_edit_carclassname.value=="" || document.frm_editcarclass.frm_edit_carclassname.value.charAt(0)==" ")
	{
		alert("Please Enter Carclassname");
		document.frm_editcarclass.frm_edit_carclassname.select();
		return false;
	}
	/*validRegExp = /^[a-z ]+$/i;
	strName = trim(document.frm_editcarclass.frm_edit_carclassname.value);
	if ( strName.search(validRegExp) == -1)
	{
		alert("Please enter valid Carclass  Name");
		document.frm_editcarclass.frm_edit_carclassname.focus();
		return false
	}*/
	return true;
}
// End of editregion page validation coding
//validation for subscriber admin
function subscriber_validation()
{
	if (document.frm_addsubscriber.frm_subscriber_name.value=="" || document.frm_addsubscriber.frm_subscriber_name.value.charAt(0)==" ")
	{
		 alert("Please enter Subscribername");
		 document.frm_addsubscriber.frm_subscriber_name.select();
		 return false
	}
	validRegExp = /^[a-z ]+$/i;
	strName = trim(document.frm_addsubscriber.frm_subscriber_name.value);
	if ( strName.search(validRegExp) == -1)
	{
		alert("Please enter valid Subscribername");
		document.frm_addsubscriber.frm_subscriber_name.focus();
		return false
	}
	if(document.frm_addsubscriber.frm_subscriber_email.value=="" || document.frm_addsubscriber.frm_subscriber_email.value.charAt(0)==" ")  
  {
					alert("Enter Email-Id");
					document.frm_addsubscriber.frm_subscriber_email.select(); 
					return false;
  }
  if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(frm_addsubscriber.frm_subscriber_email.value))
		{
			}
			else 
			{
				alert("Invalid E-mail Address! Please re-enter.");
				document.frm_addsubscriber.frm_subscriber_email.select();
				return false;
			}
return true;
}
//end of subscriber valid
//validation for subscriber admin
function editsubscriber_validation()
{
	if (document.frm_editsubscriber.frm_edit_subscriber_name.value=="" || document.frm_editsubscriber.frm_edit_subscriber_name.value.charAt(0)==" ")
	{
		 alert("Please enter Subscribername");
		 document.frm_editsubscriber.frm_edit_subscriber_name.select();
		 return false
	}
	validRegExp = /^[a-z ]+$/i;
	strName = trim(document.frm_editsubscriber.frm_edit_subscriber_name.value);
	if ( strName.search(validRegExp) == -1)
	{
		alert("Please enter valid Subscribername");
		document.frm_editsubscriber.frm_edit_subscriber_name.focus();
		return false
	}
	if(document.frm_editsubscriber.frm_edit_subscriber_email.value=="")  
  {
					alert("Enter Email-Id");
					document.frm_editsubscriber.frm_edit_subscriber_email.select(); 
					return false;
  }
  if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(frm_editsubscriber.frm_edit_subscriber_email.value))
		{
			}
			else 
			{
				alert("Invalid E-mail Address! Please re-enter.");
				document.frm_editsubscriber.frm_edit_subscriber_email.select();
				return false;
			}
return true;
}
//end of subscriber valid
//validation for season
function season_validation()
{
	if (document.frm_addseason.frm_seasonname.value=="")
	{
		 alert("Please enter Season");
		 document.frm_addseason.frm_seasonname.focus();
		 return false
	}
	return true;
}
//end ofvalidation for season
//validation for editingn season
function editseason_validation()
{
	if (document.frm_editseason.frm_editseasonname.value=="")
	{
		 alert("Please enter Season");
		 document.frm_editseason.frm_editseasonname.focus();
		 return false
	}
	return true;
}
//end of validation for editing season
// Coding for the validation of the adding the commission value
function commision_validation()
{
	if(document.frm_commission.frm_countryid.selectedIndex=="0")
	{
		alert("Please Select Countryname");
		document.frm_commission.frm_countryid.focus();
		return false;
	}
	if(document.getElementById("frm_regionid").value.length == 0)
	{
		alert("Please Select Regionname");
		document.getElementById("frm_regionid").focus();
		return false;
	}
	if(document.frm_commission.frm_supplierid.selectedIndex=="0")
	{
		alert("Please Select Suppliername");
		document.frm_commission.frm_supplierid.focus();
		return false;
	}
	if(document.frm_commission.frm_commission.value =="" && document.frm_commission.frm_netrates.value ==""){
      alert("Please enter either Commission or Net Rates");
      document.frm_commission.frm_commission.focus();
      return false;
    }

	if(document.frm_commission.frm_commission.value!=""){
		if(document.frm_commission.frm_netrates.value !=""){
		  alert("Please enter either Commission or Net Rates");
		  document.frm_commission.frm_commission.focus();
		  return false;
		}

		if(isNaN(document.frm_commission.frm_commission.value)){
		  alert("Invalid Commission value");
		  document.frm_commission.frm_commission.focus();
		  return false;
		}
		if((parseInt(document.frm_commission.frm_commission.value)>99)){
		  alert("Commission should be less than 100");
		  document.frm_commission.frm_commission.focus();
		  return false;
		}
    }else if(document.frm_commission.frm_netrates.value!=""){
		if( document.frm_commission.frm_commission.value !=""){
		  alert("Please enter either Net Rates or Commission ");
		  document.frm_commission.frm_netrates.focus();
		  return false;
		}
		if(isNaN(document.frm_commission.frm_netrates.value)){
		  alert("Invalid Net Rate value");
		  document.frm_commission.frm_netrates.focus();
		  return false;
		}
		if((parseInt(document.frm_commission.frm_netrates.value)>99)){
		  alert("Net Rate should be less than 100");
		  document.frm_commission.frm_netrates.focus();
		  return false;
		}
		
	}
	return true;
}
// End of adding of town name page validation coding
// Coding for the validation of the editing of commission value
function editcommision_validation()
{
	if(document.frm_editcommission.frm_edit_countryid.selectedIndex=="0")
	{
		alert("Please Select Countryname");
		document.frm_editcommission.frm_edit_countryid.focus();
		return false;
	}
	if(document.getElementById("frm_edit_regionid").value.length == 0 || document.getElementById("frm_edit_regionid").value ==0)
	{
		alert("Please Select Regionname");
		document.getElementById("frm_edit_regionid").focus();
		return false;
	}
	if(document.frm_editcommission.frm_edit_supplierid.selectedIndex=="0")
	{
		alert("Please Select Suppliername");
		document.frm_editcommission.frm_edit_supplierid.focus();
		return false;
	}
	if(document.frm_editcommission.frm_edit_commission_value.value =="" && document.frm_editcommission.frm_edit_netrates.value ==""){
      alert("Please enter either Commission or Net Rates");
      document.frm_editcommission.frm_edit_commission_value.focus();
      return false;
    }

	if(document.frm_editcommission.frm_edit_commission_value.value!=""){
		if(document.frm_editcommission.frm_edit_netrates.value !=""){
		  alert("Please enter either Commission or Net Rates");
		  document.frm_editcommission.frm_edit_commission_value.focus();
		  return false;
		}

		if(isNaN(document.frm_editcommission.frm_edit_commission_value.value)){
		  alert("Invalid Commission value");
		  document.frm_editcommission.frm_edit_commission_value.focus();
		  return false;
		}
		if((parseInt(document.frm_editcommission.frm_edit_commission_value.value)>99)){
		  alert("Commission should be less than 100");
		  document.frm_editcommission.frm_edit_commission_value.focus();
		  return false;
		}
    }else if(document.frm_editcommission.frm_edit_netrates.value!=""){
		if( document.frm_editcommission.frm_edit_commission_value.value !=""){
		  alert("Please enter either Net Rates or Commission ");
		  document.frm_editcommission.frm_edit_netrates.focus();
		  return false;
		}
		if(isNaN(document.frm_editcommission.frm_edit_netrates.value)){
		  alert("Invalid Net Rate value");
		  document.frm_editcommission.frm_edit_netrates.focus();
		  return false;
		}
		if((parseInt(document.frm_editcommission.frm_edit_netrates.value)>99)){
		  alert("Commission should be less than 100");
		  document.frm_editcommission.frm_edit_netrates.focus();
		  return false;
		}
		
	}
	return true;
}
// End of editing of commission value page validation coding