﻿// JScript File
var user;
var pass; 
 
function DoLogin() {
    $("div#LoginMsg").fadeOut();
    $("div#LoginMsg").html("<CENTER><IMG SRC='images/loading2.gif'></CENTER>");
    //$('#LoginMsg')[0].value = "<CENTER><IMG SRC='images/loading2.gif'></CENTER>";
    
    if(document.getElementById("txtUsername")!=null)
    {
        user = document.getElementById("txtUsername").value;
        pass = document.getElementById("txtPassword").value;
    }
 
    if(user=='' || pass=='')
    {
        alert("Username and Password fields cannot be empty");
        return;
    }
        
    var reqBody ="";
    
    reqBody = "USERNAME="+user;
    reqBody += "&PASSWORD="+pass;

    if (document.getElementById("chkRememberMe").checked)
        reqBody += "&rememberme=1";
    else
        reqBody += "&rememberme=0";
    if (document.getElementById("chkRememberPwd").checked)
        reqBody += "&rememberpwd=1";
    else
        reqBody += "&rememberpwd=0";
    
    url = "LoginHandler.ashx";
    
    var currRes = makeAPOST(url,reqBody);
    //alert(currRes);
    LoginResult(currRes);
    
//	var hippa = "The patient records available through this data source are only for the use of authorized practices, physicians, nurses, employees or staff who have signed confidentiality agreements on file with the entity from which these records are obtained. These records contain information which is privileged, confidential and exempt from disclosure under applicable law. If the reader of this message is not the intended recipient, you are hereby notified that any access, dissemination, distribution or copying of this communication is strictly prohibited. Browsing for information regarding patients that are not under your immediate care is strictly prohibited, as is tampering or otherwise interfering with the electronic information delivery system.\n\n"+
//    "Patient care decisions should not be based solely on the medical images or report summaries that can be accessed here. Integration of clinical and laboratory information, review of the final radiology report, and, when appropriate, consultation with the radiologist(s) is recommended.\n\n" +
//    "Your viewing of these records is tracked.\n\n"+
//    "Do you wish to proceed while agreeing to view only those patient’s records for which you have a clinical need?" ;

//    if(currRes=='User Validated')
//    { 
//        if(confirm(hippa)) 
//        {
//            location.href='StudyListHome.aspx';
//        }
//        else
//        {            
//            location.href='LogoffProcessor.aspx';
//        } 
//    }
//    else if(currRes=='Change Password')
//    {
//        location.href='ChangePassword.aspx';
//    }
//    else if(currRes=='refresh')
//    {
//        location.href='Login.aspx';
//    }
//    else
//    {  
//	    var LogMsg = document.getElementById('LoginMsg');
//	    LogMsg.innerHTML = currRes;
//	    LogMsg.style.display = 'block';
//    }
}


//function onResponse(text) {
//        if(text=='User Validated')
//        {
//            location.href='StudyListHome.aspx';
//        }
//        else if(text=='Change Password')
//        {
//            location.href='ChangePassword.aspx';
//        }
//        else
//        {  
//		    var LogMsg = document.getElementById('LoginMsg');
//		    LogMsg.innerHTML = text;
//		    LogMsg.style.display = 'block';
//		}
//		//alert(text); 
//	}
	
function PageQuery(q) 
{
    if(q.length > 1) this.q = q.substring(1, q.length);
    else this.q = null;
    this.keyValuePairs = new Array();
    if(q) {
    for(var i=0; i < this.q.split("&").length; i++) {
    this.keyValuePairs[i] = this.q.split("&")[i];
    }
    }
    this.getKeyValuePairs = function() { return this.keyValuePairs; }
    this.getValue = function(s) {
    for(var j=0; j < this.keyValuePairs.length; j++) {
    if(this.keyValuePairs[j].split("=")[0] == s)
    return this.keyValuePairs[j].split("=")[1];
    }
    return false;
    }
    this.getParameters = function() {
    var a = new Array(this.getLength());
    for(var j=0; j < this.keyValuePairs.length; j++) {
    a[j] = this.keyValuePairs[j].split("=")[0];
    }
    return a;
    }
    this.getLength = function() { return this.keyValuePairs.length; } 
}



function queryString(key)
{
    var page = new PageQuery(window.location.search); 
    return unescape(page.getValue(key)); 
}

function displayItem(key)
{
    if(queryString(key)=='false') 
    {
        //do nothing
    }
    else
    {
            var LogMsg = document.getElementById('LoginMsg');
		    LogMsg.innerHTML = queryString(key);
		    LogMsg.style.display = 'block';        
    }
    
    var user = document.getElementById("txtLogin");
    if(user!=null)
    user.focus();
}

