function checkNaN(formelement,text)
{
	if (isNaN(formelement.value))
	{
	alert('Enter Numeric '+text);
	formelement.focus();
	return false;
	}
	else
	{
	return true;
	}
}
function echeck(str) {

		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		if (str.indexOf(at)==-1){
		   alert("Invalid E-mail ID")
		   return false
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   alert("Invalid E-mail ID")
		   return false
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    alert("Invalid E-mail ID")
		    return false
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		    alert("Invalid E-mail ID")
		    return false
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    alert("Invalid E-mail ID")
		    return false
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		    alert("Invalid E-mail ID")
		    return false
		 }
		
		 if (str.indexOf(" ")!=-1){
		    alert("Invalid E-mail ID")
		    return false
		 }

 		 return true					
	}
/**
 * DHTML phone number validation script. Courtesy of SmartWebby.com (http://www.smartwebby.com/dhtml/)
 */

// Declaring required variables
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);
}	
	
	
function validate_contact_us()
{
	   if(document.frmcontact.user_name.value=="")
		{
			alert("Name can not be blank. Please enter it..")
			document.frmcontact.user_name.focus();
			return false;
		}
		var emailID=document.frmcontact.email
	
	if ((emailID.value==null)||(emailID.value=="")){
		alert("Please Enter your Email ID")
		emailID.focus()
		return false
	}
	if (echeck(emailID.value)==false){
		emailID.value=""
		emailID.focus()
		return false
	}
	var Phone=document.frmcontact.phone
	if ((Phone.value==null)||(Phone.value=="")){
		alert("Please Enter your Phone Number")
		Phone.focus()
		return false
	}
	if (checkInternationalPhone(Phone.value)==false){
		alert("Please Enter a Valid Phone Number")
		Phone.value=""
		Phone.focus()
		return false
	}
	
}

function validate_enquiry()
{
	   if(document.frmenquiry.user_name.value=="")
		{
			alert("Name can not be blank. Please enter it..")
			document.frmenquiry.user_name.focus();
			return false;
		}
		var emailID=document.frmenquiry.email
	
	if ((emailID.value==null)||(emailID.value=="")){
		alert("Please Enter your Email ID")
		emailID.focus()
		return false
	}
	if (echeck(emailID.value)==false){
		emailID.value=""
		emailID.focus()
		return false
	}
     var Phone=document.frmenquiry.phone
		/*if ((Phone.value==null)||(Phone.value=="")){
		alert("Please Enter your Phone Number")
		Phone.focus()
		return false
	}*/
	if (Phone.value!="")
	{
		if (checkInternationalPhone(Phone.value)==false){
			alert("Please Enter a Valid Phone Number")
			Phone.value=""
			Phone.focus()
			return false
		}
     }
	if(document.frmenquiry.message.value=="")
		{
			alert("message can not be blank. Please enter it..")
			document.frmenquiry.message.focus();
			return false;
		}
}
function isURL(urlStr) {
if (urlStr.indexOf(" ") != -1) {
alert("Spaces are not allowed in a URL");
return false;
}

if (urlStr == "" || urlStr == null) {
return true;
}

urlStr=urlStr.toLowerCase();

var specialChars="\\(\\)><@,;:\\\\\\\"\\.\\[\\]";
var validChars="\[^\\s" + specialChars + "\]";
var atom=validChars + '+';
var urlPat=/^http:\/\/(\w*)\.([\-\+a-z0-9]*)\.(\w*)/;
var matchArray=urlStr.match(urlPat);

if (matchArray==null) {
alert("The URL seems incorrect \ncheck it begins with http://\n and it has 2 .'s");
return false;
}

var user=matchArray[2];
var domain=matchArray[3];

for (i=0; i<user.length; i++) {
if (user.charCodeAt(i)>127) {
alert("This domain contains invalid characters.");
return false;
}
}

for (i=0; i<domain.length; i++) {
if (domain.charCodeAt(i) > 127) {
alert("This domain name contains invalid characters.");
return false;
}
}

var atomPat=new RegExp("^" + atom + "$");
var domArr=domain.split(".");
var len=domArr.length;

for (i=0;i<len;i++) {
if (domArr[i].search(atomPat) == -1) {
//alert("The domain name does not seem to be valid.");
return false;
}
}

return true;
} 
function checkext(imgfile)
{
var submitcount = 0;
var allowSubmit=false;

	file=imgfile;
		if (file)
			{
				extArray = new Array(".jpg", ".jpeg", ".gif");
				
				while (file.indexOf("\\") != -1)
				file = file.slice(file.indexOf("\\") + 1);
				ext = file.slice(file.indexOf(".")).toLowerCase();
				for (var i = 0; i < extArray.length; i++) 

				{
		
					if (extArray[i]==ext) 
					{ 
						allowSubmit = true; break; 
					}
				}
				if (allowSubmit) return true;
				else
				{
							alert("Please only upload files that end in types:  " 
							+ (extArray.join("  ")) + "\nPlease select a new "
							+ "file to upload and submit again.");
							err="x";
							return false;
				}
			}
		//	}
}
<!-- dealer registeration form--->
function  validate_dealer()
{
    var action= document.frm_dealer_reg.action.value
	var txtname= document.frm_dealer_reg.txtname
	if ((txtname.value==null)||(txtname.value=="")){
		alert("Please Enter your Name")
		txtname.focus()
		return false;
	}
	var txtaddress= document.frm_dealer_reg.txtaddress
	if ((txtaddress.value==null)||(txtaddress.value=="")){
		alert("Please Enter your Address")
		txtaddress.focus()
		return false;
	}
	var Phone=document.frm_dealer_reg.txtphone
	if ((Phone.value==null)||(Phone.value=="")){
		alert("Please Enter your phone")
		Phone.focus()
		return false;
	}
	if(Phone.value != '')
	{
		if (checkInternationalPhone(Phone.value)==false)
		{
			alert("Please Enter a Valid Phone Number")
			Phone.value=""
			Phone.focus()
			return false;
		}
	}
	var txtctry=document.frm_dealer_reg.txtctry
	if ((txtctry.value==null)||(txtctry.value=="")){
		alert("Please Enter your country")
		txtctry.focus()
		return false;
	}
	var theurl=document.frm_dealer_reg.txtctryurl
	if (isURL(theurl.value)==false)
	{
		theurl.value=""
		theurl.focus()
		return false;
	}
	var txtcity=document.frm_dealer_reg.txtcity
	if ((txtcity.value==null)||(txtcity.value=="")){
		alert("Please Enter your city")
		txtcity.focus()
		return false;
	}
	var thelink=document.frm_dealer_reg.txtlink
	if (isURL(thelink.value)==false)
	{
		thelink.value=""
		thelink.focus()
		return false;
	}
	
	if(document.frm_dealer_reg.action != 'edit')
	{
		var emailID= document.frm_dealer_reg.txtemail
		if ((emailID.value==null)||(emailID.value=="")){
			alert("Please Enter your Email ID")
			emailID.focus()
			return false;
		}
		
		if (document.frm_dealer_reg.txtpwd.value =="")
		{
			alert("Please Enter a Valid Password")
			document.frm_dealer_reg.txtpwd.value=""
			document.frm_dealer_reg.txtpwd.focus()
			return false;
		}
	}
	
	
	if (document.frm_dealer_reg.upload_logo.value =="")
	{
		alert("Please Enter a Valid Logo")
		document.frm_dealer_reg.upload_logo.value=""
		document.frm_dealer_reg.upload_logo.focus()
		return false;
	}
	
	if(document.frm_dealer_reg.upload_logo.value!="")
	{
				return checkext(document.frm_dealer_reg.upload_logo.value);
	}

}

