var xmlHttp;
	function get_http(){
	var xmlhttp;
		try {
		xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (e) {
			try {
			xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch (E) {
			xmlhttp = false;
			}
		}
		if (!xmlhttp && typeof XMLHttpRequest!='undefined') {xmlhttp = new XMLHttpRequest();}
	return xmlhttp;
	}
 
  
	function getMessages() {
	//	alert(page);

	}
var currentMark =0;	



function fill (data,modelUrl){
    var select = document.getElementById("AllS");
    select.options.length = 0;	
//	select.options[select.options.length] = new Option('Все модели','', false, false);	
	
  if(data.length == 0) return;
    var arr = data.split('<!--l-->');	
    for(var i in arr){
        val = arr[i].split('<!--s-->');		
		if (val[0]!==''){
			select.options[select.options.length]=new Option(val[1], val[0], false, false);
		}
    }	
} 

function getAjaxBlocks(){
	this.http = get_http();
	this.working = false;
		if (!this.working && this.http){
			var http = this.http;
			url = root_url + "ajax.php?action=getCurrencyRates";	
			this.http.open("GET", url, true);		
			this.http.onreadystatechange = function(){
					if (http.readyState == 4){
						document.getElementById("currentCurrencyRate").innerHTML = http.responseText;	
						/*alert(http.responseText);*/
						this.working = false;
					}else{
					}
				}
			this.working = true;
			this.http.send(null);
		}
		if(!this.http){
			alert('Ошибка при создании XMLHTTP объекта!')
   	}		
}

function toBasket(id, showMessage) {
	this.http = get_http();
	this.working = false;

	if (!this.working && this.http)
	{
	//alert(currencyLink);
	var http = this.http;
	url = root_url + "ajax.php?action=toBasket&id=" + id  + currencyLink;	
	//alert(url);
	this.http.open("GET", url, true);
	this.http.onreadystatechange = function()
		{
			if (http.readyState == 4)
			{
			var arr = http.responseText.split('<>');
			//alert(http.responseText);
				if(showMessage==true){
					alert("В корзине товаров: "+arr[1]+" шт. На сумму "+ arr[2]+ " " + arr[3]);
				}else{
					document.getElementById("basketContentBlock").style.display="block";	
				}
			set_basket(arr[1],arr[2]);
			this.working = false;
			//delete (this.http);
			}
			else
			{
			}
		}
	this.working = true;
	this.http.send(null);
	}
		if(!this.http)
		{
		alert('Ошибка при создании XMLHTTP объекта!')
        }
}
	
function set_basket(kol, price) {
	if(kol==0){
		document.getElementById("basketContentBlock").innerHTML= 'У Вас нет товаров в корзине.';
	}else{
		document.getElementById("basketContentBlock").innerHTML= 'Товаров <span id="basket_kol"></span> шт., на сумму <span id="basket_summ"></span>	';
		document.getElementById("basket_kol").innerHTML= kol ;
		document.getElementById("basket_summ").innerHTML= price ;
	}

}


function getMainBasketContent(){
	this.http = get_http();
	this.working = false;

	if (!this.working && this.http)
	{
	var http = this.http;
	url = root_url + "ajax.php?action=getMainBasketContent" + currencyLink;	
	this.http.open("GET", url, true);
	this.http.onreadystatechange = function()
		{
			if (http.readyState == 4)
			{
			document.getElementById("cart").innerHTML= http.responseText;
			this.working = false;
			delete (this.http);
			}
			else
			{
			}
		}
	this.working = true;
	this.http.send(null);
	}
		if(!this.http)
		{
		alert('Ошибка при создании XMLHTTP объекта!')
        }
}
	
function basketDelete(id){
	this.http = get_http();
	this.working = false;

	if (!this.working && this.http)
	{
	var http = this.http;
	url = root_url + "ajax.php?action=basketDelete&id=" + id;	
	this.http.open("GET", url, true);
	this.http.onreadystatechange = function()
		{
			if (http.readyState == 4)
			{
				toBasket(0,false);
				getMainBasketContent();
				
			this.working = false;
			delete (this.http);
			}
			else
			{
			}
		}
	this.working = true;
	this.http.send(null);
	}
		if(!this.http)
		{
		alert('Ошибка при создании XMLHTTP объекта!')
        }
}	


function tryAjaxMarkModelBlockf(id){

	this.http = get_http();
	this.working = false;

	if (!this.working && this.http)
	{
	var http = this.http;
	url = root_url + "ajax.php?action=tryAjaxMarkModelBlock&id=" + id;	
	this.http.open("GET", url, true);
	this.http.onreadystatechange = function()
		{
			if (http.readyState == 4)
			{
				//alert(http.responseText);
				
				//var x=document.getElementById("Cars");
				//alert(x.selectedIndex);
				//x.selectedIndex = 1;
			this.working = false;
			delete (this.http);
			}
			else
			{
			}
		}
	this.working = true;
	this.http.send(null);
	}
		if(!this.http)
		{
		alert('Ошибка при создании XMLHTTP объекта!')
        }
}	


function getAdvise(doIt){

if (doIt == "1"){

	this.http = get_http();
	this.working = false;

	if (!this.working && this.http)
	{
	var http = this.http;
	url = root_url + "ajax.php?action=getAdvise";	
	this.http.open("GET", url, true);
	this.http.onreadystatechange = function()
		{
			if (http.readyState == 4)
			{
				
				if(http.responseText=="1"){// need to show
					document.getElementById("amax_advise_message").style.display = "block";
					
				}
			this.working = false;
			/*delete (this.http);*/
			}
			else
			{
			}
		}
	this.working = true;
	this.http.send(null);
	}
		if(!this.http)
		{
		alert('Ошибка при создании XMLHTTP объекта!')
        }

}
}	


function setAdvise(){

	
	this.http = get_http();
	this.working = false;

	if (!this.working && this.http)
	{
	var http = this.http;
	url = root_url + "ajax.php?action=setAdvise";	
	this.http.open("GET", url, true);
	this.http.onreadystatechange = function()
		{
			if (http.readyState == 4)
			{
				document.getElementById("amax_advise_message").style.display = "none";
			this.working = false;
			delete (this.http);
			}
			else
			{
			}
		}
	this.working = true;
	this.http.send(null);
	}
		if(!this.http)
		{
		alert('Ошибка при создании XMLHTTP объекта!')
        }

}		
	


