function Validate_String(string, return_invalid_chars)
         {
         valid_chars = '1234567890-_.^~abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
         invalid_chars = '';
         
         if(string == null || string == '')
            return(true);
         
         //For every character on the string.   
         for(index = 0; index < string.length; index++)
            {
            char = string.substr(index, 1);                        
            
            //Is it a valid character?
            if(valid_chars.indexOf(char) == -1)
              {
              //If not, is it already on the list of invalid characters?
              if(invalid_chars.indexOf(char) == -1)
                {
                //If it's not, add it.
                if(invalid_chars == '')
                   invalid_chars += char;
                else
                   invalid_chars += ', ' + char;
                }
              }
            }                     
            
         //If the string does not contain invalid characters, the function will return true.
         //If it does, it will either return false or a list of the invalid characters used
         //in the string, depending on the value of the second parameter.
         if(return_invalid_chars == true && invalid_chars != '')
           {
           last_comma = invalid_chars.lastIndexOf(',');
           
           if(last_comma != -1)
              invalid_chars = invalid_chars.substr(0, $last_comma) + 
              ' and ' + invalid_chars.substr(last_comma + 1, invalid_chars.length);
                      
           return(invalid_chars);
           }
         else
           return(invalid_chars == ''); 
         }


function emailCheck(id, emailform){
		chk1 = $("input[name = 'game[que1_answer]']:checked").val();
		chk2 = $("input[name = 'game[que2_answer]']:checked").val();
		chk3 = $("input[name = 'game[que3_answer]']:checked").val();
		chk4 = $("input[name = 'game[que4_answer]']:checked").val();
		if(!(chk1) || !(chk2) || !(chk3) || !(chk4)){
			alert("Minden kérdésre adjon választ!"); 
			return false;
		}
		
		 var email_address = document.getElementById(id).value; 
		 
		 at = email_address.indexOf('@');
         dot = email_address.indexOf('.');
         
         if(at == -1 || 
            dot == -1 || 
            
            dot == 0 || 
            dot == email_address.length - 1){
        	 alert("Érvényes e-mail cimet adjon meg!");
        	 return(false);
         }
         user_name = email_address.substr(0, at);
         domain_name = email_address.substr(at + 1, email_address.length);                  
         
         if(Validate_String(user_name) === false || 
            Validate_String(domain_name) === false){
        	 	alert("Érvényes e-mail cimet adjon meg!")
        	 	return(false);                     
         }else{
        	 document.getElementById(emailform).submit();
        	 return(true);
         }
}
function returnTrue(){
	if (xmlHttp.readyState == 4){
		ready = true;
		alert("Sikeres feliratkozás");
	}
}
function GetXmlHttpObject(){
	var xmlHttp = null;	
	try{
		// Firefox, Opera 8.0+, Safari
		xmlHttp = new XMLHttpRequest();
	}
	catch (e) {
		// Internet Explorer
		try {
			xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (e) {
			xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
		}
	}
	return xmlHttp;
}
function newsmailFromOffer(email_address, name){
	 //var email_address = document.getElementById(id).value; 
	 //var name = document.getElementById(name_id).value;
	 
	 at = email_address.indexOf('@');
   dot = email_address.indexOf('.');
   
   if(at == -1 || 
      dot == -1 || 
      
      dot == 0 || 
      dot == email_address.length - 1){
  	 alert("Érvényes e-mail cimet adjon meg!");
  	 return(false);
   }
   user_name = email_address.substr(0, at);
   domain_name = email_address.substr(at + 1, email_address.length);                  
   
   if(Validate_String(user_name) === false || 
      Validate_String(domain_name) === false){
  	 	alert("Érvényes e-mail cimet adjon meg!")
  	 	return(false);                     
   }else{
  	 
  		xmlHttp = GetXmlHttpObject();
  		if (xmlHttp == null) {
  			alert ("Your browser does not support AJAX!");
  			return;
  		} 

  		var url = "http://lupustravel.mailad.eu/lists/sync.php";
  		var fullname = base64enc(escape(name));
  		var param = "listid=10&email="+email_address+"&name="+fullname;

  		xmlHttp.open("GET", url+"?"+param, true);
  		xmlHttp.onreadystatechange = new Function( "returnTrue()");
  		xmlHttp.send(null);
   }
}

function newsmail(id, name_id){
	 var email_address = document.getElementById(id).value; 
	 var name = document.getElementById(name_id).value;
	 
	 at = email_address.indexOf('@');
     dot = email_address.indexOf('.');
     
     if(at == -1 || 
        dot == -1 || 
        
        dot == 0 || 
        dot == email_address.length - 1){
    	 alert("Érvényes e-mail cimet adjon meg!");
    	 return(false);
     }
     user_name = email_address.substr(0, at);
     domain_name = email_address.substr(at + 1, email_address.length);                  
     
     if(Validate_String(user_name) === false || 
        Validate_String(domain_name) === false){
    	 	alert("Érvényes e-mail cimet adjon meg!")
    	 	return(false);                     
     }else{
    	 
    		xmlHttp = GetXmlHttpObject();
    		if (xmlHttp == null) {
    			alert ("Your browser does not support AJAX!");
    			return;
    		} 

    		var url = "http://lupustravel.mailad.eu/lists/sync.php";
    		var fullname = base64enc(escape(name));
    		var param = "listid=2&email="+email_address+"&name="+fullname;

    		xmlHttp.open("GET", url+"?"+param, true);
    		xmlHttp.onreadystatechange = new Function( "returnTrue()");
    		xmlHttp.send(null);
     }
}


//encode
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;
}

var b64str = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"+"abcdefghijklmnopqrstuvwxyz"+"0123456789+/=";
var b64str_m = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"+"abcdefghijklmnopqrstuvwxyz"+"0123456789-_=";

