function ManageCMS(mf)
{
	if(mf.cms_page.value=="")
	{
		alert("Please select page.");
		mf.cms_page.focus();
		return false;
	}
	/*if(trim(mf.txtContent.value)=="")
	{
		alert("Please enter the content.");
		//mf.txtContent.focus();
		return false;
	}*/
	return true;
}

function CheckAirport(mf)	
{
	if(mf.country.value=="")
	{
		alert("Please select country.");
		mf.country.focus();
		return false;
	}
	if(mf.city.value=="")
	{
		alert("Please enter the city.");
		mf.city.focus();
		return false;
	}
	if(mf.airport_name.value=="")
	{
		alert("Please enter the airport name.");
		mf.airport_name.focus();
		return false;
	}
	if(mf.airport_code.value=="")
	{
		alert("Please enter the airport code.");
		mf.airport_code.focus();
		return false;
	}
	
}
	
		
	function toggle(dom1,dom2,intnl_1,intnl_2)
	{
		el = document.getElementById(dom1);
		e2 = document.getElementById(dom2);
		e3 = document.getElementById(intnl_1);
		e4 = document.getElementById(intnl_2);
		
		var upperdiv=document.getElementById("upper");	
		var lastdiv=document.getElementById("last");
		
		if(el.style.display=='none' && e2.style.display=='none' && document.getElementById("Domestics").checked)
		{
			el.style.display='';
			e2.style.display='';
			e3.style.display='none';
			e4.style.display='none';
			document.getElementById("from_location_dom").disabled=false;
			document.getElementById("to_location_dom").disabled=false;
			document.getElementById("from_location1").disabled=true;
			document.getElementById("to_location1").disabled=true;
			
			upperdiv.innerHTML=International_and_domesticsStr;
			
			lastdiv.innerHTML=InternationalStr;
			document.getElementById("last").style.display="none";
			
		}	
		else if(document.getElementById("International").checked)
		{
			el.style.display='none';
			e2.style.display='none';
			e3.style.display='';
			e4.style.display='';
			document.getElementById("from_location1").disabled=false;
			document.getElementById("to_location1").disabled=false;
			document.getElementById("from_location_dom").disabled=true;
			document.getElementById("to_location_dom").disabled=true;
			
			upperdiv.innerHTML=InternationalStr;
			lastdiv.innerHTML=InternationalStr;
			document.getElementById("last").style.display="none";
			
		}
	}
	
	function toggleTrip(depart_id,return_id)
	{
		dept_id = document.getElementById(depart_id);
		retun_id = document.getElementById(return_id);
		
		if(document.getElementById('round_trip').checked)
		{
			document.getElementById('return').style.display="";
			document.getElementById('return_1').style.display="";
		}	
		else if(document.getElementById('one_way').checked)
		{
			document.getElementById('return').style.display="none";
			document.getElementById('return_1').style.display="none";
		}
	}
	
function ValidMailAccount(mf)
{
  var rxp =/^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})$/;
  if(trim(mf.from_name.value)== "")
  {
     alert("Please enter the from name.");
	 mf.from_name.focus();
	 return false;
  }

  if(trim(mf.from_email.value)=="")
  {
     alert("Please enter the from email address.");
	 mf.from_email.focus();
	 return false;
  }
  else if(rxp.test(mf.from_email.value)!=true)
	{
		alert('Invalid from email address.');
		mf.from_email.focus();
		return false;
	}
  
  if(trim(mf.subject.value)== "")
  {
     alert("Please enter the subject.");
	 mf.subject.focus();
	 return false;
  }
    if(trim(mf.mail_signature.value)== "")
  {
     alert("Please enter the e-mail signature.");
	 mf.mail_signature.focus();
	 return false;
  }
  return true;
}


