var version = 0;
if (navigator.appVersion.indexOf("MSIE")!=-1 && navigator.userAgent.indexOf("Opera")==-1) {temp=navigator.appVersion.split("MSIE");version=parseFloat(temp[1])};
// *** push emuláció *** //
function Array_push() {
	var A_p = 0;
	for (A_p = 0; A_p < arguments.length; A_p++) {
		this[this.length] = arguments[A_p];
  	}
	return this.length;
}
if (typeof Array.prototype.push == "undefined") {
	Array.prototype.push = Array_push;
}
// *** end of push emu *** //
// DOM functions
function removeChildrenFromNode(node) {
	if (node === undefined || node === null) {
		return;
	}
	var len = node.childNodes.length;
	while (node.hasChildNodes()) {
		node.removeChild(node.firstChild);
	}
}
// end of DOM functions
var passVar = function(target,vars,args) {
	var target,vars,args;
	//alert(target+", "+vars+", "+args);
	if (window.document[target]) window.document[target].SetVariable(vars, args);
}
var asFunction = function() { // asFunction(<funcion name>,[arg1],[arg2],[arg..n]);
	var a = asFunction.arguments,
		func = a[0],
		args = "";
	for (i=1;i<a.length;i++) {
		args += "|"+a[i];
	}
	passVar("fWindow","pg","run|"+func+args);
}
var initMe = function(me) {
	var me;
	passVar(me,"npr",window.npr);
	passVar(me,"pg",window.p);
	passVar(me,"nsp",window.nsp);
	//alert('html | npr:'+window.npr+' p:'+window.p+' nsp:'+window.nsp);
}
var initFlash = function() {
	initMe("fMenu");
	initMe("fWindow");
}
var setD1 = function(val) {var val; window.d1 = val; passVar("fMenu","d1",val); /*alert("js: d1="+val)*/}
var setD2 = function(val) {var val; window.d2 = val; passVar("fMenu","d2",val); /*alert("js: d2="+val)*/}
var setQM = function(val) {var val; window.qm = val; passVar("fMenu","qm",val); /*alert("js: d2="+val)*/}
var gotoPage = function(pg) {var pg; document.location.href = "main.php?d1="+window.d1+"&d2="+window.d2+"&qm="+window.qm+"&p="+pg;}

var refreshFl = function(target){

	
	
	/*window.document[target].wmode = 'static'
	window.document[target].wMode = 'transparent';
	alert(window.document[target].parentNode.innerHTML);*/
}
var showScrollBar = function(act) {
	var act,
		subpg = document.getElementById("subPage");
	switch (act) {
		case "show" : subpg.style.overflow = 'auto'; subpg.style.overflowX = 'hidden'; window.focus(); break;
		case "hide" : subpg.style.overflow = 'hidden'; break;
	}
	//alert("showScrollBar("+act+")");
}
var swapDepth = function(source,target) {
	var source = document.getElementById(source),
		target = document.getElementById(target),
		tmp    = source.style.zIndex;
	source.style.zIndex = target.style.zIndex;
	target.style.zIndex = tmp;/**/
	
}
var setDepth = function(target,val) {
	var val, target = document.getElementById(target);
	target.style.zIndex = val;
}
var showHTML = function(act) {
	//if (!document.all) {
		var act, textHolder = document.getElementById("textHolder");
		switch (act) {
			case "show" : textHolder.style.display = 'block'; break;
			case "hide" : textHolder.style.display = 'none'; break;
		}
		//alert("showHTML: "+act);
	//}
}/**/
var switchContent = function(mode) { //mode='flash'|'html'
	var mode,
		shdtop = document.getElementById("frameshd_top"),
		shdright = document.getElementById("frameshd_right"),
		mirror = document.getElementById("textMirror");
	showHTML("show");
	if (mode=="flash") {
		setDepth("textHolder",75); setDepth("flashHolder",100); showScrollBar("hide"); //passVar("fWindow","pg",window.p);
		shdtop.style.visibility = 'hidden'; shdright.style.visibility = 'hidden';
		if (!document.all) if (game=document.getElementById('gameHolder')) game.style.display = 'none';
		//textHolder.style.display = 'none';
	} else {
		setDepth("textHolder",100); setDepth("flashHolder",75); showScrollBar("show"); //asFunction("hideAll");passVar("fWindow","pg","hidden");
		shdtop.style.visibility = 'visible'; shdright.style.visibility = 'visible';
		if (!document.all) if (game=document.getElementById('gameHolder')) game.style.display = 'block';
		//textHolder.style.display = 'block';
	}
	//alert("switchContent: "+mode);
}
/*
var showHTML = function(act) {
	var act;
	switch (act) {
		case "show" : switchContent("html"); break;
		case "hide" : switchContent("flash"); break;
	}
	//var act,
	//	text = document.getElementById("textHolder");
	//	shdtop = document.getElementById("frameshd_top");
	//	shdright = document.getElementById("frameshd_right");
	//	mirror = document.getElementById("textMirror");
	//switch (act) {
	//	case "show" : text.style.display = 'block'; mirror.style.display = 'block'; shdtop.style.visibility = 'visible'; shdright.style.visibility = 'visible'; break;
	//	case "hide" : text.style.display = 'none'; mirror.style.display = 'none'; shdtop.style.visibility = 'hidden'; shdright.style.visibility = 'hidden'; break;
	//}
	//
	//alert('showHTML("'+act+'")');
}*/

