function getObjectBW(name) {
	if(!name || name == null) return null;
	else if(document.getElementById) return document.getElementById(name);
	else if(document.all) return document.all[name];
	else return null;
}
String.prototype.trim = function(){
	return this.replace(/^\s+|\s+$/g,"");
}
function onDisplay(){
	var elem_id = null;
	this.check=function(id){
		if((elem_id = getObjectBW(id))!= null){
			if(elem_id.style.display !="none") return true;
		}
		return false;
	}
	this.set=function(id, viz){
		if((elem_id = getObjectBW(id))!= null) elem_id.style.display = viz;
		return;
	}
}
var dis = new onDisplay();

var flag = 0;

function show_hide1( what_show, show )
{
	if( show )
		dis.set( what_show, "" );
	else
		dis.set( what_show, "none");
}

function klop2(inn)
{
	var t=0;
	if( dis.check("div_"+inn) )
	{
		flag = 1;
		dis.set("div_"+inn, "none");
		if( inn.indexOf("-") < 0 )
		{
			if( !flag )
			{
				for( i in vmenu )
				{
					if( (vmenu[i].indexOf("-")<0) && (vmenu[i]!=inn) )
					{
						roll("img_"+vmenu[i], 'images/img_menu_minus0.gif');
					}
				}
			}
			roll("img_"+inn, 'images/img_menu_plus0.gif');
		}
	}
	else
	{
		if( inn.indexOf("-") < 0 )
		{
			for(i in vmenu)if((vmenu[i].indexOf("-")<0)&&(vmenu[i]!=inn))
			{
				roll("img_"+vmenu[i], 'images/img_menu_plus0.gif');
			}
			else
			{
				roll("img_"+inn, 'images/img_menu_minus0.gif');
			}
		}
		if((t=inn.lastIndexOf("-"))>0)
		{
			for(i in vmenu)
			{
				if(vmenu[i].indexOf(inn.substring(0, t)+"-") == 0)
				{
					dis.set("div_"+vmenu[i], "none");
				}
			}
		}
		dis.set("div_"+inn, "");
	}
	if( ( t=inn.lastIndexOf("-") )<0 )
	{
		for(i in vmenu)
		{
			if((vmenu[i].indexOf("-")<0)&&(vmenu[i] != inn))
			{
				dis.set("div_"+vmenu[i], "none");
			}
		}
	}
}

function zoom_image(image,width,height)
{
	new_window=window.open("inc/zoom_image.php?img="+image,'','resizable=no,width='+(width+20)+',height='+(height+20),false);
}

// Goods & orders

function getCookieVal (offset)
{
	var endstr = document.cookie.indexOf (';', offset);
	if (endstr == -1)
		endstr = document.cookie.length;
	return unescape(document.cookie.substring(offset, endstr));
}

function GetCookie (name)
{
	var arg = name + '=';
	var alen = arg.length;
	var clen = document.cookie.length;
	var i = 0;
	while (i < clen)
	{
		var j = i + alen;
		if (document.cookie.substring(i, j) == arg)
			return getCookieVal (j);
		i = document.cookie.indexOf(' ', i) + 1;
		if (i == 0) break;
	}
	return null;
}
function SetCookie (name,value,expires,path,domain,secure)
{
	document.cookie = name + '=' + escape (value) +
		((expires) ? '; expires=' + expires.toGMTString() : '') +
		((path) ? '; path=' + path : '') +
		((domain) ? '; domain=' + domain : '') +
		((secure) ? '; secure' : '');
}

function roll(namePic, path)
{
	if (document.images[namePic])
		document.images[namePic].src=path;
}

function DeleteCookie (name,path,domain)
{
	if (GetCookie(name))
	{
		document.cookie = name + '=' +
			((path) ? '; path=' + path : '') +
			((domain) ? '; domain=' + domain : '') +
			'; expires=Thu, 01-Jan-70 00:00:01 GMT';
	}
}

