
    var goOnWnd;
    var shpWnd;

    function init() //----used by SmoothStart.aspx on onLoad event
    {
        try
        {
            var lblError = GetCtrl('lblError');
            var hddMsg = GetCtrl('hddMsg');
            if (IsValid(lblError) & IsValid(hddMsg))
            {
                lblError.innerHTML = hddMsg.value;
                hddMsg.value = "";
            }

            var txtSHipmentAWB = GetCtrl('txtSHipmentAWB');
            if(IsValid(txtSHipmentAWB))
                HideButton('btnGetShpAWBReport', txtSHipmentAWB.value == "");
            HideButton('btnLogon', true);
            
            var txtPassword = GetCtrl('txtPassword');
            var txtUserName = GetCtrl('txtUserName');

            var hddUP = document.getElementById('hddUP');
            if(hddUP != null && hddUP != undefined && hddUP.value != "")
                txtPassword.value = hddUP.value;

            var referee = document.referrer;
            var pos = referee.search("TabularReport.aspx");
            if(IsValid(txtUserName) && pos == -1)
            {
                /*era:
                if(txtUserName.disabled == false)
                    txtUserName.focus();
                */
                if (txtUserName.disabled == false && IsValid(txtPassword) && txtPassword.disabled == false && txtUserName.value != "" && txtPassword.value != "")
                {
                    HideButton('btnLogon', false);
                    var btnLogon = GetCtrl('btnLogon');
                    if (btnLogon != null && btnLogon != undefined && btnLogon.disabled == false)
                        btnLogon.focus();
                }
                else if(txtUserName.disabled == false)
                    txtUserName.focus();
                else 
                {
                    //var hddUP = document.getElementById('hddUP');
                    //if(hddUP != null && hddUP != undefined && hddUP.value != "")
                    //    txtPassword.value = hddUP.value;
                        
                    var btnJoin = GetCtrl('btnJoin');
                    if(IsValid(btnJoin) && btnJoin.disabled == false)
                        btnJoin.focus();
                }
            }
                
            if(txtSHipmentAWB != null && txtSHipmentAWB != "undefined" && txtSHipmentAWB.value != "")
                txtSHipmentAWB.focus();
            return true; 
        }
        catch(e){} 
    }
	function closeSession_2(e)
    {
        try
        {
    	    var hddLastMouseEvt = GetCtrl('hddLastMouseEvt');
            if(hddLastMouseEvt.value == true || hddLastMouseEvt.value == 'true' || hddLastMouseEvt.value == '1' || IsClosingBrowser(e))
            {
                window.open("Shutdown.aspx");
                return false;
            }
        }
        catch(e){}
        return true;
    }
    //--->manage Shipment/ Package searching
    function OnClickShp()
    {
        try
        {
            var txtSHipmentAWB = GetCtrl('txtSHipmentAWB');
	        if(IsValid(txtSHipmentAWB))
                SearchShipment(txtSHipmentAWB.value);
            //window.focus();
            return false;
        }
        catch(e){}
    }    
    function EvalIfKnowsTheShipment()
    {
        try
        {
            shpWnd = window.open('LoginDispatcher.aspx?Nobo=0');
            //window.focus();
            return false;
        }
        catch(e){}
    }
    function SearchShipment(shpCode) 
    {
        try
        {
            var surl = "ShipmentOrPackageChecker.aspx?SID=" + shpCode;
	        $.post(surl, SearchShipmentCallback, "json");
	    }
	    catch(ex){}
    }
    function SearchShipmentCallback(data, txtStatus)
    {
        try
        {
            var edge = data.length;
            var theMesage = "";
            var msgStartIdx = data.indexOf("*");
            if(msgStartIdx != -1)
            {
                //didn't found a shipment/ package with the specified number
                theMesage = data.substring(msgStartIdx + 1, edge);
                var lblError = GetCtrl('lblError');
                if(IsValid(lblError))
                    lblError.innerHTML = theMesage;
                //window.opener = top;
                shpWnd.close();
                return false;
            }
            else     
            {       
                //otherwise, it found a shipment...
                var shpID = data;
                shpWnd.location.href = "../ReportingManager.UI/ShipmentDetailsView.aspx?SID=" + shpID;
                shpWnd.focus();
                return false;
            }
        }
        catch(ex){}
    }  
    //<---manage Shipment/ Package searching

    //--->manage logging into portal - from SmoothStart
    function EvalItMightGoFurther() 
    {
        try 
        {
            goOnWnd = window.open('LoginDispatcher.aspx?Nobo=0');
            setTimeout('LoadFailedLogin()', 35000);            
            //goOnWnd.focus();
            return false;
        }
        catch (e) { }
    }

    function LoadFailedLogin() 
    {
        try 
        {
            //if (goOnWnd != null && goOnWnd.location.href.indexOf('Nobo=0') >= 0)
            if (goOnWnd != null && goOnWnd.location != null && goOnWnd.location.href != null && goOnWnd.location.href.indexOf('Nobo=0') >= 0)
                goOnWnd.location = 'LoginDispatcher.aspx?Nobo=1';
        }
        catch (e) { }
    }

    function OnClickAgo(sDir)
    {
        try
        {
            var sRem = "N";
            var btnRemember = GetCtrl('btnRemember');
            if (IsValid(btnRemember) && btnRemember.checked == true)
                sRem = "Y";
	        var txtPassword = GetCtrl('txtPassword');
	        var txtUserName = GetCtrl('txtUserName');
	        if(IsValid(txtPassword) && IsValid(txtUserName))
                EvalCredentials(txtUserName.value, txtPassword.value, sDir, sRem);
            return false;
        }
        catch(e){}
    }
    function EvalCredentials(uid, psw, sDir, sRem) 
    {
        try
        {
            var uidEncoded = encodeURIComponent(uid);
            var pswEncoded = encodeURIComponent(psw);
            var surl = "CredentialsChecker.aspx?UID=" + uidEncoded + "&PIS=" + pswEncoded + "&Dir=" + sDir + "&Rem=" + sRem;
	        $.post(surl, EvalCredentialsCallback, "json");
	    }
	    catch(ex){}
	}
	function EvalCredentialsCallback(data, txtStatus)
	{
	    return GeneralEvalCredentialsCallback(data, txtStatus, true);
	}
    function OnJoinClick()
    {
        try
        {
	        var questJoin = GetCtrl('questJoin');
            if(IsValid(questJoin))
                questJoin.style.display = 'none'; 
            DisableCtrlByID('txtSHipmentAWB', false);
            DisableCtrlByID('txtUserName', false);
            DisableCtrlByID('txtPassword', false);
            OnClickAgo("3");        
            return true;
        }
        catch(ex){}
    }  
	//<---manage logging into portal - from SmoothStart
	function SayThereIsAPopupBlocker(wndObj) 
	{
	    if (wndObj == null || wndObj == undefined)
	        alert("There is a popup blocker for Consignor-portal website from EDI-Soft AS. Turn it off in order to continue.")
	    else
	        wndObj.focus();
	}
	//--------->former Common.js
	var bFailedNow = false;

	function GetCtrl(ctrlID) {
	    try {
	        var ctrl = document.getElementById(ctrlID);
	        return ctrl;
	    }
	    catch (e) { }
	}
	function IsValid(ctrl) {
	    if (ctrl != null && ctrl != undefined) return true;
	    return false;
	}
	function DisableButton(obj, bDo) {
	    try {
	        if (obj != null && obj != undefined)
	            obj.disabled = bDo;
	    }
	    catch (e) { }
	}
	function DisableCtrlByID(ctrlID, bDo) {
	    try {
	        var ctrl = document.getElementById(ctrlID);
	        if (ctrl != null && ctrl != undefined)
	            ctrl.disabled = bDo;
	    }
	    catch (e) { }
	}
	function HideButton(ctrlID, bHide) {
	    try {
	        var ctrl = document.getElementById(ctrlID);
	        if (ctrl != null && ctrl != undefined) {
	            if (bHide)
	                ctrl.style.display = 'none';
	            else
	                ctrl.style.display = 'block';
	        }
	    }
	    catch (e) { }
	}
	function SearchUser_OnPaste() {
	    try {
	        var txtUserName = GetCtrl('txtUserName');
	        txtUserName.value = window.clipboardData.getData("Text");
	        SearchUser_OnKeyUp();
	    }
	    catch (e) { }
	}
	function SearchPsw_OnPaste() {
	    try {
	        var txtPassword = GetCtrl('txtPassword');
	        txtPassword.value = window.clipboardData.getData("Text");
	        SearchUser_OnKeyUp();
	    }
	    catch (e) { }
	}
	function SearchUser_OnKeyUp() {
	    try {
	        var txtSHipmentAWB = GetCtrl('txtSHipmentAWB');
	        if (IsValid(txtSHipmentAWB))
	            txtSHipmentAWB.value = "";
	        HideButton('btnGetShpAWBReport', true);

	        var txtPassword = GetCtrl('txtPassword');
	        var txtUserName = GetCtrl('txtUserName');
	        bRes = (txtUserName.value == "" || txtPassword.value == "");
	        HideButton('btnLogon', bRes);
	    }
	    catch (e) { }
	}
	function SearchAWB_OnPaste() {
	    try {
	        var txtSHipmentAWB = GetCtrl('txtSHipmentAWB');
	        txtSHipmentAWB.value = window.clipboardData.getData("Text");
	        SearchAWB_OnKeyUp();
	    }
	    catch (e) { }
	}
	function SearchAWB_OnKeyUp() {
	    try {
	        var txtPassword = GetCtrl('txtPassword');
	        var txtUserName = GetCtrl('txtUserName');
	        if (IsValid(txtPassword))
	            txtPassword.value = "";
	        if (IsValid(txtUserName))
	            txtUserName.value = "";

	        var txtSHipmentAWB = GetCtrl('txtSHipmentAWB');
	        if (IsValid(txtSHipmentAWB))
	            HideButton('btnGetShpAWBReport', txtSHipmentAWB.value == "");
	    }
	    catch (e) { }
	}
	function window_onKeyDown(e) {
	    try {
	        if (!bFailedNow)
	            showMessage("");
	        bFailedNow = false;

	        var nKey;
	        if (!e) var e = window.event;
	        if (e.keyCode) nKey = e.keyCode;
	        else if (e.which) nKey = e.which;

	        /*if(nKey == 116) //F5
	        {
	        e.keyCode = 0;
	        e.returnValue = false;
	        window.open("SmoothStart.aspx","_self");
	        return false;
	        } */
	        if (nKey == 13) {
	            var bCheckFurther = false;
	            var txtPassword = GetCtrl('txtPassword');
	            var txtUserName = GetCtrl('txtUserName');
	            if (IsValid(txtPassword) && IsValid(txtUserName)) {
	                bRes = (txtUserName.value != "" && txtPassword.value != "");
	                if (bRes) {
	                    //if the <Ask for joining> section it is visible, then won't do anything.
	                    var questJoin = GetCtrl('questJoin');
	                    if (IsValid(questJoin) && questJoin.style.display != 'none')
	                        return true;
	                    var btnLogon = GetCtrl('btnLogon');
	                    if (IsValid(btnLogon)) {
	                        //btnLogon.disabled = false;
	                        btnLogon.style.display = 'block';
	                        btnLogon.focus();
	                    }
	                }
	                else
	                    bCheckFurther = true;
	            }
	            else
	                bCheckFurther = true;
	            if (bCheckFurther) {
	                var txtSHipmentAWB = GetCtrl('txtSHipmentAWB');
	                if (IsValid(txtSHipmentAWB) && txtSHipmentAWB.value != "") {
	                    var btnGetShpAWBReport = GetCtrl('btnGetShpAWBReport');
	                    if (IsValid(btnGetShpAWBReport)) {
	                        btnGetShpAWBReport.style.display = 'block';
	                        btnGetShpAWBReport.focus();
	                    }
	                }
	            }
	        }
	    }
	    catch (e) { }
	}
	function window_onClick(e) {
	    try {
	        if (!bFailedNow)
	            showMessage("");
	        bFailedNow = false;
	        var hddLastMouseEvt = GetCtrl('hddLastMouseEvt');
	        if (IsValid(hddLastMouseEvt))
	            hddLastMouseEvt.value = IsClosingBrowser(e);
	    }
	    catch (e) { }
	}
	function showMessage(strMessage) {
	    try {
	        var lblError = GetCtrl('lblError');
	        if (IsValid(lblError) && lblError.innerHTML != strMessage)
	            lblError.innerHTML = strMessage;

	        hddMsg = GetCtrl('hddMsg'); /// + 28 oct
	        if (IsValid(hddMsg))
	            hddMsg.value = "";
	    }
	    catch (e) { }
	}
	function GeneralEvalCredentialsCallback(data, txtStatus, isStart) {
	    try {
	        var loggedInID;
	        var evalResolution = data.substring(0, 1);

	        var msgStartIdx = data.indexOf("*");
	        var edge = data.length;
	        var loggedIDEndIdx = edge;
	        var theMesage = "";
	        if (msgStartIdx != -1) {
	            loggedIDEndIdx = msgStartIdx;
	            theMesage = data.substring(msgStartIdx + 1, edge);
	        }
	        if (evalResolution != "4")
	            loggedInID = data.substring(1, loggedIDEndIdx);

	        if (evalResolution == "1" || evalResolution == "2") {
	            var txtPassword = GetCtrl('txtPassword');
	            if (IsValid(txtPassword))
	                txtPassword.value = "";
	            HideButton('btnLogon', true);

	            var btnRemember = GetCtrl('btnRemember');
	            var hddEmb = GetCtrl('hddEmb');
	            if (IsValid(btnRemember) && btnRemember.checked == true && isStart && IsValid(hddEmb) && hddEmb.value != "Y") {
	                goOnWnd.close();
	                window.location = "LoginDispatcher.aspx?Dir=" + evalResolution + "&LogID=" + loggedInID;
	                return false;
	            }
	            if (isStart) {
	                //$.post('LoginDispatcher.aspx?Dir=' + evalResolution + '&LogID=' + loggedInID);
	                //goOnWnd.location.reload(true);
	                //goOnWnd.navigate("LoginDispatcher.aspx?Dir=" + evalResolution + "&LogID=" + loggedInID);
	                goOnWnd.location.href = "LoginDispatcher.aspx?Dir=" + evalResolution + "&LogID=" + loggedInID;
	                goOnWnd.focus();
	            }
	            else 
	                window.location = "LoginDispatcher.aspx?Dir=" + evalResolution + "&LogID=" + loggedInID;
	            return false;
	        }
	        if (evalResolution == "4") {
	            //the credentials are not valid or the user is inactive
	            var txtPassword = GetCtrl('txtPassword');
	            if (IsValid(txtPassword))
	                txtPassword.value = "";
	            HideButton('btnLogon', true);

	            var lblError = GetCtrl('lblError');
	            if (IsValid(lblError))
	                lblError.innerHTML = theMesage;
	            if (isStart) {
	                //window.opener = top;
	                goOnWnd.close();
	            }
	        }
	        if (evalResolution == "3") {
	            //it trys to login with another user, while there is operational 
	            //a connection with another user
	            var lblquestion = GetCtrl('lblquestion');
	            if (IsValid(lblquestion))
	                lblquestion.innerHTML = theMesage;

	            HideButton('btnLogon', true);

	            DisableCtrlByID('txtSHipmentAWB', true);
	            DisableCtrlByID('txtUserName', true);
	            DisableCtrlByID('txtPassword', true);

	            var questJoin = GetCtrl('questJoin');
	            if (IsValid(questJoin))
	                questJoin.style.display = 'block';
	            if (isStart) {
	                goOnWnd.close();
	                window.focus();
	            }
	        }
	        return false;
	    }
	    catch (ex) { }
	}
	function OnClickBtnNo() {
	    try {
	        //var hddUP = GetCtrl('hddUP');
	        //if(IsValid(hddUP))
	        //    hddUP.value = "";
	        var questJoin = GetCtrl('questJoin');
	        if (IsValid(questJoin))
	            questJoin.style.display = 'none';

	        DisableCtrlByID('txtSHipmentAWB', false);
	        var txtPassword = GetCtrl('txtPassword');
	        if (IsValid(txtPassword)) {
	            txtPassword.disabled = false;
	            txtPassword.value = "";
	        }
	        DisableCtrlByID('txtUserName', false);
	    }
	    catch (e) { }
	    return false;
	}
