/*

Reset FrameWork	Common Function Library V2.3

Public variables:

	rfw_opera				// true if the browser is opera
	rfw_ie					// true if the browser is IE
	rfw_ie6					// true if the browser is IE6.0
	rfw_mouseX				// stores the mouse X coord of the page (updated automatically at mousemove event if the eventhandled library is included or if rfw_getMouseCoords(e) is called)
	rfw_mouseY				// stores the mouse Y coord of the page (updated automatically at mousemove event if the eventhandled library is included or if rfw_getMouseCoords(e) is called)
	rfw_scrollX				// stores the X scrollbar offset coord (updated automatically at mousemove event if the eventhandled library is included or if rfw_getScrollCoords() is called)
	rfw_scrollY				// stores the Y scrollbar offset coord (updated automatically at mousemove event if the eventhandled library is included or if rfw_getScrollCoords() is called)
	rfw_pageW				// stores the "inner-width" of the browser (updated automatically at mousemove event if the eventhandled library is included or if rfw_getScreenWidth() is called)
	rfw_pageH				// stores the "inner-height" of the browser (updated automatically at mousemove event if the eventhandled library is included or if rfw_getScreenWidth() is called)
	rfw_pageWES				// stores the "inner-width" of the browser excluding the scrollbars (updated automatically at mousemove event if the eventhandled library is included or if rfw_getScreenWidth() is called)
	rfw_pageHES				// stores the "inner-height" of the browser excluding the scrollbars (updated automatically at mousemove event if the eventhandled library is included or if rfw_getScreenWidth() is called)
	rfw_screenW				// stores the screen-width of the browser (updated automatically at mousemove event if the eventhandled library is included or if rfw_getScreenWidth() is called)
	rfw_screenH				// stores the screen-height of the browser (updated automatically at mousemove event if the eventhandled library is included or if rfw_getScreenWidth() is called)
	rfw_screenAW				// stores the screen-available-width of the browser (updated automatically at mousemove event if the eventhandled library is included or if rfw_getScreenWidth() is called)
	rfw_screenAH				// stores the screen-available-height of the browser (updated automatically at mousemove event if the eventhandled library is included or if rfw_getScreenWidth() is called)
	rfw_dom					// adds a child to a parent or removes a DOM element ( rfw_dom.add([child_object|child_id_string],[parent_object|parent_id_string]) / rfw_dom.remove([element_object|element_id_string]) )

Public functions:

	rfw_allWindowEvents(e)			// e=event	// called by RFW EventHandler

	rfw_getHost(p)				// p=boolean, if we need the port, too	// returns: string, the current host of the browser
	rfw_getPort()				// returns: string, the port of the address (if no port returns null);
	rfw_getHref()				// returns: string, the all location of the browser
	rfw_setHref(u)				// u=string, url
	rfw_getPath()				// returns: string, the path of the document (beginning with /)
	rfw_getProtocol()			// returns: string, the name of the transfer protocol

	rfw_getMouseCoords(e)			// e=event	// returns: true	// sets: rfw_mouseX, rfw_mouseY
	rfw_getScrollCoords()			// returns: true	// sets: rfw_scrollX, rfw_scrollY
	rfw_getScreenWidth()			// returns: true	// sets: rfw_screenW, rfw_screenH, rfw_screenAW, rfw_screenAH

	rfw_toInt(n)				// n=number as string	// returns: integer
	str.rfw_toInt()				// str as string	// returns: integer
	rfw_toString(s)				// s=number as integer or string	// returns: string
	int.rfw_toString()			// int=number as integer		// returns: string
	rfw_getType(o)				// o=object	// returns: string, name of the object's type

	str.rfw_lPad(s,l)			// str=string, s=string to pad with, l=integer, desired length	// returns: string, padded from the left
	str.rfw_rPad(s,l)			// str=string, s=string to pad with, l=integer, desired length	// returns: string, padded from the right

	str.rfw_hex2dec()			// str=string as hexadecimal number	// returns: integer, decimal value
	int.rfw_dec2hex()			// int=integer as decimal number	// returns: string, hexadecimal value in upper case

	rfw_findInArray(a,s)			// a=array, s=string to find	// returns the index as integer;
	rfw_findInArrayString(a,s)		// a=array, s=string to find	// returns the index key as string;
	rfw_printArray(a,br)			// a=array, br=boolean: false=line breaks are \n, true=line breaks are <br>	// returns: string, array content

	rfw_getAttribute(o,a)			// o=object, a=attribute	// returns: string, the attribute of the element/object
	rfw_setAttribute(o,a,v)			// o=object, a=attribute, v=value

	rfw_addEvent(o,type,f)			// o=object, type=event, f=function	// note: FF can't attach new event to object if it's event is already in use!

	rfw_setAlpha(o,v)			// o=object, v=integer as value (0 to 100)
	rfw_stripStyle(st)			// st=string	// returns: string (removes px from the end of input string)
	rfw_getRightPos(o)			// o=object	// returns: string
	rfw_getLeftPos(o)			// o=object	// returns: string
	rfw_getTopPos(o)			// o=object	// returns: string
	rfw_getBottomPos(o)			// o=object	// returns: string
	rfw_getStyle(o,s)			// o=object, s=style property as string	// returns: string, the computed style value of the style property

	rfw_ajax(method,url,postdata,div,code)	// method='GET|POST', url=string, postdata=string as arg1=val1&arg2=val2&arg3=val3, div=string as name of the target div, code=string that will be evaled after the ajax procedure

	rfw_getFlash(movieName)			// movieName=string (name or id of the flash movie)	// returns the flash object

	rfw_rc4(k,d)				// k=key string, d=data string	// return: string, en/decrypted data by the key
	rfw_base64(w,d)				// w='encode|decode', d=data string	// return: string

*/

