function SetSizePrevImage()//установка размеров дива дял картинок привьюшек
{
    $("#data").data("y",0);
    $(".preview").each(function(){
        y = $(this).attr("offsetTop");//y текущего элемента
        height = $(this).height();//высота текущего элемента
        if($("#data").data("y")!=y)//если мы перешли на новую строку
        { 
            cur_y = $("#data").data("y");//top предедущей строчки
            if(cur_y!=0)
              $(".preview[offsetTop="+cur_y+"]").css("height",$("#data").data("height")+5);
              
            $("#data").data("y",y); 
            $("#data").data("height",0); 
        } 
        if(height>$("#data").data("height"))//если высота эелемента больше макс. высоты
        {
            $("#data").data("height",height); 
        }
    });
   
}
function AddToCompare(id_tovar)//для срванения
{
    $.ajax({
	url: 'compare.php',
	type: 'POST',
	data: 'action=add&id_tovar=' + id_tovar,
	dataType: 'json',
	timeout: 5000,
	success: function(jsn) 
	 {
	    if(jsn.err!=null)
	        alert(jsn.err);
	    if(jsn.inf!=null) 
	        $("#inf_compr").text(jsn.inf);
	 }
	});
	return false;
}
function ImageFly(id_img,srcollTop)
{
    var src = $("#img"+id_img).attr("src");
    var top = $("#img"+id_img).offset().top;
    var left = $("#img"+id_img).offset().left;
    var height = $("#img"+id_img).height();
    var myImg = $("<img style='position:absolute;top:"+top+"px;left:"+left+"px;height:"+height+"px;' src='"+src+"'></img>");
    myImg.appendTo("a#a"+id_img);
    if(srcollTop>0)
    {
       $(document).scrollTop(srcollTop);
       if(!$.browser.msie && false)
       {
           if($.browser.safari || $.browser.webkit)
           {
               $("html:not(:animated),body:not(:animated)").animate({scrollTop:0},3000); 
           }
           else
           {
             $("html").animate({scrollTop:0},3000); 
           }
       }
   }
   myImg.animate({opacity: 0,top:130,left:90},3000); 
}
function isEmpty(name,kol)
{
	if(document.getElementById(name).value.length<kol)
	{
		alert('Не правильно заполнены поля!!')
		return false;
	}
}
function NewOdnaknopka2() {
    this.domain=location.href+'/';
    this.domain=this.domain.substr(this.domain.indexOf('://')+3);
    this.domain=this.domain.substr(0,this.domain.indexOf('/'));
    this.location=false;
    this.selection=function() {
    var sel;
    if (window.getSelection) sel=window.getSelection();
    else if (document.selection) sel=document.selection.createRange();
    else sel='';
    if (sel.text) sel=sel.text;
    return encodeURIComponent(sel);
    }
    this.redirect=function() {
    if (this.location) location.href=this.location;
    this.location=false;
    }
    this.go=function(i) {
    this.location=this.url(i);
    setTimeout('odnaknopka2.redirect()',2000);
    var scr=document.createElement('script'); 
    scr.type='text/javascript'; 
    scr.src='http://odnaknopka.ru/save2/?domain='+this.domain+'&system='+i; 
    document.body.appendChild(scr);
    return false;
    }
    this.url=function(system) {
    var title=encodeURIComponent(document.title);
    var url=encodeURIComponent(location.href);
    switch (system) {
    case 1: return 'http://memori.ru/link/?sm=1&u_data[url]='+url+'&u_data[name]='+title;
    case 2: return 'http://bobrdobr.ru/addext.html?url='+url+'&title='+title;
    case 3: return 'http://www.google.com/bookmarks/mark?op=add&bkmk='+url+'&title='+title;
    case 4: return 'http://zakladki.yandex.ru/userarea/links/addfromfav.asp?bAddLink_x=1&lurl='+url+'&lname='+title;
    case 5: return 'http://twitter.com/home?status='+title+' '+url;
    case 6: return 'http://del.icio.us/post?v=4&noui&jump=close&url='+url+'&title='+title;
    case 7: return 'http://text20.ru/add/?source='+url+'&title='+title+'&text='+this.selection();
    case 8: return 'http://news2.ru/add_story.php?url='+url;
    case 9: return 'http://www.mister-wong.ru/index.php?action=addurl&bm_url='+url+'&bm_description='+title;
    case 10: return 'http://moemesto.ru/post.php?url='+url+'&title='+title;
    case 11: return 'http://smi2.ru/add/?url='+url+'&precaption='+title;
    case 12: return 'http://www.vaau.ru/submit/?action=step2&url='+url;
    case 13: return 'http://myscoop.ru/add/?URL='+url+'&title='+title;
    case 14: return 'http://www.linkstore.ru/servlet/LinkStore?a=add&url='+url+'&title='+title;
    case 15: return 'http://www.ruspace.ru/index.php?link=bookmark&action=bookmarkNew&bm=1&url='+url+'&title='+title;
    case 16: return 'http://www.100zakladok.ru/save/?bmurl='+url+'&bmtitle='+title;
    }
    }
    this.hide=function() {
    if (this.timeout) clearTimeout(this.timeout);
    document.getElementById('odnaknopka').style.visibility='hidden';
    }
    this.show=function(element) {
    if (this.timeout) clearTimeout(this.timeout);
    var left=0,top=0;
    var style=document.getElementById('odnaknopka').style;
    while (element) {
    left+=element.offsetLeft;
    top+=element.offsetTop;
    element=element.offsetParent;
    }
    style.left=left+'px';
    style.top=top+'px';
    style.visibility='visible';
    }
    this.init=function(msg) 
    {
        var titles=new Array('Memori','&#1041;&#1086;&#1073;&#1088;&#1044;&#1086;&#1073;&#1088;','&#1047;&#1072;&#1082;&#1083;&#1072;&#1076;&#1082;&#1080; Google','&#1071;&#1085;&#1076;&#1077;&#1082;&#1089;.&#1047;&#1072;&#1082;&#1083;&#1072;&#1076;&#1082;&#1080;','Twitter','del.icio.us','&#1058;&#1077;&#1082;&#1089;&#1090; 2.0','News2','&#1052;&#1080;&#1089;&#1090;&#1077;&#1088; &#1042;&#1086;&#1085;&#1075;','&#1052;&#1086;&#1105;&#1052;&#1077;&#1089;&#1090;&#1086;','&#1057;&#1052;&#1048; 2','&#1042;&#1072;&#1072;&#1091;!','AddScoop','LinkStore','RuSpace','&#1057;&#1090;&#1086; &#1047;&#1072;&#1082;&#1083;&#1072;&#1076;&#1086;&#1082;');
        if (!document.getElementById('odnaknopka')) {
        var div=document.createElement('div');
        div.id='odnaknopka';
       // div.setAttribute("title",msg);  
        div.style.position='absolute';
        div.style.visibility='hidden';
        div.style.width='264px';
        div.style.height='182px';
        div.style.backgroundColor='transparent';
        div.style.backgroundImage='url(http://odnaknopka.ru/images/panel.png)';
        div.style.border='0';
        div.style.margin='0';
        div.style.padding='0 1px 4px 1px';
        div.style.overflow='hidden';
        div.style.zIndex='1000';
        div.style.font='normal 12px arial';
        div.style.lineHeight='20px';
        div.style.color='#666';
        html='<noindex><a href="http://odnaknopka.ru" rel="nofollow" title="'+msg+'" onclick="window.open(\'http://odnaknopka.ru/add/?url=\'+encodeURIComponent(location.href)+\'&title=\'+encodeURIComponent(document.title),\'odnaknopka\',\'scrollbars=yes,menubar=no,width=600,height=500,left='+(document.body.clientWidth/2-300)+',top='+(document.body.clientHeight/2-250)+',resizable=yes,toolbar=no,location=no,status=no\');return false;" style="display:block;float:left;width:258px;height:20px;overflow:hidden;margin:1px 0;padding:0;background-color:transparent;font:bold 11px arial;color:#666;text-decoration:none"></a></noindex>';
        for (var i=0;i<16;i++) 
        {
            html+='<noindex><a href="'+this.url(i+1)+'" rel="nofollow" style="display:block;float:left;width:108px;height:16px;overflow:hidden;margin:1px 0;padding:0 0 0 24px;background-color:transparent;background:url(http://odnaknopka.ru/images/panel.png) no-repeat -266px '+(-i*16)+'px;font:normal 12px arial;color:#666;text-decoration:none;text-align:left" onmouseover="this.style.textDecoration=\'underline\'" onmouseout="this.style.textDecoration=\'none\'" onclick="return odnaknopka2.go('+(i+1)+');">'+titles[i]+'</a></noindex>';
        }
        html+='<noindex><a href="http://odnaknopka.ru" rel="nofollow" style="display:block;float:left;width:258px;height:16px;overflow:hidden;margin:1px 0;padding:0;background-color:transparent;font:bold 11px arial;color:#666;text-decoration:none;text-align:right">&copy;&nbsp;&#1054;&#1076;&#1085;&#1072;&#1050;&#1085;&#1086;&#1087;&#1082;&#1072;.&#1088;&#1091;</a></noindex>';
        div.innerHTML=html;
        div.onmouseover=function() {if (odnaknopka2.timeout) clearTimeout(odnaknopka2.timeout)}
        div.onmouseout=function() {odnaknopka2.timeout=setTimeout('odnaknopka2.hide()',500)};
        document.body.insertBefore(div,document.body.firstChild);
    }
    document.write('<noindex><a href="http://odnaknopka.ru/add/" rel="nofollow" onclick="window.open(\'http://odnaknopka.ru/add/?url=\'+encodeURIComponent(location.href)+\'&title=\'+encodeURIComponent(document.title),\'odnaknopka\',\'scrollbars=yes,menubar=no,width=600,height=500,left='+(document.body.clientWidth/2-300)+',top='+(document.body.clientHeight/2-250)+',resizable=yes,toolbar=no,location=no,status=no\');return false;"><img src="http://odnaknopka.ru/images/button.gif" width="136" height="16" alt="&#1054;&#1076;&#1085;&#1072;&#1050;&#1085;&#1086;&#1087;&#1082;&#1072;" title="&#1054;&#1076;&#1085;&#1072;&#1050;&#1085;&#1086;&#1087;&#1082;&#1072;" style="border:0;margin:0;padding:0" onmouseover="odnaknopka2.show(this);" onmouseout="odnaknopka2.timeout=setTimeout(\'odnaknopka2.hide()\',500);"></a></noindex>');
    }
}
function NewOdnaknopka1(msg)
{
    odnaknopka2=new NewOdnaknopka2();
    odnaknopka2.init(msg);
}
function _NewOdnaknopka1(msg)
{
    document.write('<noindex><a href="http://odnaknopka.ru/add/" rel="nofollow" onclick="window.open(\'http://odnaknopka.ru/add/?url=\'+encodeURIComponent(location.href)+\'&title=\'+encodeURIComponent(document.title),\'odnaknopka\',\'scrollbars=yes,menubar=no,width=600,height=500,left='+(document.body.clientWidth/2-300)+',top='+(document.body.clientHeight/2-250)+',resizable=yes,toolbar=no,location=no,status=no\');return false;"><img src="http://odnaknopka.ru/images/button.gif" width="136" height="16" alt="&#1054;&#1076;&#1085;&#1072;&#1050;&#1085;&#1086;&#1087;&#1082;&#1072;" title="'+msg+'" border="0"></a></noindex>');
}
function openWin(wind) //ValidHtml.php
{
    myWin= open(wind,"displayWindow","width=400,height=300,left=500,top=200,status=no,toolbar=no,menubar=no");
    myWin.document.open();
    myWin.document.write("<html><head><title></head><body>");
    myWin.text("erhgeriuhgeuigh");
}
function SetWindowContent(str)
{
      myWin.document.write(str);
      myWin.document.write("</body></html>");
      myWin.document.close(); 
}
function mtRand(min, max) {
    var range = max - min + 1;
    var n = Math.floor(Math.random() * range) + min;
    return n;
}
function mkPass(len) {
    var len = len ? len : 14;
    var pass = '';
    var rnd = 0;
    var c = '';
    for (i = 0; i < len; i++) 
    {
        rnd = mtRand(0, 1); // Латиница или цифры
        if (rnd == 0) {
            c = String.fromCharCode(mtRand(48, 57));
        }
        if (rnd == 1) {
            c = String.fromCharCode(mtRand(65, 90));
        }
        pass += c;
        if ((i + 1) % 4 == 0 && len != (i + 1))
            pass += "-";
    }
    return pass;
}

