﻿/* Scripts common to all the pages in EBO */

/*-----------------------------------DimmingDiv starts-----------------------------------------------------------------------------------------------------------------------------------------------------------*/

var DIV_DIMMER_ID = "dimmer"; //Id of the div element which is using to disable the whole page.
var DIV_DIMMER_NAME = "dimmer"; //Name of the div element which is using to disable the whole page.
var DIV_DIMMER_CLASS = "dimmer"; //Name of the css class which is using for the dimmer div.
var DIV_OPAQUE_DIMMER_CLASS = "opaque_dimmer";
var DIV_DIMMER_OPACITY = 0; //This value decides the level of transperencey.Value between 1-100.1 for full transperency.
var DIV_DIMMER_COLOR = "White"; //The color of the transeperent div.
var DIV_MODEL_ID = ""; //The id of the div element to be poped.This value will set when the user call the method 'ShowPopUpWindow'.
var SLIDINGSTYLE = "NONE"; // (Possible values - FOLD, NONE, TOP-BOTTOM-CENTRE, TOP-CENTRE)
//This parameter decide the style of appearance of the dialogue.
var SLIDING_INCRIMENT = 6; //Decides the rate of movement(in pixels )
var SLIDING_ADJUST = 24; //To make the shaking effect
var SLIDING_SPEED = 1; //Timer 
var DIV_FOLDER_ID = "folder"; //While implementing the foldingeffect we are using  div with this id.
var FOLDING_RATE = 8; // Specifies the rate of folding.
var CONST_HIDDEN_SELECT_CONTROL_IDS = ""; //If the browser if IE6, then have to hide all the selct boxes.
var CUSTOMFOCUS = false; //Determines whether want to specify focus to a control explicitly.
//If the value is false (which is the default value) the focus will set to dimmer div.

var OPAQUE = false;
var ZINDEX = 0;
var MATCHID = "";
//While doing this hiding keeping the ids of select boxes which are already invisible.

//This method set the possition of the content div(Dialogue) based on the constants passed to the method.
//(CENTRE-TOP, LEFT-TOP,RIGHT-TOP)
var loginNameInPopupEnterAlertMessage = "Please enter your Email address";
var loginNameInPopupEnterValidAlertMessage = "Please enter your valid Email address";
var loginNamePasswordMessage = "Please enter your password";
var loginNameInPopupAlertTitle = "Login";
var loginAlertBtnText = "";
function showLoginPopup() {
    document.getElementById("NonRestrictedHeader1_lblLoginError").innerHTML = "";
    SetDimmerDivProperties("Sliding Style", "NONE");
    SetDimmerDivProperties("Background Color", "black");
   
    document.getElementById('NonRestrictedHeader1_divLoginPopUp').style.display = "";
    document.getElementById("NonRestrictedHeader1_txtLoginName").focus();
    ShowPopUpWindow('NonRestrictedHeader1_loginPopup');
    document.getElementById('NonRestrictedHeader1_hdnLoginPopupTop').value = document.getElementById("NonRestrictedHeader1_loginPopup").style.top;
    document.getElementById('NonRestrictedHeader1_hdnLoginPopupLeft').value = document.getElementById("NonRestrictedHeader1_loginPopup").style.left;
    
  
    
//    document.getElementById("NonRestrictedHeader1_loginPopup").style.top = "35px";
//     document.getElementById("NonRestrictedHeader1_loginPopup").style.left = window.screen.width - 224 + "px";
    return false;
}
function hideDiv(e) {
    if (checkDiv) {
        checkDiv = false;
        document.getElementById('divSelectMatchType').style.display = "none";
    }
}
function ClosePopUp(divId) {
    CloseWindow(divId);
    return false;
}
function showDiv() {
    checkDiv = true;
    document.getElementById('divSelectMatchType').style.display = "";
}
//function showScoreOptions(e, isRestrictedHeader) {
//    var matchTypeSelectDiv = document.getElementById('divSelectMatchType');

//    //    if (matchTypeSelectDiv.style.display == "")
//    //    {
//    //        matchTypeSelectDiv.style.display = "none";
//    //        return;
//    //    }

//    //var elem = document.getElementById(e);
//    var elemHeight = e.offsetHeight;
//    var elemWidth = e.offsetWidth;
//    var virtualPath = "";
//    if (isRestrictedHeader) {
//        virtualPath = document.getElementById("RestrictedHeaderJob1_hdnVirtualPath").value;
//    }
//    else {
//        virtualPath = document.getElementById("NonRestrictedHeaderJob1_hdnVirtualPath").value;
//    }

//    var createLanguageList = "<div class=\"langinnerDiv\" style=\"width:140px\" id=\"intlScores\"><a href=\"" + virtualPath + "International-Cricket-Scores.aspx" + "\">International Matches</a></div>";
//    createLanguageList += "<div class=\"langinnerDiv\" style=\"width:140px\" id=\"clubScores\"><a href=\"" + virtualPath + "Club-Cricket-Scores.aspx" + "\">Club Matches</a></div>";
//    createLanguageList += "<div class=\"langinnerDiv\" style=\"width:140px\" id=\"schoolScores\"><a href=\"" + virtualPath + "Schools-College-Cricket-Scores.aspx" + "\">School Matches</a></div>";

//    //var langauge = document.getElementById("NonRestrictedHeader1_hdnCultures").value;
//    checkDiv = true;

//    matchTypeSelectDiv.innerHTML = createLanguageList;
//    matchTypeSelectDiv.style.left = getX(e) + elemHeight - 28 + "px";
//    matchTypeSelectDiv.style.top = getY(e) + elemHeight + 0 + "px";
//    matchTypeSelectDiv.style.display = "";
//    //document.onclick = function (){document.getElementById('divSelectMatchType').style.display='none';}
//}
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;
}

//document.onclick = hideScoresOption;
//function hideScoresOption(e) {
//    var browserName = navigator.appName;
//    var nn6 = browserName == "Microsoft Internet Explorer" ? false : true;
//    var clickedObj = nn6 ? e.target : event.srcElement;

//    var matchTypeSelectDiv = document.getElementById("divSelectMatchType");

