
var isIE  = (navigator.appVersion.indexOf("MSIE") != -1) ? true : false;
var isWin = (navigator.appVersion.toLowerCase().indexOf("win") != -1) ? true : false;
var isOpera = (navigator.userAgent.indexOf("Opera") != -1) ? true : false;

var m_zIndex = 1;

if(isIE && document.execCommand)
{
    try
    {
        document.execCommand("BackgroundImageCache", false, true);
    }
    catch(exc)
    {
        alert(exc);
    }
}

function arrayContains(p_Array, p_Element)
{
    if(p_Array != null)
    {
        for(var i = 0; i < p_Array.length; i++)
        {
            if(p_Array[i] == p_Element)
            {
                return true;
            }
        }
    }
    return false;
}

function getNamedElements(p_ParentElement)
{
    var l_Array = new Array();
    
    if(p_ParentElement != null)
    {
        var l_Children = p_ParentElement.children;
        
        if(l_Children != null)
        {
            for(var i = 0; i < l_Children.length; i++)
            {
                var l_Element = l_Children[i];
                
                if(l_Element != null)
                {
                    if((l_Element.name != null) && (l_Element.name != ""))
                    {
                        l_Array.push(l_Element);
                    }
                    
                    var l_SubElements = getNamedElements(l_Element);

                    if((l_SubElements != null) & (l_SubElements.length > 0))
                    {
                        l_Array = l_Array.concat(l_SubElements);
                    }
                }
            }
        }
    }
    else
    {
        alert("Invalid Argument Exception\np_ParentElement should not be null\nFunction getNamedElements");
    }    
    
    return l_Array;
}

function getQueryString(p_ParentElementId)
{
    var l_QueryString = new Array();
    var l_AvoidDuplicates = new Array();
    
    var l_ParentElement = document.getElementById(p_ParentElementId);
    
    var l_NamedElements = getNamedElements(l_ParentElement);
    
    for(i = 0; i < l_NamedElements.length; i++)
    {
        var l_Element = l_NamedElements[i];
        var l_TagName = l_Element.tagName.toLowerCase();
        var l_Name = l_Element.name;
        var l_Value = "";
        
        if(l_Name != "")
        {
            switch(l_TagName)
            {
                case "input":
                    switch(l_Element.type)
                    {
                        case "checkbox":
                            if(l_Element.checked)
                            {
                                l_Value = l_Element.value;
                            }
                            break;
                            
                        case "radio":
                            if(!arrayContains(l_AvoidDuplicates, l_Name))
                            {
                                var l_Options = document.getElementsByName(l_Name);
                                
                                if(l_Options != null)
                                {
                                    if(l_Options.length != null)
                                    {
                                        for(var j = 0; j < l_Options.length; j++)
                                        {
                                            if(l_Options[j].checked)
                                            {
                                                l_Value = l_Options[j].value;
                                                break;
                                            }
                                        }
                                    }
                                    else
                                    {
                                        l_Value = l_Options.value;
                                    }
                                }
                                else
                                {
                                    l_Value = "";
                                }
                                
                                l_AvoidDuplicates.push(l_Name);
                            }
                            else
                            {
                                l_Name = ""; // keep this item from being added to the array
                            }
                            break;
                        
                        default:
                            l_Value = l_Element.value;
                            break;                        
                    }
                    break;
                
                case "select":
                    var l_SelectElement = l_Element;
                    
                    if(!l_SelectElement.multiple)
                    {
                        for(j = 0; j < l_SelectElement.options.length; j++)
                        {
                            var l_Option = l_SelectElement.options[j];
                            
                            if(l_Option.selected)
                            {
                                l_Value = l_Option.value;
                                break;
                            }
                        }
                    }
                    else
                    {
                        for(j = 0; j < l_SelectElement.options.length; j++)
                        {
                            var l_Option = l_SelectElement.options[j];
                            
                            if((l_Option.selected) && (l_Option.name != ""))
                            {
                                l_QueryString.push(l_Option.name + "=" + escape(l_Option.value));
                            }
                        }
                        l_Value = ""; // no specific value when multiple is set
                    }
                    break;
            }
            
            if((l_Name != null) && (l_Name != ""))
            {
                l_QueryString.push(l_Name + "=" + escape(l_Value));
            }
        }
    }
    
    return l_QueryString.join("&");
}

function getHashFromString(p_String)
{
    var l_Hash = new Array();
    var l_Lines = p_UserInfo.split("§");

    for(i = 0; i < l_Lines.length; i++)
    {        
        var l_KeyValuePair = l_Lines[i];
        var l_DelimiterIndex = l_KeyValuePair.indexOf("=");
        
        if(l_DelimiterIndex >= 0)
        {
            l_KeyName = l_KeyValuePair.substr(0, l_DelimiterIndex);
            l_Value = l_KeyValuePair.substr(l_DelimiterIndex + 1);
            
            l_Hash[l_KeyName] = l_Value;
        }
    }
    
    return l_Hash;
}

