
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 validate_req_form(objForm)
{
	var theMessage = "You entered incorrectly or forgot to fill in ::\n";
	var noErrors = theMessage;
	var focusval = objForm.name;
	
	
	
	if(objForm.qualification)
	{
		if(objForm.qualification.value=='')
		{
			theMessage+= "\nPlease enter Current Qualification";
			focusval = objForm.name;
		}
		else if(!isNaN(objForm.qualification.value))
		{
			theMessage+= "\nPlease enter Current Qualification Correctly";
			focusval = objForm.name;

		}
	
	}

	if(objForm.fname)
	{
		if(objForm.fname.value=='')
		{
			theMessage+= "\nPlease enter First Name";
			focusval = objForm.fname;
		}
		else if(!isNaN(objForm.fname.value))
		{
			theMessage+= "\nPlease enter First Name Correctly";
			focusval = objForm.fname;

		}
	
	}



	if(objForm.lname)
	{
		if(objForm.lname.value=='')
		{
			theMessage+= "\nPlease enter Last Name";
			focusval = objForm.lname;
		}
		else if(!isNaN(objForm.lname.value))
		{
			theMessage+= "\nPlease enter Last Name Correctly";
			focusval = objForm.lname;

		}
	
	}

if(objForm.email_id)
	{
		if (trimAll(objForm.email_id.value).length<=0) 
		{
			theMessage+="\nPlesae enter your email" ;
			focusval = objForm.email_id;
		} else if (!isValidEmail(trimAll(objForm.email_id.value)))
		{	
			theMessage+= "\nplesae enter valid email id" ;
			focusval = objForm.email_id;
		}
	}



		
if(objForm.address)
	{

		if(objForm.address.value=='')
		{
			theMessage+= "\nPlease enter Address.";
			focusval = objForm.address;
		}

	}

	if(objForm.city)
	{

		if(objForm.city.value=='')
		{
			theMessage+= "\nPlease enter City.";
			focusval = objForm.city;
		}

	}

	if(objForm.state)
	{

		if(objForm.state.value=='')
		{
			theMessage+= "\nPlease enter State.";
			focusval = objForm.state;
		}

	}

	if(objForm.Country)
	{

		if(objForm.Country.value=='')
		{
			theMessage+= "\nPlease Enter Your Country.";
			focusval = objForm.Country;
		}

	}

	if(objForm.phone)
	{

		if(objForm.phone.value=='')
		{
			theMessage+= "\nPlease enter phone.";
			focusval = objForm.phone;
		}
		else if(isNaN(objForm.phone.value))
		{
			theMessage+= "\nPlease enter Numeric value for phone";
			focusval = objForm.phone;

		}


	}


	

	if (theMessage == noErrors)
	{
		return true;
	} 
	else
	{
		alert(theMessage);
		focusval.focus();

		return false;
	}

}




/////////////////////////


function validate_form(objForm)
{
	var theMessage = "You entered incorrectly or forgot to fill in ::\n";
	var noErrors = theMessage;
	var focusval = objForm.name;
	
	
	
	if(objForm.name)
	{
		if(objForm.name.value=='')
		{
			theMessage+= "\nPlease enter Name";
			focusval = objForm.name;
		}
		else if(!isNaN(objForm.name.value))
		{
			theMessage+= "\nPlease enter Name Correctly";
			focusval = objForm.name;

		}
	
	}
		
if(objForm.roll_no)
	{

		if(objForm.roll_no.value=='')
		{
			theMessage+= "\nPlease enter Roll No.";
			focusval = objForm.roll_no;
		}

	}

	if(objForm.exam_apeared)
	{

		if(objForm.exam_apeared.value=='')
		{
			theMessage+= "\nPlease enter exam apeared for.";
			focusval = objForm.exam_apeared;
		}

	}

	if(objForm.exam_year)
	{

		if(objForm.exam_year.value=='')
		{
			theMessage+= "\nPlease enter Exam Year.";
			focusval = objForm.exam_year;
		}

	}

if(objForm.email_id)
	{
		if (trimAll(objForm.email_id.value).length<=0) 
		{
			theMessage+="\nPlesae enter your email" ;
			focusval = objForm.email_id;
		} else if (!isValidEmail(trimAll(objForm.email_id.value)))
		{	
			theMessage+= "\nplesae enter valid email id" ;
			focusval = objForm.email_id;
		}
	}

	

	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;
		}
	
	}

	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;
		}
	}
	
	
	if(objForm.selCountry)
	{
		//alert(objForm.selCountry.value);
		if(objForm.selCountry.value=='')
		{

			theMessage+= "\nPlease enter Your country of residence";
			focusval = objForm.selCountry;
		}
	
	}

	if(objForm.selAge)
	{
		if (trimAll(objForm.selAge.value) != "")
		{
			if(isNaN(objForm.selAge.value))
			{
				theMessage +="\nPlease enter patient's Age in digits." ;
				focusval	= objForm.selAge;
			}
			
		}
		else
		{
			theMessage +="\nPlease enter patient's Age ." ;
			focusval	= objForm.selAge;
		}
	}



	if(objForm.hUnit)
	{
		if(objForm.hUnit.value=='feet-inches' && (isNaN(objForm.feet.value) || isNaN(objForm.inches.value)))
		{
			theMessage+= "\nPlease enter Height in feet and inches Properly";
			focusval = objForm.feet;
		}
		else if(objForm.hUnit.value=='centimeters' && isNaN(objForm.cms.value))
		{
			theMessage+= "\nPlease enter Height in centimeters Properly";
			focusval = objForm.cms;
		}
	
	}




	if(objForm.selweight)
	{

		if(objForm.selweight.value!='')
		{

			if(isNaN(objForm.selweight.value))
			{
				theMessage +="\nPlease enter patient's Weight in digits." ;
				focusval	= objForm.selAge;
			}
			
		}
		else
			{
			theMessage+= "\nPlease enter patient's Weight";
			focusval = objForm.selweight;
			}
	
	}


	
	
	if(objForm.med_treatment)
	{
		if(objForm.med_treatment.value=='')
		{
			theMessage+= "\nPlease select Medical Treatment";
			focusval = objForm.med_treatment;
		}
	
	}

	if(objForm.hos_room)
	{
		if(objForm.hos_room.value=='')
		{
			theMessage+= "\nPlease select Type of Hospital Room";
			focusval = objForm.hos_room;
		}
	
	}

if(objForm.txaQuery)
	{
		if(objForm.txaQuery.value=='')
		{
			theMessage+= "\nPlease Provide Medical Treatment related information";
			focusval = objForm.txaQuery;
		}
	
	}
	///////////////////date validation



var pickDate1=trimAll(medicalform.selTentDate.value);
var pickDate= pickDate1.split("-");
var dValY1 =pickDate['0'];
var dValM1 = pickDate['1'];
var dValD1 = pickDate['2'];

var dropDate1=trimAll(medicalform.selTentDate1.value);
var dropDate= dropDate1.split("-");
var dValY2 =dropDate['0'];
var dValM2 = dropDate['1'];
var dValD2 = dropDate['2'];

var Message=checkdates(dValD1, dValD2, dValM1, dValM2, dValY1, dValY2);
	if(Message)
		{
			theMessage+= Message;
			focusval = objForm.selTentDate;
			if(focusval == '')
		{	
			focusval = objForm.selTentDate;
			//return false;
		}	
			
		}
	

	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
