// functies om Index pagina inhoud te wijzigen...
var http_request = false;
var Gurl = "";
var targetDiv = "";

function makeRequest(url, td) {

	http_request = false;
	Gurl = url;
	targetDiv = td;

	if (window.XMLHttpRequest) { // Mozilla, Safari,...
		http_request = new XMLHttpRequest();
		if (http_request.overrideMimeType) {
			http_request.overrideMimeType('text/xml');
		}
	} else if (window.ActiveXObject) { // IE
		try {
			http_request = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try {
			http_request = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e) {}
		}
	}

	if (!http_request) {
		alert('Giving up :( Cannot create an XMLHTTP instance');
		return false;
	}
	
	http_request.onreadystatechange = LoadDiv;      // deze functie handelt request af
	
	http_request.open('GET', url, true);			// actually make the request
													// The third parameter sets whether the request is asynchronous.
	http_request.send(null);
	
			/*	The parameter to the send() method can be any data you want to send to the server if POST-ing the request. 
				The data should be in the form of a query string, like:
					 name=value&anothername=othervalue&so=on 
					
			 Note that if you want to POST data, you have to change the MIME type of the request using the following line:
			 	http_request.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
				
			*/

}

// POST Request

   function makePOSTRequest(url, td, parameters) {
   
      http_request = false;
	  Gurl = url;
	  targetDiv = td;
	  
      if (window.XMLHttpRequest) { // Mozilla, Safari,...
	  
         http_request = new XMLHttpRequest();
		 
         if (http_request.overrideMimeType) {
         	// set type accordingly to anticipated content type
            http_request.overrideMimeType('text/xml');
         }
		 
      } else if (window.ActiveXObject) { // IE
         try {
            http_request = new ActiveXObject("Msxml2.XMLHTTP");
         } catch (e) {
            try {
               http_request = new ActiveXObject("Microsoft.XMLHTTP");
            } catch (e) {}
         }
      }
      if (!http_request) {
         alert('Cannot create XMLHTTP instance');
         return false;
      }
      
	  if(url == 'occasies.php' || url == 'nieuweMach.php' ){
      	
				document.getElementById('myGallery').style.top = '-500px';
				document.getElementById('side2').style.visibility = "hidden";
				document.getElementById('side3').style.visibility = "hidden";
				
		  switch(url){
				case "occasies.php":
					document.getElementById('side1').innerHTML ="<font size='2'><u><b>Huidige occasies</b></u></font>";
					break;
				case "nieuweMach.php":
					document.getElementById('side1').innerHTML ="<font size='2'><u><b>Huidige nieuwe machines</b></u></font>";
					break;	
		  }
		
		http_request.onreadystatechange = LoadNewPics;
		
		
	  }
	  
	  if(td == 'detailswin'){
      	http_request.onreadystatechange = LoadDetails;
	  }
	  
	  http_request.open('POST', url, true);
	  
                 http_request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
                 http_request.setRequestHeader("Content-length", parameters.length);
                 http_request.setRequestHeader("Connection", "close");
      
	  http_request.send(parameters);
	  //http_request.close();
   }



function LoadDiv() {

	if (http_request.readyState == 4) {
		if ((http_request.status == 0)||(http_request.status == 200)) {
		
			document.getElementById(targetDiv).innerHTML = http_request.responseText;
			
					switch(Gurl){		// daarna enkel de juiste boxen laten zien
						
							case "home.php":
							
								document.getElementById('myGallery').style.top = '0px';
								document.getElementById('side2').style.visibility = "visible";
								document.getElementById('side3').style.visibility = "visible";
								
								document.getElementById('mainContent').style.width = "400px";
								document.getElementById('mainContent').style.left = "300px";
								document.getElementById('side1').innerHTML ="<font size='2'><u><b>Huidige occasies</b></u></font>";
								
							
								 break;
								 
							case "dealers.php":
							
								document.getElementById('myGallery').style.top = '-500px';
								document.getElementById('side2').style.visibility = "hidden";
								document.getElementById('side3').style.visibility = "hidden";
 
								document.getElementById('mainContent').style.left = "15px";
								document.getElementById('mainContent').style.width = "465px";
								document.getElementById('side1').innerHTML ="<font size='2'><u><b>Machinebouwers</b></u></font>";
			
								
								 break;
								 
							case "contact.php":
								
								document.getElementById('myGallery').style.top = '-500px';
								document.getElementById('side2').style.visibility = "hidden";
								document.getElementById('side3').style.visibility = "hidden";
 								
								document.getElementById('mainContent').style.left = "15px";
								document.getElementById('mainContent').style.width = "465px";
								document.getElementById('side1').innerHTML ="<font size='2'><u><b>Contactgegevens</b></u></font>";
								
								 break;
					    								 
					}
					
			} else {
				alert('Request problem');
				alert(http_request.status);
			}
	}
}
   

