/**
 * This is SmallNSmart CMS for BurninGames.hu
 * 2003-2008
 * Developed By Koller József (OroszNyet)
 * web: http://www.burningames.hu 
 * mail: orosznyet@gmail.com
 * 
 * THIS CMS IS NOT SHAREABLE
**/
function capsLock(event){
	kc = event.keyCode?event.keyCode:event.which;
	sk = event.shiftKey?event.shiftKey:((kc == 16) ? true : false);
	if(((kc >= 65 && kc <= 90) && !sk)||((kc >= 97 && kc <= 122) && sk)) {
		return false;
	} else {
		return true;
	}
}

function setFocus(id){
	document.getElementById(id).focus();
}
    
function changeBox(whatwant ,objectID) {
	document.getElementById(objectID).innerHTML = whatwant;
}

function changeClass(whatwant ,objectID) {
	document.getElementById(objectID).className = whatwant;
}


var WindowWidth = 0, WindowHeight = 0;
if( typeof( window.innerWidth ) == "number") {
	//Non-IE
	WindowWidth = window.innerWidth;
	WindowHeight = window.innerHeight;
} else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
	//IE 6+ in 'standards compliant mode'
	WindowWidth = document.documentElement.clientWidth;
	WindowHeight = document.documentElement.clientHeight;
} else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
	//IE 4 compatible
	WindowWidth = document.body.clientWidth;
	WindowHeight = document.body.clientHeight;
}

// This script From PHP-Fusion
//modified by wooya
function addText(elname, strFore, strAft, formname) {
	if (formname == undefined) formname = "inputform";
	if (elname == undefined) elname = "message";
	element = document.forms[formname].elements[elname];
	element.focus();
	// for IE 
	if (document.selection) {
		var oRange = document.selection.createRange();
		var numLen = oRange.text.length;
		oRange.text = strFore + oRange.text + strAft;
		return false;
	// for FF and Opera
	} else if (element.setSelectionRange) {
		var selStart = element.selectionStart, selEnd = element.selectionEnd;
		var oldScrollTop = element.scrollTop;
		element.value = element.value.substring(0, selStart) + strFore + element.value.substring(selStart, selEnd) + strAft + element.value.substring(selEnd);
		element.setSelectionRange(selStart + strFore.length, selEnd + strFore.length);
		element.scrollTop = oldScrollTop;
		element.focus();
	} else {
		var oldScrollTop = element.scrollTop;
		element.value += strFore + strAft;
		element.scrollTop = oldScrollTop;
		element.focus();
	}
	return false;
}

// This script From PHP-Fusion
//modified by Wooya
function insertText(elname, what, formname) {
	if (formname == undefined) formname = "inputform";
	if (document.forms[formname].elements[elname].createTextRange) {
		document.forms[formname].elements[elname].focus();
		document.selection.createRange().duplicate().text = what;
	// for Mozilla
	} else if ((typeof document.forms[formname].elements[elname].selectionStart) != 'undefined') {
		var tarea = document.forms[formname].elements[elname];
		var selEnd = tarea.selectionEnd;
		var txtLen = tarea.value.length;
		var txtbefore = tarea.value.substring(0,selEnd);
		var txtafter =  tarea.value.substring(selEnd, txtLen);
		var oldScrollTop = tarea.scrollTop;
		tarea.value = txtbefore + what + txtafter;
		tarea.selectionStart = txtbefore.length + what.length;
		tarea.selectionEnd = txtbefore.length + what.length;
		tarea.scrollTop = oldScrollTop;
		tarea.focus();
	} else {
		document.forms[formname].elements[elname].value += what;
		document.forms[formname].elements[elname].focus();
	}
	return false;
}

function show_hide(msg_id) {
	if (document.getElementById(msg_id).style.display == "none") {
		document.getElementById(msg_id).style.display = "block";
	} else {
		document.getElementById(msg_id).style.display = "none";
	}
	
}

