
function isValidEmail(sFieldValue)
{
	var REmail=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i;

	var str=sFieldValue;
	if(!str.match(REmail)){
		return false;
	}
	else
	{
		return true;
	}
}

function checkField(fldObj, strtext, iMess)
{
	if(iMess != 0 )
	{
		iMess = 1;
	}
	if (trim(fldObj.value) == "") 
	{
		if(iMess == 1)
		{
			fldObj.focus();
			alert (strtext);
		}
		return false;
	}
	
	return true;
}


function checkfornum(str1) 
{
	//This function checks for numeric values
	var numstr="1234567890 ,";
	var intctr,intLen;
	intLen=str1.length;
	for(intCtr=0;intCtr <= intLen && numstr.indexOf(str1.charAt(intCtr))>=0 ;intCtr++);
	if(intCtr > intLen)
	{
		return 1;
	}
	else
	{
		return 0;
	}

}



//////////////
function checkforchar(strdate)
{
	//This function checks for string values
	var validdate = "abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ";
	var strlength = strdate.length;
	for(var i=0; i<=strlength; i++)
	{
		var unitstr = strdate.substr(i,1);
		if (validdate.indexOf(unitstr)==-1)
		{
			return false;
		}
	}
	return true;
}




///////////////////
function trim(str1)
{
	// This function trims any given field value for blank spaces.
	var intCtr=0
	for(intCtr=0;str1.charAt(intCtr)==" ";intCtr++);
	str1=str1.substring(intCtr,str1.length);
	return str1; 
}



function refreshParent()
{
	window.opener.location.href = window.opener.location.href;
	window.opener.location.reload(true);
	if (window.opener.progressWindow)
	{
		window.opener.progressWindow.close();
	}
}


function notyping(obj)  // function to restrict typing in image browing field
{
	
	if(event.keyCode != 32)
	{
		alert("You can not write in file name directly.\n Please click on Browse");
		obj.blur();
		return false;
	}
	else
	{
		return true;
	}
}


var message="Sorry, that function is disabled.\n\nContents & Graphics Copyright ©Compare Infobase Ltd.\nOur work is not Public Domain, and should NOT be taken from this site."; // Message for the alert box

// Don't edit below!
function click(e) 
{
	if (document.all) 
	{
		if (event.button == 2) 
		{
			alert(message);
			return false;
		}
	}
	if (document.layers) 
	{
		if (e.which == 3) 
		{
			alert(message);
			return false;
		}
	}
}

if (document.layers) 
{
	document.captureEvents(Event.MOUSEDOWN);
}

//document.onmousedown=click;

//////////function for maxlength in textarea
function ismaxlength(obj)
{
	var mlength=obj.getAttribute? parseInt(obj.getAttribute("maxlength")) : "";

	if (obj.getAttribute && obj.value.length > mlength)
	{
		obj.value = obj.value.substring(0, (mlength-1));
		alert("The maximum character limit (3000 characters) has been crossed .");
		return false;
	}
	else
	{
		return true;
	}
}


/**************************** CHANGES DONE ON 9 OCT 2007 BY ALKA *******************/

/** This function is used in sorting the form according to a field name with particuler order 
 *	sBy is sort by, i.e. whether in ascending or descending
 *	sOrder is sort order, means on which table fields sorting is done
 */
function sort_result(frmName, sBy, sOrder)
{
	var form			= frmName;
	form.sortBy.value	= sBy;	
	form.sortOrder.value= sOrder;
	form.submit();
	return true;

}/// end of function


/** This function goPage() starts
 * It is responsible for specifying limitstart in paging of records while navigating through records 
 */

function goPage(frmName, iPage)
{
	//alert(document.forms[frmName].task_action.value);

	document.forms[frmName].limitstart.value = iPage;
	document.forms[frmName].submit();
	return true;

}//end of function goPage()
//function to trim the given string
function trimAll(str){
	var l=0;
	var r=str.length;
	while((ch=str.charAt(l++)) == ' ');
	while((ch=str.charAt(--r)) == ' ');
	return(0>r)?"":str.substring(l-1,r+1);
}

