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,object, width, height)
{
    ShiftObjectTopLeftToWindowCenter(object);
    ShiftObjectCenterToCurrentTopLeft(window, object, width, height) 
}


function ShiftObjectTopLeftToWindowCenter(object) 
{   
    object.style.position = 'absolute';
    object.style.top = '50%';
    object.style.left = '50%';
}
 

function ShiftObjectCenterToCurrentTopLeft(window, object, width, height, xOffset, yOffset) 
{   
    var OriginalHeight = height;    
    if(window.document.documentElement.scrollTop != null)
    {
    
        height -= window.document.documentElement.scrollTop * 2         
    }
    
    object.style.marginLeft = "-" + parseInt(width / 2) + "px";    
    
    if(height <= 0)
    {
        if(window.document.documentElement.scrollTop > 0)
        {
            if((window.document.documentElement.scrollTop - OriginalHeight) > 0)
            { 
                object.style.marginTop = (window.document.documentElement.scrollTop - OriginalHeight / 2) + "px";
            }
        }
    }
    else
    {
        object.style.marginTop = "-" + parseInt(height / 2) + "px";    
    }
}


function ShowPopupOnTopWindow(window, clientId, width, height, shouldCenter) 
{
    var ParentWindow = window.top;
    ShowPopup(window, clientId, width, height, shouldCenter);
}
 

function ShowPopup(window, clientId, width, height, shouldCenter, shouldUseMouseCoordinates)
{
    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;
    }


    if (shouldCenter) 
    {
        CenterPopup(window,Popup, width, height);
    }


    if (shouldUseMouseCoordinates) 
    {
        var IE = window.document.all ? true : false

        if (IE) {
        
            Popup.style.left  = getMouseXY(window).X;
            Popup.style.top = getMouseXY(window).Y;   //- (height / 2);
        }
        else {
            Popup.style.left = getMouseXY(window, Event.MOUSEMOVE).X;
            Popup.style.top = getMouseXY(window, Event.MOUSEMOVE).Y;
        }
    }

    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 ShowImageDivPopup(imageUrl) 
{
    ShowPopup(window, '_ImagePopupDiv', -1, -1, false, true);
    var ImageElement = $get('_ImagePopupDivImage'); 
    ImageElement.src = imageUrl;
}


function getMouseXY(window, e) 
{
    var IE = window.document.all?true:false

    var MouseArgs = new Object();
    
    if (IE) 
    {
        if (event != null) {
        
            // grab the x-y pos.s if browser is IE
            MouseArgs.X = event.clientX + window.document.documentElement.scrollLeft;
            MouseArgs.Y = event.clientY + window.document.documentElement.scrollTop;
        }
    } 
    else 
    {  
        if(e != null)
        {
            // grab the x-y pos.s if browser is NS
            MouseArgs.X = e.pageX; //+ (document.documentElement.scrollLeft ? document.documentElement.scrollLeft : document.body.scrollLeft);
            MouseArgs.Y = e.pageY; //+ (document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop);
       }
    }
    
          
    // catch possible negative values in NS4
    if (MouseArgs.X < 0){MouseArgs.X = 0}
    if (MouseArgs.Y < 0){MouseArgs.Y = 0}  
   
  
    return MouseArgs;
}


function LoadIFrame(clientId, width, height, shouldCenter, url) {

    ShowPopup(window,clientId, width, height, shouldCenter, false);   
    window.document.getElementById(clientId).src = url;
}
    

function LoadIFrameOnParent(clientId, parentId, width, height, shouldCenter, url)
{ 
    var ParentWindow = window.top;

  
    ShowPopup(ParentWindow, clientId, width, height, shouldCenter, false);    
    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) {

            ShowPopup(window.top, authPanelId, -1, -1, false, false);   
        }
    
    
         
    }
   
}





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'] = PasswordTextBox.checked;
        
        }

              
        var PostBackText = GeneratePostBackPayloadText('', Dictionary);

        __doPostBack('LoginUser', PostBackText);
    }


    return true;
}

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 CheckEmailTextBoxSetEmailCookie(emailAddressTextBoxId, requireValidEmailAddress, invalidEmailMessage) {

    var EmailAddressTextBox = document.getElementById(emailAddressTextBoxId);
    if (EmailAddressTextBox != null && EmailAddressTextBox.value == '' && requireValidEmailAddress) {
        alert(invalidEmailMessage);
        EmailAddressTextBox.focus();
        return false;
    }
    
    if(EmailAddressTextBox.value != '')
    {
        SetCookie('Email', EmailAddressTextBox.value, 60);
    }


    return true;

}































