<!--

	/**
	 * @author: Icarus
	 * @description: Main Functions
	 * @version: 0.2
	**/

	function getEl(element){
		return eval("document.getElementById(element)");
	}

	/**
	 * @access public
	 * @description: writes email addresses from string parts
	 * @params: strpart : array(object) of string parts of the email address, obj : if we use it for link
	 * @usage:
	 *	<a href="" onmouseover="write_email(['ema','il@por','tal.','com'],this)"><script> write_email(['ema','il@por','tal.','com'],null); </script></a>
  **/

	function write_email(strparts,obj){
	 	if (obj==null) {
			for (i=0;i<strparts.length;i++) {
				document.write(strparts[i]);
			}
	  } else {
			var mail = "";
			for (i=0;i<strparts.length;i++) {
				mail += strparts[i];
			}
			obj.href=('mai'+'lto:'+mail);
	  }
	}

	/**
	 * @access public
	 * @description: submits the form when enter has been pressed.
	 * @params: field : in which field the event has happened in, e : event object
	 * @usage: onKeyPress="return submitEnter(this,event);"
  **/

	function submitEnter(field,e)
	{
		var keycode;
		if (window.event) keycode = window.event.keyCode;
		else if (e) keycode = e.which;
		else return true;

		if (keycode == 13)
		   {
			   field.form.submit();
			   return false;
		   }
		else
		   return true;
	}

	/**
	 * @access public
	 * @description: Opens a popup window with given parameters
	 * @params: name,file,width,height
	 *					scrollbar,resizable,modal (true/false)
  **/

	function popup(name,file,width,height,scrollbar,resizable,modal) {
		wLeft=(screen.width)?(screen.width-width)/2:100;
		wTop=(screen.height)?(screen.height-height)/2:100;
		childWindow=window.open(file,name,"modal=yes,width="+width+"px,height="+height+"px,scrollbars="+scrollbar+",resizable="+resizable+",top="+wTop+",left="+wLeft);
		if (childWindow.opener == null) childWindow.opener = self;
			childWindow.focus();
	}

		function resize(el) {
			var w=document.getElementById(el).width;
			var h=document.getElementById(el).height;
			if( window.innerWidth ) { mW = 8; mH = 80; } else { mW = 0; mH = 0 }
			w=w+mW; h=h+mH;
			window.resizeTo( w,h );

			/*var mW = 0, mH = 0, d = window.document.documentElement, b = window.document.body;
			if( window.innerWidth ) { mW = window.innerWidth; mH = window.innerHeight; }
			else if( d && d.clientWidth ) { mW = d.clientWidth; mH = d.clientHeight; }
			else if( b && b.clientWidth ) { mW = b.clientWidth; mH = b.clientHeight; }
			//Opera 6- adds on 16 pixels for the non-existent scrollbar
			if( window.opera && !document.childNodes ) { mW += 16; }
			window.resizeTo( w + ((w)-mW),h+((h)-mH) );*/
		}


	/**
	 * @access public
	 * @description: preload rollover images
	**/

	function preloadImages() {
	  var d=document; if(d.images){ if(!d.ps) d.ps=new Array();
		var i,j=d.ps.length,a=preloadImages.arguments; for(i=0; i<a.length; i++)
		if (a[i].indexOf("#")!=0){ d.ps[j]=new Image; d.ps[j++].src=a[i];}}
	}

	/**
	 * @access public
	 * @description: submit form
	 * @params: formId : id of the form element
	 **/

	function submitForm(formId){
		formEl = document.getElementById(formId);
		formEl.submit();
	}

	/**
	 * @access public
	 * @description: checks whether form elements are filled out and valid & submit the form
	 * @params: formEl : form element
	 * @validate
	**/

	function checkForm(formId) {
		formEl = document.getElementById(formId);
		for (i=0;i<formEl.elements.length; i++ ) {
			el = formEl.elements[i];
			if ( el.type == "text") {
				if ( el.value == "" ) {
					alert("Minden mezőt ki kell tölteni!"); return;
				} else {
					if (el.name.search(/email/) != -1) {
					 var emailExp = /^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i;
					 if ( emailExp.test(el.value) == false ) { alert ("Az email cím formátuma nem megfelelő!"); return }  ;
					}
				}
			}
		}
		formEl.submit();
	}

	function trim12 (str) {
		var	str = str.replace(/^\s\s*/, ''),
		ws = /\s/,
		i = str.length;
		while (ws.test(str.charAt(--i)));
		return str.slice(0, i + 1);
	}


	/* AJAX */

	var request = false;
	/*@cc_on @*/
	/*@if (@_jscript_version >= 5)
		try {
			request = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try {
				request = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e2) {
				request = false;
			}
		}
	@end @*/

	//if (!request && typeof XMLHttpRequest != 'undefined') {
		//request = new XMLHttpRequest();
	//}

	/* starts an ajax request with the given parameters and calls the callback function */
	function startRequest(appName,callBack,paramNames,paramValues) {
		var url = "ajax/"+appName+".php?";
		if (typeof(paramNames) == "object") {
			for (var i=0;i<paramNames.length;i++) {
				url += "&" + paramNames[i] + "=" + escape(paramValues[i]);
			}
		}
		if (typeof(paramNames) == "string") {
			url += "&" + paramNames + "=" + escape(paramValues);
		}
		request.open("GET", url, true);
		request.onreadystatechange = eval(callBack);
		request.send(null);
	}

	/** ********************************************************************** **/

	var references = new Array();
	var sumImages = null;

	function preloadReferences(){
		for (var i=0; i<references.length; i++) {
			var values = references[i].split('|');
			var image = new Image();
			image.src = "references/"+values[0]+"/"+values[1]+"/large_"+values[2];
			var image = new Image();
			image.src = "references/"+values[0]+"/"+values[1]+"/small_"+values[2];
		}
	}

	/* parse the ajax request's response string */
	function getReferences() {
		if (request.readyState == 4) {
			if (request.status == 200) {
				var response = request.responseText;
				references=response.split('&');
				preloadReferences();
				loadImages(0);
			 }
		}
	}

	/* clears image placeholders and loads in the new images  */
	function loadImages(start){

	 for (var i=0; i<4; i++) {
		index = Math.abs((i+sumImages-start)%sumImages);

		var values = references[index].split('|');

		if (i == 0) {
			var lgImg = getEl("large_img");
			var refTitle = getEl("ref_title");
			var refText = getEl("ref_text");
			lgImg.src = "references/"+values[0]+"/"+values[1]+"/large_"+values[2];
			lgImg.parentNode.className = lgImg.parentNode.className.replace("hidden", "");
			refTitle.innerHTML = values[3];
			refText.innerHTML = values[4];
		} else {
			var smImg = getEl("small_img"+[i]);
			smImg.src = "references/"+values[0]+"/"+values[1]+"/small_"+values[2];
			smImg.parentNode.className = smImg.parentNode.className.replace(" hidden", "");
		}
	 }
	}

	/* start get reference ajax call, and call back getReferences to parse the response */
	function loadReferences(cat_id,sum_img) {
		sumImages = sum_img;
		var params = "cat_id";
		var paramvals = cat_id;
		startRequest("ajax_get_references","getReferences",params,paramvals);
	}

	function onLoad() {
		preloadImages('');
		for(i=0;i<=document.links.length-1;i++) {document.links[i].hideFocus='true'}
	}


//-->