function chkTypeSearchEngine(objForm)
{
	var theMessage = "You entered incorrectly or forgot to fill in ::\n";
	var noErrors = theMessage;
	var focusval = objForm.destination_type;
	
	
	
	if(objForm.destination_type)
	{
		if(objForm.destination_type.value=='')
		{
			theMessage+= "\nPlease select destination type";
			focusval = objForm.destination_type;
		}
	
	}
		
	if(objForm.destination_drop)
	{
		if(objForm.destination_drop.value=='')
		{
			theMessage+= "\nPlease select destination";
			focusval = objForm.destination_drop;
		}
	
	}
	
	if (theMessage == noErrors)
	{
		return true;
	} 
	else
	{
		alert(theMessage);
		focusval.focus();

		return false;
	}

}




function chkStateSearchEngine(objForm)
{
	var theMessage = "You entered incorrectly or forgot to fill in ::\n";
	var noErrors = theMessage;
	var focusval = objForm.state_name;
	
	
	
	if(objForm.state_name)
	{
		if(objForm.state_name.value=='')
		{
			theMessage+= "\nPlease select state";
			focusval = objForm.state_name;
		}
	
	}
		
	if(objForm.destination_state)
	{
		if(objForm.destination_state.value=='')
		{
			theMessage+= "\nPlease select destination";
			focusval = objForm.destination_state;
		}
	
	}
	

	if (theMessage == noErrors)
	{
		return true;
	} 
	else
	{
		alert(theMessage);
		focusval.focus();

		return false;
	}

}


function chkDestSearchEngine(objForm)
{
	var theMessage = "You entered incorrectly or forgot to fill in ::\n";
	var noErrors = theMessage;
	var focusval = objForm.destination_combo;
	
	
	
	if(objForm.destination_combo)
	{
		if(objForm.destination_combo.value=='')
		{
			theMessage+= "\nPlease select destination";
			focusval = objForm.destination_combo;
		}
	
	}
	
	
	if (theMessage == noErrors)
	{
		return true;
	} 
	else
	{
		alert(theMessage);
		focusval.focus();

		return false;
	}
}

function chkTourForm(objForm)
{
	
	var theMessage	= "You entered incorrectly or forgot to fill in ::\n";
	var noErrors	= theMessage;
	var focusval	= objForm.user_name;
	var dt			= new Date();
	
	if(objForm.your_name)
	{
		if(objForm.your_name.value=='')
		{
			theMessage+= "\nPlease enter Name";
			focusval = objForm.your_name;
		}
	
	}

	if(objForm.your_email)
	{
		if (trimAll(objForm.your_email.value).length<=0) 
		{
			theMessage+="\nPlesae enter your email" ;
			focusval = objForm.your_email;
		} else if (!isValidEmail(trimAll(objForm.your_email.value)))
		{	
			theMessage+= "\nplesae enter valid email id" ;
			focusval = objForm.your_email;
		}
		else if(trimAll(objForm.your_email.value)!=trimAll(objForm.your_remail.value))
		{
			theMessage+="\nThe verification email you entered did not match." ;
			focusval = objForm.your_remail;
		}
	}
	
	
	if(objForm.selCountry)
	{
		//alert(objForm.selCountry.value);
		if(objForm.selCountry.value=='')
		{

			theMessage+= "\nPlease enter Your country of residence";
			focusval = objForm.selCountry;
		}
	
	}

	if(objForm.txiCountryCode)
	{
		var CountryCode=objForm.txiCountryCode.value;
		if(CountryCode =='')
		{
			theMessage+= "\nPlease Provide Country Code";
			focusval = objForm.txiCountryCode;
		}
		else if(isNaN(CountryCode))
		{
			theMessage+= "\nPlease Provide numeric value for Country Code";
			focusval = objForm.txiCountryCode;
		}
	
	}

	if(objForm.txiCityCode)
	{
		var cityCode=objForm.txiCityCode.value;
		if(cityCode =='')
		{
			theMessage+= "\nPlease Provide Area Code";
			focusval = objForm.txiCityCode;
		}
		else if(isNaN(cityCode))
		{
			theMessage+= "\nPlease Provide numeric value for Area Code";
			focusval = objForm.txiCityCode;
		}
	
	}


	if(objForm.txiPhone)
	{
		var phone=objForm.txiPhone.value;
		if(phone =='')
		{
			theMessage+= "\nPlease Provide Phone Number";
			focusval = objForm.txiPhone;
		}
		else if(isNaN(phone))
		{
			theMessage+= "\nPlease Provide numeric value for Phone Number";
			focusval = objForm.txiPhone;
		}
	
	}


if(objForm.mobile)
	{
		var mobile=objForm.mobile.value;
		if(mobile !='' && isNaN(mobile))
		{
			theMessage+= "\nPlease Provide Proper Mobile Number";
			focusval = objForm.mobile;
		}
		
	
	}

	///////////////////date validation
if(objForm.selTentArrDate)
	{
	 if(tourform.selTentArrDate.value == '')
	 {
	   theMessage+= "\nPlease Provide Tentative Arrival Date";
	   focusval = objForm.selTentArrDate;
	 }
var pickDate2=trimAll(tourform.selTentArrDate.value);
var pickDateDep= pickDate2.split("-");
var dValY2 =pickDateDep['0'];
var dValM2 = pickDateDep['1'];
var dValD2 = pickDateDep['2'];



var Message=checkdates(dValY2, dValM2, dValD2);
	if(Message)
		{
			theMessage+= Message;
			focusval = objForm.selTentArrDate;
			if(focusval == '')
		{	
			focusval = objForm.selTentArrDate;
			//return false;
		}	
			
		}
	}

if(objForm.selTentDate)
	{
	 if(tourform.selTentDate.value == '')
	 {
	   theMessage+= "\nPlease Provide Tentative Date";
	   focusval = objForm.selTentDate;
	 }
var pickDate1=trimAll(tourform.selTentDate.value);
var pickDate= pickDate1.split("-");
var dValY1 =pickDate['0'];
var dValM1 = pickDate['1'];
var dValD1 = pickDate['2'];



var Message=checkdates(dValY1, dValM1, dValD1);
	if(Message)
		{
			theMessage+= Message;
			focusval = objForm.selTentDate;
			if(focusval == '')
		{	
			focusval = objForm.selTentDate;
			//return false;
		}	
			
		}
	}

if(pickDate1 < pickDate2)
	 {
	   theMessage+= "\nPlease Check Tentative Arrival Date is more than Tentative Departure Date";
	   focusval = objForm.selTentDate;
	 }

if(objForm.txaQuery)
	{
		if((objForm.txaQuery.value!='') && (objForm.txaQuery.value.length < 6))
		{
			theMessage+= "\nPlease Provide Additional Requirements in detail";
			focusval = objForm.txaQuery;
		}
	
	}
	

	if (theMessage == noErrors)
	{
		return true;
	} 
	else
	{
		alert(theMessage);
		focusval.focus();

		return false;
	}


}


