function StartupScripts() {

}  
    
    
function RefreshMainPage()
{
    RefreshMainPage('Reload');
}

function RefreshMainPage(action) 
{
    RefreshMainPage(action, null);
}

function RefreshMainPage(action, arguement) 
{
    if (window.parent != null) 
    {
        if (window.parent.location != null) 
        {
            window.parent.__doPostBack(action, arguement);
        }
    }

}


function RedirectParent(redirectUrl)
{
    if (window.parent != null) 
    {        
        window.location.href = redirectUrl;
        return;
    }
}


function ClosePopupAndRedirect(redirectUrl)
{    
    if(window.parent != null  && window.parent == self)
    {
        window.location.href = redirectUrl;
        return;
    }

    // We are in a popup window                                              
    window.parent.location.href = redirectUrl
    window.setTimeout('window.close()',10);    
    
}



function CenterPopup(window, clientId, width, height, topOffset) 
{

    var WindowTop = (GetWindowHeight(window) / 2 - height / 2);
    var WindowLeft = (GetWindowWidth(window) / 2 - width / 2);

    if (topOffset == null)
        topOffset = 0;

    WindowTop -= topOffset;

    WindowTop = 50;  //+= GetScrollTop(window);
    WindowLeft += GetScrollLeft(window);

    var object = window.document.getElementById(clientId);

    object.style.position = 'absolute'
    object.style.top = WindowTop + 'px'
    object.style.left = WindowLeft + 'px'
}


function GetScrollHeight(window) {

    if (window.document.documentElement && window.document.documentElement.scrollHeight) {
        return window.document.documentElement.scrollHeight;
    }

    return window.document.body.scrollHeight;
}


function GetScrollTop(window) {

    if (window.document.documentElement && window.document.documentElement.scrollTop) {
        return window.document.documentElement.scrollTop;
    }

    return window.document.body.scrollTop; 
}


function GetScrollLeft(window) {

    if (window.document.documentElement && window.document.documentElement.scrollLeft) 
    {
        return window.document.documentElement.scrollLeft;
    }

    return window.document.body.scrollLeft;
}


function GetWindowHeight(window) {

    if (window.document.body && window.document.body.clientHeight)
        return window.document.body.clientHeight;

    return window.document.documentElement.clientHeight;
}

function GetWindowWidth(window) {

    if (window.document.body && window.document.body.clientWidth)
        return window.document.body.clientWidth;

    return window.document.documentElement.clientWidth;
}

 

function ShowPopup(window, clientId, width, height)
{
    var Popup = window.document.getElementById(clientId);

    if (Popup == null) 
    {
        alert('Could not find popup for Id: ' + clientId);
        return;
    }


    if (width != undefined && width != -1) {
        Popup.width = width;
        Popup.style.width = width;
    }


    if (height != undefined && height != -1) {
        Popup.height = height;
        Popup.style.height = height;
    }

    CenterPopup(window, clientId, width, height);


    Popup.style.display = 'inline';
    Popup.style.visibility = 'visible';
}


function HideParentPopup(clientId)
{
    if(window == null)
        return;
        
    if(window.parent == null)
        return;

    window.parent.HidePopup(clientId);
}


function HidePopup(clientId)
{
    var Popup = $get(clientId);
    
    if(Popup != null)
        Popup.style.visibility = 'hidden';
}


function IsPopupVisible(clientId) 
{
    var Popup = $get(clientId);

    if (Popup != null) 
    {
        if (Popup.style.visibility == 'visible')
            return true;
    }

    return false;
}



function LoadIFrame(clientId, width, height, shouldCenter, url) {

    ShowPopup(window,clientId, width, height);   
    window.document.getElementById(clientId).src = url;
}
    

function LoadIFrameOnParent(clientId, parentId, width, height, shouldCenter, url)
{ 
    var ParentWindow = window.top;

    ShowPopup(ParentWindow, clientId, width, height);
    ParentWindow.document.getElementById(clientId).src = url;

}


function ToggleAuthenticationControlLoginButton(authPanelId, loginImageId) 
{
    if (IsPopupVisible(authPanelId)){
        HidePopup(authPanelId);
    }
    else 
    {
        // Position the control below the Login button
        var LoginImage = document.getElementById(loginImageId);
        var AuthPanel = document.getElementById(authPanelId);

        if (LoginImage != null && AuthPanel != null) {

            AuthPanel.style.position = 'absolute';
            AuthPanel.style.display = 'inline';
            AuthPanel.style.visibility = 'visible';             
        }
         
    }   
}


function getY(oElement) {
    var iReturnValue = 0;
    while (oElement != null) {
        iReturnValue += oElement.offsetTop;
        oElement = oElement.offsetParent;
    }
    return iReturnValue;
}


function getX(oElement) {
    var iReturnValue = 0;
    while (oElement != null) {
        iReturnValue += oElement.offsetLeft;
        oElement = oElement.offsetParent;
    }
    return iReturnValue;
}


