function getEl(some){
    return document.getElementById(some);
}

function setlang(str){
    document.exitform.logout.value = str;
    document.exitform.logout.name = "nd_switch_lang";
    document.exitform.submit();
}

function checkCartWinNumeric(e){
        if (!e.key.toInt() && e.key.toInt() != 0) {
            if (e.key == "enter"){
                updateCart(e.target.id.substr(5), $(e.target.id).value);
            }
            if (e.key != "backspace" && e.key != "left" && e.key != "right" && e.key != "delete") e.stop();
        }
}

function initCartPage() {
        var divs = $('cart-holder').getElementsByTagName("input");
	for (var i=0; i<divs.length; i++)  {
        if (divs[i].className == "qtt") {
            $(divs[i]).removeEvent("keypress", checkCartWinNumeric);
            $(divs[i]).addEvent("keypress", checkCartWinNumeric);
        }
    }
}


function Raiting() {
	for(i=0; i<jQuery('.rating').size(); i++)
	{
		stars = jQuery('.rating:eq('+i+')').text()*18;
		jQuery('.rating:eq('+i+') span').css('width',stars+'px');
	};
}

function ReinitScroll(scroll,scrollto) {
    jQuery('.cart .goods').jScrollPane({showArrows:true});
    var v_nums_str = ' '+jQuery('input.v_nums_str').attr('value');
    for(i=0; i<jQuery('.nums input').size(); i++) jQuery('.nums input:eq('+i+')').attr('value',(parseInt(jQuery('.nums input:eq('+i+')').attr('value'))+v_nums_str));
    jQuery('#loading-mini').css('display','none');
            if(scroll==1) {
            if(scrollto==0) {
               jQuery('#jpane')[0].scrollTo(222200);
              }
              else
              {
                 jQuery('#jpane')[0].scrollTo(scrollto);
              }
            }
}

function ReinitQuan() {
    var v_nums_str = ' '+jQuery('input.v_nums_str').attr('value');
    for(i=0; i<jQuery('.nums input').size(); i++) jQuery('.nums input:eq('+i+')').attr('value',(parseInt(jQuery('.nums input:eq('+i+')').attr('value'))+v_nums_str));
}



function loadCart(){
  jQuery('#cart').load('/cart_handler.php');
}


function loadLoginForm(){
    jQuery('#ht-logn').load('/login_handler.php');
}

function logout(){
    var ajax = new sack();
    ajax.method        = 'POST';
    ajax.requestFile   = '/login_handler.php';
    ajax.setVar("logout", 1);
    ajax.whenCompleted = function(){
        if (!document.getElementById('input_login') && document.getElementById('opinion_container')){
            document.getElementById('opinion_container').style.display = "block";
            document.getElementById('opinion_na_container').style.display = "none";
        } else {
            if (document.getElementById('opinion_container')){
                document.getElementById('opinion_container').style.display = "none";
                document.getElementById('opinion_na_container').style.display = "block";
            } else {
                loadCart();
            }
        } 
    }
    ajax.element       = 'ht-logn';
    ajax.runAJAX();
}

function clearCart(){
    var ajax = new sack();
    if (getEl('loading-mini')) getEl('loading-mini').style.visibility = "visible";
    ajax.method        = 'POST';
    ajax.setVar("clear", 1);
    ajax.requestFile   = '/cart_handler.php';
    ajax.element       = 'cart';
    ajax.whenLoading = function(){}
    ajax.whenCompleted = function(){
        getEl('loading-mini').style.visibility = "hidden";
        initCartPage();
    }
    ajax.runAJAX();
}

function updateCart(id, quantity){
  quan=quantity.replace(" шт.","");                                   
  mstring = '?id='+id+'&quantity='+quan+'&act=upd';
  jQuery('#cart').load('/cart_handler.php'+mstring);
}


function addToCartHistory(products){
   mstring = '?ids='+products;
  jQuery('#cart').load('/cart_handler.php'+mstring);          
}

function addToCart(id, quantity){
  jQuery('#loading-mini').css('display','');
  jQuery('.cart').css('display','');
  if(quantity==1) {
     quantity=quantity+" шт."                              
  }
  if ($("field"+id)) {
    mval=$("field"+id).value;
    nval=mval;                             
    if(mval.search(" шт.")) {
      nval=mval.replace(" шт.","");
    }                                   
    $("field"+id).value=nval++;
  }
  ReinitQuan();
  quan=quantity;                             
  if(quantity.search(" шт.")) {
     quan=quantity.replace(" шт.","");
  }                                   
  mstring = '?id='+id+'&quantity='+quan+'&scroll=bottom';
  jQuery('#cart').load('/cart_handler.php'+mstring);
//   jQuery('#jpane')[0].scrollTo(222200);
            
    jQuery("#text-col-"+id).val('1');        
}


function removeFromCart1(id){
}



function removeFromCart(id){
  jQuery('#loading-mini').css('display','');                             
  if ($("field"+id)) {
    mval=$("field"+id).value;
    nval=mval.replace(" шт.","");
    $("field"+id).value=nval--;
  }                             
  ReinitQuan();                             
  mstring = '?id='+id+'&remove='+id;
  jQuery('#cart').load('/cart_handler.php'+mstring);                                   
                                 
}

