function sDisp(obj){obj.style.display="block";}
function sDispN(obj){obj.style.display="none";}

function FaqAct(id){
   OB = document.getElementById("o_block" + id);
   TB = document.getElementById("t_block" + id);
   TTB = document.getElementById("tt_block" + id);
   if ( TB.style.display == 'none'){
    TB.style.display = ''
    TTB.style.display = ''
    OB.style.display = 'none'
    }
   else{
    TB.style.display = 'none';
    TTB.style.display = 'none';
    OB.style.display = ''
    }
   }
   
function getElementsByClass(searchClass,node,tag) {
   var classElements = new Array();

   if ( node == null )
      node = document;
   if ( tag == null )
      tag = '*';
   var elements = node.getElementsByTagName(tag);
   var elemLength = elements.length;
   var pattern = new RegExp('(^|\\\\s)'+searchClass+'(\\\\s|$)');
   for (var i = 0, j = 0; i < elemLength; i++) {
      if ( pattern.test(elements[i].className) ) {
         classElements[j] = elements[i];
         j++;
      }
   }
   return classElements;
}

function GetFromForm2(formID){
	var form   = document.getElementById(formID);
	var formEl = form.elements;
	var count  = formEl.length;
	var str = '';
	for(var i=0; i<count; i++) {
	    if(typeof(formEl[i].name) != 'undefined') {
	        switch(formEl[i].type) {
	            case 'radio':
	                if (formEl[i].checked) {str += '&' + formEl[i].name + '=' + encodeURIComponent(formEl[i].value);}
	            break;
	            case 'checkbox':
	                if (formEl[i].checked) {str += '&' + formEl[i].name + '=' + encodeURIComponent(formEl[i].value);}
	            break;
				case 'select-multiple':
					for (var j=0; j < (formEl[i].options.length); j++)
						if (formEl[i].options[j].selected) 
							str += '&' + formEl[i].name +'['+j+']'+'='+ encodeURIComponent(formEl[i].options[j].value);
	            break;
	            default:
	                str += '&' + formEl[i].name + '=' + encodeURIComponent(formEl[i].value);
	            break;
	        }            
	    }
	}
	return str;
	}  

function ShowHide(id){
	elems=getElementsByClass("KnowBox");
	for(i=0;i<elems.length;i++)
		if (elems[i].getAttribute('id')!=("KnowBox"+id))
			elems[i].style.display="none";
			
	if (document.getElementById("KnowBox"+id).style.display=="")
		document.getElementById("KnowBox"+id).style.display="none";
		else document.getElementById("KnowBox"+id).style.display="";
	}	
   
function pause(ms){
		var date = new Date();
		var curDate = null;
		do { curDate = new Date(); }
		while(curDate-date < ms);
	}

function SetToAllPart(modul,field){
	var nameData = null;
	nameData = prompt ("Введите новое значение:", nameData );		
	if (nameData != null)
			SendAJAX("mod="+modul+"&type=AJAX&s=SetToAll"+"&field="+field+"&new="+encodeURIComponent(nameData));
	}
	
function GaleryOpenWindow(img, txt){
		newImg = new Image(); 
		newImg.src = img; 
		win = window.open('','new','height=50, width=100, resizable=0, top=100, left=100');
		//win.document.write("<html><head><title>" + txt + "</title></head><body style='margin: 0; padding: 0;'><table width=100% height=100%><tr><td align=center valign=middle>");
		win.document.write("<center><img id='img777' alt='идет загрузка...' src='/images/admin/indicator_medium.gif'></center>");
		//win.document.write("</td></tr></table></body></html>");	
		while (!newImg.complete)
			pause(100);
		//win.close();
		//win2 = window.open('','new2','height='+(newImg.height+20)+', width='+(newImg.width+20) + ', resize=0');
		//win.document.write("<html><head><title>" + txt + "</title></head><body style='margin: 0; padding: 0;'><table width=100% height=100%><tr><td align=center valign=middle>");
		//win2.document.write("<img alt='"+txt+"' src='"+ newImg.src +"'>");
		win.document.getElementById("img777").src = newImg.src;
		win.resizeTo(newImg.width+24,newImg.height+72);
	}

function OpenEditor(type,id){
	window.open("/admin/includes/editor.php?type="+type+"&id="+id,"Edit","height=600, width=800");
	//window.open("http://domino.artena.ru/admin/includes/editor.php?type="+type+"&id="+id,"Edit","height=600, width=800");
	}
	
function OpenEditor2(type,id){
	window.open("/admin/archedit/editor.php?type="+type+"&id="+id,"Edit","height=600, width=800");
	}