/* cat.select(){
alert('hello');
});*/
function GetPayment(id) {
    $.ajax({
        url: 'selectPayment.php',
        type: 'POST',
        data: 'ajax=true&editor_id=' + id,
        dataType: 'html',
        timeout: 5000,

        beforeSend: function() {
            $('img.loading').show();
        },
        complete: function() {
            $('img.loading').hide();
        },
        success: function(jsn) {
            $('#idCost').text(0);
            $('#paidDiv').html("");
            $('#paidDiv').append(jsn);
        }
    });
}
function check_pole2() 
{
    var login = document.getElementById('admin_login').value;
    alert(login);
    var password = document.getElementById('logpass').value;
    if (login == '') {
        mess += "Введите логин\n";
    }
    if (password == '') {
        mess += "Введите пароль\n";
    }
    if (mess != '') {
        alert(mess);
        return false;
    }
    else {
        return true;
    }
}
checkField=function(someField)
 {
  switch(someField.name)
  {
    case "fio_val":
     div2hide = document.getElementById('div_fio');
     break;
    case "phone_val":
     div2hide = document.getElementById('div_phone');
     break;
    case "email_val":
     div2hide = document.getElementById('div_email');
     break;
    case "opinion":
     div2hide = document.getElementById('div_opinion');
     break;  
  }
   if(!someField.value)
   {
    div2hide.style.display = '';
   }
   else
   {
   div2hide.style.display = 'none';
   }

 }
 
 show_skidka = function()
 { 
   div2show = document.getElementById('skidki');
   div2show.style.display = '';
 }

 show_span = function(i)
 { 
   span2show = document.getElementById('sp_'+i);
   span2show.style.display = '';
 }
 hide_span = function(i)
 { 
   span2show = document.getElementById('sp_'+i);
   span2show.style.display = 'none';
 }
 
