
var b64str = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"+"abcdefghijklmnopqrstuvwxyz"+"0123456789+/=";
var b64str_m = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"+"abcdefghijklmnopqrstuvwxyz"+"0123456789-_=";
// -lett a + helyett és _ a / helyett

function base64enc(inp,m)
{

 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 createLoginCookie(loginname,pwd)
{
	setCookie('randiklubusername',loginname,300);
	setCookie('randiklubpassword',pwd,300);
}
function getCookie(c_name)
{
	if (document.cookie.length>0)
	  {
	  c_start=document.cookie.indexOf(c_name + "=");
	  if (c_start!=-1)
		{ 
		c_start=c_start + c_name.length+1; 
		c_end=document.cookie.indexOf(";",c_start);
		if (c_end==-1) c_end=document.cookie.length;
		return unescape(document.cookie.substring(c_start,c_end));
		} 
	  }
	return "";
}

function setCookie(c_name,value,expiredays)
{
	var exdate=new Date();
	exdate.setDate(exdate.getDate()+expiredays);
	document.cookie=c_name+ "=" +escape(value)+
	((expiredays==null) ? "" : ";expires="+exdate.toGMTString());
}

function checkCookie()
{
	randiklubusername=getCookie('randiklubusername');
	if (randiklubusername!=null && randiklubusername!="")
	  {
		  document.myform.username.value=randiklubusername;
	  }
	randiklubpassword=getCookie('randiklubpassword');
	if (randiklubpassword!=null && randiklubpassword!="")
	  {
		  document.myform.password.value=randiklubpassword;
	  }
}
function checkEmail(email) {
	if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(email)){
	return (true)
	}
	return (false)
}
function testreq()
{
	if (testInputByTagName("input") > 0) return 1;
	return testInputByTagName("textarea");
}
function testInputByTagName(tagName)
{
	 
		var fields = document.getElementsByTagName(tagName);
		var hasError = 0;
		if (fields == null) return true;
		for (i = 0; i < fields.length; i++) 
		{
			var field = fields[i];
			var msg = field.getAttribute("msg");
			var email = field.getAttribute("email");
			if (msg == null) msg = field.name;
			if (field.getAttribute("required") != null)
			{
				if (field.getAttribute("numeric") != null)
				{
					if (field.value == '' || !IsNumeric(field.value))
					{
						if (hasError == 0)
						{
							alert('Kérem nem negatív egész számot adjon meg: ' + msg +' !');
						}
						hasError = 1;
					}
				}
				if (field.value == '' || (email != null && !checkEmail(field.value)))
				{
					if (hasError == 0)
					{
//						if (email != null) alert('Kérem ellenőrizze az E-mail címének helyességét: ' + msg +' !');
//						else alert('Kérem töltse ki a kötelező mezőket: ' + msg +' !');
                        alert('Kérem töltse ki a kötelező mezőket: ' + msg +' !');
					}
					hasError = 1;
				}
			}
		}
		return hasError;
}
function IsNumeric(sText)
{
	var ValidChars = "0123456789";
	var IsNumber=true;
	var Char;
	if (sText == null || sText == "") return false;
	var i = 0;
	while(i < sText.length)
	{
		Char = sText.charAt(i); 
		if (ValidChars.indexOf(Char) == -1) 
		{
			return false;
		}
		i = i + 1;
	}
	return IsNumber;
   
}
function jumpmenuwithaction(menuname, newaction)
{
	document.myform.action.value=newaction;
	document.myform.selectedmenu.value=menuname;
	document.myform.submit();
}
function jumpmenu(menuname)
{
	document.myform.selectedmenu.value=menuname;
	document.myform.submit();
}
function setaction(newaction, test)
{
	if (test) if (testreq() == 1) 
	{
		return false;
	}
	document.myform.myaction.value=newaction;
	document.myform.submit();
}
function setlang(newlang)
{
	document.myform.lang.value=newlang;
	document.myform.submit();
}
function setactionvalue(newaction)
{
	document.myform.actionvalue.value=newaction;
}