function IsAuthenticationControlValidCausePostback(userNameTextBoxId, passwordTextBoxId, rememberMeCheckBoxId, userNameErrorMessage, passwordErrorMessage) {

    if (IsAuthenticationControlValid(userNameTextBoxId, passwordTextBoxId, userNameErrorMessage, passwordErrorMessage)) {
        var Dictionary = new Array();
        
        var UserNameTextBox = document.getElementById(userNameTextBoxId);
        if (UserNameTextBox != null && UserNameTextBox.value != null) {
            Dictionary['UserName'] = UserNameTextBox.value;
        }
        
        var PasswordTextBox = document.getElementById(passwordTextBoxId);
        if (PasswordTextBox != null && PasswordTextBox.value != null) {
            Dictionary['Password'] = PasswordTextBox.value;
        }

        var RememberMeCheckBox = document.getElementById(rememberMeCheckBoxId);
        if (RememberMeCheckBox != null && RememberMeCheckBox.checked == true) {
            Dictionary['ShouldRememberMe'] = RememberMeCheckBox.checked;        
        }

              
        var PostBackText = GeneratePostBackPayloadText('', Dictionary);

        __doPostBack('LoginUser', PostBackText);
    }

    return true;
}


function SendDeleteTicketPostBack(ticketId) {

    var Dictionary = new Array();
    Dictionary['TicketId'] = ticketId;

    var PostBackText = GeneratePostBackPayloadText('', Dictionary);

    __doPostBack('DeleteTicket', PostBackText);
 
}


function PostLogoutUser() {

    __doPostBack('LogoutUser', '');    
}



function IsAuthenticationControlValid(userNameTextBoxId, passwordTextBoxId, userNameErrorMessage, passwordErrorMessage) 
{
    var UserNameTextBox = document.getElementById(userNameTextBoxId);
    if (UserNameTextBox != null && UserNameTextBox.value == '') {
        alert(userNameErrorMessage);
        UserNameTextBox.focus();
        return false;
    }


    var PasswordTextBox = document.getElementById(passwordTextBoxId);
    if (PasswordTextBox != null && PasswordTextBox.value == '') {
        alert(passwordErrorMessage);
        PasswordTextBox.focus();
        return false;
    }

    return true;
}


function fadeBackground(elementId, startColor, endColor, timeMs) {
    var startTime = new Date().getTime();

    function stepFade(elementId, startColor, endColor, startTime, endTime) {
        var now = new Date().getTime();

        var step = new Array(3);
        
        var progress = (now - startTime) / (endTime - startTime);

        step[0] = Math.round(startColor[0] + ((endColor[0] - startColor[0]) * progress));
        step[1] = Math.round(startColor[1] + ((endColor[1] - startColor[1]) * progress));
        step[2] = Math.round(startColor[2] + ((endColor[2] - startColor[2]) * progress));

        if (document.getElementById(elementId) == null)
            return;

        document.getElementById(elementId).style.backgroundColor
            = "rgb(" + step[0] + "," + step[1] + "," + step[2] + ")";

        if (now <= endTime) {
            setTimeout(function() {
                stepFade(elementId, startColor, endColor, startTime, endTime);
            }, 20);
        }
        else {
            document.getElementById(elementId).style.backgroundColor
                = "rgb(" + endColor[0] + "," + endColor[1] + "," + endColor[2] + ")";
        }
    }

    stepFade(elementId, startColor, endColor, startTime, startTime + timeMs);
}



var today = new Date();
var expiry = new Date(today.getTime() + 365 * 24 * 60 * 60 * 1000);

function GetCookieVal(offset) {
    var endstr = document.cookie.indexOf(";", offset);
    if (endstr == -1) { endstr = document.cookie.length; }
    return unescape(document.cookie.substring(offset, endstr));
}

function GetCookie(name) {
    var arg = name + "=";
    var alen = arg.length;
    var clen = document.cookie.length;
    var i = 0;
    while (i < clen) {
        var j = i + alen;
        if (document.cookie.substring(i, j) == arg) {
            return GetCookieVal(j);
        }
        i = document.cookie.indexOf(" ", i) + 1;
        if (i == 0) break;
    }
    return null;
}

function DeleteCookie(name, path, domain) {
    if (GetCookie(name)) {
        document.cookie = name + "=" +
    ((path) ? "; path=" + path : "") +
    ((domain) ? "; domain=" + domain : "") +
    "; expires=Thu, 01-Jan-70 00:00:01 GMT";
    }
}

function SetCookie(name,value,expiredays){
    var exdate=new Date();
    exdate.setDate(exdate.getDate()+expiredays);
    document.cookie=name+ "=" +escape(value)+
    ((expiredays==null) ? "" : ";expires="+exdate.toGMTString());
}


function CheckEmailTextBoxPostBack(emailAddressTextBoxId, requireValidEmailAddress, invalidEmailMessage, parentIds) 
{
    var EmailAddressTextBox = document.getElementById(emailAddressTextBoxId);
    if (EmailAddressTextBox != null && EmailAddressTextBox.value == '' && requireValidEmailAddress) 
    {
        alert(invalidEmailMessage);
        EmailAddressTextBox.focus();
        return false;
    }

    if (parentIds == null) {
        return false;
    }

    if (VerifySelectionsAreFinished(parentIds) == false)
        return null;


    if (EmailAddressTextBox.value == null || EmailAddressTextBox.value == '') {
        return false;
    }

    return EmailAddressTextBox.value;
}


function WriteFlashObjectToDiv(divName, imagePath, flashObjectName, width, height, flashVersion, bgcolor) 
{
    var FlashObject = new SWFObject(imagePath, flashObjectName, width, height, flashVersion, bgcolor);
    FlashObject.write(divName);
}


