var rfw_comLibVer=2.3;
var rfw_opera=navigator.appVersion.indexOf('Opera')>=0?true:false;
var rfw_ie = document.all?true:false;
if (!rfw_ie) document.captureEvents(Event.MOUSEMOVE,function(e) { rfw_getMouseCoords(e) },false);
var rfw_ie6=/msie|MSIE 6/.test(navigator.userAgent);
var rfw_mouseCapture=true;
var rfw_mouseX;
var rfw_mouseY;
var rfw_scrollCapture=true;
var rfw_scrollX;
var rfw_scrollY;
var rfw_screenCapture=true;
var rfw_pageW;
var rfw_pageH;
var rfw_screenW;
var rfw_screenH;
var rfw_screenAW;
var rfw_screenAH;
var rfw_XMLhttp=new Array;
var rfw_dom = {
	get: function(el) {
		if(typeof el==='string') {
			return document.getElementById(el);
		} else {
			return el;
		}
	},
	add: function(el,dest) {
		var el=this.get(el);
		var dest=this.get(dest);
		dest.appendChild(el);
	},
	remove: function(el) {
		var el=this.get(el);
		el.parentNode.removeChild(el);
	}
};

/*

var fd4m4=jkdf1()+"."+klrttt()+ploofd(true);
var m43r=klrttt()+ploofd(true);

if(rfw_getHost(false)!=fd4m4 && rfw_getHost(false)!=m43r) {
	alert("a-a, nem ciganykodunk");
	rfw_comLibVer=0;
}


function jkdf1() {
	return "w"+"w"+"w";
}

function klrttt() {
	var athhz=chr(115)+chr(104)+'t'+chr(117)+chr(102)+'f';
	return athhz;
}

function ploofd(d) {
	if(d) {
		return chr(46)+chr(104)+'u';
	}
}

*/

// All-window-event triggered functions

	function rfw_allWindowEvents(e) {
		rfw_getScrollCoords();
		rfw_getMouseCoords(e);
		rfw_getScreenWidth();
	}

// Location related functions

	function rfw_getHost(p) {
		if(p) {
			return location.host;
		} else {
			return location.hostname;
		}
	}

	function rfw_getPort() {
		return location.port;
	}

	function rfw_getHref() {
		return location.href;
	}

	function rfw_setHref(u) {
		return window.location.assign(u);
	}

	function rfw_getPath() {
		return location.pathname;
	}

	function rfw_getProtocol() {
		return location.protocol;
	}

