//<![CDATA[
var ns6=document.getElementById&&!document.all
function restrictinput(maxlength,e,placeholder){
if (window.event&&event.srcElement.value.length>=maxlength)
return false
else if (e.target&&e.target==eval(placeholder)&&e.target.value.length>=maxlength){
var pressedkey=/[a-zA-Z0-9\.\,\/]/ //detect alphanumeric keys
if (pressedkey.test(String.fromCharCode(e.which)))
e.stopPropagation()
}
}

function countlimit(maxlength,e,placeholder){
var theform=eval(placeholder)
var lengthleft=maxlength-theform.value.length
var placeholderobj=document.all? document.all[placeholder] : document.getElementById(placeholder)
if (window.event||e.target&&e.target==eval(placeholder)){
if (lengthleft<0)
theform.value=theform.value.substring(0,maxlength)
placeholderobj.innerHTML=lengthleft
}
}

function displaylimit(thename, theid, thelimit){
var theform=theid!=""? document.getElementById(theid) : thename
var limit_text='<b><span id="'+theform.toString()+'">'+thelimit+'</span></b>'
if (document.all||ns6)
document.write(limit_text)
if (document.all){
eval(theform).onkeypress=function(){ return restrictinput(thelimit,event,theform)}
eval(theform).onkeyup=function(){ countlimit(thelimit,event,theform)}
}
else if (ns6){
document.body.addEventListener('keypress', function(event) { restrictinput(thelimit,event,theform) }, true); 
document.body.addEventListener('keyup', function(event) { countlimit(thelimit,event,theform) }, true); 
}
}

/* проверка мыла */
	function checkemail(form)
	{
		if(form.new_useremail.value.search("^(.+)((@){1})(.+)$") == -1)
		{
			alert("Пожалуйста, укажите валидный e-mail адрес.");
			return false;
		}
		return true;
	}
	
	
	function check_add_form(form_name)
	{
		if(form_name.admin_email.value.search("^(.+)((@){1})(.+)$") == -1)
		{
			alert("Пожалуйста, укажите валидный e-mail адрес.");
			return false;
		}
		if(form_name.admin_name.value.search("^(.+)(.+)$") == -1)
		{
			alert("Пожалуйста, укажите имя администратора.");
			return false;
		}
		return true;
	}
	
	function check_delete_account(form_name)
	{
		if(form_name.userpassword.value.search("^(.+)(.+)$") == -1)
		{
			alert("Пожалуйста, введите текщий пароль доступа к сервису.");
			return false;
		}
		if(confirmUse("Вы действительно хотите удалить аккаунт?"))
		{ 
			form_name.action.value="delete";
			form_name.submit(); 
		}
	}

/* меню
*/
	function borderize(what,color,bgcolor)
	{
		what.style.borderColor=color;
		what.bgColor = bgcolor;
	}
	function borderize_on(e)
	{
		if (document.all)
		source3=event.srcElement
		else if (document.getElementById)
		source3=e.target
		if (source3.className=="menulines")
		{
			borderize(source3,"black","#D0D0D0") //  Цвет выделенной рамки
		}else
		{
			while(source3.tagName!="TABLE")
			{
				source3=document.getElementById? source3.parentNode : source3.parentElement
				if (source3.className=="menulines")
				borderize(source3,"black","#D0D0D0") //  Цвет выделенной рамки
			}
		}
	}
	function borderize_off(e)
	{
		if (document.all)
		source4=event.srcElement
		else if (document.getElementById)
		source4=e.target
		if (source4.className=="menulines")
		{
			borderize(source4,"silver","white") //  Цвет рамки после события OnMouseOut
		} else
		{
			while(source4.tagName!="TABLE")
			{
				source4=document.getElementById? source4.parentNode : source4.parentElement
				if (source4.className=="menulines")
				borderize(source4,"silver","white")  //  Цвет рамки после события OnMouseOut
			}
		}
	}

	function checkall(f) {
		for (i = 0; i < f.elements.length; i++) {
		f.elements[i].checked = true;
		}
	}
	function nocheckall(f) {
		for (i = 0; i < f.elements.length; i++) {
		f.elements[i].checked = false;
		}
	}
	function countcheck(f) {
		total  = 0;
		for (i = 0; i < f.elements.length; i++) {
		if(f.elements[i].checked) {
			total++;
		}
		}
		return total;
	}
	function AnySelected(f)
	{
		for (i = 0; i < f.elements.length; i++) {
			if (f.elements[i].checked) return true;
		}
		return false;
	}
	function confirmUse(s)
	{
    	return window.confirm(s);
	}

	function deleteselected(f){
		if(AnySelected(f)) {
		if(confirmUse("Вы действительно хотите удалить выделенные позиции?")) { 
			f.action.value="delete";
			f.submit(); 
		}
		} else {
		alert("Вы должны отметить хотя бы одну позицию!");
		}
	}
	function blockselected(f){
		if(AnySelected(f)) {
		if(confirmUse("Вы действительно хотите блокировать выделенные позиции?")) { 
			f.action.value="block";
			f.submit(); 
		}
		} else {
		alert("Вы должны отметить хотя бы одну позицию!");
		}
	}
	function unblockselected(f){
		if(AnySelected(f)) {
			f.action.value="unblock";
			f.submit(); 
		} else {
		alert("Вы должны отметить хотя бы одну позицию!");
		}
	}
	function blacklist_add(f){
		if(AnySelected(f)) {
		if(confirmUse("Вы действительно хотите добавить выделенные позиции в чёрный список?")) { 
			f.action.value="blacklist";
			f.submit(); 
		}
		} else {
		alert("Вы должны отметить хотя бы одну позицию!");
		}
	}
	function export_xls(f){
		if(confirmUse("Экспортировать список в XLS файл?")) { 
			f.action.value="export";
			f.submit(); 
		}
	}

	function update_cy(id,f){
			f.action.value="update_cy";
			f.id.value = id;
			f.submit(); 
	}

	// запрет на копирование данных
	var message='По Правилам Сервиса Вы не имеете права копировать данные любого вида со страниц сайта Сервиса.\n\nЗа информацией Вы можете обратиться к администрации Сервиса с помощью формы "Обратной связи".';
	var ie = document.all;
	function click(e)
	{
		if (ie)
		{
			if (event.button == 2)
			{
				alert(message);
				return false;
			}
		}
		if (document.layers)
		{
			if (e.which == 3)
			{
				alert(message);
				return false;
			}
		}
	}
	if (document.layers)
	{
		document.captureEvents(Event.MOUSEDOWN);
	}