//    if (matchTypeSelectDiv != null && clickedObj.id != "aScoreOptions" && clickedObj.id != "intlScores" && matchTypeSelectDiv.style.display == "") {
//        matchTypeSelectDiv.style.display = "none";
//        return;
//    }
//    hideLangaugesOption(e);
//}
//function hideLangaugesOption(e) {
//    var browserName = navigator.appName;
//    var nn6 = browserName == "Microsoft Internet Explorer" ? false : true;
//    var clickedObj = nn6 ? e.target : event.srcElement;
//    var langSelectDiv = document.getElementById("NonRestrictedHeaderJob1_dropDivLang");

//    if (langSelectDiv != null && clickedObj.id != "NonRestrictedHeaderJob1_lnkShowLanguages" && langSelectDiv.style.display == "") {
//        langSelectDiv.style.display = "none";
//        return;
//    }
//}

function AlignContentDiv(possition) {
    var arrayPageSize = GetPageSize();
    var contentDivSize = GetDivSize(DIV_MODEL_ID);
    var scrollValues = GetScrollValues();
    var top = (arrayPageSize[3] / 2) - (contentDivSize[1] / 2) + parseInt(scrollValues[3]);
    var left = (arrayPageSize[2] / 2) - (contentDivSize[0] / 2) + parseInt(scrollValues[2]);
    switch (possition) {
        case "CENTRE-TOP":
            SetPossition(left, scrollValues[3]);
            break;
        /* case "LEFT-TOP":
        SetPossition(scrollValues[2], scrollValues[3]);
        break;
        case "RIGHT-TOP":
        SetPossition(0, parseInt(scrollValues[0]) - contentDivSize[1]);
        break;*/ 
        default:
            alert("The option selected is not implemented.Please implement it in method AlignContentDiv.");
    }
}


//This method writes a div elements  into the document.
//These div elements are using to implement the dimming feature.

function BuildDimmerDiv() {
    //This div element is using to disable  the wole page.
    var divHtml = '<div  id = ' + DIV_DIMMER_ID + ' name = ' + DIV_DIMMER_NAME + ' class=' + DIV_DIMMER_CLASS + ' style="-moz-opacity: ' + (parseInt(DIV_DIMMER_OPACITY) / 100) + ';opacity: ' + (parseInt(DIV_DIMMER_OPACITY) / 100) + '; FILTER:chroma(color=#FFFFFF) allowTransparency alpha(opacity=' + parseInt(DIV_DIMMER_OPACITY) + ');BACKGROUND-COLOR:' + DIV_DIMMER_COLOR + ';width:100%; height:200px"></div>';
    document.write(divHtml);

    //This div element is using to im plement the folding effect.
    divHtml = '<div  id = ' + DIV_FOLDER_ID + ' name = ' + DIV_FOLDER_ID + ' class=' + DIV_DIMMER_CLASS + ' style="-moz-opacity: .3;opacity: .3; FILTER:chroma(color=#black) allowTransparency alpha(opacity=30);BACKGROUND-COLOR:white;width:10px; height:200px"></div>';
    document.write(divHtml);

    //This div element is using to disable  the wole page(Without transperancy).
    var divHtml = '<div  id = OPAQUE_' + DIV_DIMMER_ID + ' name = ' + DIV_DIMMER_NAME + ' class=' + DIV_OPAQUE_DIMMER_CLASS + ' style="BACKGROUND-COLOR:' + DIV_DIMMER_COLOR + ';width:100%; height:200px"></div>';
    document.write(divHtml);

}


//This mehod return an array with the information about the client browser.
//The elements in the array - 
//                           Browsername, BrowserVersion (eg: MSIE 6.0)
function GetBrowserInfo() {
    var browserName = "";
    var browserVersion = "";

    if (navigator.appVersion != null) {
        //navigator.appVersion is 4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.1.4322; .NET CLR 2.0.50727)
        var browserVersionDetails = navigator.appVersion.split(";");
        browserVersion = browserVersionDetails[1];
    }
    if (navigator.appName != null) {
        browserName = navigator.appName;
    }
    var browserInfo = new Array(browserName, browserVersion);
    return browserInfo;
}


//Disable the page before showing the dialogue.Disabling the page is achived by enabling a transperent div
//over the page.
function DisablePage() {
    if (OPAQUE == true) {
        DIV_DIMMER_ID = "OPAQUE_" + DIV_DIMMER_ID;
    }
    else {
        DIV_DIMMER_ID = DIV_DIMMER_ID.replace("OPAQUE_", "");
    }
    var browserInfo = GetBrowserInfo();
    var dimmerDiv = document.getElementById(DIV_DIMMER_ID);
    if (ZINDEX == 990) {
        dimmerDiv.style.zIndex = ZINDEX;
    }
    if (dimmerDiv) {
        dimmerDiv.style.left = '0px';
        dimmerDiv.style.top = '0px';

        var arrayPageSize = GetPageSize();
        dimmerDiv.style.height = arrayPageSize[5] + 'px';
        dimmerDiv.style.width = arrayPageSize[4] - 21 + 'px';

        //If the browser is IE 6 then hide all the select boxes.
        if (browserInfo[1].indexOf("MSIE 6.0") > -1) {
            CONST_HIDDEN_SELECT_CONTROL_IDS = "";
            SetControlVisibility("select", "hidden");
            dimmerDiv.style.height = arrayPageSize[1] + 'px';
            dimmerDiv.style.width = arrayPageSize[0] + 'px';
        }
        dimmerDiv.style.backgroundColor = DIV_DIMMER_COLOR;
        dimmerDiv.style.display = "block";
        if (!CUSTOMFOCUS) {
            //dimmerDiv.focus();
        }
    }
    window.onresize = AlignDimmerOnResize;
}

//Function adjusts the width and height of the div while resizing the window.
function AlignDimmerOnResize() {
    var dimmerDiv = document.getElementById(DIV_DIMMER_ID);
    var scrollValues = GetScrollValues();
    if (dimmerDiv) {
        if (dimmerDiv.style.display = "block") {
            dimmerDiv.style.left = '0px';
            dimmerDiv.style.top = '0px';
            var arrayPageSize = GetPageSize();
            dimmerDiv.style.height = arrayPageSize[5] + parseInt(scrollValues[1]) + 'px';
            dimmerDiv.style.width = arrayPageSize[4] + 'px';
        }
    }
}

