
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;
	}
}


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 chkQueryForm(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;
		}
		else if(!isNaN(objForm.your_name.value))
		{
			theMessage+= "\nPlease enter Name Correctly";
			focusval = objForm.your_name;

		}
	
	}

if(objForm.selCountry)
	{
		//alert(objForm.selCountry.value);
		if(objForm.selCountry.value=='')
		{

			theMessage+= "\nPlease enter Your country of residence";
			focusval = objForm.selCountry;
		}
	
	}


	
	if(objForm.txiPhone)
	{
		var phone1=objForm.txiPhone.value;
		var phone2=phone1.split('-');
		var phone=phone2[1];
		

		if(phone1.value!='')
		{

			if(phone=='')
			{
				theMessage+= "\nPlease enter phone number";
					focusval = objForm.txiPhone;
			}

		else if(isNaN(phone))
			{
				theMessage+= "\nPlease enter numeric value for phone";
				focusval = objForm.txiPhone;

			}

		}

		
		else
		{
			theMessage+= "\nPlease enter phone number";
				focusval = objForm.txiPhone;

		}
		 
	
	}

if(objForm.txiPhone1)
	{
		var phone1=objForm.txiPhone1.value;
		
		if(phone1=='')
			{
				theMessage+= "\nPlease enter phone number";
					focusval = objForm.txiPhone1;
			}

		else
		{
	      if(isNaN(phone1))
			{
				theMessage+= "\nPlease enter numeric value for phone";
				focusval = objForm.txiPhone1;

			}

		}

		
			
	}


	if(objForm.your_email)
	{
		if (trimAll(objForm.your_email.value).length<=0) 
		{
			theMessage+="\nPlease 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.dapart_date)
	{

		if(objForm.dapart_date.value=='')
		{
			 
				theMessage+= "\nPlease enter daparture date";
				focusval = objForm.dapart_date;

			

		}
		 
	
	}



	



if(objForm.adult)
	{
		if(objForm.adult.value=='')
		{
			theMessage+= "\nPlease enter the number of Adults";
			focusval = objForm.adult;
		}
		else if(isNaN(objForm.adult.value))
			{
				theMessage+= "\nPlease numeric value for Adults";
				focusval = objForm.adult;

			}
	
	}
	
if(objForm.txaQuery)
	{
		
		if(objForm.txaQuery.value=='')
		{

			theMessage+= "\nPlease enter Your Query";
			focusval = objForm.txaQuery;
		}
	
	}	

if(objForm.child)
	{
		if(objForm.child.value=='')
		{
			theMessage+= "\nPlease enter the number of child";
			focusval = objForm.child;
		}
		else if(isNaN(objForm.child.value))
			{
				theMessage+= "\nPlease numeric value for child";
				focusval = objForm.child;

			}
	
	}
	
	
	
	
	

	///////////////////date validation





	/*if(objForm.other.checked==true && objForm.other_option.value=='NA')
	{
		theMessage+="\nPlease provide the other tours option !";
		focusval = objForm.other_option;
	}
*/

	if (theMessage == noErrors)
	{
		return true;
	} 
	else
	{
		alert(theMessage);
		focusval.focus();

		return false;
	}


}


////////////////////check date function

function checkdates(dValD1, dValD2, dValM1, dValM2, dValY1, dValY2)
{
	var tempM1=dValM1-1;
	var tempM2=dValM2-1;
	var tempD1=dValD1;
	var tempD2=dValD2;
	var tempY1=dValY1;
	var tempY2=dValY2;
	var increments=30;

	// 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());
	

	var christmas2=new Date(tempY2,tempM2,tempD2); 
	var christmas1=new Date(tempY1,tempM1,tempD1);
	//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 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= '\nCheck In Date date should be greater than today';
		//alert("Incorrect dates...Date should be greater then today");
		//return msg;
	}

	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.
*/
function validateFileExtensionPhoto(fld) 
{
	if(!/(\.bmp|\.gif|\.jpg|\.jpeg)$/i.test(fld.value)) // only these extension allowed
	{
		alert("Invalid image file type.");
		fld.value='';
		fld.focus();
		return false;
	}
	else
	{		
		return true;
	}

}// end of function