function CheckChangeEmail(mf)
{
  var rxp =/^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})$/;
  if(trim(mf.oldemail.value)=="")
  {
     alert("Please enter old password.");
	 mf.oldemail.focus();
	 return false;
  }
 
  if(rxp.test(mf.oldemail.value)!=true)
	{
		alert("Invalid e-mail address.");
		mf.oldemail.focus();
		return false;
	}
  if(trim(mf.newemail.value)=="")
  {
     alert("Please enter new e-mail address.");
	mf.newemail.focus();
	 return false;
  }
  if(rxp.test(mf.newemail.value)!=true)
	{
		alert("Invalid e-mail address.");
		mf.newemail.select();
		mf.newemail.focus();
		return false;
	}
  return true;
}


function ValidChars(validchars,value) 
 { 
	var key='';
	var keychar='';
	for(i=0;i<value.length;i++)
	{
		keychar = value.charAt(i);
		keychar = keychar.toLowerCase();
		validchars = validchars.toLowerCase();
		if (validchars.indexOf(keychar) == -1)
		{
			key=keychar;
		}
	}
	if(key!='')
		return false;
	else
		return true;
}

function isURL(string)			// function to check valid format of url
{
	if(!string) return false;
	string = string.toLowerCase();
	urlRegExp = /^(((ht|f)tp(s?))\:\/\/)([0-9a-zA-Z\-]+\.)+[a-zA-Z]{2,6}(\:[0-9]+)?(\/\S*)?$/
	return urlRegExp.test(string);
}


function isValidTelephone(strTmp)
{
	var valid = "+-()0123456789 ";
	for (var i=0; i < strTmp.length; i++) 
	{
		temp = strTmp.substring(i, i+1);
		if (valid.indexOf(temp) == "-1") 
		{
			alert("ALERT_MSG_PHONE_NUMBER");
			return false;
		}	
	}
	return true;
}

function isValidFax(strTmp)
{
	var valid = "+-()0123456789 ";
	for (var i=0; i < strTmp.length; i++) 
	{
		temp = strTmp.substring(i, i+1);
		if (valid.indexOf(temp) == "-1") 
		{
			alert("ALERT_MSG_FAX_NUMBER");
			return false;
		}	
	}
	return true;
}


function trim(str)
{ 
	return str.replace(/^\s*|\s*$/g,""); 
}
  var rxp =/^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})$/;


function set_focus(mf)
{
	if(mf.admin_username.value=="")
	{
		mf.admin_username.focus();
	}
}
	


function val_updateglobalprice()
{

  if(document.updateglobalprice.globalprice.value!="" && isNaN(document.updateglobalprice.globalprice.value))
  {
	  alert("ALERT_MSG_NUMERIC_VALUE");
	  document.updateglobalprice.globalprice.value="";
	  document.updateglobalprice.globalprice.focus();
  return false;
  }
  else
  {
  return true;
  }
}