function startsWith(p_FullString, p_StartString)
{
    if(p_FullString.substr(0, p_StartString.length) == p_StartString)
    {
        return true;
    }
    else
    {
        return false;
    }
}

function getOptionValue(p_OptionName)
{
    var l_Element = document.getElementsByName(p_OptionName);
    
    if(l_Element != null)
    {
        if(l_Element.length != null)
        {
            var i;
            
            for(i = 0; i < l_Element.length; i++)
            {
                if(l_Element[i].checked)
                {
                    return l_Element[i].value;
                }
            }
        }
        else
        {
            return l_Element.value;
        }
    }
    else
    {
        return "";
    }
}

function validateTime(p_Field)
{
    var l_Time = document.getElementById(p_Field).value;
    var l_DoubleDot = l_Time.indexOf(":");
    
    if(l_DoubleDot > 0)
    {
        var l_Hours = Number(l_Time.substring(0, l_DoubleDot));
        var l_Minutes = Number(l_Time.substring(l_DoubleDot + 1));
        
        if (!isNaN(l_Hours) && !isNaN(l_Minutes))
        {
            if((l_Hours >= 0) && (l_Hours <= 23) && (l_Minutes >= 0) && (l_Minutes <= 59))
            {
                l_Hours = "0" + l_Hours;
                l_Minutes = "0" + l_Minutes;
                var newValue = l_Hours.substr(l_Hours.length - 2) + ":" + l_Minutes.substr(l_Minutes.length - 2);
                document.getElementById(p_Field).value = newValue;
                return true;
            }
        }
    }
    alert("The time you specified is invalid");
    return false;
}

function validateField(p_ElementID)
{
    try
    {
        var l_Element = document.getElementById(p_ElementID);
        
        if(l_Element == null)
        {
            alert("Element not found: " + p_ElementID);
            
            return false;
        }
        else if(l_Element.value == "")
        {
            alert("Field \"" + document.getElementById(p_ElementID).title + "\" is required.");
            document.getElementById(p_ElementID).focus();
            
            return false;
        }

        return true;
    }
    catch(exc)
    {
        alert(exc);
        
        return false;
    }
}    

function alertAndFocus(p_AlertMessage, p_ElementToFocus)
{
    alert(p_AlertMessage);
    setElementFocus(p_ElementToFocus);
    return false;
}

function strZero(p_Number, p_Width)
{
    var l_String = p_Number.toString();
    
    if(l_String.length < p_Width)
    {
        var l_Zeroes = "0";
        
        while(l_String.length + l_Zeroes.length < p_Width)
        {
            l_Zeroes = l_Zeroes + '0';
        }
        
        return l_Zeroes + l_String;
    }
    else
    {
        return l_String;
    }    
}

var m_TimeoutHandle;

function AsyncExecute(p_AspxScript, p_Arguments)
{
    window.clearTimeout(m_TimeoutHandle);

    var l_PeriscopixHome = "";
    
    if(p_AspxScript.substr(0, 1) == "/")
    {
        l_PeriscopixHome = document.getElementById("PeriscopixHome");
        l_PeriscopixHome = ( l_PeriscopixHome != null ? l_PeriscopixHome.value : "" );
    }

    document.getElementById("AsyncIFrame").src = l_PeriscopixHome + p_AspxScript + ".aspx?" + p_Arguments;
}

function AsyncExecutePost(p_AspxScript, p_Arguments)
{
    window.clearTimeout(m_TimeoutHandle);

    var l_PeriscopixHome = "";
    
    if(p_AspxScript.substr(0, 1) == "/")
    {
        l_PeriscopixHome = document.getElementById("PeriscopixHome");
        l_PeriscopixHome = ( l_PeriscopixHome != null ? l_PeriscopixHome.value : "" );
    }

    var l_Form = document.forms[0];
    l_Form.action = l_PeriscopixHome + p_AspxScript + ".aspx";
    l_Form.method = "post";
    
    if(p_Arguments != null)
    {
        var l_Arguments = p_Arguments.split("&");

        for(var i = 0; i < l_Arguments.length; i++)
        {
            var l_Argument = l_Arguments[i];
            var l_EqIndex = l_Argument.indexOf("=");
            
            if(l_EqIndex > 0)
            {
                var l_ArgumentName = l_Argument.substr(0, l_EqIndex);
                var l_ArgumentValue = l_Argument.substr(l_EqIndex + 1);
                
                var l_Element = document.getElementById(l_ArgumentName);
                
                if(l_Element != null)
                {
                    l_Element.value = unescape(l_ArgumentValue);
                }
                else
                {
                    l_Html = "<input type=hidden id=\"" + l_ArgumentName + "\" name=\"" + l_ArgumentName + "\" value=\"" + l_ArgumentValue + "\">";
                    l_Element = document.createElement(l_Html);
                    l_Form.appendChild(l_Element);
                }
            }
        }
    }
    
    l_Form.submit();
}

function resetTimeouts() // <- Timeouts because in the future we may have multiple timeouts to handle
{
    try
    {
    }
    catch(exc)
    {
    }
}

