var glob=new Array();
function popupShow(){
	document.getElementById("popup").style.display="block";
//	document.getElementById("usl").style.marginTop="15px";
}
function popupHide(){
	document.getElementById("popup").style.display="none";
//	document.getElementById("usl").style.marginTop="";
}
function menuHover(obj){
	obj.style.background="#FFFF80";
}
function menuOut(obj){
	obj.style.background="#FFFFFF";
}
function hidde(id){	$("#"+id).hide('slow');}
function news(id){	if ($("#news"+id).html()=="")
	{
		$.post("request.php",{func:"news", id:id}, news2);
	}
	else
	{		$("#news"+id).html("");
		hidde("news"+id);
	}}
function news2(str)
{	var arr = new Array();
	arr=str.split("|");
	// id|text
	$("#news"+arr[0]).html(arr[1]);
	$("#news"+arr[0]).show('slow');
}
function article(id){
	if ($("#article"+id).html()=="")
	{
		$.post("request.php",{func:"article", id:id}, article2);
	}
	else
	{
		$("#article"+id).html("");
		hidde("article"+id);
	}
}
function article2(str)
{
	var arr = new Array();
	arr=str.split("|");
	// id|text
	$("#article"+arr[0]).html(arr[1]);
	$("#article"+arr[0]).show('slow');
}

function add_disk(id)
{	var col=$("#d"+id).val();
	$.post("request.php",{func:"add_disk", id: id, col:col}, add_disk2);
}
function add_disk2(id)
{
/*	$("#"+id).html('Добавленно');
	$("#"+id).attr('class',"basket_added");
	$("#"+id).attr( 'onclick', null );
	basket_count();
*/  self.location="zakaz.php?zakaz=1";
}
function add_shin(id)
{
	var col=$("#s"+id).val();
	$.post("request.php",{func:"add_shin", id: id, col:col}, add_shin2);
}
function add_shin2(id)
{
/*	$("#"+id).html('Добавленно');
	$("#"+id).attr('class',"basket_added");
	$("#"+id).attr( 'onclick', null );
	basket_count();
*/	self.location="zakaz.php?zakaz=1";
}
function add_spec(id)
{
	var col=$("#d"+id).val();
	$.post("request.php",{func:"add_spec", id: id, col:col}, add_spec2);
}
function add_spec2(id)
{
/*	$("#"+id).html('Добавленно');
	$("#"+id).attr('class',"basket_added");
	$("#"+id).attr( 'onclick', null );
	basket_count();
*/  self.location="zakaz.php?zakaz=1";
}
function basket_count()
{	$.post("../request.php",{func:"basket_count"}, basket_count2);
}
function basket_count2(c)
{	$('#basket').html(c);
	if (c==0)
	{		$("#img_basket").attr("src","img/basket.jpg");
		tr_clear();
	}
	else
	{		$("#img_basket").attr("src","img/basket_s.jpg");	}
}
function tr_clear()
{	$.post("../request.php",{func:"tr_clear"},tr_clear2);
}
function tr_clear2(str)
{	if (str=="ok")
	{		basket_count();
		$("#body").html('<br><br><div align="center">Ваша корзина пуста.</div>');
	}
}
function del_disk(id)
{	$.post("../request.php",{func:"del_disk",id:id},del_disk2);
}
function del_disk2(str)
{	var arr = new Array();
	arr=str.split("|");
	$("#disk"+arr[0]).slideUp("slow");
	$("#sum").html(arr[1]);
	basket_count();}
