// function to check the login validations
function chk_blank()
{
if(document.login.name.value=="")
{
alert("Enter your username to login");
document.login.name.focus();
return false;
}
if(document.login.pass.value=="")
{
alert("Enter your password");
document.login.pass.focus();
return false;
}
return true;
}

//BOF :contact us form validations
function checkcontactus()
{
	if(document.contactus.name.value.length==0)
		{
			alert("Enter your name");
			document.contactus.name.focus();
			return false;
		}
	if(document.contactus.company.value.length==0)
		{
			alert("Enter the name of the company");
			document.contactus.company.focus();
			return false;
		}
		if(document.contactus.email.value.length==0)
		{
			alert("Enter your Email Address");
			document.contactus.email.focus();
			return false;
		}
  	    var emailExp = /^[\w\-\.\+]+\@[a-zA-Z0-9\.\-]+\.[a-zA-z0-9]{2,4}$/;
    	if(!document.contactus.email.value.match(emailExp))
    	{
   	    alert("Please Enter Valid Email Address!");
        document.contactus.email.focus();
        return false;
   	    }
      	if ((document.contactus.dayphone.value==null)||(document.contactus.dayphone.value=="")){
		alert("Enter your Day Phone number")
		document.contactus.dayphone.focus()
		return false
	   }
	   if (checkInternationalPhone(document.contactus.dayphone.value)==false){
		alert("Please Enter a Valid  Day Phone Number")
		document.contactus.dayphone.focus()
		return false
	   }
	  if ((document.contactus.evening.value==null)||(document.contactus.evening.value=="")){
		alert("Enter your Evening Phone number")
		document.contactus.evening.focus()
		return false
	   }
	   if (checkInternationalPhone(document.contactus.evening.value)==false){
		alert("Please Enter a Valid  Evening Phone Number")
		document.contactus.evening.focus()
		return false
	   }
      if ((document.contactus.fax.value==null)||(document.contactus.fax.value=="")){
		alert("Enter your Fax no")
		document.contactus.fax.focus()
		return false
	   }
	   if (checkInternationalPhone(document.contactus.fax.value)==false){
		alert("Please Enter a Valid Fax Number")
		document.contactus.fax.focus()
		return false
	   }
		if(document.contactus.contactme.value.length==0)
		{
			alert("Enter the Best time to contact you ");
			document.contactus.contactme.focus();
			return false;
		}
		if(document.contactus.contactmevia.value.length==0)
		{
			alert("Enter your Address to contact ");
			document.contactus.contactmevia.focus();
			return false;
		}
     }
// EOF : CONTACT US FORM VALIDATION 

function check_number()
{
	var str=document.contactus.dayphone.value
	var inpVal = parseInt(str, 10)
		if (isNaN(inpVal))
			{
            alert(" Enter only numbers");
			str=="";
			document.contactus.dayphone.focus();
			return false;
			}
		
			else if(str.length>10 || str.length<10)
			{
				alert("Phone no. should not be less than 10 digits");
				document.contactus.dayphone.value=="";
				document.contactus.dayphone.focus();
				return false;
			}
			return true;
}
			//---------------------------------------validations for testimonials
			
			function check_blank()
			{
				if(document.testimonial.mail.value=="")
				{
					alert("Enter the email address");
					document.testimonial.mail.focus();
					return false;
				}
				if(document.testimonial.feedback.value=="")
				{
					alert("Enter the feedback");
					document.testimonial.feedback.focus();
					return false;
				}
				return true;
			}





//_______________________________validations for jobcard1_____________________________________________--

function check_blanks()
{
	
		
	 if(jobcard.ro_number.value=="")
	{																			//to check the first name blank
		alert("Enter First Name");
		jobcard.ro_number.focus();
		return false;
	}
	
	  if(jobcard.lastname.value=="")
	{																			//to check the surname blank
		alert("Enter your Lastname");
		jobcard.lastname.focus();
		return false;
	}
	if(jobcard.veh_make.value=="")
	{																		 //to check the company name blank
		alert("Enter Company Name");
		jobcard.veh_make.focus();
		return false;
	}	
	if(jobcard.comments.value=="")		//to check the text blank 
	{
		alert("Enter Address ");
		jobcard.comments.focus();
		return false;
	}
	
	

	 if(jobcard.day.options[jobcard.day.selectedIndex].value=="select")		//to check the text blank 
	{
		
		alert("Select day ");
		jobcard.day.options.focus();
		return false;
	}
 if(jobcard.month.options[jobcard.month.selectedIndex].value=="select1")		//to check the text blank 
	{
		
		alert("Select Month ");
		jobcard.month.options.focus();
		return false;
	}

	if(jobcard.year.options[jobcard.year.selectedIndex].value=="select2")		//to check the text blank 
	{
		
		alert("Select Year ");
		jobcard.year.options.focus();
		return false;
	}
	
	return true;
}


