// JavaScript Document
function ltrim(s)
{
return s.replace(/^\s*/,"");
}
function rtrim(s)
{
return s.replace(/\s*$/,"");
}
function trim(s)
{
return rtrim(ltrim(s));
}
function hide_text(id,realvalue,boxvalue)
{
	if(boxvalue==realvalue)
		document.getElementById(id).value='';
}
function show_text(id,realvalue,boxvalue)
{
	if(trim(boxvalue)=='')
		document.getElementById(id).value=realvalue;
}
function Chk_Numeric(obj_nam,pos)    //Please Enter a Valid Product Price
 {
	 var x=document.getElementById(obj_nam).value; 
	 if(pos==1)//for first_name,last_name validation,city
	 {
		 var invalids = "`~@#$%^&*()_-+=\|{}[]:;'\"<>,.?/";
		 for(i=0; i<invalids.length; i++) 
		 {    
			if(x.indexOf(invalids.charAt(i)) >= 0 || x==false)
			{
				return false;
			}
		 }
	 }
	 if(pos==2) //for comments validation
	 {
	 	var invalids = "`~#%^&*()-+=\|{}[]:;'\"<>?/ ";
		 for(i=0; i<invalids.length; i++) 
		 {    
			if(x.indexOf(invalids.charAt(i)) >= 0 || x==false)
			{
				return false;
			}
		 }
	 }
	 if(pos==3)//for company name validation
	 {
	 	var invalids = "`~#$%^&*()_-+=\|{}[]:;'\"<>?/,";
		 for(i=0; i<invalids.length; i++) 
		 {    
			if(x.indexOf(invalids.charAt(i)) >= 0 || x==false)
			{
				return false;
			}
		 }
	 }
	 if(pos==4) //Address validation
	 {
	 	var invalids = "`~^*|<>?";
		for(i=0; i<invalids.length; i++) 
		 {    
			if(x.indexOf(invalids.charAt(i)) >= 0 || x==false)
			{
				return false;
			}
		 }
	 }
	if(pos==5) //integer validation
	 {
	 	var invalids = "+-";
		for(i=0; i<invalids.length; i++) 
		 {    
			if(x.indexOf(invalids.charAt(i)) >= 0 || x==false)
			{
				return false;
			}
		 }
	 }
	 return true;
 }
// Function to check wether email contains 2 chars after @ symbol and 2 chars after . symbol
function checkEmailFormat(email) {
	var myFirstArray = email.split('@');
	var mySecondArray = myFirstArray[1].split('.');
	if(mySecondArray[0].length >= 2 && mySecondArray[1].length >= 2)
	{
		return true;
	}
	return false;
}
//validation for Email format
function checkEmail(email) {
   var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
   var reg1 = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-])+\.([A-Za-z]{2,4})+\.([A-Za-z]{2,4})+\.([A-Za-z]{2,4})$/;
   if(reg1.test(email) == true) {
      return false;
   }
   if(reg.test(email) == false) {
      return false;
   }
else
return checkEmailFormat(email);
}
function urlFormat(url)//function to check url of the form http://www.xxx.com
{
	//pattern for url of format http://www.xxx.com
	var p=/^((http|https)\:\/\/)?((www)\.)?([a-z0-9]+(\_|\.|\-|\/)?)+\.[a-z0-9]{2,5}$/i;
	if(p.test(url)==true)
		return true;
	else
		return false;
}
function numericFormat(num)//function to check url of the form http://www.xxx.com
{
	//pattern for url of format http://www.xxx.com
	var p=/^[0-9]+([\.][0-9]+)?$/;
	if(p.test(num)==true)
		return true;
	else
		return false;
}
function imageFormat(image)
{
	if(image!="")
	{
		var b=image.lastIndexOf('.',image.length);
		var c=image.substr(b+1,image.length);
		if(!((c=='jpg')||(c=='JPG')||(c=='png')||(c=='PNG')||(c=='jpeg')||(c=='JPEG')||(c=='gif')||(c=='GIF')||(c=='bmp')||(c=='BMP')))
			return false;
		else
			return true;
	}
}
function imagelogoFormat(image)
{
	if(image!="")
	{
		var b=image.lastIndexOf('.',image.length);
		var c=image.substr(b+1,image.length);
		if(!((c=='jpg')||(c=='JPG')||(c=='png')||(c=='PNG')||(c=='jpeg')||(c=='JPEG')||(c=='gif')||(c=='GIF')||(c=='bmp')||(c=='BMP')))
			return false;
		else
			return true;
	}
}

function BookAppointment(variable)
{
	mErrStr = "";
	mFieldName = "";
	if(trim(document.BookAnAppointment.FirstName.value) == "")
	{
	mErrStr +="FirstName \n";
	if(mFieldName == "")
		mFieldName = "FirstName";
	}
	if(trim(document.BookAnAppointment.LastName.value) == "")
	{
	mErrStr +="LastName \n";
	if(mFieldName == "")
		mFieldName = "LastName";
	}
	if(trim(document.BookAnAppointment.Phone.value) == "")
	{
	mErrStr +="Phone \n";
	if(mFieldName == "")
		mFieldName = "Phone";
	}
	if(trim(document.BookAnAppointment.Email.value) == "")
	{
	mErrStr +="E-mail Address \n";
	if(mFieldName == "")
		mFieldName = "Email";
	}
	if(trim(document.BookAnAppointment.Email.value)!="")
	{
		var emailID=document.BookAnAppointment.Email;
		if (checkEmail(emailID.value)==false)
		{
			mErrStr +="Valid E-mail Address \n";
			mFieldName = "Email";
		}
	} 
	if(trim(document.BookAnAppointment.ConfirmEmail.value) == "")
	{
	mErrStr +="E-mail Address \n";
	if(mFieldName == "")
		mFieldName = "ConfirmEmail";
	}
	if(trim(document.BookAnAppointment.ConfirmEmail.value)!="")
	{
		var emailID=document.BookAnAppointment.Email;
		var ConfirmemailID=document.BookAnAppointment.ConfirmEmail;
		if (emailID.value!=ConfirmemailID.value)
		{
			mErrStr +="Email and Confirm Email must match \n";
			mFieldName = "ConfirmEmail";
		}
	} 
	if(trim(document.BookAnAppointment.Reason.value) == "")
	{
	mErrStr +="Reason \n";
	if(mFieldName == "")
		mFieldName = "Email";
	}
	if(trim(document.BookAnAppointment.how.value) == "")
	{
	mErrStr +="How did you hear about us? \n";
	if(mFieldName == "")
		mFieldName = "how";
	}
	/*if(trim(document.contact.contactSelection.value) == "")
	{
	mErrStr +="Area Of Interest \n";
	if(mFieldName == "")
		mFieldName = "contactSelection";
	}
	if(trim(document.BookAnAppointment.contactComments.value) == "")
	{
	mErrStr +="Comments \n";
	if(mFieldName == "")
		mFieldName = "contactComments";
	}*/
		
		
		
}
