var xmlHttp = createXmlHttpRequestObject(); 
var lastname = "456";
var lastFacility = '';
var name = '';

function createXmlHttpRequestObject(){	
  var xmlHttp;
  // if running Internet Explorer
  if(window.ActiveXObject)
  {
    try{
      xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
    }
    catch (e) 
    {
      xmlHttp = false;
    }
  }
  // if running Mozilla or other browsers
  else
  {
    try 
    {
      xmlHttp = new XMLHttpRequest();
    }
    catch (e) 
    {
      xmlHttp = false;
    }
  }
  if (!xmlHttp)
    alert("Error creating the XMLHttpRequest object.");
  else 
    return xmlHttp;
}


// -------------------------------- Contact form --------------------------------------

function ajaxContactFormProcess(){
	
  if (xmlHttp.readyState == 4 || xmlHttp.readyState == 0){
    var name 		= encodeURIComponent(document.forms['contactform'].name.value);
	var company 	= encodeURIComponent(document.forms['contactform'].company.value);
	var email 		= encodeURIComponent(document.forms['contactform'].email.value);
	var tel 		= encodeURIComponent(document.forms['contactform'].tel.value);
	var url 		= encodeURIComponent(document.forms['contactform'].url.value);
	var project 	= encodeURIComponent(document.forms['contactform'].project.value);
	var description = encodeURIComponent(document.forms['contactform'].description.value);
	var budget 		= encodeURIComponent(document.forms['contactform'].budget.value);
	
	var sendURL = "ajax/processor.php?action=contactform&name=" + name;
	sendURL += "&company=" + company;
	sendURL += "&email=" + email;
	sendURL += "&tel=" + tel;
	sendURL += "&url=" + url;
	sendURL += "&project=" + project;
	sendURL += "&budget=" + budget;
	sendURL += "&description=" + description;
	
	//alert(sendURL);
	
	xmlHttp.open("GET", sendURL, true);  
	xmlHttp.onreadystatechange = handleServerResponseContact;
    xmlHttp.send(null);
	
	//document.getElementById("contactformcontent").innerHTML = '';
	
  }else{ 
    setTimeout('ajaxvideoprocess()', 1000);
  }
}



// executed automatically when a message is received from the server
function handleServerResponseContact() {
  if (xmlHttp.readyState == 4) {
    if (xmlHttp.status == 200) {
      
	  xmlResponse = xmlHttp.responseXML;
      
	  xmlDocumentElement = xmlResponse.documentElement;

	  var myhtmlcode = xmlDocumentElement.getElementsByTagName("htmlcode").item(0).firstChild.data;
	
      try{document.getElementById("contactformcontent").innerHTML = '<p>Thank you. Your request has been sent.</p>';}catch(err){}
	
	$('contactformtable').fade({ duration: 0.2, from: 1, to: 0 });
	$('contactformresponse').appear({ duration: 0.2, from: 0, to: 1 });
	
	} else {
      alert("There was a problem accessing the server: " + xmlHttp.statusText);
    }
  }
}

// -------------------------------- Content loader --------------------------------------

function ajaxLoadText(textfile){
	
  if (xmlHttp.readyState == 4 || xmlHttp.readyState == 0){
	  

	var sendURL = "ajax/processor.php?action=loadtext&textfile=" + textfile;
	//alert(sendURL);
	
	xmlHttp.open("GET", sendURL, true);  
	xmlHttp.onreadystatechange = handleServerResponseContentLoad;
    xmlHttp.send(null);

	
  }else{ 
    setTimeout('ajaxLoadText()', 1000);
  }
}


// executed automatically when a message is received from the server
function handleServerResponseContentLoad() {
	
  if (xmlHttp.readyState == 4) {
	  
    if (xmlHttp.status == 200) {
      
	  xmlResponse = xmlHttp.responseXML;
      
	  xmlDocumentElement = xmlResponse.documentElement;

	  var myhtmlcode = xmlDocumentElement.getElementsByTagName("htmlcode").item(0).firstChild.data;
		//alert(myhtmlcode);
	if(myhtmlcode.length >10){
		try{document.getElementById("text2").innerHTML = myhtmlcode;}catch(err){}
	}

	} else {
      alert("There was a problem accessing the server: " + xmlHttp.statusText);
    }
  
  }
  
}