var showFlash = function(act,runfunc) {
	var act, runfunc;
		//flash = document.getElementById("flashHolder");
		subpg = document.getElementById("subPage");
	switch (act) {
		case "show" : switchContent("flash"); break;
		case "hide" : switchContent("html"); break;
		/*case "show" : flash.style.visibility = 'visible'; subpg.style.overflow = 'hidden'; break;
		case "hide" : flash.style.visibility = 'hidden'; subpg.style.overflow = 'auto'; subpg.style.overflowX = 'hidden'; break;*/
	}
	if (runfunc) runfunc();
	//alert('showFlash("'+act+'", '+runfunc+')');
}
var showHideFlash = function(act) {
	var act;
	switch (act) {
		case "show" : switchContent("flash"); break;
		case "hide" : switchContent("html"); break;
		/*case "show" : showHTML('hide');showFlash('show'); break;
		case "hide" : showHTML('show');showFlash('hide'); break;*/
	}
	//alert('showHideFlash("'+act+'")');
}

var setBg = function(color) {
	var color;
	if (!color) color = "black";
	//textcolor = (color=="yellow") ? "#000000" : "#dfdfdf";
	document.getElementById("leftSide").className="left_"+color;
	document.getElementById("subPage").className=color;
	document.getElementById("textMirror").className=color+"_mir";
}
var neutralize = function() {
	//objectSwap('fMenu','fWindow');
	/*alert(objectSwap);
	delete objectSwap;
	objectSwap = null;
	alert(objectSwap);*/
}
var newFscommand = function(command, args) {
	var args = args.split("|"),astr="";
	for (i=0;i<args.length;i++) {
		sep = (i<args.length-1) ? "," : "";
		astr += "'"+args[i]+"'"+sep;
	}
	eval(command+"("+astr+")");
}
var fMenu_DoFSCommand = function(command, args) {
	newFscommand(command, args);
}
var fWindow_DoFSCommand = function(command, args) {
	newFscommand(command, args);
}
var fGame_DoFSCommand = function(command, args) {
	newFscommand(command, args);
}
var dropShadow = function(target){
	var tid = target;
	d=document;
	target = d.getElementById(tid);
	cname = target.className;
	content = target.innerHTML;
	
	if (!d.targetCopy) {
		d.targetCopy = d.createElement("div");
		d.targetCopy.id = tid+"_copy";
		d.targetCopy.className = cname;
	}
	d.targetCopy.innerHTML = content;
	
	if (!d.targetShadow) {
		d.targetShadow = d.createElement("div");
		d.targetShadow.id = tid+"_shadow";
		d.targetShadow.className = cname+"_shadow";
	}
	d.targetShadow.innerHTML = content;
	
	target.style.visibility = "hidden";
	target.parentNode.appendChild(d.targetShadow);
	target.parentNode.appendChild(d.targetCopy);
	
}
var preLoadImgs = function() {
	var a=preLoadImgs.arguments,d=document; d.img = [];
	for (i=0;i<a.length;i++) {
		d.img[i].src=a[i];
	}
}
document.focused = 'none';
document.blured  = 'none';
var setButtonEvents = function(tagtype) {
	btnArr = document.getElementsByTagName(tagtype);
	for (i=0; i<btnArr.length; i++) {
		var btn = btnArr[i];
		var btnType = btn.type.toLowerCase();
		  if (btnType != 'hidden' && btnType != 'file') {
			btn.emptyval='';
			if (version > 4) {
				btn.cOrig = (btn.className) ? btn.className+" "+btn.className : "";
				btn.fokusz= (btn.className) ? "_focus" : " focus";
				btn.cOver = btn.cOrig+btn.fokusz;
				btn.onmouseout = function(){if (document.focused!=this || document.blured == this) this.className = this.cOrig;}
			}
			btn.onmouseover = function() {if (version > 4) {this.className = this.cOver;} window.boxactive=true;}
			btn.onfocus = function() {
				if (version > 4) {
					document.focused=this;
					this.onmouseover();
					document.blured='none';
					this.className = this.className.replace("err ","");  
					this.style.color='#000000';//hibaszín (piros) helyett visszaáll az alap
				}
				if (this.value=='[az Ön neve]') {
					this.emptyval='[az Ön neve]';
					this.value=''
				} 
				else if (this.value=='[postacíme]') {
					this.emptyval='[postacíme]';
					this.value=''
				} 
				else if (this.value=='[email címe]') {
					this.emptyval='[email címe]';
					this.value=''
				} 
				else if (this.value=='[az üzenet szövege]') {
					this.emptyval='[az üzenet szövege]';
					this.value=''
				} 
				else if (this.value=='[megjegyzés]') {
					this.emptyval='[megjegyzés]';
					this.value=''
				}
				else {
					this.emptyval='';
				}
			}
			btn.onblur = function(){if (version > 4) {document.blured=this; this.onmouseout();} if (this.value=='') this.value=this.emptyval;}

			if (version > 4 && (btnType == 'submit' || btnType == 'reset' || btnType == 'button' || btn.cOrig.indexOf('btn') != -1)) {
				btn.cDown = btn.cOrig+"_down";
				btn.onmousedown = function() {this.className = this.cDown;}
				btn.onfocus = function() {document.focused='none'; document.blured='none'; this.onmouseover();}
				btn.onmouseout = btn.onmouseup = function() {this.className = this.cOrig;}
				btn.onblur = function() {document.focused='none'; document.blured='none'; this.onmouseout();}
			}
		}
	}
}
// ########### Game functions ########### //

