var b64str = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"+"abcdefghijklmnopqrstuvwxyz"+"0123456789+/=";
var b64str_m = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"+"abcdefghijklmnopqrstuvwxyz"+"0123456789-_=";


function page_show(page)
{			
	{
		var url = page ;
		var pars ="";
		var myAjax = new Ajax.Request(
					url, 
					{
						method: 'post', 
						parameters: pars, 
						onComplete: showPage
					});
	}
}


function showPage(originalRequest)
	{		
		document.getElementById('content-hu').innerHTML = "" ;
		document.getElementById('content-hu').innerHTML = originalRequest.responseText;		
	}

function nyelv(lang)
{
	//self.location.href = self.location.href
	link = document.location.href.split("php"); 
	
	if (link[1]== null )
		document.location.href = "index.php?lang=" + lang;
	else
	document.location.href = link[0] + "php?lang=" + lang;
	//document.location.href = "index.php?lang=" + lang;
}


function swf_change(target)
{
	var flash ;
	
	flash = '<object type="application/x-shockwave-flash" data="images/swf/' + target + '.swf" width="150" height="150">' ;
	flash += '<param name="movie" value="' + target + '.swf" />' ;
	flash += '<img src="images/swf/' + target + '.swf" width="150" height="150" alt="flash_movie" />' ; 
	document.getElementById('flash').innerHTML = flash ;
}


function base64enc(inp,m)
{
//ajax posthoz, magyar karakterek miatt
 if (inp=="") return("");

 var b64ch=(m==1)?b64str:b64str_m;

 for (i=0;i<inp.length;i++)
 {
   //if (inp.charCodeAt(i)>255) alert("i:"+i+" code:"+inp.charCodeAt(i)+" ch:"+inp.charAt(i));
   if (inp.charCodeAt(i)>255) alert("i:"+i+" code:"+inp.charCodeAt(i)+" code:"+inp.charCodeAt(i+1));
   //alert(inp.charCodeAt(i)+inp.charAt(i));
 }

 if (typeof(btoa)=="function")
  {
    alap=btoa(inp);
    if (m!=1)
    {
     alap=alap.replace(/\x2B/g,"-");
     alap=alap.replace(/\x2F/g,"_");
    }
    return alap;
  }

    var out = ""; //This is the output
    var chr1, chr2, chr3 = ""; //These are the 3 bytes to be encoded
    var enc1, enc2, enc3, enc4 = ""; //These are the 4 encoded bytes
    var i = 0; //Position counter

    do
    { //Set up the loop here
        chr1 = inp.charCodeAt(i++); //Grab the first byte
        chr2 = inp.charCodeAt(i++); //Grab the second byte
        chr3 = inp.charCodeAt(i++); //Grab the third byte

        //Here is the actual base64 encode part.
        //There really is only one way to do it.
        enc1 = chr1 >> 2;
        enc2 = ((chr1 & 3) << 4) | (chr2 >> 4);
        enc3 = ((chr2 & 15) << 2) | (chr3 >> 6);
        enc4 = chr3 & 63;

        if (isNaN(chr2))
        {
          enc3 = enc4 = 64;
        }
         else if (isNaN(chr3))
         {
            enc4 = 64;
         }

        //Lets spit out the 4 encoded bytes
        out = out + b64ch.charAt(enc1) + b64ch.charAt(enc2) + b64ch.charAt(enc3) + b64ch.charAt(enc4);

        // OK, now clean out the variables used.
        chr1 = chr2 = chr3 = "";
        enc1 = enc2 = enc3 = enc4 = "";

    } while (i < inp.length); //And finish off the loop

    //Now return the encoded values.
    return out;
}


function mail_check(mezo) 
{ 
	var reg = /^[0-9_a-z\.-]+@([0-9a-z-]+\.)+[a-z]{2,4}$/i; 	
	if (reg.test(mezo.value)) 
		{
			document.getElementById(mezo.name).style.backgroundColor = '#ffffff';
			return true;
		}
	else
		{
			document.getElementById(mezo.name).style.backgroundColor = '#ffaaaa';
			return false ;
		}
}



function ures(mezo)
{
  if (mezo.value == "") 
	{
		document.getElementById(mezo.name).style.backgroundColor = '#ffaaaa';
		return true;
	}
  else
	{
		document.getElementById(mezo.name).style.backgroundColor = '#ffffff';
		return false;
  }
}


function kuldes_check()
{	
	hiba = false ;
	if ( ures(document.getElementById("nev")) == true)
		{
			hiba = true;			
		}

	if (mail_check(document.getElementById("email")) == false )
		{
			hiba = true;
		}	

	if (document.getElementById("uzenet").value.length == 0)
		{
			document.getElementById("uzenet").style.backgroundColor = '#ffaaaa';
			hiba = true;
		}
	else
		{document.getElementById("uzenet").style.backgroundColor = '#ffffff'; }
	
	if (hiba==true )
		{
			var sztring = "K&eacute;rj&uuml;k, ellen&otilde;rizze a jel&ouml;lt mez&otilde;ket!"
			alert(sztring) ;
		}
	else
		{
			var nev = base64enc(escape(document.getElementById("nev").value)) ;
			//var lakcim = base64enc(escape(document.getElementById("lakcim").value)) ;
			
			var telefon = document.getElementById("telefon").value ;
			var email = document.getElementById("email").value ;
			var uzenet = base64enc(escape(document.getElementById("uzenet").value)) ;			
			
			
			
			var url = 'mailsend.php';		
			var pars = 'Id=ok' + '&nev=' + nev +   '&telefon=' + telefon + '&email=' + email + '&uzenet=' + uzenet ;

			var myAjax = new Ajax.Request(
				url, 
				{
					method: 'post', 
					parameters: pars, 
					onComplete: showResponse
				});
		}
}



function showResponse(originalRequest)
{
	//put returned XML in the textarea
	//$('user_nick').value = originalRequest.responseText;

	$('mail').innerHTML = originalRequest.responseText;
}