function getAbsoluteTop(p_Element)
{
    var l_Top = getOffsetTop(p_Element);    
    var l_OffsetParent = p_Element.offsetParent;
    
    while(l_OffsetParent != null)
    {     
        l_Top += getOffsetTop(l_OffsetParent);
        l_OffsetParent = l_OffsetParent.offsetParent;
    }
    
    return l_Top;
}

function getScreenTop(p_Element)
{
    var l_Top = getOffsetTop(p_Element);    
    var l_OffsetParent = p_Element.offsetParent;
    
    while(l_OffsetParent != null)
    {     
        l_Top += getOffsetTop(l_OffsetParent);
        
        if(l_OffsetParent.offsetParent != null)
        {
            l_OffsetParent = l_OffsetParent.offsetParent;
        }
        else
        {
            l_OffsetParent = getFrameElement(l_OffsetParent);
        }
    }
    
    return l_Top;
}

function getFrameElement(p_Element)
{
    if(p_Element != null)
    {
        var l_Document = p_Element.document;
        
        if(l_Document != null)
        {
            var l_ParentWindow = l_Document.parentWindow;
            
            if(l_ParentWindow != null)
            {
                return l_ParentWindow.frameElement;
            }
        }
    }
    
    return null;
}

function getOffsetTop(p_Element)
{
    if(p_Element != null)
    {
        var l_OffsetTop = p_Element.offsetTop;
        
        if(l_OffsetTop != null)
        {
            return l_OffsetTop;
        }
    }
    
    return 0;
}

function getAbsoluteLeft(p_Element)
{
    var l_Left = getOffsetLeft(p_Element);
    var l_OffsetParent = p_Element.offsetParent;
    
    while(l_OffsetParent != null)
    {        
        l_Left += getOffsetLeft(l_OffsetParent);
        l_OffsetParent = l_OffsetParent.offsetParent;
    }
    
    return l_Left;
}

function getScreenLeft(p_Element)
{
    var l_Left = getOffsetLeft(p_Element);
    var l_OffsetParent = p_Element.offsetParent;
    
    while(l_OffsetParent != null)
    {        
        l_Left += getOffsetLeft(l_OffsetParent);
        
        if(l_OffsetParent.offsetParent != null)
        {
            l_OffsetParent = l_OffsetParent.offsetParent;
        }
        else
        {
            l_OffsetParent = getFrameElement(l_OffsetParent);
        }
    }
    
    return l_Left;
}

function getOffsetLeft(p_Element)
{
    if(p_Element != null)
    {
        var l_OffsetLeft = p_Element.offsetLeft;
        
        if(l_OffsetLeft != null)
        {
            return l_OffsetLeft;
        }
    }
    
    return 0;
}
 
function getEventTarget(e)
{
    if(e != null)
    {
        if(e.target == null)
        {
            return e.srcElement;
        }
        else
        {
            return e.target;
        }
    }
    else if(window.event != null)
    {
        return window.event.srcElement;
    }
    else
    {
        return null;
    }
}

function Today()
{
    var l_Today = new Date(Date());
    return new Date(l_Today.getFullYear(), l_Today.getMonth(), l_Today.getDate());
}

//function trim(p_Text)
//{
//    if(p_Text != null)
//    {
//        while((p_Text != "") && (p_Text.substr(0, 1) == " "))
//        {
//            p_Text = p_Text.substr(1);
//        }
//        while((p_Text != "") && (p_Text.substr(p_Text.length - 1, 1) == " "))
//        {
//            p_Text = p_Text.substr(0, p_Text.length - 1);
//        }
//        return p_Text;
//    }
//    else
//    {
//        return "";
//    }
//}

function parseDateValue(p_Date)
{
    if(p_Date != null)
    {
        p_Date = trim(p_Date);
        
        var l_Space = p_Date.indexOf(" ");
        
        if(l_Space >= 0)
        {
            p_Date = p_Date.substr(p_Date, l_Space);
        }    
        
        var l_Delimiter = p_Date.indexOf("/");
        
        if(l_Delimiter >= 0)
        {
            return parseDateValueDelimiter(p_Date, "/");
        }

        l_Delimiter = p_Date.indexOf("-");
        
        if(l_Delimiter >= 0)
        {
            return parseDateValueDelimiter(p_Date, "-");
        }        
    }

    return NaN;    
}

function parseDateValueDelimiter(p_Date, p_Delimiter)
{
    var l_DateComponents = p_Date.split(p_Delimiter);
    
    if(l_DateComponents.length == 3)
    {
        var l_Days = Number(l_DateComponents[0]);
        var l_Months = Number(l_DateComponents[1]);
        var l_Years = Number(l_DateComponents[2]);
        
        if(l_Years < 100)
        {
            l_Years = l_Years + 2000;
        }
        
        if(!isNaN(l_Days) && !isNaN(l_Days) && !isNaN(l_Days))
        {
            var l_DateValue = new Date();
            l_DateValue.setFullYear(l_Years);
            l_DateValue.setMonth(l_Months - 1);
            l_DateValue.setDate(l_Days);
            
            return l_DateValue.valueOf();
        }
        else
        {
            return NaN;
        }
    }
    else
    {
        return NaN;
    }
}