function delFromCart(id){
  mstring = '?id='+id+'&del='+id;
  jQuery('#cart').load('/cart_handler.php'+mstring);
}


function delFromCartALL(){          
  jQuery('#cart').load('/cart_handler.php?clear=2');
}

function undelFromCartALL(){          
  jQuery('#cart').load('/cart_handler.php?clear=3');
}




function delFromCart1(id,eleme,quantity){
        jQuery(eleme).parents('div.item').find('img, .name, .price').animate({opacity:0.3});
	jQuery(eleme).hide();
                             //alert('mydel');
  mstring = '?id='+id+'&delhide='+id+'&quantity='+quantity;
  jQuery('#cart').load('/cart_handler.php'+mstring);
}

function undelFromCart1(id,eleme,quantity){
        jQuery(eleme).parents('div.item').find('img, .name, .price').animate({opacity:1});
	jQuery(eleme).hide();
                             
  mstring = '?id='+id+'&delshow='+id+'&quantity='+quantity;
  jQuery('#cart').load('/cart_handler.php'+mstring);
}


function delFromCartSilent(id){
    var ajax = new sack();
    ajax.method        = 'POST';
    ajax.setVar("id", id);
    ajax.setVar("del", id);
    ajax.whenLoading = function(){}
    ajax.requestFile   = '/cart_handler.php';
    ajax.element       = '';
    ajax.runAJAX();
}

function goToCart(path, sum, min_sum, alert_msg){
            window.location.href = path;
    //if (sum > min_sum) window.location.href = path;
    //else alert('Минимальная сумма заказа: 100грн');
}

function withoutShipping(el){
    if (el.checked) getEl('address').disabled = 'disabled';
    else getEl('address').disabled = '';
}

function withoutAddress(){
    if (!getEl('rb_addr_avbl').checked) getEl('address').disabled = 'disabled';
    else getEl('address').disabled = '';
}

function withFarfor(el){
    if (el.checked) getEl('farfor').disabled = '';
    else getEl('farfor').disabled = 'disabled';
}

function orderSubmit(){
    getEl('address').disabled = '';
    getEl('surname').disabled = '';
    getEl('email').disabled = '';
}

function banketSubmit(){
    getEl('mail').disabled = '';
}

function ending_hour(i, word){
                        if ((i>0 && i<10)||(i>20)){
                        last = i.toString().substring(i.toString().length, 0);
                        if (last==1) return word;
                        else {if (last>1 && last<5) return word+"а";
                        else return word+"ов";}
                    } else {
                        return word+"ов";
                    }}

function ending_min(i, word){
                        if ((i>0 && i<10)||(i>20)){
                        last = i.toString().substring(i.toString().length, 1); 
                        if (last==1) return word+"а";
                        else {if (last>1 && last<5) return word+"ы";
                        else return word;}
                    } else {
                        return word;
                    }}

function drawCountDown(expoffer)
	{
	today  = new Date();
	todayDate  = today.getTime();

	target = new Date(expoffer); 
	targetDate = target.getTime();
	if ((targetDate - todayDate)>0) {
		dayzLeft = (Math.floor(((targetDate - todayDate) / (60*60)) / 1000)-(Math.floor(((targetDate - todayDate) / (60*60)) / 1000)%24))/24;
		hourzLeft = (Math.floor(((targetDate - todayDate) / (60*60)) / 1000)%24);
		minutezLeft = (Math.floor(((targetDate - todayDate) / (60)) / 1000)%60);
		//secondzLeft = (Math.floor((targetDate - todayDate) / 1000)%60);

		//document.getElementById("countdays").innerHTML = dayzLeft;
		if (hourzLeft) document.getElementById("counthours").innerHTML = hourzLeft + " " + ending_hour(hourzLeft, 'час');
                else document.getElementById("counthours").innerHTML = "";
		if (minutezLeft) document.getElementById("countminutes").innerHTML = minutezLeft + " " + ending_min(minutezLeft, 'минут');
                else document.getElementById("countminutes").innerHTML = "";
		//document.getElementById("countseconds").innerHTML = secondzLeft;
		}
	else {
                //document.getElementById("ac-tc").style.display = "none";
		//document.getElementById("ac-tl").style.display = "none";
		//document.getElementById("ac-tc").style.display = "none";
		}
	}

function vote(q){
    function is_numeric(num){
	var exp = new RegExp("^([0-9])*$","g");
	return exp.test(num);
    }
    var ajax = new sack();
    if (q){
        for (var i=0;i<9;i++){
            if (document.voteform.answers.item(i) != null && document.voteform.answers.item(i).checked) {
                ajax.setVar('voted', document.voteform.answers.item(i).value);
            }
        }
    }
    
    ajax.method        = 'POST';
    ajax.requestFile   = '/public_voting_handler.php';
    ajax.element       = 'voting_';
    ajax.runAJAX();
}

var currentSubitem = null;
var nextSubitem = null;
var inHide = 0;
var inShow = 0;
var fromShow = 0;

function showSubmenu(el){
    el1 = el;
    el = el.parentNode.getElementsByTagName("ul");
    if (el.length == 0){
        nextSubitem = null;
        toggleSubmenu();
        return true;
    }
    el = $(el[0]);

    if (currentSubitem != el && nextSubitem != el){
        nextSubitem = el;
        toggleSubmenu();        
    }
}

