﻿function getWindowHeight() {
    var windowHeight = 0;
    if (typeof (window.innerHeight) == 'number') {
        windowHeight = window.innerHeight;
    }
    else {
        if (document.documentElement && document.documentElement.clientHeight)
            windowHeight = document.documentElement.clientHeight;
        else 
            if (document.body && document.body.clientHeight)
                windowHeight = document.body.clientHeight;
    }
    return windowHeight;
}
function getWindowWidth() {
    var windowWidth = 0;
    if (typeof (window.innerWidth) == 'number') {
        windowWidth = window.innerWidth;
    }
    else {
        if (document.documentElement && document.documentElement.clientWidth)
            windowWidth = document.documentElement.clientWidth;
        else
            if (document.body && document.body.clientHeight)
                windowWidth = document.body.clientWidth;
    }
    return windowWidth;
}
function setPopFooter() {
    var windowHeight = getWindowHeight();
    var contentElement = document.getElementById('divCenterContent');
    var contentHeight = contentElement.offsetHeight;
    var stuffHeight = 40;
    if (windowHeight - (contentHeight + stuffHeight) > 0)
        contentElement.style.height = windowHeight - stuffHeight +"px"; // contentElement + windowHeight - (contentElement + stuffHeight) + "px";
}
function setFooter() {
    if (document.getElementById) {
        var windowHeight = getWindowHeight();
        if (windowHeight > 0) {
            var headerElement = document.getElementById('divHeader');
            var headerMenu = document.getElementById('ctl00_pnlNavBar');
            var headerHeight=headerElement.offsetHeight;;
            if(headerMenu !=null)
                headerHeight = headerHeight + headerMenu.offsetHeight;
            
            var contentElement = document.getElementById('divCenterContent');
            var contentHeight = contentElement.offsetHeight;
            var footerElement = document.getElementById('divFooter');
            var footerCatElement = document.getElementById('divFooterCategory');
            var footerHeight = footerElement.offsetHeight + footerCatElement.offsetHeight;
            var stuffHeight = headerHeight + footerHeight;
            if (windowHeight - stuffHeight >= 0 && contentHeight <= (windowHeight - stuffHeight)) {
                if (navigator.appName != "Microsoft Internet Explorer")
                 contentElement.style.minHeight = windowHeight - stuffHeight - 18 + "px"; 
                else
                    contentElement.style.height = windowHeight - stuffHeight - 18 + "px";
            }
        }
    }
}
function WindowTopX(popUpHeight) {
    var h = 0;
    if (document.all || document.layers)
        h = screen.availHeight;
    else if (window.innerHeight)
        h = window.innerHeight + 200;
    if (h > popUpHeight)
        topPos = (h - popUpHeight) / 2;
    else
        topPos = 0;
    return topPos;
}
function WindowLeftY(popUpWidth) {
    var w = 0;
    if (document.all || document.layers)
        w = screen.availWidth;
    else if (window.innerWidth)
        w = window.innerWidth;
    var leftPos;
    if (w > popUpWidth)
        leftPos = (w - popUpWidth) / 2;
    else
        leftPos = 0;
    return leftPos;
}
function OpenPopupWindow(url, windowName, popupWidth, popupHeight, features, useDefaultFeature) {
    var openWindowID = null;
    var topX, leftY;
    var top = WindowTopX(popupHeight);
    var left = WindowLeftY(popupWidth);
    var wfeature = "";
    if (features == "") {
        if (useDefaultFeature)
            wfeature ="width=" + popupWidth + ",height=" + popupHeight + ",top=" + top + ",left=" + left+ ",location=0,menubar=0,resizable=1,status=1,titlebar=0,toolbar=0,scrollbars=0";
        else
            wfeature = "width=" + popupWidth + ",height=" + popupHeight + ",top=" + top + ",left=" + left;
    }
    else
        wfeature = "width=" + popupWidth + ",height=" + popupHeight + ",top=" + top + ",left=" + left + "," + features;
    openWindowID = window.open(url, windowName, wfeature)
    return openWindowID;
}
function ShowHideDiv(id, display, visibility) {
    var d = document.getElementById(id);
    if (d != null) {
        d.style.display = display;
        d.style.visibility = visibility;
    }
}

//centering popup
function centerPopup(divId) {
//request data for centering   
var windowWidth = document.documentElement.clientWidth;   
var windowHeight = document.documentElement.clientHeight;
var popupHeight = $("#" + divId).height();
var popupWidth = $("#" + divId).width();
var ele = document.getElementById("ctl00_cphMainContent_ctrlDisplayEventSectionLinks_hfTempVal");
//centering
var getWindowHeightWidth;
getWindowHeightWidth = (getWindowHeight() / 2) - 350;
var leftVal;
if (ele != null)
    leftVal = Math.round((getWindowWidth() / 2) - 350);
else
    leftVal = 60;    
if(getWindowHeightWidth > 0)
{
$("#" + divId).css({   
 "position": "absolute",   
 "top": Math.round((getWindowHeight()/2) - 350),
 "left": leftVal//Math.round((getWindowWidth()/2) - 350)
 });
 }
 else{
    $("#" + divId).css({   
    "position": "absolute",   
    "top": Math.round((windowHeight/2)-(popupHeight/2)),
    "left": leftVal //Math.round((windowWidth / 2) - (popupWidth / 2))
 });
 }
}

