var xmlHttp
/************************/
// JavaScript Document
function trim1(str){ 
	return((""+str).replace(/^\s*([\s\S]*\S+)\s*$|^\s*$/,'$1') ); 
}
function trim(str){ 
	return((""+str).replace(/^\s*([\s\S]*\S+)\s*$|^\s*$/,'$1') ); 
}

function isNumber1(str){
//	var filter=/^[\d]+$/;
	var filter=/^[0-9]+$/;
	if(filter.test(trim(str)))
	return true;
	else
	return false
}

function isSpchar1(value){
  var iChars = "!@#$%^&*()+=-[]\';,./{}|\":<>?";

  for (var i = 0; i < value.length; i++) {
  	if (iChars.indexOf(value.charAt(i)) != -1) 
  	{
  		return true;
  	}
  }	
  return false;
}

function isNum1(value){
  var iChars = "0123456789";

  for (var i = 0; i < value.length; i++) {
  	if (iChars.indexOf(value.charAt(i)) != -1) 
  	{
  		return true;
  	}
  }	
  return false;
}

function isValidEmail1(value){
	var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i;
	if(filter.test(trim(value)))
		return true;
	else
		return false;
	
}

function toogleElement1(EleName,style){
	var objEle = document.getElementById(EleName);
	if(objEle)
		objEle.style.display=style;
}

function showNotification1(msg){
	showStatus1(msg,'statusMsg');
}
function showError1(msg){
	showStatus1(msg,'statusErr');
}

function showStatus1(msg,type){
	var ele = document.getElementById('msg');
	ele.innerHTML = msg;
	ele.className = type;
	toogleElement1('msg','block');
}

function showPNRError1(msg){
	showPNRStatus1(msg,'statusErr');
}

function showPNRStatus1(msg,type){
	
	var ele = document.getElementById('pnrmsg');
	ele.innerHTML = msg;
	ele.className = type;
	toogleElement1('pnrmsg','block');
}

function showPNRNotification1(msg){
	showPNRStatus1(msg,'statusMsg');
}

function hideStatus1(){
	toogleElement1('msg','none');
}

function changeError1(id){
	//document.getElementById(id).style.background="#FFCCCC";
	document.getElementById(id).style.borderStyle="solid";
	document.getElementById(id).style.borderColor="red";
	}
function changeProper1(id){
	//document.getElementById(id).style.background="#fff";
	document.getElementById(id).style.borderStyle="";
	document.getElementById(id).style.borderColor="";
	}

function showThanks1(formdiv){
	
	toogleElement1(formdiv,'none');
	toogleElement1('thanks','block');
}
function showform1(url){
	location=url;
}

function doDateCheck1(from, to) {
			var fromTemp = from;
			var fdd = fromTemp.slice(0,2);
			var fmm = fromTemp.slice(3,5);
			var fyy = fromTemp.slice(6,10);

			var toTemp = to;
			var tdd = toTemp.slice(0,2);
			var tmm = toTemp.slice(3,5);
			var tyy = toTemp.slice(6,10);
		
			var fromDate = new Date(fyy,fmm,fdd);
			var toDate = new Date(tyy,tmm,tdd);

		if (fromDate > toDate) {
			//alert("Return date should be greater than the Departure date.");
			return false;
		}
		else{
			return true;
		}
	}