var xmlHttp = false;
   try {
     xmlHttp = new XMLHttpRequest();
   } catch (trymicrosoft) {
     try {
       xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
     } catch (othermicrosoft) {
       try {
         xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
       } catch (failed) {
         xmlHttp = false;
       }  
     }
   }
  
 function del_opinion(opinion_id)
 {
  var url = "/scripts/opinions.php?action=delete&op_id="+opinion_id;
  xmlHttp.open("GET", url, true);
  xmlHttp.onreadystatechange = deleteOpinionUpdatePage;
  xmlHttp.send(null);
  td_name="td_del_"+opinion_id;
 }
 
function deleteOpinionUpdatePage() {
   if (xmlHttp.readyState == 4 && xmlHttp.status==200) {
   var response = xmlHttp.responseText;
   td_name="td_del_"+response;
   document.getElementById(td_name).innerHTML = "<b>удалено</b>";
   document.getElementById(td_name).className="div_processed";
  }
  else 
  { //document.getElementById(td_name).innerHTML = "удаление...";
  }
} 

function check_opinion(opinion_id)
 {
  var url = "/scripts/opinions.php?action=check&op_id="+opinion_id;
  xmlHttp.open("GET", url, true);
  xmlHttp.onreadystatechange = checkOpinionUpdatePage;
  xmlHttp.send(null);
  td_name="td_check_"+opinion_id;
 }
 