/**
	This script and many more are available free online at
	The JavaScript Source!! http://javascript.internet.com
	V1.1.3: Sandeep V. Tamhankar (stamhankar@hotmail.com)
	Original:  Sandeep V. Tamhankar (stamhankar@hotmail.com)
	
	Customized and Error Alert boxs removed by Orosznyet
**/
function emailCheck (emailStr) {
	var checkTLD = 1;
	var knownDomsPat=/^(com|net|org|edu|int|mil|gov|arpa|biz|aero|name|coop|info|pro|museum)$/;
	var emailPat=/^(.+)@(.+)$/;
	var specialChars="\\(\\)><@,;:\\\\\\\"\\.\\[\\]";
	var validChars="\[^\\s" + specialChars + "\]";
	var quotedUser="(\"[^\"]*\")";
	var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/;
	var atom=validChars + '+';
	var word="(" + atom + "|" + quotedUser + ")";
	var userPat=new RegExp("^" + word + "(\\." + word + ")*$");
	var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$");
	var matchArray=emailStr.match(emailPat);
	if (matchArray==null) {
		return false;
	}
	var user=matchArray[1];
	var domain=matchArray[2];
	
	for (i=0; i<user.length; i++) {
		if (user.charCodeAt(i)>127) {
			return false;
		}
	}
	
	for (i=0; i<domain.length; i++) {
		if (domain.charCodeAt(i)>127) {
			return false;
		}
	}
	
	if (user.match(userPat)==null) {
		return false;
	}

	var IPArray=domain.match(ipDomainPat);
	if (IPArray!=null) {
		for (var i=1;i<=4;i++) {
			if (IPArray[i]>255) {
				return false;
			}
		}
		return true;
	}

	var atomPat=new RegExp("^" + atom + "$");
	var domArr=domain.split(".");
	var len=domArr.length;
	
	for (i=0;i<len;i++) {
		if (domArr[i].search(atomPat)==-1) {
			return false;
		}
	}
	
	if (checkTLD && domArr[domArr.length-1].length!=2 && domArr[domArr.length-1].search(knownDomsPat)==-1) {
		return false;
	}
	
	if (len<2) {
		return false;
	}
	return true;
}

/**
 Like isNum()
 check the sting is a number
**/
function isInt (str) {
	var i = parseInt (str);
	if (isNaN (i)) {
		return false;
	}	
	i = i . toString ();
	if (i != str) {
		return false;
	}
	return true;
}
/**
 Like hq_alfaNum()
 Check text is Apha numerical...
**/
function alphanumeric(alphane) {
	var regex = /^[-0-9A-Z_@\s]+$/i;
	if(regex.test(alphane)){
		return true;
	} else {
		return false;
	}
}