function ShowIndicator(objID){
	document.getElementById(objID).innerHTML='<center><img alt="идет загрузка..." src="/images/admin/indicator_medium.gif" border=0 style="border: none 0px red"></center>';
	}
	
function getRequestObject(){
		var req = null;
		if (typeof XMLHttpRequest != "undefined")
			req = new XMLHttpRequest();
		if (!req && typeof ActiveXObject != "undefined"){
			try
			{req=new ActiveXObject("Msxml2.XMLHTTP");}
			catch (e){
				try
				{req=new ActiveXObject("Microsoft.XMLHTTP");}
				catch (e2){
					try 
					{req=new ActiveXObject("Msxml2.XMLHTTP.4.0");}
					catch (e3)
					{req=null;}
				}
			}
		}
		if(!req && window.createRequest)
			req = window.createRequest();
		return req;
	}

function SendAJAX(arg){
		//alert(arg);
		var xmlHttp = getRequestObject();
		var addrSave=window.top.location.protocol+"//"+window.top.location.host;
		xmlHttp.open('POST', addrSave, true);
	  	xmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded; charset=UTF-8");
	  	xmlHttp.setRequestHeader("Content-Length", arg.length);
	  	xmlHttp.send(arg);
	}
	
function SendGetAJAX(arg,objID){
		ShowIndicator(objID);
		//alert(arg);
		var xmlHttp = getRequestObject();
		var addrSave=window.top.location.protocol+"//"+window.top.location.host;//+window.top.location.pathname;
		xmlHttp.onreadystatechange = function() {
			if (xmlHttp.readyState == 4) {
			//alert(xmlHttp.responseText);
			document.getElementById(objID).innerHTML=unescape(xmlHttp.responseText);
			}
		}		
		xmlHttp.open('POST', addrSave, true);
	  	xmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded; charset=UTF-8");
	  	xmlHttp.setRequestHeader("Content-Length", arg.length);
	  	xmlHttp.send(arg);
	}
	
function ChangeField(table,field,id,objID){
	var nameData = document.getElementById(objID).innerHTML;
	nameData = prompt ("Введите новое значение:", nameData );		
	if (nameData != null)
			SendGetAJAX("mod=edit&type=AJAX&table="+table+"&field="+field+"&id="+id+"&new="+encodeURIComponent(nameData),objID);
	}
	
function Refresh(module,id){
	SendGetAJAX("mod="+module+"&type=AJAX&s=Refresh&id=" + id, module+id);
	}
	
/*----- PartModul -----*/

function Move(modul,who,id,direct){
	ShowIndicator(modul + who + id);
	if (direct==1) arg = "mod="+modul+"&type=AJAX&s="+who+"Up&id="+id;
	if (direct==0) arg = "mod="+modul+"&type=AJAX&s="+who+"Down&id="+id;
	var xmlHttp = getRequestObject();
	var addrSave=window.top.location.protocol+"//"+window.top.location.host+window.top.location.pathname;
	xmlHttp.onreadystatechange = function() {
		if (xmlHttp.readyState == 4) {
		var newid= xmlHttp.responseText;
		//alert(newid);
		if (newid == id){
			if (direct==1) alert("Выше нельзя!");
			if (direct==0) alert("Ниже нельзя!");
			SendGetAJAX("mod="+modul+"&type=AJAX&s=Show"+who+"&id="+id, modul+who+id);
			}
		else{
			try {
				document.getElementById(modul+who+newid).id = "temp";
				document.getElementById(modul+who+id).id = modul+who+newid;
				document.getElementById("temp").id = modul+who+id;
				SendGetAJAX("mod="+modul+"&type=AJAX&s=Show"+who+"&id="+id, modul+who+id);
				SendGetAJAX("mod="+modul+"&type=AJAX&s=Show"+who+"&id="+newid, modul+who+newid);
				}
			catch (error) {
				document.getElementById(modul+who+id).id = modul+who+newid;
				SendGetAJAX("mod="+modul+"&type=AJAX&s=Show"+who+"&id="+newid, modul+who+newid);
				}
			}
		} 
	}		
	xmlHttp.open('POST', addrSave, true);
	xmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded; charset=UTF-8");
	xmlHttp.setRequestHeader("Content-Length", arg.length);
	xmlHttp.send(arg);
	}

function Hide(modul,who,id){
	SendGetAJAX("mod="+modul+"&type=AJAX&s="+who+"Hide&id="+id, modul+who+id);
	}

