function flash_version(){
    var d, n = navigator, m, f = 'Shockwave Flash';
    if((m = n.mimeTypes) && (m = m["application/x-shockwave-flash"]) && m.enabledPlugin && (n = n.plugins) && n[f]) {d = n[f].description}
    else if (window.ActiveXObject) { try { d = (new ActiveXObject((f+'.'+f).replace(/ /g,''))).GetVariable('$version');} catch (e) {}}
    return d ? d.replace(/\D+/,'').split(/\D+/) : [0,0];
 };

function getAbsolutePos(el)
{
	var r = { x: el.offsetLeft, y: el.offsetTop };
	if (el.offsetParent)
	{
		var tmp = getAbsolutePos(el.offsetParent);
		r.x += tmp.x;
		r.y += tmp.y;
	}
	return r;
}


function ch_dyn(iid)
{
	if ($('#'+iid))
		if ($('#'+iid).css('display') == 'none')
			$('#'+iid).css('display','block');
		else
			$('#'+iid).css('display','none');
}

function setCookie (name, value, expires, path, domain, secure) {
      document.cookie = name + "=" + escape(value) +
        ((expires) ? "; expires=" + expires : "") +
        ((path) ? "; path=" + path : "") +
        ((domain) ? "; domain=" + domain : "") +
        ((secure) ? "; secure" : "");
}
function getCookie(name) {
        var cookie = " " + document.cookie;
        var search = " " + name + "=";
        var setStr = null;
        var offset = 0;
        var end = 0;
        if (cookie.length > 0) {
                offset = cookie.indexOf(search);
                if (offset != -1) {
                        offset += search.length;
                        end = cookie.indexOf(";", offset)
                        if (end == -1) {
                                end = cookie.length;
                        }
                        setStr = unescape(cookie.substring(offset, end));
                }
        }
        return(setStr);
}

function deleteCookie( name, path, domain ) {
	if ( getCookie( name ) ) document.cookie = name + '=' +
			( ( path ) ? ';path=' + path : '') +
			( ( domain ) ? ';domain=' + domain : '' ) +
			';expires=Thu, 01-Jan-1970 00:00:01 GMT';
}



function showTyreProducers()
{	
	if ($('#tyreProducersLayer').css('display') == 'none')
		$('#tyreProducersLayer').css('display','block');
	else 
		$('#tyreProducersLayer').css('display','none');
		
	$('#selectedTyreProducers').html('');

	$('#tyreProducersLayer input').each(
	function ()
	{
		if (this.checked)
		{
			$('#selectedTyreProducers').html($('#selectedTyreProducers').html()+$('.producer'+this.value).html()+'<br>');
		}

	}
	);
}




function showDiskProducers()
{	
	if ($('#diskProducersLayer').css('display') == 'none')
		$('#diskProducersLayer').css('display','block');
	else 
		$('#diskProducersLayer').css('display','none');
		
		
	$('#selectedDiskProducers').html('');
	$('#diskProducersLayer input').each(
	function ()
	{
		if (this.checked)
		{
			$('#selectedDiskProducers').html($('#selectedDiskProducers').html()+$('.producer'+this.value).html()+'<br>');
		}
	}
	);

}

function showAkbProducers()
{	
	if ($('#akbProducersLayer').css('display') == 'none')
		$('#akbProducersLayer').css('display','block');
	else 
		$('#akbProducersLayer').css('display','none');
		
		
	$('#selectedAkbProducers').html('');
	$('#akbProducersLayer input').each(
	function ()
	{
		if (this.checked)
		{
			$('#selectedAkbProducers').html($('#selectedAkbProducers').html()+$('.producer'+this.value).html()+'<br>');
		}
	}
	);

}

function showDiskProducers1()
{	
	if ($('#diskProducersLayer').css('display') == 'none')
		$('#diskProducersLayer').css('display','block');
	else{ 
		$('#diskProducersLayer').css('display','none');
		document.form1.submit();

	}	
		
	$('#selectedDiskProducers').html('');
	$('#diskProducersLayer input').each(
	function ()
	{
		if (this.checked)
		{
			$('#selectedDiskProducers').html($('#selectedDiskProducers').html()+$('.producer'+this.value).html()+'<br>');
		}
	}
	);
}

