var cur_section  = 0;  				//
var selected_list =''; 				//
var origCols; 						//
var serverAdress = "/include/ajax.php";
var tmp_class = '';
var arrEvents   = new Array();

function GoEvents()
	{
	if(!arrEvents) arrEvents   = new Array();
	for(var i=0;i<arrEvents.length;i++){
		eval(arrEvents[i]);
		}
	}


function login_site()
	{
	 document.getElementById("check_login").value = "not_null";
	 login = document.getElementById("email");
	 if(login.value=='')
	 	{
		alert("Поле не заполнено");
		login.focus();
		return;
		}
	pass = document.getElementById("upass");
	 if(pass.value=='')
	 	{
		alert("Поле не заполнено");
		pass.focus();
		return;
		}
	if(confirm('Запомнить на этом компьютере?'))
		document.getElementById("remember").value = 1;

	document.getElementById("uform").submit();
	}

function ShowBlock(id)
	{
	ob = document.getElementById(id);
	if(ob)
		{
		ob.style.display  = (ob.style.display == 'none')? '' : 'none';
		}
	}

function SelectZaklad(ob,act)
	{
	if(act)
		{
		tmp_class = ob.className;
		ob.className = 'hed_zakld_s';
		}
	else
		{
		ob.className = tmp_class;
		tmp_class = '';
		}
	}

function SelectUrlico(ob,act)
	{
	 tmp_class = 'hed_zakld_s';
	 if(act)
	 	{
		document.getElementById("user_name").style.display="none";
		document.getElementById("user_sname").style.display="none";
		document.getElementById("user_adress").style.display="none";
		document.getElementById("ur_name").style.display="";
		document.getElementById("ur_inn_kpp").style.display="";
		document.getElementById("ur_adress").style.display="";
		document.getElementById("ur_index").style.display="";
		document.getElementById("urlico").value="1";
		document.getElementById('zakl_1').className = 'hed_zakld_ns';
		ob.className = 'hed_zakld_s';
		}
	else
		{
		document.getElementById("user_name").style.display="";
		document.getElementById("user_sname").style.display="";
		document.getElementById("user_adress").style.display="";
		document.getElementById("ur_name").style.display="none";
		document.getElementById("ur_inn_kpp").style.display="none";
		document.getElementById("ur_adress").style.display="none";
		document.getElementById("ur_index").style.display="none";
		document.getElementById("urlico").value="0";
		document.getElementById('zakl_2').className = 'hed_zakld_ns';
		ob.className = 'hed_zakld_s';
		}
	}



