function checkEnter(e, caller) //e is event object passed from function invocation
{
    var characterCode //literal character code will be stored in this variable

    if (e && e.which || e.which == 0) { //if which property of event object is supported (NN4)

        e = e;
        characterCode = e.which; //character code is contained in NN4's which property
    }
    else {
        e = event;
        characterCode = e.keyCode //character code is contained in IE's keyCode property
    }

    if (characterCode == 13)//if generated character code is equal to ascii 13 (if enter key)
    {
        if (document.all) {
            e.returnValue = false;
            e.cancel = true;
        }
        else {
            e.preventDefault();
        }
        var obj = document.getElementById(caller);
        if (obj) {

            if (obj.click) {
                obj.click();
            }
        }
        return false;
    }
    else {
        return true;
    }

}

/*
//start: ENCODE string
function base64Encode(str) {
var c, d, e, end = 0;
var u, v, w, x;
var ptr = -1;
var input = str.split("");
var output = "";
while(end == 0) {
c = (typeof input[++ptr] != "undefined") ? input[ptr].charCodeAt(0) : 
((end = 1) ? 0 : 0);
d = (typeof input[++ptr] != "undefined") ? input[ptr].charCodeAt(0) : 
((end += 1) ? 0 : 0);
e = (typeof input[++ptr] != "undefined") ? input[ptr].charCodeAt(0) : 
((end += 1) ? 0 : 0);
u = enc64List[c >> 2];
v = enc64List[(0x00000003 & c) << 4 | d >> 4];
w = enc64List[(0x0000000F & d) << 2 | e >> 6];
x = enc64List[e & 0x0000003F];
        
// handle padding to even out unevenly divisible string lengths
if (end >= 1) {x = "=";}
if (end == 2) {w = "=";}
        
if (end < 3) {output += u + v + w + x;}
}
// format for 76-character line lengths per RFC
var formattedOutput = "";
var lineLength = 76;
while (output.length > lineLength) {
formattedOutput += output.substring(0, lineLength) + "\n";
output = output.substring(lineLength);
}
formattedOutput += output;
return formattedOutput;
}
//end: ENCODE string
*/

//start: DECODE string
/*function base64Decode(str) {
var c=0, d=0, e=0, f=0, i=0, n=0;
var input = str.split("");
var output = "";
var ptr = 0;
do {
f = input[ptr++].charCodeAt(0);
i = dec64List[f];
if ( f >= 0 && f < 128 && i != -1 ) {
if ( n % 4 == 0 ) {
c = i << 2;
} else if ( n % 4 == 1 ) {
c = c | ( i >> 4 );
d = ( i & 0x0000000F ) << 4;
} else if ( n % 4 == 2 ) {
d = d | ( i >> 2 );
e = ( i & 0x00000003 ) << 6;
} else {
e = e | i;
}
n++;
if ( n % 4 == 0 ) {
output += String.fromCharCode(c) + 
String.fromCharCode(d) + 
String.fromCharCode(e);
}
}
}
while (typeof input[ptr] != "undefined");
output += (n % 4 == 3) ? String.fromCharCode(c) + String.fromCharCode(d) : 
((n % 4 == 2) ? String.fromCharCode(c) : "");
return output;
}
//end: DECODE string
*/


function CheckSubscribe(valueSearch) {
    var email = $('#mail').val();
    if (email != valueSearch) {
        //search the hidden field
        location.href = '?email=' + email;
        return true;
    }
    return false;
}

function GetTicket(errorMessage) {
    var ticket = $('#txtTicketId').val();
    var age = $('#txtAge').val();
    var gender = $("input[@name='gender']:checked").val();
        
    if (ticket=='' && (age == '' || gender == '' || gender==undefined || gender == null))
    {
        alert(errorMessage);
        return;
    }

    //if the ticket is not null, it means we search for that ticket
    if (ticket != '') {
        location.href = '?ticketId=' + ticket;
        return false;
    }
    else {
        //if we have gender selected
        if (gender != null) {
            if (age != '') {
                location.href = '?gender=' + gender + '&age=' + age;
                return false;
            }
            else {
                location.href = '?gender=' + gender;
                return false;
            }
        }
        //if we have only age
        else
           // if (age != '') {
            location.href = '?age=' + age;
            return false;
        //}
    }
    return false;
}

function ClearTicket() {
    $('#txtTicketId').val('');
    $('#txtAge').val('');
    $('input[name="gender"]')[0].checked = false;
    $('input[name="gender"]')[1].checked = false;
    return false;
}

function RedirectWithoutQueryString() {
    if (document.location.href.indexOf('?') >= 0)
        document.location.href = document.location.href.substring(0, document.location.href.indexOf('?'));
}


