//check e-mail address
function checkEmail(checkString){
    var newString = "";
    var at = false;
    var dot = false;
    // if e-mail has '@'
    if (checkString.indexOf("@") != -1) {
      at = true;
    } 
    // if e-mail has '.'
    else if (checkString.indexOf(".") != -1) {
      dot = true;
    }
    // parse remainder of the string
    for (var i = 0; i < checkString.length; i++) {
        ch = checkString.substring(i, i + 1)
        if ((ch >= "A" && ch <= "Z") || (ch >= "a" && ch <= "z")
                || (ch == "@") || (ch == ".") || (ch == "_")
                || (ch == "-") || (ch >= "0" && ch <= "9")) {
                newString += ch;
                if (ch == "@") {
                    at=true;
                }
                if (ch == ".") {
                    dot=true;
                }
        }
    }
    if ((at == true) && (dot == true) && (checkString.length>=7)) {
        return true;
    }
    else {
      // display error message
      return false;
    }
}
function valid(form) {

	  requiredFieldColor = '#66AF89';
	  missingFields = false;
	  
	  if (form.name.value=='') {
	    form.name.style.backgroundColor=requiredFieldColor;
		missingFields = true;
	  }else {
	    form.name.style.backgroundColor='';
	  }

	  document.getElementById("reqLabel3").style.display = "none";
	  if (form.emailAddr.value=='') {
		form.emailAddr.style.backgroundColor=requiredFieldColor;
		missingFields = true;
		badEmail = true;
	  }else {
	    if (checkEmail(form.emailAddr.value) == false) {
	    	document.getElementById("reqLabel3").style.display = "inline";
			form.emailAddr.style.backgroundColor=requiredFieldColor;
	    	missingFields = true;
			badEmail = true;
	    }else {  
			form.emailAddr.style.backgroundColor='';
			badEmail = false;
		}
	  }  
	  
	  document.getElementById("reqLabel4").style.display = "none";
	  if (form.confirmEmailAddr.value=='') {
	    form.confirmEmailAddr.style.backgroundColor=requiredFieldColor;
		missingFields = true;
		badConfirmEmail = true;
	  }else {
	    if (checkEmail(form.confirmEmailAddr.value) == false) {
	    	document.getElementById("reqLabel4").style.display = "inline";
			form.confirmEmailAddr.style.backgroundColor=requiredFieldColor;
	    	missingFields = true;
			badConfirmEmail = true;
	    }else {  
			form.confirmEmailAddr.style.backgroundColor='';
			badConfirmEmail = false;
		}
	  }
	  
	  document.getElementById("reqLabel2").style.display = "none";
	  if (form.emailAddr.value!='' && form.confirmEmailAddr.value!='') {
	  	if (form.emailAddr.value != form.confirmEmailAddr.value) {
			form.emailAddr.style.backgroundColor=requiredFieldColor;
	    	form.confirmEmailAddr.style.backgroundColor=requiredFieldColor;
	    	document.getElementById("reqLabel2").style.display = "inline";
	    	missingFields = true;
	     }else {
		 	if (!badEmail && !badConfirmEmail) {
	        	form.emailAddr.style.backgroundColor='';
	        	form.confirmEmailAddr.style.backgroundColor='';
	     }	}
	  }
	  
	  if (form.product.value=="") {
	    form.product.style.backgroundColor=requiredFieldColor;
		missingFields = true;
	  }else {
	    form.product.style.backgroundColor='';
	  }
	  
	  if (form.zip.value=='') {
	    form.zip.style.backgroundColor=requiredFieldColor;
		missingFields = true;
	  }else {
	    form.zip.style.backgroundColor='';
	  }
	  
	  if (form.subject.value=='') {
	    form.subject.style.backgroundColor=requiredFieldColor;
	 	missingFields = true;
	  }else {
	    form.subject.style.backgroundColor='';
	  }

	  if (form.comment.value=='') {
	    form.comment.style.backgroundColor=requiredFieldColor;
	 	missingFields = true;
	  }else {
	    form.comment.style.backgroundColor='';
	  }

	  if (missingFields) {
	  	document.getElementById("reqLabel1").style.display = "inline";
		return false;
	  }else {
	     return true;
	  }

	}

function validateExpert(form) {

	  requiredFieldColor = '#66AF89';
	  missingFields = false;
	  
	  if (form.name.value=='') {
	    form.name.style.backgroundColor=requiredFieldColor;
		missingFields = true;
	  }else {
	    form.name.style.backgroundColor='';
	  }

	  document.getElementById("reqLabel3").style.display = "none";
	  if (form.emailAddr.value=='') {
		form.emailAddr.style.backgroundColor=requiredFieldColor;
		missingFields = true;
	  }else {
	    if (checkEmail(form.emailAddr.value) == false) {
	    	document.getElementById("reqLabel3").style.display = "inline";
			form.emailAddr.style.backgroundColor=requiredFieldColor;
	    	missingFields = true;
	    }else {  
			form.emailAddr.style.backgroundColor='';
		}
	  }  
	  
	  if (form.state.value=="") {
	    form.state.style.backgroundColor=requiredFieldColor;
		missingFields = true;
	  }else {
	    form.state.style.backgroundColor='';
	  }
	  
	  if (form.question.value=='') {
	    form.question.style.backgroundColor=requiredFieldColor;
		missingFields = true;
	  }else {
	    form.question.style.backgroundColor='';
	  }
	  
	  if (missingFields) {
	  	document.getElementById("reqLabel1").style.display = "inline";
		return false;
	  }else {
	     return true;
	  }
	  
	}

function validateFriend(form) {

	  requiredFieldColor = '#66AF89';
	  missingFields = false;
	  
	  document.getElementById("reqLabel2").style.display = "none";
	  if (form.txtSenderEmail.value=='') {
		form.txtSenderEmail.style.backgroundColor=requiredFieldColor;
		missingFields = true;
	  }else {
	    if (checkEmail(form.txtSenderEmail.value) == false) {
	    	document.getElementById("reqLabel2").style.display = "inline";
			form.txtSenderEmail.style.backgroundColor=requiredFieldColor;
	    	missingFields = true;
	    }else {  
			form.txtSenderEmail.style.backgroundColor='';
		}
	  } 
	  
	  if (form.txtSenderName.value=="") {
	    form.txtSenderName.style.backgroundColor=requiredFieldColor;
		missingFields = true;
	  }else {
	    form.txtSenderName.style.backgroundColor='';
	  }
	  
	  document.getElementById("reqLabel3").style.display = "none";
	  if (form.txtRecipientEmail.value=='') {
		form.txtRecipientEmail.style.backgroundColor=requiredFieldColor;
		missingFields = true;
	  }else {
	    if (checkEmail(form.txtRecipientEmail.value) == false) {
	    	document.getElementById("reqLabel3").style.display = "inline";
			form.txtRecipientEmail.style.backgroundColor=requiredFieldColor;
	    	missingFields = true;
	    }else {  
			form.txtRecipientEmail.style.backgroundColor='';
		}
	  } 

	  if (form.txtRecipientName.value=="") {
		    form.txtRecipientName.style.backgroundColor=requiredFieldColor;
			missingFields = true;
		  }else {
		    form.txtRecipientName.style.backgroundColor='';
		  }
		  
	  if (missingFields) {
	  	document.getElementById("reqLabel1").style.display = "inline";
		return false;
	  }else {
	     return true;
	  }
	  
	}

