//***********************************************************************************************************************
//	Trim Function
//***********************************************************************************************************************
function Trim(strVal){
    var strMatch = strVal.match(/^\s*(\S+(\s+\S+)*)\s*$/);
    result = (strMatch == null) ? "" : strMatch[1];
    return result;
}
//***********************************************************************************************************************

//***********************************************************************************************************************
//	Email Validation Function
//***********************************************************************************************************************
function isEmail(objObject){
	var regEmail, strValue;	
	regEmail = /^[a-zA-Z][\w\.-]*[a-zA-Z0-9]@[a-zA-Z0-9][\w\.-]*[a-zA-Z0-9]\.[a-zA-Z][a-zA-Z\.]*[a-zA-Z]$/;
	strValue = objObject.value;
	if (objObject.value == "") return true;
	if(! regEmail.test(strValue)){		
		return false;
	}
	return true;
}
//***********************************************************************************************************************

//***********************************************************************************************************************
//	Numeric Value Validation Function
//***********************************************************************************************************************
function isNumeric(objObject){
	var regNumeric, strValue;	
	regNumeric = /[0-9]+/g;
	strValue = objObject.value;
	if (objObject.value == "") return true;
	if(!regNumeric.test(strValue)){
		return false;
	}
	return true;
}
//***********************************************************************************************************************

//***********************************************************************************************************************
//	Form Validation Function  (QUOTE FORM)
//***********************************************************************************************************************
function doVALIDATEQUOTEFORM(){
	var theForm = document.frmQUOTEFORM;
	if(Trim(theForm.fname.value).length == 0){
		alert('Please enter your name.');
		theForm.fname.focus();
		return false;
	}
	if(Trim(theForm.sname.value).length == 0){
		alert('Please enter your surname.');
		theForm.sname.focus();
		return false;
	}	
	if(Trim(theForm.age.value).length == 0){
		alert('Please enter your age.');
		theForm.age.focus();
		return false;
	//}		
	//if(isNumeric(theForm.age) == false){
		//alert("Please enter proper numeric value in age..");
		//theForm.age.focus();
		//return false;
	}
	if(Trim(theForm.address.value).length == 0){
		alert('Please enter your postal address.');
		theForm.address.focus();
		return age;
	}	
	if(Trim(theForm.address.value).length == 100){
		alert('Please enter only 100 characters in your postal address.');
		theForm.address.focus();
		return age;
	}
	if(Trim(theForm.hphone.value).length == 0){
		alert('Please enter your Landline number.');
		theForm.hphone.focus();
		return age;
	}
	
	if(Trim(theForm.mphone.value).length == 0){
		alert('Please enter your Mobile number.');
		theForm.mphone.focus();
		return age;
	}
	
	if(Trim(theForm.email.value).length == 0){
		alert('Please enter your email id.');
		theForm.email.focus();
		return false;
	}
	
	if (isEmail(theForm.email) == false){
		alert("Please enter your valid email id.\nFor example: xyz@xyz.com");
		theForm.email.focus();
		return false;	
	}
	var blnTreatment = false;
	t = 1;
	for(var i=0; i<theForm.elements.length; i++){ 
		var element = theForm.elements[i];
		if(element.type == "checkbox"){
			if(element.id == "treatment_" + t){
				if(element.checked == true){
					blnTreatment = true;					
					break;
				}else{
					blnTreatment = false;
				}
				t++;
			}						
		}
	} 
	if(blnTreatment == false){
		alert("Please enter select type of treatment.");
		return false;	
	}
	
	
	if(Trim(theForm.otherspecify.value).length == 0){
		alert('Please Specify Your Treatment.');
		theForm.otherspecify.focus();
		return age;
	}
	
	
	if(Trim(theForm.addinfo.value).length == 0){
		alert('Please enter additional information.');
		theForm.addinfo.focus();
		return false;
	}
	
	
	//var blnRefferal = false;
	//t = 1;
	//for(var i=0; i<theForm.elements.length; i++){ 
		//var element = theForm.elements[i];
	//	if(element.type == "checkbox"){
			//if(element.id == "refferal_" + t){
			//	if(element.checked == true){
				//	blnRefferal = true;					
				//	break;
			//	}else{
				//	blnRefferal = false;
			//	}
		//		t++;
		//	}						
	//	}
//	} 
		
//	if(blnRefferal == false){
	//	alert("Please enter select how did you hear about us.");
		//return false;	
//	}

	
	if(Trim(theForm.hospitalorsurgeon.value).length == 0){
		alert('Please Specify Hospital or Surgeon.');
		theForm.hospitalorsurgeon.focus();
		return false;
	}
	
	
	if(Trim(theForm.comments.value).length == 0){
		alert('Please Enter any questions or comments.');
		theForm.comments.focus();
		return false;
	}

	if(theForm.agree.checked != true){
		alert('You need to agree to our terms and conditions\nin order to send you quote.');
		theForm.agree.focus();
		return false;		
	}
	theForm.submit();
	return true;
}
//***********************************************************************************************************************

//***********************************************************************************************************************
//	Form Validation Function  (CONTACT FORM)
//***********************************************************************************************************************
function doVALIDATECONTACTFORM(){
	var theForm = document.frmCONTACTFORM;
	if(Trim(theForm.name.value).length == 0){
		alert('Please enter your name.');
		theForm.name.focus();
		return false;
	}
	if(Trim(theForm.email.value).length == 0){
		alert('Please enter your email id.');
		theForm.email.focus();
		return false;
	}
	if (isEmail(theForm.email) == false){
		alert("Please enter your valid email id.\nFor example: xyz@xyz.com");
		theForm.email.focus();
		return false;	
	}	
	if(Trim(theForm.age.value).length == 0){
		alert('Please enter your age.');
		theForm.age.focus();
		return false;
	}		
	if(isNumeric(theForm.age) == false){
		alert("Please enter proper numeric value in age..");
		theForm.age.focus();
		return false;
	}
	if(Trim(theForm.choice.value).length == 0){
		alert('Please enter your choice of treatment.');
		theForm.choice.focus();
		return false;
	}
	if(Trim(theForm.country.value).length == 0){
		alert('Please enter your country.');
		theForm.country.focus();
		return false;
	}
	if(Trim(theForm.services_sought.value).length == 0){
		alert('Please enter your service sought information.');
		theForm.services_sought.focus();
		return false;
	}
	if(Trim(theForm.services_sought.value).length == 250){
		alert('Please enter only 250 characters in your service\nsought information.');
		theForm.services_sought.focus();
		return false;
	}	
	theForm.submit();
	return true;
}
//***********************************************************************************************************************

