

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 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.user_name)
	{
		if(objForm.user_name.value=='')
		{
			theMessage+= "\nPlease enter Name";
			focusval = objForm.user_name;
		}
	
	}

	if(objForm.cidate)
	{
		var val = objForm.cidate.value;
		
		fld = val;
		fmt = 'w';
		rng	='f';
		if(!validateDate(fld,fmt,rng))
		{
			theMessage += "\n Enter a valid date.";
		}
	}
	
	if(objForm.user_email)
	{
		if (trimAll(objForm.user_email.value).length<=0) 
		{
			theMessage+="\nPlesae enter your email" ;
			focusval = objForm.user_email;
		} else if (!isValidEmail(trimAll(objForm.user_email.value)))
		{	
			theMessage+= "\nplesae enter valid email id" ;
			focusval = objForm.user_email;
		}
	}
	
	if(objForm.user_mobile)
	{
		if (trimAll(objForm.user_mobile.value) != "")
		{
			if(isNaN(objForm.user_mobile.value))
			{
				theMessage +="\n Please enter mobile number in digits." ;
				focusval	= objForm.user_mobile;
			}
		}
	}

	if(objForm.nights)
	{
		if(objForm.nights.value=='')
		{
			theMessage+= "\nPlease enter nights";
			focusval = objForm.nights;
		}
	
	}

	if(objForm.days)
	{
		if(objForm.days.value=='')
		{
			theMessage+= "\nPlease enter days";
			focusval = objForm.days;
		}
	
	}


	
	
	if(objForm.pacakge_id)
	{
		if(objForm.pacakge_id.value=='')
		{
			theMessage+= "\nPlease select package";
			focusval = objForm.pacakge_id;
		}
	
	}

	if(objForm.double_room)
	{
		if(trim(objForm.double_room.value) == '' && (objForm.single_room.value) == '')
		{
			theMessage+= "\nPlease select double rooms";
			focusval = objForm.double_room;
		}
		else
		{
			if(objForm.double_room.value=='')
			{
				theMessage+= "\nPlease select double rooms";
				focusval = objForm.double_room;
			}
			else if(objForm.single_room.value=='')
			{
				theMessage+= "\nPlease selct single rooms";
				focusval = objForm.single_room;
			}
		}
	
	}

	
	if(objForm.check_complete)
	{
		if(objForm.check_complete.checked==false)
		{
			theMessage+= "\nPlease check the checkbox ";
			focusval = objForm.single_room;
		}
	
	}

	if(objForm.verif_box)    //check if image verification left empty
	{
		if (trim(objForm.verif_box.value).length<=0)
		{
			theMessage+="\nImage verification code is missing!";
			focusval = objForm.verif_box;
		}
		else if (isNaN(objForm.verif_box.value))
		{
			theMessage+="\nEnter a numeric value in verification box!";
			focusval = objForm.verif_box;
		}
		else if ((trim(objForm.verif_box.value).length>4 ) || (trim(objForm.verif_box.value).length<4 ))
		{
			theMessage+="\nEnter only four digits as seen in image!";
			focusval = objForm.verif_box;
		}
	}


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

		return false;
	}


}

/*	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
