var wo=null;

function wopen() {
     document.forms[0].action="loader.aspx";
     document.forms[0].Password_SHA256.value=sha256_digest(document.getElementById('Password').value);
     if(document.getElementById('msg')) document.getElementById('msg').innerHTML="<br>";
     wo=window.open("","wo","width="+window.screen.availWidth+",height="+window.screen.availHeight+",toolbar=no,status=no,menubar=no,scrollbars=no,resizable=no",true);
     ret = true;
     if(wo==null || typeof(wo)=="undefined") alert("You have Luxor CRM blocked by a pop-up blocker. \nOur application runs in a separate, popup window, so please allow popup for this website.");
     else {
        try { if(wo.location!="about:blank") ret = confirm("You are currently logged in to Luxor. The Luxor window may be minimized.\nDo you wish to re-login ?"); }
        catch(e) {ret = confirm("You are currently logged in to Luxor. The Luxor window may be minimized.\nDo you wish to re-login ?");}
        wo.focus();
     }
     setTimeout(function () { document.forms[0].Username.value="";
            document.forms[0].Password_SHA256.value="";document.getElementById("Password").value="";}, 10000);
     return ret;
}
    
$(function(){
    $("#msg").hide();document.forms[0].Username.focus();
    tmp=document.location.search.match(/w=(\d+)/);
    if(tmp && document.forms[0].w) document.forms[0].w.value=tmp[1];
    tmp=document.location.search.match(/h=(\d+)/);
    if(tmp && document.forms[0].h) document.forms[0].h.value=tmp[1];
});

function show_msg(msg) {
     switch(msg) {
     case "lock":
        $("#msg").html("This Account is Locked. Try again in 30 min.").show();
        setTimeout("$('#msg').slideUp()",7000);
        break;
     case "try":
        $("#msg").html("Username or password is incorrect. Please try again.").show();
        setTimeout("$('#msg').slideUp()",7000);
        break;
     case "err":
        $("#msg").html("Fatal error occured. Sorry, cannot login.").show();
        setTimeout("$('#msg').slideUp()",7000);
        break;
     case "pass":
        $("#msg").html("Password has been changed successfully. Login with your new password.").show();
        setTimeout("$('#msg').slideUp()",7000);
        break;
     case "lic":
        $("#msg").html("You don't have a licence. Please contact your Luxor CRM administrator.").show();
        setTimeout("$('#msg').slideUp()",7000);
        break;
     case "exp":
        $("#msg").html("Trial version expired. Please contact us.").show();
        setTimeout("$('#msg').slideUp()",7000);
        break;
     default:
        $("#msg").html("").hide();
        break;
     }
}