function del_shin(id)
{
	$.post("../request.php",{func:"del_shin",id:id},del_shin2);
}
function del_shin2(str)
{
	var arr = new Array();
	arr=str.split("|");
	$("#shin"+arr[0]).slideUp("slow");
	$("#sum").html(arr[1]);
	basket_count();
}
function del_spec(id)
{
	$.post("../request.php",{func:"del_spec",id:id},del_spec2);
}
function del_spec2(str)
{
	var arr = new Array();
	arr=str.split("|");
	$("#spec"+arr[0]).slideUp("slow");
	$("#sum").html(arr[1]);
	basket_count();
}
function check()
{
	var err=0;
	if($("#fio").val()=="")
	{
		$("#fio").css('background',"#FF8080");
		err=1;
	}
	if($("#mobil").val()=="")
	{
		$("#mobil").css('background',"#FF8080");
		err=1;
	}
//	if($("#addres").val()=="")
//	{
//		$("#addres").css('background',"#FF8080");
//		err=1;
//	}
	if(check_radio()===false)
	{
		$("#tab_dost").css('background',"#FF8080");
		err=1;
	}
	if (err==0)
	{
		send_zakaz();
	}
}
function check_radio()
{	// проверяем выбрана ли доставка
	var arr_dost=$("input:radio");
	if(arr_dost.length) // иначе либо стол заказов либо нет пунктов.
	{
		var type_dost=false;
		for(var i=0;i<arr_dost.length;i++)
		{
			if($(arr_dost[i]).attr("checked"))
			{
				type_dost=$(arr_dost[i]).val();
			}
		}
		return(type_dost);
	}
	else
	{		return(0);	}
}
function isEmail()
{
	str=document.getElementById("email").value;
	var supported = 0;
	if (window.RegExp)
	{
		var tempStr = "a";
		var tempReg = new RegExp(tempStr);
		if (tempReg.test(tempStr)) supported = 1;
	}
	if (!supported)
	return (str.indexOf(".") > 2) && (str.indexOf("@") > 0);
	var r1 = new RegExp("(@.*@)|(\\.\\.)|(@\\.)|(^\\.)");
	var r2 = new
	RegExp("^.+\\@(\\[?)[a-zA-Z0-9\\-\\.]+\\.([a-zA-Z]{2,3}|[0-9]{1,3})(\\]?)$");
	return (!r1.test(str) && r2.test(str));
}
function clear_bg(obj)
{
	obj.style.background="#FFFFFF";
}
function chek_length(obj)
{	var name=obj.id.substr(0,5);
	var i=(obj.id.substr(6,1)*1);
	var char=0;
	if(name=="mobil")
	{		if(i<2)
		{			char=3;		}
		else
		{			char=2;		}
		if((obj.value.length>=char)&&i<=3)
		{			obj.value=obj.value.substr(0,char);
			var n2="mobil_"+(i+1);
			var el=document.getElementById(n2);
			el.focus();		}	}
}
function send_zakaz()
{	$("#mess").html('<img src="img/upload.gif" border="0">');
	$("#mess").show("fast");
	$.post("../request.php",{		func:"send_zakaz",
		fio:$("#fio").val(),
		phone:$("#phone").val(),
		mobil:$("#8").val()+$("#mobil_0").val()+$("#mobil_1").val()+$("#mobil_2").val()+$("#mobil_3").val(),
		email:$("#email").val(),
		addres:$("#addres").val(),
		note:$("#note").val(),
		zakaz:$("#zakaz").val(),
		type_dost:check_radio()
	}, send_zakaz2);
}
function send_zakaz2(str)
{	$("#mess").hide("fast");
	alert("Ваш заказ №"+str);
	self.location="index.php";
}
function count_sum(col,price)
{	var total_count=$("#total_count").val();
	var total_sum=0;
	for(var i=0;i<total_count;i++)
	{		pr=$("#pr_"+i).html()*1;
		col=$("#col_"+i).val()*1;
		col=Math.round(col);
		$("#col_"+i).val(col);
		total_sum+=(pr*col);
// alert("total_count="+total_count+" pr="+pr+" col="+col+" total="+(pr*col)+" total_sum="+total_sum);
	}
	$("#total_sum").html(total_sum);
}
function show_menu(id)
{
// m= количество меню
	var m=15;
	for(var i=1;i<=m;i++)
	{		$("#menu"+i+" > div").slideUp("fast");	}
	$("#menu"+id+" > div").slideDown("fast");
}
function numeric(str,id,max)
{
	str=str.replace(",",".");
	str=str.replace(" ","");
	if ((str*1)>0)
	{
		str=str.substr(0,(max-1));
	}
	else
	{
		str=4;
	}
	id.value=str;
//	id.focus();
}
function name_select(str)
{   // Массив что-б при первом открытии заполнить все селекты	var arr = new Array();
	arr=str.split("|");
	for(var i=0;i<arr.length;i=i+2)
	{		if($("#"+arr[i]).val()=="")
		{			$("#"+arr[i]+" option:selected").text(arr[i+1]);		}
	}
}
function clear_sel(str)
{	var arr = new Array();
	arr=str.split("|");
	$('#'+arr[0]+' option:contains('+arr[1]+')').text("");
}

