// return XMLHttpRequest Object
function getHTTPObject() {
  var xmlhttp;
  /*@cc_on
  @if (@_jscript_version >= 5)
	try {
	  xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
	} catch (e) {
	  try {
	    xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
	  } catch (E) {
	    xmlhttp = false;
	  }
	}
  @else
  xmlhttp = false;
  @end @*/
  if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
	try {
	  xmlhttp = new XMLHttpRequest();
	  xmlhttp.overrideMimeType("text/xml");
	} catch (e) {
	  xmlhttp = false;
	}
  }
  return xmlhttp;
}

// change recherche page: normal, stock, promo, advanced
function recherche(selected, outer_link)
{
	var url = "ajax_recherche.php?";
	var http = getHTTPObject();
	if(typeof(outer_link)=='undefined'){
		outer_link = '';
	}
	if(outer_link!=""){
		outer_link_value = '&outer_link=' + outer_link;
	}else{
		outer_link_value = '';
	}
	http.open("GET", url + "selected=" + selected + outer_link_value, true);
	http.onreadystatechange = function()
	{
		if(http.readyState == 4)
	   	{
			document.getElementById('div_recherche').innerHTML = http.responseText;
			
			if (selected == 4) {
				initAdvancedSearch();
				document.getElementById('promotion_flash').style.display = 'none';
				document.getElementById('promotion_image').style.display = 'inline';
                document.getElementById('special_cars_flashes').style.display = 'none';
			} else {
				document.getElementById('promotion_flash').style.display = 'inline';
				document.getElementById('promotion_image').style.display = 'none';
                document.getElementById('special_cars_flashes').style.display = 'inline';
			}
			
	   	}
	};
	http.send(null);
}

// moteur recherche page: normal, stock, promo, advanced
function moteur_recherche(selected, outer_link)
{
	var url = "ajax_recherche.php?version=moteur&";
	var http = getHTTPObject();
	if(typeof(outer_link)=='undefined'){
		outer_link = '';
	}
	if(outer_link!=""){
		outer_link_value = '&outer_link=' + outer_link;
	}else{
		outer_link_value = '';
	}
	http.open("GET", url + "selected=" + selected + outer_link_value, true);
	http.onreadystatechange = function()
	{
		if(http.readyState == 4)
	   	{
			document.getElementById('div_recherche').innerHTML = http.responseText;
	   	}
	};
	http.send(null);
}

// select betamodele according to marque selected
function marque_change(marque, type, outer_link)
{
	var url = "ajax_recherche.php?";
	var http = getHTTPObject();
	if(typeof(outer_link)=='undefined'){
		outer_link = '';
	}
	if(outer_link!=""){
		outer_link_value = '&outer_link=' + outer_link;
	}else{
		outer_link_value = '';
	}	
	var width = document.getElementById('betamodele').style.width;
	http.open("GET", url + "marque=" + marque + "&type=" + type + outer_link_value + "&betamodele_width=" + width, true);
	http.onreadystatechange = function()
	{
		if(http.readyState == 4)
	   	{
			document.getElementById('div_betamodele').innerHTML = http.responseText;
	   	}
	};
	http.send(null);
}

// advanced search 
function advanced_search(field,outer_link)
{
	var url = "ajax_recherche.php?";
	var http = getHTTPObject();
	if(outer_link!=""){
		outer_link_value = '&outer_link=' + outer_link;
	}else{
		outer_link_value = '';
	}
	//alert(outer_link_value);
	//http.open("GET", url + "field=" + field.name + "&value=" + field.value, true);
	http.open("GET", url + "field=" + field.name + "&cle_marque=" + document.getElementById('marque').value + "&cle_modele=" + document.getElementById('modele').value + outer_link_value, true);
	http.onreadystatechange = function()
	{
		if(http.readyState == 4)
	   	{
			document.getElementById('div_advanced_search').innerHTML = http.responseText;
	   	}
	};
	http.send(null);
}

// ajax js for options, equipement, technique in devis page
function panel(selected,cle_vehicule)
{
	var url = "ajax_devis.php?";
	var http = getHTTPObject();
	http.open("GET", url + "selected=" + selected + "&cle_vehicule=" + cle_vehicule, true);
	http.onreadystatechange = function()
	{
		if(http.readyState == 4)
	   	{
			document.getElementById('div_devis_panel').innerHTML = http.responseText;
	   	}
	};
	http.send(null);
}