function validate_login()
{
	if(document.frmlogin.txtuname.value =="")
	{
		alert("Please Enter a Valid username")
		document.frmlogin.txtuname.value=""
		document.frmlogin.txtuname.focus()
		return false
	}
	if(document.frmlogin.txtpwd.value =="")
	{
		alert("Please Enter a Valid passowrd")
		document.frmlogin.txtpwd.value=""
		document.frmlogin.txtpwd.focus()
		return false
	}
}
function validate_forgotpwd()
{
	var emailID= document.frmforgotpwd.txtemail
	if ((emailID.value==null)||(emailID.value=="")){
		alert("Please Enter your Email ID")
		emailID.focus()
		return false
	}
	if (echeck(emailID.value)==false){
		emailID.value=""
		emailID.focus()
		return false
	}
}
function validate_addcar()
{
	if(document.frm_addcar.year.value=="")
	{
		alert('Please select year');
		document.frm_addcar.year.focus()
		return false;
	}
	if(document.frm_addcar.make.value=="")
	{
		alert('Please enter make');
		document.frm_addcar.make.focus()
		return false;
	}
	if(document.frm_addcar.model.value=="")
	{
		alert('Please enter model');
		document.frm_addcar.model.focus()
		return false;
	}
	if(document.frm_addcar.mileage.value=="")
	{
		alert('Please enter mileage');
		document.frm_addcar.mileage.focus()
		return false;
	}
	if(!checkNaN(document.frm_addcar.mileage,'mileage')) return false;
	if(document.frm_addcar.price.value=="")
	{
		alert('Please enter price');
		document.frm_addcar.price.focus()
		return false;
	}
	if(!checkNaN(document.frm_addcar.price,'price')) return false;
	if(document.frm_addcar.fuel_type.value=="")
	{
		alert('Please select fuel type');
		document.frm_addcar.fuel_type.focus()
		return false;
	}
	if(!checkNaN(document.frm_addcar.no_of_doors,'number of doors')) return false;
	if(!checkNaN(document.frm_addcar.seats,'seats')) return false;
	if(!checkNaN(document.frm_addcar.no_of_owners,'number of owners')) return false;
	
}