function dateToString(p_DateValue)
{
    var l_Day = p_DateValue.getDate();
    var l_Month = p_DateValue.getMonth() + 1;
    var l_Year = p_DateValue.getFullYear();
    
    return strZero(l_Day, 2) + "/" + strZero(l_Month, 2) + "/" + strZero(l_Year, 4);
}

function exQuoted(p_Source)
{
    return "\"" + p_Source + "\"";
}

function exSingQuoted(p_Source)
{
    return "'" + p_Source + "'";
}

function toInteger(p_Source)
{
    try
    {
        var l_Value = Number(p_Source);
        
        return isNaN(l_Value) ? 0 : l_Value;
    }
    catch(exc)
    {
        return 0;
    }
}

function gotoLocation(p_Location)
{
    var l_PeriscopixHome = document.getElementById("PeriscopixHome");

    l_PeriscopixHome = ( l_PeriscopixHome != null ? l_PeriscopixHome.value : "" );
    
    if(p_Location == null)
    {
        p_Location = "/Welcome.aspx"
    }    
    
    window.open(l_PeriscopixHome + p_Location, "_self");
}

function gotoHome()
{
    gotoLocation("/Welcome.aspx");
}

function goBack()
{
    window.history.back();
}

function getElementValue(p_Element, p_DefaultValue)
{
    var l_Element;
    
    if(typeof(p_Element) == "string")
    {
        l_Element = document.getElementById(p_Element);
    }
    else    
    {
        l_Element = p_Element;
    }
    
    if(l_Element != null)
    {
        try
        {
            if(l_Element.tagName == "SELECT")
            {
                return getSelectedOptionValue(l_Element);
            }
            else
            {
                return l_Element.value;
            }
        }
        catch(exc)
        {
            return p_DefaultValue;
        }
    }
    else
    {
        return p_DefaultValue;
    }
}

function setElementValue(p_Element, p_Value)
{
    var l_Element;
    
    if(typeof(p_Element) == "string")
    {
        l_Element = document.getElementById(p_Element);
    }
    else    
    {
        l_Element = p_Element;
    }
   
    if(l_Element != null)
    {
        try
        {
            if(l_Element.type == "checkbox")
            {
                l_Element.checked = (p_Value == true) || (p_Value == "on") || (p_Value == l_Element.value);
            }
            else
            {
                l_Element.value = p_Value;
            }
        }
        catch(exc)
        {
        }
    }
}

function setElementSrc(p_Element, p_Value)
{
    var l_Element;
    
    if(typeof(p_Element) == "string")
    {
        l_Element = document.getElementById(p_Element);
    }
    else    
    {
        l_Element = p_Element;
    }
   
    if(l_Element != null)
    {
        try
        {
            l_Element.src = p_Value;
        }
        catch(exc)
        {
        }
    }
}

function setInnerText(p_Element, p_Text)
{
    var l_Element = p_Element;

    if(typeof(l_Element) == "string")
    {
        l_Element = document.getElementById(l_Element);
    }

    if(l_Element != null)
    {
        try
        {
            if(l_Element.innerText != null)
            {
                l_Element.innerText = p_Text;
            }
            else if(l_Element.textContent != null)
            {
                l_Element.textContent = p_Text;
            }
        }
        catch(exc)
        {
        }
    }
}

function getInnerText(p_Element)
{
    var l_Element = p_Element;

    if(typeof(l_Element) == "string")
    {
        l_Element = document.getElementById(l_Element);
    }

    if(l_Element != null)
    {
        try
        {
            var l_InnerText = l_Element.innerText;
            
            if(l_InnerText != null)
            {
                return l_InnerText;
            }
            else
            {
                return l_Element.textContent;
            }
        }
        catch(exc)
        {
        }
    }
}

function getSelectedOptionText(p_Element)
{
    if(typeof(p_Element) == "string")
    {
        p_Element = document.getElementById(p_Element);
    }
    
    if((p_Element != null) && (p_Element.options != null))
    {
        var l_SelectedIndex = p_Element.selectedIndex;
        
        if(l_SelectedIndex != null)
        {
            var l_Option = p_Element.options[l_SelectedIndex];
            
            if(l_Option != null)
            {
                return l_Option.text;
            }
        }
    }
}

function setElementOptionByValue(p_Element, p_Value)
{
    if(typeof(p_Element) == "string")
    {
        p_Element = document.getElementById(p_Element);
    }

    if((p_Element != null) && (p_Element.options != null))
    {
        for(var i = 0; i < p_Element.options.length; i++)
        {
            var l_Option = p_Element.options[i];
            
            if((l_Option != null) && (l_Option.value == p_Value))
            {
                l_Option.selected = true;
                
                return;
            }
        }        
    }
}

