function validateEmail(value) {
if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(value)){
return value
} else {
alert('The Email Address is not valid.');
return "";
}
}

function trim( str ) {
var resultStr = "";
resultStr = TrimLeft(str);
resultStr = TrimRight(resultStr);
return resultStr;
}

function TrimLeft( str ) {
var resultStr = "";
var i = len = 0;
if (str+"" == "undefined" || str == null)    
return "";
str += "";

if (str.length == 0) 
resultStr = "";
else {    
len = str.length;
while ((i <= len) && (str.charAt(i) == " "))
i++;
resultStr = str.substring(i, len);
}
return resultStr;
}

function TrimRight( str ) {
var resultStr = "";
var i = 0;
if (str+"" == "undefined" || str == null)    
return "";
str += "";
if (str.length == 0) 
resultStr = "";
else {
i = str.length - 1;
while ((i >= 0) && (str.charAt(i) == " "))
i--;
resultStr = str.substring(0, i + 1);
}

return resultStr; 
}

function validate(form){

if (trim(document.getElementById("first_name").value) == "" || document.getElementById("first_name").value == "First Name")
{ alert("Please, fill the First Name Field"); document.getElementById("first_name").focus(); return; }

if (trim(document.getElementById("last_name").value) == "" || trim(document.getElementById("last_name").value) == "Last Name")
{ alert("Please, fill the Last Name Field"); document.getElementById("last_name").focus(); return; }

if (trim(document.getElementById("address").value) == "Address")
{ alert("Please, fill the Address Field"); document.getElementById("address").focus(); return; }

if (trim(document.getElementById("city").value) == "City")
{ alert("Please, fill the City Field"); document.getElementById("city").focus(); return; }

if (trim(document.getElementById("state").value) == "State")
{ alert("Please, fill the State Field"); document.getElementById("state").focus(); return; }

if (trim(document.getElementById("zip_code").value) == "" || trim(document.getElementById("zip_code").value) == "Zip Code")
{ alert("Please, fill the Zip Code Field"); document.getElementById("zip_code").focus(); return; }

if (trim(document.getElementById("country").value) == "Country")
{ alert("Please, fill the Country Field"); document.getElementById("country").focus(); return; }

var mail = trim(document.getElementById("email_address").value);
mail = validateEmail(trim(document.getElementById("email_address").value));
document.getElementById("email_address").value = mail;
if (mail == "")
{alert("Please, write your Email"); document.getElementById("email_address").focus(); return; }

if (trim(document.getElementById("phone_number").value) == "" || trim(document.getElementById("phone_number").value) == "Phone Number")
{ alert("Please, fill the Phone Field"); document.getElementById("phone_number").focus(); return; }

if (trim(document.getElementById("best_time_to_call").value) == "" || trim(document.getElementById("best_time_to_call").value) == "Best Time To Call")
{ alert("Please, fill the Best time to call Field"); document.getElementById("best_time_to_call").focus(); return; }

if (trim(document.getElementById("store_size").value) == "" || trim(document.getElementById("store_size").value) == "Size of store desired (sq.ft.)")
{ alert("Please, fill the Store size Field"); document.getElementById("store_size").focus(); return; }

/*opciones = document.getElementsByName("found_loc");
var seleccionado = false;
for(var i=0; i<opciones.length; i++) {	
  if(opciones[i].checked) { seleccionado = true;  break; }
}
if(!seleccionado) {
  alert("Please, select yes or no"); document.getElementById("found_loc").focus(); return false;
}

//if (trim(document.getElementById("found_loc").value) == "")
//{ alert("Please, select yes or no"); document.getElementById("found_loc").focus(); return; }

if (trim(document.getElementById("city1").value) == "City")
{ alert("Please, select the City"); document.getElementById("city1").focus(); return; }

if (trim(document.getElementById("state1").value) == "State")
{ alert("Please, select the State"); document.getElementById("state1").focus(); return; }

if (trim(document.getElementById("country2").value) == "Country")
{ alert("Please, select the Country"); document.getElementById("country2").focus(); return; }

opciones = document.getElementsByName("req_finance"); 
var seleccionado = false;
for(var i=0; i<opciones.length; i++) {	
  if(opciones[i].checked) { seleccionado = true;  break; }
}
if(!seleccionado) {
  alert("Please, select yes or no if you require financing"); document.getElementById("req_finance").focus(); return false;
}
//if (document.getElementById("req_finance").checked)
//{ alert("Please, select yes or no if you require financing"); document.getElementById("req_finance").focus(); return; }

opciones = document.getElementsByName("req_visa");
var seleccionado = false;
for(var i=0; i<opciones.length; i++) {	
  if(opciones[i].checked) { seleccionado = true;  break; }
}
if(!seleccionado) {
  alert("Please, select yes or no if you need a USA investment visa"); document.getElementById("req_visa").focus(); return false;
}

//if (document.getElementById("req_visa").checked)
//{ alert("Please, select yes or no if you need a USA investment visa"); document.getElementById("req_visa").focus(); return; }

if (trim(document.getElementById("how_soon").value) == "" || trim(document.getElementById("how_soon").value) == "How soon would you like to open")
{ alert("Please, fill the How soon would you like to open Field"); document.getElementById("how_soon").focus(); return; }*/

if (trim(document.getElementById("comments").value) == "" || trim(document.getElementById("comments").value) == "Comments")
{ alert("Please, fill the comments field"); document.getElementById("comments").focus(); return false; }

var sometext=trim(document.getElementById("seq_ques").value);
var casechanged=sometext.toLowerCase();
var defaulttext="Is Fire Hot or Cold? - This proves you're a person";
defaulttext=defaulttext.toLowerCase();
if (casechanged == defaulttext)
{ alert("Please, fill the Security Question"); document.getElementById("seq_ques").focus(); return false; }
else
if (casechanged != "hot")
{ alert("Please, Answer the correct Security Question"); document.getElementById("seq_ques").focus(); return false; }
else
{document.getElementById("mainform").submit();return true;}
}