function showShellProducers()
{	
	if ($('#shellProducersLayer').css('display') == 'none')
		$('#shellProducersLayer').css('display','block');
	else 
		$('#shellProducersLayer').css('display','none');
		
		
	$('#selectedShellProducers').html('');
	$('#shellProducersLayer input').each(
	function ()
	{
		if (this.checked)
		{
			$('#selectedShellProducers').html($('#selectedShellProducers').html()+$('.producer'+this.value).html()+'<br>');
		}
	}
	);
}

function model_view(mark)
{
   // �������� ����� ������� �� <input>-����.
        var query = '';
        // ������� ����� ������ JSHttpRequest.
        var req = new Subsys_JsHttpRequest_Js();
        // ���, ������������� ���������� ��� ��������� ��������.
        req.onreadystatechange = function() {
            if (req.readyState == 4) {
                if (req.responseJS) {
                    document.getElementById('replica_models_list').innerHTML='<br>������: '+req.responseJS.models;
                }
            }
        }
        // ��������� ����������� (����� ��� ���������� ��������
        // �� ���������� � ������� ��������� ���).
        req.caching = false;
        // �������������� ������.
        req.open('POST', 'load_models.php?id='+mark+'&mm_model='+mm_model, true);
        // �������� ������ ������� (�������� � ���� ����).
        req.send({ id: mark});
}

function get_cai(containe,cai)
{
	 $.ajax({
	   type: "POST",
	   url: "load_cai.php",
	   data: "containe="+containe+"&cai="+cai,
	   success: function(msg){
	     document.getElementById('cai').innerHTML= msg;
	   }
	 });
}

function chPagerShowCount(count)
{
	deleteCookie('pagerCount');
	setCookie ('pagerCount', count, 'Mon, 01-Jan-2015 00:00:00 GMT');
	setCookie ('goPage', 1, 'Mon, 01-Jan-2015 00:00:00 GMT');

	var reg = new RegExp("(.*?)#(.*)", 'i');
	if (arr1 = reg.exec(window.location))
	{
		window.location = arr1[1];
	} else window.location = window.location;		
}

function chPagerShowCount2(count)
{
	setCookie ('pagerCount', count, 'Mon, 01-Jan-2015 00:00:00 GMT');
	setCookie ('goPage', 1, 'Mon, 01-Jan-2015 00:00:00 GMT');

	$('.counts a').removeClass('a');
	$('.counts .show'+count).addClass('a');
}


function SeasonChange(id)
{
	if (id == 2)
		$('.shipselect').css('display','none')
	else 
		$('.shipselect').css('display','inline')
}

function sformHide(name)
{
	
	if ($("#"+name+"").css('display') == 'none'){
		$("#"+name).css('display','block');
		$("."+name+"1").css('display','none');
	}else{
		$("#"+name+"").css({
					display: 'none'
					});
	}

}
function setValidator(id, regex) {
  var element = document.getElementById(id);
  if (element) {
    var lastValue = element.value;
    if (!regex.test(lastValue))
      lastValue = '';
    setInterval(function() {
      var value = element.value;
      if (value != lastValue) {
        if (regex.test(value))
          lastValue = value;
        else
          element.value = lastValue;
      }
    }, 10);
  }
}


function chdis(l)
{
	if ($(l).css('display') == 'none')
		$(l).css('display','block');
	else
		$(l).css('display','none');
}


/* ������� loadFoto ��� ������� */

	function loadFoto(id,src,href)
	{
		a = $('#link'+id);
		img = $('#img'+id);	
		
		if (img.src.indexOf(src) >= 0)
		{
			return true;
		}
		else
		{
			img.src = src;
			return false;
		}
	}


/* �������� ������������ ����� �� ���� �����, ������� � �.�. */

function unroll(id)
	{
		$('#'+id).css("display","block");
		var html = document.documentElement.clientHeight;
		if(html - $('#'+id).height() > 0)
		$('#'+id).height(html);
	}
	


