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";
}

// 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 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 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;
}