// Coordinates related functions

	function rfw_getMouseCoords(e) {
		if(!rfw_mouseCapture) return false;
		if(!e) var e=window.Event;
		if(rfw_ie) {
			rfw_getScrollCoords();
			rfw_mouseX=event.clientX+rfw_scrollX;
			rfw_mouseY=event.clientY+rfw_scrollY;
		} else {
			rfw_mouseX=e.pageX;
			rfw_mouseY=e.pageY;
		}
		if(rfw_mouseX<0) rfw_mouseX=0;
		if(rfw_mouseY<0) rfw_mouseY=0;
		return true;
	}

	function rfw_getScrollCoords() {
		if(!rfw_scrollCapture) return false;
		if(typeof(window.pageYOffset)=='number') {
			rfw_scrollX=window.pageXOffset;
			rfw_scrollY=window.pageYOffset;
		} else if(document.body && (document.body.scrollLeft || document.body.scrollTop)) {
			rfw_scrollX=document.body.scrollLeft;
			rfw_scrollY=document.body.scrollTop;
		} else if(document.documentElement && (document.documentElement.scrollLeft || document.documentElement.scrollTop)) {
			rfw_scrollX=document.documentElement.scrollLeft;
			rfw_scrollY=document.documentElement.scrollTop;
		} else {
			rfw_scrollX=0;
			rfw_scrollY=0;
		}
		return true;
	}

	function rfw_getScreenWidth() {
		if(!rfw_screenCapture) return false;
		rfw_screenAW=screen.availWidth;
		rfw_screenAH=screen.availHeight;
		rfw_screenW=screen.width;
		rfw_screenH=screen.height;

		if(typeof window.innerWidth != 'undefined') {
			rfw_pageW=window.innerWidth;
			rfw_pageH=window.innerHeight;
		} else if(typeof document.documentElement != 'undefined' && typeof document.documentElement.clientWidth !='undefined' && document.documentElement.clientWidth != 0) {
			rfw_pageW=document.documentElement.clientWidth;
			rfw_pageH=document.documentElement.clientHeight;
		} else {
			rfw_pageW=document.getElementsByTagName('body')[0].clientWidth;
			rfw_pageH=document.getElementsByTagName('body')[0].clientHeight;
		}

		if(window.innerWidth==undefined) {
			rfw_pageWES=document.documentElement.clientWidth;
		} else {
                	rfw_pageWES=window.innerWidth;
		}
            
		if(window.innerHeight==undefined) {
			rfw_pageHES=document.documentElement.clientHeight;
		} else {
			rfw_pageHES=window.innerHeight;
		}

		return true;
	}

	function rfw_getDocHeight() {
		return Math.max(
			Math.max(document.body.scrollHeight, document.documentElement.scrollHeight),
			Math.max(document.body.offsetHeight, document.documentElement.offsetHeight),
			Math.max(document.body.clientHeight, document.documentElement.clientHeight)
		);
	}

	function rfw_getDocWidth() {
		return Math.max(
			Math.max(document.body.scrollWidth, document.documentElement.scrollWidth),
			Math.max(document.body.offsetWidth, document.documentElement.offsetWidth),
			Math.max(document.body.clientWidth, document.documentElement.clientWidth)
		);
	}
	

// Type related functions

	function rfw_toInt(n) {
		n=rfw_toString(n);
		if(n.length==0) return 0;
		return parseInt(parseFloat(n));
	}

	function rfw_toString(s) {
		return ''+s+'';
	}

	String.prototype.rfw_toInt=function() {
		var str=this;
		return rfw_toInt(str);
	};

	Number.prototype.rfw_toString=function() {
		var i=this;
		return rfw_toString(i);
	};

	function rfw_getType(o) {
		return typeof(o);
	}

// String related functions

	String.prototype.rfw_lPad=function(s,l) {
		var str=this;		
		while(str.length<l) { str=s+str; }
		return str;
	};
 
	String.prototype.rfw_rPad=function(s,l) {
		var str=this;
		while(str.length<l) str+=s;
		return str;
	};

	function chr(i) {
		return String.fromCharCode(i);
	}

// Number related function

	String.prototype.rfw_hex2dec=function() {
		return parseInt(this.toLowerCase(),16);
	};

	Number.prototype.rfw_dec2hex=function() {
		return Math.round(this).toString(16).toUpperCase();
	};

// Array related functions

	function rfw_findInArray(a,s) {
		for(i=0; i<a.length; i++) {
			if(a[i]==s) return i;
		}
		return false;
	}

	function rfw_findInArrayString(a,s) {
		for(i in a) {
			if(a[i]==s) return i;
		}
		return false;
	}

	function rfw_alertArray(a) {
		alert(rfw_printArray(a,false));
	}

	function rfw_printArray(a,br) {
		var v=rfw_getArrayValues(a,true,false,0);
		if(br) { v=v.replace(/\n/g,'<br>'); v=v.replace(/ /g,'&nbsp;'); }
		return v;
	}			

	function rfw_getArrayValues(a,r,ra,t) {
		var tabs='';
		for(i=0;i<t;i++) tabs+='        ';
		if(ra) var arrayItems=new Array();
		if(!ra) var arrayItems="";
		if(a.constructor==Array) {
			for(i in a) {
				if(r) {
					if(a[i].constructor==Array) {
						if(ra) arrayItems.push(rfw_getArrayValues(a[i],true,true,0));
						if(!ra) {
							arrayItems+=tabs+'['+i+'] => Array {\n';
							arrayItems+=''+rfw_getArrayValues(a[i],true,false,t+1);
							arrayItems+=tabs+'}\n';
						}
					} else {
						if(!ra) arrayItems+=tabs+'['+i+'] => '+a[i]+'\n';
					}
				}				
			}
		}
		return arrayItems;
	}