////////////////////check date function

function checkdates(dValY1, dValM1,dValD1)
{
	
	
	var tempM1=dValM1-1;
	//var tempM2=dValM2-1;
	var tempD1=dValD1;
	//var tempD2=dValD2;
	var tempY1=dValY1;
	//var tempY2=dValY2;
	var increments=30;
//alert(tempY1=dValY1+"-"+tempM1+"-"+tempD1);return false;
	// validating dates
	
	//if(!validate(tempM1,tempD1,tempY1)){
		//document.form1.month1.focus();
	//	return false;
	//}

//	if(!validate(tempM2,tempD2,tempY2)){
		//document.form1.month2.focus();
	//	return false;
	//}

	//Set the two dates
	today=new Date();
	//var christmas=new Date(today.getFullYear(), 11, 25) 
	
	var today_time=(today.getTime());
	
//alert(today_time);
	//var christmas2=new Date(tempY2,tempM2,tempD2); 
	var christmas1=new Date(tempY1,tempM1,tempD1);
//alert(christmas1);
	//Month is 0-11 in JavaScript
	//Set 1 day in milliseconds
	var one_day=1000*60*60*24
		
	//Calculate difference btw the two dates, and convert to days
	var today_diffrence;
	//diffrence=(Math.ceil((christmas2.getTime()-christmas1.getTime())/(one_day)))+1;

    today_diffrence=(Math.ceil((christmas1.getTime()-today_time)/(one_day)));
	
	//alert(today_diffrence);
	//checking is dates are nagetive?
	if (today_diffrence < 0){
		var msg= '\nTentative Date date should be earlier than today';
		//alert("Incorrect dates...Date should be greater then today");
		return msg;
	}
/*	else if(tempY1 == '')
	{
		var msg= '\nPlease Provide Tentative Date';
	}

	if (diffrence<=0){
		var msg='\nCheck Out Date should be greater than Check In Date';
		//alert("Incorrect dates...Second date should be greater");
		//return msg;
	}
	*/
return msg;
	
}

/*	This function to check for input type image extensions.
	If extension is  not defined type then it show the alert message.
*/