function selectThis(id,wid,heig)
	{

//black_fon=document.createElement('div'); black_fon.className='black_fon'; $('body').append(black_fon);

			unselect = function(){
				$('#overlay').css('display','none');
				$('#'+id).css({'position':'relative'});
				if(wid && heig)
				{
					$('#'+id).removeAttr('style');
					$('#'+id).css({'display':'none'});
				}
				else
					$('#'+id).css({'display':'none'});

			
				if($('.clickClose').length)
					$('.clickClose').css({'display':'none'});
					
				if(id=="map")
				$('#'+id).css({'display':'block'});

			}


			unroll('overlay');
			$('#'+id).attr('style','display:block; position:fixed; top:100px; z-index:1005; border:1px solid #999999;');
			if(wid && heig)
				$('#'+id).css({'width':wid,'height':heig});
	
			if($('.clickClose').length)
			{
				$('.clickClose').css({'position':'absolute','z-index':'1100','margin-top':'-20px','display':'block'});
				$('.clickClose').click(unselect);
			}

			$('#overlay').click(unselect);
	}




function picChange(url,id)
	{
		$('#'+id).attr({src:url});
	} 


/* ����-���� � �������� ������� */
function showhelp()
	{
		if ($('#help_content').css('display') == 'none')
			$('#help_content').css('display','block');
		else
			$('#help_content').css('display','none');
	}



// Payment Bill ������ ����

function pb_status(num)
{
	$(window).load(function(){

		porgress_bar = function()
		{
		
					   $.ajax({
					   url: "/online/paymentBillStatus.php?num="+num,
					   cache: false,
					   success: function(msg){
							if(msg==1)
								{
									$('#load_pic').css('display','none');
									$('#pbill').css('display','inline');
								}
							else
								{
									$('#load_pic').css('display','block');
									$('#pbill').css('display','none');
									window.setTimeout(porgress_bar, 5000);
								}
							 }
						});
		}

		porgress_bar();

	});
}


// �������� "��������"

    function EnsureNumeric()
    {
        var k = window.event.keyCode;
        if ((k < 48 || k > 57) && k != 8)
            window.event.returnValue = false;
    }


	function view(w,h, mode){
			if(!w) w=483;
			if(!h) h=298;
			if(!mode) mode=0;
			id_view = window.open('/map.php?mode='+mode+'','edit_detail_window','width='+w+', height='+h+'');
	}
	function view_print(w,h){
			if(!w) w=483;
			if(!h) h=298;
			id_view = window.open('map.php','edit_detail_window','width='+w+', height='+h+'');
			id_view.print();
	}


	function view_mapframe1(){
			if (document.getElementById('yandexmap').style.display = "block")
			{
				document.getElementById('yandexmap').style.display = "none";
			}
			document.getElementById('googlemap').style.display = "block";
			initialize();
	}
	function hide_mapframe1(){
			document.getElementById('googlemap').style.display = "none";
			GUnload();
	}

	function view_mapframe2(){
			if (document.getElementById('googlemap').style.display = "block")
			{
				document.getElementById('googlemap').style.display = "none";
				GUnload();
			}
			document.getElementById('yandexmap').style.display = "block";
			ymaps_js();
	}
	function hide_mapframe2(){
			document.getElementById('yandexmap').style.display = "none";
	}


	function view_mapframe11(){
			if (top.document.getElementById('mapframe2').style.display == "block")
			{
				yg_map2.document.getElementById('yandexmap').style.display = "none";
				top.document.getElementById('mapframe2').style.display = "none";
			}
			top.document.getElementById('mapframe1').style.display = "block";
			yg_map1.document.getElementById('googlemap').style.display = "block";
	}
	function hide_mapframe11(){
			document.getElementById('mapframe1').style.display = "none";
			yg_map1.document.getElementById('googlemap').style.display = "none";
	}

	function view_mapframe12(){
			if (top.document.getElementById('mapframe1').style.display == "block")
			{
				yg_map1.document.getElementById('googlemap').style.display = "none";
				top.document.getElementById('mapframe1').style.display = "none";
			}
			top.document.getElementById('mapframe2').style.display = "block";
			yg_map2.document.getElementById('yandexmap').style.display = "block";
	}
	function hide_mapframe12(){
			document.getElementById('mapframe2').style.display = "none";
			yg_map2.document.getElementById('yandexmap').style.display = "none";
	}


	function view_google(){
			document.getElementById('googlemap').style.visibility = "visible";
			document.getElementById('googlemap').style.height = "495px";
			
			if (document.getElementById('yandexmap').style.visibility == "visible")
			{
				document.getElementById('yandexmap').style.visibility = "hidden";
				document.getElementById('yandexmap').style.height = "0px";
			}
	}
	function hide_google(){
			document.getElementById('googlemap').style.visibility = "hidden";
			document.getElementById('googlemap').style.height = "0px";
	}
	function view_yandex(){
			document.getElementById('yandexmap').style.visibility = "visible";
			document.getElementById('yandexmap').style.height = "480px";
	
			if (document.getElementById('googlemap').style.visibility == "visible")
			{
				document.getElementById('googlemap').style.visibility = "hidden";
				document.getElementById('googlemap').style.height = "0px";
			}
	}
	function hide_yandex(){
			document.getElementById('yandexmap').style.visibility = "hidden";
			document.getElementById('yandexmap').style.height = "0px";
	}




	function validate_email(email)
	{ 
	
		var reg = new RegExp("[0-9a-z_]+@[0-9a-z_^.]+\\.[a-z]", 'i');
	 
	 if (!reg.test(email)) { return false;}
	 else { return true; }
	}
	
	function getBodyScrollTop()
	{
	  return self.pageYOffset || (document.documentElement && document.documentElement.scrollTop) || (document.body && document.body.scrollTop);
	}
	
	
	
	function showMes()
	{
	
		//window.document.getElementById('whait').style.top=getBodyScrollTop();	
		//window.document.getElementById('whait').style.left=(document.body.clientWidth-197)/2;	
		
		
		window.document.getElementById('whait').style.display = 'block';
	}
	
	function hideMes()
	{
		window.document.getElementById('whait').style.display = 'none';
	}
	
	
	function check_contact_form()
	{
		form = document.mail;
		
		
		if (!validate_email(form.cont.value)) showMes();
		else form.submit();
	}


