// JavaScript Document
function FrontPage_Form1_Validator(theForm) {

  if (theForm.first_name.value == "")
  {
    alert("Please enter your first name.");
    theForm.first_name.focus();
    return (false);
  }

  if (theForm.last_name.value == "")
  {
    alert("Please enter your last name.");
    theForm.last_name.focus();
    return (false);
  }
  
  if (theForm.title.value == "")
  {
    alert("Please enter your title.");
    theForm.title.focus();
    return (false);
  }  

  if (theForm.email.value == "")
  {
    alert("Please enter your email.");
    theForm.email.focus();
    return (false);
  }  

  if (theForm.company.value == "")
  {
    alert("Please enter your company.");
    theForm.company.focus();
    return (false);
  }  
  
  if (theForm.type_organization.value == "")
  {
    alert("Please indicate your type of organization");
    theForm.type_organization.focus();
    return (false);
  }

 if (theForm.street.value == "")
  {
    alert("Please enter your address.");
    theForm.street.focus();
    return (false);
  }
  
  if (theForm.city.value == "")
  {
    alert("Please enter your city.");
    theForm.city.focus();
    return (false);
  }  
  
	if (theForm.state.value == "")
  {
    alert("Please select your state.");
    theForm.state.focus();
    return (false);
  }
  
  if (theForm.zip.value == "")
  {
    alert("Please enter your zip.");
    theForm.zip.focus();
    return (false);
  }  
  
  if (theForm.country.value == "")
  {
    alert("Please select your country.");
    theForm.country.focus();
    return (false);
  }
    


// creating job var, getting all the job elements, iterate all job elements, find checked value, set variable to checked value, one first value quit loop
var job = null;
var els = document.getElementsByName("job");
for (var i=0; i<els.length; i++){
	var el = els[i];
	if (el.checked)
	{
		job=el.value;
		break;
	}	
}
// check if other is selected, if so, put it here
if (job=="Other")
	{
	job= document.getElementsByName("other")[0].value;
	}

// creating subscription var, getting all the subscription elements, iterate all subscription elements, find checked value, set variable to checked value, one first value quit loop
var subscript = null;
var els = document.getElementsByName("subscription");
for (var i=0; i<els.length; i++){
	var el = els[i];
	if (el.checked)
	{
		subscript=el.value;
		break;
	}		
}

// creating resp var, getting all the job elements, iterate all job elements, find checked value, set variable to checked value, append value quit loop
var resp = "";
var els = document.getElementsByName("responsibilities");
for (var i=0; i<els.length; i++){
	var el = els[i];
	if (el.checked)
	{
		resp+=el.value+ ", ";
		
	}
}

//set description by combining 3 fields in form
document.getElementsByName("description")[0].value= "PEJ Subscription: " + subscript + " " + "| Job: " + job + " " + "| Responsibilities: " + resp;
//alert(document.getElementsByName("description")[0].value);

if (theForm.country.value == "United States")
   {
   document.getElementsByName("retURL")[0].value = "http://www.performance-edge-journal.com/subscribe_thanks.html";
   }
else if (theForm.country.value == "Canada")
   {
   document.getElementsByName("retURL")[0].value = "http://www.performance-edge-journal.com/subscribe_thanks.html";
   }
else
   {
   document.getElementsByName("retURL")[0].value = "http://www.performance-edge-journal.com/subscribe_thanks_global.html";   
   }

theForm.submit.disabled=true;
document.getElementsByName('submit')[0].disabled=true;
 
return true;
}