var RE_START = /^([\ \t\n]+)/;
var RE_END   = /^([\ \t\n]+)/;
var HEXA = Array('0','1','2','3','4','5','6','7','8','9','a','b','c','d','e','f');

function trim(s)	{return String(s).replace(RE_START,"").replace(RE_END,"");}
function ch(c)		{return String.fromCharCode(c);}
if (!document.getElementById) { document.getElementById = function() { return null; }}

function generalWindow(windowName, url, prp)
 {
  try
   {
    if ((typeof navigator[windowName] != "undefined") && (navigator[windowName] != null))
     {
      if (navigator[windowName].closed) navigator[windowName] = window.open(url,"",prp);
      else navigator[windowName].location.href = url;
     }
    else navigator[windowName] = window.open(url,"",prp);
   }
  catch (err)
   {
    if ((typeof navigator[windowName] == "undefined") || (navigator[windowName]==null)) navigator[windowName] = window.open(url,"",prp);
    else navigator[windowName].location.href = url;
   }
  navigator[windowName].focus();
 }

function DV(key,def)
 {
  return ((typeof key != "undefined") && (key != null) && (typeof DICTIONARY != "undefined") && (DICTIONARY != null) && (typeof DICTIONARY[key] != "undefined")) ? DICTIONARY[key] : ((typeof def != "undefined" && def!=null) ? def : key);
 }

function AlertMessage(key,ret)
 {
  alert(DV(key,key));
  return ret;
 }
 
function underConstruction()
 {
  AlertMessage('Fejlesztés alatt.');
 }

function RefreshOpener()
 {
  var op = window.opener;
  window.opener.location.href = window.opener.location.href;
 }


function initializeMenu(menuId, RootMenuId) {
	var menu = document.getElementById(menuId);
	var RootMenu = document.getElementById(RootMenuId);

	if (menu == null || RootMenu == null) return;

	RootMenu.onmouseover = function() {
		menu.style.visibility = "visible";
	}	

	RootMenu.onmouseout = function (e) {
		var relatedTarget = null;
		if (e) { 
			relatedTarget = e.relatedTarget; 
		} else if (window.event) { 
			relatedTarget = window.event.toElement; 
		}

		if (elementContains(this, relatedTarget)) return false;
	
		for (i = 0; i < this.childNodes.length; i++) {
			if ((node = this.childNodes[i]).nodeName.toLowerCase() == "ul") {
				node.style.visibility = "hidden";
			}
		}
		return false;
  }
}

function elementContains(elmOuter, elmInner) {
	while (elmInner && elmInner != elmOuter) {
		elmInner = elmInner.parentNode;
	}
	return (elmInner == elmOuter);
}

function setStyle(val) {
	if(val == 1) document.getElementById("hirlevelinpt").style.border = "1px solid #F53725";
	else document.getElementById("hirlevelinpt").style.border = "1px solid #DDDFDF"
}

function goPage(id)
 {
  var url = "";
 
  switch(id)
   {
    case 	"p1"	: 	url = "/Alkategoriatermekek/825"; break;
    case	"p2"	:	url = "/Alkategoriatermekek/836"; break;
    case	"p3"	:	url = "/Alkategoriatermekek/844"; break;
    case	"p4"	:	url = "/Alkategoriatermekek/848"; break;
    case	"p5"	:	url = "/Alkategoriatermekek/855"; break;
    case	"p6"	:	url = "/Alkategoriatermekek/842"; break;    
    default		:	underConstruction();
   }    
  if (url != "") window.location.href=url;
 }				

function SendPage(url, lang)
 {
  if(lang == 2)
   generalWindow("SENDPAGEWIDNOW","/en/sendPage/F"+url,"width=600,height=440");
  else
   generalWindow("SENDPAGEWIDNOW","/sendPage/F"+url,"width=600,height=440");
 }

function PrintPage(url)  
 {
  generalWindow("PRINTPAGEWINDOW","/printPage"+url,"width=650,height=400,scrollbars=yes");
  //underConstruction();
 }
  
 function SetOffset(off,lim)
 	{
 		window.location.href = LANG_URL+"/"+URLPREFIX+off+"/"+lim;
 	}

 function SetOffset2(off,lim)
 	{
 		window.location.href = LANG_URL+"/"+URLPREFIX+off+"/"+lim+URLPOSTFIX;
 	}

function trim(stringToTrim) {
	stringToTrim = String(stringToTrim);
	return stringToTrim.replace(/^\s+|\s+$/g,"");
}

function rtrim(stringToTrim) {
	return stringToTrim.replace(/\s+$/,"");
}

function ltrim(stringToTrim) {
	return stringToTrim.replace(/^\s+/,"");
}

function checkForm(formId, fieldIds)
{
	isAllFill = true;  
	for(i in fieldIds)
		{
			if(this.document.getElementById(fieldIds[i]).value == '' || !isAllFill)
				{
					isAllFill = false;
					break;
				}
			if(this.document.getElementById(fieldIds[i]).name == 'mail')
				{
					var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
					if (!filter.test(this.document.getElementById(fieldIds[i]).value))
						{
							isAllFill = false;
							break;
						}
				}
		}
	if(isAllFill)
		document.forms[formId].submit();
	else
		alert('Minden mező kitöltése kötelező\nvagy hibás az e-mail cím!');
}

function checkMail(mail, fieldId)
{
	var x = mail;
	var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	if (!filter.test(x))
		setTimeout('this.document.getElementById("'+fieldId+'").focus();alert("Nem megfelelő e-mail cím!");', 100);
}
function deniedChars(e)
{
	var keynum;
	var keychar;
	var charcheck;
	
	if(window.event) // IE
		{
			keynum = e.keyCode;
		}
	else if(e.which) // Netscape/Firefox/Opera
		{
			keynum = e.which;
		}
	keychar = String.fromCharCode(keynum);
	charcheck = /%/;
	return !charcheck.test(keychar);
}

function langVisible(aktlang){
  $("div.langselect a").click(function(){
  	var $this = $(this);
  	var lang = $this.attr("id").substr(5,2);
  	var reg = new RegExp("^"+LANG_URL);
  	if(lang == "hu") window.location = _URI_.replace(reg,"");
  	else window.location = _URI_.replace(reg,"/"+lang);
    return false;
  });  
	$("div.langselect a").each(function(){
		var $this = $(this);
		if($this.attr("id") !== aktlang) $this.css("display","inline");
	});
}