function CheckMail1()
{
var str=document.jobcard.email.value

		
		if(str!="")
		{
		var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i
		if (filter.test(str))
		testresults=true
		else{
		alert("A valid email address is required")
		document.jobcard.email.value="";
		document.jobcard.email.focus();
		return false;
		}
	}
	return true;
}


//-------------------------------validations for edit page---------------


function check_blank1()
{
	
	if(document.edit.email.value=="")
	{
		alert("Enter your email address");
		document.edit.email.focus()
		return false;
	}
	if(document.edit.ce.value=="")
	{
		alert("Enter your Confirmemail address");
		document.edit.ce.focus()
		return false;
	}
	if(document.edit.ce.value!=document.edit.email.value)
	{
		alert(" Confirm Email and Email does not match");
		document.edit.ce.focus();
		return false;
	}
	if(document.edit.fn.value=="")
	{
		alert("Enter your email address");
		document.edit.fn.focus()
		return false;
	}
	if(document.edit.email.value=="")
	{
		alert("Enter your email address");
		document.edit.email.focus()
		return false;
	}
	return true;
}

//-------------------------------------------------------------

function check_search_blank()
{
if(formcheck.name.value=="")     //Last Name field blank check
{	
	alert ("Last Name Required");
	formcheck.name.focus();
		return false;
}
return true;
}

//---------------------------------------
function onlinecard_check()
{
if(form1.Name.value=="")     //Last Name field blank check
{	
	alert ("Name Required");
	form1.Name.focus();
		return false;
}
if(form1.Vehicle.value=="")     //Last Name field blank check
{	
	alert ("Vehicle Required...");
	form1.Vehicle.focus();
		return false;
}
if(form1.email.value=="")     //Last Name field blank check
{	
 alert ("Email Required...");
 form1.email.focus();
 return false;
}
return true;
}
/////////// check  email on blur 
function CheckMail_online()
{
   var str=document.form1.email.value
		if(str!="")
		{
		var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i
		if (filter.test(str))
		testresults=true
		else{
		alert("A valid Email address is required")
		document.form1.email.value="";
		document.form1.email.focus();
		return false;
		}
	}
	return true;
}
///------------------------------------------------

function pswd_chng()
{
if(form1.old_pswd.value=="")     //Last Name field blank check
{	
	alert ("Old Password Required");
	form1.old_pswd.focus();
		return false;
}
if(form1.new_pswd.value=="")     //Last Name field blank check
{	
	alert ("New Password Required...");
	form1.new_pswd.focus();
		return false;
}
if(form1.con_pswd.value=="")     //Last Name field blank check
{	
	alert ("Confirm Password Required...");
	form1.con_pswd.focus();
		return false;
}
if(form1.new_pswd.value!=form1.con_pswd.value)     //comparison
{	
	alert ("Confirm Password Doesn't match...");
	form1.con_pswd.focus();
		return false;
}
return true;
}
///////// check phone validation /// ////
var digits = "0123456789";
// non-digit characters which are allowed in phone numbers
var phoneNumberDelimiters = "()- ";
// characters which are allowed in international phone numbers
// (a leading + is OK)
var validWorldPhoneChars = phoneNumberDelimiters + "+";
// Minimum no of digits in an international phone no.
var minDigitsInIPhoneNumber = 10;

function isInteger(s)
{   var i;
    for (i = 0; i < s.length; i++)
    {   
        // Check that current character is number.
        var c = s.charAt(i);
        if (((c < "0") || (c > "9"))) return false;
    }
    // All characters are numbers.
    return true;
}
function trim(s)
{   var i;
    var returnString = "";
    // Search through string's characters one by one.
    // If character is not a whitespace, append to returnString.
    for (i = 0; i < s.length; i++)
    {   
        // Check that current character isn't whitespace.
        var c = s.charAt(i);
        if (c != " ") returnString += c;
    }
    return returnString;
}
function stripCharsInBag(s, bag)
{   var i;
    var returnString = "";
    // Search through string's characters one by one.
    // If character is not in bag, append to returnString.
    for (i = 0; i < s.length; i++)
    {   
        // Check that current character isn't whitespace.
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }
    return returnString;
}

function checkInternationalPhone(strPhone){
var bracket=3
strPhone=trim(strPhone)
if(strPhone.indexOf("+")>1) return false
if(strPhone.indexOf("-")!=-1)bracket=bracket+1
if(strPhone.indexOf("(")!=-1 && strPhone.indexOf("(")>bracket)return false
var brchr=strPhone.indexOf("(")
if(strPhone.indexOf("(")!=-1 && strPhone.charAt(brchr+2)!=")")return false
if(strPhone.indexOf("(")==-1 && strPhone.indexOf(")")!=-1)return false
s=stripCharsInBag(strPhone,validWorldPhoneChars);
return (isInteger(s) && s.length >= minDigitsInIPhoneNumber);
}
/////// EOF : Phone validation //////////////////