//returns an array with scroll values.
function GetScrollValues() {
    var scrollWidth;
    var scrollHeight;
    var scrollLeft;
    var scrollTop;

    scrollWidth = document.body.scrollWidth;
    scrollHeight = document.body.scrollHeight;
    scrollLeft = document.body.scrollLeft;
    scrollTop = document.body.scrollTop;
    var browserInfo = GetBrowserInfo();
    if (browserInfo[1].indexOf("MSIE 6.0") > -1) {
        var arrayPageSize = GetPageSize();
        scrollWidth = arrayPageSize[0];
        scrollHeight = arrayPageSize[1];
        scrollLeft = document.documentElement.scrollLeft;
        scrollTop = document.documentElement.scrollTop;
    }
    if (window.pageYOffset)
    {  
	    scrollTop = window.pageYOffset 
	}
    else if(document.documentElement && document.documentElement.scrollTop)
    { 
	    scrollTop = document.documentElement.scrollTop; 
    } 
    else if(document.body)
    { 
	    scrollTop = document.body.scrollTop; 
    } 

    if(window.pageXOffset)
    { 
	    scrollLeft=window.pageXOffset 
    }
    else if(document.documentElement && document.documentElement.scrollLeft)
    { 
	    scrollLeft=document.documentElement.scrollLeft; 
    }
    else if(document.body)
    { 
	    scrollLeft=document.body.scrollLeft; 
    }
  
    scrollValues = new Array(scrollWidth, scrollHeight, scrollLeft, scrollTop);
    return scrollValues;
}

//This method set the visiblity of controls of a specific type.
//typeOfControl type of control to consider (eg select)
//visibility contains values 'visible' or 'hidden'.
//In case if we want to skip some controls from processing in this method please include the 
// attribute 'DialogueElement' with value 1 in the control tag(eg <input type="text" DialogueElement = '1' />)
function SetControlVisibility(typeOfControl, visibility) {
    //var controls = document.all.tags(typeOfControl);
    var controls = document.getElementsByTagName(typeOfControl);
    var control;
    for (index = 0; index < controls.length; index++) {
        control = controls[index];
        //Check whether we need to consider this control
        if (control.DialogueElement != "1") {
            if (visibility == "visible") {
                if (CONST_HIDDEN_SELECT_CONTROL_IDS.indexOf(control.Id) == -1) {
                    control.style.visibility = visibility;
                }
            }
            else if (visibility == "hidden") {
                //Check whether the control is visible or not.
                if (!IsControlVisible(control)) {
                    CONST_HIDDEN_SELECT_CONTROL_IDS = CONST_HIDDEN_SELECT_CONTROL_IDS + ";" + control.Id;
                }
                else {
                    control.style.visibility = visibility;
                }
            }
        }
    }
}

//Function to verify whether a control is visible.The control is passing as input.
//The method return true if the control is visible, else false.
function IsControlVisible(control) {
    var isVisible = true;
    if (control.style.visibility == "hidden") {
        isVisible = false;
    }
    if (control.style.display == "none") {
        isVisible = false;
    }
    return isVisible;
}

//Implement the folding effect by using a seperate div element.
function FoldContentdiv() {
    var arrayPageSize = GetPageSize();
    var arrayContentDivSize = GetDivSize(DIV_MODEL_ID);
    var folderDiv = document.getElementById(DIV_FOLDER_ID);
    folderDiv.style.zIndex = '990';
    folderDiv.style.width = arrayContentDivSize[0] + 'px';
    folderDiv.style.height = '10px';
    //folderDiv.style.top     = '0px';
    var scrollValues = GetScrollValues();
    folderDiv.style.top = scrollValues[3] + 'px';
    folderDiv.style.left = (arrayPageSize[0] / 2 - arrayContentDivSize[0] / 2) + 'px';
    folderDiv.style.display = 'block';
    ShowFold();
}

//Implementing the folding effect.
function ShowFold() {
    var folderDiv = document.getElementById(DIV_FOLDER_ID);
    var arrayFolderDivSize = GetDivSize(DIV_FOLDER_ID);
    var arrayContentDivSize = GetDivSize(DIV_MODEL_ID);
    var repeat = 0;
    /*if (parseInt(arrayFolderDivSize[0]) < parseInt(arrayContentDivSize[0]))
    {
    folderDiv.style.width   = parseInt(arrayFolderDivSize[0]) + 8 + "px";
    folderDiv.style.left    = parseInt(arrayFolderDivSize[2]) - 4 + "px";
    repeat = 1;
    }*/
    if (parseInt(arrayFolderDivSize[1]) < parseInt(arrayContentDivSize[1])) {
        folderDiv.style.height = (parseInt(arrayFolderDivSize[1]) + FOLDING_RATE) + "px";
        repeat = 1;
    }
    if (repeat == 1) {
        var t = setTimeout("ShowFold()", 0);
    }
    else {
        AlignContentDiv("CENTRE-TOP");
        SetContentdivDisplay("block");
        var t = setTimeout("RemoveWrapper()", 100);
    }
}

//Method to remove the folding div after displaying dialogue.
function RemoveWrapper() {
    var folderDiv = document.getElementById(DIV_FOLDER_ID);
    folderDiv.style.display = 'none';

}

//Method to enable the page in folding style.
function SlideFold() {
    var folderDiv = document.getElementById(DIV_FOLDER_ID);
    folderDiv.style.display = 'block';
    SetContentdivDisplay("none");
    FoldUp();
}

//Move the folder div upward to get the folding effect
function FoldUp() {
    var folderDiv = document.getElementById(DIV_FOLDER_ID);
    var arrayFolderDivSize = GetDivSize(DIV_FOLDER_ID);
    var arrayContentDivSize = GetDivSize(DIV_MODEL_ID);
    var repeat = 0;
    /*if (parseInt(arrayFolderDivSize[0])- 8 > 0)
    {
    folderDiv.style.width   = parseInt(arrayFolderDivSize[0]) - 8 + "px";
    folderDiv.style.left    = parseInt(arrayFolderDivSize[2]) + 4 + "px";
    repeat = 1;
    }*/
    if (parseInt(arrayFolderDivSize[1]) - FOLDING_RATE > 0) {
        folderDiv.style.height = (parseInt(arrayFolderDivSize[1]) - FOLDING_RATE) + "px";
        repeat = 1;
    }
    if (repeat == 1) {
        var t = setTimeout("FoldUp()", 0);
    }
    else {
        var folderDiv = document.getElementById(DIV_FOLDER_ID);
        folderDiv.style.display = 'none';
        SetDimmerDivdivDisplay("none");
    }
}