function hideSubMenu(){
    nextSubitem = null;
    toggleSubmenu();
}

function toggleSubmenu(){
    if (inShow == 1 || inHide == 1){
        return true;
    }
    if (currentSubitem != null && (fromShow==0 || (fromShow==1 && nextSubitem != null))){
        fromShow = 0;
        hideSubItem();
    } else {
        fromShow = 0;
        showNextSubmenu();
    }
}

function showNextSubmenu(){
    if (nextSubitem == null){
        return true;
    }
    if (inShow == 1 || inHide == 1){
        toggleSubmenu();
        return true;
    }
    else {
        inShow = 1;
    }
    if (nextSubitem == currentSubitem){
        nextSubitem = null;
        inShow = 0;
        return true;
    }

    el1 = nextSubitem;
    el = nextSubitem.parentNode.getElementsByTagName("ul");
    if (el.length == 0){
        nextSubitem = null;
        currentSubitem = null;
        return true;
    }
    el = $(el[0]);

    if (currentSubitem!=null){
        toggleSubmenu();
        return true;
    }
    
    if (!el || el == "undefined" || el.style.display == "block"){
        nextSubitem = null;
        currentSubitem = null;
        return true;
    }

    currentSubitem = el;
    nextSubitem = null;

    el1 = el1.parentNode.getElementsByTagName("a");
    el1 = $(el1[0]);
    el1.className = "navitemhovered";

    el.style.overflow = "hidden";
    el.style.visibility = "hidden";
    el.style.height = "auto";
    el.style.display = "block";
    var sizes = $(el).getSize();
    el.style.height = "1px";
    el.style.visibility = "visible";

    var eff = new Fx.Morph(el, {duration: 200, onComplete: function(){
                                          inShow = 0;
                                          fromShow = 1;
                                          toggleSubmenu();
                               }});
    eff.start({
        'height': sizes['y']
    });
}

function hideSubItem(){
    if (currentSubitem == null){
        return true;
    }
    
    if (inHide == 1 || inShow == 1){
        toggleSubmenu();
        return true;
    }
    else {
        inHide = 1;
    }

    currentSubitem.style.overflow = "hidden";
    var sizes = currentSubitem.getSize();

    var eff = new Fx.Morph(currentSubitem, {duration: 200, onComplete: function(){
                                          el1 = currentSubitem.parentNode.getElementsByTagName("a");
                                          el1 = $(el1[0]);
                                          el1.className = "navitemvisited";
                                          currentSubitem.style.display = "none";
                                          currentSubitem = null;
                                          inHide = 0;
                                          toggleSubmenu();
                               }});
    eff.start({
        'height': 1
    });
}


function iinc(el){
    $(el).value = $(el).value*1 + 1;
    return false;
}

function idec(el){
    $(el).value = ($(el).value > 1) ? ($(el).value*1 - 1) : 1;
    return false;
}

function switchToCat(){
    $('cat_selector').className = "active";
    $('par_selector').className = "";
    $('catTab').style.display = "block";
    $('parTab').style.display = "none";
}

function switchToSelector(){
    $('par_selector').className = "active";
    $('cat_selector').className = "";
    $('catTab').style.display = "none";
    $('parTab').style.display = "block";
}

var openedForm = null

function openOfferForm(el){
    hideOfferForm();
    openedForm = el;
    var eff = new Fx.Morph(el, {duration: 400, transition: Fx.Transitions.Quad.easeOut});
    eff.set({
        'opacity': 0
    });
    $(el).style.visibility = "visible";
    eff.start({
        'opacity': 1
    });
    return false;
}

function hideOfferForm(){
    if (openedForm != null){
        var id = openedForm.substr(5);
        var eff = new Fx.Morph(openedForm, {duration: 300, transition: Fx.Transitions.Quad.easeOut, onComplete: function(){
        }});
        eff.start({
            'opacity': 0
        });
        openedForm = null;
    }
}

function showPopup(){

document.body.style.overflow = 'hidden';
//window.onscroll=function() { window.scrollTo(0,0) }



    $('popup').style.visibility = "hidden";       
    $('popup').style.display = "block";
 
    var sizes = $("popup").getSize();
    
    $('popup').style.display = "none";
    $('popup').style.visibility = "visible";
    var w = $(window).getSize();
    $('popup').style.left = (w['x']-sizes['x'])/2 + 'px';
    $('popup').style.top = ((w['y'] ? w['y'] : w['x']*0.5)-sizes['y'])/2 + 'px';
  
    showWindow("popup", "popup_close","image");
   
}

function showOpinionPopup(){
    $('opinion_popup').style.visibility = "hidden";
    $('opinion_popup').style.display = "block";
    var sizes = $("opinion_popup").getSize();
    $('opinion_popup').style.display = "none";
    $('opinion_popup').style.visibility = "visible";
    var w = $(window).getSize();
    $('opinion_popup').style.left = (w['x']-sizes['x'])/2 + 'px';
    $('opinion_popup').style.top = ((w['y'] ? w['y'] : w['x']*0.5)-sizes['y'])/2 + 'px';
    showWindow("opinion_popup", "opinion_popup_close");
}