function panel_vo(selected, num_offre, cle_vehicule)
{
	var url = "ajax_devis_vo.php?";
	var http = getHTTPObject();
	http.open("GET", url + "selected=" + selected + "&num_offre=" + num_offre + "&cle_vehicule=" + cle_vehicule, true);
	http.onreadystatechange = function()
	{
		if(http.readyState == 4)
	   	{
			document.getElementById('div_devis_panel').innerHTML = http.responseText;
	   	}
	};
	http.send(null);
}

function panel_stock(selected, cle_vehicule_stock, cle_vehicule)
{
	var url = "ajax_devis_stock.php?";
	var http = getHTTPObject();
	http.open("GET", url + "selected=" + selected + "&cle_vehicule=" + cle_vehicule + "&cle_vehicule_stock=" + cle_vehicule_stock, true);
	http.onreadystatechange = function()
	{
		if(http.readyState == 4)
	   	{
			document.getElementById('div_devis_panel').innerHTML = http.responseText;
	   	}
	};
	http.send(null);
}

function panel_robusto(selected,cle_vehicule_robusto,cle_vehicule_cohiba)
{
	var url = "ajax_devis.php?";
	var http = getHTTPObject();
	http.open("GET", url + "selected=" + selected + "&cle_vehicule=" + cle_vehicule_cohiba + "&cle_vehicule_robusto=" +cle_vehicule_robusto, true);
	http.onreadystatechange = function()
	{
		if(http.readyState == 4)
	   	{
			document.getElementById('div_devis_panel').innerHTML = http.responseText;
	   	}
	};
	http.send(null);
}

//ajax for set session of options selected
function set_options_session(selected_options,ref)
{
	var url = "ajax_options.php?";
	var http = getHTTPObject();
	//alert(url + "option=" + selected_options + "&ref=" + ref);
	http.open("GET", url + "option=" + selected_options + "&ref=" + ref, true);
	http.onreadystatechange = function()
	{
		if(http.readyState == 4)
	   	{
	   		//it will return some js code, and we need to run the codes.
	   		eval(http.responseText);
	   	}
	};
	http.send(null);
}

//ajax for set session of options selected
function set_options_stock_session(selected_options,cle_stock_vehicule,cle_vehicule)
{
	var url = "ajax_options_stock.php?";
	var http = getHTTPObject();
	//alert(url + "option=" + selected_options + "&ref=" + ref);
	http.open("GET", url + "option=" + selected_options + "&cle_stock_vehicule=" + cle_stock_vehicule + "&cle_vehicule=" + cle_vehicule, true);
	http.onreadystatechange = function()
	{
		if(http.readyState == 4)
	   	{
	   		//it will return some js code, and we need to run the codes.
	   		eval(http.responseText);
	   	}
	};
	http.send(null);
}

function set_options_robusto_session(selected_options,ref)
{
	var url = "ajax_options_robusto.php?";
	var http = getHTTPObject();
	//alert(url + "option=" + selected_options + "&ref=" + ref);
	http.open("GET", url + "option=" + selected_options + "&ref=" + ref, true);
	http.onreadystatechange = function()
	{
		if(http.readyState == 4)
	   	{
	   		//it will return some js code, and we need to run the codes.
	   		//alert(http.responseText)
	   		eval(http.responseText);
	   	}
	};
	http.send(null);
}

function get_form_apprasial(type,ref_aramis,num_offre,arrive,identifiant)
{
	var url = "include_devis_formulaire.php?";
	var http = getHTTPObject();
	http.open("GET", url + "type=" + type + "&ref_aramis=" + ref_aramis + "&num_offre=" + num_offre + "&arrive=" + arrive + "&identifiant=" + identifiant, true);
	http.onreadystatechange = function()
	{
		if(http.readyState == 4)
	   	{
			document.getElementById('td_form_apprasial').innerHTML = http.responseText;
	   	}
	};
	http.send(null);
}

function goto(type, page)
{
	var url = "include_count_click.php?";
	var http = getHTTPObject();
	var responseText = "";
	http.open("GET", url + "type=" + type, true);
	http.onreadystatechange = function()
	{
		if(http.readyState == 4)
	   	{
			responseText = http.responseText;
	   	}
	};
	http.send(null);
	
	if(type == "vehicule") {
		location.href = page;
	}else if(type == "video") {
		window.open(page,'_blank','toolbar=0,location=0,directories=0,status=1,scrollbars=0,resizable=0,copyhistory=0,menuBar=0,width=817,height=525');
	}else if(type != "loading") {
		window.open(page, "_blank");
	}
}