//Method to get the width, height, left, top of the  div.Id of the div element is passing as the input
function GetDivSize(divId) {
    var contentDiv = document.getElementById(divId);
    var width = 0;
    var height = 0;
    var left = 0;
    var top = 0;
    if (contentDiv) {
        width = contentDiv.style.width.replace('px', "");
        height = contentDiv.style.height.replace('px', "");
        left = contentDiv.style.left.replace('px', "");
        top = contentDiv.style.top.replace('px', "");
    }
    var contentDivSize = new Array(width, height, left, top);
    return contentDivSize;
}

//Method to get the possition of the content div.
function GetContentDivPossition() {

    var contentDiv = document.getElementById(DIV_MODEL_ID);
    var left = 0;
    var top = 0;
    if (contentDiv) {
        left = contentDiv.style.left.replace("px", "");
        top = contentDiv.style.top.replace("px", "");
    }
    var contentDivPossition = new Array(left, top);
    return contentDivPossition;
}

//This method will invoke automaticaly while loading the page.
//This method checks for all the requiremets and set up initial things for the  Dimmingdiv feature.
function InitialiseDimmingDiv() {
    BuildDimmerDiv();
}

//Possition the content div in centre of the window.
function PossitionInCentre() {
    var arrayPageSize = GetPageSize();
    var scrollValues = GetScrollValues();
    var contentDivSize = GetDivSize(DIV_MODEL_ID);
    //var top            = (arrayPageSize[1] / 2) - (contentDivSize[1] / 2) + parseInt(scrollValues[3]);
    //var left           = (arrayPageSize[0] / 2) - (contentDivSize[0] / 2) + parseInt(scrollValues[2]);alert(top);
    var top = (arrayPageSize[3] / 2) - (contentDivSize[1] / 2) + parseInt(scrollValues[3]);
    var left = (arrayPageSize[2] / 2) - (contentDivSize[0] / 2) + parseInt(scrollValues[2]);
    SetPossition(left, top);
    SetContentdivDisplay("block");
}

//Method to set the display style of the content div.
function SetContentdivDisplay(displayStyle) {
    var contentDiv = document.getElementById(DIV_MODEL_ID);
    if (contentDiv) {
        contentDiv.style.display = displayStyle;
    }
}
//Method to set the display style of the dimmer div.
function SetDimmerDivdivDisplay(displayStyle) {
    var contentDiv = document.getElementById(DIV_DIMMER_ID);
    if (contentDiv) {
        contentDiv.style.display = displayStyle;
    }
}


//Method to set the possition of the content div.The left and top possitions are passing to the function.
function SetPossition(left, top) {
    var contentDiv = document.getElementById(DIV_MODEL_ID);
    var arrayPageSize = GetPageSize();
    var contentDivSize = GetDivSize(DIV_MODEL_ID);
    var scrollValues = GetScrollValues();
    var isIE = document.all;
    if (contentDiv) {
        if (left == 'center') {
            //contentDiv.style.left  = (arrayPageSize[2] / 2) - (contentDivSize[0] / 2) + parseInt(scrollValues[2]) + 'px';
            if (isIE) {
                contentDiv.style.left = (window.screen.availWidth / 2) + document.documentElement.scrollLeft - (contentDivSize[0] / 2) + 'px';
            }
            else {
                contentDiv.style.left = (window.screen.availWidth / 2) + document.body.scrollLeft - (contentDivSize[0] / 2) + 'px';
            }
        }
        else {
            contentDiv.style.left = left + 'px';
        }
        if (top == 'center') {
            //contentDiv.style.top = (screen.availHeight - parseInt(contentDivSize[1])/2)/4;
            if (isIE) {
                contentDiv.style.top = (window.screen.availHeight / 2) + document.documentElement.scrollTop - 180 - (contentDivSize[1] / 2) + 'px';
            }
            else if (navigator.userAgent.toLowerCase().indexOf("firefox") != -1) {
                contentDiv.style.top = (window.screen.availHeight / 2) + document.documentElement.scrollTop - 180 - (contentDivSize[1] / 2) + 'px';
            }
            else {

                var h = document.body.scrollHeight - window.innerHeight;
                contentDiv.style.top = (window.screen.availHeight / 2) + h - 90 - (contentDivSize[1] / 2) + 'px';
            }
        }
        else {
            contentDiv.style.top = top + 'px';
        }

    }
}

//This method set the visibilty mode of the content window to visible.
function ShowContentWindow() {
    var contentDiv = document.getElementById(DIV_MODEL_ID);
    var arrayPageSize = GetPageSize();
    var scrollValues = GetScrollValues();
    var contentDivSize = GetDivSize(DIV_MODEL_ID);
    if (contentDiv) {
        switch (SLIDINGSTYLE) {
            case "NONE":
                PossitionInCentre();
                break;
            case "CENTER":
                SetPosition('center', 200);
                break;
            case "CUSTOM":
                //SetPossition(380, 10);
                SetPositionCenter();
                SetContentdivDisplay("block");
                break;
            case "TOP-CENTRE":
                AlignContentDiv("CENTRE-TOP");
                SetContentdivDisplay("block");
                SlideTopCentre();
                break;
            case "TOP-BOTTOM-CENTRE":
                AlignContentDiv("CENTRE-TOP");
                SetContentdivDisplay("block");
                SlideTopBottom();
                break;
            case "FOLD":
                AlignContentDiv("CENTRE-TOP");
                FoldContentdiv("block");
                break;
            case "BOTTOM_SCROLL_CENTER":
                SetPossition('center', 'center');
                break;
            case "CUSTOM-BOTTOM-CENTRE":
                SetPossition('center', 'center');
                AlignCenter();
                SetContentdivDisplay("block");
                break;
            case "CUSTOM-CENTRE":
                SetPossition(280, 100);
                SetContentdivDisplay("block");
                break;
            default:
                alert("The sliding style specified is not implemented.");

        }
    }
}

function AlignCenter() {
    var _run;
    if (navigator.userAgent.indexOf("Firebird") != -1 || navigator.userAgent.indexOf("Firefox") != -1 || navigator.appName == "Microsoft Internet Explorer")
    { _run = false; } //IE/Mozilla  
    else
    { _run = true; } //Safari
    if (_run == false) {
        window.onscroll = function() { ScrollWindow(); };
    }
    else if (_run == true) {
        ScrollOther();
    }
}

