// form validation function //
function isInt(val)
{
	var k=val.length;
	for ( var i=0; i<k; i++)
	{
		ch = val.charAt(i);
		if((ch > '9' || ch < '0'))
		{
			return false;
		}
	}
	return true;
}

function check(diesel,cng,cngfactory,dd_make,model_txt,txt_other_make,txt_other_model,dd_year,dd_expiry,txt_sellprice,txt_mileage,dd_registration,dd_location,txt_contact,txt_contactname)
{
	   // alert(document.getElementById('div_hd_make1').style.display);
		if(dd_make.value=='0' && document.getElementById('div_hd_make1').style.display=='none')
	    {
		inlineMsg(dd_make,'Please Select Make.',2);
		return false;
		}
		if((model_txt.value=='' || model_txt.value=='0') && document.getElementById('div_hd_model1').style.display=='none' && txt_other_model.value =='')
	    {
		inlineMsg(model_txt,'Please Select Model.',2);
		return false;
		}
	    if(txt_other_make.value=='' && document.getElementById('div_hd_make1').style.display=='')
	    {
		inlineMsg(txt_other_make,'Please Select Make.',2);
		return false;
		}
		/*if(txt_other_model.value=='' && document.getElementById('div_hd_model1').style.display=='')
	    {
		inlineMsg(txt_other_model,'Please Select Model.',2);
		return false;
		}*/
		if(dd_year.value=='')
	    {
		inlineMsg(dd_year,'Please Select year.',2);
		return false;
		}
		if(txt_sellprice.value=='')
		{
		inlineMsg(txt_sellprice,'Please Enter Price of your car.',2);
		return false;
		}
                if(!isInt(txt_sellprice.value))
		{
			inlineMsg(txt_sellprice,'Please Enter a Valid Price. Only Digits Are Allowed.',2);
			return false;	
		}
		if(txt_sellprice.value!='' && txt_sellprice.value.length <5)
		{
			inlineMsg(txt_sellprice,'Please give actual value like, 275000 etc.',2);
		return false;
		}
		 if(dd_expiry.value=='')
	        {
		alert("Please Mention Expiry Period");
		inlineMsg(dd_expiry,'Please Mention Expiry Period.',2);
		dd_expiry.focus();
		return false;
		}
		if ((!diesel[0].checked) && (!diesel[1].checked)) {
			inlineMsg(diesel[1],'Please mention engine is diesel or not.',2);
		
		//diesel[0].focus();
		return false;
		}
		if ((!cng[0].checked) && (!cng[1].checked)) {
			//alert(cng[1].checked)
				inlineMsg(cng[1],'Please mention  CNG fitted or not.',2);
		
		//cng[0].focus();
		return false;
		}
		if ((!cngfactory[0].checked) && (!cngfactory[1].checked)) {
				inlineMsg(cngfactory[1],'Please mention  CNG is factory fitted or not.',2);
		
		//cngfactory[0].focus();
		return false;
		}
/*var nameRegex = /^[a-zA-Z]+(([\'\,\.\- ][a-zA-Z ])?[a-zA-Z]*)*$/;
	  var numberRegex= /^([0-9])+ ([\'\,\.\-\- ][0-9])?[0-9]*)*$/ ;
     var contactname=document.getElementById('txt_contactname1').value;
     var contact=document.getElementById('txt_contact1').value;

if(contactname=='')
		{
		inlineMsg('txt_contactname1','Please Enter Seller name of the car.',2);
		return false;
		}
      
   if(!contactname.match(nameRegex)) {
  
  inlineMsg('txt_contactname1','You have entered an invalid name.',2);
    return false;
  } 
  
  if(contact=='')
		{
		inlineMsg('txt_contact1','Please Enter Contact No.',2);
		return false;
		}
      
  
if(!contact.match(numberRegex)) {
    //alert("Numbers only")
    inlineMsg('txt_contact1','<strong>Error</strong><br />You have to enter numbers only.',2);
    return false; 	}
*/
if(txt_contactname.value=='')
		{
		inlineMsg(txt_contactname,'Please Enter Seller name of the car.',2);
		return false;
		}
if(txt_contactname.value==' ')
		{
		inlineMsg(txt_contactname,'Please Enter Seller name of the car.',2);
		return false;
		}
if(txt_contactname.value=='  ')
		{
		inlineMsg(txt_contactname,'Please Enter Seller name of the car.',2);
		return false;
		}


if(txt_contact.value=='')
		{
		inlineMsg(txt_contact,'Please Enter Seller contact no.',2);
		return false;
		}
		
if(txt_contact.value==' ')
		{
		inlineMsg(txt_contact,'Please Enter Seller contact no.',2);
		return false;
		}
if(txt_contact.value=='  ')
		{
		inlineMsg(txt_contact,'Please Enter Seller contact no.',2);
		return false;
		}
if(txt_contact.value=='   ')
		{
		inlineMsg(txt_contact,'Please Enter Seller contact no.',2);
		return false;
		}



//}
return true;
}
//if ther is error in 
/*function validate(form) {
var txt_fname = document.getElementById("txt_fname").value;
var txt_lname = document.getElementById("txt_lname").value;
var txt_username = document.getElementById("text_username").value;
var txt_email = document.getElementById("txt_email").value;
var txt_no = document.getElementById("txt_homephone").value;
var txt_offno = document.getElementById("txt_officephone").value;
var txt_mob = document.getElementById("txt_mobile").value;
var txt_postal = document.getElementById("txt_postalcode").value;

var userPhoto = document.getElementById("userPhoto").value;
var chk_dealer = document.signUpForm.dealer.checked;
var companyname= document.getElementById("txt_companyname").value;
var chk_agree = document.signUpForm.chk_agree.checked;
//var chk_agree = document.getElementById('chk_agree').value;

//alert('alert');

var nameRegex = /^[a-zA-Z]+(([\'\,\.\- ][a-zA-Z ])?[a-zA-Z]*)*$/;
var emailRegex = /^[\w-\.]+@([\w-]+\.)+[\w-]{2,4}$/;
var messageRegex = new RegExp(/<\/?\w+((\s+\w+(\s*=\s*(?:".*?"|'.*?'|[^'">\s]+))?)+\s*|\s*)\/?>/gim);
var numberRegex= /^([0-9])*$/ ;

if(txt_fname == "") {
    inlineMsg('txt_fname','You must enter your first name.',2);
    return false;
  }
  
  //**************************************************************
 //if(!txt_fname.match(nameRegex)) {
//    inlineMsg('txt_fname','You have entered an invalid first name.',2);
//    return false;
// }   if(txt_lname == "") {
//    inlineMsg('txt_lname','You must enter user last name.',2);
//    return false;
//  } 
 // if(txt_lname.length < 6) {
//    inlineMsg('txt_lname','lastname should have atleast 6 Characters.',2);
//    return false;
//  } 
  //*****************************************************************************
  if(txt_username == "") {
  
	inlineMsg('text_username','You must enter your userid.',2);
    return false;
  }
  
  if (txt_email == "")
		{
			inlineMsg('txt_email','Please enter a valid email address.',2);
			return false;
		}  else 
		      {if(!txt_email.match(emailRegex)) {
                inlineMsg('txt_email','<strong>Error</strong><br />You have entered an invalid email.',2);
                return false; }
			  }
	
	if(!txt_no.match(numberRegex)) {
   // alert("Numbers only")
    inlineMsg('txt_homephone','<strong>Error</strong><br />You have to enter numbers only',2);
    return false; }
    
	if(!txt_offno.match(numberRegex)) {
    //alert("Numbers only")
    inlineMsg('txt_officephone','<strong>Error</strong><br />You have to enter numbers only.',2);
    return false; }
    
	if(!txt_mob.match(numberRegex)) {
   // alert("Numbers only")
    inlineMsg('txt_mobile','<strong>Error</strong><br />You have to enter numbers only.',2);
    return false; }
    
	if(!txt_postal.match(numberRegex)) {
    //alert("Numbers only")
    inlineMsg('tst_postalcode','<strong>Error</strong><br />You have to enter numbers only.',2);
    return false; 	}
   
   
   if (chk_dealer == true)
		{
		if (companyname == "")
		{
			inlineMsg('txt_companyname','Please enter company name',2);
			return false;
		}	
		}
   
	if (chk_agree != true){
	inlineMsg('chk_agree','Please agree to terms and conditions.',2);
	return false;
}
else{
	return true;
}
	 /* if(userPhoto!= "")
        {
			//alert(userPhoto)
            //var str = strrev(document.getElementById('logo').value);
            var str = strrev(userPhoto);
            var strArray = str.split(".");
            if(strrev(strArray[0]) == "bmp" || strrev(strArray[0]) == "BMP" ||
               strrev(strArray[0]) == "GIF" || strrev(strArray[0]) == "gif" ||
               strrev(strArray[0]) == "JPG" || strrev(strArray[0]) == "jpg")
            {
            }
            else
            {
				inlineMsg('userPhoto','Please use only JPG and GIF image.',2);
                //alert("Please use only JPG and GIF image.");
                return false;
            }
        }   
       
        function strrev(str)
        {
           if (!str) return '';
           var revstr='';
           for (i = str.length-1; i>=0; i--)
               revstr+=str.charAt(i)
           return revstr;
        }
		
	
		

} */
//********************
function validate(form) {
var txt_fname = document.getElementById("txt_fname").value;
var txt_lname = document.getElementById("txt_lname").value;
var txt_username = document.getElementById("text_username").value;
var txt_email = document.getElementById("txt_email").value;
var txt_no = document.getElementById("txt_homephone").value;
var txt_offno = document.getElementById("txt_officephone").value;
var txt_mob = document.getElementById("txt_mobile").value;
//var txt_postal = document.getElementById("txt_postalcode").value;

var userPhoto = document.getElementById("userPhoto").value;
var chk_dealer = document.signUpForm.dealer.checked;
var companyname= document.getElementById("txt_companyname").value;
var contactperson= document.getElementById("txt_contactperson").value;

var chk_agree = document.signUpForm.chk_agree.checked;
//var chk_agree = document.getElementById('chk_agree').value;

//alert('alert');

var nameRegex = /^[a-zA-Z]+(([\'\,\.\- ][a-zA-Z ])?[a-zA-Z]*)*$/;
var emailRegex = /^[\w-\.]+@([\w-]+\.)+[\w-]{2,4}$/;
var messageRegex = new RegExp(/<\/?\w+((\s+\w+(\s*=\s*(?:".*?"|'.*?'|[^'">\s]+))?)+\s*|\s*)\/?>/gim);
var numberRegex= /^([0-9])*$/ ;

if(txt_fname == "") {
    inlineMsg('txt_fname','You must enter your first name.',2);
    return false;
  }
 
  if(txt_username == "") {
  
	inlineMsg('text_username','You must enter your userid.',2);
    return false;
  }
  
  if (txt_email == "")
		{
			inlineMsg('txt_email','Please enter a valid email address.',2);
			return false;
		}  else 
		      {if(!txt_email.match(emailRegex)) {
                inlineMsg('txt_email','<strong>Error</strong><br />You have entered an invalid email.',2);
                return false; }
			  }
	
	if(!txt_no.match(numberRegex)) {
   // alert("Numbers only")
    inlineMsg('txt_homephone','<strong>Error</strong><br />You have to enter numbers only',2);
    return false; }
    
	if(!txt_offno.match(numberRegex)) {
    //alert("Numbers only")
    inlineMsg('txt_officephone','<strong>Error</strong><br />You have to enter numbers only.',2);
    return false; }
    
	if(!txt_mob.match(numberRegex)) {
   // alert("Numbers only")
    inlineMsg('txt_mobile','<strong>Error</strong><br />You have to enter numbers only.',2);
    return false; }
    
	
   
   
   if (chk_dealer == true)
		{
		if (companyname == "")
		{
			inlineMsg('txt_companyname','Please enter company name',2);
			return false;
		}
		if (contactperson == "")
		{
			inlineMsg('txt_contactperson','Please enter contactperson',2);
			return false;
		}
		}
   
	if (chk_agree != true){
	inlineMsg('chk_agree','Please agree to terms and conditions.',2);
	return false;
}
else{
	return true;
}
	 /* if(userPhoto!= "")
        {
			//alert(userPhoto)
            //var str = strrev(document.getElementById('logo').value);
            var str = strrev(userPhoto);
            var strArray = str.split(".");
            if(strrev(strArray[0]) == "bmp" || strrev(strArray[0]) == "BMP" ||
               strrev(strArray[0]) == "GIF" || strrev(strArray[0]) == "gif" ||
               strrev(strArray[0]) == "JPG" || strrev(strArray[0]) == "jpg")
            {
            }
            else
            {
				inlineMsg('userPhoto','Please use only JPG and GIF image.',2);
                //alert("Please use only JPG and GIF image.");
                return false;
            }
        }   
       
        function strrev(str)
        {
           if (!str) return '';
           var revstr='';
           for (i = str.length-1; i>=0; i--)
               revstr+=str.charAt(i)
           return revstr;
        }
		
	*/	
		

}

function validate_company(form) {
var txt_fname = document.getElementById("txt_fname").value;
var txt_lname = document.getElementById("txt_lname").value;
var txt_username = document.getElementById("text_username").value;
var txt_email = document.getElementById("txt_email").value;

var txt_offno = document.getElementById("txt_officephone").value;
var txt_mob = document.getElementById("txt_mobile").value;
//var txt_postal = document.getElementById("txt_postalcode").value;

var userPhoto = document.getElementById("userPhoto").value;

var companyname= document.getElementById("txt_companyname").value;
var contactperson= document.getElementById("txt_contactperson").value;

var chk_agree = document.signUpForm.chk_agree.checked;
//var chk_agree = document.getElementById('chk_agree').value;

//alert('alert');

var nameRegex = /^[a-zA-Z]+(([\'\,\.\- ][a-zA-Z ])?[a-zA-Z]*)*$/;
var emailRegex = /^[\w-\.]+@([\w-]+\.)+[\w-]{2,4}$/;
var messageRegex = new RegExp(/<\/?\w+((\s+\w+(\s*=\s*(?:".*?"|'.*?'|[^'">\s]+))?)+\s*|\s*)\/?>/gim);
var numberRegex= /^([0-9])*$/ ;

if (companyname == "")
		{
			inlineMsg('txt_companyname','Please enter company name',2);
			return false;
		}
if(txt_fname == "") {
    inlineMsg('txt_fname','You must enter your first name.',2);
    return false;
  }
 
  if(txt_username == "") {
  
	inlineMsg('text_username','You must enter your userid.',2);
    return false;
  }
  if (contactperson == "")
		{
			inlineMsg('txt_contactperson','Please enter contactperson',2);
			return false;
		}
  
  if (txt_email == "")
		{
			inlineMsg('txt_email','Please enter a valid email address.',2);
			return false;
		}  else 
		      {if(!txt_email.match(emailRegex)) {
                inlineMsg('txt_email','<strong>Error</strong><br />You have entered an invalid email.',2);
                return false; }
			  }
	
	if(!txt_no.match(numberRegex)) {
   // alert("Numbers only")
    inlineMsg('txt_homephone','<strong>Error</strong><br />You have to enter numbers only',2);
    return false; }
    
	if(!txt_offno.match(numberRegex)) {
    //alert("Numbers only")
    inlineMsg('txt_officephone','<strong>Error</strong><br />You have to enter numbers only.',2);
    return false; }
    
	if(!txt_mob.match(numberRegex)) {
   // alert("Numbers only")
    inlineMsg('txt_mobile','<strong>Error</strong><br />You have to enter numbers only.',2);
    return false; }
    
	
   
   
  
		
		
		if (contactperson == "")
		{
			inlineMsg('txt_contactperson','Please enter contactperson',2);
			return false;
		}
		
   
	if (chk_agree != true){
	inlineMsg('chk_agree','Please agree to terms and conditions.',2);
	return false;
     }
     else{
	  return true;
      }
	 /* if(userPhoto!= "")
        {
			//alert(userPhoto)
            //var str = strrev(document.getElementById('logo').value);
            var str = strrev(userPhoto);
            var strArray = str.split(".");
            if(strrev(strArray[0]) == "bmp" || strrev(strArray[0]) == "BMP" ||
               strrev(strArray[0]) == "GIF" || strrev(strArray[0]) == "gif" ||
               strrev(strArray[0]) == "JPG" || strrev(strArray[0]) == "jpg")
            {
            }
            else
            {
				inlineMsg('userPhoto','Please use only JPG and GIF image.',2);
                //alert("Please use only JPG and GIF image.");
                return false;
            }
        }   
       
        function strrev(str)
        {
           if (!str) return '';
           var revstr='';
           for (i = str.length-1; i>=0; i--)
               revstr+=str.charAt(i)
           return revstr;
        }
		
	*/	
		

}
<!--sheraz'code -->
function test_setvalidate(form) {
  var name = document.getElementById("name").value;
  var t_tital = document.getElementById("tital").value;
  var teste_m = document.getElementById("testemonial").value;
  var web_site = document.getElementById("website").value;
  var nameRegex = /^[a-zA-Z]+(([\'\,\.\- ][a-zA-Z ])?[a-zA-Z]*)*$/;
  var websiteRegex = /^([a-z0-9_-]+\.)*[a-z0-9_-]+(\.[a-z]{2,6}){1,2}$/;
  var messageRegex = new RegExp(/<\/?\w+((\s+\w+(\s*=\s*(?:".*?"|'.*?'|[^'">\s]+))?)+\s*|\s*)\/?>/gim);

if(name == "") {
   
   inlineMsg('name','You must enter your name.',2);
    return false;
  }
  
  if(!name.match(nameRegex)) {
  
  inlineMsg('name','You have entered an invalid name.',2);
    return false;
  } 
  if(t_tital == "") {
   
   inlineMsg('tital','You must enter some tital.',2);
    return false;
  }
  
  if(!t_tital.match(nameRegex)) {
    inlineMsg('tital','You have entered an invalid tital.',2);
    return false;
  } 
   
  if(teste_m == "") {
   
   inlineMsg('testemonial','You must enter some text.',2);
    return false;
  }
   
   if(web_site == ""){ return true}
     else  if(!web_site.match(websiteRegex)) {
  
      inlineMsg('website','You have entered an invalid web address.',2);
      return false;
      }
  
    return true;
}
 function check_contact(form){
	  var name = document.getElementById("txt_name").value;
	  var txt_email = document.getElementById("txt_email").value;
	 
      var txt_no = document.getElementById("txt_phone").value;
	  var emailRegex = /^[\w-\.]+@([\w-]+\.)+[\w-]{2,4}$/;
	  var numberRegex= /^([0-9])*$/ ;
	  
	  if(name == "") {
  
	inlineMsg('txt_name','You must enter your name.',2);
    return false;
  }
  
  if (txt_email == "")
		{
			inlineMsg('txt_email','Please enter a valid email address.',2);
			return false;
		}  else 
		      {if(!txt_email.match(emailRegex)) {
                inlineMsg('txt_email','<strong>Error</strong><br />You have entered an invalid email.',2);
                return false; }
			  }

	 if(!txt_no.match(numberRegex)) {
   // alert("Numbers only")
    inlineMsg('txt_phone','<strong>Error</strong><br />You have to enter numbers only',2);
    return false; }
	 
	 
	 }
<!--End sheraz'code -->
// START OF MESSAGE SCRIPT //
// START OF MESSAGE SCRIPT //

var MSGTIMER = 20;
var MSGSPEED = 5;
var MSGOFFSET = 3;
var MSGHIDE = 3;

// build out the divs, set attributes and call the fade function //
function inlineMsg(target,string,autohide) {
  var msg;
  var msgcontent;
  if(!document.getElementById('msg')) {
    msg = document.createElement('div');
    msg.id = 'msg';
    msgcontent = document.createElement('div');
    msgcontent.id = 'msgcontent';
    document.body.appendChild(msg);
    msg.appendChild(msgcontent);
    msg.style.filter = 'alpha(opacity=0)';
    msg.style.opacity = 0;
    msg.alpha = 0;
  } else {
    msg = document.getElementById('msg');
    msgcontent = document.getElementById('msgcontent');
  }
  msgcontent.innerHTML = string;
  msg.style.display = 'block';
  var msgheight = msg.offsetHeight;
  if(document.getElementById(target)!=null)
	  var targetdiv = document.getElementById(target);
  else
  	  var targetdiv = document.getElementById(target.name);
  targetdiv.focus();
  var targetheight = targetdiv.offsetHeight;
  var targetwidth = targetdiv.offsetWidth;
  var topposition = topPosition(targetdiv) - ((msgheight - targetheight) / 2);
  var leftposition = leftPosition(targetdiv) + targetwidth + MSGOFFSET;
  msg.style.top = topposition + 'px';
  msg.style.left = leftposition + 'px';
  clearInterval(msg.timer);
  msg.timer = setInterval("fadeMsg(1)", MSGTIMER);
  if(!autohide) {
    autohide = MSGHIDE;  
  }
  window.setTimeout("hideMsg()", (autohide * 1000));
}

// hide the form alert //
function hideMsg(msg) {
  var msg = document.getElementById('msg');
  if(!msg.timer) {
    msg.timer = setInterval("fadeMsg(0)", MSGTIMER);
  }
}

// face the message box //
function fadeMsg(flag) {
  if(flag == null) {
    flag = 1;
  }
  var msg = document.getElementById('msg');
  var value;
  if(flag == 1) {
    value = msg.alpha + MSGSPEED;
  } else {
    value = msg.alpha - MSGSPEED;
  }
  msg.alpha = value;
  msg.style.opacity = (value / 100);
  msg.style.filter = 'alpha(opacity=' + value + ')';
  if(value >= 99) {
    clearInterval(msg.timer);
    msg.timer = null;
  } else if(value <= 1) {
    msg.style.display = "none";
    clearInterval(msg.timer);
  }
}

// calculate the position of the element in relation to the left of the browser //
function leftPosition(target) {
  var left = 0;
  if(target.offsetParent) {
    while(1) {
      left += target.offsetLeft;
      if(!target.offsetParent) {
        break;
      }
      target = target.offsetParent;
    }
  } else if(target.x) {
    left += target.x;
  }
  return left;
}

// calculate the position of the element in relation to the top of the browser window //
function topPosition(target) {
  var top = 0;
  if(target.offsetParent) {
    while(1) {
      top += target.offsetTop;
      if(!target.offsetParent) {
        break;
      }
      target = target.offsetParent;
    }
  } else if(target.y) {
    top += target.y;
  }
  return top;
}

// preload the arrow //
if(document.images) {
  arrow = new Image(7,80); 
  arrow.src = "images/msg_arrow.gif"; 
}