// form validation function //
function $(id) {return document.getElementById(id);}


function validate(form) {
  var topic = form.txt_topic.value;
  var company = form.txt_company.value;
  var contactp = form.txt_name.value;
  var phone = form.txt_phone.value;
  var email = form.txt_email.value;
  var message = form.txta_message.value;
  var hear = form.txt_hearof.value; 
 
  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 reWhiteSpace = new RegExp(/^\s+$/);

 // TOPIC /////////////////////////
  
  if(topic == "" || reWhiteSpace.test(topic) == true) {
 	
    modinputbad('txt_topic');
    var a = "1";
   }else {
    
  modinputgood('txt_topic');
     var a = "0";
  }
 
  // COMPANY /////////////////////////
  if(company == "" || reWhiteSpace.test(company) == true) {
    modinputbad('txt_company');
    var b = "1";
    }else {
  modinputgood('txt_company');
     var b = "0";
  }
  
  // CONTACTP /////////////////////////
  if(contactp == "" || reWhiteSpace.test(contactp) == true) {
    modinputbad('txt_name');
    var c = "1";
   }else {
  modinputgood('txt_name');
     var c = "0";
  }
  
    // PHONE /////////////////////////
  if(phone == "" || reWhiteSpace.test(phone) == true) {
    modinputbad('txt_phone');
    var d = "1";
    }else {
  modinputgood('txt_phone');
     var d = "0";
  }

  
  /// EMAIL /////////////////////////
  if(email == "" || !email.match(emailRegex)) {
    modinputbad('txt_email');
      var e = "1";
  }else {
     modinputgood('txt_email');
      var e = "0";
  }
 
  
 
  //MESSAGE  /////////////////////////
  if(message == "" || reWhiteSpace.test(message) == true) {

    modinputbad('txta_message');
	var f = "1";
  }else{
    modinputgood('txta_message');
	var f = "0";
  }
  
   //hear /////////////////////////
  if(hear == "" || reWhiteSpace.test(hear) == true) {

    modinputbad('txt_hearof');
	var g = "1";
  }else{
    modinputgood('txt_hearof');
	var g = "0";
  }
  
  
  
  
function modinputbad(id) {
	$(id).style.border = '1px solid #b63939';
	$(id).style.background = '#ffdfdf';
	$('cancelcon_'+id).innerHTML = '<img style="float:left;" src="/site/global/images/icons/cancel_16.png"/>';
	
}

function modinputgood(id) {	
	$(id).style.border = '1px solid #D9D9D9';
	$(id).style.background = '#F2F4F3';
	$('cancelcon_'+id).innerHTML = '';

}


  var added = a+b+c+d+e+f+g;
  
  var dowork = added.indexOf('1');

  if(dowork == '-1')return true; else return false;
  
}