function checkOpinionUpdatePage() {
   if (xmlHttp.readyState == 4 && xmlHttp.status==200) {
   var response = xmlHttp.responseText;
  // td_name="td_del_"+response;
   document.getElementById(td_name).innerHTML = "<b>одобрено</b>";
   document.getElementById(td_name).className="div_processed";
  }
  else 
  {// document.getElementById(td_name).innerHTML = "одобрение...";
  }
}

function send_opinion()
{ 
  var opinion_fio = document.getElementById("opinion_fio").value;
  var opinion_text = document.getElementById("opinion_text").value;
  var opinion_site = encodeURIComponent(document.getElementById("opinion_site").value);
  if(opinion_text.length>=30)
  {
      opinion_text = encodeURIComponent(opinion_text.replace(/\n/g,"<br>"));
      var opinion_num = document.getElementById("opinion_num").value;
      var tovar_id = document.getElementById("tovar_id").value;
      var url = "/scripts/opinions.php?action=send&tovar_id="+tovar_id+"&fio_val="+opinion_fio+"&opinion="+opinion_text+"&opinion_num="+opinion_num+"&site_val="+opinion_site;
     // alert(url);
      xmlHttp.open("GET", url, true);
      xmlHttp.onreadystatechange = sendOpinionUpdatePage;
      xmlHttp.send(null);
  }
  else
    alert("Минимальное мнение о товаре 30 символов!");
}
 
