var iPath="/images/";
var http_request;
var XMLobject=new String;
var lst_idss;
var lst_idss1;
var sel_ids;

var func_res=function(){
		if(document.getElementById("edt_frm")!=null&&document.getElementById("edt_frm").style.display=="block"){
			with(document.getElementById("edt_frm").style){
				var pos=getElementPosition(lst_idss);
				var pos1=getElementPosition("edt_frm");
				var pos2=getElementPosition("cnts");
				var sz=getClientsz();
				top=(pos.top-pos1.height)>0?(pos.top-pos1.height):'10';
				width=pos2.width;
				left=pos2.left-50;
				if(document.getElementById("banss_lst")!=null&&document.getElementById("banss_lst").style.display=="block"){
					var pos=getElementPosition("add_b");
					with(document.getElementById("banss_lst").style){
						top=pos.top+pos.height;
						left=pos.left-pos.width;
					}
				}
			}
		}
		if(document.getElementById("stats")!=null&&document.getElementById("stats").style.display=="block"){
			with(document.getElementById("stats").style){
				var pos=getElementPosition(lst_idss1);
				var pos1=getElementPosition("stats");
				var pos2=getElementPosition("cnts");
				var sz=getClientsz();
				top=(pos.top-pos1.height)>0?(pos.top-pos1.height):'10';
				width=pos2.width;
				left=pos2.left-50;
			}
		}
		if(document.getElementById("wht_img").style.display=="block"){
			var sz=getClientsz();
			with(document.getElementById("wht_img")){
				style.width=sz.width;
				style.height=sz.height;
			}
		}

		if(document.getElementById("conners")!=null){
			document.getElementById("conners").style.left=(document.compatMode=='CSS1Compat' && !window.opera?document.documentElement.clientWidth:document.body.clientWidth)-350;
		}
		closeCalendar();
	};

function shw_tm(obj,obj_p){
	try{
		with(document.getElementById(obj)){
			var elm_p=getElementPosition(obj_p);
			style.display="block";
			style.top=elm_p.top;
			style.left=elm_p.left;
			style.width=elm_p.width;
		}
	}catch(er){}
}
function hide_tm(obj){
	try{
		with(document.getElementById(obj)){
			style.display="none";
			style.top="0";
			style.left="0";
		}
	}catch(er){}
}
function show_edt(idss){
	with(document.getElementById("edt_frm").style){
		display="block";
		var pos=getElementPosition(lst_idss);
		var pos1=getElementPosition("edt_frm");
		var pos2=getElementPosition("cnts");
		var sz=getClientsz();
		top=(pos.top-pos1.height)>0?(pos.top-pos1.height):'10';
		width=pos2.width+60;
		left=pos2.left-100;
		closeCalendar();
	}
	window.onresize=func_res;
}

function hide_edt(){
	document.getElementById("edt_frm").style.display="none";
	lst_idss="";
	window.onresize=function(){
		if(document.getElementById("conners")!=null){
			document.getElementById("conners").style.left=(document.compatMode=='CSS1Compat' && !window.opera?document.documentElement.clientWidth:document.body.clientWidth)-350;
		}
	}
	if(document.getElementById("banss_lst")!=null){
		document.getElementById("banss_lst").style.display="none";
	}
	if(document.getElementById("block_cont")!=null){
		document.getElementById("block_cont").style.display="none";
	}
	closeCalendar();
	return false;
	
}
function getElementPosition(elemId){
    var elem = document.getElementById(elemId);	
    var w = elem.offsetWidth;
    var h = elem.offsetHeight;	
    var l = 0;
    var t = 0;	
    while (elem){
        l += elem.offsetLeft;
        t += elem.offsetTop;
        elem = elem.offsetParent;
    }
    return {"left":l, "top":t, "width": w, "height":h};
}

function st_path(str){
	iPath=str;
}
function ob_over(ob1,img_n,img,cls){
	try{
		if(document.images && loaded){ 
			document.images[img_n].src = self[img].src;
		}
		ob1.className=cls;
	}catch(er){}
}

function ob_over1(ob1,ob2,ob3,img_n,img,cls,cls1,cls2){
	try{
		if(document.images && loaded){ 
			document.images[img_n].src = self[img].src;
		}
		ob1.className=cls;
		ob2.className=cls1;
		ob3.className=cls2;
	}catch(er){}
}

function preLoad(){
	if(document.images){
		var argLen = arguments.length;
			for(var i = 0; i < argLen; i++){
				var arg = arguments[i];
				self[arg ] = new Image();
				self[arg ].src = iPath + arg + '.jpg';
			}
		loaded = true;
	}
}

function do_src(){
	if(document.getElementById("kwd").value==""){
		alert("Критерии поиска");
	}else{
		document.location.href="/search/"+document.getElementById("kwd").value+"/";
	}
}