function showRecoverPopup(){
    $('recover_popup').style.visibility = "hidden";
    $('recover_popup').style.display = "block";
    var sizes = $("recover_popup").getSize();
    $('recover_popup').style.display = "none";
    $('recover_popup').style.visibility = "visible";
    var w = $(window).getSize();
    $('recover_popup').style.left = (w['x']-sizes['x'])/2 + 'px';
    $('recover_popup').style.top = ((w['y'] ? w['y'] : w['x']*0.5)-sizes['y'])/2 + 'px';
    showWindow("recover_popup", "recover_popup_close");
}

function check_field(field){
    switch ($(field).name){
        case "email": if ($(field).value.length == 0) {
                          $("email_tip").innerHTML = "<span class=\"tip-left\">&nbsp;</span>Вы не ввели e-mail!<span class=\"tip-right\">&nbsp;</span>";
                          $("email_tip").className = "tip-visible";
                      } else {
                          var regex = new RegExp("^([a-z0-9\+_\-]+)(\.[a-z0-9\+_\-]+)*@([a-z0-9\-]+\.)+[a-z]{2,6}$");
                          if (!regex.test($(field).value)){
                              $("email_tip").innerHTML = "<span class=\"tip-left\">&nbsp;</span>Что-то не похоже на e-mail!<span class=\"tip-right\">&nbsp;</span>";
                              $("email_tip").className = "tip-visible";
                          } else {
                              $("email_tip").innerHTML = "<span class=\"tip-left\">&nbsp;</span>Проверяю...<span class=\"tip-right\">&nbsp;</span>";
                              $("email_tip").className = "tip-visible";
                              var ajax = new sack();
                              $('reg_submit').disabled = "disabled";
                              ajax.method        = 'POST';
                              ajax.requestFile   = '/check_email_handler.php';
                              ajax.element       = 'hiddenbox';
                              ajax.setVar("email", $(field).value);
                              ajax.whenLoading = function(){}
                              ajax.whenCompleted = function(){
                                  if ($('hiddenbox').innerHTML == "ok") {
                                      $("email_tip").className = "tip";
                                      $('reg_submit').disabled = "";
                                  } else {
                                      $("email_tip").innerHTML = "<span class=\"tip-left\">&nbsp;</span>Вы уже зарегистрированы у нас. <a href='/pass_recover'>Напомнить пароль?</a><span class=\"tip-right\">&nbsp;</span>";
                                      $("email_tip").className = "tip-visible";
                                  }
                                  $('hiddenbox').innerHTML = "";
                              }
                              ajax.runAJAX();
                          }
                      }
                      break;
        case "repassword": if ($("reg_password").value != $("reg_repassword").value) {
                               $($(field).name + "_tip").className = "tip-visible";
                           } else {
                               $($(field).name + "_tip").className = "tip";
                           }
                           break;
        default:  if ($(field).value.length == 0) {
                      $($(field).name + "_tip").className = "tip-visible";
                  } else {
                      $($(field).name + "_tip").className = "tip";
                  }
    }
}

function validate_reg_form(){
    var error = 0;
    if ($("reg_email").value.length==0){
        error++;
        $("email_tip").innerHTML = "<span class=\"tip-left\">&nbsp;</span>Вы не ввели e-mail!<span class=\"tip-right\">&nbsp;</span>";
        $("email_tip").className = "tip-visible";
    } else {
        var regex = new RegExp("^([a-z0-9\+_\-]+)(\.[a-z0-9\+_\-]+)*@([a-z0-9\-]+\.)+[a-z]{2,6}$");
        if (!regex.test($("reg_email").value)){
            error++;
            $("email_tip").innerHTML = "<span class=\"tip-left\">&nbsp;</span>Что-то не похоже на e-mail!<span class=\"tip-right\">&nbsp;</span>";
            $("email_tip").className = "tip-visible";
        } else {
            $("email_tip").className = "tip";
        }
    }
    if ($("reg_tel").value.length==0){
        error++;
        $("tel_tip").className = "tip-visible";
    } else {
        $("tel_tip").className = "tip";
    }
    if ($("reg_mon").value=="-" || $("reg_year").value=="-" || $("reg_day").value=="-"){
        error++;
        $("reg_date_tip").className = "tip-visible";
    } else {
        $("reg_date_tip").className = "tip";
    }
    if ($("reg_name").value.length==0){
        error++;
        $("name_tip").className = "tip-visible";
    } else {
        $("name_tip").className = "tip";
    }
    if ($("reg_surname").value.length==0){
        error++;
        $("surname_tip").className = "tip-visible";
    } else {
        $("surname_tip").className = "tip";
    }
    if ($("reg_password").value.length==0){
        error++;
        $("password_tip").className = "tip-visible";
    } else {
        $("password_tip").className = "tip";
    }
    if ($("reg_fromwhere").value==0){
        error++;
        $("reg_fromwhere_tip").className = "tip-visible";
    } else {
        $("reg_fromwhere_tip").className = "tip";
    }
    if ($("reg_password").value != $("reg_repassword").value){
        error++;
        $("repassword_tip").className = "tip-visible";
    } else {
        $("repassword_tip").className = "tip";
    }
    
    if (error == 0){
        var ajax = new sack();
        ajax.method        = 'POST';
        ajax.requestFile   = '/register_handler.php';
        ajax.element       = 'hiddenbox';
        ajax.setVar("email", $("reg_email").value);
        ajax.setVar("day", $("reg_day").value);
        ajax.setVar("mon", $("reg_mon").value);
        ajax.setVar("year", $("reg_year").value);
        ajax.setVar("fromwhere", $("reg_fromwhere").value);
        ajax.setVar("password", $("reg_password").value);
        ajax.setVar("repassword", $("reg_repassword").value);
        ajax.setVar("fromwhere", $("reg_fromwhere").value);
        ajax.setVar("name", $("reg_name").value);
        ajax.setVar("surname", $("reg_surname").value);
        ajax.setVar("tel", $("reg_tel").value);
        ajax.setVar("address", $("reg_address").value);
        $('l1').style.display = "block";
        //$('reg_form').style.display = "none";
        //$('popup').style.display = "none";
        jQuery('#popup').css('display','none');
        jQuery('#dark').css('display','none');
        ajax.whenLoading = function(){}
        ajax.whenCompleted = function(){
            if ($('hiddenbox').innerHTML == "ok") {
                $('reg_form').reset();
                loadLoginForm();
                hidePopup();
            } else {
                $('error_area').innerHTML = "<span style='color:red'>Ошибка при регистрации</span>";
            }
            $('reg_form').style.display = "block";
            $('l1').style.display = "none";
            $('hiddenbox').innerHTML = "";
        }
        ajax.runAJAX();
    }
    
}


