function GetNavigator()
{
//	alert('ok')
  if (navigator.userAgent.indexOf("MSIE", 0)!=-1)
   	return "MSIE";
 if (navigator.userAgent.indexOf("Opera", 0)!=-1)
   	return "Opera";

}
function ConfirmDeleteRequest(gourl, question)
{
	if (question==null) question = "Вы действительно хотите удалить элемент"
	if (confirm(question))
		window.location.href=gourl

}

function AddElement(from, to, deletelink)
{
	var fromelement = document.getElementById(from);
	var toelement = document.getElementById("td_"+to);
	var counter = document.getElementById(to+"counter");
	index = counter.value
	elementname  = from.split("_")[0]
	text = fromelement.innerHTML.replace("name="+elementname+"_"+0,"name="+elementname+"_"+index);
	text = text.replace("id="+elementname+"_"+0,"id="+elementname+"_"+index);
	toelement.innerHTML+= text +"<a href='#' onClick='RemoveId(\""+elementname+"_"+index+"\", this)'>[X]</a><br>"
   	counter.value = parseInt(counter.value)+1
}
function RemoveId(id, link)
{
	var toremove = document.getElementById(id);
	if(toremove==null || link==null)
	{
		alert('Нечего удалять')
		return;
	}
	toremove.id = "__"
	toremove.name = "__"
	toremove.style.display = "none";
    link.style.display = "none";
}
function Check(chbox)
{
	var inputs = document.getElementsByTagName("input");
	for(i=0; i < inputs.length ; i++)
	{
   		if (inputs(i).type != "checkbox") continue;
		if (inputs(i).id == chbox.id) continue;

		checkbox = inputs(i);

		if (chbox.value == checkbox.parent)
		{
			checkbox.checked=chbox.checked
			CheckChild(checkbox)
		}

	}
	return true;
}
function IEPngFix(img, to, width, height)
{
var code = '<IMG SRC="'+ img +'" WIDTH="' + width + '" HEIGHT="' + height + '" BORDER=0>';
if( navigator.userAgent.indexOf("MSIE 6") > 1 )
	code = '<IMG SRC="include/_images/spacer.gif" WIDTH="' + width + '" HEIGHT="' + height + '" STYLE="filter: progid:DXImageTransform.Microsoft.AlphaImageLoader (src=' + img + ')">';
	var td = document.getElementById(to);
	td.innerHTML=code;

}
function CheckChild(chbox)
{
	var inputs = document.getElementsByTagName("input");

	for(j=0; j < inputs.length ; j++)
	{
   		if (inputs(j).type != "checkbox") continue;
		if (inputs(j).id == chbox.id) continue;

		checkbox = inputs(j);

		if (chbox.value == checkbox.parent)
		{
			checkbox.checked=chbox.checked
			CheckChild(checkbox)
		}

	}
	return true;
}
function CheckRadio(ToCheck)
{

		r = document.getElementById(ToCheck);
	    if (r==null)
	    	return
		r.checked=true;
}
function Select(obj)
{
	if (obj==null) null

		obj.style.background="#eeeeee";


		//alert(td.style)

}
function UnSelect(obj)
{
	if (obj==null) return
		obj.style.background="none";

		//alert(td)
}
function AddLinkToMenu (link, id, text, id2, text2)
{

    if (!opener)
	{
		alert ('окно не найдено')
		window.close()
	}
		totext = opener.document.getElementById(text);
		toid = opener.document.getElementById(id);
    	totext2 = opener.document.getElementById(text2);
		toid2 = opener.document.getElementById(id2);

		if (!totext || !toid)
		{
			alert ('не найдены элементы управления')
    		window.close()
		}

		totext.innerHTML = link.linkname;
		toid.value = link.id;
		if(totext2!=null && toid2!=null)
		{
			totext2.innerHTML = link.linkname;
			toid2.value = link.id;
		}
		window.close()

}
function LinkAdd(link, to, name)
{

    if (GetNavigator()=="Opera")
    {
    	alert('Данный браузер не поддерживает некоторые свойства, используйте IE 6+ ');
    	return;
    }
    if (!opener)
	{
		alert ('окно не найдено')
		window.close()
	}
		divname = opener.document.getElementById(name);
		id = opener.document.getElementById(to);
    	if (!divname || !id)
		{
			alert ('не найдены элементы управления')
    		window.close()
		}
        divname.innerHTML = link.linkname;

		id.value = link.link;
		window.close()

}
function RefreshOpener(w)
{
	var obj = opener.document.getElementById(w);
	window.close();
	obj.form.submit();


}
function RemoveDesc(id)
{
		div = document.getElementById(id);
		div.innerHTML = "";
		div.id = "___";
		div.style.display ="none";


}
function AddMeta()
{
	list =  document.getElementById('metalist');
	place =  document.getElementById('metatagsplace');

	var text="";
	var id ="";
	if (list==null || place==null) return;

	for(i=0;i<list.options.length;i++)
	{
		if (list.options[i].selected)
		{
			text = list.options[i].text;
        	id = list.options[i].value;
        }
	}
	div =  document.getElementById('div_'+id);

	if (div==null)
		place.innerHTML+="<div id='div_"+id+"'><table width=100%><tr><td >"+text+"</td><td align = right width=100%><input name=\"meta_"+id+"\" type=\"text\" class = 'inputtext' value=\"\"></td><td><a href='javascript:void(0)' onClick='RemoveDesc(\"div_"+id+"\")'>X</a></td></tr></table></div>";

}
function ClearLink(to, name, aadd)
{
        divname = document.getElementById(name);
		id = document.getElementById(to);

     	aadd = document.getElementById(aadd);

     	if (id.value==-1) return

     	if (divname==null || id==null)
		{
			alert ('не найдены элементы управления')
    		window.close()
    		return
		}
		if (aadd.innerHTML=="Удалить")
		{	divname.innerHTML = "Нет";
			id.value = "";
			aadd.innerHTML="Отменить"
		}
		else
			if (aadd.innerHTML=="Отменить")
			{
				divname.innerHTML = divname.orvalue;
				id.value = id.orvalue;
				aadd.innerHTML="Удалить"
			}

}
function CheckNotSelf(radio, checkid)
{
	if (radio.value == checkid)
	{
			alert("Нельзя переносить раздел таким образом(самого в себя)")
			radio.checked=false
	}

}
//function CheckParent(срусл)
function AjaxToggle(ref, text)
{

    divname = document.getElementById("ajaxtoggle");
    if (divname==null) return;
    divname.innerHTML = "<a href='"+ref+"'>"+text+"</a>";

}