function CheckAdminLogin(mf)
{
	  if(trim(mf.admin_username.value)=='')
	  {
		alert('Please enter the username.');
		mf.admin_username.focus();
		return false;
	  }
	 
	 if(trim(mf.admin_password.value)=='')
	 {
		alert('Please enter the password.');
		mf.admin_password.focus();
		return false;
	  }
 	 return true;
}


 function valchgpassfrm()
   {
	   msg="";
	   count=0;
     if(document.chgpassfrm.opassword.value=="")
	 {
	  count++;
	  msg=msg+count+") Please enter old password.\n";
	 }
	 if(document.chgpassfrm.npassword.value=="")
	 {
	 count++;
	 msg=msg+count+") Please enter new password.\n";
	 }
	 if(document.chgpassfrm.cpassword.value=="")
	 {
	 count++;
	 msg=msg+count+") Please confirm new password\n";
	 }
	 if(document.chgpassfrm.npassword.value!='' && document.chgpassfrm.cpassword.value!="" && document.chgpassfrm.cpassword.value != document.chgpassfrm.npassword.value)
	 {
	 count++;
	 msg=msg+count+") The new password field does not match the confirm password field.\n";
	 document.chgpassfrm.cpassword.value='';
	 document.chgpassfrm.npassword.value='';
	 }
	 if(count>0)
	 {
		 alert(msg);
		 return false;
	 }
	 else
	 {
	 	return true;
	 }
   }

   /*--------------------------validation for add office admin -----------------*/
   function valadd_editadminfrm()
	{
		msg="";
		count=0;
    if(document.addadminfrm.username.value=="")
	{
	count++;
	msg=msg+count+") Please enter the username.\n";
	}
	if(document.addadminfrm.emailid.value=="")
	{
	count++;
	msg=msg+count+") ALERT_MSG_EMAIL\n";
	}
	if(!(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(document.addadminfrm.emailid.value)))
			 {
			  count++;
	   msg=msg+count+") ALERT_INVALID_EMAIL\n";


			 }
	if(document.addadminfrm.password.value=="")
	{
	count++;
	msg=msg+count+") Please enter the password.\n";
	}
	if(document.addadminfrm.cpassword.value=="")
	{
	count++;
	msg=msg+count+") Please confirm new password\n";
	}
	if(document.addadminfrm.password.value!="" && document.addadminfrm.cpassword.value!="" && document.addadminfrm.password.value != document.addadminfrm.cpassword.value)
	{
	count++;
	msg=msg+count+") The new password field does not match the confirm password field.";
	ocument.addadminfrm.password.value='';
	ocument.addadminfrm.cpassword.value='';
	}
	if(count>0)
	{
	alert(msg);
	return false;
	}
	else
	{
	return true;
	}
}

/*---------------------------vaidation for on chek chek all and chek delete selected record--------------------------------*/
function CheckAll()
	{

    for (var i = 0; i < document.myForm.elements.length; i++)
   {
    if(document.myForm.elements[i].type == 'checkbox')
 	{
		if(document.myForm.mainCheckbox.checked == true)
		{ document.myForm.elements[i].checked = true;}

	   if(document.myForm.mainCheckbox.checked == false)
		{ document.myForm.elements[i].checked = false;}
     }
	 }
	}

	// javascript which work on click of delete Selected button
function onDelete(err_msg,confirm_msg){
var count=0;

	    for (var i = 0; i < document.myForm.elements.length; i++)
     {
    	if(document.myForm.elements[i].type == 'checkbox')
	    {
        	if(document.myForm.elements[i].checked == true)
	        {
	            var count=count +i;
	        }
     	}
	 }
	if(count==0)
	{
	 alert(err_msg);
     return false;
	}
	else
    {

     if (confirm (confirm_msg))
     {
       document.myForm.submit();
      return true;

     }
     else
     {
      return false;
     }
	}
}


