function explode(seporator, str) {
   var mas;
   mas=str.toString().split(seporator.toString());
   return mas;
}


function getObj(id) {
    var item = null;
    if (document.getElementById) {
        item = document.getElementById(id);
    }
    else if (document.all) {
        item = document.all[id];
    }
    else if (document.layers) {
        item = document.layers[id];
    }
    return item;
}

function ShowHide(id) {
    var item = null;
    if (document.getElementById) {
        item = document.getElementById(id);
    }
    else if (document.all) {
        item = document.all[id];
    }
    else if (document.layers) {
        item = document.layers[id];
    }
    if (!item) {
    }
    else if (item.style) {
        if (item.style.display == "none") {
            item.style.display = "";

        }
        else {
            item.style.display = "none";
        }
    }
    else {
        item.visibility = "show";
    }
}


var achtung_counter = 0;
var achtung_timer;
var achtung_error = true;
function achtung() {
    if (achtung_error) {
        getObj('loginplease').style.borderColor = "#FF0000";
        achtung_counter++;
        achtung_error=false;
    } else {
        getObj('loginplease').style.borderColor = "#B3B9C3";
        achtung_error=true;
    }
    if (achtung_counter < 3) {
        achtung_timer = setTimeout("achtung()",200);
        
        
    } else {
        achtung_counter = 0;
        clearTimeout(achtung_timer);
        getObj('loginplease').style.borderColor = "#B3B9C3";
        achtung_error = true;
    }
}

function orderform(id){
    dontlocation =0;
    $("#basketid").attr("value", id);
    $.post(
    '/katalog_get_vals.php',
    {
        id: id
    },
    drawOrderForm
    );
}

function drawOrderForm(result){
   $("#orderres").attr("innerHTML", result);
   $("#basketerr").hide();
   $("#orderform").show();
}

var dontlocation = 0;
function togoBasket(){
    toBasket();
    if (dontlocation == 0){
      document.location = "/katalog_basket.php";
    }
}

function toBasket(){
    var count = $("#bvals").attr("value");
    var id = $("#basketid").attr("value");
    if (count > 0){
        $.post(
        '/katalog_to_basket.php',
        {
            id:id,
            vals:count,
            act:"save"
        },
        drawTopBlockBasket
        )
    }
    else{
        alert('Укажите количество!');
    }
}

function drawTopBlockBasket(result){
   temp = explode("|", result);
   $("#basketres").attr("innerHTML", temp[2]);
   if(temp[0] == 1){
     $("#orderform").hide();
   }else{
     $("#bvals").attr("value", temp[1]);
     $("#basketerr").show();
     dontlocation =1;
   }
}