function sendPassword(){
    var error = 0;
    if ($("recover_email").value.length==0){
        error++;
        $("recover_email_tip").innerHTML = "<span class='tip-left'>&nbsp;</span>Вы не ввели e-mail!<span class='tip-right'>&nbsp;</span>";
        $("recover_email_tip").className = "tip-visible";
    } else {
        var regex = new RegExp("^([a-z0-9\+_\-]+)(\.[a-z0-9\+_\-]+)*@([a-z0-9\-]+\.)+[a-z]{2,6}$");
        if (!regex.test($("recover_email").value)){
            error++;
            $("recover_email_tip").innerHTML = "<span class='tip-left'>&nbsp;</span>Что-то не похоже на e-mail!<span class='tip-right'>&nbsp;</span>";
            $("recover_email_tip").className = "tip-visible";
        } else {
            $("recover_email_tip").className = "tip";
        }
    }
    if (error == 0){
        var ajax = new sack();
        ajax.method        = 'POST';
        ajax.requestFile   = '/recover_handler.php';
        ajax.element       = 'recover_hiddenbox';
        ajax.setVar("mail", $("recover_email").value);
        $('l2').style.display = "block";
        $('recover_form').style.display = "none";
        ajax.whenCompleted = function(){
            if ($('recover_hiddenbox').innerHTML == "ok") {
                $('recover_error_area').innerHTML = "На Ваш e-mail отправлено письмо с инструкциями по восстановлению пароля";
            } else {
                $('recover_error_area').innerHTML = $('recover_hiddenbox').innerHTML;
            }
            $('recover_form').style.display = "block";
            $('l2').style.display = "none";
            $('recover_hiddenbox').innerHTML = "";
        }
        ajax.runAJAX();
    }
}



function sendPassword1(){
    var error = 0;
    if ($("input_login7").value.length==0){
        error++;
        $("recover_email_tip1").innerHTML = "<span class='tip-left'>&nbsp;</span>Вы не ввели e-mail!<span class='tip-right'>&nbsp;</span>";
        $("recover_email_tip1").className = "tip-visible";
    } else {
        var regex = new RegExp("^([a-z0-9\+_\-]+)(\.[a-z0-9\+_\-]+)*@([a-z0-9\-]+\.)+[a-z]{2,6}$");
        if (!regex.test($("input_login7").value)){
            error++;
            $("recover_email_tip1").innerHTML = "<span class='tip-left'>&nbsp;</span>Что-то не похоже на e-mail!<span class='tip-right'>&nbsp;</span>";
            $("recover_email_tip1").className = "tip-visible";
        } else {
            $("recover_email_tip1").className = "tip";
        }
    }
    if (error == 0){
        var ajax = new sack();
        ajax.method        = 'POST';
        ajax.requestFile   = '/recover_handler.php';
        ajax.element       = 'recover_hiddenbox1';
        ajax.setVar("mail", $("input_login7").value);
        ajax.whenCompleted = function(){
            if ($('recover_hiddenbox1').innerHTML == "ok") {
                jQuery('#recover_error_area1').css('display','');
                $('recover_error_area1').innerHTML = "На Ваш e-mail отправлено письмо с инструкциями по восстановлению пароля";
            } else {
                $('recover_error_area1').innerHTML = $('recover_hiddenbox1').innerHTML;
            }
            
        }
        ajax.runAJAX();
    }
}