function Show(modul,who,id){
	SendGetAJAX("mod="+modul+"&type=AJAX&s="+who+"Show&id="+id, modul+who+id);
	}	

function SetCaption(modul,who,id){
	var nameData = document.getElementById(modul+who+"Caption"+id).innerHTML;
	
	if (who=='Item') nameData = prompt ("Введите новую подпись к изображению:", nameData );
			else nameData = prompt ("Введите новое название раздела:", nameData );
			
	if (nameData != null)
			SendGetAJAX("mod="+modul+"&type=AJAX&s="+who+"SetCaption&id="+id+"&txt="+encodeURIComponent(nameData),modul+who+"Caption"+id);
	}
	
function ItemDel(modul,id){
		if (confirm("Вы действительно хотите удалить элемент?")){
		SendAJAX("mod="+modul+"&type=AJAX&s=ItemDel&id="+id);
		document.getElementById(modul+"Item"+id).style.display = "none";
		}
	}

function ItemAdd(modul,part){
		SendAJAX("mod=catalog1&type=AJAX&s=ItemAdd&part="+part);
		SendGetAJAX("mod=catalog1&type=AJAX&s=ShowList&part="+part, "catalogList");
	}

function PartDel(modul,id){
		if (confirm("Вы действительно хотите удалить раздел фотогалереи?")) 
			{SendGetAJAX("mod="+modul+"&type=AJAX&s=PartDel&part="+id, modul+"Part"+id)}
	}

function PartAdd(modul){
		var arg = "mod="+modul+"&type=AJAX&s=PartAdd";
		var xmlHttp = getRequestObject();
		var addrSave=window.top.location.protocol+"//"+window.top.location.host+window.top.location.pathname;
		xmlHttp.onreadystatechange = function() {
			if (xmlHttp.readyState == 4) {
			var id= xmlHttp.responseText;
			document.getElementById(modul+"PartList").innerHTML += "<div id='temp"+id+"'><div>";
			SendGetAJAX("mod="+modul+"&type=AJAX&s=ShowPart&div=1&id=" + id,"temp"+id);
			} 
		}		
		xmlHttp.open('POST', addrSave, true);
	  	xmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded; charset=UTF-8");
	  	xmlHttp.setRequestHeader("Content-Length", arg.length);
	  	xmlHttp.send(arg);
	}
	
/*----- Фотогалерея -----*/

function GalerySetParams(part){
		var width = document.getElementById("GaleryWidth").value;
		var height = document.getElementById("GaleryHeight").value;
		var heighttxt = document.getElementById("GaleryHeightTxt").value;
		var ipp = document.getElementById("GaleryIpp").value;
		SendAJAX("mod=galery&type=AJAX&s=SetParams&part="+part+"&width="+width+"&height="+height+"&heighttxt="+heighttxt+"&ipp="+ipp);
		SendGetAJAX("mod=galery&type=AJAX&s=ShowList&part=" + part,"galeryList");
	}
	
function CatalogSetParams(part){
		var width = document.getElementById("CatalogWidth").value;
		var height = document.getElementById("CatalogHeight").value;
		var ipp = document.getElementById("CatalogIpp").value;
		SendAJAX("mod=catalog&type=AJAX&s=SetParams&part="+part+"&width="+width+"&height="+height+"&ipp="+ipp);
		SendGetAJAX("mod=catalog&type=AJAX&s=ShowList&part=" + part,"catalogList");
	}
	
function Catalog1SetParams(part){
		var width = document.getElementById("CatalogWidth").value;
		var height = document.getElementById("CatalogHeight").value;
		var ipp = document.getElementById("CatalogIpp").value;
		SendAJAX("mod=catalog1&type=AJAX&s=SetParams&part="+part+"&width="+width+"&height="+height+"&ipp="+ipp);
		SendGetAJAX("mod=catalog1&type=AJAX&s=ShowList&part=" + part,"catalogList");
	}
	
	
function NewsSetParams(part){
		var width = document.getElementById("NewsWidth").value;
		var height = document.getElementById("NewsHeight").value;
		var ipp = document.getElementById("NewsIpp").value;
		SendAJAX("mod=news&type=AJAX&s=SetParams&part="+part+"&width="+width+"&height="+height+"&ipp="+ipp);
		SendGetAJAX("mod=news&type=AJAX&s=ShowList&part=" + part,"newsList");
	}
	