var saveRecord = function(ihtml) {
	if (!window.rec) {
		//alert("playername: "+playername);
		testobj = document.getElementById('top10');
		testobj.innerHTML = ihtml;
		dropShadow("leftSide");
		window.rec = true;
		setTimeout(function(){window.rec = false;},2000);
	}
}
var teszt = function() {
	testobj = document.getElementById('top10');
	testobj.innerHTML = "<li>teszt</li>";
	//alert(testobj.innerHTML);
	//removeChildrenFromNode(testobj);
	/*newli = document.createElement('li');
	newtext = document.createTextNode('teszt');
	newli.appendChild(newtext);
	testobj.appendChild(newli);*/
	dropShadow("leftSide");
}
var fscRecord = function(ihtml) {
	saveRecord(ihtml);
}
// ######### End Game functions ######## //
window.onload = function() {
	setButtonEvents('input');
	setButtonEvents('textarea');
	preLoadImgs(
				'pic/subpgbg_black.gif',
				'pic/subpgbg_brown.gif',
				'pic/subpgbg_darkorange.gif',
				'pic/subpgbg_green.gif',
				'pic/subpgbg_orange.gif',
				'pic/subpgbg_red.gif',
				'pic/subpgbg_yellow.gif',
				'pic/subpgbg_black_trans_top.gif',
				'pic/subpgbg_brown_trans_top.gif',
				'pic/subpgbg_darkorange_trans_top.gif',
				'pic/subpgbg_green_trans_top.gif',
				'pic/subpgbg_orange_trans_top.gif',
				'pic/subpgbg_red_trans_top.gif',
				'pic/subpgbg_yellow_trans_top.gif',
				'pic/subpgbg_black_trans_bot.gif',
				'pic/subpgbg_brown_trans_bot.gif',
				'pic/subpgbg_darkorange_trans_bot.gif',
				'pic/subpgbg_green_trans_bot.gif',
				'pic/subpgbg_orange_trans_bot.gif',
				'pic/subpgbg_red_trans_bot.gif',
				'pic/subpgbg_yellow_trans_bot.gif'
				);
}
