//-- FILENAME: checkContactForm.js --//
//-- $Name: Release_7-8 $ --//
//-- $Header: /CVSRepositories/TSI_WebSite/JS_Repository/checkContactForm.js,v 1.15 2011/01/13 17:17:10 TSI Exp $ --//
//--                  Copyright 2004 - 2011 TurnSignal Inc. All Rights Reserved.                                  --//
//--==============================================================================================================--//
/*
    contact_trnsgnl.php   name="ContactTsForm"
    contact_mrsftr.php    name="ContactMsFsForm"
    contact_njatrd.php    name="ContactNjTdForm"
    contact_trdstn.php    name="ContactTrSnForm"
    contact_esgnl.php     name="ContactEsForm"
    RefCdeReqForm.html    name="ReqRefCode"
*/
function checkContactForm(theForm) {
if(Test_Mode) { alert("Test_Mode--Entering checkContactForm() W/ Form Name--:" + theForm.name + ":--\n opsMode--:" + opsMode + ":--\n oururl--:" + oururl + ":--"); }
//
  var pos = oururl.lastIndexOf("/");
  var len = oururl.length;
  var basePath =  oururl.substring(0,pos);
  var scriptName = oururl.substring(pos+1, len);
  pos = scriptName.indexOf("#");
  if (pos > 0) {
    scriptName = scriptName.substring(0, pos);
  }
//if (Test_Mode) { alert("Test_Mode--Base Path: " + basePath + "\nScript Name: " + scriptName); }
//
  if ((theForm.name == "ContactTrSnForm" || theForm.name == "ContactMsFsForm") && opsMode == "freetrial") {
    if(theForm.AccountType[0].checked == false && theForm.AccountType[1].checked == false) {
      alert("Please select an Account type!");
      theForm.AccountType[0].focus();
      return false;
     }
  }
//
  if (theForm.CustName.value == "") {
    alert("Please tell us your Name!");
    theForm.CustName.focus();
    return false;
  }
//
	if (theForm.DayFone.value == "") {
	  alert("Please tell us your day-time phone number!");
	  theForm.DayFone.focus();
	  return false;
	} else {
	  var valid = check4number(theForm.DayFone.value);
	  if (!valid) {
	    alert("Numbers and spaces only in phone number.");
	    theForm.DayFone.value = "";
	    theForm.DayFone.focus();
	    return false;
	  }
	}
//
  if (theForm.Email1.value == "") {
    alert("Please tell us the email address where you would like us to respond.");
    theForm.Email1.focus();
    return false;
  } else {
    var valid = check4spcl(theForm.Email1.value);
    if (!valid) {
      alert("Entered email address does not appear to be valid!");
      theForm.Email1.value = "";
			theForm.Email1.focus();
      return false;
    } else {
      if (theForm.Email2.value != theForm.Email1.value) {
        alert("\"eMail\"  and  \"Confirm eMail\" must MATCH!");
				theForm.Email2.focus();
				theForm.Email2.select();
        return false;
      }
    }
  }
//
  if (theForm.name !== "ReqRefCode") {
	  var i;
	  var picked ="";
	  for (i = 0; i<= 2;i++) {
	    if(theForm.TraderType[i].checked == true) {
	      picked = theForm.TraderType[i].value
	    }
	  }
	  if (picked == "") {
	    alert("Please indicate the type of trader you are!");
	    return false
	  }
	  if (picked == "Corporate" || picked == "Professional") {
	    if (theForm.Company.value == "") {
	      alert("Professional/Corporate Traders please tell us your Company affiliation.");
	      theForm.Company.focus();
	      return false;
	    }
	  } else {
      theForm.Company.value = "N/A For Individuals";
    }
	//
    picked ="";
    for (i = 0; i<= 2;i++) {
      if(theForm.Experience[i].checked == true) {
        picked = theForm.TraderType[i].value
      }
    }
    if (picked == "") {
      theForm.Experience[0].value = "-not set-";
      theForm.Experience[0].checked = true;
    }
  //
	  if (theForm.Markets.value == "") {
      theForm.Markets.value = "-not set-";
    }
  //
	  if (theForm.Subject.value == "") {
	    alert("Please tell us a Subject.");
	    theForm.Subject.focus();
	    return false;
	  }
	  if (theForm.Message.value == "") {
	    alert("Don't forget to enter your Question or Comment.");
	    theForm.Message.focus();
	    return false;
	  }
  }

//
  if (theForm.name == "ContactTrSnForm" && opsMode == "freetrial") {
    var freeTrial = false;
    if (theForm.AccountType[0].checked == true) { freeTrial = true; }
    if (freeTrial) {
	    if (!theForm.readterms.checked) {
	      alert("Please Read terms of the Introductory Offer.");
	      theForm.readterms.focus();
	      return false;
	    }
	  } else {
	    theForm.readterms.value = "-NotChecked-";
	  }
  }
//
  if (theForm.name == "ContactTsForm") {
    var target = basePath + "/thanks_trnsgnl.php?" + oururl + "~" + opsMode;
  }
  if (theForm.name == "ContactEsForm") {
    var target = basePath + "/thanks_esgnl.php?" + basePath + "/" + scriptName + "~" + opsMode;
  }
  if (theForm.name == "ContactTrSnForm") {
    var target = basePath + "/thanks_trdstn.php?" + basePath + "/" + scriptName + "~" + opsMode;
  }
  if (theForm.name == "ContactNjTdForm") {
    var target = basePath + "/thanks_njatrd.php?" + basePath + "/" + scriptName + "~" + opsMode;
  }
  if (theForm.name == "ContactMsFsForm") {
    var target = basePath + "/thanks_mrsftr.php?" + basePath + "/" + scriptName + "~" + opsMode;
  }
  if (theForm.name == "ReqRefCode") {
    var target = basePath + "/RefCdeReqProc.php?" + basePath + "/" + scriptName + "~" + opsMode;
  }
  theForm.action = target;
  theForm.control.value = document.cookie;
//
  if (Test_Mode) {
    var answer = confirm("Test_Mode--checkContactForm() complete W/ target--|" + theForm.action + "|--")
	  if (answer){
		  theForm.submit();
	  }
	} else {
	  theForm.submit();
	}
}  //end function checkContactForm()
