//===========================================================
function popup(path) {
        window.open(path, "smth","width=500,height=500,top=100,left=200,titlebar=no,toolbar=no,location=no,statusbar=no,menubar=no,scrollbars=no,resizable=no");
}

function popupGoods(path) {
        window.open(path, "goods","width=680,height=500,top=100,left=200,titlebar=no,toolbar=no,location=no,statusbar=no,menubar=no,scrollbars=yes,resizable=no");
}

//Select All for multiple select by Gleb Deykalo gd@defa.ru
function setSelectOptions(the_form, the_select, do_check)
{
    var selectObject = document.forms[the_form].elements[the_select];
    var selectCount  = selectObject.length;

    for (var i = 0; i < selectCount; i++) {
        selectObject.options[i].selected = do_check;
    }

    return true;
}

//======================================================
/*
JS Gallery (without reloading page) by GD gd@defa.ru
*/
function prev(id) {
        if (cur_i[id] == 1) {
                cur_i[id] = max_i[id];
        } else {
                cur_i[id]=cur_i[id]-1;
        }

        $('photo'+id).src=f[id][cur_i[id]];
        $('photo'+id).alt=n[id][cur_i[id]];

        $('ph_name'+id).innerHTML=n[id][cur_i[id]];
        $('cpr'+id).innerHTML=cpr[id][cur_i[id]];
        $('lnk'+id).innerHTML='<a href="'+lnk[id][cur_i[id]]+'">'+lnk[id][cur_i[id]]+'</a>';
}

function next(id) {
        if (cur_i[id] == max_i[id]) {
                cur_i[id]=1;
        } else {
                cur_i[id]=cur_i[id]+1;
        }

        $('photo'+id).src=f[id][cur_i[id]];
        $('photo'+id).alt=n[id][cur_i[id]];

        $('ph_name'+id).innerHTML=n[id][cur_i[id]];
        $('cpr'+id).innerHTML=cpr[id][cur_i[id]];
        $('lnk'+id).innerHTML='<a href="'+lnk[id][cur_i[id]]+'">'+lnk[id][cur_i[id]]+'</a>';
}
//======================================================
//Omni functions
function clear_me(field) {
        if ((field.name=='login') && (field.value=='логин'))  {
                field.value="";
        }

        if ((field.name=='pwd') && (field.value=='******')) {
                field.value="";
        }

}

function change_validation(frm) {
//        alert(frm.name.alt);
        frm.name.alt='blank';
//        alert(frm.name.alt);
        frm.phone.alt='blank';
        frm.mail.alt='email|3';
        frm.city.alt='blank';
        frm.address.alt='blank';
}

function res() {
        var x=document.getElementById('top').offsetWidth;
        var y=document.getElementById('top').offsetHeight+document.getElementById('bottom').offsetHeight;

        window.resizeTo(x+6,y+67);
}


//=============================================================
//rollover

function SimpleSwap(el,which) {
    el.src = el.getAttribute(which || "origsrc");
}
function SimpleSwapSetup(){
    var x = document.getElementsByTagName("img");
    for (var i=0;i<x.length;i++){
    var oversrc = x[i].getAttribute("oversrc");
    if (!oversrc) continue;

    // preload image
    // comment the next two lines to disable image pre-loading
    x[i].oversrc_img = new Image();
    x[i].oversrc_img.src=oversrc;
    // set event handlers
    x[i].onmouseover = new Function("SimpleSwap(this,'oversrc');");
    x[i].onmouseout = new Function("SimpleSwap(this);");
    // save original src
    x[i].setAttribute("origsrc",x[i].src);
}
}
var PreSimpleSwapOnload =(window.onload)? window.onload : function(){};
window.onload = function(){PreSimpleSwapOnload(); SimpleSwapSetup();}

//=============================================================

function showOrHide(id, li) {
    var div = document.getElementById('childs_of_'+id);

    if ((typeof(div) != 'undefined') && (div != null)) {
        if (div.style.display == 'none') {
            div.style.display = 'block';
            li.className = 'active';
        } else {
            div.style.display = 'none';
            li.className = '';            
        }
    }
}

function getgs(id) {
    var div = document.getElementById(id);

    if ((typeof(div) != 'undefined') && (div != null)) {
        if (div.style.visibility == 'hidden') {
            div.style.visibility = 'visible';
        } else {
            div.style.visibility = 'hidden';
        }
    }
}

var opened_div = '';

function order(id) {
    closeDiv(opened_div);
    opened_div = 'div_' + id;

    var div = document.getElementById(opened_div);
    if ((typeof(div) != 'undefined') && (div != null)) {
        div.style.visibility = 'visible';
    }
}

function closeDiv(id) {
    var div = document.getElementById(id);
    if ((typeof(div) != 'undefined') && (div != null)) {
        div.style.visibility = 'hidden';
    }
}

function sendOrder(form, id) {
    var quant = document.getElementById('quantity' + id);

    if ((typeof(quant) != 'undefined') && (quant != null)) {
        if (quant.value > 0) {
            location.href = form.action.replace(/quantity\.1/, 'quantity.' + quant.value);
            closeDiv('order' + id);
        }
    }
}

function showorder(id) {
    var div = document.getElementById(id);
    div.style.display = 'block';
}

function loader()
{
	var div1 = document.getElementById('preloader');
	var div2 = document.getElementById('fake');
	div1.style.display = 'none';
	if (navigator.userAgent.indexOf("MSIE") >= 0) {
		div2.style.display = 'block';
	} else {
		div2.style.display = 'table-cell';
	}
	div2.style.visibility = 'visible';
}

function loaderbase()
{
	var div = document.getElementById('l-wrap');
	div.style.display = 'none';
}