/**
  * Modified by Wooya to work properly with Opera
**/
function correctPNG() {
   // correctly handle PNG transparency in Win IE 5.5 or higher.
   if (navigator.appName=="Microsoft Internet Explorer" && navigator.userAgent.indexOf("Opera")==-1) {
      for(var i=0; i<document.images.length; i++) {
         var img = document.images[i]
         var imgName = img.src.toUpperCase()
         if (imgName.substring(imgName.length-3, imgName.length) == "PNG") {
            var imgID = (img.id) ? "id='" + img.id + "' " : ""
            var imgClass = (img.className) ? "class='" + img.className + "' " : ""
            var imgTitle = (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' "
            var imgStyle = "display:inline-block;" + img.style.cssText
            if (img.align == "left") imgStyle = "float:left;" + imgStyle
            if (img.align == "right") imgStyle = "float:right;" + imgStyle
            if (img.parentElement.href) imgStyle = "cursor:hand;" + imgStyle
            var strNewHTML = "<span " + imgID + imgClass + imgTitle
            + " style=\"" + "width:" + img.width + "px; height:" + img.height + "px;" + imgStyle + ";"
            + "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
            + "(src=\'" + img.src + "\', sizingMethod='scale');\"></span>"
            img.outerHTML = strNewHTML
            i = i-1
         }
      }
   }
}

function GetOffset (LayerID, Align){
	var TotalOffset = ((Align == "left") ? LayerID.offsetLeft : LayerID.offsetTop);
	var ParentOffset = LayerID.offsetParent;
	while (ParentOffset != null) {
		if(ParentOffset.style.position != "relative"){
			TotalOffset = ((Align == "left") ? (TotalOffset + ParentOffset.offsetLeft) : (TotalOffset + ParentOffset.offsetTop));
		}
		ParentOffset = ParentOffset.offsetParent;
	}
	return TotalOffset;
}

function Overlay(Compare, BoxId,RemoveWith) {
	var TargetBox = document.getElementById(BoxId);
	TargetBox.style.display = (TargetBox.style.display != "block") ? "block" : "none";
	var LeftOffset = GetOffset(Compare, "left");
	if ((LeftOffset + 400) < WindowWidth) {
		TargetBox.style.left = LeftOffset + "px";
	} else {
		TargetBox.style.left = (LeftOffset-RemoveWith) + "px";
	}
	TargetBox.style.top  = (GetOffset(Compare, "top") + 25) + "px";
	return false;
}

function HideOverlay (BoxId) {
	document.getElementById(BoxId).style.display = "none";
	return false;
}

var NewPopUp = null;
function PopupWin(URL, Width, Height) {
	if (NewPopUp != null) {
		NewPopUp.close();
		NewPopUp = null;
	}
	NewPopUp = window.open(URL, "","toolbar=no,menubar=no,location=no,personalbar=no,scrollbars=yes,status=no,directories=no,resizable=yes,height=" + Height + ",width=" + Width);
	NewPopUp.focus();
}

function ImgSrc(NewUrl,ImgId) {
	var Img = document.getElementById(ImgId);
	Img.src = NewUrl;
}

/**
* original script from: http://www.xtractpro.com/articles/Animated-Collapsible-Panel.aspx
**/
var currentContent = null;
function AniToggle (content, interval, step) {
    // wait for another animated expand/collapse action to end
    if (currentContent==null) {
        currentContent = content;
        var expand = (content.style.display == "none");
        if (expand) {
			content.style.display = "block";
		}
        var max_height = content.offsetHeight;

        var step_height = step + (expand ? 0 : -max_height);
        //if (image != "undefined") { AniToggleIcon(image); }
                
        // schedule first animated collapse/expand event
        content.style.height = Math.abs(step_height) + "px";
        setTimeout("DoAnimToggle("
            + interval + "," + step
            + "," + max_height + "," + step_height + ")", interval);
    }
}

function parsebytesize (size) {
	var kb = 1024;
	var mb = 1024 * kb;
	var gb = 1024 * mb;
	var tb = 1024 * gb;
	var vReturn = "";
	if (size == 0) { vReturn = "Üres"; }
	else if (size < kb) { vReturn = size + " " + (size > 1 ? "Bájt" : "Bájt"); }
	else if (size < mb) { vReturn = Math.round(size / kb) + " " + "Kb"; }
	else if (size < gb) { vReturn = Math.round(size / mb) + " " + "Mb"; }
	else if (size < tb) { vReturn = Math.round( size/ gb) + " " + "Gb"; }
	else { vReturn = Math.round(size / tb) + " " + "Tb"; }
	
	return " ~ " + vReturn;
}


Scroller = {
	// control the speed of the scroller.
	// dont change it here directly, please use Scroller.speed=50;
	speed:10,

	// returns the Y position of the div
	gy: function (d) {
		gy = d.offsetTop
		if (d.offsetParent) while (d = d.offsetParent) gy += d.offsetTop
		return gy
	},

	// returns the current scroll position
	scrollTop: function (){
		body=document.body
	    d=document.documentElement
	    if (body && body.scrollTop) return body.scrollTop
	    if (d && d.scrollTop) return d.scrollTop
	    if (window.pageYOffset) return window.pageYOffset
	    return 0
	},

	// attach an event for an element
	// (element, type, function)
	add: function(event, body, d) {
	    if (event.addEventListener) return event.addEventListener(body, d,false)
	    if (event.attachEvent) return event.attachEvent('on'+body, d)
	},

	// kill an event of an element
	end: function(e){
		if (window.event) {
			window.event.cancelBubble = true
			window.event.returnValue = false
      		return;
    	}
	    if (e.preventDefault && e.stopPropagation) {
	      e.preventDefault()
	      e.stopPropagation()
	    }
	},
	
	// move the scroll bar to the particular div.
	scroll: function(d){
		i = window.innerHeight || document.documentElement.clientHeight;
		h=document.body.scrollHeight;
		a = Scroller.scrollTop()
		if(d>a)
			if(h-d>i)
				a+=Math.ceil((d-a)/Scroller.speed)
			else
				a+=Math.ceil((d-a-(h-d))/Scroller.speed)
		else
			a = a+(d-a)/Scroller.speed;
		window.scrollTo(0,a)
	  	if(a==d || Scroller.offsetTop==a)clearInterval(Scroller.interval)
	  	Scroller.offsetTop=a
	},
	// initializer that adds the renderer to the onload function of the window
	init: function(){
		Scroller.add(window,'load', Scroller.render)
	},

	// this method extracts all the anchors and validates then as # and attaches the events.
	render: function(){
		a = document.getElementsByTagName('a');
		Scroller.end(this);
		window.onscroll
	    for (i=0;i<a.length;i++) {
	      l = a[i];
	      if(l.href && l.href.indexOf('#') != -1 && ((l.pathname==location.pathname) || ('/'+l.pathname==location.pathname)) ){
	      	Scroller.add(l,'click',Scroller.end)
	      		l.onclick = function(){
	      			Scroller.end(this);
		        	l=this.hash.substr(1);
		        	 a = document.getElementsByTagName('a');
				     for (i=0;i<a.length;i++) {
				     	if(a[i].name == l){
				     		clearInterval(Scroller.interval);
				     		Scroller.interval=setInterval('Scroller.scroll('+Scroller.gy(a[i])+')',10);
						}
					}
				}
	      	}
		}
	}
}
// invoke the initializer of the scroller
//Scroller.init();