var easyRechRequest;

// TELL-A-FRIEND POPUP

function tell_a_friend(email, lng)
{
    popwin("/mail/easy/easy_tell_a_friend.php?email="+email+"&lang="+lng, 520, 570);
}

function tell_a_friend_combination(combination, lng)
{
    popwin("/mail/easy/easy_tell_a_friend.php?combination="+combination+"&lang="+lng, 520, 570);
}

// RECHERCHE FUNKTIONEN

function email_search_key(ev)
{
    var kc=get_keycode(ev);
    if(kc==13) { email_search_submit(); }
}

function email_category_switch(newcat)
{
    email_search_form_disabled(true);
    setTimeout("email_category_switch_now('"+newcat+"');",50);
}

function email_category_switch_now(newcat)
{
    if(typeof(newcat) == "undefined")
    {
        document.getElementById("pdomain").innerHTML="";
    } else {
        var theurl=document.getElementById('email_search').action+"?kid="+newcat;
        ajax_call(theurl);
    }
    email_search_submit_now();
    }

function email_search_submit()
{
    email_search_form_disabled(true);
    setTimeout('email_search_submit_now();',50);
}

function email_search_submit_now()
{
    easyRechRequest = ajax_form_submit(document.getElementById('email_search'), true);
    easyRechRequest.onreadystatechange = email_search_receive;

}

/*
* Receive Ajax Response
*/

function email_search_receive()
{
    // Wait for reception
    if(easyRechRequest.readyState == 4) {
        email_search_form_disabled(false);
        if(easyRechRequest.status == 200) {   
            ajax_parent_push(easyRechRequest); 
        } else { 
            debug_print("Error "+easyRechRequest.status); 
        }
    }
}

function email_search_form_disabled(ena)
{
    // Clone progress innerHTML
    if(ena) {
        document.getElementById('rech_result').innerHTML = document.getElementById('rech_progress').innerHTML;
    }
    hourglass(ena);
        
    // Enable / Disable Buttons
    document.getElementById("okbutton").disabled=ena;
    document.getElementById("pfirstname").disabled=ena;
    document.getElementById("plastname").disabled=ena;
    var kid=document.getElementById("pkid");
    var dmn=document.getElementById("pdomain");
    kid.disabled=ena;
    dmn.disabled=(ena || (kid.value == ""));
}

function email_search_autoexec()
{
    var pfirstname = document.getElementById("pfirstname").value;
    var plastname = document.getElementById("plastname").value;
    var pkid = document.getElementById("pkid").value;

    // Run Autoexec?
    if(pfirstname || plastname || pkid) {
        email_search_submit();
    }
}

function open_mailbox(mburl)
{
    popwin(mburl,800,600,'mailapp','yes');
}