//Adjusting Div on Window.onscroll for IE/Mozilla       
function ScrollWindow() {
    var contentDiv = document.getElementById(DIV_MODEL_ID);
    if (contentDiv.style.display == "block") {
        SetPossition('center', 'center');
    }
}
//Adjusting Div on Window.onscroll for Safari       
function ScrollOther() {
    (document.getElementById) ? dom = true : dom = false;
    var contentDivSize = GetDivSize(DIV_MODEL_ID);
    var top;
    if (dom && !document.all) {
        top = (window.pageYOffset / 2) + (window.innerHeight - contentDivSize[1]);
    }
    if (document.all) {
        top = (window.screen.availHeight / 2) + document.documentElement.scrollTop - 90 - (contentDivSize[1] / 2);
    }
    document.getElementById(DIV_MODEL_ID).style.top = top + 'px';
    window.setTimeout("ScrollOther()", 50);
}
function SetPositionCenter() {
    var contentDiv = document.getElementById(DIV_MODEL_ID);

    var arrayPageSize = GetPageSize();
    var contentDivSize = GetDivSize(DIV_MODEL_ID);
    var scrollValues = GetScrollValues();
    var isIE = document.all;
    var screenWidth = arrayPageSize[2];
    var screenHeight = arrayPageSize[3];
    var divWidth = contentDivSize[0];
    var divHeight = contentDivSize[1];
    var top = parseInt(screenHeight) / 2 - parseInt(divHeight) / 2;
    //var top = (parseInt(screenHeight) - parseInt(divHeight)) - 35;
    var left = parseInt(screenWidth) / 2 - parseInt(divWidth) / 2;
    if (contentDiv) {
        contentDiv.style.left = left + 'px';

        if (scrollValues[0] > 0) {
            // navigator.user agent contains safari, mozilla, chrome expect internet explorer
            if (navigator.userAgent.toLowerCase().indexOf("safari") != -1) {
                contentDiv.style.top = top + document.body.scrollTop + 'px';
            }
            else {
                contentDiv.style.top = top + document.documentElement.scrollTop + 'px';
            }
        }
    }
}

//Method to set the possition of the content div.The left and top possitions are passing to the function.
function SetPosition(left, top) {
    var contentDiv = document.getElementById(DIV_MODEL_ID);
    var arrayPageSize = GetPageSize();
    var contentDivSize = GetDivSize(DIV_MODEL_ID);
    var scrollValues = GetScrollValues();
    var isIE = document.all;
    if (contentDiv) {
        if (left == 'center') {
            if (isIE) {
                contentDiv.style.left = (window.screen.availWidth / 2) - contentDiv.clientHeight + 'px';
            }
            else {

            }
        }
    }
}

//The developer can use this method to show the pop up window. The id of the window to be shown is passed as the parameter.
//The user has to define the content of the window to be poped in a Div and have to pass id of that div to this function.
function ShowPopUpWindow(windowId) {
    if (ValidateModelWindow(windowId)) {
        DisablePage();
        ShowContentWindow();
    }
}
//
function js_CheckEnterClick(btnId, e) {
    if (window.event) // IE
    {
        if (event.keyCode && event.keyCode == 13) {
            document.getElementById(btnId).focus();
        }
    }
    else if (e.which) // Netscape/Firefox/Opera
    {
        if (e.which && e.which == 13) {
            document.getElementById(btnId).focus();
        }
    }
}
function checkRequiredFieldsInPage() {
    var loginName = trim(document.getElementById('txtLoginName').value).toString();
    var loginPassword = trim(document.getElementById('txtLoginPassword').value).toString();

    if (loginName == '') {
        CreateCordiantAlertLogin(loginNameInPopupAlertTitle, loginNameInPopupEnterAlertMessage + '.', 'txtLoginName', null, loginAlertBtnText);
        return false;
    }
    else if (emailCheck(loginName) == false) {
    CreateCordiantAlertLogin(loginNameInPopupAlertTitle, loginNameInPopupEnterValidAlertMessage + '.', 'txtLoginName', null, loginAlertBtnText);
        return false;
    }
    else if (loginPassword == '') {
    CreateCordiantAlertLogin(loginNameInPopupAlertTitle, loginNamePasswordMessage + '.', 'txtLoginPassword', null, loginAlertBtnText);
        return false;
    }
    else {
        return true;
    }
}
function checkRequiredFieldsInPopup() {
    var loginName = trim(document.getElementById('NonRestrictedHeader1_txtLoginName').value).toString();
    var loginPassword = trim(document.getElementById('NonRestrictedHeader1_txtLoginPassword').value).toString();

    if (loginName == '') {
        CreateCordiantAlertLogin(loginNameInPopupAlertTitle, loginNameInPopupEnterAlertMessage + '.', 'NonRestrictedHeader1_txtLoginName', null, loginAlertBtnText);
        return false;
    }
    else if (emailCheck(loginName) == false) {
    CreateCordiantAlertLogin(loginNameInPopupAlertTitle, loginNameInPopupEnterValidAlertMessage + '.', 'NonRestrictedHeader1_txtLoginName', null, loginAlertBtnText);
        return false;
    }
    else if (loginPassword == '') {
    CreateCordiantAlertLogin(loginNameInPopupAlertTitle, loginNamePasswordMessage + '.', 'NonRestrictedHeader1_txtLoginPassword', null, loginAlertBtnText);
        return false;
    }
    else {
        return true;
    }

}
function CloseWindow(windowId) {
    DIV_MODEL_ID = windowId;
    EnablePage();
}

function SlideTopCentre() {
    var arrayPageSize = GetPageSize();
    var scrollValues = GetScrollValues();
    var contentDivSize = GetDivSize(DIV_MODEL_ID);
    var divPossition = GetContentDivPossition();
    var center = (arrayPageSize[3] / 2) - (contentDivSize[1] / 2) + parseInt(scrollValues[3]);

    //if ( parseInt(divPossition[1]) + parseInt(contentDivSize[1]) + SLIDING_INCRIMENT <  parseInt(arrayPageSize[1]))
    if (parseInt(divPossition[1]) + parseInt(contentDivSize[1]) + SLIDING_INCRIMENT < parseInt(scrollValues[1])) {
        //if (parseInt(divPossition[1]) + SLIDING_INCRIMENT <  (arrayPageSize[1] / 2) - (contentDivSize[1] / 2) + SLIDING_ADJUST)
        if (parseInt(divPossition[1]) + SLIDING_INCRIMENT < center + SLIDING_ADJUST) {
            SetPossition(divPossition[0], parseInt(divPossition[1]) + parseInt(SLIDING_INCRIMENT));
            var t = setTimeout("SlideTopCentre()", SLIDING_SPEED);
        }
        else {
            SlideDownCentre();
        }
    }
}

