var req;
var inr;
var myvar=getCookie("cok_menu");
var cur_nod=new Array(0,0,0,0,0,0,0,0,0,0,0,0,0,0);
if (myvar!=null){
if (myvar.lastIndexOf(',')>20) cur_nod=myvar.split(',');
}
var working=false;
function get_http() {
        var res;
        if (window.XMLHttpRequest) res=new XMLHttpRequest();
        else res=new ActiveXObject("Microsoft.XMLHTTP");
        return res;
}



function get_content(name, url, param) {
nod=getNode(name);
        if(!req) {
                req=get_http();
        }
        if (req) {
                if (param) {
                        url+="?l="+encodeURIComponent(param);
			url+="?l="+param;
                }
				
	 	req.open("GET", url, true);
				// req.setRequestHeader('Content-Type','application/x-www-form-urlencoded;charset=utf-8');
                req.onreadystatechange = function() {
                        if (req.readyState == 4) {
                               nod.innerHTML=req.responseText;
		               if(onload) onload();
                        } else {
                                nod.innerHTML="<center>Loading...</center>";
                        }
                }
                req.send(null);
        } else {
                alert('Error created XMLHTTP object!');
        }
}

function fill (name, data) {

nod=getNode(name);
        nod.innerHTML=data;
}

// Открытие окна
function open_window(name, title, x, y, width, height) {
        document.getElementById(name+'_title').innerHTML=title
        d = document.getElementById(name+'_content');
        d.style.height=height;
        d.style.width=width;

        d = document.getElementById(name);
        d.style.display = "block";
        d.style.left = x;
        d.style.top = y;
//        d.style.width = width;
//        d.style.height = height;
}

// Спрятать окно
function hide_window(name) {
        document.getElementById(name).style.display = "none";
}

function get_countries_list(title, param) {
        x=document.body.scrollWidth-215;
        y=130;
        get_content('window_content', '/modules/countries_list.php', param);
        open_window('window', title, x, y, 200, 85);
}

function win_open(url) {
        var win_open = window.open(url, "_blank", "copyhistory=0, directories=0, height=600, location=0, menubar=0, scrollbars=yes, status=0, toolbar=0, width=850, resizable=1");
        win_open.focus();
}

function get_page(title, url, width, height) {
        if (!width) {width=500}
        if (!height) {height=500}
        x=document.body.clientWidth;
		if (x<1000){
		 x=170+ document.body.scrollLeft;
		}else{
		x=(document.body.clientWidth-1000)/2+170+document.body.scrollLeft;
		}
        if (x<0) {x=0;}
        y=(document.body.clientHeight-height)/2 + document.body.scrollTop;
        if (y<115) {y=115;}
        get_content('window_content', url);
        open_window('window', title, x, y, width, height);
}

function gets_page(title, url, width, height, pos) {

        if (!width) {width=500}
        if (!height) {height=500}
        open_window('window', title, pos.x, pos.y, width, height);
		  get_content('window_content', url);
}

function emlrepair(arr) {
        var a="";
        for(var i=0;i<arr.length;i++) {a+=String.fromCharCode(arr[i]);}
        return a;
}

function emlexplode(str) {
        var a=new Array();
        var tmp="";
        for(var i=0;i<str.length;i++) {
                if (str.substr(i,1)==","||str.substr(i,1)==".") {
                        a[a.length]=parseInt(tmp)-1;tmp="";
                } else tmp+=str.substr(i,1)
        }
        if (tmp) a[a.length]=parseInt(tmp)-1;
        return a;
}

function emlwrite(str,msg,css) {
        var x=emlrepair(emlexplode(str));
        document.write('<a href=javascript:void(0) onclick="window.location=\'mail\u0074o\u003a'+x+'\'">'+(msg?msg:'<img src=/images/knopemail.gif border=0 vspace=4>')+'</a>');
}

function emlstart(str) {
        var x=emlrepair(emlexplode(str));
        window.location='mail\u0074o\u003a'+x+'?subject=l2b.info';
}
function preg_h(par){
par=par.replace('HR','<a href="'+glP);
par=par.replace('PR',glR);
return par;
}

function add_subm(submen){
if (typeof(submen)=="undefined") return;
for(t=0; t<submen.length; t++){
inr+='<tr><td class="vb8" align="right">&curren;</td><td>'+preg_h(submen[t])+'</td></tr>';
}
}

function sel_m(nod){
cur_nod[nod]^=1;
node=getNode('menu_box');
inr='<table border="0" cellpadding="0" cellspacing="2" width="160" class="ver8">';
inr+='<tr><td width="10"></td><td width="150"></td></tr>';
for(i=0; i<cont_menu.length; i++){
cur_nod[i]-=0;
cm=(cont_menu[i].length==2)? '<tr><td valign="bottom"><img src="'+glP+'img/pl.gif" onclick="sel_m('+i+')" width="10" height="10" align="доп. меню" style="cursor:hand;"></td><td>':'<tr><td colspan="2">';
cm= (cur_nod[i]!=0)? cm.replace('pl.gif','mn.gif'):cm;
inr+=cm+preg_h(cont_menu[i][0])+'</td></tr>';

if (cur_nod[i]!=0) add_subm(subm[i]);
}
inr+='</table>';
node.innerHTML=inr;
expr=new Date();
y=expr.getYear();
expr.setYear(y+1);
document.cookie="cok_menu="+cur_nod.toString()+"; path="+glP+"; expires="+expr;
//alert("cok_menu="+cur_nod.toString()+"; path="+glP+"; expires="+expr);

}

function getNode( nodeId ) {
if( document.getElementById )
	return document.getElementById( nodeId );
else if( document.all && document.all( nodeId ) )
	return document.all( nodeId );
else if( document.layers && document.layers[ nodeId ] )
	return document.layers[ nodeId ];
else
	return false;
}

function onl(par){
if (par>0) sel_m(nod);
}

function getCookie(name) {
	var cookie = " " + document.cookie;
	var search = " " + name + "=";
	var setStr = null;
	var offset = 0;
	var end = 0;
	if (cookie.length > 0) {
		offset = cookie.indexOf(search);
		if (offset != -1) {
			offset += search.length;
			end = cookie.indexOf(";", offset)
			if (end == -1) {
				end = cookie.length;
			}
			setStr = unescape(cookie.substring(offset, end));
		}
	}
	return(setStr);
}
function getAbsolutePos(el)
{
   var r = { x: el.offsetLeft, y: el.offsetTop };
   if (el.offsetParent)
   {
       var tmp = getAbsolutePos(el.offsetParent);
       r.x += tmp.x;
       r.y += tmp.y;
   }
   return r;
}


