// .----------------------------------------------------------------------------.
// |.--------------------------------------------------------------------------.|
// || This script is the private property of                                   ||
// ||          Mobilit-e Limited (Company Registration Number: 351410)         ||
// ||          Dublin, Ireland                                                 ||
// ||                                                                          ||
// || No use/reuse is permitted without prior written permission of Mobilit-e. ||
// || Written permission is only valid in the form of a legally binding        ||
// ||      software licence contract with Mobilit-e.                           ||
// ||                                                                          ||
// ||                Copyright: 2002,2003,2004                                      ||
// |'--------------------------------------------------------------------------'|
// '----------------------------------------------------------------------------'
//
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

 function checkfieldforblanks(buildproductlist) {

	if (buildproductlist.CollectionSearch.value==""){
	alert("Please enter a value.");
	buildproductlist.CollectionSearch.focus();
	return false;
	}

return true;

} 

function ValidateDetails()
{

  // Enter name of mandatory fields
  var fieldRequired = Array("firstname", "lastname", "position", "phoneno", "email", "companyname", "department", "accountno", "addressline1", "addresstown", "addresscounty");
  var fieldList = Array("firstname", "lastname", "position", "phoneno", "email", "companyname", "department", "accountno", "addressline1", "addressline2", "addressline3", "addresstown", "addresscounty");

  // Enter field description to appear in the dialog box
  var fieldDescription = Array("First Name", "Last Name", "Position", "Phone Number", "Email", "Company Name", "Department", "Reagecon Account No", "Address Line 1", "Town", "County");
  
  // Variable for account number and address validation
  var hasAccount = true;
  var hasAddress = true;

  // dialog message
  var alertMsg = "Please complete the following for registration.\n";
  var l_Msg = alertMsg.length;

  for (var i = 0; i < fieldRequired.length; i++)
  {

    var obj = document.forms[1].elements[fieldRequired[i]];

    if (obj.value == "" || obj.value == null)
    {
      // Check mandatory fields
      if (i <= 6)
      {  
        alertMsg += " - " + fieldDescription[i] + "\n";
      }
      else
      {
        // Is there an account number 
        if (i == 7)
        {
          hasAccount = false;
        }
        else
        {
          // If no account number, address details must be supplied
          if (i > 7 && hasAccount == false)
          {  
            hasAddress = false; 
          } 
        } 
      } 
    }  
  }

  if (hasAddress == false)
  {
    alertMsg += " ------------- \n" + "Please enter account no or \n" + "full address details.";
  }

if (document.forms[1].email.value.indexOf("@") == -1 || document.forms[1].email.value.indexOf(".") == -1) {
alertMsg += " ------------- \n" + "Please include a proper email address.";
}

  if (alertMsg.length == l_Msg)
  {
	
     var Firstname = '&Firstname=' + document.forms[1].firstname.value;
     var Lastname = '&Lastname=' + document.forms[1].lastname.value;
     var Position = '&Position=' + document.forms[1].position.value;
     var Companyname = '&Companyname=' + document.forms[1].companyname.value;
     var Department = '&Department=' + document.forms[1].department.value;
     var Accountnumber = '&Accountnumber=' + document.forms[1].accountno.value;
     var Adr1 = '&Adr1=' + document.forms[1].addressline1.value;
     var Adr2= '&Adr2=' + document.forms[1].addressline2.value;
     var Adr3= '&Adr3=' + document.forms[1].addressline3.value;
     var Town = '&Town=' +document.forms[1].addresstown.value;
     var County = '&County=' + document.forms[1].addresscounty.value;
     var EMail = '&EMail=' + document.forms[1].email.value;
     var Phonenumber = '&Phonenumber=' + document.forms[1].phoneno.value;
     var date = new Date();
     var d  = date.getDate();
     var day = (d < 10) ? '0' + d : d;
     var m = date.getMonth() + 1;
     var month = (m < 10) ? '0' + m : m;
     var yy = date.getYear();
     var year = (yy < 1000) ? yy + 1900 : yy;
     var dateClicked = '&Date=' + (day + "/" + month + "/" + year);
    
     var message = 'http://www.reagecon.com/perspective/httplisten.php?command=REAGECONREGISTER' +  Firstname + Lastname + Position + Companyname + Department + Accountnumber + Adr1 + Adr2 + Adr3 + Town + County + EMail + Phonenumber + dateClicked;
      
     //Call loadXMLDoc function     
     loadXMLDoc(message)
	
     //Tidy up and clear fields

    for (var x = 0; x < fieldList.length; x++)
    {
      var obj2 = document.forms[1].elements[fieldList[x]];
      obj2.value = "";
    }


    document.forms[1].onsubmit = cancelSubmit;
    //alert(message);	
    //return true;

  }
  else
  {
    alert(alertMsg);
    return false;
  }
}
 

var xmlhttp
function loadXMLDoc(url)
{
// code for Mozilla, etc.
if (window.XMLHttpRequest)
  {
  xmlhttp=new XMLHttpRequest()
  xmlhttp.onreadystatechange=xmlhttpChange
  xmlhttp.open("GET",url,true)
  xmlhttp.send(null)
  alert("Thank you for registering with Reagecon. \n You will be contacted shortly..");
  }
// code for IE
else if (window.ActiveXObject)
  {
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP")
    if (xmlhttp)
    {
    xmlhttp.onreadystatechange=xmlhttpChange
    xmlhttp.open("GET",url,true)
    xmlhttp.send()
alert("Thank you for registering with Reagecon. \n You will be contacted shortly.");
    }
  }
}

//Error handling

function xmlhttpChange()
{
// if xmlhttp shows "loaded"
if (xmlhttp.readyState==4)
  {
  // if "OK"
  if (xmlhttp.status==200)
    {
    // ...some code here
	
    }
  else
    {
    alert("Problem retrieving XML data")
    }
  }
}
