////////////////////////////////////////////////////////////////////////////
// zajlik bt. (c) 1999-2006

    // Displays a panel and hides another (only for 2 panel model) 
    function switchPanel(showthis, hidethis){
        // Select appropriate panel
        document.getElementById(showthis).style.display = "inline";
        document.getElementById(hidethis).style.display = "none";
    }
    function showPanel(showthis){
        document.getElementById(showthis).style.display = "inline";
    }
    function hidePanel(hidethis){
        document.getElementById(hidethis).style.display = "none";
    }
    
    function dimUserPass(){
   	 	if(document.getElementById('gamuser').value=="email"){
			document.getElementById('gamuser').value="";
   	 		document.getElementById('gampass').value="";
   	 	}
    }
 
////////////////////////////////////////////////////////////////////////////
// Hide status bar messages
//Hide status bar msg II script- by javascriptkit.com
//Visit JavaScript Kit (http://javascriptkit.com) for script
//Credit must stay intact for use

function hidestatus(){
	window.status='';
	return true;
}
if (document.layers) document.captureEvents(Event.MOUSEOVER | Event.MOUSEOUT);
document.onmouseover=hidestatus;
document.onmouseout=hidestatus;



////////////////////////////////////////////////////////////////////////////
// Foto navigation
   function browseFoto(newsid, fotoid){
   	 http.onreadystatechange = processBrowseFoto;
     http.open('get', 'index.php?fotobrowser=most&newsid='+newsid+'&showfoto='+fotoid);
     http.send(null);
   }	
   function processBrowseFoto(){        
	if(http.readyState == 4){
		// Set the number
		var hirfotores = http.responseText.split("**");
		document.getElementById('hir_full_foto').innerHTML = hirfotores[0];
		document.getElementById('hir_full_foto_nav').innerHTML = hirfotores[1];
		// Recreate object for stupid IE
		if(navigator.appName == "Microsoft Internet Explorer"){
			http = createRequestObject();
		}
	}
   }
////////////////////////////////////////////////////////////////////////////
// Forum related functions
    var globalMessageSaver = new Array();
    var globalMessageID = "";
    var globalReplyID = "";
    function forumLoadQuote(messageid, replyid){
        // If done with all others
        if(globalMessageID == ""){
        	// If this one is already open then hide
        	if(globalMessageSaver[messageid+replyid]){
        		forumHideQuote(messageid, replyid);
        		return;
        	}
        
            // Begin...
            globalReplyID = replyid;
            globalMessageID = messageid;
            // Exchange to 'loading' icon
            globalMessageSaver[globalMessageID+globalReplyID] = document.getElementById('forum-quote-'+globalMessageID+'-'+globalReplyID).innerHTML;            
            document.getElementById('forum-quote-'+globalMessageID+'-'+globalReplyID).innerHTML = "betöltés...";
            // Now load the quote
            forumRequest("forum.php?quote="+replyid+"&orig="+messageid);
        }
    }
    
    function forumShowQuote(){
        if(http.readyState == 4){
            // exchange it
            document.getElementById('forum-quote-'+globalMessageID+'-'+globalReplyID).innerHTML = globalMessageSaver[globalMessageID+globalReplyID]+"<br>"+http.responseText;
            globalMessageID = "";
            globalReplyID = "";
            // Recreate object for stupid IE
            if(navigator.appName == "Microsoft Internet Explorer") http = createRequestObject();
        }
    }

    function forumHideQuote(messageid, replyid){
        // Reset the content and image
        document.getElementById('forum-quote-'+messageid+'-'+replyid).innerHTML = globalMessageSaver[messageid+replyid];
        globalMessageSaver[messageid+replyid] = "";
    }
    
    function forumRequest(action) {
        http.onreadystatechange = forumShowQuote;
        http.open('get', action);
        http.send(null);
    }
    function forumMessageDelete(id, forumid){
    	var res = confirm('biztonsan törölni akarod ezt az üzit?');
    	if(res) window.location = 'gamadmin.php?forum='+forumid+'&messagedelete='+id;
    	else return false;
    }

////////////////////////////////////////////////////////////////////////////
// Shared form submission
	function sharedSearchGo(){
		window.location = "keres.php?keres="+document.getElementById('sharedsearch').value;
	}
	function sharedLoginGo(){
		var qs = "sidebarlogin=true&gamuser="+document.getElementById('gamuser').value+"&gampass="+document.getElementById('gampass').value;
        http.onreadystatechange = sharedLoginResult;
		sendPostRequest("profile.php", qs);
	}
	function sharedLoginResult(){
					if(http.readyState == 4){
						// if error
						if(http.responseText == "okay"){
							if(window.location.search == "?kilep=most") window.location = "index.php";
							else window.location = window.location;
						}
						if(http.responseText == "changepass") window.location = "profile.php?beall=most&beall_jelszo=most";
						if(http.responseText == "error") alert("helytelen user vagy pass!"); 
						
						// Recreate object for stupid IE
						if(navigator.appName == "Microsoft Internet Explorer") http = createRequestObject();
						globalRequestInProgress = false;
					}
	}