function LoadNewPics() {

	if (http_request.readyState == 4) {
		if ((http_request.status == 0)||(http_request.status == 200)) {
		
			document.getElementById('myGallery').style.top = '-500px';
			document.getElementById('side2').style.visibility = "hidden";
 
			document.getElementById(targetDiv).style.left = "170px";
			document.getElementById(targetDiv).style.width = "465px";
			document.getElementById(targetDiv).innerHTML = http_request.responseText;
			
			}	
	}
}

function LoadDetails() {

	if (http_request.readyState == 4) {
		if ((http_request.status == 0)||(http_request.status == 200)) {
		
				winpops =window.open(Gurl,"","width=700,height=600,scrollbars=yes,titlebar=no");
			}	
	}
}	


// --------- NOT USED----------------------------------------------------------------------------------------

function LoadDivOld() {

	if (http_request.readyState == 4) {
		if ((http_request.status == 0)||(http_request.status == 200)) {
		
					document.getElementById(targetDiv).innerHTML = http_request.responseText;
					
					hiddenAll(); 	// Eerst alle boxen verbergen

				switch(Gurl){		// daarna enkel de juiste boxen laten zien
				
					case "bank.htm":
						 showBankpag();
						 break;
						 
					case "home.htm":
						 showHomepag();
						 break;
						 
					case "beleggingen.htm":
						 showBeleggingenpag();
						 break;

					case "verzekeringen.htm":
							showVerzekerpag();
							break;

					case "zichtrekening.htm":
							showBankpag();
							break;	

					case "kredieten.htm":
							showKredietpag();
							break;
							
					case "centea.htm":
							showBankpag();
							break;

					case "pensioensparen.htm":
							showBeleggingenpag();
							break;

					case "kindersparen.htm":
							showBeleggingenpag();
							break;

					case "beleggingsverzekering.htm":
							showBeleggingenpag();
							break;
							
					case "motorrijtuigen.htm":
							showMotorRijpag();
							break;

					case "hospi.htm":
							showVerzekerpag();
							break;

					case "schuldsaldoverz.htm":
							showVerzekerpag();
							break;
							
					case "brandverzekering.htm":
							showVerzekerpag();
							break;

					case "familiale.htm":
							showVerzekerpag();
							break;							

					case "woningkrediet.htm":
							showBankpag();
							EmptyDiv('kredtoptext');
							break;
																																																																
					case "voorafbetkrediet.htm":
							showBankpag();
							EmptyDiv('kredtoptext');
							break;
							
					case "leningopafb.htm":
							showBankpag();
							EmptyDiv('kredtoptext');
							break;

					case "kredietopening.htm":
							showBankpag();
							EmptyDiv('kredtoptext');
							break;
							
					case "bedrijfswagenkrediet.htm":
							showBankpag();
							EmptyDiv('kredtoptext');
							break;																					
				}	
					
		} else {
			alert('Request problem');
			alert(http_request.status);
		}
	}
}

function hiddenAll(){

	document.getElementById('conlineBox').style.visibility = "hidden";
	document.getElementById('mercatorBox').style.visibility = "hidden";
	document.getElementById('BankBox').style.visibility = "hidden";
	document.getElementById('BeleggingBox').style.visibility = "hidden";
	document.getElementById('VerzekeringenBox').style.visibility = "hidden";
	document.getElementById('LinkKreBox').style.visibility = "hidden";
	document.getElementById('LinkAutoVerzBox').style.visibility = "hidden";

}

function showHomepag() {

	document.getElementById('conlineBox').style.visibility = "visible";
}

function showBankpag() {

	document.getElementById('BankBox').style.visibility = "visible";
	document.getElementById('conlineBox').style.visibility = "visible";
}

function showBeleggingenpag() {

	showBankpag();
	document.getElementById('BeleggingBox').style.visibility = "visible";
}

function showVerzekerpag() {

	document.getElementById('VerzekeringenBox').style.visibility = "visible";
}

function showKredietpag() {

	showBankpag();
	document.getElementById('LinkKreBox').style.visibility = "visible";
}

function showMotorRijpag() {

	showVerzekerpag();
	document.getElementById('LinkAutoVerzBox').style.visibility = "visible";
}

function EmptyDiv(div) {

		document.getElementById(div).innerHTML = "";
}

/*

for more info look: 

http://developer.mozilla.org/en/docs/AJAX:Getting_Started

-----

The full list of the http_request.readyState values is as follows:

    * 0 (uninitialized)
    * 1 (loading)
    * 2 (loaded)
    * 3 (interactive)
    * 4 (complete) 



You have two options to access data:

    * http_request.responseText – will return the server response as a string of text
    * http_request.responseXML – will return the response as an XMLDocument object you can traverse using the JavaScript DOM functions 


*/

