var type = "IE";    //browser verzio tarolasara

BrowserSniffer();

//detects the browser
function BrowserSniffer() {
    if (navigator.userAgent.indexOf("Opera")!=-1 && document.getElementById) type="OP";	//Opera
    else if (document.all) type="IE";                                                  	//Internet Explorer e.g. IE4 upwards
    else if (document.layers) type="NN";                                               	//Netscape Communicator 4
    else if (!document.all && document.getElementById) type="MO";                      	//Mozila e.g. Netscape 6 upwards
    else type = "IE";       															//legyen IE ha egyik sem
}

//Bongeszo detektalasanak eredmenye
function whatBrows() {
    window.alert("Böngészo: " + type);
}

//Puts the contents of str into the layer id
//id is the name of the layer
//str is the required content
//Works with all browsers except Opera
function ChangeContent(id, str) {
    if (type=="IE") {
        document.all[id].innerHTML = str;
    }
    if (type=="NN") {
        document.layers[id].document.open();
        document.layers[id].document.write(str);
        document.layers[id].document.close();
    }
    if (type=="MO" || type=="OP") {
        document.getElementById(id).innerHTML = str;
    }
}

//Change the color of the layer background
//id is the name of the layer
//color is the required color
//Works with all browsers except NN4
function ChangeLayerBgColor(id, color){
    if (type=="IE") document.all[id].style.backgroundColor=color;
    if (type=="NN") document.layer['id'].bgColor=color;
    if (type=="MO" || type=="OP") document.getElementById(id).style.backgroundColor=color;
}

//menuitem highlighting
function ChangeLayerMenuItemColor(id, color, textColor){
	if (type=="IE"){
		document.all[id].style.backgroundColor=color;
		document.all[id].style.color=textColor;
	}
    if (type=="NN"){
		document.layer['id'].bgColor=color;
		document.layer['id'].color=textColor;
	}
    if (type=="MO" || type=="OP"){
		document.getElementById(id).style.backgroundColor=color;
		document.getElementById(id).style.color=textColor;
	}
}

//text szinezes
function ChangeIdColor(id, textColor){
	if (type=="IE"){
		document.all[id].style.color=textColor;
	}
    if (type=="NN"){
		document.layer['id'].color=textColor;
	}
    if (type=="MO" || type=="OP"){
		document.getElementById(id).style.color=textColor;
	}
}

//hatterkep csereje
function ChangeIdBG(id, pic){
	picStr = 'url('+pic+')';
    if (type=="IE") document.all[id].style.backgroundImage= picStr;
	if (type=="NN")	document.layer['id'].backgroundImage=picStr;
	if (type=="MO" || type=="OP") document.getElementById(id).style.backgroundImage=picStr;
}

//barmi csereje
function ChangeIdAnything(id, altalanos, ertek){
	if (type=="IE") document.all[id].style[altalanos] = ertek;
	if (type=="NN")	document.layer['id'][altalanos] = ertek;
	if (type=="MO" || type=="OP") document.getElementById(id).style[altalanos] = ertek;
}

//Show and hide a layer
//id is the name of the layer
//action is either hidden or visible
//Seems to work with all versions NN4 plus other browsers
function ShowLayer(id, action){
    if (type=="IE") eval("document.all." + id + ".style.visibility='" + action + "'");
    if (type=="NN") eval("document." + id + ".visibility='" + action + "'");
    if (type=="MO" || type=="OP") eval("document.getElementById('" + id + "').style.visibility='" + action + "'");
}

//layer X pozicio valtasa
function ChangeLayerXPos(id, value){
    if (type=="IE") document.all[id].style.left=value;
	if (type=="NN")	document.layer['id'].left=value;
    if (type=="MO" || type=="OP") document.getElementById(id).style.left=value;
}

//layer magassag valtasa
function ChangeLayerHeight(id, value){
    if (type=="IE") document.all[id].style.height=value;
	if (type=="NN")	document.layer['id'].height=value;
    if (type=="MO" || type=="OP") document.getElementById(id).style.height=value;
}

//layer szelesseg valtasa
function ChangeLayerWidth(id, value){
    if (type=="IE") document.all[id].style.width=value;
	if (type=="NN")	document.layer['id'].width=value;
    if (type=="MO" || type=="OP") document.getElementById(id).style.width=value;
}

//layer X pozicio valtasa relativan
function ChangeLayerXPosByValue(id, stepvalue){
    if (type=="IE") oldvalue = document.all[id].style.left;
    if (type=="NN")	oldvalue = document.layer['id'].left;
    if (type=="MO" || type=="OP") oldvalue = document.getElementById(id).style.left;
    oldvalue = oldvalue.replace('px','');
    //alert(oldvalue);
    newvalue = parseInt(oldvalue)+stepvalue;
    ChangeLayerXPos(id,newvalue);
}

//layer Y pozicio valtasa
function ChangeLayerYPos(id, value){
    if (type=="IE") document.all[id].style.top=value;
	if (type=="NN")	document.layer['id'].top=value;
    if (type=="MO" || type=="OP") document.getElementById(id).style.top=value;
}