function setElementOptionByText(p_Element, p_Text)
{
    if(typeof(p_Element) == "string")
    {
        p_Element = document.getElementById(p_Element);
    }

    if((p_Element != null) && (p_Element.options != null))
    {
        for(var i = 0; i < p_Element.options.length; i++)
        {
            var l_Option = p_Element.options[i];
            
            if((l_Option != null) && (l_Option.text == p_Text))
            {
                l_Option.selected = true;
                
                return;
            }
        }        
    }
}

function getSelectedOptionValue(p_Element)
{
    if(typeof(p_Element) == "string")
    {
        p_Element = document.getElementById(p_Element);
    }
    
    if((p_Element != null) && (p_Element.options != null))
    {
        var l_SelectedIndex = p_Element.selectedIndex;
        
        if(l_SelectedIndex != null)
        {
            var l_Option = p_Element.options[l_SelectedIndex];
            
            if(l_Option != null)
            {
                return l_Option.value;
            }
        }
    }
}

function setElementVisible(p_ElementId, p_Visible)
{
    var l_Element = null;

    if(typeof(p_ElementId) == "string")
    {
        l_Element = document.getElementById(p_ElementId);
    }    
    else
    {
        l_Element = p_ElementId;
    }
    
    if(l_Element != null)
    {
        try
        {
            l_Element.style.display = p_Visible ? "inline" : "none";
        }
        catch(exc)
        {
        }
    }
}

var m_UseInline = false

function setElementVisible2(p_Element, p_Visible, p_DisplayString)
{
    var l_Element;
    
    if(typeof(p_Element) == "string")
    {
        l_Element = document.getElementById(p_Element);
    }
    else
    {   
        l_Element = p_Element;
    }

    if(l_Element != null)
    {
        try
        {
            if(p_DisplayString == null)
            {
                p_DisplayString = "inline";
            }
        
            l_Element.style.display = p_Visible ? (m_UseInline ? "inline" : p_DisplayString) : "none";
        }
        catch(exc)
        {
            m_UseInline = true;
            l_Element.style.display = p_Visible ? "inline" : "none";
        }
    }
}

function setElementEnabled(p_Element, p_Enabled)
{
    try
    {
        if(typeof(p_Element) == "string")
        {
            p_Element = document.getElementById(p_Element);
        }
        
        if(p_Element != null)
        {
            p_Element.disabled = !p_Enabled;
        }
    }
    catch(exc)
    {
    }
}

function getElementEnabled(p_Element)
{
    try
    {
        if(typeof(p_Element) == "string")
        {
            p_Element = document.getElementById(p_Element);
        }
        
        if(p_Element != null)
        {
            return !p_Element.disabled;
        }
    }
    catch(exc)
    {
    }

    return false; // <- false by default if no element is found
}

function setElementClass(p_Element, p_ClassName)
{
    try
    {
        if(typeof(p_Element) == "string")
        {
            p_Element = document.getElementById(p_Element);
        }
        
        if(p_Element != null)
        {
            p_Element.className = p_ClassName;
        }
    }
    catch(exc)
    {
    }
}

function getElementClass(p_Element, p_ClassName)
{
    try
    {
        if(typeof(p_Element) == "string")
        {
            p_Element = document.getElementById(p_Element);
        }
        
        if(p_Element != null)
        {
            return p_Element.className;
        }
    }
    catch(exc)
    {
    }

    return null;
}

function getRadioOption(p_ElementName)
{
    var l_Elements = document.getElementsByName(p_ElementName);

    if(l_Elements != null)
    {
        for(var i = 0; i < l_Elements.length; i++)
        {
            if(l_Elements[i].checked)
            {            
                return l_Elements[i];
            }
        }
    }    
    return null;
}

function getRadioOptionValue(p_ElementName, p_DefaultValue)
{
    var l_SelectedOption = getRadioOption(p_ElementName);
    
    if(l_SelectedOption != null)
    {
        return l_SelectedOption.value;
    }
    else
    {   
        return p_DefaultValue;
    }
}

function setRadioOption(p_ElementName, p_Value)
{
    var l_Elements = document.getElementsByName(p_ElementName);

    if(l_Elements != null)
    {
        for(var i = 0; i < l_Elements.length; i++)
        {
            if(l_Elements[i].value == p_Value)
            {            
                l_Elements[i].checked = true;
                return;
            }
        }
    }    
}

function toggleCheck(p_Element)
{
    if(typeof(p_Element) == "string")
    {
        var l_Element = document.getElementById(p_Element);
        
        if(l_Element != null)
        {
            toggleCheck(l_Element);
        }
    }
    else
    {
        if(p_Element != null)
        {
            try
            {
                var l_CurrentState = p_Element.checked;
                
                if(l_CurrentState != null) // otherwise this object does not have the checked property
                {
                    p_Element.checked = ! l_CurrentState;
                }
            }
            catch(exc) // ignore exceptions
            {
            }    
        }
    }
}

function getChecked(p_Element)
{
    return getElementChecked(p_Element);
}

function getElementChecked(p_Element)
{
    try
    {
        if(typeof(p_Element) == "string")
        {
            p_Element = document.getElementById(p_Element);
        }
        
        if(p_Element != null)
        {
            return p_Element.checked; // true, false or null if the object does not support the "checked" property
        }
    }
    catch(exc)
    {
    }
}

