//////////////////////////////////////////
//    Javascript for CI-Contact.html    //
//////////////////////////////////////////

var xmlHttp;
var form = document.frmContact;
var fldName, fldAddress, fldCity, fldState, fldZip, fldPhone, fldEmail;
var Uname, Uaddress, Ucity, Ustate, Uzip, Uphone, Uemail;


// -------------------------------------------------------------------------------
function onclickSubmit()
{
    fldName = document.getElementById("txtName");
    Uname = trimAll(String(fldName.value));
    fldAddress = document.getElementById("txtAddress");
    Uaddress = trimAll(String(fldAddress.value));
    fldCity = document.getElementById("txtCity");
    Ucity = trimAll(String(fldCity.value));
    fldState = document.getElementById("selState");
    Ustate = fldState[fldState.selectedIndex].value;;
    fldZip = document.getElementById("txtZip");
    Uzip = trimAll(String(fldZip.value));
    fldPhone = document.getElementById("txtPhone");
    Uphone = trimAll(String(fldPhone.value));
    fldEmail = document.getElementById("txtEmail");
    Uemail = trimAll(String(fldEmail.value));
    
  //-----------------------------------------------------------
  //----------         field validation          --------------
  //-----------------------------------------------------------


  if (Uname.length == 0)
  {
  	 alert("You must provide your name in order to receive information about Jacobs Ladder.");
  	 document.frmContact.txtName.focus();
  	 return false;
  }
  if (Uaddress.length == 0)
  {
  	 alert("You must provide your mailing address in order to receive information about Jacobs Ladder.");
  	 document.frmContact.txtAddress.focus();
  	 return false;
  }
  if (Ucity.length == 0)
  {
  	 alert("You must provide your mailing address in order to receive information about Jacobs Ladder.");
  	 document.frmContact.txtCity.focus();
  	 return false;
  }
  if (Ustate == 0)
  {
  	 alert("You must provide your mailing address in order to receive information about Jacobs Ladder.");
  	 form.selState.focus();
	 return false;      
  }
  if (Uzip.length == 0)
  {
  	 alert("You must provide your mailing address in order to receive information about Jacobs Ladder.");
  	 document.frmContact.txtZip.focus();
  	 return false;
  }
  if (Uemail.length == 0)
  {
  	 alert("You must provide your email address in order to receive information about Jacobs Ladder.");
  	 document.frmContact.txtEmail.focus();
  	 return false;
  }
  
  //-----------------------------------------------------------
  //----------       end field validation         -------------
  //-----------------------------------------------------------


  ajaxFunction();
  
}
  
// -------------------------------------------------------------------------------
function ajaxFunction()
{ 
    xmlHttp=GetXmlHttpObject();
    if (xmlHttp==null)
    {
       alert("Your browser does not support AJAX!");
       return;
    } 
    
    var url="CI-Contact.aspx?n=";
    url = url + Uname + "&a=" + Uaddress;
    url = url + "&c=" + Ucity + "&s=" + Ustate + "&z=" + Uzip;
    url = url + "&p=" + Uphone + "&e=" + Uemail;
    
    xmlHttp.onreadystatechange = stateChanged;
    xmlHttp.open("GET",url,true);
    xmlHttp.send(null);
}

// -------------------------------------------------------------------------------
function stateChanged() 
{ 
    if (xmlHttp.readyState==4)
    { 
        var returnMsg = xmlHttp.responseText;
        
        if (returnMsg == "OK")
        {
         	//window.open('./CI-InfoResponse.html','','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,copyhistory=no,width=300,height=300,top=300,left=350').focus();
            var strURL = "./CI-ContactComplete.html";
            window.location = strURL;
        }
        else
        {
           //alert(returnMsg);
           alert("An error has occurred while attempting to send your request for additional information.");
        }
    }
}

// -------------------------------------------------------------------------------
function GetXmlHttpObject()
{
    var xmlHttp = null;
    try
    {    
        // Firefox, Opera 8.0+, Safari
        xmlHttp=new XMLHttpRequest(); 
    }
    catch (e)
    {    
        // Internet Explorer 
        try
        {
            xmlHttp=new ActiveXObject("Msxml2.XMLHTTP"); 
        }
        catch (e)
        {
            xmlHttp=new ActiveXObject("Microsoft.XMLHTTP"); 
        }
    }
    return xmlHttp;
}