function validate_banket_form(){
    var error = 0;
    if ($("banket_fio").value.length==0){
        error++;
        $("banket_fio_tip").className = "tip-visible";
    } else {
        $("banket_fio_tip").className = "tip";
    }
    if ($("banket_name").value.length==0){
        error++;
        $("banket_name_tip").className = "tip-visible";
    } else {
        $("banket_name_tip").className = "tip";
    }
    if ($("banket_tel").value.length==0){
        error++;
        $("banket_tel_tip").className = "tip-visible";
    } else {
        $("banket_tel_tip").className = "tip";
    }
    if ($("banket_mail").value.length==0){
        error++;
        $("banket_mail_tip").className = "tip-visible";
    } else {
        var regex = new RegExp("^([a-z0-9\+_\-]+)(\.[a-z0-9\+_\-]+)*@([a-z0-9\-]+\.)+[a-z]{2,6}$");
        if (!regex.test($("banket_mail").value)){
            error++;
            $("banket_mail_tip").innerHTML = "<span class='tip-left'>&nbsp;</span>Что-то не похоже на e-mail!<span class='tip-right'>&nbsp;</span>";
            $("banket_mail_tip").className = "tip-visible";
        } else {
            $("banket_mail_tip").className = "tip";
        }
    }
    if ($("banket_address").value.length==0){
        error++;
        $("banket_address_tip").className = "tip-visible";
    } else {
        $("banket_address_tip").className = "tip";
    }
    if ($("banket_guests").value.length==0){
        error++;
        $("banket_guests_tip").className = "tip-visible";
    } else {
        $("banket_guests_tip").className = "tip";
    }
    if ($("banket_date").value.length==0){
        error++;
        $("banket_date_tip").className = "tip-visible";
    } else {
        $("banket_date_tip").className = "tip";
    }

    if (error != 0){
        return false;
    }
}


function validate_opinion_form(){
    var error = 0;
    if ($("opinion_text").value.length==0){
        error++;
        $("opinion_text_tip").className = "tip-visible";
    } else {
        $("opinion_text_tip").className = "tip";
    }

    if (!$("opinion_rules").checked){
        error++;
        $("opinion_rules_tip").className = "tip-visible";
    } else {
        $("opinion_rules_tip").className = "tip";
    }

    if (!$("opinion_photo").value){
        error++;
        $("opinion_photo_tip").className = "tip-visible";
    } else {
        $("opinion_photo_tip").className = "tip";
    }

    if (error != 0){
        return false;
    } else return true;
}


function validate_feedback_form(){
    var error = 0;
    if ($("feedback_fio").value.length==0){
        error++;
        $("feedback_fio_tip").className = "tip-visible";
    } else {
        $("feedback_fio_tip").className = "tip";
    }
    if ($("feedback_tel").value.length==0){
        error++;
        $("feedback_tel_tip").className = "tip-visible";
    } else {
        $("feedback_tel_tip").className = "tip";
    }
    if ($("feedback_mail").value.length==0){
        error++;
        $("feedback_mail_tip").className = "tip-visible";
    } else {
        var regex = new RegExp("^([a-z0-9\+_\-]+)(\.[a-z0-9\+_\-]+)*@([a-z0-9\-]+\.)+[a-z]{2,6}$");
        if (!regex.test($("feedback_mail").value)){
            error++;
            $("feedback_mail_tip").innerHTML = "<span class='tip-left'>&nbsp;</span>Что-то не похоже на e-mail!<span class='tip-right'>&nbsp;</span>";
            $("feedback_mail_tip").className = "tip-visible";
        } else {
            $("feedback_mail_tip").className = "tip";
        }
    }
    if ($("feedback_message").value.length==0){
        error++;
        $("feedback_message_tip").className = "tip-visible";
    } else {
        $("feedback_message_tip").className = "tip";
    }

    if (error != 0){
        return false;
    }
}


function validate_profile_form(){
    var error = 0;
    if ($("profile_email").value.length==0){
        error++;
        $("profile_email_tip").innerHTML = "<span class='tip-left'>&nbsp;</span>Вы не ввели e-mail!<span class='tip-right'>&nbsp;</span>";
        $("profile_email_tip").className = "tip-visible";
    } else {
        var regex = new RegExp("^([a-z0-9\+_\-]+)(\.[a-z0-9\+_\-]+)*@([a-z0-9\-]+\.)+[a-z]{2,6}$");
        if (!regex.test($("profile_email").value)){
            error++;
            $("profile_email_tip").innerHTML = "<span class='tip-left'>&nbsp;</span>Что-то не похоже на e-mail!<span class='tip-right'>&nbsp;</span>";
            $("profile_email_tip").className = "tip-visible";
        } else {
            $("profile_email_tip").className = "tip";
        }
    }
    if ($("profile_tel").value.length==0){
        error++;
        $("profile_tel_tip").className = "tip-visible";
    } else {
        $("profile_tel_tip").className = "tip";
    }
    if ($("profile_name").value.length==0){
        error++;
        $("profile_name_tip").className = "tip-visible";
    } else {
        $("profile_name_tip").className = "tip";
    }
    if ($("profile_surname").value.length==0){
        error++;
        $("profile_surname_tip").className = "tip-visible";
    } else {
        $("profile_surname_tip").className = "tip";
    }
    if ($("profile_password").value.length==0){
        error++;
        $("profile_password_tip").className = "tip-visible";
    } else {
        $("profile_password_tip").className = "tip";
    }
    if ($("profile_password").value != $("profile_repassword").value){
        error++;
        $("profile_repassword_tip").className = "tip-visible";
    } else {
        $("profile_repassword_tip").className = "tip";
    }
    if (error != 0){
        return false;
    }
    
}