function sendOpinionUpdatePage() {
   if (xmlHttp.readyState == 4 && xmlHttp.status==200) {
   var response = xmlHttp.responseText;
   //alert(response);
  // td_name="td_del_"+response;
  // document.getElementById("opinion_fio").value = "";
   document.getElementById("opinion_num").value = "";  
   if(response=="1") 
   {
     document.getElementById("opinion_text").value="";
    document.getElementById("opinion_send_status").innerHTML="Ваше мнение отправлено на рассмотрение модератору. Оно появится на сайте после проверки. Спасибо!";
   }
   else document.getElementById("opinion_send_status").innerHTML=response;
   document.getElementById("opinion_send_status").style.display="";
  }
  else 
  { document.getElementById("opinion_send_status").innerHTML="отправка данных...";
    document.getElementById("opinion_send_status").style.display="";
  }
}  

function send_user_email()
 { var user_email = document.getElementById("user_email").value;
   if(user_email)
   {
  var url = "/scripts/zakaz.php?action=extract_user_info&user_email="+user_email;
     // alert(url);
      xmlHttp.open("GET", url, true);
      xmlHttp.setRequestHeader("Content-Type", "text/plain; charset=windows-1251");
      xmlHttp.onreadystatechange = send_user_emailUpdatePage;
      xmlHttp.send(null);
   }
 }
 
function send_user_emailUpdatePage() {
   if (xmlHttp.readyState == 4 &&  xmlHttp.status==200) {
   var response = xmlHttp.responseText.split("|");
   //alert(xmlHttp.responseText);
   //alert(response[0]);
  // td_name="td_del_"+response;
   document.getElementById("user_fio").value = response[0];
   document.getElementById("user_phone").value = response[1];
   document.getElementById("user_phone2").value = response[2];
  }
  else 
  { 
  }
}  
function empty(mixed_var) 
{
    if(mixed_var=="" || mixed_var=="0" || mixed_var == "null" || mixed_var == null  || mixed_var == "false")
        return true;
    else
       return false;
}
$('html').keypress(function(e)
{
	pressed(e);
});
function IsMoscow(id_city)
{
	var city = $('#'+id_city).val();
    city = city.toLowerCase();
    if (city == 'мо' || city == 'москва' || city == 'moscow' || city == 'mo' || city == 'mscw')
	{
		return true;
	}
	else
		return false;
}
function IsMetro(id_city) //'#user_city'
{
   if(IsMoscow(id_city))
        $('.sp_metro').css('display', 'table-row');
    else
        $('.sp_metro').css('display', 'none');
}
function changeMetro(idOkrug, id_select) {
    $.ajax({
        url: 'indexAjax.php',
        type: 'POST',
        data: 'ajax=true&section=ChangeOkrug&region=' + idOkrug,
        dataType: 'html',
        timeout: 5000,
        success: function(metro_s) {
            if (metro_s !== '') {
                $('#' + id_select + ' option').remove();
                $('#' + id_select).append(metro_s);
            }
        }
    });
}
function pressed(event) 
{
    if ((event.keyCode == 13 || event.keyCode == 10) && event.ctrlKey) 
	{
        if (navigator.appName == "Microsoft Internet Explorer") {
            var range = document.selection.createRange();
            errText = range.text;
        }
        else {
            errText = getSelection();
        }
        if (errText != "") 
		{
            var textMsg = 'URL: ' + self.location.href + '\n\r\n\rТекст: "' + errText + '"\n\r\n\rОтослать замечание?';
            if (confirm(textMsg)) 
			{
				errText = encodeURIComponent(errText);
				var selfLocat = encodeURIComponent(self.location.href);
				
                $.ajax({
                    url: 'indexAjax.php',
                    type: 'POST',
                    data: 'ajax=true&section=see_error&text=' + errText  + '&location=' + selfLocat,
                    dataType: 'json',
                    timeout: 5000,
                    success: function(msg) {
                        alert(msg.msg);
                    }
                });
            }
        }
    }
}