//centering popup for edit event sections   
function centerEditSectionPopup(divId) {
    //request data for centering   
    var windowWidth = document.documentElement.clientWidth;
    var windowHeight = document.documentElement.clientHeight;
    var popupHeight = $("#" + divId).height();
    var popupWidth = $("#" + divId).width();
    //centering
    var getWindowHeightWidth;
    getWindowHeightWidth = (getWindowHeight() / 2) - 350;
    if (getWindowHeightWidth > 0) {
        $("#" + divId).css({
            "position": "absolute",
            "top": Math.round((getWindowHeight() / 2) - 350),
            "left": Math.round((getWindowWidth() / 2) - 550)
        });
    }
    else {
        $("#" + divId).css({
            "position": "absolute",
            "top": Math.round((windowHeight / 2) - (popupHeight / 2)),
            "left": Math.round((windowWidth / 2) - (popupWidth / 2))
        });
    }
}

var n = 500;
var dragok = false;
var y, x, d, dy, dx;
function down(e) {
    try {
    if (!e) e = window.event;
    var temp = (typeof e.target != "undefined") ? e.target : e.srcElement;
    temp.style.cursor = "move";
    temp = temp.parentNode;  //temp.parentElement;
    dragok = true;
    temp.style.zIndex = n++;
    d = temp;
    dx = parseInt(temp.style.left + 0);
    dy = parseInt(temp.style.top + 0);
    x = e.clientX;
    y = e.clientY;
    return false;
    }
    catch (ex) { 
    
    }
    return false;
}
function move(e) {
    if (dragok) {
        if (!e) e = window.event;
        var temp = (typeof e.target != "undefined") ? e.target : e.srcElement;
        //        temp.style.cursor = "move";
        try {
          
            d.style.left = dx + e.clientX - x + "px";
            d.style.top = dy + e.clientY - y + "px";
            if (parseInt(d.style.top) < 0)
                d.style.top = "0px";
            if (parseInt(d.style.left) < 0)
                d.style.left = "0px";
            return false;
        }
        catch (ex)
        { }
    }
}
function up() {
    dragok = false;
}

function IncrementVal(cntrl) {
    var ele = document.getElementById(cntrl);
    if (ele != null) {
        ele.value = "1";
    }
}
function HasPageValidators() {
    var hasValidators = false;
    try {
        if (Page_Validators.length > 0) {
            hasValidators = true;
        }
    }
    catch (error) {
    }
    return hasValidators;
}

function ValidationGroupEnable(validationGroupName, isEnable) {
    if (HasPageValidators()) {
        for (i = 0; i < Page_Validators.length; i++) {
            if (Page_Validators[i].validationGroup == validationGroupName) {
                ValidatorEnable(Page_Validators[i], isEnable);
            }
        }
    }
}
function setCssClass(displayMode, eventSectionPropertyMapperID) {
    var divHeader = document.getElementById(eventSectionPropertyMapperID);
    if (divHeader != null) {
        if (displayMode == 'Edit') {
            divHeader.className = "eventSectionNewEdit";
            ShowHideDiv("spTitle" + eventSectionPropertyMapperID, "inline", "visible");
        }
        else {
            divHeader.className = "eventSection";
                ShowHideDiv("spTitle" + eventSectionPropertyMapperID, "none", "hidden");
        }
    }
}

function getAllPopUpSectionDivs() {
    var subDivs = document.getElementsByTagName("div");
    var countEl = 0;
    for (var no = 0; no < subDivs.length; no++) {
        var attr = subDivs[no].getAttribute('type');
        if (opera) attr = subDivs[no].type;
        if (attr == 'pop') {
            var ele = document.getElementById(subDivs[no].id);
            ele.style.visibility = "hidden";
            ele.style.display = "none";
        }
    }
}
var viewCountID=null
function AddViewCount(lnkID, viewcountObjId) {
    if (viewCountID == null) {
        viewCountID = viewcountObjId;
        FlockEx.AjaxMethods.IncreaseViewCount(lnkID, OnSuccessFullyUpdateviewCount);
    }
    else {
        setTimeout('AddViewCount("' + lnkID + '","' + viewcountObjId + '")',1000);
    }
}
function OnSuccessFullyUpdateviewCount(value) {
    if (viewCountID != null) {
        var viewCountObj = document.getElementById(viewCountID);
        if (viewCountObj != null) {
            viewCountObj.innerHTML = value;
        }
        viewCountID = null;
    }

}

function CheckForHTMLChars(sender, arg) {
    var cntrl = document.getElementById(sender.id);
    var vRx = new RegExp("<(.|\n)+?>", "ig");
    if (cntrl != null) {
        if (vRx.test(desc.value)) {
            arg.IsValid = false;
        }
        else
            arg.IsValid = true;
    }
}