
	// TRIM() -  :)
	function trim(str) 
	{
		while (str.substring(0,1) == ' ')
		{
			str = str.substring(1, str.length);
		}

		while (str.substring(str.length-1, str.length) == ' ')
		{
			str = str.substring(0,str.length-1);
		}
		return str;
	}

	//resizeolja az aktualis ablakot
	function resizeOuterTo(w,h)
	{
		 if (parseInt(navigator.appVersion)>3) {
		   if (navigator.appName=="Netscape") {
			top.outerWidth=w;
			top.outerHeight=h;
		   }
		   else top.resizeTo(w,h);
		 }
	}


	// the DECIMAL to HEX converter
	function dec2hex(cval)
	{
		if (cval > 255) {cval = 255};
		hexascii = "0123456789ABCDEF";
		cval0 = Math.floor(cval/16);
		cval1 = cval - (cval0 * 16);
		c1 = hexascii.charAt(cval0);
		c2 = hexascii.charAt(cval1);
		mystr = c1 + c2;
		return mystr;
	}


	// uj popup ablak nyitasa
	function OpenPage(url,wndname,width,height,center,scrollbars,resize)
	{ 
		var left = 25; 
		var top = 25; 

		if(center == true) 
		{ 
			left = (screen.width - width)/2; 
			top = (screen.height - height)/2; 
		} 

		scrollbars = ( (scrollbars == undefined) || (scrollbars == false) ) ? 0 : 1;
		resize = ( (resize == undefined) || (resize == false) ) ? 0 : 1;

		var winStats='toolbar=no,location=no,directories=no,menubar=0,'; 
		winStats+='scrollbars='+scrollbars+',resizable='+resize+',width='+width+',height='+height; 
		if (navigator.appName.indexOf("Microsoft")>=0) 
		{ 
			winStats+=',left='+left+',top='+top; 
		} 
		else 
		{ 
			winStats+=',screenX='+left+',screenY='+top; 
		} 

		apopup=window.open(url,wndname,winStats);
		apopup.window.focus(apopup);
	}


	function PT_toggleDIV(divID)
	{
		if($(divID).style.display != 'block')
			$(divID).style.display = 'block';
		else
			$(divID).style.display = 'none';

	}

	
	// e-mail ellenorzo REGEXP
	var emailRe = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*\.(\w{2}|(com|hu|co.hu|net|org|edu|int|mil|gov|arpa|biz|aero|name|coop|info|pro|museum))$/

	// telefonszam ellenorzo REGEXP
    // var phoneRe = /^((\+\d{1,3}(-| )?\(?\d\)?(-| )?\d{1,3})|(\(?\d{2,3}\)?))(-| )?(\d{3,4})(-| )?(\d{4})(( x| ext)\d{1,5}){0,1}$/


	// lellenorzi, hogy helyes karakterek vannak-e a megadott telefonszamban
    function check_phonenumber(TheNumber)
    {
        var valid = 1;
        var GoodChars = "0123456789";
        var i = 0;

		if(TheNumber.length != 7)
		{
			valid = 0;
			return valid;
		}


        if(trim(TheNumber) == '')
		{
			// Return false if number is empty
			valid = 0;
			return valid;
        }


        for (i =0; i <= TheNumber.length -1; i++)
		{
			if (GoodChars.indexOf(TheNumber.charAt(i)) == -1)
			{
				// alert(TheNumber.charAt(i) + " is no good.")
				valid = 0;
				return valid;
			}
        }

        return valid;
    }

	// lellenorzi, hogy helyes keruletet irt-e be
    function check_district(District)
    {
         var valid = 1;
         var GoodChars = "0123456789.XIVMCL";
         var i = 0;

         if(District=="")
	         valid = 0;

         for(i=0; i<= District.length-1; i++)
			if(GoodChars.indexOf(District.charAt(i)) == -1)
				valid = 0

         return valid;
    }

	// _act es _act nelkuli képállapotok cseréje
	function toggleIcon(id)
	{
		var img = document.getElementById(id);
		if( img )
		{
		  if( img.src.indexOf('_act.') == -1 )
			  img.src = img.src.replace('.gif','_act.gif');
		  else
			  img.src = img.src.replace('_act.gif','.gif');
		}
	}

	// elintezi a rollover kepek OVER és OUT állapotát
	function rollover_img(img, status, str_ext)
	{
		if(str_ext == undefined)
			str_ext = 'jpg';

		// alert(str_ext);
		str_ext = '.' + str_ext;

		var src = img.src;
		var pos = src.indexOf(str_ext);

		switch(status)
		{
			case 'over' : img.src = src.substr(0, pos) + '_a' + str_ext;
						  break;

			case 'out' : img.src = src.substr(0, pos-2) + str_ext;
						 break;
		}
	}

	// lenyit vagy becsuk egy DIV-et (state = [open, close])
	function chg_div_state(id_div, state, height)
	{
		div = document.getElementById(id_div);

		div.style.display = (state == 'open' ? 'block' : 'none');
		div.style.height = (state == 'open' ? height : '0px');

		return;
	}

	// ha le volt nyitva a div akkor becsukas lesz, amugy kinyitas
	function flip_div_state(id_div, height)
	{
		div = document.getElementById(id_div);

		if(div.style.display != 'block')
			chg_div_state(id_div, 'open', height)
		else
			chg_div_state(id_div, 'close');

		return;
	}



		function CreatePreviewImage(TempImage,img,MaxWidth,MaxHeight)
		{
			img.src = TempImage.src;
			TempWidth = TempImage.width;
			TempHeight = TempImage.height;
			TempRatio = TempWidth / TempHeight;

			if( (TempWidth > MaxWidth) || (TempHeight > MaxHeight) )
			{
				if(TempWidth > MaxWidth)
				{
					TempWidth = MaxWidth;
					TempHeight = TempWidth / TempRatio;
				}

				if(TempHeight > MaxHeight)
				{
					TempHeight = MaxHeight;
					TempWidth = TempHeight * TempRatio;
				}
			}

			img.width=TempWidth;
			img.height=TempHeight;
		}
		
		function PreviewImage(file,img,MaxWidth,MaxHeight)
		{
			var filename = "file:///" + file.value;

			var TempRatio = "";
			var TempImage = new Image();
			TempImage.onload = function(){CreatePreviewImage(this,img,MaxWidth,MaxHeight);};
			TempImage.src = filename;
			img.style.display = 'block';
			img.style.display = 'inline';
		}