////////////////////////////////////////////////////////////////////////////
// Ajax basic functions
function createRequestObject() {
    var ro;
    if (window.ActiveXObject){
        ro = new ActiveXObject("Microsoft.XMLHTTP");
    }else{
        ro = new XMLHttpRequest();
	}
    return ro;
}

var http = createRequestObject();

function handleResponse() {
    if(http.readyState == 4){
        var response = http.responseText;
        var update = new Array();

        if(response.indexOf('|' != -1)) {
            update = response.split('|');
            document.getElementById(update[0]).innerHTML = update[1];
        }
    }
}

function getResponse(){
    if(http.readyState == 4){
        httpResult = http.responseText;
    }
    else{
        httpResult = 0;
    }    
}

////////////////////////////////////////////////////////////////////////////
// Ajax - POST functions
   // sendPostRequest("xyz.php", "asdf=1&sdfsdfk=".encodeURI(asdf.value())); 
   function sendPostRequest(url, parameters) {
      http.open('POST', url, true);
      http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
      http.setRequestHeader("Content-length", parameters.length);
      http.setRequestHeader("Connection", "close");
      http.send(parameters);
   }
   function generatePostQuery(formid){
		var querystring = "absolutelynothing=asdf";
		for(i = 0; i < document.getElementById(formid).length; i++){
			// if the element is a checkbox
			if(document.getElementById(formid).elements[i].type=="checkbox" || document.getElementById(formid).elements[i].type=="radio"){
				// only add if checked
				if(document.getElementById(formid).elements[i].checked){
					querystring = querystring+"&"+document.getElementById(formid).elements[i].name+"="+document.getElementById(formid).elements[i].value;
				}
			}
			else{
				// replace problematic characters
				var qs = document.getElementById(formid).elements[i].value;
				qs = qs.replace(/&/g, "%26");
				qs = qs.replace(/\+/g, "%2b");
				querystring = querystring+"&"+document.getElementById(formid).elements[i].name+"="+qs;
			}
		}
		return querystring;
   }

////////////////////////////////////////////////////////////////////////////
// Ajax - personalized request functions

function sndReq(action) {
    http.onreadystatechange = handleResponse;
    http.open('get', action);
    http.send(null);
}

////////////////////////////////////////////////////////////////////////////
// Below originally from http://www.k10k.net/

// CHECK CLIENT BROWSER & PLATFORM
// Works: IE4+, NS4+, Opera
	var its;
	var browserName = '';
	var browserNameLong = '';
	var browserNew = '';
	var preloadFlag = false;
	var Macintosh = navigator.userAgent.indexOf('Mac')>0;
	browserNaming();

	function its() {
		var n = navigator;
		var ua = ' ' + n.userAgent.toLowerCase();
		var pl = n.platform.toLowerCase();
		var an = n.appName.toLowerCase();
		// browser version
		this.version = n.appVersion;
		this.nn = ua.indexOf('mozilla') > 0;
		// 'compatible' versions of mozilla aren't navigator
		if(ua.indexOf('compatible') > 0) {
			this.nn = false;
		}

		this.opera = ua.indexOf('opera') > 0;
		this.ie = ua.indexOf('msie') > 0;
		this.major = parseInt( this.version );
		this.minor = parseFloat( this.version );
		// platform
		this.mac = ua.indexOf('mac') > 0;
		this.win = ua.indexOf('win') > 0;
		// workaround for IE5 which reports itself as version 4.0
		if(this.ie) {
			if(ua.indexOf("msie 5") > 1) {
			var msieIndex = navigator.appVersion.indexOf("MSIE") + 5;
			this.major = parseFloat(navigator.appVersion.substr(msieIndex,3));
			}
		}
		return this;
	}
	function browserNaming() {
		its = new its();

		// is it a DOM-enabled browser?
		if (!document.getElementById) {
			browserNew = false;
		}
		else {
			browserNew = true;
		}
		// need the name, too
		if (its.opera) {
			browserName = "Opera";
		}
		else if (its.ie) {
			browserName = "IE";
		}
		else {
			browserName = "NS";
		}
		// and the number
		browserNameLong = browserName + its.major;
	}
	
// POPUP WINDOW
// Works: IE4+, NS4+, Opera
// Notes: IE4/IE4.5 for the mac spawns windows 17px too short
	function newWindow(desktopURL,windowName,width,height) {
		if ((Macintosh) && ((browserNameLong == "IE4") || (browserNameLong == "IE4.5"))) {
 			var newheight = parseInt(height + 17);
		}
		else {
			var newheight = height;
		}
		window.open(desktopURL,windowName,'toolbar=0,location=0,directories=0,status=1,menubar=0,scrollbars=1,width='+width+',height='+newheight+',resizable=0');
	}

	function newFixedWindow(desktopURL,windowName,width,height) {
 		window.open(desktopURL,windowName,'toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0,width='+width+',height='+height+',resizable=0');
	}

	