/* replica_index.tpl */

	$(window).load(function (){
		$('#paramsForm select').change(function (){$('#paramsForm').submit() });		
		$('.pos').keyup(calculteSumm);
		$('.photo .big').click(function (){ 
			$('.big').css('display','none');
		});
		$('.photo img').click(
		function ()
		{ 	
			$('.big').css('display','none');
			$(this).siblings('.big').css('display','block');
		});
	})


	var summ = 0;

	function calculteSumm()
	{
		saveOrder();
		loadOrder();
	
		$('#summC').html(summ);				
	}
	
	function loadPhoto(tn,big,cae)
	{
		$('#photo'+cae).html('<img src="'+tn+'" width="100" class="preload"><div class="big"><img class="preload" src="'+big+'" width="400">');
		$('#href'+cae).css('display','none');
		
	}
	
	var process_str = '';
	
	function process()
	{
		$('#processC').html('<img src="/replica/load25.gif">');		
		process_str = '';
		$('.pos').each(
		function ()
		{
			tmp = parseInt(this.id)*parseInt(this.value);
			if (tmp)
			{
				process_str += 	this.name+'-'+this.value+';';
			}
		}
		);
		
		$.ajax({
		   type: "POST",
		   url: "/replica/process.php",
		   data: "str="+process_str,
		   success: function(msg){
		     $('#processC').html('<b>����� ��������</b>');
		   }
		 });
		
		
	}


	var order = new Array();
	var tmp_str = '';

	
	function saveOrder()
	{
		tmp_str = '';
		$('.pos').each(
		function ()
		{
			if (this.value)
			{
				order[this.name] = this.id+'-'+this.value;
			}else deleteOrderClean(this.name);
		});	
		for (var key in order) {
			if (key && order[key])
			tmp_str += key+':'+order[key]+'\n';
		}		
				
		setCookie('replica_order', tmp_str);
		
		if ($('#orderC').html())loadOrderTextClean();
	}
	
	function deleteOrderClean(cae)
	{
		tmp_arr = order;		
		order = new Array();
		
		
		for (var key in tmp_arr)
		{
			if (key != cae)
			{
				order[key] = tmp_arr[key];
				
			}
		}
	}
	
	function deleteOrder(cae)
	{
		deleteOrderClean(cae);	
		
		
		$('input[name='+cae+']').val('');
		
		calculteSumm();
		loadOrderText();
		loadOrderText();
	}
	
	function loadOrderTextClean()
	{
	
		$('#orderC').html('<img src="/replica/load25.gif">');
			$.ajax({
			   type: "POST",
			   url: "/replica/process.php",
			   data: "show=1",
			   success: function(msg){
			     $('#orderC').html(msg);
			     $('#showOrder').html('������');
			   }
			 });
	}
	function loadOrderText()
	{
		if ($('#orderC').html())
		{
			$('#orderC').html('');
		    $('#showOrder').html('�������� �����');
		}else 
		{
			loadOrderTextClean();
		}
	}
	
	function loadOrder()
	{
		tmp = getCookie('replica_order');
		if (tmp)
		{
			arr = tmp.split('\n');
			var reg = new RegExp("(.*?):(.*?)-(.*)", 'i');
			summ = 0;
	
			$.each(arr,function ()
			{			
				//52262:4120-3
				if (arr1 = reg.exec(this))
				{
					
					order[arr1[1]] = arr1[2]+'-'+arr1[3];				
					summ += parseInt(arr1[2])*parseInt(arr1[3]);
					$('input[name='+arr1[1]+']').val(arr1[3]);
				}
			
			});
			
			$('#summC').html(summ);
		}
	}
	
	function clearOrder()
	{
		order = Array();
		setCookie('replica_order', '');
		$('.pos').val('');
		calculteSumm();
		$('#summC').html('');
	}

