function isie(){
	var isIE  = (navigator.appVersion.indexOf("MSIE") != -1) ? true : false;
	if(navigator.userAgent.indexOf("Opera") != -1){
		isIE = false;
	}
	return isIE;
}


function getEl(id){
    if(document.layers){
        return document.layers[id];
    }
    if(document.all && document.all.item){
        return document.all[id];
    }
    if(document.getElementById){
        return document.getElementById(id);
    }
}

function he(){
    if(document.body.clientWidth){
	   wdt = document.body.clientWidth;
	   clh = document.body.clientHeight;
    }
    if(window.innerWidth){
	   wdt = window.innerWidth;
	   clh = window.innerHeight;
    }
    return clh;
}

function getExpDate(days, hours, minutes) {
    var expDate = new Date( );
    if (typeof days == "number" && typeof hours == "number" && 
        typeof hours == "number") {
        expDate.setDate(expDate.getDate( ) + parseInt(days));
        expDate.setHours(expDate.getHours( ) + parseInt(hours));
        expDate.setMinutes(expDate.getMinutes( ) + parseInt(minutes));
        return expDate.toGMTString( );
    }
}
   
// utility function called by getCookie( )
function getCookieVal(offset) {
    var endstr = document.cookie.indexOf (";", offset);
    if (endstr == -1) {
        endstr = document.cookie.length;
    }
    return unescape(document.cookie.substring(offset, endstr));
}
   
// primary function to retrieve cookie by name
function getCookie(name) {
    var arg = name + "=";
    var alen = arg.length;
    var clen = document.cookie.length;
    var i = 0;
    while (i < clen) {
        var j = i + alen;
        if (document.cookie.substring(i, j) == arg) {
            return getCookieVal(j);
        }
        i = document.cookie.indexOf(" ", i) + 1;
        if (i == 0) break; 
    }
    return "";
}
   
// store cookie value with optional details as needed
function setCookie(name, value, expires, path, domain, secure) {
    document.cookie = name + "=" + escape (value) +
        ((expires) ? "; expires=" + expires : "") +
        ((path) ? "; path=" + path : "") +
        ((domain) ? "; domain=" + domain : "") +
        ((secure) ? "; secure" : "");
}
   
// remove the cookie by setting ancient expiration date
function deleteCookie(name,path,domain) {
    if (getCookie(name)) {
        document.cookie = name + "=" +
            ((path) ? "; path=" + path : "") +
            ((domain) ? "; domain=" + domain : "") +
            "; expires=Thu, 01-Jan-70 00:00:01 GMT";
    }
}

function wi(){
    if(document.body.clientWidth){
	   wdt = document.body.clientWidth;
	   clh = document.body.clientHeight;
    }
    if(window.innerWidth){
	   wdt = window.innerWidth;
	   clh = window.innerHeight;
    }
    return wdt;
}

function wr(){
	//alert("dfgdf");
	var w = wi();
	var cont = getEl("container");
	if(w < 780){
		cont.style.width = 780;
	} else {
		cont.style.width = "100%";
	} 
}

function showButton(){
	//alert("good");
	var cb = getEl('catbutton');
	// alert(cb.src.indexOf('c_o'));
	if(cb.src.indexOf('c_o') > 0){
		cb.src = 'img/c_c.gif';
	} else {
		cb.src = 'img/c_o.gif';
	}
}

function reshe(){
	// alert('sdfdf');
	var wh = he();
	var c = getEl("container");
	var o = getEl("coco1");
	var n = getEl("nav");
	//var f = getEl("footer");
	if(!o) return;
	var delta = wh-(c.offsetHeight)+n.offsetHeight;
	if(delta > 0){
		//alert(delta);
		o.style.height = delta+40+o.offsetHeight+'px';
	}
}

var is;
var _url;
var _header;

function sepop(url, w, h){
	_url = 'i/s/b/'+url+'.jpg';
	_header = 'Лицензии и сертификаты';
	if((w == '')||(h == '')){
		return false;
	}
	// is.focus( );
	// make sure it isn't already opened
    if (!is || is.closed) {
	    var left = parseInt((screen.availWidth/2) - (w/2));
	    var top = parseInt((screen.availHeight/2) - (h/2));
	    var windowFeatures = "width=" + w + ",height=" + h + 
	        ",left=" + left + ",top=" + top + 
	        ",screenX=" + left + ",screenY=" + top;
		is = window.open("", "imShow", windowFeatures);
        // newWindow = window.open("","sub","status,height=200,width=300");
        // delay writing until window exists in IE/Windows
        setTimeout("writeToWindow()", 50);
    } else if (is.focus) {
        // window is already open and focusable, so bring it to the front
        is.focus( );
    }
}

function writeToWindow() {
    // assemble content for new window
    var newContent = "";
    //alert (_header);
    newContent += "<html><head><title>"+_header+"</title>";
    newContent += "<style>body {border:0 solid; padding:0; margin:0; }</style></head>";
    newContent += "<body>";
    newContent += "<img src='"+_url+"' alt='"+_header+"' width='100%' hspace='0' vspace='0'/>";
    newContent += "</body></html>";
    // write HTML to new window document
    //is.document.body.style.border = "0";
   // is.document.body.style.padding = "0";
    //is.document.body.style.margin = "0";
    is.document.write(newContent);
    is.document.close( ); // close layout stream
}

function bswitch(){
	var br = $('brand');
	var cat = $('cat');
	var sw = $('bsw');
	//alert(sw.value);
	if(sw.value == 'бренды') {
		sw.value = 'категории';
		br.style.display = 'block';
		cat.style.display = 'none';
		setCookie('bsw', 2, 0, "/");
	} else {
		sw.value = 'бренды';
		cat.style.display = 'block';
		br.style.display = 'none';
		setCookie('bsw', 1, 0, "/");
	}
}

window.onresize = wr;

