﻿// JScript File

function backToLogin(){
try{
    LastReset = Number(document.frames.top.frames[1].document.getElementById('reset').value);
    if (LastReset >= 1){
        window.top.location = "login.aspx"
        //alert('goto login');
    }else{
        KeepAliveID = Math.floor(Math.random()*10001);
       // alert(KeepAliveID);
        document.frames.top.frames['Nav'].document.getElementById('KeepAliveID').value = KeepAliveID;
        KeepAlivePopup=  Number(document.frames.top.frames['Nav'].document.getElementById('KeepAlivePopup').value);
        KeepAliveKickout=  Number(document.frames.top.frames['Nav'].document.getElementById('KeepAliveKickout').value);
        setTimeout("disableAllFrames(" + KeepAliveID + ")",KeepAlivePopup);
        setTimeout("backToLogin()",KeepAliveKickout);
    }
    }catch (error) {}
}

function disableAllFrames(KeepAliveID) {
try{
if (KeepAliveID == document.frames.top.frames['Nav'].document.getElementById('KeepAliveID').value||KeepAliveID==undefined){
    var xmlHttp=makeRequest();
       xmlHttp.open("POST", "PasswordCheck.aspx?Disable=True&PasswordCheck=" + document.frames.top.frames['Main'].document.getElementById('Reset_1_Password__1').value, false);
      if (window.ActiveXObject){
         xmlHttp.send(null);
	  } else {
	    xmlHttp.send('');
	  }
	  sz = new String(xmlHttp.responseText);

    for (var i = 0; i < document.frames.top.frames.length; i++) {
    try{
        document.frames.top.frames[i].document.getElementById('disableBackground').width=document.frames.top.frames[i].document.body.scrollWidth-3;
        document.frames.top.frames[i].document.getElementById('disableBackground').height=document.frames.top.frames[i].document.body.scrollHeight-3;
        document.frames.top.frames[i].document.getElementById('myDiv').style.clip='rect(auto auto auto auto)';
        document.frames.top.frames[1].document.getElementById('EnterPassword').style.clip='rect(auto auto auto auto)';
        document.frames.top.frames[i].ListBoxHide(1,'disableBackground');
        document.frames.top.frames[i].ListBoxHide(1,'myDiv');
        window.history.forward(1);
           }catch (error) {    }
   }
   document.frames.top.frames[1].document.getElementById('reset').value =Number(document.frames.top.frames[1].document.getElementById('reset').value) +1;
   }

       }catch (error) {}
}

function testPassword(){
    enableAllFrames();
}

function keepAlive(){
    try{
/*send ajax request to keep session alive*/
    LastReset=0;
    document.getElementById('reset').value = LastReset;
    KeepAliveID = Math.floor(Math.random()*10001);
    document.frames.top.frames['Nav'].document.getElementById('KeepAliveID').value = KeepAliveID;
    KeepAlivePopup=  Number(document.frames.top.frames['Nav'].document.getElementById('KeepAlivePopup').value);
    KeepAliveKickout=  Number(document.frames.top.frames['Nav'].document.getElementById('KeepAliveKickout').value);
    setTimeout("disableAllFrames(" + KeepAliveID + ")",KeepAlivePopup);
    setTimeout("backToLogin()",KeepAliveKickout);
    }catch (error) {}
}

function enableAllFrames() {
    try{
 /*Check if it is a valid password*/
    var xmlHttp=makeRequest();
    if (document.frames.top.frames['Main'].document.getElementById('Reset_1_Password__1').value != ''){
        xmlHttp.open("POST", "PasswordCheck.aspx?PasswordCheck=" + document.frames.top.frames['Main'].document.getElementById('Reset_1_Password__1').value, false);
        if (window.ActiveXObject){
            xmlHttp.send(null);
	    } else {
	        xmlHttp.send('');
	    }
	    sz = new String(xmlHttp.responseText);

	    if (sz == 'True'){
            for (var i = 0; i < document.frames.top.frames.length; i++) {
                try{
                    document.frames.top.frames[i].document.getElementById('disableBackground').width=document.frames.top.frames[i].document.body.scrollWidth-3;
                    document.frames.top.frames[i].document.getElementById('disableBackground').height=document.frames.top.frames[i].document.body.scrollHeight-3;
                    document.frames.top.frames[i].document.getElementById('myDiv').style.clip='rect(auto 0 auto 0)';
                    document.frames.top.frames[i].document.getElementById('IFrameBlock').style.clip='rect(auto 0 auto 0)';
                    try{
                        document.frames.top.frames[i].document.getElementById('EnterPassword').style.clip='rect(auto 0 auto 0)';
                        document.frames.top.frames[i].document.getElementById('Reset_1_Password__1').value = '';
                    }catch (error) {}
                        document.frames.top.frames['Nav'].document.keepAlive();
                }catch (error) {}
            }
        }
        if (sz =='False'){
            document.frames.top.frames[1].document.getElementById('reset').value = '';
        }
        if (sz ==''){
            backToLogin();
        }
        }
    }catch (error) {}
}