function SlideTopBottom() {
    var arrayPageSize = GetPageSize();
    var contentDivSize = GetDivSize(DIV_MODEL_ID);
    var divPossition = GetContentDivPossition();
    var slidingValues = GetScrollValues();
    var bottom = parseInt(slidingValues[3] + arrayPageSize[3]);
    //if ( parseInt(divPossition[1]) + parseInt(contentDivSize[1]) + parseInt(SLIDING_INCRIMENT) <  parseInt(arrayPageSize[1]))
    if (parseInt(divPossition[1]) + parseInt(contentDivSize[1]) + parseInt(SLIDING_INCRIMENT) < bottom) {
        SetPossition(divPossition[0], parseInt(divPossition[1]) + parseInt(SLIDING_INCRIMENT));
        var t = setTimeout("SlideTopBottom()", SLIDING_SPEED);
    }
    else {
        SlideDownCentre();
    }
}

function SlideDownCentre() {
    var arrayPageSize = GetPageSize();
    var contentDivSize = GetDivSize(DIV_MODEL_ID);
    var divPossition = GetContentDivPossition();
    var slidingValues = GetScrollValues();
    var center = (arrayPageSize[3] / 2) - (contentDivSize[1] / 2) + parseInt(scrollValues[3]);
    if (parseInt(divPossition[1]) - parseInt(SLIDING_INCRIMENT) > center) {
        SetPossition(divPossition[0], parseInt(divPossition[1]) - parseInt(SLIDING_INCRIMENT));
        var t = setTimeout("SlideDownCentre()", SLIDING_SPEED);
    }
    else {
        PossitionInCentre();
    }
}

function SlideDownTop() {
    var arrayPageSize = GetPageSize();
    var contentDivSize = GetDivSize(DIV_MODEL_ID);
    var divPossition = GetContentDivPossition();
    var slidingValues = GetScrollValues();

    if (parseInt(divPossition[1]) - parseInt(SLIDING_INCRIMENT) > slidingValues[3]) {
        SetPossition(divPossition[0], parseInt(divPossition[1]) - parseInt(SLIDING_INCRIMENT));
        var t = setTimeout("SlideDownTop()", SLIDING_SPEED);
    }
    else {
        SetContentdivDisplay("none");
        SetDimmerDivdivDisplay("none");
    }
}


//This method validates the window to be poped up.The window is actually a div tag.The id of the div is passed by the user.
//
function ValidateModelWindow(windowId) {
    var contentDiv = document.getElementById(windowId);
    //Check whether the window to be shown is exist.
    if (windowId == null) {
        alert('The Dialogue to be poped is not found, please verify the id passed to the method ShowPopUpWindow');
        return false;
    }
    //The window to be poped is valid.Set the id of the window to be poped to the constant.
    DIV_MODEL_ID = windowId;
    return true;
}




//To set the properties for customising the dimming div feature appearance.
function SetDimmerDivProperties(property, value) {
    switch (property) {
        case "Background Color":
            DIV_DIMMER_COLOR = value;
            break;
        case "Sliding Style":
            SLIDINGSTYLE = value;
            break;
        case "Sliding Delay":
            SLIDING_SPEED = value;
            break;
        case "CUSTOM FOCUS":
            CUSTOMFOCUS = value;
            break;
        case "OPAQUE":
            OPAQUE = value;
            break;
        case "Z-INDEX":
            ZINDEX = value;
            break;
        case "MATCHID":
            MATCHID = value;
            break;
        default:
            alert(property + "not defined");
    }
}


//Enabling the page when the user close the dialogue.
function EnablePage() {
    window.onresize = "";
    var browserInfo = GetBrowserInfo();
    //If the browser is IE 6 then hide all the select boxes.
    if (browserInfo[1].indexOf("MSIE 6.0") > -1) {
        SetControlVisibility("select", "visible");
    }
    switch (SLIDINGSTYLE) {
        case "NONE":
            SetContentdivDisplay("none");
            SetDimmerDivdivDisplay("none");
            break;
        case "CUSTOM":
            SetPossition(0, 0);
            SetContentdivDisplay("none");
            SetDimmerDivdivDisplay("none");
            break;
        case "TOP-BOTTOM-CENTRE":
            SlideDownTop();
            break;
        case "TOP-CENTRE":
            SlideDownTop();
            break;
        case "FOLD":
            SlideFold();
            break;
        case "CUSTOM-BOTTOM-CENTRE":
            SetContentdivDisplay("none");
            SetDimmerDivdivDisplay("none");
            break;
        case "BOTTOM_SCROLL_CENTER":
            SetContentdivDisplay("none");
            SetDimmerDivdivDisplay("none");
            break;
        case "CUSTOM-CENTRE":
            SetContentdivDisplay("none");
            SetDimmerDivdivDisplay("none");
            break;
    }
}


