//***********************************************************************************************************************
//	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 home phone number.');
		theForm.hphone.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(theForm.Others.checked == true){
		if(Trim(theForm.otherspecify.value).length == 0){
			alert('Please enter others information in treatment.');
			theForm.otherspecify.focus();
			return false;
		}	
		if(Trim(theForm.otherspecify.value).length == 100){
			alert('Please enter only 100 characters others information\nin treatment.');
			theForm.otherspecify.focus();
			return false;
		}			
	}
	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 == 100){
		alert('Please enter What Hospital or Surgeon you would like to get your treatment from.');
		theForm.hospitalorsurgeon.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.phone.value).length == 0){
		alert('Please enter your Landline Number.');
		theForm.phone.focus();
		return false;
	}
   if(Trim(theForm.phone2.value).length == 0){
		alert('Please enter your Mobile Number.');
		theForm.phone2.focus();
		return false;
	}
	if(Trim(theForm.hospitalorsurgeon.value).length == 0){
		alert('Please enter What Hospital or Surgeon you would like to get your treatment from.');
		theForm.hospitalorsurgeon.focus();
		return false;
	}
	
	if(Trim(theForm.enquiry1.value).length == 0){
		alert('Please enter your Enquiry.');
		theForm.enquiry1.focus();
		return false;
	}
	theForm.submit();
	return true;
}
//***********************************************************************************************************************
