
///////////////////////////////////////////////////////////////////////////////
///  e4system v 0.4.1
///  (c) 2002, Michal Kouďa , e4you spol. s r.o., michal.kouda@e4you.cz
///  encoding: iso-8859-2
///////////////////////////////////////////////////////////////////////////////
///  JavaScript function library
///////////////////////////////////////////////////////////////////////////////

/// identifikace vlastnosti browseru 
runningInGecko = (navigator.product == 'Gecko')
runningInMSIE = (document.all != null)


/// funkce nastavujici objektu tridu
function setClass(obj,cls) {
	obj.className=cls;
	return true;
};

/// kontroluje, jestli parametr je ve formatu emailove
/// adresy ('' == správné ~= žádný e-mail)
function validEmail(email) {
	if(email=='') return true;
	reEmail = new RegExp("^[a-zA-Z0-9._-]+@[a-zA-Z0-9._-]+[.][a-zA-Z]{2,7}$");
	return reEmail.test(email);
};

/// kontroluje, jestli parametr je ve formátu
/// správného uživatleského jména
function validUsername(username) {
	if(username=='') return false;
	reLogin = new RegExp("^[a-zA-Z0-9_-]{4,48}$");
	return reLogin.test(username);
};

/// kontroluje, jestli parametr je ve formátu
/// správného uživatleského hesla
function validPasswd(passwd) {
	if(passwd == '******') return true;
	if(passwd == '') return false;
	if(passwd.length < 6) return false;
	reAZ = new RegExp('[0-9]+');
	if(!reAZ.test(passwd)) return false;
	re09 = new RegExp('[a-zA-Z]+');
	if(!re09.test(passwd)) return false;
	return true;
};

function validUserPasswdPair(username,passwd) {
	if(!validUsername(username)) return false;
	if(!validPasswd(passwd)) return false;
	if(passwd.toUpperCase()==username.toUpperCase()) return false;
	if(passwd.search(username)!=-1) return false;
	revuname = '';
	for(i=0;i<username.length;i++) {
		revuname = username.charAt(i) + revuname;
	}
	if (revuname.toUpperCase()==passwd.toUpperCase()) return false;
	return true;
}

function validICO(ico) {
	if(ico=='') return true;
	reICO = new RegExp("^[0-9]{8}$");
	return reICO.test(ico);
};

function validDIC(dic) {
	if(dic=='') return true;
	reDIC = new RegExp("^([a-zA-Z]{2}|[0-9]{3}-)[0-9]{8,10}$");
	return reDIC.test(dic);
};


function openLink(url) {
	previewWin=window.open(url,'linx','');
}


PicWinOpened = false;
function previewImg(src,w,h,description) {
	if(PicWinOpened) {
		PicWin.close();
		PicWinOpened = false;
	}
	winw = w + 20;
	winh = h + 30;
	PicWin = window.open('','picturedetail','width='+winw+',height='+winh+',resizable=no,location=no,status=no,scrollbars=no');
	with(PicWin) {
		document.open();
		document.write('<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">');
		document.write('<head><title>'+description+'</title></head>');
		document.write('<html><body style="margin: 10px 0 0 0; padding: 0px; background-color: black; text-align:center; font-family: verdana,sans-serif; font-size: 11px;">');
		document.write('<a href="javascript: window.close();" title="Zavřít okno"><img src="'+src+'" alt="Zavřít okno" width="'+w+'" height="'+h+'" border="0" /></a>');
		document.write('<div style="color: white">'+description+'</div>');
		document.write('</body></html>');
		document.close();
		focus();
		PicWinOpened = true;
	};
	return false;
};

function openImageWindow(src) {
	if(PicWinOpened) {
		PicWin.close();
		PicWinOpened = false;
	}
	PicWin = window.open('','picturedetail','width=100,height=100,resizable=no,location=no,status=no,scrollbars=no');
	with(PicWin) {
		document.open();
		document.write('<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">');
		document.write('<html><body style="margin: 10px 0 0 0; padding: 0px; background-color: black; text-align:center; font-family: verdana,sans-serif; font-size: 11px;">');
		document.write('<a href="javascript: window.close();" title="Zavřít okno"><img src="'+src+'" alt="'+name+'" border="0" onLoad="window.resizeTo(this.width+20,this.height+40); window.innerWidth=this.width+6; window.innerHeight=this.height+30; return true;"/></a>');
		document.write('</body></html>');
		document.close();
		focus();
		PicWinOpened = true;
	};
	return false;
};


/// vraci objekt podle jeho  id
function getObject(objectName) {
	try {
		if(document.all) {
			obj = eval("document.all['"+objectName+"']");
			return obj;
		} else if(document.getElementById) {
			return document.getElementById(objectName);
		} else {
			return false;
		}
	} catch(error) {
		alert("Object find error: "+error);
		return false;
	}
}

/// vytiskne strukturu objektu do nove otevreneho okna
function debugObject(dbgObject) {
	try {
		var debugLog = "[" + dbgObject.name + "]\n";
	} catch(error) {
		var debugLog = "[undefined]\n";
	}
	for (property in dbgObject) {
		try {
			debugLog += '\t.' + property ;
			debugLog += ' = ' + eval('dbgObject.' + property) + "\n";
		} catch(error) {
			debugLog += '\t.' + property + " = ???\n";
		}
	}
	debugWin = window.open('','debug');
	debugWin.document.write("<h2>Vypis objektu</h2>");
	debugWin.document.write("<pre>" + debugLog + "</pre>");
	return debugLog;
}

/// vytiskne strukturu objektu podle jmena do nove otevreneho okna
function debugObjectByName(dbgObjectName) {
	dbgObject = getObject(dbgObjectName);
	if(dbgObject) {
		return debugObject(dbgObject);
	} else {
		return false;
	}
}


function openWindowEx(url,winname,width,height,left,top) {
	win = open(url,winname,'left='+left+',top='+top+',width='+width+',height='+height+',menubar=no,status=no,scrollbars=yes');
	win.focus();
	return true;
}
