/* 
  swap images by placing off/on flags according to what reference is passed 0/1 
*/
function rollOver(imageName, ref){
  var imageName, ref;
	var image_obj;
	
	image_obj = eval("document." + imageName);
	
	switch (ref){
	  case 1: image_obj.src = eval(imageName + "_on"+ ".src"); break;
	  case 0: image_obj.src = eval(imageName + "" + ".src"); break;
	  default: // do nothing here . . . . 
	}
}

/*----------------------------------------------------------------
Activate and Deactivate the Billing section on the applicaton form
<content_apply.php>
----------------------------------------------------------------*/
function DeactivateBilling(){
  var fieldObj;
  
  for(var i = 0; i < document.applicationFrm.elements.length; i++){
     if(document.applicationFrm.elements[i].name.indexOf("billing_") != -1){
	   fieldObj = eval("document.applicationFrm." + document.applicationFrm.elements[i].name);
	   fieldObj.disabled = true;
	   fieldObj.style.backgroundColor = "#CCCCCC";
	 }
  } 
  if(!document.applicationFrm.same_as_billing.checked){
     ActivateBilling();
  }
  
}

function ActivateBilling(){ 
   for(var i = 0; i < document.applicationFrm.elements.length; i++){
     if(document.applicationFrm.elements[i].name.indexOf("billing_") != -1){
	   fieldObj = eval("document.applicationFrm." + document.applicationFrm.elements[i].name);
	   fieldObj.disabled = false;
	   fieldObj.style.backgroundColor = "#FFFFFF";
	 }
   }
}


/*----------------------------------------------------------------
Activate and Deactivate the Industrial section on the applicaton form
<content_apply_2.php>
----------------------------------------------------------------*/
function DeactivateIndustrialOther(){
  var fieldObj;
  
   fieldObj = eval("document.applicationFrm.industry_other_specify");
	   fieldObj.disabled = false;
	   fieldObj.style.backgroundColor = "#FFFFFF";
	   
 
  if(!document.applicationFrm.industry_other.checked){
     ActivateIndustrialOther();
  }
  
}

function ActivateIndustrialOther(){ 
  
    
	   fieldObj = eval("document.applicationFrm.industry_other_specify");
	   fieldObj.value ="";
	   fieldObj.disabled = true;
	   fieldObj.style.backgroundColor = "#CCCCCC";
	  
	 
}


/*----------------------------------------------------------------
Write status text to browser status bar on bottom
----------------------------------------------------------------*/
function setStatusBarText(strText){
  var strText;
  
  window.defaultStatus = "Welcome to Plastic Welding School LLC";  
  window.status = strText;
  
}

/*----------------------------------------------------------------
Open pop up window
----------------------------------------------------------------*/
function popWindow(urlText){
  var urlText;
  window.open(urlText,'APPL','width=750,top=50,left=350,resizable,scrollbars');
}

/*----------------------------------------------------------------
Replace the current URI of any web page with a new one using the
following function
----------------------------------------------------------------*/
function directUser(refURL){
  var refURL;
  
  location.replace(refURL);
}


/*----------------------------------------------------------------
Verify if the email address value passed is valid.
We are not using an SMTP validation. We cann't control totally
what people actually write down as email addresses
----------------------------------------------------------------*/
function isEmail(refEmail){
  var refEmail;
  
  if(refEmail.indexOf("@") == -1 || refEmail.indexOf(".") == -1){
     return false;
    }
  return true;
}


/*----------------------------------------------------------------
Validate form input on the contact us form <content_contact.php>
----------------------------------------------------------------*/
function validateForm(refForm){
  var refForm;
  var objForm;
  
  objForm = eval("document." + refForm);
  
  if(objForm.last_name && objForm.last_name.value == ""){
    alert("Please enter your Last Name!");
	objForm.last_name.focus();
    return false
  }
  
  if(objForm.first_name && objForm.first_name.value == ""){
    alert("Please enter your First Name!");
	objForm.first_name.focus();
    return false
  }
  
  if(objForm.address1 && objForm.address1.value == ""){
    alert("Please enter your Street Address!");
	objForm.address1.focus();
    return false
  }
  
  if(objForm.city && objForm.city.value == ""){
    alert("Please enter your City Name!");
	objForm.city.focus();
    return false
  }
  
  if(objForm.state && objForm.state.value == "NA"){
    alert("Please select your State Name!");
	objForm.state.focus();
    return false
  }
   
  if(objForm.zip_code && objForm.zip_code.value == ""){
    alert("Please Enter your Zip Code!");
	objForm.zip_code.focus();
    return false
  }
  
  if(objForm.country && objForm.country.value == "NA"){
    alert("Please select your Country Name!");
	objForm.country.focus();
    return false
  }
  
  if(objForm.phone && objForm.phone.value == ""){
    alert("Please enter your Phone Number!");
	objForm.phone.focus();
    return false
  }
  
  if((objForm.email && objForm.email.value == "") || !isEmail(objForm.email.value)){
    alert("Please enter your Email Account!");
	objForm.email.focus();
    return false
  }
  return true;
  
  
}