function _CheckDate(text, type)
{
	msg ="Неверный ввод цифр"
	try
	{
		if (text.value=="") return
		if(!parseInt(text.value))
		{
			alert(msg)
			text.value="";
			return
		}
		switch (type)
		{
			case "day":
				if(parseInt(text.value)>31 || parseInt(text.value)<0)
				{
						alert(msg)
						text.value="";
				}
			break;
			case "month":
				if(parseInt(text.value)>12 || parseInt(text.value)<0)
				{
						alert(msg)
						text.value="";
				}
			break;
			case "year":
				if(parseInt(text.value)>2100 || parseInt(text.value)<1970)
				{
						alert(msg)
						text.value="";
				}
			break;

		}

	}
	catch (err)
	{
		alert("Ошибка")
	}
}
function CheckTextBox(textbox)
{
	if (textbox.value.length>255)
	{
		alert("Текст в текстовом поле более 255, будет обрезан")
		textbox.value = textbox.value.substring(0,255)
	}
}
function OpenEditor(txtid)
{
 w  = 850;
 h = 750;
 if (window.screen.height<h)
 	h  = window.screen.height-50;
 if (window.screen.width<w)
 	w  = window.screen.width;

 wnd = window.open("include/editor/editor.html?txtid="+txtid, "Addlink","width="+w+",height="+h+",status=no,toolbar=no,menubar=no")
}
function OpenFCKEditor(txtid)
{
 w  = 850;
 h = 750;
 if (window.screen.height<h)
 	h  = window.screen.height-50;
 if (window.screen.width<w)
 	w  = window.screen.width;

// wnd = window.open("include/editor/editor.html?txtid="+txtid, "Addlink","width="+w+",height="+h+",status=no,toolbar=no,menubar=no")
 wnd = window.open("include/fckeditor/editor.html?txtid="+txtid+"&height="+h, "Addlink","width="+w+",height="+h+",status=no,toolbar=no,menubar=no")

}

function OpenAddLinkMenu(id, text, id2, text2)
{
	wnd = window.open("include/addlinktomenu.php?to="+id+"&text="+text+"&to2="+id2+"&text2="+text2	,"Addlink","width=1024,height=768,toolbar=no,menubar=no,resizable=yes,scrollbars=yes");
}
function OpenAddDict(linkname, table, action, editid)
{
	wnd = window.open("include/addtodict.php?editid="+editid+"&action="+action+"&linkname="+linkname+"&table="+table,"Addlink","width=300,height=200,toolbar=no,menubar=no,resizable=yes,scrollbars=yes");
}

function OpenAddLink(id, name, Radio)
{
	if (Radio!=null)
	{
		CheckRadio(Radio)
	}
	wnd = window.open("include/addlink.php?to="+id+"&name="+name,"Addlink","width=1024,height=768,status=no,toolbar=no,menubar=no,resizable=yes,scrollbars=yes");
}
function OpenImage(src, w,h)
{
	wnd = window.open(src,"Image","width="+w+",height="+h+",status=no,toolbar=no,menubar=no,resizable=yes,scrollbars=yes");

}
function DeleteFile(link, HVar)
{
	v = document.getElementById(HVar)
	if (v==null) return
	if (v.value=="true")
	{
			v.value ="delete"
			link.innerHTML="отменить"
			return;

	}
    if (v.value=="delete")
	{
			v.value ="true"
			link.innerHTML="удалить"
			return;
	}

}

