﻿var fieldPrompts = new Array();

function inputFocus(fieldObj) {
    if (fieldObj.className=='AuxText') {
        if (fieldObj.id=='_ctl0_Login_Password') {
            changeInputType('_ctl0_Login_Password', 'password');
            fieldObj = document.getElementById('_ctl0_Login_Password');
        }
        fieldPrompts[fieldObj.id] = fieldObj.value;
        fieldObj.value = '';
        fieldObj.className = 'MediumText';
        fieldObj.select();
        fieldObj.focus();
    }
}

function inputBlur(fieldObj) {
    if (fieldObj.value=='') {
        if (fieldObj.id=='_ctl0_Login_Password') {
            changeInputType('_ctl0_Login_Password', 'text');
            fieldObj = document.getElementById('_ctl0_Login_Password');
        }
        fieldObj.value = fieldPrompts[fieldObj.id];
        fieldObj.className = 'AuxText';
    }
}

function changeInputType(objID, oType) {
    var oldObject = document.getElementById(objID);
    var newObject = document.createElement('input');
    newObject.type = oType;
    if(oldObject.value) newObject.value = oldObject.value;
    if(oldObject.size) newObject.size = oldObject.size;
    if(oldObject.name) newObject.name = oldObject.name;
    if(oldObject.id) newObject.id = oldObject.id;
    if(oldObject.onfocus) newObject.onfocus = oldObject.onfocus;
    if(oldObject.onblur) newObject.onblur = oldObject.onblur;
    if(oldObject.className) newObject.className = oldObject.className;
    if(oldObject.onkeydown) newObject.onkeydown = oldObject.onkeydown;
    oldObject.parentNode.replaceChild(newObject,oldObject);
    return;
}

function reloadMenu(menuID, menuItemLabelsString, menuItemUrlsString, menuItemTargetsString) {
    var listElement = document.getElementById(menuID);
    if(listElement) {
        listElement.innerHTML = "";
        var menuItemLabels = menuItemLabelsString.split('|');
        var menuItemUrls = menuItemUrlsString.split('|');
        var menuItemTargets = menuItemTargetsString.split('|');
        for(var i = 0; i < menuItemLabels.length && i < menuItemUrls.length; i++) {
            listElement.innerHTML += "<li><a" + (Boolean(menuItemTargets[i]) ? " target=\"_blank\"" : "") + (menuItemUrls[i] != "" ? " href=\"" + menuItemUrls[i]  + "\"": "") + ">" + menuItemLabels[i] + "</a></li>";
        }
    }
}

function showHideDetail(controlID) {
    var control = document.getElementById(controlID);
    if(control.style.display == "none") {
        control.style.display = "block";
    }
    else {
        control.style.display = "none";
    }
}

function defaultButton(btn, event){

    var key;

    if(window.event)
         key = window.event.keyCode;     //IE
    else
         key = event.which;              //Firefox

    if (key == 13)
    {
        if (btn != null)
        { //If we find the button click it
            btn.click();
            event.keyCode = 0
        }
    }
}

function createCookie(name,value,days) {
    if (days) {
        var date = new Date();
        date.setTime(date.getTime()+(days*24*60*60*1000));
        var expires = "; expires="+date.toGMTString();
    }
    else var expires = "";
    document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
    var nameEQ = name + "=";
    var ca = document.cookie.split(';');
    for(var i=0;i < ca.length;i++) {
        var c = ca[i];
        while (c.charAt(0)==' ') c = c.substring(1,c.length);
        if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
    }
    return null;
}

function eraseCookie(name) {
    createCookie(name,"",-1);
}

function loadFontSize() {
    var fontSize = readCookie("fontsize");
    if(fontSize) {
        document.body.style.fontSize = fontSize + "em";
    }
    else { document.body.style.fontSize = "0.7em"; }
}

function changeFontSize(increaseFont) {
    var fontSize = readCookie("fontsize");
    if(!fontSize) { fontSize = "0.7"; }
    var newFontSize;
    if(increaseFont) {
         newFontSize = parseFloat(fontSize) + 0.05;                
    }
    else {
         newFontSize = parseFloat(fontSize) - 0.05;                
    }            
    document.body.style.fontSize = newFontSize + "em";
    createCookie("fontsize", newFontSize, 365);
}

function assignPageValidatorGroups(Page_Validators, validationGroup) {
    if (typeof(Page_Validators) != "undefined") {
        for (i = 0; i < Page_Validators.length; i++) {
            
        }
    }
}


String.prototype.trim = function() {
    return this.replace(/^\s+|\s+$/g,"");
}