  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() 
{
	///if call server is called by pressing enter and form is submitted, go to bottom of page
window.scrollBy(0,1200);
  // Get the name and email from the web form
 var theForm = document.getElementById('requirements_form');
 var name = document.getElementById("strQuickName").value;
 var email = document.getElementById("strQuickEmail").value;
 var telephone = theForm.telephone.value;
 var trackingid = document.getElementById("trackingid").value;
 var organisationdetails = theForm.organisationdetails.value;
 var newwebsite = theForm.newwebsite.checked;
 var improvelook = theForm.improvelook.checked;
 var improveecommerce = theForm.improveecommerce.checked;
 var improvetraffic = theForm.improvetraffic.checked;
 var flashanimation = theForm.flashanimation.checked;
 var existingwebsite = theForm.existingwebsite.value;
 var budget = theForm.budget.value;
 var projectvision = theForm.projectvision.value;
 
//radiobuttons
try
{
	for (var i=0;i<theForm.timeframe.length;i++)
	{
		if (theForm.timeframe[i].checked==true)
			{
			var timeframe=theForm.timeframe[i].value;
			break ;
			}
	}

	for (var i=0;i<theForm.role.length;i++)
	{
		if (theForm.role[i].checked==true)
			{
			var role=theForm.role[i].value;
			break ;
			}
	}
	
}
	catch (f)
{
}
  // Build the URL to connect to
  
var params = "strQuickName=" + escape(name) + "&strQuickEmail=" + escape(email) + "&telephone=" + escape(telephone) + "&organisationdetails=" + escape(organisationdetails) + "&newwebsite=" + escape(newwebsite) + "&improvelook=" + escape(improvelook) +"&improveecommerce=" + escape(improveecommerce) +"&improvetraffic=" + escape(improvetraffic) + "&flashanimation=" + escape(flashanimation) + "&existingwebsite=" + escape(existingwebsite) +"&timeframe=" + escape(timeframe) + "&role=" + escape(role) + "&budget=" + escape(budget) + "&projectvision=" +escape(projectvision) +"&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 submitbutton = document.getElementById('submitbutton');
//deletethis.parentNode.removeChild(deletethis);
submitbutton.style.display = "none";
}
catch (e)
{
}

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

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

		try
	{
//remove the progressbar
			var deletethis = document.getElementById('AJAX_Update');
			deletethis.parentNode.removeChild(deletethis);
			//reset submit components
			called_already = false;
			submitbutton.style.display = "block";
			submitbutton.value = "Update";
			createDataContainer();
			document.getElementById('AJAX_text2').innerHTML = "";
			document.getElementById('AJAX_text2').innerHTML += "Thank you, <strong>" + x.getElementsByTagName('FirstName')[0].childNodes[0].nodeValue + "<\strong>.";
			document.getElementById('AJAX_text2').innerHTML += " Our systems have logged your email as <strong>" + x.getElementsByTagName('Email')[0].childNodes[0].nodeValue +" </strong> and your telephone number as <strong>" + x.getElementsByTagName('telephone')[0].childNodes[0].nodeValue +"  </strong>. We will contact you within 24 hours to discuss your requirements in more detail. <p>See our list of <a href=\"services.htm\">services</a> or go to our <a href=\"index.htm\">homepage</a>.</p>";
			//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_text2');
    if(div){return};
    var div=document.createElement('div');
    div.setAttribute('id','AJAX_text2');
    document.getElementById('leftcontent2').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('leftcontent2').appendChild(div2);
}


function ValidateForm()
{
	clearClass("hilite");
	var theField = document.getElementById('strQuickEmail');
	var theForm = document.getElementById('requirements_form');
	
	  if (theForm.strQuickName.value == "")
	  {
	    alert("Please enter your name. e.g. Joe Smith");
	    hilitefield(theForm.strQuickName);
		theForm.strQuickName.focus();
	    return (false);
	  }
	  
	  if (theForm.strQuickEmail.value == "")
	  {
	    alert("Please enter an Email address. e.g. joe@acme.com");
	    hilitefield(theForm.strQuickEmail);
		theForm.strQuickName.focus();
	    return (false);
	  }
	  
	 if (theField.value.length > 40)
	  {
	    alert("Please enter at most 40 characters in the \"E-mail\" field.");
	    hilitefield(theForm.strQuickEmail);
		theForm.strQuickEmail.focus();
	    return (false);
	  }
	
		var emailad = theField.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: " + theField.value + " is invalid. Please enter a valid e-mail address.");
			hilitefield(theForm.strQuickEmail);
			document.getElementById('strQuickEmail').focus();
			return false;
		}
	  if (theForm.telephone.value == "")
	  {
	    alert("Please enter your telephone number. e.g. +44 1234 56789");
	    hilitefield(theForm.telephone);
		theForm.telephone.focus();
	    return (false);
	  }  
	  
	//don't call if sent before
	if (called_already === false)
		{
		called_already = callServer();
		}	
	return false;
}



function changeClass (objectName, newClassName)
{
	if (objectName.getAttributeNode("class")) 
	{
	  for (var i = 0; i < objectName.attributes.length; i++) {
		if (objectName.attributes[i].name.toUpperCase() == 'CLASS') {
		  objectName.attributes[i].value = newClassName;
		}
	  }
	// otherwise create a new attribute
	} 
	else 
	{
	  objectName.setAttribute("class", newClassName);
	}
return true;
}


