﻿employerLogin=false;
function headerLogin(isEmployer) 
{
    _email = document.getElementById('xloginEmailID').value;
    _password = document.getElementById('xloginPasswordID').value;  
    document.getElementById('xloginEmailID').disabled=true;
    document.getElementById('xloginPasswordID').disabled = true;
    
    if(isEmployer)
    {
        employerLogin=true;
        new Ajax.Request('/jobs/ajax/loginQuick.aspx', {parameters:'e='+_email+'&p='+_password+'&guid='+_guid+'&employerLogin=1' , onSuccess:handlerHeaderLogin, onFailure:handlerHeaderError});
    }
    else
    {
        employerLogin=false;
        new Ajax.Request('/jobs/ajax/loginQuick.aspx', {parameters:'e='+_email+'&p='+_password+'&guid='+_guid , onSuccess:handlerHeaderLogin, onFailure:handlerHeaderError});
    }
    
}

function headerLogout() 
{
//alert('/jobs/ajax/logout.aspx&guid=<%Response.Write(getGUID());%>')
    new Ajax.Request('/jobs/ajax/logout.aspx', {parameters:'&guid='+_guid , onSuccess:handlerHeaderOut, onFailure:handlerHeaderError});
}

var handlerHeaderError = function(t) {
    alert('Error>> ' + t.status + ' -- ' + t.statusText);
}

var handlerHeaderOut = function(t) 
{
    urlStr = "" + window.location;
    if (urlStr.indexOf('screening.aspx')<0)
        window.location=window.location;
    else
        window.location="/";
}

var handlerHeaderLogin = function(t) {
    //alert("response:"+t.responseText)
    document.getElementById('xloginEmailID').disabled = false;
    document.getElementById('xloginPasswordID').disabled = false;
    if (t.responseText == 'failed') {
        alert("Login incorrect");
    }
    else {
        if (employerLogin)
            window.location = "https://jobs.search.co.uk/employerHomepage.aspx";
        else {
            
            urlStr = "" + window.parent.location;
            if (urlStr.indexOf('/apply') < 0)
                window.parent.location = "mySearch";
            else
                window.parent.location.reload(true);
        }
    }
}


function forgotPassShow()
{
    var openOutDiv = new Object();
    openOutDiv.onMotionFinished = function()
    {
        dummy_mc = document.getElementById('sendPassBox');
        zzz = new Tween(dummy_mc.style,'height',Tween.strongEaseInOut,parseInt(dummy_mc.style.height),50,1,'px');
        zzz.fixTime;
        zzz.start();  
    }

    dummy_mc = document.getElementById('loginBox');
    zzz = new Tween(dummy_mc.style,'height',Tween.strongEaseInOut,parseInt(dummy_mc.style.height),0,1,'px');
    zzz.fixTime;
    zzz.start();
    zzz.addListener(openOutDiv);
}

function sendPass(isEmployer)
{
    _email = document.getElementById('sendEmail').value;
 
    
 
    if (isEmployer)
    {
               
        new Ajax.Request('/jobs/ajax/spass.aspx', {parameters:'employerLogin=1&e='+_email+'&rand='+Math.floor(Math.random()*100000) , onSuccess:passSent, onFailure:handlerHeaderError});
    }
    else
    {
        new Ajax.Request('/jobs/ajax/spass.aspx', { parameters: 'e=' + _email + '&rand=' + Math.floor(Math.random() * 100000), onSuccess: passSent, onFailure: handlerHeaderError });
    }
        
}

 
function passSent()
{
    var openOutDiv = new Object();
    openOutDiv.onMotionFinished = function()
    {
        dummy_mc = document.getElementById('loginBox');
        zzz = new Tween(dummy_mc.style,'height',Tween.strongEaseInOut,parseInt(dummy_mc.style.height),100,1,'px');
        zzz.fixTime;
        zzz.start();  
    }

    document.getElementById('passMsg').innerHTML="If registered the password has been sent.";
    dummy_mc = document.getElementById('sendPassBox');
    zzz = new Tween(dummy_mc.style,'height',Tween.strongEaseInOut,parseInt(dummy_mc.style.height),0,1,'px');
    zzz.fixTime;
    zzz.start();
    zzz.addListener(openOutDiv); 
}