function SeoWordAdd(type){
		var Word = encodeURIComponent(document.getElementById("SeoWordWord").value);
		var Desc = encodeURIComponent(document.getElementById("SeoWordDesc").value);
		var Link = encodeURIComponent(document.getElementById("SeoWordLink").value);
		var Title = encodeURIComponent(document.getElementById("SeoWordTitle").value);
		//alert(Word+"\n"+Desc+"\n"+Link+"\n"+Title);
		//SendAJAX("mod=seo&type=AJAX&s=Add&link="+Link+"&word="+Word+"&desc="+Desc+"&title="+Title);
		if (type==1){
			SendAJAX("mod=seo&type=AJAX&s=Add&link="+Link+"&word="+Word+"&desc="+Desc+"&title="+Title);
			SendGetAJAX("mod=seo&type=AJAX&s=ShowList","SeoWord");
			}
			else{
			SendGetAJAX("mod=seo&type=AJAX&s=Add&link="+Link+"&word="+Word+"&desc="+Desc+"&title="+Title,"seoform");
			//self.close();
			}
	}

function SeoWordDel(id){
		SendAJAX("mod=seo&type=AJAX&s=Del&id="+id);
		SendGetAJAX("mod=seo&type=AJAX&s=ShowList","SeoWord");
	}
	
/*----- FAQ -----*/

function FaqSetParams(part){
		var ipp = document.getElementById("FaqIpp").value;
		SendAJAX("mod=faq&type=AJAX&s=SetParams&part="+part+"&ipp="+ipp);
		SendGetAJAX("mod=faq&type=AJAX&s=ShowList&part=" + part,"faqList");
	}

/*----- Order -----*/	
	
function OrderSetCaption(id){
	var nameData = document.getElementById("OrderCaption").innerHTML;
	nameData = prompt ("Введите новое название раздела:", nameData );
	if (nameData != null)
			SendGetAJAX("mod=order&type=AJAX&s=SetCaption&id=" + id + "&txt=" + encodeURIComponent(nameData),"OrderCaption");
	}

function OrderSetEmail(id){
	var nameData = document.getElementById("OrderEmail").innerHTML;
	nameData = prompt ("Введите новый e-mai:", nameData );
	if (nameData != null)
			SendGetAJAX("mod=order&type=AJAX&s=SetEmail&id=" + id + "&txt=" + encodeURIComponent(nameData),"OrderEmail");
	}
/*----- menus -----*/
function MenusChangeType(id,oldtype,type){
	//alert(id+"\n"+type);
	if (confirm("Вы действительно хотите изменить тип пункт меню?")){
		SendGetAJAX("mod=menus&type=AJAX&s=ItemSetType&id="+id+"&txt="+encodeURIComponent(type),"menusItem"+id);
		}else{
		document.getElementById("menusSelect"+id).value=oldtype;
		}
	}
	
function MenusChangeTypeP(id,oldtype,type){
	//alert(id+"\n"+type);
	if (confirm("Вы действительно хотите изменить тип пункт меню?")){
		SendGetAJAX("mod=menus&type=AJAX&s=ItemSetType&id="+id+"&txt="+encodeURIComponent(type),"menusItem"+id);
		}else{
		document.getElementById("menusSelectP"+id).value=oldtype;
		}
	}
	
function MenusItemAdd(part){
		SendAJAX("mod=menus&type=AJAX&s=ItemAdd&part="+part);
		SendGetAJAX("mod=menus&type=AJAX&s=ShowSubList&id="+part,"menusSubMenu"+part);
	}
	
function ShowSubLevel(id){
	document.getElementById("menusItemSubLink"+id).style.display="none";
	document.getElementById("menusItemSubLink_"+id).style.display="";
	document.getElementById("menusItem"+id).innerHTML+="<div class='menusSub' id=menusSubMenu"+id+"></div>"
	SendGetAJAX("mod=menus&type=AJAX&s=ShowSubList&id="+id,"menusSubMenu"+id);
	}

function HideSubLevel(id){
	document.getElementById("menusItemSubLink_"+id).style.display="none";
	document.getElementById("menusItemSubLink__"+id).style.display="";
	document.getElementById("menusSubMenu"+id).style.display="none";
	}
	
function ShowSubLevel2(id){
	document.getElementById("menusItemSubLink__"+id).style.display="none";
	document.getElementById("menusItemSubLink_"+id).style.display="";
	document.getElementById("menusSubMenu"+id).style.display="";
	}

function SetSeo(id){
	window.open("/includes/seoform.php?id="+id,"Seo","height=300, width=300");
	}

function Login(){
		var login = document.getElementById("admin_login").value;
		var pass = document.getElementById("admin_pass").value;
		SendGetAJAX("mod=login&type=AJAX&login="+login+"&pass="+pass,"content");
		//document.location.href='/menus/';
	}