﻿
function GetAttributeValue(attribList, attribName, firstDelim,secondDelim) 
{

    var attribNameLowerCase = attribName.toLowerCase();
    if (attribList) 
    {
        var attribArr = attribList.split(firstDelim);
        for (var i = 0, loopCnt = attribArr.length; i < loopCnt; i++) 
        {
            var nameValueArr = attribArr[ i ].split(secondDelim);
            for (var j = 0, loopCnt2 = nameValueArr.length; j < loopCnt2;j++) 
            {
                if (nameValueArr[0].toLowerCase().replace(/\s/g, '') == attribNameLowerCase && loopCnt2 > 1) 
                {
                    return nameValueArr[1];
                }
            }
        }
     }
}

// ********** POP-UPS **********
function popup(strPage, intWidth, intHeight, strOptions) {
    var intTop = (screen.height - intHeight) / 2;
    var intLeft = (screen.width - intWidth) / 2;
    window.open(strPage, "", "top=" + intTop + ",left=" + intLeft + ",width=" + intWidth + ",height=" + intHeight + "," + strOptions);
    //  window.open(strPage, '', 'top=50, left=200, width=500, height=400, resizable=yes, toolbar=no, scrollbars=no, status=yes');
}
// ********** FIN POP-UPS **********

function GetQueryStringValue(varName) 
{
    return GetAttributeValue(window.location.search.substring(1), varName, '&', '=');
}




function ReadCookie(cookieName) {
 
     var theCookie=""+document.cookie;
     var ind=theCookie.indexOf(cookieName);
     
     if (ind==-1 || cookieName=="") return ""; 
     
     var ind1=theCookie.indexOf(';',ind);
     
     if (ind1==-1) ind1=theCookie.length; 
     
     return unescape(theCookie.substring(ind+cookieName.length+1,ind1));
 }

 function SetCookie(cookieName, cookieValue, nDays) {
     var today = new Date();
     var expire = new Date();
     if (nDays == null || nDays == 0) nDays = 1;
     expire.setTime(today.getTime() + 3600000 * 24 * nDays);
     document.cookie = cookieName + "=" + escape(cookieValue)
                 + ";expires=" + expire.toGMTString();
 }




function toggleDisabledStyle(element,display) {
//Will toggle a given element's display property between "none" and "block"
//hiding and unhiding it
    
    try {
//        alert('attempting to toggle ' + element +' to disabledStyle=' + display);
        if(display)
            element.style.display = "block";
        else 
            element.style.display = "none";
    }
    catch(E)
    { 
        alert(E)
    }
}

function toggleDisabledStyleInline(element, display) {
    //Will toggle a given element's display property between "none" and "inline"
    //hiding and unhiding it

    try {
        //        alert('attempting to toggle ' + element +' to disabledStyle=' + display);
        if (display)
            element.style.display = "inline";
        else
            element.style.display = "none";
    }
    catch (E) {
        alert(E)
    }
}


function toggleDisabled(element,toggle) {
//Will toggle a given element's disabled property 
//including all children    
    try {
//        alert('attempting to toggle ' + element +' to disabled=' + toggle);
        element.disabled = toggle;
    }
    catch(E)
    { 
//        alert(E)
    }
    
    if (element.childNodes && element.childNodes.length > 0) {
        for (var x = 0; x < element.childNodes.length; x++) {
            toggleDisabled(element.childNodes[x],toggle);
        }
    }
}



function clearValue(element) {
    
    try {
//        alert('attempting to clear ' + element);
        element.value = '';
    }
    catch(E)
    { 
        alert(E)
    }
    
}



function HistoryBack() {

    if (document.referrer != '')
        document.write('Thanks for visiting from ' + document.referrer);  
}

//Character counter
function charCount(tbElement, charCnt, maxLenght) {
    if (tbElement.value.length > maxLenght) tbElement.value = tbElement.value.substring(0, maxLenght);
    if (charCnt) charCnt.value = tbElement.value.length;
}

if (typeof(Sys) !== "undefined") Sys.Application.notifyScriptLoaded();

function showLayer(ShadowId, LayerId, width, height, left, top) {

    var shadow = document.getElementById(ShadowId);
    var question = document.getElementById(LayerId);

    question.style.width = width + 'px';
    question.style.height = height + 'px';
    question.style.left = left + 'px';
    question.style.top = top + 'px';


    shadow.style.display = 'block';
    question.style.display = 'block';

    shadow = null;
    question = null;
}

function hideLayer(ShadowId, LayerId) {
    var shadow = document.getElementById(ShadowId);
    var question = document.getElementById(LayerId);

    shadow.style.display = 'none';
    question.style.display = 'none';

    shadow = null;
    question = null;
}

function getWindowWidth() {
    var myWidth;

    if (typeof (window.innerWidth) == 'number') {
        //Non-IE 
        myWidth = window.innerWidth;
    } else if (document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight)) {
        //IE 6+ in 'standards compliant mode' 
        myWidth = document.documentElement.clientWidth;
    } else if (document.body && (document.body.clientWidth || document.body.clientHeight)) {
        //IE 4 compatible 
        myWidth = document.body.clientWidth;
    }

    return myWidth;
}

function getWindowHeight() {
    var myHeight;

    if (typeof (window.innerWidth) == 'number') {
        //Non-IE 
        myHeight = window.innerHeight;
    } else if (document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight)) {
        //IE 6+ in 'standards compliant mode' 
        myHeight = document.documentElement.clientHeight;
    } else if (document.body && (document.body.clientWidth || document.body.clientHeight)) {
        //IE 4 compatible 
        myHeight = document.body.clientHeight;
    }
    return myHeight;
}