var xmlHttp
var xmlHttp2
var xmlHttp3
var xmlHttp4
var xmlTitle
var nextpage

/**
*		This function is an onload function.
*		It will perform al the onload checks.
**/

function checkVars(){
	checkLoggedIn();
}

function checkShopVars(){
	checkUserLoggedIn();
}

function checkCheckoutVars(){
	getUserAddress();
	checkLoggedIn();
}

function checkLoggedIn(){
	xmlHttp = null;
	xmlHttp=GetXmlHttpObject();
    
  if (xmlHttp==null){
    alert ("Your browser does not support AJAX!");
    return;
  }
  var page = document.getElementById("page").value;
  var args = "page="+page;
	
  xmlHttp.onreadystatechange=stateLoginCheckReady;
  xmlHttp.open('POST', '/home/checks/checkloggedin.php');
	xmlHttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	xmlHttp.send(args);
}

function stateLoginCheckReady() { 
	if (xmlHttp.readyState==4){ 
		document.getElementById("address").innerHTML=xmlHttp.responseText;
	}
}

/**
*	Function to check if the user is logged in during the checkout procedure
*/
function checkUserLoggedIn(){	
	//xmlHttp = null;
	xmlHttp = GetXmlHttpObject();
	
	if (xmlHttp==null){
    	alert ("Your browser does not support AJAX!");
    	return;
  	}
 	
  	var args = "";

  	xmlHttp.onreadystatechange=stateUserLoginCheckReady;
  	xmlHttp.open('POST', '/home/checks/checkuserloggedin.php');
	xmlHttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	xmlHttp.send(args);
}

function stateUserLoginCheckReady() { 
	if (xmlHttp.readyState==4){ 
		if(xmlHttp.responseText == 1){
			location.href="verzenden.phtml";
		} else {
			document.getElementById("errormsg").innerHTML=xmlHttp.responseText;	
		}
	}
}

/**
* 	Function te retrieve the address of the customer
*/
function getUserAddress(save){
	xmlHttp2 = GetXmlHttpObject();
	
	if(save != null){
	
		if(document.getElementById(companyname) != null)
			companyname = document.getElementById(companyname).value;
		if(document.getElementById(firstname) != null)
			firstname = document.getElementById(firstname).value;
		if(document.getElementById(lastname) != null)
			lastname = document.getElementById(lastname).value;
		if(document.getElementById(address) != null)
			address = document.getElementById(address).value;
		if(document.getElementById(zipcode) != null)
			zipcode = document.getElementById(zipcode).value;
		if(document.getElementById(city) != null)
			city = document.getElementById(city).value;
		var args = "companyname="+companyname+"&firstname="+firstname+"&lastname="+lastname+"&address="+address+"&zipcode="+zipcode+"&city="+city;
	} else {
		var args = "";
	}
	
	if (xmlHttp2==null){
    	alert ("Your browser does not support AJAX!");
    	return;
  	}
 	
  	xmlHttp2.onreadystatechange=stateUserAddressComplete;
  	xmlHttp2.open('POST', '/home/checks/getaddress.php');
	xmlHttp2.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	xmlHttp2.send(args);
}

function stateUserAddressComplete() { 
	if (xmlHttp2.readyState==4){ 
		if(document.getElementById("sendaddress"))
			document.getElementById("sendaddress").innerHTML=xmlHttp2.responseText;
		else if(document.getElementById("billaddress"))
			document.getElementById("billaddress").innerHTML=xmlHttp2.responseText;
	}
}


/**
* 	Function te retrieve the address of the customer
*/
function getUserChangeAddress(){
	xmlHttp3 = GetXmlHttpObject();
	
	if (xmlHttp3==null){
    	alert ("Your browser does not support AJAX!");
    	return;
  	}
 	
  	var args = "";

  	xmlHttp3.onreadystatechange=stateUserChangeAddressComplete;
  	xmlHttp3.open('POST', '/home/checks/changeaddress.php');
	xmlHttp3.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	xmlHttp3.send(args);
}

function stateUserChangeAddressComplete() { 
	if (xmlHttp3.readyState==4){ 
		if(document.getElementById("sendaddress"))
			document.getElementById("sendaddress").innerHTML=xmlHttp3.responseText;
		else if(document.getElementById("billaddress"))
			document.getElementById("billaddress").innerHTML=xmlHttp3.responseText;
	}
}


/**
*	Function which changes the news which is displayed
*
**/
function changeNews(number,title){
  xmlHttp=GetXmlHttpObject();
  
  xmlTitle = title;
  
  if (xmlHttp==null)
    {
    alert ("Your browser does not support AJAX!");
    return;
    } 
    
  document.getElementById("newsarticle").innerHTML="<br><br><br><br><img src=\"img/indicator.white.gif\" style=\"margin-left: 150px;\">";
     
    
  var url="getnews.php";
  url=url+"?number="+number;

  xmlHttp.onreadystatechange=stateChanged;
  xmlHttp.open("GET",url,true);
  xmlHttp.send(null);
} 

function stateChanged() { 
	if (xmlHttp.readyState==4){ 
		document.getElementById("newsarticle").innerHTML=xmlHttp.responseText;
	}
	  sIFR.replaceElement("h2", named({sFlashSrc: "sifr/assistent.swf", sColor: "#FF0000", sCase: "lower", sWmode: "transparent"}));
}

/**
*		This function changes the content on the course page
*
**/

function changeCourses(id){
  xmlHttp=GetXmlHttpObject();
  
  if (xmlHttp==null)
    {
    alert ("Your browser does not support AJAX!");
    return;
    } 
    
  var url="getcourses.php";
  url=url+"?id="+id;

  xmlHttp.onreadystatechange=stateCourseContentReady;
  xmlHttp.open("GET",url,true);
  xmlHttp.send(null);
} 

function stateCourseContentReady() { 
	if (xmlHttp.readyState==4){ 
		document.getElementById("coursecontent").innerHTML=xmlHttp.responseText;
	}
	  sIFR.replaceElement("h2", named({sFlashSrc: "sifr/assistent.swf", sColor: "#FF0000", sCase: "lower", sWmode: "transparent"}));
}


/**
*		This function enables enter in the loginform
*
**/

function submitenter(myfield,e)
{
var keycode;
if (window.event) keycode = window.event.keyCode;
else if (e) keycode = e.which;
else return true;

if (keycode == 13){
   myfield.form.submit();
   return false;
} else 
   return true;
}

/**
*	Function which constructs a xmlhttp object
*
**/
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;
}