function setElementChecked(p_Element, p_State)
{
    setChecked(p_Element, p_State);
}

function setChecked(p_Element, p_State)
{
    if(typeof(p_Element) == "string")
    {
        var l_Element = document.getElementById(p_Element);
        
        if(l_Element != null)
        {
            setChecked(l_Element, p_State);
        }
    }
    else
    {
        if((p_Element != null) && (p_Element.checked != null))
        {
            try
            {
                if(p_State == null)
                {
                    p_State = true;
                }
                
                p_Element.checked = p_State;
            }
            catch(exc) // ignore exceptions
            {
            }    
        }
    }
}

function setElementFocus(p_Element, p_Select)
{
    var l_Element = getElementFromId(p_Element);
    
    if(l_Element != null)
    {
        try
        {
            l_Element.focus();
            
            if(p_Select == true)
            {
                l_Element.select();
            }
        }
        catch(exc)
        {
        }
    }
}

function getElementFromId(p_Element)
{
    if(typeof(p_Element) == "string")
    {  
        return document.getElementById(p_Element);
    }
    else
    {
        return p_Element;
    }
}

function autoExecOnLoad()
{
    var l_PeriscopixHome = getElementValue("PeriscopixHome") + "/images/";

    preLoadImage(l_PeriscopixHome + "Button.png");   
    preLoadImage(l_PeriscopixHome + "ButtonFocus.png");   
    preLoadImage(l_PeriscopixHome + "ButtonPressed.png");   
    preLoadImage(l_PeriscopixHome + "BiggerButton.png");   
    preLoadImage(l_PeriscopixHome + "BiggerButtonFocus.png");   
    preLoadImage(l_PeriscopixHome + "BiggerButtonPressed.png");   
}

function preLoadImage(p_ImageURL)
{
    var l_Image = new Image(109, 21);
    
    l_Image.src =  p_ImageURL;
}

function getRootElement()
{
    if(document.documentElement != null)
    {
        return document.documentElement;
    }
    else
    {
        return document.body;
    }
}

function getDocumentWidth()
{
    var l_RootElement = getRootElement();
    
    var l_Width = l_RootElement.clientWidth;
    
    return l_Width > 0 ? l_Width : l_RootElement.offsetWidth;
}

function getDocumentHeight()
{
    var l_RootElement = getRootElement();
    
    var l_Height = l_RootElement.clientHeight;
    
    return l_Height > 0 ? l_Height : l_RootElement.offsetHeight;
}

/*
function getBrowserWindowWidth()
{
    var l_DocElement = document.documentElement;
    
    if(l_DocElement != null)
    {
        var l_ClientWidth = l_DocElement.clientWidth;
        
        if((l_ClientWidth != null) && (l_ClientWidth > 0))
        {
            return l_ClientWidth;
        }
    }
    
    return screen.availWidth;
}
*/

function getCookieValue(p_CookieName, p_ValueName)
{
    var l_Cookies = document.cookie.replace("; ", ";").split(";");
   
    for(var j = 0; j < l_Cookies.length; j++)
    {
        var l_Cookie = l_Cookies[j];
        
        if(l_Cookie != "")
        {
            var l_Equals = l_Cookie.indexOf("=");
            var l_CookieName = l_Cookie.substr(0, l_Equals);
            
            if(l_CookieName == p_CookieName)
            {
                if(p_ValueName == null)
                {
                    return l_Cookie.substr(l_Equals + 1);
                }
                else
                {
                    var l_CookieValues = l_Cookie.substr(l_Equals + 1).split("&");
                    
                    for(var i = 0; i < l_CookieValues.length; i++)
                    {
                        var l_ThisValue = l_CookieValues[i];
                        
                        l_Equals = l_ThisValue.indexOf("=");
                        
                        var l_ValueName = l_ThisValue.substr(0, l_Equals);
                        
                        if(l_ValueName == p_ValueName)
                        {
                            return l_ThisValue.substr(l_Equals + 1);
                        }                    
                    }

                    return "";
                }
            }
        }
    }

    return "";
}

function cancelBubble(e)
{
    if(window.event != null)
    {
        window.event.cancelBubble = true;
    }
    else if(e != null)
    {
        try
        {            
            e.stopPropagation();
        }
        catch(exc)
        {
        }
    }
}

// Removes leading whitespaces

function leftTrim( value ) 
{
    if(value != null)
    {
        var l_StartIndex = 0;
        
        while(l_StartIndex < value.length)
        {
            var l_CharCode = value.charCodeAt(l_StartIndex);
            
            if((l_CharCode <= 32) || (l_CharCode == 160))
            {
                l_StartIndex++;
            }
            else
            {
                break;
            }
        }
        
        if(l_StartIndex < value.length)
        {
            return value.slice(l_StartIndex);
        }
        else
        {
            return "";
        }    
    }
}

// Removes ending whitespaces