// Element related functions

	function rfw_getAttribute(o,a) {
		try {
			if(rfw_opera) var v=eval("o."+a);
			else var v=o.getAttribute(a);
			return v;
		} catch(err) {
			return null;
		}
	}

	function rfw_setAttribute(o,a,v) {
		o.setAttribute(a,v);
	}

// Event related functions

	function rfw_addEvent(o,type,f) {
		if(o.attachEvent) {
			o['e'+type+f]=f;
			o[type+f]=function(){o['e'+type+f](window.event);};
			o.attachEvent('on'+type,o[type+f]);
		} else {
			o.addEventListener(type,f,true);
		}
	}

// Style related functions

	function rfw_setAlpha(o,v) {
			v=rfw_toInt(v);
			o.style.MozOpacity=v/100;
			o.style.filter="alpha(opacity="+v+")";
			o.style.opacity=v/100;
	}

	function rfw_stripStyle(st) {
		if(st.substring(st.length-2)=='px') {
			return st.substring(0,st.length-2);
		} else {
			return st;
		}
	}

	function rfw_getRightPos(o) {
		var r=o.offsetLeft + o.offsetWidth;
		while((o=o.offsetParent)!=null) {
			if(o.tagName!='HTML') r+=o.offsetLeft;
		}
		return r;
	}

	function rfw_getBottomPos(o) {
		var r=o.offsetTop + o.offsetHeight;
		while((o=o.offsetParent)!=null) {
			if(o.tagName!='HTML') r+=o.offsetTop;
		}
		return r;
	}

	function rfw_getTopPos(o) {
		var r=o.offsetTop;
		while((o=o.offsetParent)!=null) {
			if(o.tagName!='HTML') r+=o.offsetTop;
		}
		return r;
	}
	
	function rfw_getLeftPos(o) {
		var r=o.offsetLeft;
		while((o=o.offsetParent)!=null) {
			if(o.tagName!='HTML') r+=o.offsetLeft;
		}
		return r;
	}

	function rfw_getStyle(o,s) {
		var st='';
		if(document.defaultView && document.defaultView.getComputedStyle) {
			st=document.defaultView.getComputedStyle(o,'').getPropertyValue(s);
		} else if(o.currentStyle) {
			s=s.replace(/\-(\w)/g,function(strMatch,p1) { return p1.toUpperCase(); });
			st=o.currentStyle[s];
		}
		if(st.match(/rgb\(([0-9]*?),\s*?([0-9]*?),\s*?([0-9]*?)\)/gi)) {
			st=st.replace(/rgb\(([0-9]*?),\s*?([0-9]*?),\s*?([0-9]*?)\)/gi,rfw_getStyleColorReplace);
		}
		return st;
	}

	function rfw_getStyleColorReplace(m,r,g,b) {
		return rfw_getStyleColorDecHex(r)+rfw_getStyleColorDecHex(g)+rfw_getStyleColorDecHex(b);
	}

	function rfw_getStyleColorDecHex(d) {
		return Number(d).toString(16).toUpperCase().rfw_lPad('0',2);
	}