// PRELOADING THE MOUSEOVER IMAGES
// Works: IE4+, NS4+, Opera
	function createObject(imgName,imgSrc) {
		if (loadingFlag) {
			eval(imgName + ' = new Image()');
			eval(imgName + '.src = "' + imgSrc + '"');
			return imgName;
		}
	}

// MOUSEOVER IMAGE SWITCHING
// Works: IE4+, NS4+, Opera
// Notes: NS4 needs the DIV-name in there if image is in a DIV
	function changeImage(layer,imgName,imgObj) {
		if (preloadFlag) {
			if (browserNew) {
				document.getElementById(imgName).src = eval(imgObj+'.src');
			}
			if ((!browserNew) && (browserName == "NS") && (layer!=null)) {
				eval('document.'+layer+'.document.images["'+imgName+'"].src = '+imgObj+'.src');
			}
			else {
				document.images[imgName].src = eval(imgObj+'.src');
			}
		}
	}

// LOAD IFRAME/LAYER
// Works: IE4+, NS6+, Opera
	function load(targetWindow, page) {
		eval('window.'+targetWindow+'.location.href = page');
	}

// SWITCHES BUTTON CLASS
// Works: IE4+, NS6+
	function buttonSwitcher(thisId,param) {
		d = document.getElementById(thisId);
		if (param == "off") {
			d.style.backgroundColor='#78AD1D';
		}
		else {
			d.style.backgroundColor='#FFA800';
		}
	}

// SWITCHES BUTTON TEXT CLASS
// Works: IE4+, NS6+
	function buttonTxtSwitcher(thisId,param) {
		d = document.getElementById(thisId);
		if (param == "off") {
			d.style.backgroundColor='#BCCF9D';
		}
		else {
			d.style.backgroundColor='#FFD82B';
		}
	}

// DOM / GET PROPERTY
// Works: IE5+, NS6+, Opera
	function getIdProperty(id,property) {
		var styleObject = document.getElementById( id );
		if (styleObject != null) {
			styleObject = styleObject.style;
				if (styleObject[property]) {
					return styleObject[ property ];
				}
			}
		return (styleObject != null) ?
		styleObject[property] :
		null;
	}

// DOM / SET PROPERTY
// Works: IE5+, NS6+, Opera
	function setIdProperty(id,property,value) {
		var styleObject = document.getElementById( id );
		if (styleObject != null) {
			styleObject = styleObject.style;
			styleObject[ property ] = value;
		}
	}

// MOVE FUNCTION
// Works: IE5+, NS6+, Opera
	function move(id,xValue,yValue,additive ) {
		var left = parseInt(getIdProperty(id, "left"));
		var top = parseInt(getIdProperty(id, "top"));
		if (additive) {
			setIdProperty(id,"left",left + xValue);
			setIdProperty(id,"top",top + yValue);
		}
		else {
			setIdProperty(id,"left",xValue);
			setIdProperty(id,"top",yValue);
		}
	}

// HIDE AND SHOW LAYERS
// Works: IE4+, NS6+, Opera
	function hide(id) {
		setIdProperty(id,"visibility","hidden");
	}
	function show(id) {
		setIdProperty(id,"visibility","visible");
	}

// CHANGE DISPLAY VALUE FOR LAYERS
// Works: IE4+, NS6+, Opera
	function switchDisplay(id,value) {
		setIdProperty(id,"display",value);
	}

// RANDOM NUMBER GENERATOR
// Works: IE4+, NS4+, Opera
	function randNum (num) {
		var now = new Date();
		var rand = Math.round(num * Math.cos(now.getTime()));
		if (rand < 0) rand = - rand;
		if (rand == 0) rand++;
		return rand;
	}

// ANTI-SPAM
	function antispam(name,domain) {
    	document.location = "mailto:" + name + "@" + domain;
	}

// STATUS
	function s(txt) {
		self.status = txt;
	}
 
// Confirm delete
	function globalConfirm(message, url, idNumber){
   		result = confirm(message);
   		if(result == true){
	    		window.parent.location.href = url + idNumber;
   		}
  	}

// Submit form on enter 
    function submitenter(myfield,e){
            var keycode;
            if (window.event) keycode = window.event.keyCode;
            else if (e) keycode = e.which;
            else return true;

            if(keycode == 13){
               myfield.form.submit();
               return false;
            }
            else return true;
    }
    
// Pause execution
function pause(numberMillis){
	var now = new Date();
	var exitTime = now.getTime() + numberMillis;
	while (true){
		now = new Date();
		if (now.getTime() > exitTime) return;
	}
}