function chSortOrder(sort,ord)
{
	setCookie ('sort', sort, 'Mon, 01-Jan-2015 00:00:00 GMT');
	setCookie ('ord', ord, 'Mon, 01-Jan-2015 00:00:00 GMT');

	var reg = new RegExp("(.*?)#(.*)", 'i');
	if (arr1 = reg.exec(window.location))
	{
		window.location = arr1[1];
	} else window.location = window.location;		
}

function valve(id) {
    if ($("#"+id).css("display") == "none") {
    	$("#"+id).css("display", "block");
    	$("#valve").removeClass(id+'_close');
    	$("#valve").addClass(id+'_open');
    }
    else {
    	$("#"+id).css("display", "none");
    	$("#valve").removeClass(id+'_open');
    	$("#valve").addClass(id+'_close');    	
    }
}

function dselect(d) {
	$(".dselect").removeClass("selected");
	$("#dselect"+d).addClass("selected");
	$("#diametr").val(d);
}

function set_cookie(cookie_name, value, expire)
{
    var expire_date = new Date();
    
    expire_date.setDate(expire_date.getDate() + expire);
    document.cookie = (cookie_name + "=" + escape(value) + ((expire == null) ? "" : ";expires=" + expire_date.toGMTString() +  "; path=/"));

    return true;
}
function get_cookie(cookie_name)
{
    if (document.cookie.length > 0) {
        cookie_start = document.cookie.indexOf(cookie_name + "=");
        
        if (cookie_start != -1) { 
            cookie_start = ((cookie_start + cookie_name.length) + 1); 
            cookie_end   = document.cookie.indexOf(";", cookie_start);
            
            if ( cookie_end == -1) {
                cookie_end = document.cookie.length;
            }
            
            return unescape(document.cookie.substring(cookie_start, cookie_end));
        } 
    }
    
    return false;
}

$(function(){

$("body").click(function(e){

if ($('#tyreProducersLayer').css('display') == 'none'){} else {
if(e.target.id == "tyreProducersLayer" || $(e.target).parents("#tyreProducersLayer").size()){} else {
javascript:showTyreProducers()
}
}

if ($('#diskProducersLayer').css('display') == 'none'){} else {
if(e.target.id=="diskProducersLayer" || $(e.target).parents("#diskProducersLayer").size()){} else {
javascript:showDiskProducers()
}
}

if ($('#help_content').css('display') == 'none'){} else {
if(e.target.id=="help_content" || $(e.target).parents("#help_content").size()){} else {
javascript:showhelp()
}
}

});

})