// Подбор по автомабилю
function get_model(id)
{	$.post("../request.php",{func:"get_model",id:id},get_model2);
}
function get_model2(str)
{	$("#model").html(str);
	$("#model").removeAttr("disabled");
}
function get_year(id)
{
	$.post("../request.php",{func:"get_year",id:id},get_year2);
}
function get_year2(str)
{	$("#year").html(str);
	$("#year").removeAttr("disabled");
}
function get_obj(id)
{	$.post("../request.php",{func:"get_obj",id:id, model:$("#model").val()},get_obj2);
}
function get_obj2(str)
{
	$("#obj").html(str);
	$("#obj").removeAttr("disabled");
}

function auto_find(id)
{	$.post("../request.php",{func:"auto_find", model:$("#model").val(), year:$("#year").val(), obj:$("#obj").val()},auto_find2);
}
function auto_find2(str)
{	self.location='../podbor.php?'+str;}
function auto_find_spec(id)
{	$.post("../request.php",{func:"auto_find_spec", model:$("#model").val(), year:$("#year").val(), obj:$("#obj").val()},auto_find2_spec);
}
function auto_find2_spec(str)
{	self.location='../spec.php?'+str;}

function zoom(img)
{	$("#zoom_img").attr("src",img);
	$("#div_zoom").show('fast');}
function zoom_hide()
{	$("#div_zoom").hide('fast');}
function ed_col(str)
{	var arr = new Array();
	arr=str.split("|");
	$.post("../request.php",{func:"ed_col", id:arr[0], val:arr[1], table:arr[2]},ed_col_disk);
}
function ed_col_disk(str)
{	var arr = new Array();
	arr=str.split("|");
//	price_d'.$i.' 	ansv($id."|".$sum."|".count_sum());
	$("#price_"+arr[0]).html(arr[1]);
	$("#sum").html(arr[2]);
}
function get_shin_model(id)
{	$.post("request.php",{func:"get_shin_model", id:id},get_shin_model2);
}
function get_shin_model2(str)
{	$("#model").html(str);}
function show_news()
{	$("#menu_td").css("width","253px");
	if (screen.width>1024)
	{		$("#news0").show("fast");
		$("#news1").show("fast");
		$("#news2").show("fast");
		$("#news0").css("width","253px");
		var h=$("#main_window").css("height");
		h=h.substring(0,4);
		$("#news1").attr("height",h*1+50);
	}
	scroll();
}function scroll()
{
	var windowHeight;

	if (self.innerHeight) {    // all except Explorer
	     windowHeight = self.innerHeight;
	 } else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
	     windowHeight = document.documentElement.clientHeight;
	 } else if (document.body) { // other Explorers
	     windowHeight = document.body.clientHeight;
	 }
	$("#main_window").css("height",windowHeight);
}
function hide_news()
{
	$("#news0").hide("fast");
	$("#news1").hide("fast");
	$("#news2").hide("fast");
}
function news_coment()
{
    if($("#user").val()=="");
    {
        $("#user").css("bakground","red");
    }
    if($("#text").val()=="");
    {
        $("#text").css("bakground","red");
    }

    $.post("verify.php",{recaptcha_challenge_field:$("#recaptcha_challenge_field").val(),
        recaptcha_response_field:$("#recaptcha_response_field").val(),
        user:$("#user").val(),
        text:$("#text").val(),
        id:$("#id_news").val()
    },news_coment2);
}
function news_coment2(str)
{
    if(str==0)
    {
        location.reload(true);
    }
    else
    {
        Recaptcha.showhelp();
        Recaptcha.reload();
    }
}
function get_coment(id)
{
    var page=0;
    if(glob['coment_page'])
    {
        page=glob['coment_page'];
    }
    $.post("request.php",{func:"get_coment",id:id,page:page},get_coment2);
}
function get_coment2(html)
{
    $("#news_coments").html(html);
}
function coment_page(id,page)
{
    glob['coment_page']=page;
    get_coment(id);
}