/**********************************/
function submitBusHirePage(form,str1){ 


	var url=str1;


		var bustype = document.getElementById("busType").value;
		
		var category = document.getElementById("category").value;
	
		var datereturn= document.getElementById("returnDate").value;
	
		var pickuptime = document.getElementById("pickuptime").value;
		var pickuppoint = document.getElementById("pickuppoint").value;
	
		var coach;
		if( document.getElementById("acRadio").checked){
			 coach = document.getElementById("acRadio").value;
		}else{
			coach="Non AC";
		}
		
		var name = document.getElementById("name").value;
		var emailid = document.getElementById("emailid").value;
		var mobileNum= document.getElementById("mobileNum").value;
		var fromcity = document.getElementById("fromcity").value;
		var tocity = document.getElementById("tocity").value;
		var comments= document.getElementById("comments").value;
		var datejourny= document.getElementById("departDate").value;
	
		if(name==""){

			showError1("The Name cannot be left blank");
			document.getElementById("name").focus();
			changeError1('name');
			return false;
		}else if(isNum1(name)){
			//alert("name " + name);
			showError1("Numbers are not allowed in the Name");
			document.getElementById("name").focus();
			changeError1('name');
			return false;
		}
		else if(isSpchar1(name)){
			showError("Special characters not allowed in the Name");
			document.getElementById("name").focus();
			changeError1('name');
			return false;
		}
		else{
			changeProper1('name');
		}


		if(emailid==""){
			showError1("The Email Id cannot be left blank");
			document.getElementById("emailid").focus();
			//document.getElementById("emailid").style.background="#FFCCCC";
			changeError1('emailid');
			return false;
		}else {

			if(!isValidEmail1(emailid))
			{
				showError1("Invalid Email Address.");
				document.getElementById("emailid").focus();
				changeError1('emailid');
				return false;
			}else{
				changeProper1('emailid');
			}
		}

		if(mobileNum=="" || mobileNum.length != '10'){
			showError1("Mobile Number should be 10 digit");
			document.getElementById("mobileNum").focus();
			changeError1('mobileNum');
			return false;
		}else{
			changeProper1('mobileNum');
		}

		if(!isNumber1(mobileNum))
		{
			showError1("Please enter numbers only");
			document.getElementById("mobileNum").focus();
			changeError1('mobileNum');
			return false;
		}else{
			changeProper1('mobileNum');
		}
		if(fromcity==""){
			showError1("From city cannot be blank");
			document.getElementById("fromcity").focus();
			changeError1('fromcity')
			return false;
		}else if(isNum1(fromcity)){
			//alert("name " + name);
			showError1("Numbers are not allowed in the From city");
			document.getElementById("fromcity").focus();
			changeError1('fromcity');
			return false;
		}
		else{
			changeProper1('fromcity');
		}

		if(tocity==""){
			showError1("To city cannot be blank");
			document.getElementById("tocity").focus();
			changeError1('tocity');
			return false;
		}else if(isNum1(tocity)){
			//alert("name " + name);
			showError1("Numbers are not allowed in the To city field");
			document.getElementById("tocity").focus();
			changeError1('tocity');
			return false;
		}
		else{
			changeProper1('tocity');
		}
		
	if(datejourny=="" || datejourny=="dd-mm-yyyy"){
			showErro1r("Departure date cannot be blank");
			document.getElementById("departDate2").focus();
			// document.getElementById("departDate").value="";
			changeError1('departDate');
			return false;

		}
		else{
			
			changeProper1('departDate');
			
		}
	
		if( datereturn=="" || datereturn=="dd-mm-yyyy"){
			showError1("Return date cannot be blank");
			document.getElementById("returnDate").focus();
			//document.getElementById("returnDate").value="";
			changeError1('returnDate')
			return false;
		}else if( datereturn!=""){
			var fromTemp2 = datejourny.replace(/-/,"/");
			var from = fromTemp2.replace(/-/,"/");
			var toTemp2 = datereturn.replace(/-/,"/");
			var to = toTemp2.replace(/-/,"/");
			var check = doDateCheck1(from, to);
			if(!check){
				showError1("Return Date should be greater than or equal to Departure Date.");
				changeError1('returnDate');
				return false;
			}else {
				changeProper1('returnDate');
			}

		}

		if(comments==""){
			showError1("Please provide some comments");
			document.getElementById("comments").focus();
			changeError1('comments');
			return false;
		}else{
			changeProper1('comments');
		}
		url=url+"?name="+name;
		url=url+"&emailid="+emailid;
		url=url+"&mobile="+mobileNum;
		url=url+"&fromcity="+fromcity;
		url=url+"&tocity="+tocity;
		url=url+"&datejourny="+datejourny;
		url=url+"&comments="+comments;
		url=url+"&requestname="+form;
		url=url+"&coach="+coach;
		url=url+"&pickuptime="+pickuptime;
		url=url+"&pickuppoint="+pickuppoint;
		url=url+"&datereturn="+datereturn;
		url=url+"&category="+category;
		url=url+"&bustype="+bustype;
		
		
		xmlHttp=GetXmlHttpObject();
		if (xmlHttp==null)
		  {
		  alert ("Your browser does not support AJAX!");
		  return;
		  } 
		  
		

		xmlHttp.onreadystatechange=stateChanged;
		xmlHttp.open("GET",url,true);
		xmlHttp.send(null);
		toogleElement(form,'none');
		toogleElement('thanks','block');
}


