﻿var pageloading = true; // we use this so the test suite tests don't time out

function pageLoaded(sender, args) {
    pageloading = false;
}

function initializeRequest(sender, args)
{
    pageloading = true;
}


var origNoticeText = null;

function LoginOpen(o) {
    var SignInLink = document.getElementById("ctl00_LoginView1_SignInLink");
    var LoginBox = document.getElementById("ctl00_LogIn_LoginBox");
    var SignInArea = document.getElementById("ctl00_SignInArea");
    var Navigation = document.getElementById("NavigationBox");
    var Notice = document.getElementById("Notice");

    if (origNoticeText == null && Notice != null) {
        origNoticeText = Notice.innerHTML;
    }
    
    LoginBox.style.top = "65px";

    if (SignInLink.innerHTML == "Log In") {
        if (Notice == null) {
            Navigation.style.visibility = "hidden";
        }
        LoginBox.style.left = SignInArea.offsetLeft + SignInArea.offsetWidth - 580 + "px";
        LoginBox.style.visibility = "visible";
        SignInLink.innerHTML = "[Close]";
        var txtBox = document.getElementById("ctl00_Login1_UserName");
        if (txtBox != null) txtBox.focus();
        
    }
    else {
        LoginBox.style.visibility = "hidden";
        if (Notice == null) {
            Navigation.style.visibility = "visible";
        }
        SignInLink.innerHTML = "Log In";
        
    }
}

function mouseOver(o, bColor) {
     o.style.borderBottom = '';
     o.style.backgroundColor = bColor;
     o.style.border = 'solid 1px lightgray';
     o.style.padding = '3px';
}
function mouseOut(o, bColor)
{
     o.style.backgroundColor = bColor;
     o.style.border = 'none';
     o.style.border = 'solid 1px lightgray';
     o.style.padding = '3px';
}

function checkKey() {
//      var keyCode = window.event.keyCode;
//     if (keyCode == 113) document.location = '';
}

document.onkeyup = checkKey;

$(document).ready(function () {
    var prm = Sys.WebForms.PageRequestManager.getInstance();
    prm.add_pageLoaded(pageLoaded);
    prm.add_initializeRequest(initializeRequest);
});
//$(document).ready(function() {
//     $("#MyTreeDiv A").contextMenu({
//          menu: 'myMenu'
//     }, function(action, el, pos) {
//          alert(
//               'Action: ' + action + '\n\n' +
//               'Element text: ' + $(el).text() + '\n\n' + 
//               'GUID: ' + getGUID($(el).attr("href")) + '\n\n' + 
//               'X: ' + pos.x + ' Y: ' + pos.y + ' (relative to element)\n\n' + 
//               'X: ' + pos.docX + ' Y: ' + pos.docY+ ' (relative to document)');
//          });
//});

function getGUID(mystr) {
     var reGUID = /\w{8}[-]\w{4}[-]\w{4}[-]\w{4}[-]\w{12}/g 
     var retArr = [];
     var retval = '';
     retArr = mystr.match(reGUID);
     if(retArr != null)
     {
          retval = retArr[retArr.length - 1];
     }
     return retval;
}

function AutoCompleteTextBox_itemSelected(sender, e)
{
     // alert('Key: ' + e.get_text() + ' val: ' + e.get_value());
     var controlId = sender._id;// "ctl00_Content_ctl00_Content_AutoText_AutoCompl"
     controlId = controlId.substr(6);
     controlId = controlId.substr(0, controlId.length - 15);
     // alert(controlId);
     
     var textBox = document.getElementById(controlId);
     
     __doPostBack(textBox.name, e.get_value());
}
               
function handleEnter(targetBtn, event)
{
     var keyCode = event.keyCode ? event.keyCode : event.which ? event.which : event.charCode;
     if (keyCode == 13) {
          document.getElementById(targetBtn).click();
          return false;
     }
     else
          return true;
 }
 // alert((new Date()).getTimezoneOffset());
 
 
 var timezone = jstz.determine_timezone(); // Now you have an instance of the TimeZone object.

if (document.cookie.indexOf("TimeZoneName=") == -1) {
    document.cookie = "TimeZoneName=" + timezone.name();

    if (document.cookie)
        document.location.reload(true);
}

// jquery example
//function timeFormatLocal(timeStr) {
//    var dt = new Date(timeStr);
//    return dt.toLocaleString();
//}

//    
//function timeReformatLocal(selector) { $(selector).each(function () { $(this).html(timeFormatLocal($(this).html())); }); }