/*---------------validation for change status of admin---------------------*/
function change_adminstatus(adminid)
{
if(confirm("CONFIRM_CHANGE_STATUS"))
 {
  document.getElementById("ajaxtr").style.display="";
  document.getElementById("message").style.display="none";
    document.getElementById("ajaxdiv").style.display="block";
	url="../ajax/process.php?process=changeadminstatus&adminid="+adminid;
	//alert(url);
	loadXMLDocgetprice(url);
	}
}
/*-------------------function for change hedaer image status-------------------------------*/
	function change_headerimagestatus(imageid)
	{
	  if(confirm("CONFIRM_CHANGE_HEADER_IMAGE"))
      {
	 document.getElementById("ajaxtr").style.display="";
    document.getElementById("message").style.display="none";
    document.getElementById("ajaxdiv").style.display="block";
	url="../ajax/process.php?process=changeheaderimagestatus&headeridid="+imageid;
	loadXMLDocgetprice(url);
	    }
	}
	
	/*============Change Tips Status====by addison==========*/
	
	function change_TipsStatus(tipsid)
	{
		if(confirm("CONFIRM_CHANGE_STATUS"))
		 {
			 document.getElementById("ajaxtr").style.display="";
			 document.getElementById("message").style.display="none";
			 document.getElementById("ajaxdiv").style.display="block";
			 url="../ajax/process.php?process=changetipsstatus&tipsid="+tipsid;
			 loadXMLDocgetprice(url);
		}
	}
	
	function change_contractorstatus(cont_id)
	{
		if(confirm("CONFIRM_CHANGE_STATUS"))
		 {
			 document.getElementById("ajaxtr").style.display="";
			 document.getElementById("message").style.display="none";
			 document.getElementById("ajaxdiv").style.display="block";
			 url="../ajax/process.php?process=changecontractorstatus&cont_id="+cont_id;
			 loadXMLDocgetprice(url);
		}
	}
	
	function change_contractorapproval(cid)
	{
		if(confirm("CONFIRM_MSG_CONTRACTOR_APRROVAL_DISAPPROVAL"))
		 {
			 document.getElementById("ajaxtr").style.display="";
			 document.getElementById("message").style.display="none";
			 document.getElementById("ajaxdiv").style.display="block";
			 url="../ajax/process.php?process=contractorapproval&cid="+cid;
			 loadXMLDocgetprice(url);
		}	
	} 
	/*============Change Tips Status=========by addison=====*/
	
/*-----------------validation for change category status---------------------*/
function change_catstatus(catid)
{
	if(confirm("CONFIRM_CHANGE_STATUS"))
	 {
     document.getElementById("ajaxtr").style.display="";
     document.getElementById("message").style.display="none";
    document.getElementById("ajaxdiv").style.display="block";
	url="../ajax/process.php?process=changecategorystatus&catid="+catid;
	loadXMLDocgetprice(url);
	}
}
function sendmailtocontractor(quoteid)
{
if(confirm("CONFIRM_SEND_MAIL"))
 {
     document.getElementById("ajaxtr").style.display="";
     document.getElementById("message").style.display="none";
    document.getElementById("ajaxdiv").style.display="block";
	url="../ajax/process.php?process=sendmailtocontractor&quoteid="+quoteid;
	loadXMLDocgetprice(url);
	}

}
/*------------------validation for change page status-----------------*/
function change_pagestatus(linkid)
{
if(confirm("CONFIRM_CHANGE_STATUS"))
 {
 document.getElementById("ajaxtr").style.display="";
  document.getElementById("message").style.display="none";
    document.getElementById("ajaxdiv").style.display="block";
	url="../ajax/process.php?process=changepagetatus&linkid="+linkid;
	//alert(url);
	loadXMLDocgetprice(url);
	}
}