function submitHirePage1(form,str1)
{ 


var url=str1;

	if(form=="car_form"){
		
		
			var name = document.getElementById("name").value;
			var emailid = document.getElementById("emailid").value;
			var mobileNum= document.getElementById("mobileNum").value;
			var fromcity = document.getElementById("fromcity").value;
			var tocity = document.getElementById("tocity").value;
			var depdate= document.getElementById("departDate").value;
			var returnDate= document.getElementById("returnDate").value;
			var comments= document.getElementById("comments").value;
			var buscategory= document.getElementById("buscategory").value;
			var carType= document.getElementById("carType").value;
			
			var pickuptime= document.getElementById("pickuptime").value;
			var pickuppoint= document.getElementById("pickuppoint").value;
			
			if(document.getElementById("acRadio1").checked){
				var acRadio = "AC";
			}else{
				var acRadio = "Non AC";
			}

			
			if(buscategory=="0"){
				
				showError1("The bus category cannot be left blank");
				document.getElementById("buscategory").focus();
				changeError1('buscategory')
				return false;
			}else{
					changeProper1('buscategory')
			}
			
			
			/*
			if(name==""){
				showError1("The Name cannot be left blank");
				document.getElementById("name").focus();
				changeError1('name')
				return false;
			}else{
				changeProper1('name')
			}
			*/
			
			if(name==""){
				
				showError1("The Name cannot be left blank");
				document.getElementById("name").focus();
				changeError1('name')
				return false;
			}else if(isNum1(name)){
					//alert("name " + name);
					showError1("Numbers are not allowed in the Name");
					document.getElementById("name").focus();
					changeError1('name')
					return false;
			}
			else if(isSpchar1(name)){
					showError("Special characters not allowed in the Name");
					document.getElementById("name").focus();
					changeError1('name')
					return false;
			}
			else{
				changeProper1('name')
			}
			
			
			if(emailid==""){
				showError1("The Email Id cannot be left blank");
				document.getElementById("emailid").focus();
				//document.getElementById("emailid").style.background="#FFCCCC";
				changeError1('emailid')
				return false;
			}else {
			
				if(!isValidEmail1(emailid))
				{
					showError1("Invalid Email Address.");
					document.getElementById("emailid").focus();
					changeError1('emailid')
					return false;
				}else{
					changeProper1('emailid')
				}
			}
			
			
			if(mobileNum=="" || mobileNum.length != '10'){
				showError1("Mobile Number should be 10 digit");
				document.getElementById("mobileNum").focus();
				changeError1('mobileNum')
				return false;
			}else{
				changeProper1('mobileNum')
			}
			
			if(!isNumber1(mobileNum))
			{
				showError1("Please enter numbers only");
				document.getElementById("mobileNum").focus();
				changeError1('mobileNum')
				return false;
			}else{
				changeProper1('mobileNum')
			}
			
			
			if(fromcity==""){
				showError1("From city cannot be blank");
				document.getElementById("fromcity").focus();
				changeError1('fromcity')
				return false;
			}else if(isNum1(fromcity)){
					//alert("name " + name);
					showError1("Numbers are not allowed in the From city");
					document.getElementById("fromcity").focus();
					changeError1('fromcity')
					return false;
			}
			else{
				changeProper1('fromcity')
			}
			
			if(tocity==""){
				showError1("To city cannot be blank");
				document.getElementById("tocity").focus();
				changeError1('tocity')
				return false;
			}else if(isNum1(tocity)){
					//alert("name " + name);
					showError1("Numbers are not allowed in the To city field");
					document.getElementById("tocity").focus();
					changeError1('tocity')
					return false;
			}
			else{
				changeProper1('tocity')
			}
			
			
			
			if(depdate=="" || depdate=="dd-mm-yyyy"){
				     showError1("The Departure Date cannot be blank");
					 document.getElementById("departDate").focus();
					 
					 changeError1('departDate')
				return false;
			}
			else{
				changeProper1('departDate')
			}
			
			if(carType=="0"){
					
					showError1("The car type cannot be left blank");
					document.getElementById("carType").focus();
					changeError1('carType')
					return false;
			}else{
					changeProper1('carType')
			}
		
			if(comments==""){
				showError1("Please provide some comments");
				document.getElementById("comments").focus();
				changeError1('comments')
				return false;
			}else{
				changeProper1('comments')
			}
			
			url=url+"?name="+name;
			url=url+"&emailid="+emailid;
			url=url+"&mobile="+mobileNum;
			url=url+"&fromcity="+fromcity;
			url=url+"&tocity="+tocity;
			url=url+"&depdate="+depdate;
			url=url+"&retdate="+returnDate;
			url=url+"&comments="+comments;
			url=url+"&requestname="+form;
			url=url+"&buscategory="+buscategory;
			url=url+"&carType="+carType;
			url=url+"&acRadio="+acRadio;
			url=url+"&pickuptime="+pickuptime;
			url=url+"&pickuppoint="+pickuppoint;	
	
	}else{
		
		var name = document.getElementById("name").value;
		var emailadd = document.getElementById("emailadd").value;
		var mobileNum = document.getElementById("mobileNum").value;
		var altNumber =""; 
		if(document.getElementById("altPhoneNo")!=null){
			altNumber = document.getElementById("altPhoneNo").value;
		}else{
			altNumber = "022";
		}
		
		var depdate = document.getElementById("departDate").value;
		var retdate = document.getElementById("returnDate").value;
		var tocity = document.getElementById("tocity").value;
		var area = "";
		if(document.getElementById("area")!=null){
			area=document.getElementById("area").value;
		}else{
			area="mum";
		}
		var comments = document.getElementById("comments").value;
		var noofadult = document.getElementById("adult").value;
		var noofchild = document.getElementById("child").value;
		var checkInTime ="";
		if(document.getElementById("checkInTime")!=null){
			checkInTime=document.getElementById("checkInTime").value;
		}else{
			checkInTime="10:00 AM";
		}
		var checkOutTime = "";
		if(document.getElementById("checkOutTime")!=null){
			checkOutTime=document.getElementById("checkOutTime").value;
		}else{
			checkOutTime="10:00 AM";
		}
		
		var rooms = "";
		if(document.getElementById("rooms")!=null){
			rooms=document.getElementById("rooms").value;
		}else{
			rooms="1";
		}
		
		var roomType = "";
		if(document.getElementById("roomType")!=null){
			roomType=document.getElementById("roomType").value;
		}else{
			roomType="Standard";
		}
		
		var roomPref = "";
		if(document.getElementById("roomPref")!=null){
			roomPref=document.getElementById("roomPref").value;
		}else{
			roomPref="AC";
		}
		
		
		if(name == "") {
		   showError1("The Name cannot be left blank");
		   document.getElementById("name").focus();
		   changeError1('name');
		   return false;
		   }
		if(isSpchar1(name)) {
		   showError("Special characters not allowed in the name");
		   document.getElementById("name").focus();
		   changeError1('name');
		   return false;
		   }
		else {
		   changeProper1('name')}
		if(emailadd == "") {
		   showError1("The Email Id cannot be left blank");
		   document.getElementById("emailadd").focus();
		   changeError1('emailadd');
		   return false;
		   }
		else {
		   changeProper1('emailadd');
		   }
		if(!isValidEmail1(emailadd)) {
		   showError1("Invalid Email address.");
		   document.getElementById("emailadd").focus();
		   changeError1('emailadd');
		   return false;
		   }
		else {
		   changeProper1('emailadd');
		   }
		if(mobileNum == "" || mobileNum.length != '10') {
		   showError1("Mobile Number should be 10 digit");
		   document.getElementById("mobileNum").focus();
		   changeError1('mobileNum');
		   return false;
		   }
		else {
		   changeProper1('mobileNum');
		   }
		if(!isNumber1(mobileNum)) {
		   showError1("Please Enter numbers only");
		   document.getElementById("mobileNum").focus();
		   changeError1('mobileNum');
		   return false;
		   }
		else {
		   changeProper1('mobileNum');
		   }
		if(!isNumber1(altNumber)) {
		   showError1("The Alternate Number should be a number and should not be empty");
		   document.getElementById("altPhoneNo").focus();
		   changeError1('altNumber');
		   return false;
		   }
		if(tocity == "") {
		   showError1("The City cannot be blank");
		   document.getElementById("tocity").focus();
		   changeError1('tocity');
		   return false;
		   }
		else if(isNum1(tocity)) {
		   //alert("name " + name);
		   showError1("Numbers are not allowed in the To city field");
		   document.getElementById("tocity").focus();
		   changeError1('tocity');
		   return false;
		   }
		else {
		   changeProper1('tocity');
		   }
		if(area=="") {
			   //alert("name ");
			   showError1("Area field should not be blank");
			   document.getElementById("area").focus();
			   changeError1('area');
			   return false;
			   }
		if(isNum1(area)) {
		   //alert("name ");
		   showError1("Numbers are not allowed in the area field");
		   document.getElementById("area").focus();
		   changeError1('area');
		   return false;
		   }
		if(depdate == "" || depdate == "dd-mm-yyyy") {
		   //alert(depdate);
		   showError1("CheckIn Date cannot be blank");
		   document.getElementById("departDate").focus();
		   // document.getElementById("departDate").value="";
		   changeError1('departDate');
		   return false;
		   }
		else {
		   changeProper1('departDate');
		   }
		if(retdate == "" || retdate == "dd-mm-yyyy") {
		   showError1("CheckOut Date cannot be blank");
		   document.getElementById("returnDate").focus();
		   // document.getElementById("returnDate").value="";
		   changeError1('returnDate');
		   return false;
		   }
		else if(retdate != "") {
		   var fromTemp2 = depdate.replace(/-/,"/");
		   var from = fromTemp2.replace(/-/,"/");
		   var toTemp2 = retdate.replace(/-/,"/");
		   var to = toTemp2.replace(/-/,"/");
		   var check = doDateCheck1(from, to);
		   if(!check) {
		      showError1("CheckOut Date should be greater than or equal to CheckIn date.");
		      changeError1('returnDate');
		      return false;
		      }
		   else {
		      changeProper1('returnDate');
		      }
		   }
		if(checkInTime == "Select") {
		   showError1("The check in time must be selected");
		   document.getElementById("checkInTime").focus();
		   changeError1('checkInTime');
		   return false;
		   }
		if(checkOutTime == "Select") {
		   showError1("The check out time must be selected");
		   document.getElementById("checkOutTime").focus();
		   changeError1('checkOutTime');
		   return false;
		   }
		if(roomPref!= "AC" && roomPref != "NON-AC") {
			   showError1("The room preference must be selected");
			   document.getElementById("roomPref").focus();
			   changeError1('roomPref');
			   return false;
			   }
		if(rooms == "Select") {
		   showError1("The no of rooms must be selected");
		   document.getElementById("rooms").focus();
		   changeError1('rooms');
		   return false;
		   }
		if(roomType == "Select") {
		   showError1("The type of room must be selected");
		   document.getElementById("roomType").focus();
		   changeError1('roomType');
		   return false;
		   }
		if(noofadult == "Select") {
		   showError1("The number of adults must be selected");
		   document.getElementById("adult").focus();
		   changeError1('adult');
		   return false;
		   }
		if(isNum1(name)) {
		   //alert("name " + name);
		   showError1("Numbers are not allowed in the name");
		   document.getElementById("name").focus();
		   changeError1('name');
		   return false;
		   }
		if(comments == "") {
		   showError1("Please provide some comments");
		   document.getElementById("comments").focus();
		   changeError1('comments');
		   return false;
		   }
		else {
		   changeProper1('comments');
		   }
		url = url + "?name=" + name;
		url = url + "&emailid=" + emailadd;
		url = url + "&mobile=" + mobileNum;
		url = url + "&depdate=" + depdate;
		url = url + "&retdate=" + retdate;
		url = url + "&city=" + tocity;
		url = url + "&comments=" + comments;
		url = url + "&requestname=" + form;
		url = url + "&noofadult=" + noofadult;
		url = url + "&altNumber=" + altNumber;
		url = url + "&area=" + area;
		url = url + "&adult=" + noofadult;
		url = url + "&noofchild=" + noofchild;
		url = url + "&checkInTime=" + checkInTime;
		url = url + "&checkOutTime=" + checkOutTime;
		url = url + "&rooms=" + rooms;
		url = url + "&roomType=" + roomType;
		url = url + "&roomPref=" + roomPref.value; 
		
		
	}
	
	

	
	
xmlHttp=GetXmlHttpObject();
if (xmlHttp==null)
  {
  alert ("Your browser does not support AJAX!");
  return;
  } 
  


xmlHttp.onreadystatechange=stateChanged;
xmlHttp.open("GET",url,true);
xmlHttp.send(null);
toogleElement(form,'none');
toogleElement('thanks','block');
}//end of function

function stateChanged() 
{ 

	if (xmlHttp.readyState==1){
	document.getElementById("thanks").innerHTML="Loading...";
	}else if (xmlHttp.readyState==2){
	document.getElementById("thanks").innerHTML="Loading...";
	}else if (xmlHttp.readyState==3){
	document.getElementById("thanks").innerHTML="Loading...";
	}else if (xmlHttp.readyState==4){
	document.getElementById("thanks").innerHTML=xmlHttp.responseText;
	}
}

function GetXmlHttpObject()
{
var xmlHttp=null;
try
  {
  // Firefox, Opera 8.0+, Safari
  xmlHttp=new XMLHttpRequest();
  }
catch (e)
  {
  // Internet Explorer
  try
    {
    xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
    }
  catch (e)
    {
    xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
    }
  }
return xmlHttp;
} 

