function ref(){
	loadXMLDoc("sec_img.php","");
}
function loadXMLDoc(url,txt){
	xmlhttp=null;
	if (window.XMLHttpRequest){
		xmlhttp=new XMLHttpRequest();
  	}else{
  		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  	}
	if(xmlhttp.addEventListener && navigator.userAgent.indexOf("Opera")==-1){
		xmlhttp.addEventListener("load",stateChange,false);
	}else{
		xmlhttp.onreadystatechange=stateChange;
	}
	xmlhttp.open("POST",url,true);
	xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	xmlhttp.setRequestHeader("Content-length", txt.length);
	xmlhttp.setRequestHeader("Connection", "close");
	xmlhttp.send(txt);
}
function pif(){
	if(window.parent)window.parent.location='index.php?opt=pif.php';
	else window.location='index.php?opt=pif.php';
}
function rg(){
	if(window.parent)window.parent.location='index.php?opt=rg.php';
	else window.location='index.php?opt=rg.php';
}
var effn='';
function effi(n,obj){
	effn=n;
	document.getElementById("ef_d").innerHTML=obj.innerHTML;
}
function eff(){
	if(key=='yes'){	
		var er='';
		//var estsel=effn;
		//var eidno=document.fr.eidno.value;
		//if(estsel==0)er+='<li>შეამოწმე სტატუსი!</li>'
		if(er==''){
			if(window.parent)window.parent.location='index.php?opt=ef.php';
			else window.location='index.php?opt=ef.php';
		}else{
			document.getElementById('eref').style.display='block';
			document.getElementById('ulef').innerHTML=er;
		}
	}else{
		document.getElementById('eref').style.display='block';
		document.getElementById('ulef').innerHTML='<li>გაიარეთ ავტორიზაცია / რეგისტრაცია!</li>';
	}
}
var sffn='';
function sffi(n,obj){
	sffn=n;
	document.getElementById("sf_d").innerHTML=obj.innerHTML;
}
function sff(){
	if(key=='yes'){
		if(adi=='adi'){
			if(window.parent)window.parent.location='index.php?opt=sf.php';
			else window.location='index.php?opt=sf.php';
		}
		var er='';
		var sstsel=sffn;
		var sidno=document.fr.sidno.value;
		if(sstsel==0)er+='<li>შეამოწმე სტატუსი!</li>'
		if(er==''){
			if(window.parent)window.parent.location='index.php?opt=sf.php&sst='+sstsel+'&idno='+sidno;
			else window.location='index.php?opt=sf.php&sst='+sstsel+'&idno='+sidno;
		}else{
			document.getElementById('ersf').style.display='block';
			document.getElementById('ulsf').innerHTML=er;
		}
	}else{
		document.getElementById('ersf').style.display='block';
		document.getElementById('ulsf').innerHTML='<li>გაიარეთ ავტორიზაცია / რეგისტრაცია!</li>';
	}
}
function fg(){
	if(window.parent)window.parent.location='index.php?opt=fg.php';
	else window.location='index.php?opt=rg.php';
}
function cls(id){
	document.getElementById(id).style.display="none";
}
function outi(){
	if(window.parent)window.parent.location='out.php';
	else window.location='out.php';
}
function sn(){
	var er='';
	var no=document.fr.no.value;
	var pw=document.fr.pw.value;
	var rm=document.fr.rm.value;//(document.fr.rm.checked)?document.fr.rm.value:'';
	if((no.length<9 || no.length>11) || no=='პირადი ნომერი')er+='<li>შეამოწმე პირადი ნომერი!</li>';
	if(pw.length<6 || pw.length>12 || pw=="******")er+='<li>შეამოწმე პაროლის!</li>';
	if(er==''){
		document.getElementById("ulsn").innerHTML='<li>მოითმინე...</li>';
		loadXMLDoc('sin.php','no='+no+'&pw='+pw+'&rm='+rm);
	}else{
		document.getElementById("ulsn").innerHTML=er;
	}
	document.getElementById("ersn").style.display="block";
}
function snr(){
	if(document.fr.rm.value=='yes'){
		document.fr.rm.value='';
		document.getElementById("rgi").src='images/mounishnavi.jpg';
	}else{
		document.fr.rm.value='yes';
		document.getElementById("rgi").src='images/monishnuli.jpg';
	}
}
function newsa(){
	if(window.parent)window.parent.location='index.php?opt=newsr.php';
	else window.location='index.php?opt=newsr.php';
}
function news(id){
	if(window.parent)window.parent.location='index.php?opt=news.php&id='+id;
	else window.location='index.php?opt=news.php&id='+id;
}
var inti=null;
var n_l=0;
var n_w=0;
var w=160;
function n_rg(){
	n_w=document.getElementById("n_tbm").offsetWidth;
	n_l+=w;
	if(n_l > 0){
		n_l=0;
	}
	document.getElementById("n_tbm").style.left=n_l+"px";
}
function n_lf(){
	n_w=document.getElementById("n_tbm").offsetWidth;
	n_l-=w;
	if((n_w+n_l-w) < 0){
		n_l=w-n_w;
	}
	document.getElementById("n_tbm").style.left=n_l+"px";
}
function n_of(){
	clearInterval(inti);
	inti=null;
}
function n_ofg(){
	clearInterval(inti);
	inti=null;
}
function n_fscreen(id){
	if(window.parent)window.parent.location='index.php?opt=n_gal.php&id='+id;
	else window.location='index.php?opt=n_gal.php&id='+id;
}
function n_ib(id,src){
	if(window.parent)window.parent.location='index.php?opt=n_ib.php&id='+id+'&src='+src;
	else window.location='index.php?opt=n_ib.php&id='+id+'&src='+src;
}
function newse(){
	if(window.parent)window.parent.location='index.php?opt=newse.php';
	else window.location='index.php?opt=newse.php';
}
function del(src){
	loadXMLDoc('del.php','src='+src);
}
function voti(){
	if(document.getElementById("sq2_2").style.display!='block'){
		document.getElementById("sq2_1").style.display='none';
		document.getElementById("sq2_2").style.display='block';
	}else{
		document.getElementById("sq2_1").style.display='block';
		document.getElementById("sq2_2").style.display='none';
	}	
}
function vote(){
	if(window.parent)window.parent.location='index.php?opt=vote.php';
	else window.location='index.php?opt=vote.php';
}
function v_add(){
	if(document.getElementById("v_daa").style.display!='block'){
		document.getElementById("v_daa").style.display='block';
	}else{
		document.getElementById("v_daa").style.display='none';
	}	
}
function v_edit(id){
	if(window.parent)window.parent.location='index.php?opt=votee.php&id='+id;
	else window.location='index.php?opt=votee.php&id='+id;
}
function v_vt(id,n){
	loadXMLDoc("votc.php","id="+id+"&n="+n);
}
function c_mang(){
	if(window.parent)window.parent.location='index.php?opt=conte.php';
	else window.location='index.php?opt=conte.php';
}
function c_add(){
	if(document.getElementById("c_daa").style.display!='block'){
		document.getElementById("c_daa").style.display='block';
	}else{
		document.getElementById("c_daa").style.display='none';
	}	
}
function srch(){
	var er='';
	var word=document.fr.word.value;
	var selY=0;
	var selm=0;
	var seldd=0;
	document.fr.word.style.borderColor='#006699';
	document.getElementById("selY").style.borderColor='#006699';
	document.getElementById("selm").style.borderColor='#006699';
	//if(document.fr.selY.selectedIndex>0)selY=document.fr.selY.options[document.fr.selY.selectedIndex].value;
	selY=document.getElementById("Y_d").innerHTML;
	//if(document.fr.selm.selectedIndex>0)var selm=document.fr.selm.options[document.fr.selm.selectedIndex].value;
	selm=(sdmn>0)?sdmn:0;//document.getElementById("m_d").innerHTML;
	//if(document.fr.seld.selectedIndex>0)var seld=document.fr.seld.options[document.fr.seld.selectedIndex].value;
	seldd=(sddn>0)?sddn:0;
	if(word!='' || (selY>0 && selm>0)){
		if(window.parent)window.parent.location='index.php?opt=srch.php&word='+word+'&Y='+selY+'&m='+selm+'&d='+seldd;
		else window.location='index.php?opt=srch.php&word='+word+'&Y='+selY+'&m='+selm+'&d='+seldd;
	}else{
		document.fr.word.style.borderColor='#ff0000';
		document.getElementById("selY").style.borderColor='#ff0000';
		document.getElementById("selm").style.borderColor='#ff0000';
	}	
}
function arch(n){
	var er='';
	var word=document.fr.word.value;
	var r=document.getElementById("Y_d").innerHTML;
	var selY=(r>0)?r:0;//document.fr.selY.options[document.fr.selY.selectedIndex].value;
	r=document.getElementById("m_d").innerHTML;
	var selm=(r>0)?r:0;//document.fr.selm.options[document.fr.selm.selectedIndex].value;
	r=document.getElementById("d_d").innerHTML;
	var seld=(r>0)?r:0;//document.fr.seld.options[document.fr.seld.selectedIndex].value;
	a_lim(word,selY,selm,seld,n)
}
function lb_mang(){
	if(window.parent)window.parent.location='index.php?opt=lba.php';
	else window.location='index.php?opt=lba.php';
}
function lb_load(){
	if(window.parent)window.parent.location='index.php?opt=lb.php&id='+lb_chv;
	else window.location='index.php?opt=lb.php&id='+lb_chv;
}
var lb_chv='';
function lb_ch(n,obj){
	lb_chv=n;
	//document.getElementById("lb_d").innerHTML=obj.innerHTML;
	lb_load();
}
function lb_arch(){
	if(window.parent)window.parent.location='index.php?opt=lbarch.php';
	else window.location='index.php?opt=lbarch.php';
}
function lb_lim(n){
	if(window.parent)window.parent.location='index.php?opt=lbarch.php&lim='+n;
	else window.location='index.php?opt=lbarch.php&lim='+n;
}
function lbe(id){
	if(window.parent)window.parent.location='index.php?opt=lbe.php&id='+id;
	else window.location='index.php?opt=lbe.php&id='+id;
}
function a_lim(w,Y,m,d,n){
	if(window.parent)window.parent.location='index.php?opt=arch.php&word='+w+'&Y='+Y+'&m='+m+'&d='+d+'&lim='+n;
	else window.location='index.php?opt=arch.php&word='+w+'&Y='+Y+'&m='+m+'&d='+d+'&lim='+n;
}
function send(){
	var er='';
	document.fr.cmail.style.borderColor='#006699';
	document.fr.cmsg.style.borderColor='#006699';
	var cmail=document.fr.cmail.value;
	var cmsg=document.fr.cmsg.value;
	if((cmail.length<8 || cmail.length>70) && cmail!='' && cmail=='თქვენი ელ-ფოსტა'){
		document.fr.cmail.style.borderColor='#ff0000';
		er+=1;
	}
	if(cmsg.length<2 || cmsg=='ტექსტი'){
		document.fr.cmsg.style.borderColor='#ff0000';
		er+=1;
	}
	if(er==''){
		cmail=(cmail!='თქვენი ელ-ფოსტა')?cmail:'';
		loadXMLDoc('contact.php','mail='+cmail+'&msg='+cmsg);
	}
}
function gt(lnk){
	location=lnk;
}
function ab(){
	if(window.parent)window.parent.location='index.php?opt=about.php';
	else window.location='index.php?opt=about.php';
}
function ss(){
	if(window.parent)window.parent.location='index.php?opt=struct.php';
	else window.location='index.php?opt=struct.php';
}
function tsf(){
	if(window.parent)window.parent.location='index.php?opt=task.php';
	else window.location='index.php?opt=task.php';
}
function con(){
	if(window.parent)window.parent.location='index.php?opt=conti.php';
	else window.location='index.php?opt=conti.php';
}
function sd_sf(){
	if(document.getElementById("seld1").style.display!='block'){
		document.getElementById("seld1").style.display='block';
		document.getElementById("tdsq3").style.zIndex=10000;
		if(document.getElementById("tdsq4").style.zIndex>100)sd_se();
		if(document.getElementById("tdgz").style.zIndex>100)sd_sl();
	}else{
		document.getElementById("seld1").style.display='none';
		document.getElementById("tdsq3").style.zIndex=100;
	}	
}
function overi(obj){
	obj.style.backgroundColor='#eeeeee';
}
function outii(obj){
	obj.style.backgroundColor='#ffffff';
}
function sd_se(){
	if(document.getElementById("sele1").style.display!='block'){
		document.getElementById("sele1").style.display='block';
		document.getElementById("tdsq4").style.zIndex=10000;
		if(document.getElementById("tdsq3").style.zIndex>100)sd_sf();
		if(document.getElementById("tdgz").style.zIndex>100)sd_sl();
	}else{
		document.getElementById("sele1").style.display='none';
		document.getElementById("tdsq4").style.zIndex=100;
	}	
}
function sd_sl(){
	if(document.getElementById("sell1").style.display!='block'){
		document.getElementById("sell1").style.display='block';
		document.getElementById("tdgz").style.zIndex=10000;
		if(document.getElementById("tdsq3").style.zIndex>100)sd_sf();
		if(document.getElementById("tdsq4").style.zIndex>100)sd_se();
	}else{
		document.getElementById("sell1").style.display='none';
		document.getElementById("tdgz").style.zIndex=100;
	}	
}
function sd_Y(){
	if(document.getElementById("selY1").style.display!='block'){
		document.getElementById("selY1").style.display='block';
		document.getElementById("selY").style.zIndex=10000;
		document.getElementById("tdsq7").style.zIndex=10000;
		document.getElementById("selm1").style.display='none';
		document.getElementById("seldd1").style.display='none';
		document.getElementById("selm").style.zIndex=1000;
		document.getElementById("seldd").style.zIndex=1000;
	}else{
		document.getElementById("selY1").style.display='none';
		document.getElementById("tdsq7").style.zIndex=100;
		document.getElementById("selY").style.zIndex=1000;
	}	
}
var sdYn='';
function sd_Yi(n,obj){
	sdYn=n;
	document.getElementById("Y_d").innerHTML=obj.innerHTML;
}
function sd_m(){
	if(document.getElementById("selm1").style.display!='block'){
		document.getElementById("selm1").style.display='block';
		document.getElementById("selm").style.zIndex=10000;
		document.getElementById("tdsq7").style.zIndex=10000;
		document.getElementById("selY1").style.display='none';
		document.getElementById("seldd1").style.display='none';
		document.getElementById("selY").style.zIndex=1000;
		document.getElementById("seldd").style.zIndex=1000;
	}else{
		document.getElementById("selm1").style.display='none';
		document.getElementById("tdsq7").style.zIndex=100;
		document.getElementById("selm").style.zIndex=1000;
	}	
}
var sdmn='';
function sd_mi(n,obj){
	sdmn=n;
	document.getElementById("m_d").innerHTML=obj.innerHTML;
}
function sd_d(){
	if(document.getElementById("seldd1").style.display!='block'){
		document.getElementById("seldd1").style.display='block';
		document.getElementById("seldd").style.zIndex=10000;
		document.getElementById("tdsq7").style.zIndex=10000;
		document.getElementById("selY1").style.display='none';
		document.getElementById("selm1").style.display='none';
		document.getElementById("selY").style.zIndex=1000;
		document.getElementById("selm").style.zIndex=1000;
	}else{
		document.getElementById("seldd1").style.display='none';
		document.getElementById("tdsq7").style.zIndex=100;
		document.getElementById("seldd").style.zIndex=1000;
	}	
}
var sddn='';
function sd_di(n,obj){
	sddn=n;
	document.getElementById("d_d").innerHTML=obj.innerHTML;
}
function ban(){
	if(window.parent)window.parent.location='index.php?opt=ban.php';
	else window.location='index.php?opt=ban.php';
}
function s_up(){
	document.getElementById("st_cnt").style.top=-100+"px";
}
function s_down(){
	document.getElementById("st_cnt").style.top=0+"px";
}
function bovr(id){
	document.getElementById(id).style.display='block';
}
function bout(id){
	document.getElementById(id).style.display='none';
}