function writeNumber( num, one, two, five )
{
	num+="";
	sResText = five; // по умолчанию выводим «пять дней»
	nDaysLeftLength = num.length;
	if( num.charAt(nDaysLeftLength - 2) != "1" )
	{
		if( num.charAt(nDaysLeftLength - 1) == "2" ||
			num.charAt(nDaysLeftLength - 1) == "3" ||
			num.charAt(nDaysLeftLength - 1) == "4" )
		{
			sResText = two;
		}
		else if (num.charAt(nDaysLeftLength - 1) == "1")
		{
			sResText = one;
		}
	}
	return sResText.replace( /%number%/i, num );
}


function validEmail(str)
{
	str = str.toLowerCase( );
	if (str.indexOf("@") > 1)
	{
		var addr = str.substring(0, str.indexOf("@"));
		var domain = str.substring(str.indexOf("@") + 1, str.length);
		// at least one top level domain required
		if (domain.indexOf(".") == -1)
		{
			alert("Проверьте заполнение имени сервера в вашем e-mail.");
			return false;
		}
		// parse address portion first, character by character
		for (var i = 0; i < addr.length; i++)
		{
			oneChar = addr.charAt(i).charCodeAt(0);
			// dot or hyphen not allowed in first position; dot in last
			if( (i == 0 && (oneChar == 45 || oneChar == 46))  ||
				(i == addr.length - 1 && oneChar == 46) )
			{
				alert("Проверьте имя пользователя в вашем e-mail.");
				return false;
			}
			// acceptable characters (- . _ 0-9 a-z)
			if ( oneChar == 45 || oneChar == 46 || oneChar == 95 ||
				(oneChar > 47 && oneChar < 58) || (oneChar > 96 && oneChar < 123)) {
				continue;
			}
			else
			{
				alert("Проверьте имя пользователя в вашем e-mail.");
				return false;
			}
		}
		for (i = 0; i < domain.length; i++)
		{
			oneChar = domain.charAt(i).charCodeAt(0);
			if( (i == 0 && (oneChar == 45 || oneChar == 46)) ||
				((i == domain.length - 1  || i == domain.length - 2) && oneChar == 46))
			{
				alert("Проверьте заполнение имени сервера в вашем e-mail.");
				return false;
			}
			if( oneChar == 45 || oneChar == 46 || oneChar == 95 ||
				(oneChar > 47 && oneChar < 58) || (oneChar > 96 && oneChar < 123)) {
				continue;
			}
			else
			{
				alert("Проверьте заполнение имени сервера в вашем e-mail.");
				return false;
			}
		}
		return true;
	}
	alert("Проверьте заполнение поля e-mail.");
	return false;
}

function preloadImg()
{
	var args = preloadImg.arguments;
	document.imageArray = new Array(args.length);
	for(var i=0; i<args.length; i++)
	{
		document.imageArray[i] = new Image;
		document.imageArray[i].src = args[i];
	}
}

var submenu_timeout=0;
var submenu_cur = false;
function btn_mover( container, id ) {
	if( !container.btn )
	{
		container.btn = container.childNodes[0].rows[1].cells[1];
		container.nextClassName=container.btn.className;
	}
	container.btn.className="button_mover";
	if( submenu  = document.getElementById("submenu_"+id) ) {
		if( submenu_cur ) {
			clearTimeout( submenu_timeout );
			submenu_cur.style.display = "none";
			submenu_cur = submenu;
			submenu_cur.style.display = "block";
		}
		else {
			clearTimeout( submenu_timeout );
			submenu_timeout = setTimeout( function() { submenu_cur = document.getElementById("submenu_"+id); submenu_cur.style.display="block"; }, 500 );
		}
	}
}
function btn_mout( container, id ) {
	if( !container.btn )
	{
		container.btn = container.childNodes[0].rows[1].cells[1];
		container.nextClassName=container.btn.className;
	}
	container.btn.className=container.nextClassName;
	if( document.getElementById("submenu_"+id) ) {
		clearTimeout( submenu_timeout );
		submenu_timeout = setTimeout( function() { document.getElementById("submenu_"+id).style.display="none"; submenu_cur = false; }, 500 );
	}
}


function roll_pwd_on( inp ) {
	inp.style.display="none";
	inp.form.elements.upd.style.display="block";
	inp.form.elements.upd.focus();
}

function roll_pwd_off( inp ) {
	if( !inp.value.length ) {
		inp.style.display="none";
		inp.form.elements.upd1.style.display="block";
	}
}