function sf()
//formfocusfunction
{
document.getElementById('strQuickName').focus();
}

function q5()
//formfocusfunction for q5
{
document.getElementById('existing').focus();
return true;
}

function q9()
//formfocusfunction for q9
{
document.getElementById('budget').focus();
return true;
}


function findparentLabel(o)
{
// traverse the document tree upwards till we find a label	
	if (o.nodeName.toUpperCase() == 'LABEL')
		{
		//alert ("The object passed to checkDiv is a " + o.nodeName);
		parentLabel = o;	
		//alert ("CheckDiv is about to return a " + divobject.nodeName);
		return parentLabel;
		}
	else
	{
	findparentLabel(o.parentNode);
	}

}

function findnextLabel(label_object)
{
	var labelarray = document.getElementsByTagName('label');
	//alert ("Div_object id = " + div_object.attributes.getNamedItem("id").value);
	//find the div that matches this one
	//alert ("There are: " + divarray.length + " divs in this document "); 
	for (var z = 0; z < labelarray.length; z++)
	{
		if (label_object === labelarray[z])
			{
			//alert(div_object.attributes.getNamedItem("id").value);
			nextLabel = labelarray[z+1];
			//alert(nextDiv.attributes.getNamedItem("id").value);
			return true;
			}	
	}
}

var interval_move = 0

function scrollDown()
{
//initiate event handler to move the window
timedelta=10;

//scrollit = function scrollnow() {window.scrollBy(0,8);};

	if (!interval_move)
	{
		interval_move = setInterval("go_scroll(8)", timedelta);
		stop_scrolling = setTimeout("clearInterval(interval_move);interval_move=0;", 300);
	}
}

function go_scroll(speed)
{
window.scrollBy(0,speed);
}

function findparentDiv(oo)
{
// traverse the document tree upwards till we find a div	
	if (oo.nodeName.toUpperCase() == 'DIV')
		{
		//alert ("The object passed to checkDiv is a " + o.nodeName);
		parentDiv = oo;	
		//alert ("CheckDiv is about to return a " + divobject.nodeName);
		return parentDiv;
		}
	else
	{
	findparentDiv(oo.parentNode);
	}

}

function findnextDiv(div_object)
{
	var divarray = document.getElementsByTagName('div');
	//alert ("Div_object id = " + div_object.attributes.getNamedItem("id").value);
	//find the div that matches this one
	//alert ("There are: " + divarray.length + " divs in this document "); 
	for (var z = 0; z < divarray.length; z++)
	{
		if (div_object === divarray[z])
			{
			//alert(div_object.attributes.getNamedItem("id").value);
			nextDiv = divarray[z+1];
			//alert(nextDiv.attributes.getNamedItem("id").value);
			return true;
			}	
	}
}

function clearClass(className)
//removes all classes called classname from divs in the document
{
var divarray = document.getElementsByTagName('div');
//alert(divarray[11].attributes.getNamedItem("class").value);
//alert(divarray[11].className);
for (var z = 0; z < divarray.length; z++)
	{
		if (divarray[z].className == className)
			{
			changeClass (divarray[z],"None");
			return true;
			}	
	}
}

function hide_existing(checkbox)
{
var existingwebsite = document.getElementById('q6');

	if (checkbox.checked)
		{
		existingwebsite.style.display = "none"
		}
	else
		{
		existingwebsite.style.display = "block";
		}
		alertName(checkbox)
		return true;
}

function hilitefield(fieldobject)
{
clearClass("hilite");
findparentDiv(fieldobject);
changeClass (parentDiv,"hilite");
//had some issues with this causing exceptions
try
{fieldobject.focus();
}
catch (e)
{}

}


function alertName(clickedobject)
{
findparentDiv(clickedobject);
//only hilite radio buttons
try
{
if (clickedobject.getAttributeNode("type").value.toUpperCase() == "RADIO")
	{
	//This loop ensures that no more than one option is colored red
	var radio_collection = parentDiv.getElementsByTagName('input');
	for (var k=0;k < radio_collection.length;k++)
		{
		changeClass(radio_collection[k].parentNode,"None");
		}
	//Color the selected red
	changeClass(clickedobject.parentNode, "red3");
	}
}
catch (e)
{
}
//remove all hilite classes
clearClass("hilite");
//changeClass (parentDiv,"None");
scrollDown();
findnextDiv(parentDiv);
changeClass (nextDiv,"hilite");
return true;
}

function setField(FieldID, FieldValue )
{
//	alert ("Setting " + FieldID + " to " + FieldValue);
document.getElementById(FieldID).value = FieldValue;
}

window.onload = function() 
{
//check url for parameters and if exist populate fields
	if (window.location.search)
	{
		var urlparameters = window.location.search.substr(1).split("&");
		for (x=0;x<urlparameters.length;x++) 
			{
				var para = urlparameters[x].split("=");
				setField (para[0], unescape(para[1]));
			}
		//focus on telephone field if parameters present
		var telephone1 = document.getElementById('telephone')
		hilitefield(telephone1);
//		telephone1.focus();
	}
else
	{
	hilitefield(document.getElementById('strQuickName'));
//	sf();
	}
	//changeClass(document.getElementById('strQuickName').parentNode, "hilite");
}

