// email

function checkEmail (strng) {
var error="";
if (strng == "") {
   error = "Please enter an email address.\n";
}

    var emailFilter=/^.+@.+\..{2,3}$/;
    if (!(emailFilter.test(strng))) { 
       error = "Please enter a valid email address.\n";
    }
    else {
//test email for illegal characters
       var illegalChars= /[\(\)\<\>\,\;\:\\\"\[\]]/
         if (strng.match(illegalChars)) {
          error = "The email address contains illegal characters.\n";
       }
    }
return error;    
}

// non-empty textbox

function isEmpty(strng,fieldname) {
var error = "";
  if (strng.length == 0) {
     error = fieldname + " has not been filled in.\n"
  }
return error;	  
}

// valid selector from dropdown list

function checkDropdown(choice) {
var error = "";
    if (choice == 0) {
    error = "Please choose a state.\n";
    }    
return error;
}   
function checkPosition(choice) {
var error = "";
    if (choice == "Please select") {
    error = "Please choose a position.\n";
    }
return error;
}


 
function checkHear(choice) {
var error = "";
    if (choice == "Please select") {
    error = "Please choose how did you hear about Virtual Radiologic.\n";
    }
return error;
}

// check for checked checkbox
function checkboxChoose(item) {
	var error = "";
	var _flag = false;
	for (var _i=0; _i<item.length; _i++) {
		if(item[_i].checked){
			_flag = true;
		};
	}
    if (_flag == false) {
    	error = "Please choose what are you interested in.\n";
    } 
	
	
	
return error;
} 

function addInterestItemToHidden(sender,txt) {
	var f = $("#_hdnTbInterests");
	var vals = f.val();
	if(sender.checked) {
		if(vals == "") vals = txt; else vals += "," + txt;
		f.val(vals);
	}
	else {
		var valArray = vals.split(',');
		vals = "";
		for(var i = 0; i < valArray.length; i++) {
			if(valArray[i] != txt) {
				if(vals == "") vals = valArray[i]; else vals += "," + valArray[i];
			}
		}
		f.val(vals);
	}
}


function checkQuoteForm(theForm) {
	var why = "";
    why += isEmpty(theForm._tbFirstName.value,"First Name");
    why += isEmpty(theForm._tbLastName.value,"Last Name");
	why += isEmpty(theForm._tbCompanyName.value,"Company Name");
 	why += isEmpty(theForm._tbAddress1.value,"Address 1");
 	why += isEmpty(theForm._tbCity.value,"City");
 	why += checkDropdown(theForm._tbstate.value);
 	why += isEmpty(theForm._tbzip.value,"Zip");
 	why += checkEmail(theForm._tbEmail.value);
	why += checkPosition(theForm._tbposition.value);
	why += checkHear(theForm._tbother.value);
	why += checkboxChoose(theForm._tbineterest);
    if (why != "") {
       alert(why);
       return false;
    }
return true;
}

function checkRequestForm(theForm) {
 var why = "";
    why += isEmpty(theForm._tbFirstName.value,"First Name");
    why += isEmpty(theForm._tbLastName.value,"Last Name");
	why += isEmpty(theForm._tbCompanyName.value,"Company Name");
 	why += isEmpty(theForm._tbAddress1.value,"Address 1");
 	why += isEmpty(theForm._tbCity.value,"City");
 	why += checkDropdown(theForm._tbstate.value);
 	why += isEmpty(theForm._tbzip.value,"Zip");
 	why += checkEmail(theForm._tbEmail.value);
	why += checkPosition(theForm._tbposition.value);
	why += checkHear(theForm._tbother.value);
	why += checkboxChoose(theForm._tbineterest);
 	if (why != "") {
       alert(why);
       return false;
    }
return true;
}

function checkFormEmail(theForm) {
 var why = "";;
 	why += checkEmail(theForm._nlEmail.value);		 	         
 	if (why != "") {
       alert(why);
       return false;
    }
return true;
}

function toggleForms() {
	radios = document.getElementsByName('formtoggle');
	if (radios[0].checked) { 
		document.getElementById('quote').style.display = "block";
		document.getElementById('general').style.display = "none";
		 }
	if(radios[1].checked) { 
		document.getElementById('quote').style.display = "none";
		document.getElementById('general').style.display = "block";
		 }
	}