/////////////////////////////////////////////////////////////
var selectedObj=null;
var shatlID=0;
var resID=0;
var selShat=null;
var selShatStr=null;
var selRes=null
var selResStr=null;
function setSelectedElem(evt){
	var target=(evt.target)?evt.target:evt.srcElement;
	var imgID = (target.id) ? target.id:"";
	if(imgID){
		if(imgID.substr(0,2)=='mv'){
			shatlID=imgID.substr(2);
			selectedObj = document.getElementById("dm"+shatlID);
			
			var r=selectedObj.innerHTML;
			var rrie=r.lastIndexOf("<IMG");
			var rrot=r.lastIndexOf("<img");
			rr=(rrie > -1)?rrie:((rrot > -1)?rrot:-1);
			selShatStr=r.substr(0,rr);
			selShat.innerHTML=selShatStr;
		}
		return true;
	}
	selectedObj = null;
	return;
}
function ovi(evt){
	evt=(evt)?evt:event;
	var target=(evt.target)?evt.target:evt.srcElement;
	var imgID = (target.id) ? target.id:"";
	if(imgID.substr(0,2)=='mv'){
		resID=imgID.substr(2);
		selRes=document.getElementById("dm"+resID);
		
		var r=selRes.innerHTML;
		var rrie=r.lastIndexOf("<IMG");
		var rrot=r.lastIndexOf("<img");
		rr=(rrie > -1)?rrie:((rrot > -1)?rrot:-1);
		selResStr=r.substr(0,rr);
		
		target.src='images/mov.png';
	}
	
}
function oti(evt){
	evt=(evt)?evt:event;
	var target=(evt.target)?evt.target:evt.srcElement;
	var imgID = (target.id) ? target.id:"";
	if(imgID.substr(0,2)=='mv'){
		target.src='images/mov30.png';
		selRes=null;
	}
}
function engage(evt){
	evt=(evt)?evt:event;
	setSelectedElem(evt);
	if(selectedObj) {
		offsetX=evt.clientX+zxcWWHS()[0]+10;
		offsetY=evt.clientY+zxcWWHS()[1]+10;
		selShat.style.display="block";
		selShat.style.left=(evt.clientX+zxcWWHS()[0]+10)+"px";
		selShat.style.top=(evt.clientY+zxcWWHS()[1]+10)+"px";
		return false;
	}	
}
function dragIt(evt){
	evt=(evt)?evt:event;
	if (selectedObj) {
		selShat.style.left=(evt.clientX+zxcWWHS()[0]+10)+"px";
		selShat.style.top=(evt.clientY+zxcWWHS()[1]+10)+"px";
		return false;
	}
}
function release(evt){
	if (selectedObj) {
		if(selRes){
			
			selRes.innerHTML=selShatStr+'<img src="images/mov30.png" alt="" class="imo" id="mv'+resID+'">';
			selectedObj.innerHTML=selResStr+'<img src="images/mov30.png" alt="" class="imo" id="mv'+shatlID+'">';
		}
		oti(evt);
		selShat.style.display="none";
		shatlID=0;
		resID=0;
		selShatStr=null;
		selRes=null
		selResStr=null;
	}
}
/*
function Test(){
 alert('scoll top: '+zxcWWHS()[3]+'\nWindow Height: '+zxcWWHS()[1])/
}
function zxcWWHS(){
	if (window.innerHeight) return [window.innerWidth-10,window.innerHeight-10,window.pageXOffset,window.pageYOffset];
 	else if (document.documentElement.clientHeight) 
		return	[document.documentElement.clientWidth-10,document.documentElement.clientHeight-10,document.documentElement.scrollLeft,document.documentElement.scrollTop];
 return [document.body.clientWidth,document.body.clientHeight,document.body.scrollLeft,document.body.scrollTop];
}
*/
function zxcWWHS(){
	if (window.innerHeight) return [window.pageXOffset,window.pageYOffset];
 	else if (document.documentElement.clientHeight) return	[document.documentElement.scrollLeft,document.documentElement.scrollTop];
 	return [document.body.scrollLeft,document.body.scrollTop];
}
function initDrag(){
	selShat=document.getElementById("shatl");
	document.onmouseover=ovi;
	document.onmouseout=oti;
	document.onmousedown=engage;
	document.onmousemove=dragIt;
	document.onmouseup=release;
	
}
function lb_del(id){
	if(id>0){
		if(confirm("წავშალო ეს კანონი?"))loadXMLDoc('lb_del.php','id='+id);
	}else{
		alert("სისტემური შეცდომა!");
	}
}