// Ajax related functions

	function rfw_ajax(method,url,postdata,div,code) {
		var i=rfw_XMLhttp.length+1;

		if (window.XMLHttpRequest) {
			rfw_XMLhttp[i]=new XMLHttpRequest();
		} else if(window.ActiveXObject) {
			rfw_XMLhttp[i]=new ActiveXObject('Microsoft.XMLHTTP');
		}

		var randstuff=Math.floor(Math.random()*1000000000);	

		if(url.match(/\?/)) url=url+"&randstuff="+randstuff;
		if(!url.match(/\?/)) url=url+"?randstuff="+randstuff;

		if(typeof(rfw_XMLhttp[i])=='object') {
			if(method=='GET') rfw_XMLhttp[i].open('GET',url,true);
			if(method=='POST') {
				rfw_XMLhttp[i].open('POST',url,true);
				rfw_XMLhttp[i].setRequestHeader("Content-type","application/x-www-form-urlencoded");
				rfw_XMLhttp[i].setRequestHeader("Content-length",postdata.length);
				rfw_XMLhttp[i].setRequestHeader("Connection","close");
			}
			rfw_XMLhttp[i].onreadystatechange=function() {
				if((rfw_XMLhttp[i].readyState==4) || (rfw_XMLhttp[i].readyState=="complete")) {
					var data=rfw_XMLhttp[i].responseText;
					if(data.match(/error/) || data.match(/notice/) || data.match(/>warning/)) {
						alert(data);
					} else {
						if(div.length>0) {
							try {
								document.getElementById(div).innerHTML=data;
							} catch(err) {
								alert("ERROR rfw_ajax: can't access DIV ["+div+"]");
							}
						} else {
							try {
								eval(data);
							} catch(err) {
								// rfw_ajax(method,url,postdata,div,code)
								alert("ERROR: "+err.description + "\n\n");
							}
						}
					}
					try {
						eval(code);
					} catch(err) {
						alert("ERROR: "+err.description+"\n\n");
					}
				}
			}
			if(method=='GET') rfw_XMLhttp[i].send(null);
			if(method=='POST') rfw_XMLhttp[i].send(postdata);
		}
	}

// Flash related functions 

	function rfw_getFlash(movieName) {
        	if(navigator.appName.indexOf("Microsoft")!=-1) {
			return window[movieName];
		} else {
			return document[movieName];
		}
	}


// Time related functions

	function rfw_ms2time(t) {
		var h=Math.floor(t/3600000)+"";
		if(h.length==1) h="0"+h;
		var m=Math.floor((t-h*3600000)/60000)+"";
		if(m.length==1) m="0"+m;
		var s=Math.floor((t-h*3600000-m*60000)/1000)+"";
		if(s.length==1) s="0"+s;
		return h+":"+m+":"+s;
	}


// Cookie related functions
	function rfw_getCookie(cn) {
		if(document.cookie.length>0) {
			cstart=document.cookie.indexOf(cn+'=');
			if(cstart!=-1) {
				cstart=cstart+cn.length+1;
				cend=document.cookie.indexOf(";",cstart);
				if(cend==-1) cend=document.cookie.length;
				return unescape(document.cookie.substring(cstart,cend));
			}
		}
		return false;
	}

	function rfw_setCookie(cn,value,expiredays) {
		var exdate=new Date();
		exdate.setDate(exdate.getDate()+expiredays);
		document.cookie=cn+'='+escape(value)+((expiredays==null)?'':';expires='+exdate.toUTCString());
	}


// En/DeCryption related functions



	function rfw_base64(w,d) {
		var b64_map='ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=';
		var i,byte1,byte2,byte3;
		var ch1,ch2,ch3,ch4;
		var result=new Array();
		var j=0;
		if(w=='encode') {
			if(typeof(btoa)=='function') return btoa(d);
			for (i=0;i<d.length;i+=3) {
				byte1=d.charCodeAt(i);
				byte2=d.charCodeAt(i+1);
				byte3=d.charCodeAt(i+2);
				ch1=byte1>>2;
				ch2=((byte1&3)<<4)|(byte2>>4);
				ch3=((byte2&15)<<2)|(byte3>>6);
				ch4=byte3&63;
				if(isNaN(byte2)) {
					ch3=ch4=64;
				} else if(isNaN(byte3)) {
					ch4 = 64;
				}
				result[j++]=b64_map.charAt(ch1)+b64_map.charAt(ch2)+b64_map.charAt(ch3)+b64_map.charAt(ch4);
			}
		}
		if(w=='decode') {
			d=d.replace(/[^a-z0-9\+\/=]/ig,'');
			if(typeof(atob)=='function') return atob(d);
			while((d.length%4)!=0) d+='=';
			for(i=0;i<d.length;i+=4) {
				ch1=b64_map.indexOf(d.charAt(i));
				ch2=b64_map.indexOf(d.charAt(i+1));
				ch3=b64_map.indexOf(d.charAt(i+2));
				ch4=b64_map.indexOf(d.charAt(i+3));
				byte1=(ch1<<2)|(ch2>>4);
				byte2=((ch2&15)<<4)|(ch3>>2);
				byte3=((ch3&3)<<6)|ch4;
				result[j++]=String.fromCharCode(byte1);
				if(ch3!=64) result[j++]=String.fromCharCode(byte2);
				if(ch4!=64) result[j++]=String.fromCharCode(byte3);	
			}
		}	
		return result.join('');
	}