function rightTrim( value ) 
{	
    if(value != null)
    {
        var l_EndIndex = value.length - 1;
        
        while(l_EndIndex >= 0)
        {
            var l_CharCode = value.charCodeAt(l_EndIndex);
            
            if((l_CharCode <= 32) || (l_CharCode == 160))
            {
                l_EndIndex++;
            }
            else
            {
                break;
            }
        }
        
        if(l_EndIndex >= 0)
        {
            return value.substr(0, l_EndIndex + 1);
        }
        else
        {
            return "";
        }    
    }
}

// Removes leading and ending whitespaces

function trim(value) 
{
	return leftTrim(rightTrim(value));
}

// ========================================================
// GET PIXEL LEFT/TOP/WIDTH/HEIGHT
// ========================================================

function getPixelLeft(p_Element)
{
    var l_PixelLeft = p_Element.style.pixelLeft;
    
    if(l_PixelLeft == null)
    {
        l_PixelLeft = p_Element.style.left;
        
        if(l_PixelLeft != null)
        {
            l_PixelLeft = Number(l_PixelLeft.replace("px", ""));
            
            if(isNaN(l_PixelLeft))
            {
                l_PixelLeft = null;
            }
        }

        if(l_PixelLeft == null)
        {
            l_PixelLeft = l_PixelLeft.offsetLeft;
        }
    }    
    
    return l_PixelLeft;
}

function getPixelTop(p_Element)
{
    var l_PixelTop = p_Element.style.pixelTop;
    
    if(l_PixelTop == null)
    {
        l_PixelTop = p_Element.style.top;
        
        if(l_PixelTop != null)
        {
            l_PixelTop = Number(l_PixelTop.replace("px", ""));
            
            if(isNaN(l_PixelTop))
            {
                l_PixelTop = null;
            }
        }

        if(l_PixelTop == null)
        {
            l_PixelTop = l_PixelTop.offsetTop;
        }
    }    
    
    return l_PixelTop;
}

function getPixelWidth(p_Element)
{
    var l_PixelWidth = p_Element.style.pixelWidth;
    
    if(l_PixelWidth == null)
    {
        l_PixelWidth = p_Element.style.width;
        
        if(l_PixelWidth != null)
        {
            l_PixelWidth = Number(l_PixelWidth.replace("px", ""));
            
            if(isNaN(l_PixelWidth))
            {
                l_PixelWidth = null;
            }
        }

        if(l_PixelWidth == null)
        {
            l_PixelWidth = l_PixelWidth.offsetWidth;
        }
    }    
    
    return l_PixelWidth;
}

function getPixelHeight(p_Element)
{
    var l_PixelHeight = p_Element.style.pixelHeight;
    
    if(l_PixelHeight == null)
    {
        l_PixelHeight = p_Element.style.height;
        
        if(l_PixelHeight != null)
        {
            l_PixelHeight = Number(l_PixelHeight.replace("px", ""));
            
            if(isNaN(l_PixelHeight))
            {
                l_PixelHeight = null;
            }
        }

        if(l_PixelHeight == null)
        {
            l_PixelHeight = l_PixelHeight.offsetHeight;
        }
    }    
    
    return l_PixelHeight;
}

function generateFlashObject(p_Swf, p_ObjectId, p_Width, p_Height, p_BgColor, p_ClassName, p_FlashVars, p_Transparent, p_sAlign)
{
    document.write("<object id='" + p_ObjectId + "' classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000' codebase='http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=5,0,0,0' width='" + p_Width + "' height='" + p_Height + "' class='" + p_ClassName + "'>\n");
    document.write("    <param name='movie' value='" + p_Swf + "'/>\n");
    document.write("    <param name='menu' value='false'/>\n");
    document.write("    <param name='quality' value='best'/>\n");
    document.write("    <param name='bgcolor' value='" + p_BgColor + "'/>\n");
    document.write("    <param name='allowScriptAccess' value='always'/>\n");
    document.write("    <param name='allowFullScreen' value='false'/>\n");
    document.write("    <param name='sAlign' value='" + p_sAlign + "'/>\n");
    
    var l_FlashVars = "";
    
    if((p_FlashVars != null) && (p_FlashVars != ""))
    {
        document.write("    <param name='flashvars' value='" + p_FlashVars + "'/>\n");
        l_FlashVars = "flashvars='" + p_FlashVars + "'";
    }
    
    var l_wMode = "";
    
    if(p_Transparent)
    {
        document.write("    <param name='wmode' value='transparent'/>\n");
        l_wMode = "wmode='transparent'";
    }
    
    document.write("    <embed src='" + p_Swf + "' menu='false' quality='best' " + l_FlashVars + "  " + l_wMode + " bgcolor='" + p_BgColor + "' salign='" + p_sAlign + "' allowScriptAccess='always' allowFullScreen='false' width='" + p_Width + "' height='" + p_Height + "' type='application/x-shockwave-flash' pluginspage='http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash'>\n");
    document.write("    </embed>\n");
    document.write("</object>\n");
}