/*------------------------------------*/
function change_paytermstatus(tid)
{
if(confirm("CONFIRM_CHANGE_STATUS"))
 {
 document.getElementById("ajaxtr").style.display="";
  document.getElementById("message").style.display="none";
    document.getElementById("ajaxdiv").style.display="block";
	url="../ajax/process.php?process=change_paymentterm&termid="+tid;
	loadXMLDocgetprice(url);
	}
}
function change_notemailstatus(eid)
{
if(confirm("CONFIRM_CHANGE_STATUS"))
 {
 document.getElementById("ajaxtr").style.display="";
  document.getElementById("message").style.display="none";
    document.getElementById("ajaxdiv").style.display="block";
	url="../ajax/process.php?process=change_notemailsent&emailid="+eid;
	loadXMLDocgetprice(url);
	}
}
/*-------------confirm message for delete a songle record---------------------*/
function confirm_delete(msg)
{
  if (confirm (msg))
     {

      return true;

     }
     else
     {
      return false;
     }

}
/*--------------------------add & edit  category form  validation--------------------------------*/
function CheckMapCategoryForm()
{
	  if(document.frmcategorymap.state.value=="0")
	  {
		  alert("ALERT_MSG_STATE_NAME");
		  document.frmcategorymap.state.focus();
		  return false;
	  }
	  if(document.frmcategorymap.catname.value=="0")
	  {
		  alert("ALERT_MSG_CATEGORY_NAME");
		  document.frmcategorymap.catname.focus();
		  return false;
	  }
	   if(document.frmcategorymap.catname.value=="nocat")
	  {
		  alert("You have already to mapped all categories.");
		  document.frmcategorymap.catname.focus();
		  return false;
	  }
	  
	if(!ValidChars("abcdefghijklmnopqrstuvwxyz1234567890.-_& ",document.frmcategorymap.catname.value) || document.frmcategorymap.catname.value.indexOf(" ")==0)
  	{
		alert("Please enter a valid category name. It does not allow any special characters or first space character.");
		document.frmcategorymap.catname.focus();
		document.frmcategorymap.catname.select();
		return false;
  	}
	
	if(trim(document.frmcategorymap.Phone.value)!="")
	{
		 if(!isValidTelephone(document.frmcategorymap.Phone.value))
		  {
			document.frmcategorymap.Phone.focus();
			return false;
		  }
	}
	if(trim(document.frmcategorymap.fax.value)!="")
	{
		 if(!isValidFax(document.frmcategorymap.fax.value))
		  {
			document.frmcategorymap.fax.focus();
			return false;
		  }
	}
	if(trim(document.frmcategorymap.email.value)!='')
	{
		var subject=document.frmcategorymap.email.value;
		var myregexp = /^[A-Z0-9._%-]+@[A-Z0-9._%-]+\.[A-Z]{2,3}$/i;
		if (!subject.match(myregexp))
		{
			alert("ALERT_INVALID_EMAIL");
			document.frmcategorymap.email.focus();
			return false;
		}

		/*
		if(!(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(document.frmcategorymap.email.value)))
		{
			alert("ALERT_INVALID_EMAIL");
			document.frmcategorymap.email.focus();
			return false;
		}
		*/
	}	
	if(trim(document.frmcategorymap.website.value)!='')
	{
		if(isURL(document.frmcategorymap.website.value)==false)
		{
			alert("ALERT_MSG_WEBSITE");
			document.frmcategorymap.website.focus();
			return false;
			
		}
	}	
	
	return true;
}

function CheckCategoryForm()
{
	  if(trim(document.addcatfrm.catname.value)=="")
	  {
		  alert("ALERT_MSG_CATEGORY_NAME_TEXTBOX");
		  document.addcatfrm.catname.focus();
		  return false;
	  }
	if(!ValidChars("abcdefghijklmnopqrstuvwxyz1234567890.-_& ",document.addcatfrm.catname.value) || document.addcatfrm.catname.value.indexOf(" ")==0)
  	{
		alert("Please enter a valid category name. It does not allow any special characters or first space character.");
		document.addcatfrm.catname.focus();
		document.addcatfrm.catname.select();
		return false;
  	}
	
	if(trim(document.addcatfrm.Comment.value)=="")
	  {
		  alert("Please enter the description.");
		  document.addcatfrm.Comment.focus();
		  return false;
	  }
	  
	return true;
}

function CheckCategoryEditForm()
{
	  if(trim(document.addcatfrm.catname.value)=="")
	  {
		  alert("ALERT_MSG_CATEGORY_NAME_TEXTBOX");
		  document.addcatfrm.catname.focus();
		  return false;
	  }
	  if(!ValidChars("abcdefghijklmnopqrstuvwxyz1234567890.-_& ",document.addcatfrm.catname.value) || document.addcatfrm.catname.value.indexOf(" ")==0)
  	{
		alert("Please enter a valid category name. It does not allow any special characters or first space character.");
		document.addcatfrm.catname.focus();
		document.addcatfrm.catname.select();
		return false;
  	}
	
	  if(trim(document.addcatfrm.sub_catname.value)=="")
	  {
		  alert("ALERT_MSG_SUB_CATEGORY_NAME");
		  document.addcatfrm.sub_catname.focus();
		  return false;
	  }
	  
	  if(!ValidChars("abcdefghijklmnopqrstuvwxyz1234567890.-_& ",document.addcatfrm.sub_catname.value) || document.addcatfrm.sub_catname.value.indexOf(" ")==0)
  	{
		alert("Please enter a valid sub category name. It does not allow any special characters or first space character.");
		document.addcatfrm.sub_catname.focus();
		document.addcatfrm.sub_catname.select();
		return false;
  	}
	
	return true;
}