function profile_toggle(el){
    if ($('profile_pass_tr').className=="dn"){
        $('profile_pass_tr').className = "d";
        $('profile_repass_tr').className = "d";
        el.className = "w_arrow_open";
    } else {
        $('profile_pass_tr').className = "dn";
        $('profile_repass_tr').className = "dn";
        el.className = "w_arrow";
    }
}

function vacancy_toggle(el, id){
    if ($('vacancy_id_'+id).style.display == "" || $('vacancy_id_'+id).style.display == "none"){
        $('vacancy_id_'+id).style.display = "block";
        el.className = "wv_arrow_open";
    } else {
        $('vacancy_id_'+id).style.display = "none";
        el.className = "wv_arrow";
    }
}



function uncheck(el){

    $(el).checked = false;

    if ($(el.substr(0, el.length-1) + "1").checked){ 
        $('td_'+el.substr(0, el.length-1) + "1").style.background='#EDD38C';
        $('td_'+el.substr(0, el.length-1) + "2").style.background='#EDD38C';
        $('td_'+el.substr(0, el.length-1) + "3").style.background='#EDD38C';
    } else if ($(el.substr(0, el.length-1) + "2").checked){ 
        $('td_'+el.substr(0, el.length-1) + "1").style.background='#F3E7C1';
        $('td_'+el.substr(0, el.length-1) + "2").style.background='#F3E7C1';
        $('td_'+el.substr(0, el.length-1) + "3").style.background='#F3E7C1';
    } else {
        $('td_'+el.substr(0, el.length-1) + "1").style.background='#FFF';
        $('td_'+el.substr(0, el.length-1) + "2").style.background='#FFF';
        $('td_'+el.substr(0, el.length-1) + "3").style.background='#FFF';
    }    
    jQuery('.block_content').html("<div align='center' style='padding-top: 200px;'><div class='load'><img src='/img/loading.gif' alt='loading...' /></div></div>");   




    var names='';



    var inputList = document.param_form.getElementsByTagName('input');


    for (var i=0;i<inputList.length;i++)
    {
        if (inputList[i].type == "checkbox" && inputList[i].checked == true) {
           names=names+"&"+inputList[i].name+"="+inputList[i].value;
           //names= names + '"'+inputList[i].value+'",';
        }
    }


    //names = names + '""';
    //alert(names);
    //jQuery('.block_content').load('/search_handler.php?se=true&'+names);

    //var names='';

    jQuery('.block_content').load('/search_handler.php?'+names);
    
    
      // jQuery.get("/search_handler.php", { 'par[]': [names] },function(data){
	//	jQuery('.block_content').html(data);
	//});    

}


/*
function uncheck(el){
    $(el).checked = false;

    if ($(el.substr(0, el.length-1) + "1").checked){ 
        $('td_'+el.substr(0, el.length-1) + "1").style.background='#EDD38C';
        $('td_'+el.substr(0, el.length-1) + "2").style.background='#EDD38C';
        $('td_'+el.substr(0, el.length-1) + "3").style.background='#EDD38C';
    } else if ($(el.substr(0, el.length-1) + "2").checked){ 
        $('td_'+el.substr(0, el.length-1) + "1").style.background='#F3E7C1';
        $('td_'+el.substr(0, el.length-1) + "2").style.background='#F3E7C1';
        $('td_'+el.substr(0, el.length-1) + "3").style.background='#F3E7C1';
    } else {
        $('td_'+el.substr(0, el.length-1) + "1").style.background='#FFF';
        $('td_'+el.substr(0, el.length-1) + "2").style.background='#FFF';
        $('td_'+el.substr(0, el.length-1) + "3").style.background='#FFF';
    }

    var ajax = new sack();
    ajax.method        = 'POST';
    ajax.requestFile   = '/search_handler.php';
    ajax.element       = 'block_content';
    ajax.whenCompleted = function() {
        initCatPage();
    }
    ajax.whenLoading = function() {
        jQuery('.block_content').html("<div align='center' style='padding-top: 200px;'><div class='load'><img src='/img/loading.gif' alt='loading...' /></div></div>");
    }
 
    var inputList = document.param_form.getElementsByTagName('input');
    for (var i=0;i<inputList.length;i++)
    {
        if (inputList[i].type == "checkbox" && inputList[i].checked == true) {
           ajax.setVar(inputList[i].name, inputList[i].value);
        }
    } 
    ajax.runAJAX();
}
*/