function makePOSTRequest(url, param,answer,mem) {
    if (window.XMLHttpRequest) {
        http_request = new XMLHttpRequest();
        if (http_request.overrideMimeType) {
            http_request.overrideMimeType(mem);
        }
    } else if (window.ActiveXObject) { 
		try {
            http_request = new ActiveXObject("Msxml2.XMLHTTP");
        } catch (e) {
            try {
                http_request = new ActiveXObject("Microsoft.XMLHTTP");
            } catch (e) {}
        }
    }
    if (!http_request) {
        alert('Ваша версия Интернет браузера не поддерживает используемые технологии обмена данными!');
        return false;
    }
    http_request.onreadystatechange = answer; 
    http_request.open('POST', url, true);
    http_request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
   	http_request.send(param);
}

function makeGETRequest(url,answer,mem) {
    if (window.XMLHttpRequest) { 
        http_request = new XMLHttpRequest();
        if (http_request.overrideMimeType) {
            http_request.overrideMimeType(mem);
        }
    } else if (window.ActiveXObject) { 
        try {
            http_request = new ActiveXObject("Msxml2.XMLHTTP");
        } catch (e) {
            try {
                http_request = new ActiveXObject("Microsoft.XMLHTTP");
            } catch (e) {}
        }
    }
    if (!http_request) {
        alert('Ваша версия Интернет браузера не поддерживает используемые технологии обмена данными!');
        return false;
    }
    http_request.onreadystatechange=answer; //Тут написать функцию которая вызовется после получения странички
    http_request.open('GET', url, true);
    http_request.send(null);
}
function shw_w_img(){
	try{
		var sz=getClientsz();
		with(document.getElementById("wht_img")){
			style.width=sz.width;
			style.height=sz.height;
			style.display="block";
		}
		closeCalendar();
	}catch(err){}	
}

function getClientsz(){
	var w=document.compatMode=='CSS1Compat' && !window.opera?document.documentElement.clientWidth:document.body.clientWidth;
	var h=(document.body.scrollHeight > document.body.offsetHeight)?document.body.scrollHeight:document.body.offsetHeight;
	return {"width": w, "height":h};
}

function do_reg(){
	with(document.lgns){
		if(login.value!=""&&password.value!=""){
			submit();
		}
	}
}

function del_tag(strr){
	var tmpstr="";
	tmpstr=strr;
	var pattern=/(<.*?>)|(<\/.*?>)|([';!\"\{\}]*)/ig;
	tmpstr=tmpstr.replace(pattern,'');
	return tmpstr;
}

function del(page,idss){
	if(window.confirm('Вы действительно хотите удалить эту запись')){
		shw_w_img();
		document.getElementById("edt_frm").style.display="none";
		makePOSTRequest("/edit_xml.php?act=del&page="+page, "id="+idss,alertContents1);
	}
}

function lstOver(object){
	object.className = 'tbl_over';
 }

 function lstOut(object){
	object.className = 'tbl_out';
 }
 
function show_stat(wht,idss,w_id){
	closeCalendar();
	document.getElementById("col_show").innerHTML="";
	document.getElementById("col_go").innerHTML="";
	sel_ids=w_id;
	with(document.getElementById("stats").style){
		display="block";
		var pos=getElementPosition(idss);
		var pos1=getElementPosition("stats");
		var pos2=getElementPosition("cnts");
		lst_idss1=idss;
		var sz=getClientsz();
		top=(pos.top-pos1.height)>0?(pos.top-pos1.height):'10';
		width=pos2.width;
		left=pos2.left-50;
	}
	window.onresize=func_res;
}

function col_chk1(chkstr){
	var tmpstr=new String;
	var res=new String;
	var pattern="[^0-9]";
	var regexpobj=new RegExp(pattern,"ig");
	tmpstr=chkstr;
	res=regexpobj.exec(tmpstr);
	if(res!=null){
		return true;
	}else{
		return false;
	}
}

function col_chk2(chkstr){
	var tmpstr=new String;
	var res=new String;
	var pattern="[0-9\.]";
	var regexpobj=new RegExp(pattern,"ig");
	tmpstr=chkstr;
	res=regexpobj.exec(tmpstr);
	if(res==null){
		return true;
	}else{
		return false;
	}
}


function checkdata(){	
	if(event.keyCode>27){
		if (col_chk1(String.fromCharCode(event.keyCode))==true){
			event.returnValue=false;
		}
	}
}
function checkdata1(){	
	if(event.keyCode>27){
		if (col_chk2(String.fromCharCode(event.keyCode))==true){
			event.returnValue=false;
		}
	}
}

function chklog_frm(me,keyKodes){
	if(keyKodes==13){
		if(me=="login"){
			document.lgns.password.focus();
		}
		if(me=="password"){
			do_reg();
		}
	}
}