/*-----------------------annual fee form validation----------------------------*/

function val_updateannualfee()
{
  if(document.updateannualfee.annualfee.value=="")
  {
  alert("ALERT_MSG_ANNUALFEE_VALUE");
  document.updateannualfee.annualfee.focus();
  return false;
  }
  if(isNaN(document.updateannualfee.annualfee.value))
  {
  alert("ALERT_MSG_NUMERIC_VALUE");
  document.updateannualfee.annualfee.value="";
  return false;
  }
  else
  {
  return true;
  }
}

function val_editsubcatfrm(type)
{
  var type;
  if(document.addsubcatfrm.catname.value=="")
  {
  alert("ALERT_MSG_SUB_CATEGORY_NAME_SELECT");
  document.addsubcatfrm.catname.focus();
  return false;
  }
  if(document.addsubcatfrm.subcatname.value=="")
  {
    alert("ALERT_MSG_SUB_CATEGORY_NAME");
    document.addsubcatfrm.subcatname.focus();
    return false;
  }
  if(document.addsubcatfrm.disporder.value!="" && isNaN(document.addsubcatfrm.disporder.value))
  {
  alert("ALERT_MSG_NUMERIC_VALUE_DISP_ORDER");
  document.addsubcatfrm.disporder.value="";
  return false;
  }
  if(document.addsubcatfrm.catdescription.value=="")
  {
  alert("ALERT_MSG_SUBCAT_DESCRIPTION");
  document.addsubcatfrm.catdescription.focus();
  return false;
  }
  else
  {
  return true;
  }
}


/*---------------------------------show sub category------------------------------*/
function show_sub_category(id)
{
  var url = "show_sub_category.php?process=showsubcategory&catid="+id;
  document.location.href=url;

}
function add_sub_category(id,start)
{
  var url = "add_new_subcategory.php?catid="+id+"&start="+start;
  document.location.href=url;

}


function edit_sub_category(id,start,catid)
{
 
  var url = "edit_sub_category.php?id="+id+"&start="+start+"&catid="+catid;
  document.location.href=url;

}



 function show_subcatdiv(catid)
 {
	 if(document.getElementById("subcat_"+catid+"").style.display=="")
	 {
		 
		 document.getElementById("subcat_"+catid+"").style.display="none";
		 var objSub=eval("document.editfrmshop.subcategoryname");
		if(objSub.length==undefined)
			objSub.checked=false;	
		else
		{
			for(i=0;i<objSub.length;i++)
			{
				if(-1!=objSub[i].name.indexOf(catid))
					objSub[i].checked=false;
			}
		}		
		
    }
	else
	{
		document.getElementById("subcat_"+catid+"").style.display="";
	}
 }

function show_subcatdivAdd(catid)
 {
	 if(document.getElementById("subcat_"+catid+"").style.display=="")
	 {
		 
		 document.getElementById("subcat_"+catid+"").style.display="none";
		 var objSub=eval("document.addfrmshop.subcategoryname");
		if(objSub.length==undefined)
			objSub.checked=false;	
		else
		{
			for(i=0;i<objSub.length;i++)
			{
				if(-1!=objSub[i].name.indexOf(catid))
				objSub[i].checked=false;
			}
		}
    }
	else
	{
		document.getElementById("subcat_"+catid+"").style.display="";
	}
 }