function validate_v_form(id){
    var error = 0;
    if ($("v_name_"+id).value.length==0){
        error++;
        $("v_name_"+id+"_tip").className = "tip-visible";
    } else {
        $("v_name_"+id+"_tip").className = "tip";
    }
    
    if ($("v_job_before_"+id).value.length==0){
        error++;
        $("v_job_before_"+id+"_tip").className = "tip-visible";
    } else {
        $("v_job_before_"+id+"_tip").className = "tip";
    }
    
    if ($("v_tel_"+id).value.length==0){
        error++;
        $("v_tel_"+id+"_tip").className = "tip-visible";
    } else {
        $("v_tel_"+id+"_tip").className = "tip";
    }
    
    if ($("v_2x2_"+id).value.length==0){
        error++;
        $("v_2x2_"+id+"_tip").innerHTML = "<SPAN class='tip-left'> </SPAN>Поле не может быть пустым<SPAN class='tip-right'> </SPAN>";
        $("v_2x2_"+id+"_tip").className = "tip-visible";
    } else {
        if ($("v_2x2_"+id).value != "4"){
            error++;
            $("v_2x2_"+id+"_tip").innerHTML = "<SPAN class='tip-left'> </SPAN>А если подумать?..<SPAN class='tip-right'> </SPAN>";
            $("v_2x2_"+id+"_tip").className = "tip-visible";
        } else {
            $("v_2x2_"+id+"_tip").className = "tip";
        }
    }
    if (error != 0){
        return false;
    }
    
}


function cart_validate(){
    var error = 0;
    jQuery('#cart_name_tip').removeClass("tip-visible");
    jQuery('#cart_email_tip').removeClass("tip-visible");
    jQuery('#cart_tel_tip').removeClass("tip-visible");
    jQuery('#cart_address_tip').removeClass("tip-visible");
    jQuery('#cart_count_tip').removeClass("tip-visible");

    jQuery('#cart_email_tip').addClass("tip");
    jQuery('#cart_name_tip').addClass("tip");
    jQuery('#cart_tel_tip').addClass("tip");
    jQuery('#cart_address_tip').addClass("tip");
    jQuery('#cart_count_tip').addClass("tip");
    
    if(jQuery('#cart_name').val().length==0) {
      error++;
      jQuery('#cart_name_tip').removeClass("tip");
      jQuery('#cart_name_tip').addClass("tip-visible");      
    }
    
     if(jQuery('#cart_email').val().length==0) {
      error++;
      jQuery('#cart_email_tip').removeClass("tip");
      jQuery('#cart_email_tip').addClass("tip-visible");      
    }
        
     if(jQuery('#cart_tel').val().length==0) {
      error++;
      jQuery('#cart_tel_tip').removeClass("tip");
      jQuery('#cart_tel_tip').addClass("tip-visible");      
    }
    
    if(jQuery('#cart_address').val().length==0) {
      error++;
      jQuery('#cart_address_tip').removeClass("tip");
      jQuery('#cart_address_tip').addClass("tip-visible");      
    }        

    if(jQuery('#cart_count').val()==0) {
      error++;
      jQuery('#cart_count_tip').removeClass("tip");
      jQuery('#cart_count_tip').addClass("tip-visible");      
    }
    

    if (error != 0){
        return false;
    } else {
    
        jQuery('#reg_menu').css('display','');
       return false;
     }
    
}



// for faq
function initFaqPage()
{
	var n = document.getElementById("left-nav-faq");
	if (n)
	{
		var lis = n.getElementsByTagName("li");
		for (var i = 0; i < lis.length; i++)
		{
			if (lis[i].getElementsByTagName("ul").length)
			{
				if (lis[i].parentNode.id == "left-nav-faq")
				{
					var a = lis[i].getElementsByTagName("a").item(0);
					if (a)
					{
						a.onclick = function ()
						{
							var p = this.parentNode;
							if (p.className.indexOf("active") != -1)
								p.className = p.className.replace("active", "");
							else
								p.className += " active";
							return false;
						}
					}
				}
			}
		}
	}
}

function checkNumeric(e){
        if (!e.key.toInt() && e.key.toInt() != 0 && e.key != "backspace" && e.key != "delete" && e.key != "left" && e.key != "right") {
            e.stop();
        }
}

function cart_movedown(){
    if ($('last_id').value<$('max_id').value){
        $('last_id').value++;
        $('prod'+$('last_id').value).style.display = 'block';
        $('prod'+$('first_id').value).style.display = 'none';
        $('first_id').value++;
    }
    return false;
}

function cart_moveup(){
    if ($('first_id').value>0){
        $('first_id').value--;
        $('prod'+$('first_id').value).style.display = 'block';
        $('prod'+$('last_id').value).style.display = 'none';
        $('last_id').value--;
    }
    return false;
}


function initCatPage()
{

	var divs = document.getElementsByTagName("div");
	for (var i=0; i<divs.length; i++)  {
		if (divs[i].className == "cart-item")  {
			divs[i].onmouseover = function()
			{
			this.className += " cart-item-hover";
			}
			divs[i].onmouseout = function()
			{
			this.className = this.className.replace(" cart-item-hover", "");
			}
		}
		if (divs[i].className == "cart-item-holder")  {
			divs[i].onmouseover = function()
			{
			this.className += " cart-item-holder-hover";
			}
			divs[i].onmouseout = function()
			{
			this.className = this.className.replace(" cart-item-holder-hover", "");
			}
		}
	}

}


function imposeMaxLength(Object, MaxLen)
{
  return (Object.value.length <= MaxLen);
}


if (window.addEventListener)
	window.addEventListener("load", initCatPage, false);
else if (window.attachEvent)
	window.attachEvent("onload", initCatPage);