// ========================================================
// SUPPORT TO ELEMENT DRAG 
// ========================================================

var m_DragApproved = false;
var m_DragZ;
var m_DragX
var m_DragY;
var m_DragTempX;
var m_DragTempY;

function DragMove(event)
{
    var l_Event = event != null ? event : window.event;
    
    if(l_Event != null)
    {
        if((l_Event.button == 1) && (m_DragApproved))
        {
            m_DragZ.style.left = (m_DragTempX + l_Event.clientX - m_DragX) + "px";
            m_DragZ.style.top = (m_DragTempY + l_Event.clientY - m_DragY) + "px";
            
            return false;
        }
    }
}

function Drags()
{
    if (document.all != null)
    {
        if (event.srcElement.className == "drag")
        {
            l_DragApproved = true;
            m_DragZ = event.srcElement;
            m_DragTempX = getPixelLeft(m_DragZ);
            m_DragTempY = getPixelTop(m_DragZ);
            m_DragX = event.clientX;
            m_DragY = event.clientY;
        }
    }
}

document.onmousemove = DragMove;
document.onmousedown = Drags;
document.onmouseup = new function() { m_DragApproved = false };


////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//
//  TOP TOOLBAR
//
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

function mouseOverTab(e)
{
    getEventTarget(e).className = "TabCellFocus";
}

function mouseOutTab(e)
{
    getEventTarget(e).className = "TabCellStyle";
}

var m_Direction = -4;
var m_CurrentValue = 254;

function blinkEffect()
{
    var l_Element = document.getElementById("TabTr");

    l_Element.style.color = "#" + m_CurrentValue.toString(16) + m_CurrentValue.toString(16) + m_CurrentValue.toString(16);
    
    if(m_CurrentValue > 250)
    {
        m_Direction = -4;
    }
    else if(m_CurrentValue < 210)
    {
        m_Direction = 4;
    }
    
    m_CurrentValue += m_Direction;
    
    window.setTimeout("blinkEffect()", 50, "Javascript");
}

function mouseClickTab(p_Address)
{
    var l_OpenAddress = true;
    
    try
    {
        l_OpenAddress = beforeSwitchingTab(p_Address);
    }
    catch(exc)
    {
    }
    
    if(l_OpenAddress)
    {
        window.open(p_Address, "_self");
    }
}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//
//  CREATE RANDOM FRAME
//
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

function createRandomFrame()
{
    var l_FrameName = "Frame_" + Math.round(Math.random() * 65535);
            
    var l_Frame;
    
    try
    {
        l_Frame = document.createElement("<iframe name='" + l_FrameName + "' frameBorder='0'>");
    }
    catch(exc)
    {
        l_Frame = document.createElement("iframe");
    }

    l_Frame.id = l_FrameName;
    l_Frame.name = l_FrameName;
    l_Frame.style.display = "none";

    document.body.appendChild(l_Frame);
    
    return l_Frame;
}

function deleteObject(p_Object)
{
    var l_Object;

    if(typeof(p_Object) == "string")
    {
        l_Object = document.getElementById(p_Object);
    }
    else
    {
        l_Object = p_Object;
    }
    
    if(l_Object != null)
    {
        var l_Parent = l_Object.parentNode;
        
        if(l_Parent != null)
        {
            try
            {
                l_Parent.removeChild(l_Object);
            }
            catch(exc)
            {
                alert(exc);
            }
        }
    }
}

function fixFrameScrolling(p_Element)
{
    if(isIE == false)
    {
        var l_Element;

        if(typeof(p_Element) == "string")
        {
            l_Element = document.getElementById(p_Element);
        }
        else    
        {
            l_Element = p_Element;
        }

        if(l_Element != null)
        {
            try
            {
                l_Element.style.overflowY = "scroll";
            }
            catch(exc)
            {
            }
        }
    }
}





function getScrollTop()
{
    var l_WorkArea = getRootElement();
    
    if(l_WorkArea != null)
    {        
        return l_WorkArea.scrollTop != null ? l_WorkArea.scrollTop : 0;
    }
    else
    {
        return 0;
    }
}

function formatAsCurrency(p_Value, p_Decimals)
{
    var l_Value = Number(p_Value);
    
    if(isNaN(l_Value) == false)
    {
        return l_Value.toFixed(p_Decimals != null ? p_Decimals : 2);
    }
    else
    {
        return p_Value;
    }    
}

function formatElementAsCurrency(p_Element, p_Decimals)
{
    var l_Value = Number(p_Element.value);
    
    if(isNaN(l_Value) == false)
    {
        p_Element.value = l_Value.toFixed(p_Decimals != null ? p_Decimals : 2);
        return true;
    }
    else
    {
        return false;
    }
}

// Google Tracking Code

function gaTrackPageView()
{
	try 
	{
		var pageTracker = _gat._getTracker("UA-10062719-1");
		pageTracker._trackPageview();
		pageTracker._trackEvent("Test Category", "Test Action", "Test Label (Value=1)", 1);
	} 
	catch(err) 
	{
	    alert(err);
	}
}