// Returns array with page width, height and window width, height
function GetPageSize() {
    var xScroll, yScroll;

    var scrollWidth, scrollHeight;

    isIE = document.all;
    //For Height
    if (isIE) {
        if (document.body.scrollHeight > document.body.clientHeight || document.body.scrollHeight > window.screen.height) {
            scrollHeight = document.body.scrollHeight;
        }
        else if (document.body.scrollHeight < window.screen.height) {
            scrollHeight = window.screen.availHeight;
        }
        else {
            scrollHeight = document.body.clientHeight;
        }
    }
    else {
        scrollHeight = document.body.scrollHeight;
    }
    //For Width
    if (isIE) {
        if (document.body.scrollWidth > document.body.clientWidth || document.body.scrollWidth > window.screen.width) {
            scrollWidth = document.body.scrollWidth;
        }
        else if (document.body.scrollWidth < window.screen.Width) {
            scrollWidth = window.screen.availWidth;
        }
        else {
            scrollWidth = document.body.clientWidth;
        }
    }
    else {
        scrollWidth = document.body.scrollWidth;
    }


    if (window.innerHeight && window.scrollMaxY) {
        xScroll = document.body.scrollWidth;
        yScroll = window.innerHeight + window.scrollMaxY;
    }
    else if (document.body.scrollHeight > document.body.offsetHeight) {
        xScroll = document.body.scrollWidth;
        yScroll = document.body.scrollHeight;
    }
    else {
        xScroll = document.body.offsetWidth;
        yScroll = document.body.offsetHeight;
    }
    var windowWidth, windowHeight;
    if (self.innerHeight) {
        windowWidth = self.innerWidth;
        windowHeight = self.innerHeight;
    }
    else if (document.documentElement && document.documentElement.clientHeight) {
        windowWidth = document.documentElement.clientWidth;
        windowHeight = document.documentElement.clientHeight;
    } else if (document.body) {
        windowWidth = document.body.clientWidth;
        windowHeight = document.body.clientHeight;
    }

    if (yScroll < windowHeight) {
        pageHeight = windowHeight;
    }
    else {
        pageHeight = yScroll;
    }

    if (xScroll < windowWidth) {
        pageWidth = windowWidth;
    }
    else {
        pageWidth = xScroll;
    }
    if (scrollHeight < windowHeight) {
        scrollHeight = windowHeight;
    }
    arrayPageSize = new Array(pageWidth, pageHeight, windowWidth, windowHeight, scrollWidth, scrollHeight);
    return arrayPageSize;
}


//Call the method to set up the initial settings for the Dimmingdiv feature.
InitialiseDimmingDiv();

/*-----------------------------------------------------------------------Dimming Div ends--------------------------------------------------------------------------------------------------------------------------*/

/*---------------------------------------------------------------------------JsonHandler starts--------------------------------------------------------------------------------------------------------------------*/

function ErrorHandler(result) {
    DisableAjaxCallImage();
    var isPageLoad = false;
    var msg = "";
    if (result.get_message().indexOf('Session Time Out.') >= 0) {
        msg = "";
        msg += result.get_message() + "\r\n";
        location.href = "../";
    }
    else if (result.get_message().indexOf('Please enter valid e-mail id') >= 0) {
        msg = "";
        msg += result.get_message() + "\r\n";
        alert(msg);
        return;
    }
    else if (result.get_message().indexOf('deadlock') >= 0) {
        return;
    }
    else {
        isPageLoad = true;
        msg += "System encountered an exception. This could be a temporary issue. Please click OK to refresh the page.";
        alert(msg);
        location.reload();
    }
    if (!isPageLoad) {
        alert(msg);
    }

}
function TimeoutHandler(result) {
    alert("Timeout : System encountered an exception. This could be a temporary issue. Please click OK to refresh the page. ");
    location.reload();
}

/*-------------------------------------------------------JsonHandler ends-----------------------------------------------------------------------------------------------------------------------------------------------*/

//Displays the Ajax Loading image
function RenderAjaxCallImage() {
    if (!document.getElementById("ajaxDiv")) {
        var ajaxDiv = document.createElement("div");
        ajaxDiv.setAttribute("id", "ajaxDiv");
        var img = document.createElement("img");
        img.setAttribute("src", "../Images/loading.gif");
        ajaxDiv.style.position = "absolute";
        ajaxDiv.style.left = window.screen.width / 2 + 'px';
        ajaxDiv.style.top = window.screen.height / 2.5 + 'px';
        ajaxDiv.appendChild(img);
        document.body.appendChild(ajaxDiv);
    }
    else {
        document.getElementById("ajaxDiv").style.display = "";
    }

}

//Hides the Ajax loading image
function DisableAjaxCallImage() {
    var ajaxDiv = document.getElementById("ajaxDiv");

    if (ajaxDiv) {
        ajaxDiv.style.display = "none";
    }
}

function trim(item) {
    worker = new String(item);

    if (worker.indexOf(" ") != -1) {
        if (worker.indexOf(" ") == 0) {
            worker = worker.substring(1, worker.length);
            trim(worker);
        }
    }
    if (worker.lastIndexOf(" ") != -1) {
        if (worker.lastIndexOf(" ") >= worker.length - 1) {
            worker = worker.substring(0, worker.length - 1);
            trim(worker);
        }
    }
    return worker;
}
function CloseCordiantAlert(validateObject) {
    document.getElementById('divHamaraAlerts').style.height = "150px";
    document.getElementById('divHamaraAlerts').style.width = "300px";
    CloseWindow("divHamaraAlerts");
    if (typeof validateObject != "undefined") {
        validateObject.focus();
    }
}

function CreateCordiantAlert(title, message, validateObject, methodToCallInOk, width, height) 
{
    if (width != null )
    {
        document.getElementById('divHamaraAlerts').style.width = width + "px";
    }
    if (height != null )
    {
        document.getElementById('divHamaraAlerts').style.height = height + "px";
    }
    document.getElementById('divHamaraAlerts').innerHTML = "";
    var strAlert = "";
    strAlert += "<div><div class='popupCurve'></div>";
    strAlert += "<div class='popupTitle font14pt'>";
    strAlert += "<div><span class=\"popupClose\"><a href=\"#\" ";

    if (typeof methodToCallInOk != "undefined") {
        strAlert += "onclick='" + methodToCallInOk + ";CloseCordiantAlert(" + validateObject + ")'";
    }
    else if (typeof validateObject != "undefined") {
        strAlert += "onclick='CloseCordiantAlert(" + validateObject + ");'";
    }
    else {
        strAlert += "onclick='CloseCordiantAlert();'";
    }



    strAlert += "\">X</a></span>&nbsp;&nbsp;<strong>" + title + "</strong></div>"


    strAlert += "</div>";
    strAlert += "<div class='popupContent' align='center'>";
    strAlert += "<span class='font13pt' style = 'text-align:center'>" + message + "</span>";
    strAlert += "<div style='clear:both;text-align:center;height:auto;margin-top:10px;'>";
    strAlert += "<input type='button' id='btnAlertOk' style='width: 50px; background-color:#6CB45A; color: Black; border: solid 1px Black; height: 25px;cursor:pointer;'";

    if (typeof methodToCallInOk != "undefined") {
        strAlert += "onclick='" + methodToCallInOk + ";CloseCordiantAlert(" + validateObject + ")'";
    }
    else if (typeof validateObject != "undefined") {
        strAlert += "onclick='CloseCordiantAlert(" + validateObject + ");'";
    }
    else {
        strAlert += "onclick='CloseCordiantAlert();'";
    }

    strAlert += "name='btnAlertOk' value='Ok' style='width: 25px; background-color:#6CB45A; color: Black; border: solid 1px Black; height: 25px;cursor:pointer;' />";
    strAlert += "</div>";
    strAlert += "</div>";
    strAlert += "</div>";
    if (document.getElementById('divHamaraAlerts')) {
        document.getElementById('divHamaraAlerts').innerHTML = strAlert;
    }
    //    else
    //    {
    //        this.frameElement.ownerDocument.getElementById('divHamaraAlerts').innerHTML = strAlert;
    //    }
    SetDimmerDivProperties("Sliding Style", "NONE");
    SetDimmerDivProperties("Background Color", "black");
    //SetDimmerDivProperties("CUSTOM FOCUS", true );
    ShowPopUpWindow('divHamaraAlerts');
    document.getElementById('divHamaraAlerts').style.display = "";
    document.getElementById("btnAlertOk").focus();
    return false;
}

