var isMSIE = (navigator.appName == "Microsoft Internet Explorer");
var isOpera = (navigator.userAgent.indexOf("Opera") != -1);
var isNetscape = (navigator.appName == "Netscape");

function ShowHideElement(name)
{
	var obj = document.getElementById(name);
	if(obj.style.display == "none")
		obj.style.display = "block";
	else
		obj.style.display = "none";
}

function ShowHideImage(name, url){
	var obj = document.getElementById(name);
	if(obj.style.display == "none")
	{
		obj.src = url;
		obj.style.display = "block";
	}
	else
		obj.style.display = "none";
}

// Change object size
// cmd (1 - Increase, 2 - Decrease)
// direction (1 - width, 2 - height, 3 - both)
// pref - preffix for the cookies
// obj - object
function FrmChangeSize(cmd, direction, pref, obj, step, minw, maxw, minh, maxh)
{
	if(!(cmd==1 || cmd==2)) return false;
	if(!(direction==1 || direction==2 || direction==3) ) return false;
	if(!step) step=50;
	if(!minh || !minw || !maxh || !maxw) return false;
	var obj = document.getElementById(obj);
	if(!obj) return false;
	if(!pref) pref = "pref_";

	var w=parseInt(obj.style.width);
	var h=parseInt(obj.style.height);

	if(cmd==1)
	{
		if( (direction == 1) || (direction == 3) )
		{
			if( (w + step) <= maxw ) w = w + step;
		}
		if( (direction == 2) || (direction == 3) )
		{
			if( (h + step) <= maxh ) h = h + step;
		}
	}
	if(cmd==2)
	{
		if( (direction == 1) || (direction == 3) )
		{
			if( (w - step) >= minw ) w = w - step;
		}
		if( (direction == 2) || (direction == 3) )
		{
			if( (h - step) >= minh ) h = h - step;
		}
	}

	obj.style.width = w+'px';
	obj.style.height = h+'px';
	var expDate = new Date;
	expDate.setTime (expDate.getTime() + (600*24*60*60*1000));
	SetCookie(pref + "w", w, expDate, "/");
	SetCookie(pref + "h", h, expDate, "/");
}


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 OpenWindow(url, imgname, w, h){
	var features='left=0,top=0,resizable=1,menubar=0,location=0,status=0,toolbar=0';
	wm=window.screen.width-10;hm=window.screen.height-60;
	if(w>wm || h>hm){features=features+',scrollbars=1';}else{features=features+',scrollbars=0';}
	if(w>wm){features=features+',width='+wm;}else{features=features+',width='+w;}
	if(h>hm){features=features+',height='+hm;}else{features=features+',height='+h;}
	window.open(url, imgname, features, true);
}

function OpenWindowCatalog(url, imgname, w, h){
	var features='left=0,top=0,resizable=1,menubar=0,location=0,status=0,toolbar=0';
	wm=window.screen.width-10;hm=window.screen.height-60;
	features=features+',scrollbars=1';
	if(w>wm){features=features+',width='+wm;}else{features=features+',width='+w;}
	if(h>hm){features=features+',height='+hm;}else{features=features+',height='+h;}
	window.open(url, imgname, features, true);
}

function getElem(div) {
	return document.getElementById ? document.getElementById(div) : document.all[div]
}
function getElem2(div, obj) {
	if(isMSIE){
		return obj.Document.getElementById ? obj.Document.getElementById(div) : obj.Document.all[div];
	}
	if(isOpera){
		return obj.contentDocument.getElementById ? obj.contentDocument.getElementById(div) : obj.contentDocument.all[div];
	}
	if(isNetscape){// Mozilla
		return obj.contentDocument.getElementById ? obj.contentDocument.getElementById(div) : obj.contentDocument.all[div];
	}
}

function newImage(pimg)
{
  if (document.images)
  {
    rslt = new Image();
    rslt.src = pimg;
    return rslt;
  }
}

/**
* Проверка Email
*/
function isEmail(email)
{
	var arr1 = email.split("@");
	if (arr1.length != 2) return false;
	else if (arr1[0].length < 1) return false;
	var arr2 = arr1[1].split(".");
	if (arr2.length < 2) return false;
	else if (arr2[0].length < 1) return false;
	return true;
}


/**
* Проверка строки на пустоту
*/
function isEmpty (txt)
{
	var ch;
	if (txt == "") return true;
	for (var i=0; i<txt.length; i++){
		ch = txt.charAt(i);
		if (ch!=" " && ch!="\n" && ch!="\t" && ch!="\r") return false;
	}
	return true;
}


// добавляем элемент в строковый массив в куках
//=============================================
function array_cookie_add(id, name, expDate)
{
	var str = GetCookie(name);
	if(str == null) str = "";
	var newstr = str;
	if(str.length>0)
	{
		str = '_' + str + '_';
		if( str.indexOf('_' + id + '_') == -1 )
		{
			newstr = newstr + '_' + id;
		}
	}
	else
	{
		newstr = id;
	}
	SetCookie(name, newstr, expDate, "/");
}
// удаляем элемент из строкового массива в куках
//=============================================
function array_cookie_delete(id, name, expDate)
{
	var str = GetCookie(name);
	if(str == null) str = "";
	var newstr = str;
	if(str.length>0)
	{
		newstr = "";
		var arr = str.split('_');
		for(var i = 0; i<arr.length; i++ )
		{
			if(arr[i] != id) newstr = newstr + (newstr?"_":"") + arr[i];
		}
	}
	SetCookie(name, newstr, expDate, "/");
}


var common = {

	MenuOver: function (obj)
	{
		return this.MenuChangeState('over', obj);
	},
	MenuOut: function (obj)
	{
		return this.MenuChangeState('out', obj);
	},
	
	MenuChangeState: function (state, obj)
	{
		if( state != 'out' && state != 'over' ){
			return false;
		}
		if( obj == null ){
			return false;
		}
		var obj1 = obj;
		/*
		var obj1 = null;
		for (var i=0;i < obj.childNodes.length;i++) {
			if (obj.childNodes[i].nodeType == 1 && obj.childNodes[i].className != 'bull') {
				obj1 = obj.childNodes[i];
				break;
			}
		}*/
		if( obj1 == null ){
			return false;
		}
		var classes = obj1.className.split(' ');
		var new_classes = new Array();
		for(var i = 0; i<classes.length; i++)
		{
			if( state == 'over' || state == 'out' ){
				if(classes[i] != 'hover'){
					new_classes.push(classes[i]);
				}
			}
		}
		if( state == 'over' ){
			new_classes.push('hover')
		}
		var new_className = new_classes.join(' ');
		if( obj1.className != new_className ){
			obj1.className = new_className;
		}
		return true;
	},
	
	

stupidIE:null};