/*	document.onmousedown=click;*/

	
/* счётчик прогресс-бара */
	var mycount;
	
	function UpdateProgress(barvalue){
		mycount = barvalue + 0;
		if(mycount <= 400){
			divProgress.style.width = mycount;
		}
	}
	function Tick(stopvalue){
		mycount = mycount + 5;
		if(mycount <= stopvalue){
			divProgress.style.width = mycount;
			if(mycount < 400)
				window.setTimeout ("Tick(" + stopvalue + ");", 50);
		}
	}
	
	
/***********************************************
* Cool DHTML tooltip script II- © Dynamic Drive DHTML code library (www.dynamicdrive.com)
* This notice MUST stay intact for legal use
* Visit Dynamic Drive at http://www.dynamicdrive.com/ for full source code
***********************************************/

var offsetfromcursorX=12 //Customize x offset of tooltip
var offsetfromcursorY=10 //Customize y offset of tooltip

var offsetdivfrompointerX=10 //Customize x offset of tooltip DIV relative to pointer image
var offsetdivfrompointerY=14 //Customize y offset of tooltip DIV relative to pointer image. Tip: Set it to (height_of_pointer_image-1).

document.write('<div id="dhtmltooltip"></div>') //write out tooltip DIV
document.write('<img id="dhtmlpointer" src="images/arrow2.gif">') //write out pointer image

var ie=document.all
var ns6=document.getElementById && !document.all
var enabletip=false
if (ie||ns6)
var tipobj=document.all? document.all["dhtmltooltip"] : document.getElementById? document.getElementById("dhtmltooltip") : ""

var pointerobj=document.all? document.all["dhtmlpointer"] : document.getElementById? document.getElementById("dhtmlpointer") : ""

function ietruebody(){
return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
}

function ddrivetip(thetext, thewidth, thecolor){
if (ns6||ie){
if (typeof thewidth!="undefined") tipobj.style.width=thewidth+"px"
if (typeof thecolor!="undefined" && thecolor!="") tipobj.style.backgroundColor=thecolor
tipobj.innerHTML=thetext
enabletip=true
return false
}
}

function positiontip(e){
if (enabletip){
var nondefaultpos=false
var curX=(ns6)?e.pageX : event.clientX+ietruebody().scrollLeft;
var curY=(ns6)?e.pageY : event.clientY+ietruebody().scrollTop;
//Find out how close the mouse is to the corner of the window
var winwidth=ie&&!window.opera? ietruebody().clientWidth : window.innerWidth-20
var winheight=ie&&!window.opera? ietruebody().clientHeight : window.innerHeight-20

var rightedge=ie&&!window.opera? winwidth-event.clientX-offsetfromcursorX : winwidth-e.clientX-offsetfromcursorX
var bottomedge=ie&&!window.opera? winheight-event.clientY-offsetfromcursorY : winheight-e.clientY-offsetfromcursorY

var leftedge=(offsetfromcursorX<0)? offsetfromcursorX*(-1) : -1000

//if the horizontal distance isn't enough to accomodate the width of the context menu
if (rightedge<tipobj.offsetWidth){
//move the horizontal position of the menu to the left by it's width
tipobj.style.left=curX-tipobj.offsetWidth+"px"
nondefaultpos=true
}
else if (curX<leftedge)
tipobj.style.left="5px"
else{
//position the horizontal position of the menu where the mouse is positioned
tipobj.style.left=curX+offsetfromcursorX-offsetdivfrompointerX+"px"
pointerobj.style.left=curX+offsetfromcursorX+"px"
}

//same concept with the vertical position
if (bottomedge<tipobj.offsetHeight){
tipobj.style.top=curY-tipobj.offsetHeight-offsetfromcursorY+"px"
nondefaultpos=true
}
else{
tipobj.style.top=curY+offsetfromcursorY+offsetdivfrompointerY+"px"
pointerobj.style.top=curY+offsetfromcursorY+"px"
}
tipobj.style.visibility="visible"
if (!nondefaultpos)
pointerobj.style.visibility="visible"
else
pointerobj.style.visibility="hidden"
}
}

function hideddrivetip(){
if (ns6||ie){
enabletip=false
tipobj.style.visibility="hidden"
pointerobj.style.visibility="hidden"
tipobj.style.left="-1000px"
tipobj.style.backgroundColor=''
tipobj.style.width=''
}
}

document.onmousemove=positiontip
//]]>
