// JavaScript Document
  var called_already = false;
  var xmlHttp = false;
/*@cc_on @*/
/*@if (@_jscript_version >= 5)
try {
  xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
  try {
    xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
  } catch (e2) {
    xmlHttp = false;
  }
}
@end @*/

if (!xmlHttp && typeof XMLHttpRequest != 'undefined') {
  xmlHttp = new XMLHttpRequest();
}

function callServer() 
{
  // Get the name and email from the web form
  var name = document.getElementById("strQuickName").value;
  var email = document.getElementById("strQuickEmail").value;
  var trackingid = document.getElementById("trackingid").value;

  // Build the URL to connect to
  
var params = "strQuickName=" + escape(name) + "&strQuickEmail=" + escape(email) + "&submit=Submit" +"&trackingid=" + escape(trackingid) + "&xml=1";
var url = "Scripts/requirements_AJAX.php?" + params;  

// Open a connection to the server
  xmlHttp.open("post", url, true);

  // Setup a function for the server to run when it's done
  xmlHttp.onreadystatechange = updatePage;
  xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
  xmlHttp.setRequestHeader("Referer", "http://website-design-studio.net");
  // Send the request
  xmlHttp.send(params);
  return true;
}  

function updatePage() 
{
//inform the user that we are working on the request
try 
{
var deletethis = document.getElementById('quotebutton');
deletethis.parentNode.removeChild(deletethis);
}
catch (e)
{
}

createDataContainer2();
document.getElementById('AJAX_Update').innerHTML = "<img src\=\"images\/Progressbar.gif\" class=\"centred3\" alt\=\"ProgressBar\" \/>"

createDataContainer();
document.getElementById('AJAX_text').innerHTML = "Transmitting your data...";
  if (xmlHttp.readyState == 4) 
  { 
  	var xmldoc = xmlHttp.responseXML;
	try
	{
	var x = xmldoc.documentElement;
	}
	catch (e)
	{
	createDataContainer();
	document.getElementById('AJAX_text').innerHTML = "Database Connectivity problem. Please try again later." + e ;
	}

		try
	{
//remove the progressbar
			var deletethis = document.getElementById('AJAX_Update');
			deletethis.parentNode.removeChild(deletethis);

			createDataContainer();
			document.getElementById('AJAX_text').innerHTML = "";
			document.getElementById('AJAX_text').innerHTML += "Thank you, <strong>" + x.getElementsByTagName('FirstName')[0].childNodes[0].nodeValue + "<\strong>.";
			document.getElementById('AJAX_text').innerHTML += " Our systems have logged your email as <strong>" + x.getElementsByTagName('Email')[0].childNodes[0].nodeValue +"</strong>. We will contact you within 24 hours to discuss your requirements in more detail. If you'd like to share more details about your project please click <a href=\"requirements.htm\?strQuickName=" + document.getElementById("strQuickName").value + "&strQuickEmail=" + document.getElementById("strQuickEmail").value + "\">here.</a><br />";
			//add a tracking id to the page
			document.getElementById('trackingid').setAttribute('value', x.getElementsByTagName('RecordID')[0].childNodes[0].nodeValue);
	}
	catch (e)
	{
	}
  }
}

function createDataContainer(){
    var div=document.getElementById('AJAX_text');
    if(div){return};
    var div=document.createElement('div');
    div.setAttribute('id','AJAX_text');
    document.getElementById('Quote2').appendChild(div);
}
function createDataContainer2(){
    var div2=document.getElementById('AJAX_Update');
    if(div2){return};
    var div2=document.createElement('div');
    div2.setAttribute('id','AJAX_Update');
    document.getElementById('Quote2').appendChild(div2);
}

function URL_analysis() 
{
	  var xmlHttp = false;
/*@cc_on @*/
/*@if (@_jscript_version >= 5)
try {
  xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
  try {
    xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
  } catch (e2) {
    xmlHttp = false;
  }
}
@end @*/

if (!xmlHttp && typeof XMLHttpRequest != 'undefined') {
  xmlHttp = new XMLHttpRequest();
}
  // Get the name and email from the web form
  var URL_address = document.getElementById("SCANURL").value;

  // Build the URL to connect to
  
var params = "SCANURL=" + escape(URL_address);
var url_analysis = "Scripts/url_analysis.php?" + params;  

// Open a connection to the server
  xmlHttp.open("post", url_analysis, true);

  // Setup a function for the server to run when it's done
  xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
  xmlHttp.setRequestHeader("Referer", "http://website-design-studio.net");
  // Send the request
  xmlHttp.send(params);
  return true;
}  

function ValidateForm(theinput)
{
//form is second parent due to div wrapping input fields
if (FormValidatorQuote(theinput.parentNode.parentNode) == true)
	{
	//don't call if sent before
	if (called_already === false)
		{
		called_already = callServer();
		}	
	}
}

	function FormValidatorQuote(theForm)
	{
	  if (theForm.strQuickName.value == "")
	  {
	    alert("Please enter a value for the \"Name\" field.");
	    theForm.strQuickName.focus();
	    return (false);
	  }

	  if (theForm.strQuickName.value.length < 3)
	  {
	    alert("Please enter at least 3 characters in the \"Name\" field.");
	    theForm.strQuickName.focus();
	    return (false);
	  }

	  if (theForm.strQuickName.value.length > 60)
	  {
	    alert("Please enter at most 60 characters in the \"Name\" field.");
	    theForm.strQuickName.focus();
	    return (false);
	  }

	  if (theForm.strQuickEmail.value == "")
	  {
	    alert("Please enter a value for the \"E-mail\" field.");
	    theForm.strQuickEmail.focus();
	    return (false);
	  }

	  if (theForm.strQuickEmail.value.length < 7)
	  {
	    alert("Please enter at least 7 characters in the \"E-mail\" field.");
	    theForm.strQuickEmail.focus();
	    return (false);
	  }

	  if (theForm.strQuickEmail.value.length > 40)
	  {
	    alert("Please enter at most 40 characters in the \"E-mail\" field.");
	    theForm.strQuickEmail.focus();
	    return (false);
	  }
	  	var emailad = theForm.strQuickEmail.value;
		var exclude=/[^@\-\.\w]|^[_@\.\-]|[\._\-]{2}|[@\.]{2}|(@)[^@]*\1/;
		var check=/@[\w\-]+\./;
		var checkend=/\.[a-zA-Z]{2,3}$/;
	if(((emailad.search(exclude) != -1)||(emailad.search(check)) == -1)||(emailad.search(checkend) == -1))
		{		
			alert ("E-mail: " + theForm.strQuickEmail.value + " is invalid. Please enter a valid e-mail address.");
			theForm.strQuickEmail.focus();
			return (false);
		}
	  //don't call if sent before
	if (called_already === false)
		{
		called_already = callServer();
		}
	return (false);
	}