function CreateCordiantAlertLogin(title, message, validateObject, methodToCallInOk, btnText) {

    document.getElementById('divHamaraAlerts').innerHTML = "";
    var strAlert = "";
    strAlert += "<div><div class='popup_blue_bCurve'></div>";
    strAlert += "<div class='popup_blue_Title font14pt'>";
    strAlert += "<strong>" + title + "</strong></div>";
    strAlert += "<div class='popup_blue_Content' align='center'>";
    strAlert += "<span class='font13pt' style = 'text-align:center'>" + message + "</span>";
    strAlert += "<div style='clear:both;text-align:center;height:auto;margin-top:10px;'>";
    strAlert += "<input type='button' id='btnAlertOk'";
    if (typeof btnText != "undefined" && loginAlertBtnText != "") {
        btnText = loginAlertBtnText;
    }
    else {
        btnText = "OK";
    }
    if (typeof methodToCallInOk != "undefined" && methodToCallInOk != null) {
        strAlert += "onclick='" + methodToCallInOk + ";CloseCordiantAlert(" + validateObject + ")'";
    }
    else if (typeof validateObject != "undefined") {
        strAlert += "onclick='CloseCordiantAlert(" + validateObject + ");'";
    }
    else {
        strAlert += "onclick='CloseCordiantAlert();'";
    }

    strAlert += "name='btnAlertOk' value='" + btnText + "' class='JobBtn' />";
    strAlert += "</div>";
    strAlert += "</div>";
    strAlert += "</div>";
    if (document.getElementById('divHamaraAlerts')) {
        document.getElementById('divHamaraAlerts').innerHTML = strAlert;
    }
    //    else
    //    {
    //        this.frameElement.ownerDocument.getElementById('divHamaraAlerts').innerHTML = strAlert;
    //    }
    SetDimmerDivProperties("Sliding Style", "NONE");
    SetDimmerDivProperties("Background Color", "black");
    //SetDimmerDivProperties("CUSTOM FOCUS", true );
    ShowPopUpWindow('divHamaraAlerts');
    document.getElementById('divHamaraAlerts').style.display = "";
    document.getElementById("btnAlertOk").focus();
    return false;
}

function CreateCordiantConfirm(title, message, methodToCallInOk,width, height) 
{
    if (width != null )
    {
        document.getElementById('divHamaraAlerts').style.width = width + "px";
    }
    if (height != null )
    {
        document.getElementById('divHamaraAlerts').style.height = height + "px";
    }
    document.getElementById('divHamaraAlerts').innerHTML = "";
    var strAlert = "";
    strAlert += "<div><div class='popupCurve'></div>";
    strAlert += "<div class='popupTitle font14pt'>";
    strAlert += "<div><span class=\"popupClose\"><a href=\"javascript:void(0)\" ";


    strAlert += "onclick='CloseCordiantAlert()';";
    


    strAlert += "\">X</a></span>&nbsp;&nbsp;<strong>" + title + "</strong></div>"


    strAlert += "</div>";
    strAlert += "<div class='popupContent' align='center'>";
    strAlert += "<span class='font13pt' style = 'text-align:center'>" + message + "</span>";
    strAlert += "<div style='clear:both;text-align:center;height:auto;margin-top:10px;'>";
    strAlert += "<input type='button' id='btnAlertOk' style='margin-right:10px;width: 50px;background-color:#6CB45A; color: Black; border: solid 1px Black; height: 25px;cursor:pointer;'";

    if (typeof methodToCallInOk != "undefined") {
        strAlert += "onclick='" + methodToCallInOk + ";CloseCordiantAlert()'";
    }
    else {
        strAlert += "onclick='CloseCordiantAlert();'";
    }

    strAlert += "name='btnAlertOk' value='Ok' style='width: 25px; background-color:#6CB45A; color: Black; border: solid 1px Black;height: 25px;' />";

    strAlert += "<input type='button' id='btnAlertCancel' style='width: 50px;background-color:#6CB45A; color: Black; border: solid 1px Black; height: 25px;cursor:pointer;'";

    
    strAlert += "onclick='CloseCordiantAlert();'";

    strAlert += "name='btnAlertCancel' value='Cancel' style='width: 25px; background-color:#6CB45A; color: Black; border: solid 1px Black; height: 25px;' />";
    
    
    
    strAlert += "</div>";
    strAlert += "</div>";
    strAlert += "</div>";
    if (document.getElementById('divHamaraAlerts')) {
        document.getElementById('divHamaraAlerts').innerHTML = strAlert;
    }
    //    else
    //    {
    //        this.frameElement.ownerDocument.getElementById('divHamaraAlerts').innerHTML = strAlert;
    //    }
    SetDimmerDivProperties("Sliding Style", "NONE");
    SetDimmerDivProperties("Background Color", "black");
    //SetDimmerDivProperties("CUSTOM FOCUS", true );
    ShowPopUpWindow('divHamaraAlerts');
    document.getElementById('divHamaraAlerts').style.display = "";
    document.getElementById("btnAlertOk").focus();
    return false;
}