/*----------------------------------------------------------------
Validate form data of the application form <content_apply[2,3,4].php>
I wanted to seperate this validation function from the one above
----------------------------------------------------------------*/
function validateAppForm(refForm){
  var refForm;
  var objForm;
  
  objForm = eval("document." + refForm);
  
  //Student fields
  if(objForm.last_name && objForm.last_name.value == ""){
    alert("Please enter your Last Name!");
	objForm.last_name.focus();
    return false
  }
  
  if(objForm.first_name && objForm.first_name.value == ""){
    alert("Please enter your First Name!");
	objForm.first_name.focus();
    return false
  }
  
  if(objForm.address1 && objForm.address1.value == ""){
    alert("Please enter your Street Address!");
	objForm.address1.focus();
    return false
  }
  
  if(objForm.city && objForm.city.value == ""){
    alert("Please enter your City Name!");
	objForm.city.focus();
    return false
  }
  
  if(objForm.state && objForm.state.value == "NA"){
    alert("Please select your State Name!");
	objForm.state.focus();
    return false
  }
   
  if(objForm.zip_code && objForm.zip_code.value == ""){
    alert("Please Enter your Zip Code!");
	objForm.zip_code.focus();
    return false
  }
  
  if(objForm.country && objForm.country.value == "NA"){
    alert("Please select your Country Name!");
	objForm.country.focus();
    return false
  }
  
  if(objForm.phone && objForm.phone.value == ""){
    alert("Please enter your Phone Number!");
	objForm.phone.focus();
    return false
  }
  
  if((objForm.email && objForm.email.value == "") || !isEmail(objForm.email.value)){
    alert("Please enter your Email Account!");
	objForm.email.focus();
    return false
  }
  
  //Company Fields
  /*
  if(objForm.company_name && objForm.company_name.value == ""){
    alert("Please enter your Company Name!");
	objForm.company_name.focus();
    return false
  }
  
  if(objForm.company_address1 && objForm.company_address1.value == ""){
    alert("Please enter your Company Street Address!");
	objForm.company_address1.focus();
    return false
  }
  
  if(objForm.company_city && objForm.company_city.value == ""){
    alert("Please enter your Company City Name!");
	objForm.company_city.focus();
    return false
  }
  
  if(objForm.company_state && objForm.company_state.value == "NA"){
    alert("Please select your Company State Name!");
	objForm.company_state.focus();
    return false
  }
   
  if(objForm.company_zip_code && objForm.company_zip_code.value == ""){
    alert("Please Enter your Company Zip Code!");
	objForm.company_zip_code.focus();
    return false
  }
  
  if(objForm.company_country && objForm.company_country.value == "NA"){
    alert("Please select your Company Country Name!");
	objForm.company_country.focus();
    return false
  }
  
  if(objForm.contact_phone && objForm.contact_phone.value == ""){
    alert("Please enter your Contact Phone Number!");
	objForm.contact_phone.focus();
    return false
  }
  
  if((objForm.contact_email && objForm.contact_email.value == "") || !isEmail(objForm.contact_email.value)){
    alert("Please enter your Contact Email Account!");
	objForm.contact_email.focus();
    return false
  }
  */
  
  //Billing Fields if enabled
  if(objForm.same_as_billing && !objForm.same_as_billing.checked){
  if(objForm.billing_address1 && objForm.billing_address1.value == ""){
    alert("Please enter your Billing Street Address!");
	objForm.billing_address1.focus();
    return false
  }
  
  if(objForm.billing_city && objForm.billing_city.value == ""){
    alert("Please enter your Billing City Name!");
	objForm.billing_city.focus();
    return false
  }
  
  if(objForm.billing_state && objForm.billing_state.value == "NA"){
    alert("Please select your Billing State Name!");
	objForm.billing_state.focus();
    return false
  }
   
  if(objForm.billing_zip_code && objForm.billing_zip_code.value == ""){
    alert("Please Enter your Billing Zip Code!");
	objForm.billing_zip_code.focus();
    return false
  }
  
  if(objForm.billing_country && objForm.billing_country.value == "NA"){
    alert("Please select your Billing Country Name!");
	objForm.billing_country.focus();
    return false
  }
  
  if(objForm.billing_phone && objForm.billing_phone.value == ""){
    alert("Please enter your Billing Phone Number!");
	objForm.billing_phone.focus();
    return false
  }
  }
 
  
  return true;
  
  
}