function FixPng(el)
	{
	if (!/MSIE (5\.5|6\.)/.test(navigator.userAgent) ||
   (event && !/(background|src)/.test(event.propertyName))) return;

    if(el.tagName.toLowerCase() =='img')
		{var src = el.src;

		el.style.filter  = "progid:DXImageTransform.Microsoft.AlphaImageLoader"
	         + "(src=\'" + src + "\', sizingMethod='image')";
		el.src = '/admin/images/blank.gif';
		el.style.border = 'none';
		}
	else{
	      var bgImg = el.style.backgroundImage;
	      if(bgImg.match(/^url[("']+(.*\.png)[)"']+$/i))
	      	{
	          var src = RegExp.$1;

	          el.style.backgroundImage ='none';

              el.style.filter  = "progid:DXImageTransform.Microsoft.AlphaImageLoader"
	         + "(src=\'" + src + "\', sizingMethod='crop')";
	         }
		}
	}



function  add_basket_sel(id)
	{
	var order = document.getElementById("order_cnt");
	var order_size = document.getElementById("order_size").value;
	var order_cnt = parseInt(order.value);

	if(!order_cnt)
		{
			alert("Не выбрано кол-во товара");
			order.focus();
			return;
		}
		if(confirm('Добавить к корзину?'))	{
			destination.push("order_us");
			ajax_req="action=add&select="+id+"&order_cnt="+order_cnt+"&size="+order_size+"&target=basket";
			cache.push(ajax_req);
			execAjax();
			order.value = '';
		}
	}

function  change_basket_sel(id,order_cnt)
	{
			destination.push("order_summ");
			ajax_req="action=change&select="+id+"&order_cnt="+order_cnt+"&target=basket";
			cache.push(ajax_req);
			execAjax();
	}

function CheckLatin(el)
	{
		str = el.value;
		reg = new RegExp("^[0-9a-zA-Z_\-]{1,150}$","i");
        result = reg.test(str);
		if(result==false)
			{
			alert("Поле должно содержать только латинские символы и знаки '_' '-'");
			el.focus();
			return 0;
			}
	return 1;
	}

	function show_submenu(ob,id,class_name)
		{
		ob.className = class_name;
		obj = 	document.getElementById(id);
		//obj.className = class;
		if(obj)
			{
			obj.style.display = (obj.style.display=="none")? "" : "none";
			event.cancelBubble=true;
			}
		}

	function SendQuest(flag)
		{
		if(document.getElementById('name').value=='')
			{
			document.getElementById('name').focus();
			alert('Поле должно быть заполнено');
			return;
			}
		if(document.getElementById('date').value=='')
			{
			document.getElementById('date').focus();
			alert('Поле должно быть заполнено');
			return;
			}
		if(document.getElementById('regplace').value=='')
			{
			document.getElementById('regplace').focus();
			alert('Поле должно быть заполнено');
			return;
			}
		if(document.getElementById('adress').value=='')
			{
			document.getElementById('adress').focus();
			alert('Поле должно быть заполнено');
			return;
			}
		if(document.getElementById('phone').value=='')
			{
			document.getElementById('phone').focus();
			alert('Поле должно быть заполнено');
			return;
			}

		if(flag)
			{
			if(document.getElementById('auto').value=='')
			{
			document.getElementById('auto').focus();
			alert('Поле должно быть заполнено');
			return;
			}
			if(document.getElementById('number').value=='')
			{
			document.getElementById('number').focus();
			alert('Поле должно быть заполнено');
			return;
			}
			}
		document.getElementById("quest_form").submit();
		}

	 function CheckUserForm()
		{
			uForm = document.getElementById("reg_form")
			for (var i=0; i < uForm.length; i++)
				{
				if(uForm[i].name!='subscribe'  && uForm[i].name!='description' && uForm[i].name!='blog' && uForm[i].name!='photo' && uForm[i].value=='')
					{
					alert("Поле должно быть заполнено"+uForm[i].name);
					uForm[i].focus();
					return;
					}
				}
			var ob = document.getElementById("login");
			if(CheckLatin(ob)==0)
				{
				ob.focus();
				return 0;
				}

			pass1 =  document.getElementById("pass");
			pass2 =  document.getElementById("pass2");
			if(pass2.value==pass1.value)
				{
				 uForm.submit();
				}
			else
				alert("Пароли не совпадают");
				return;
		}

		function CheckEmptyField(ob)
			{
			var str = ob.value;
			if(ob.tagName.toLowerCase() == 'select')
				{
				str = (ob.selectedIndex >=0) ? ob[ob.selectedIndex].text : '';
				}
			var reg = new RegExp("^\\s+$","i");
			var result = reg.test(str);
			if(str=='' || result)
			  {
			  return 0;
			  }
			return 1;
			}

		function ChoicePayment()
			{
			var ob =  document.getElementById("pay_system");
			location.href = document.getElementById("url").value + ob.value + "/";

			}


		function ShowMapCityList(id, el)
				{
				var ob = document.getElementById(id);
				if(ob)
				{
					if(ob.style.display=='none')
						{
						ob.style.display = '';
						el.innerHTML = '[-]';
						}
					else
						{
						ob.style.display = 'none';
						el.innerHTML = '[+]';
						}
					}
				}


			//Опеределяет позицию курсора мышки
			function defMousePosition(event) {
				var x = y = 0;
				if (document.attachEvent != null) { // Internet Explorer & Opera
					x = window.event.clientX + document.documentElement.scrollLeft + document.body.scrollLeft;
					y = window.event.clientY + document.documentElement.scrollTop + document.body.scrollTop;
				}
				if (!document.attachEvent && document.addEventListener) { // Gecko
					x = event.clientX + window.scrollX;
					y = event.clientY + window.scrollY;
				}
				return {x:x, y:y};
			}


				function HidStoreInfo()
				{
				ob  = 	document.getElementById('store_info_id');
				if(ob) ob.style.display = 'none';
				}




function ShowStoreInfo(name,adress,e_)
		{
					e = e_ || window.event;
					var txt = (name+'<br>'+adress);
					mp = defMousePosition(e);
					ob  = 	document.getElementById('store_info_id');
					if(ob)
						{
						ob.style.display = 'block';
						ob.style.top = mp.y;
						ob.style.left = mp.x;
						ob.innerHTML = txt;
						}
					else
						{
						newD = document.createElement('div');
						newD.style.position='absolute';
						newD.style.zIndex = 100;
						newD.id = 'store_info_id';
						newD.className = 'store_info_pop';
						newD.style.top = mp.y;
						newD.style.left = mp.x;
						newD.innerHTML = txt;
						document.getElementsByTagName('BODY')[0].appendChild(newD);
						}
			}


function ShowSWFProd(url,size)
		{
		destination.push("for_eval");
		ajax_req="url="+url+"&action=showphoto&target=catalog&size="+size+"&is_flash=1";
		cache.push(ajax_req);
		execAjax();
		return 0;
		}

function SetCenterPage(el)
	{
	     var offset =  (document.documentElement) ?  document.documentElement : document.body;
	     var div_h = el.clientHeight;
         var clientH = offset.clientHeight;
         var scrollTop = (offset.scrollTop >  document.body.scrollTop) ? offset.scrollTop : document.body.scrollTop;

         el.style.top = (clientH < div_h) ?  scrollTop+"px" : parseInt((clientH - div_h)/2)+scrollTop+"px";
         el.style.left = parseInt((offset.clientWidth - el.clientWidth)/2) + 'px';

	}


function SetSizeShowBgimg(el)
		{
		  var div_box = document.getElementById('show_img_bg');
		  if(!div_box) return;
		  div_box.style.height = el.height+20+'px';
          div_box.style.width = el.width+'px';
          div_box.style.padding = '10px';

		  var imgs  = div_box.getElementsByTagName('img');

		 SetCenterPage(div_box);

		 imgs[0].style.display = '';
   		}

function CloseShowBgImg()
	{
	 var div_box =  document.getElementById('show_img_bg');
     var div_bg =  document.getElementById('img_bg_bl');

     if(div_box) div_box.parentNode.removeChild(div_box);
     if(div_bg) div_bg.parentNode.removeChild(div_bg);
	}

function ShowBgImg(img_url,is_flash)
	{
     if(document.getElementById('show_img_bg')) CloseShowBgImg();

     if(is_flash){
        ShowSWFProd(img_url,arguments[2]);
     	var img =document.createElement("div");
        img.id = "prod_swf";
        img.style.textAlign = "center";
     	}
     else
     {
     var img = new Image();
     img.id  = 'show_img_src';
     img.alt  = '';
     /*img.width = 0;
     img.height = 0;*/
     img.style.display = 'none';
     img.onload  = function()
     				{
                     this.style.display = 'inline';
                     SetSizeShowBgimg(this);
	  				}
     }
     img.src =  img_url;
     var div_bg = document.createElement("div");
     var div_box = document.createElement("div");
     var div_cl = document.createElement("div");
     div_cl.className = 'show_bg_img_close';
     div_cl.onclick = CloseShowBgImg;

     div_cl.appendChild(document.createTextNode('X'));
     div_bg.id  = 'img_bg_bl';
     div_box.className = "show_img_bg";
     div_box.id = "show_img_bg";
     div_bg.className = "img_bg_bl";
     div_box.appendChild(div_cl);

     if(img) div_box.appendChild(img);
     div_bg.style.backgroundColor = '#000';
     var off_w = (document.documentElement && document.documentElement.clientWidth) || document.body.clientWidth;
     var off_y = document.body.scrollHeight || (document.documentElement && document.documentElement.scrollHeight);
     var left_off  = (document.documentElement && document.documentElement.scrollWidth) || document.body.scrollWidth;

     var width_bg = (left_off > off_w) ? left_off : off_w;

     div_bg.style.width = left_off+'px';
     div_bg.style.height = off_y + 'px';

     div_box.style.textAlign = 'right';
     div_bg.style.filter = "alpha(opacity='80')";

     div_box.style.width = 300 + 'px';
     div_box.style.height = 300 + 'px';

     div_box.style.padding = '10px';
     div_box.style.backgroundColor = '#fff';

     div_box.style.filter = "alpha(opacity='100')";
     div_bg.style.top = 0;
     div_bg.style.left = 0;

     document.body.appendChild(div_bg);
     document.body.appendChild(div_box);

     SetCenterPage(div_box);
     if(img && img.width > 0){SetSizeShowBgimg(img);};

   	}

function OrderSelectSection()
	{
	if(arguments[0] && arguments[0].value == 0) {       var another = ById('products4');
       if(another){another.style.display = (arguments[0].checked) ? 'block' : 'none';}
 		var aninput = ById('prod_list_4');
 		if(aninput)
 			{ 			document.another_value = (document.another_value) ? document.another_value : aninput.value;
 			aninput.onclick = function(){this.value = (this.value == document.another_value) ? '' : this.value;}
 			aninput.onblur = function(){this.value = (this.value == '') ? document.another_value : this.value;} 			aninput.value = (!arguments[0].checked) ? document.another_value: aninput.value;
 			var ancnt = ById('product_4');
 			if(ancnt && !arguments[0].checked){ 				 ancnt.value = '';
 				}
 			}

	return;
	}
    var oForm  = ById('order_form');
	if(oForm){
        pid ='';
        var arrCatalog = ByTag(oForm,'input');
		for(var i = 0; i<arrCatalog.length; i++){
            if(arrCatalog[i].name == 'catalog' && arrCatalog[i].checked){
            		pid += (pid=='') ? arrCatalog[i].value : ','+ arrCatalog[i].value ;
            	}
			}
		var cond_1 = ById('cond_1');
		var cond_2 = ById('cond_2');
	    var cond1 = (cond_1 && cond_1.checked) ? cond_1.value : 0;
	    var cond2 = (cond_2 && cond_2.checked) ? cond_2.value : 0;
		destination.push("for_eval");
		ajax_req="pid="+pid+"&action=product_list&target=catalog&cond1="+cond1+"&cond2="+cond2 ;
		cache.push(ajax_req);
		execAjax();
	    OrderDisableList();
	  }
	}

function  OrderDisableList()
	{
     var box  = ById('prod_list');
     if(box){
       var arrProdList = ByTag(box,'select');
       for(var i = 0; i<arrProdList.length; i++){
       	 arrProdList[i].disabled = true;
       	}
      }

	}

function GetRadioSelIndex(rGroup)
	{
	for (i=0; i< rGroup.length; i++) {
     if (rGroup[i].checked) {
		 return i;
		 }
      }
	}

function OrderSelectCond()
	{
    var oForm  = ById('order_form');
    if(oForm){
    	var arrSection = oForm.catalog;
   		if(arrSection){
        	var index =  GetRadioSelIndex(arrSection);
        	if(index>=0){
        			var pid = arrSection[index].value;
		        	OrderSelectSection();
        		}
    		}
       }
	}

function OrderSubmit(id)
	{
	var oForm  = document.getElementById(id);
	if(oForm){
         CheckForm(oForm);
		}
	}
function GetLabelByEl(el,id)
		{
		var arrLabels = ByTag(el,'label');
		for (var i=0; i < arrLabels.length; i++)
			{
			var lFor =  GetAttr(arrLabels[i],'htmlFor');
			if(lFor==id) return arrLabels[i].innerHTML;
			}
        return '';
		}

function ById(id)
	{
	return document.getElementById(id);
	}

function ByTag(el,tag)
	{
	 if(el)
		 return el.getElementsByTagName(tag);
	return 0;
	}


function GetAttr(el,name)
	{
	return el[name] || el.getAttribute(name) || '';
	}

function CheckNumField(ob)
			{
			var str = ob.value;
			if(arguments[1] && arguments[1] == 1)
			   {var reg = new RegExp("^[1-9]{1}[0-9]*$","i");}
			else
				{var reg = new RegExp("^[0-9]+[\.,]{0,1}[0-9]*$","i");}
			var result = reg.test(str);
			if(str=='' || !result)
			  {
			  return 0;
			  }
			return 1;
			}

function CheckEmail(el1)
			{
			 var el = el1;
				str = el.value;
				reg = new RegExp("^[0-9\\-a-z_\\.]+@[0-9\\-a-z_^\\.]+\\.[a-z]{2,3}$","i");

				result = reg.test(str);
				if(result==false)
					 {
						return 0;
					 }
			return 1;
			}

function ShowPodViewFlashMore(id)
	{	var box = ById(id);
	if(box){        box.style.display  = 'block';		}
	}


//****************  Google Maps  ****************************************************************
function initializeGM() {
 if (GBrowserIsCompatible()) {
 document.getElementById("google_map").style.display='block';
 map = new GMap2(document.getElementById("google_map"));

 if(!window.center_map){
	 map.addControl(new GLargeMapControl());
	 map.addControl(new GMapTypeControl());
	 map.addControl(new google.maps.LocalSearch(), new GControlPosition(G_ANCHOR_BOTTOM_RIGHT, new GSize(10,50)));
 }
 address = '';

 var center = new GLatLng(gSh, gD);
 city_url  =  (arguments[1]) ? arguments[1] : '';
 if(arguments[0] && arguments[0]!=''){ 	address =  arguments[0];
 	geocoder = new GClientGeocoder();
 	checkgeocoder(); 	}
 else putMarker(center,store_name);

 }
 }
 function showAddress(address){
	if (geocoder&&(address||''))
	{
		if('')
		{
			return;// putMarker(address);
		}
		else{
			geocoder.getLatLng(
							address,
							function(point)
							{
								if (!point)
								{
									if(address.lastIndexOf(',')>0)
									{
										window.setTimeout('showAddress(\'' + address.substr(0, address.lastIndexOf(',')) + '\')', 100);
									}
									else if (!address || address.toLowerCase().indexOf('москва'))
									{
										document.getElementById("google_map").innerHTML='';
										document.getElementById("google_map").style.display='none';
									}
								}
								else
								{
									if(point.x<0||point.y<0)return false;
       									putAllMarker(point);
       								}
							}
						 );
		}
	}
}
function putAllMarker(point_){
  var marker = new Array();
  for(var i=0; i<arrStoreData.length; i++){      marker[i] = new GMarker(new GLatLng(parseFloat(arrStoreData[i][1]), parseFloat(arrStoreData[i][2])));
      map.addOverlay(marker[i]);
      marker[i].bindInfoWindowHtml('<div class="marker_info"><a href="'+base_path+'flashmap/'+city_url+'/store-'+arrStoreData[i][0]+'/">'+arrStoreData[i][3]+'</a></div>');
 	}
 	map.setCenter(point_, gMs);
}

function putMarker(point, address){
	if(window.center_map){        var center_map = new GLatLng(window.center_map[0],window.center_map[1]);
        map.setCenter(center_map, gMs);
		}
	else{
		map.setCenter(point, gMs);
    	}
    var marker = new GMarker(point);
    map.addOverlay(marker);
    if(address)marker.openInfoWindowHtml('<div style="padding-top:10px;">'+address+'</div>');
}

var checkgeocoder=function(){
	if (geocoder){
		 showAddress(address);
		 }
	 else window.setTimeout('checkgeocoder()', 100);
}

function GetMapPrint(store_id,city_url){	if(map){
		var zoom = map.getZoom();
        var center =  map.getCenter();
		for(i in center)
			{			alert(i);			}
		var url = base_path+'flashmap/'+city_url+'/store-'+store_id+'/?print=printpage&zoom='+zoom+'&x='+center.x+'&y='+center.y;
		window.open(url,"print","resizable=yes,scrollbars=yes,menubar=no ,width=800, height=750,top=50, left=50");
	 }
	}

/********************************* //Google Maps  ***********************************************************************/

/********************************* Yandex Maps  ***********************************************************************/
/*
function GetMapPrintYM(store_id,city_url){
	if(map){
		var zoom = map.getZoom();
        var center =  map.getCenter();
		var url = base_path+'flashmap/'+city_url+'/store-'+store_id+'/?print=printpage&zoom='+zoom+'&x='+center.getX()+'&y='+center.getY();
		window.open(url,"print","resizable=yes,scrollbars=yes,menubar=no ,width=800, height=750,top=50, left=50");
	 }
	}

*/

function GetMapPrintYM(store_id,city_url){
	if(map){
		var zoom = map.getZoom();
        var center =  map.getCenter();
		if(window.cur_store)
			{store_id  = cur_store ;}
		var url = base_path+'flashmap/'+city_url+'/store-'+store_id+'/?print=printpage&zoom='+zoom+'&x='+center.getX()+'&y='+center.getY();
		window.open(url,"print","resizable=yes,scrollbars=yes,menubar=no ,width=800, height=750,top=50, left=50");
	 }
	}


function initializeYM() {
    map = new YMaps.Map(ById("google_map"));
    if(!window.center_map){
    	map.addControl(new YMaps.TypeControl());
		map.addControl(new YMaps.ToolBar());
		map.addControl(new YMaps.Zoom());
    }
   else {   		 map.disableDblClickZoom();
   		 map.disableDragging();
   		 }
    city_url  =  (arguments[1]) ? arguments[1] : '';
    if(arguments[0] && arguments[0]!=''){
		 	address =  arguments[0];
		if(gD == 0 && gSh == 0){
		    var geocoder = new YMaps.Geocoder(address, {results: 1, boundedBy: map.getBounds()});
		    YMaps.Events.observe(geocoder, geocoder.Events.Load, function () {
		    if (this.length()) {
		        map.setCenter(this.get(0).getGeoPoint(), gMs);
		    }else {
		        alert("Ничего не найдено")
		    }
		});
		YMaps.Events.observe(geocoder, geocoder.Events.Fault, function (error) {
		    alert("Произошла ошибка: " + error.message)
		});
		}
	  else{     	 map.setCenter(new YMaps.GeoPoint( gD, gSh), gMs);
		  }
	   putAllMarkerYM(1);
	}
	else{
		 var point = new YMaps.GeoPoint( gD, gSh);
	     if(window.center_map){	        var center_map = new YMaps.GeoPoint(window.center_map[1],window.center_map[0]);
	        map.setCenter(center_map, gMs);
	        putAllMarkerYM(0);
	     	}
	     else {putMarkerYM(point,store_name,store_adress, store_phone);}
		}

}

function putMarkerYM(point, name, address,phone){
	map.setCenter(point, gMs);

    if(window.center_map){
        var center_map = new YMaps.GeoPoint(window.center_map[1],window.center_map[0]);
        map.setCenter(center_map, gMs);
		}
	else{
         var center_point = (window.center_map2 && parseFloat(window.center_map2[1])>0 && parseFloat(window.center_map2[0])>0) ?  new YMaps.GeoPoint(window.center_map2[1],window.center_map2[0]) : point;
		 map.setCenter(center_point, gMs);
    	}
    var placemark = new YMaps.Placemark(point);
    if(name)
    	{
    	  placemark.name = name;
    	  placemark.setIconContent(name);
    	}
    if (address) placemark.description = address+phone;
    map.addOverlay(placemark);
    placemark.openBalloon();
}

function putAllMarkerYM(mode){
  var placemark = new Array();
  for(var i=0; i<arrStoreData.length; i++){
     if(arrStoreData[i][4] == ''){       	var name = arrStoreData[i][3];
       	placemark[i] = new YMaps.Placemark(new YMaps.GeoPoint( arrStoreData[i][2], arrStoreData[i][1]));
       }
     else{     	placemark[i] = new YMaps.Placemark(new YMaps.GeoPoint( arrStoreData[i][2], arrStoreData[i][1]),  {style: "default#redPoint"});
        var name = (window.ym_msg) ? ym_msg[0]+arrStoreData[i][4]: arrStoreData[i][4];
     	}
   if(mode) {placemark[i].setIconContent(name);}
   placemark[i].name = '<div>'+name+'</div>';
   placemark[i].id = arrStoreData[i][0];
   placemark[i].description = '<div class="marker_info">'+arrStoreData[i][5]+arrStoreData[i][6]+'</div>';
   map.addOverlay(placemark[i]);
   /*if(arrStoreData[i][7]) {placemark[i].openBalloon();}*/
   YMaps.Events.observe(placemark[i], placemark[i].Events.Click, function (obj) {
						    cur_store = obj.id;
						});
 	}
}
/********************************* Yandex Maps  ***********************************************************************/
