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


function validate(form) {
  var txt_name = form.txt_name.value;
  var txt_company = form.txt_company.value;
  var txt_phone = form.txt_phone.value;
  var txt_email = form.txt_email.value;
  var txt_topic = form.txt_topic.value;
  var lst_importance = form.lst_importance.value;
  var txta_message = form.txta_message.value;
 
  var emailRegex = /^[\w-\.]+@([\w-]+\.)+[\w-]{2,4}$/;
  var reWhiteSpace = new RegExp(/^\s+$/);

 // TOPIC /////////////////////////
  
  if(txt_name == "" || reWhiteSpace.test(txt_name) == true) {
 	
    modinputbad('txt_name');
    var a = "1";
   }else {
    
  modinputgood('txt_name');
     var a = "0";
  }
 
  // COMPANY /////////////////////////
  if(txt_company == "" || reWhiteSpace.test(txt_company) == true) {
    modinputbad('txt_company');
    var b = "1";
    }else {
  modinputgood('txt_company');
     var b = "0";
  }
  
  // txt_phone /////////////////////////
  if(txt_phone == "" || reWhiteSpace.test(txt_phone) == true) {
    modinputbad('txt_phone');
    var c = "1";
   }else {
  modinputgood('txt_phone');
     var c = "0";
  }

  
  /// EMAIL /////////////////////////
  if(txt_email == "" || !txt_email.match(emailRegex)) {
    modinputbad('txt_email');
      var d = "1";
  }else {
     modinputgood('txt_email');
      var d = "0";
  }
 
  // PHONE /////////////////////////
  if(txt_topic == "" || reWhiteSpace.test(txt_topic) == true) {
    modinputbad('txt_topic');
    var e = "1";
    }else {
  modinputgood('txt_topic');
     var e = "0";
  }
 
  //lst_importance  /////////////////////////
  if(lst_importance == "") {

    modinputbad('lst_importance');
	var f = "1";
  }else{
    modinputgood('lst_importance');
	var f = "0";
  }

  
  //MESSAGE  /////////////////////////
  if(txta_message == "" || reWhiteSpace.test(txta_message) == true) {

    modinputbad('txta_message');
	var g = "1";
  }else{
    modinputgood('txta_message');
	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;
  
}