//layer Y pozicio valtasa relativan
function ChangeLayerYPosByValue(id, stepvalue){
    if (type=="IE") oldvalue = document.all[id].style.top;
    if (type=="NN")	oldvalue = document.layer['id'].top;
    if (type=="MO" || type=="OP") oldvalue = document.getElementById(id).style.top;
    oldvalue = oldvalue.replace('px','');
    newvalue = parseInt(oldvalue)+stepvalue;
    ChangeLayerYPos(id,newvalue);
}

// get the true offset of anything on NS4, IE4/5 & NS6, even if it's in a table!
function getAbsX(elt) { return (elt.x) ? elt.x : getAbsPos(elt,"Left"); }
function getAbsY(elt) { return (elt.y) ? elt.y : getAbsPos(elt,"Top"); }
function getAbsPos(elt,which) {
 iPos = 0;
 while (elt != null) {
  iPos += elt["offset" + which];
  elt = elt.offsetParent;
 }
 return iPos;
}
function getHeight(elt){//magassag
	return elt.offsetHeight;
}
function getWidth(elt){//szelesseg
	return elt.offsetWidth;
}

function OpenFullscreenWindow(target){
//	alert(screen.availWidth);
//	fullscreenWindow = window.open(target);
//	fullscreenWindow = window.open(target, 'fullscreenWindow', 'top=0, left=0');
	fullscreenWindow = window.open(target, 'fullscreenWindow', 'top=0, left=0, status=yes, location=yes, resizable=yes, titlebar=yes, toolbar=yes, menubar=yes, scrollbars=yes');
	fullscreenWindow.resizeTo(screen.availWidth, screen.availHeight);
//	alert(screen.availWidth);
}

function OpenPrintWindow(target){
	fullscreenWindow = window.open(target, 'fullscreenWindow', 'width=560, height=620, top=0, left=0, status=no, location=no, resizable=no, titlebar=yes, toolbar=yes, menubar=yes, scrollbars=yes');
//	fullscreenWindow.resizeTo(560, screen.availHeight);
}

//paf popup kep ablakmegnyito
function openImageWin(targeturl, szeles, magas, kamu){
	fullscreenWindow = window.open(targeturl, 'picWindow', 'width='+szeles+', height='+magas+', top=0, left=0, status=no, location=no, resizable=no, titlebar=yes, toolbar=no, menubar=no, scrollbars=no');
}

//ajanlja ismerosnek ablak
function openAjismWin(targeturl, szeles, magas, kamu){
	fullscreenWindow = window.open(targeturl, 'picWindow', 'width='+szeles+', height='+magas+', top=0, left=0, status=no, location=no, resizable=no, titlebar=yes, toolbar=no, menubar=no, scrollbars=yes');
}


function preLoadImages(){
	var imgSrcs = new Array();

	var imgTags = document.getElementsByTagName('img');
	var tableTags = document.getElementsByTagName('table');
	var tdTags = document.getElementsByTagName('td');

	var numOfImgs = imgTags.length;
	var numOfTables = tableTags.length;
	var numOfTds = tdTags.length;

	for(i = 0; i < numOfImgs; i++){
		imgSrcs[i] = imgTags[i].src;
		imgTags[i].src = 'alapkereso/pics/empty.gif';
	}
	for(i = 0; i < numOfTables; i++){
		imgSrcs[i + numOfImgs] = tableTags[i].background;
		tableTags[i].background = 'alapkereso/pics/empty.gif';
	}
	for(i = 0; i < numOfTds; i++){
		imgSrcs[i + numOfImgs + numOfTables] = tdTags[i].background;
		tdTags[i].background = 'alapkereso/pics/empty.gif';
	}

	var imgObjs = new Array();

	for(var i = 0; i < numOfImgs; i++){
		imgObjs[i] = new Image();
		imgObjs[i].src = imgSrcs[i];
	}
	for(var i = numOfImgs; i < numOfImgs + numOfTables; i++){
		imgObjs[i] = new Image();
		imgObjs[i].background = imgSrcs[i];
	}
	for(var i = numOfImgs + numOfTables; i < numOfImgs + numOfTables + numOfTds; i++){
		imgObjs[i] = new Image();
		imgObjs[i].background = imgSrcs[i];
	}

	for(i = 0; i < numOfImgs; i++){
	      imgTags[i].src = imgObjs[i].src;
	}
	for(i = 0; i < numOfTables; i++){
		tableTags[i].background = imgObjs[i + numOfImgs].background;
	}
	for(i = 0; i < numOfTds; i++){
		tdTags[i].background = imgObjs[i + numOfImgs + numOfTables].background;
	}

}


function CacheImages(imgSrcs){
	var numOfImgs = imgSrcs.length;
	var imgObjs = new Array();

	for(i in imgSrcs){
		imgObjs[i] = new Image();
		imgObjs[i].src = imgSrcs[i];
	}
}

function LTrim( value ) {
	var re = /\s*((\S+\s*)*)/;
	return value.replace(re, "$1");
}

function RTrim( value ) {
	var re = /((\s*\S+)*)\s*/;
	return value.replace(re, "$1");
}

function myTrim( value ) {
	return LTrim(RTrim(value));
}