//<----------------former Common.js

//----------------> former Relogin.js
	//--> for default page; 
	function defInit() //-----used in Defalut.aspx on onLoad event
    {
	    //Check if this page runs EMBEDDED in a third party web site (was loaded from iframe or not).
	    var docPath = document.location;
	    var sDocPath = docPath.toString();
	    try 
        {
	        if (HasEmbParam(sDocPath))
	            return;

	        var parentPath = parent.document.location;
	        var sParentPath = parentPath.toString();
	        if (sParentPath == sDocPath) 
            {
	            //It does not run embedded
	            if (HasParams(sDocPath))
	                window.location.replace(sDocPath + "&Emb=N");
	            else
	                window.location.replace(sDocPath + "?Emb=N");
	        }
	        else 
            {
	            //it runs EMBEDDED in a third party web site
	            //this is for other browsers but IE --> because for IE it isthrowing exception when trying to access: parent.document.location
	            if (HasParams(sDocPath))
	                window.location.replace(sDocPath + "&Emb=Y");
	            else
	                window.location.replace(sDocPath + "?Emb=Y");
	        }
	    }
	    catch (e) 
        {
	        //this is for IE
	        //it runs EMBEDDED in a third party web site
	        if (HasParams(sDocPath))
	            window.location.replace(sDocPath + "&Emb=Y");
	        else
	            window.location.replace(sDocPath + "?Emb=Y");
	    }
	}
	function HasParams(spath) 
    {
	    var arr = spath.split("?");
	    if (arr.length == 2) return true;
	    return false;
	}
	function HasEmbParam(spath) 
    {
	    var arr = spath.split("?Emb=");
	    if (arr.length == 2) return true;
	    arr = spath.split("&Emb=");
	    if (arr.length == 2) return true;
	    return false;
	}
    //<--for default page
	function reinit()  //------used in LoginDispatch on onLoad event
    {
        try 
        {
	        var hddShow = GetCtrl('hddShow');
	        if (IsValid(hddShow) && hddShow.value == "1") 
            {
	            HideButton('strtLogDisp', true);
	            HideButton('strtReLogDisp', false);
	            var txtUserName = GetCtrl('txtUserName');
	            /* era:
	            if (IsValid(txtUserName) && txtUserName.disabled == false)
	            txtUserName.focus();
	            */
	            var txtPassword = GetCtrl('txtPassword');
	            var hddUP = document.getElementById('hddUP');
	            if (hddUP != null && hddUP != undefined && hddUP.value != "")
	                txtPassword.value = hddUP.value;

	            if (txtUserName.disabled == false && txtPassword.disabled == false && txtUserName.value != "" && txtPassword.value != "") 
                {
	                HideButton('btnLogon', false);
	                var btnLogon = GetCtrl('btnLogon');
	                if (btnLogon != null && btnLogon != undefined && btnLogon.disabled == false)
	                    btnLogon.focus();
	            }
	            else if (txtUserName.disabled == false)
	                txtUserName.focus();
	        }
	    }
	    catch (e) { }
	}
	function OnClickRelogin(sDir) {
	    try {
	        
            var txtPassword = GetCtrl('txtPassword');
	        var txtUserName = GetCtrl('txtUserName');
	        if (IsValid(txtPassword) && IsValid(txtUserName))
	            ReEvalCredentials(txtUserName.value, txtPassword.value, sDir);
	        return false;
	    }
	    catch (e) { }
	}
	function ReEvalCredentials(uid, psw, sDir) {
	    try {
	        var uidEncoded = encodeURIComponent(uid);
	        var pswEncoded = encodeURIComponent(psw);
	        var surl = "CredentialsChecker.aspx?UID=" + uid + "&PIS=" + psw + "&Dir=" + sDir;
	        $.post(surl, ReEvalCredentialsCallback, "json");
	    }
	    catch (ex) { }
	}
	function ReEvalCredentialsCallback(data, txtStatus) {
	    return GeneralEvalCredentialsCallback(data, txtStatus, false);
	}
	function ShowRelogin() {
	    try {
	        var hddShow = GetCtrl('hddShow');
	        if (IsValid(hddShow))
	            hddShow.value = "1";
	        return false;
	    }
	    catch (e) { }
	}
	function OnReJoinClick() {
	    try {
	        var questJoin = GetCtrl('questJoin');
	        if (IsValid(questJoin))
	            questJoin.style.display = 'none';
	        //DisableCtrlByID('txtSHipmentAWB', false);
	        DisableCtrlByID('txtUserName', false);
	        DisableCtrlByID('txtPassword', false);
	        OnClickRelogin("3");
	        return true;
	    }
	    catch (ex) { }
	}
	//<--------------former Relogin.js
	//--------------->former Shutdown.js
    function IsClosingBrowser(e) {
	    //capturing ALT + F4
	    if (!e) var e = window.event;
	    nKey = e.keyCode;
	    if (nKey == undefined || nKey == null)
	        nKey = e.which;

	    if (e.altKey == true && nKey == 0)
	        return true;
	    Xwidth = window.document.body.offsetWidth - e.clientX;
	    YHeight = e.clientY;
	    //if( Xwidth <= 30 && YHeight < 0 )
	    if (Xwidth < 0 && YHeight < 0)
	        return true;
	    return false;
	}
	//<---------------former Shutdown.js
