﻿var pageContext;


function SetPageContext(context) {
    pageContext = context[0];
}

//Gets client cached Model Data for MVC Control
function GetControlModelData(controlId) {
    return controlmodeldata[controlId];
}

//Sets client cached Model Data for MVC Control
function SetControlModelData(controlId, data) {
    controlmodeldata[controlId] = eval(data);
}

//Gets client cached Config Data for MVC Control
function GetControlConfigData(controlId) {
    if (controlconfigdata[controlId] != null) {
        return controlconfigdata[controlId];
    }
    else {
        return null;
    }
}

//Sets client cached Config Data for MVC Control
function SetControlConfigData(controlId, data) {
    controlconfigdata[controlId] = data;
}

function showDiv(divname) {
    $('#' + divname).show();
}

function hideDiv(divname) {
    $('#' + divname).hide();
}

function GetScrollYPos() {
    var y = 0;
    if (typeof (window.pageYOffset) == 'number') {
        // Netscape
        y = window.pageYOffset;
    } else if (document.body && (document.body.scrollLeft || document.body.scrollTop)) {
        // DOM
        y = document.body.scrollTop;
    } else if (document.documentElement && (document.documentElement.scrollLeft || document.documentElement.scrollTop)) {
        // IE6 standards compliant mode
        y = document.documentElement.scrollTop;
    }
    return y;
}

function GetScrollXPos() {
    var x = 0;
    if (typeof (window.pageYOffset) == 'number') {
        x = window.pageXOffset;
    } else if (document.body && (document.body.scrollLeft || document.body.scrollTop)) {
        x = document.body.scrollLeft;
    } else if (document.documentElement && (document.documentElement.scrollLeft || document.documentElement.scrollTop)) {
        x = document.documentElement.scrollLeft;
    }
    return x;
}

function centerObject(divname) {
        var x = GetScrollXPos();
        var y = GetScrollYPos();
        var windowWidth = document.documentElement.clientWidth;
        var windowHeight = document.documentElement.clientHeight;
        var popupHeight = document.getElementById(divname).offsetHeight;
        var popupWidth = document.getElementById(divname).offsetWidth;
        var top = (windowHeight / 2 - popupHeight / 2) + y;
        var left = (windowWidth / 2 - popupWidth / 2) + x;
        if (top < 0) {
            top = 0;
        }
        if (left < 0) {
            left = 0;
        }
        document.getElementById(divname).style.top = top + 'px';
        document.getElementById(divname).style.left = left + 'px';
        document.getElementById(divname).style.position = 'absolute';
    }

function GetMaxEditorSize(widthoffset, heightoffset) {
    var myWidth = 0, myHeight = 0;
    if (typeof (window.innerWidth) == 'number') {
        //Non-IE
        myWidth = window.innerWidth;
        myHeight = window.innerHeight;
    } else if (document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight)) {
        //IE 6+ in 'standards compliant mode'
        myWidth = document.documentElement.clientWidth;
        myHeight = document.documentElement.clientHeight;
    } else if (document.body && (document.body.clientWidth || document.body.clientHeight)) {
        //IE 4 compatible
        myWidth = document.body.clientWidth;
        myHeight = document.body.clientHeight;
    }

    if (myWidth > 980) {
        myWidth = 980;
    }
    var maxEditorSize = { "width": myWidth - 10 - widthoffset, "height": myHeight - 10 - heightoffset };
    return maxEditorSize;
}

function checkinit() {
try
{
if(pageinit != 1) {
    alert(pageinit);
    window.location.reload();
}
}
catch(ex) {
    alert(pageinit);
    window.location.reload();
}
}

function SetEventDate(evd) {
    $.ajax({
        type: "POST",
        url: "/Model/TFACMS/Model.asmx/SetEventDate",
        data: "{ 'eventDate': '" + evd + "'}",
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        success: function(msg) {
        window.location.href = 'events';
        }
    });


}

function clone_obj(obj) {
    var c = obj instanceof Array ? [] : {};

    for (var i in obj) {
        if (i != '__type') {
            var prop = obj[i];

            if (typeof prop == 'object') {
                if (prop instanceof Array) {
                    c[i] = [];

                    for (var j = 0; j < prop.length; j++) {
                        if (typeof prop[j] != 'object') {
                            c[i].push(prop[j]);
                        } else {
                            c[i].push(clone_obj(prop[j]));
                        }
                    }
                } else {
                try {
                    if (prop.getMonth) {
                        c[i] = prop;
                    } else {
                        c[i] = clone_obj(prop);
                    }
                }
                catch (ex) {
                    c[i] = clone_obj(prop);
                }
                }
            } else {
                c[i] = prop;
            }
        }
    }

    return c;
}

function NewRow(index, rowitemcount) {
    if (index == 0) {
        return 0;
    }
    if (parseInt(index / rowitemcount) == index / rowitemcount) {
        return 1;
    }
    else {
        return 0;
    }
}
function NumberOfFillCells(numberofitems, rowitemcount) {
    var no = rowitemcount - (((numberofitems / rowitemcount) - parseInt(numberofitems / rowitemcount)) * rowitemcount);
    var ar = new Array();
    for (var x = 0; x < Math.round(no); x++) {
        ar[x] = '';
    }
    return ar;
}

function toggleDiv(divname) {
    var div = document.getElementById(divname);
    if (div.style.visibility == 'visible') {
        div.style.visibility = 'hidden';
        div.style.display = 'none';
    }
    else {
        div.style.visibility = 'visible';
        div.style.display = '';
    }
}




function showeditgallery(id) {
    centerDiv('#TFAMasterPage_editviewer' + id + '_EditPanel');
    $("#editBackground").css({ "opacity": "0.9" });
    $("#editBackground").fadeIn("def");
    $('#TFAMasterPage_editviewer' + id + '_EditPanel').fadeIn("def");
}
function showcreategallery(id) {
    centerDiv('#TFAMasterPage_createGallery' + id + '_EditPanel');
    $("#editBackground").css({ "opacity": "0.9" });
    $("#editBackground").fadeIn("def");
    $('#TFAMasterPage_createGallery' + id + '_EditPanel').fadeIn("def");

}
function hidecreategallery(id) {
    __doPostBack('TFAMasterPage_main_PhotoGalleryPlaceholder1_updatepanel1', '');
    //var opac = document.getElementById('TFAMasterPage_createGallery1_EditPanel');
    //opac.className = "FreezePaneOff";
    $("#editBackground").fadeOut("def");
    $('#TFAMasterPage_createGallery' + id + '_EditPanel').fadeOut("def");
}

function showupload(id, imagetype) {
    //var opac = document.getElementById('TFAMasterPage_imageupload' + id + '_imageuploadpanel');
    //opac.className = "FreezePaneOnUpl";

    centerDiv('#TFAMasterPage_imageupload' + id + '_imageuploadpanel');
    $('#TFAMasterPage_editviewer' + id + '_EditPanel').fadeOut(100, function() { $('#TFAMasterPage_imageupload' + id + '_imageuploadpanel').fadeIn("fast"); });


}
function hideupload(id) {
    //var opac = document.getElementById('TFAMasterPage_imageupload' + id + '_imageuploadpanel');
    //opac.className = "FreezePaneOffUpl";

    $('#TFAMasterPage_imageupload' + id + '_imageuploadpanel').fadeOut("fast", function() { $('#TFAMasterPage_editviewer' + id + '_EditPanel').fadeIn("fast"); });
}
function hideeditgallery() {
    __doPostBack('TFAMasterPage_main_PhotoGalleryPlaceholder1_updatepanel1', '');
    //var opac = document.getElementById('TFAMasterPage_editviewer1_EditPanel');
    //opac.className = "FreezePaneOff";
    $("#editBackground").fadeOut("def");
    $('#TFAMasterPage_editviewer1_EditPanel').fadeOut("def");
}

function centerDiv(divname) {
    var x = GetScrollXPos();
    var y = GetScrollYPos();
    var windowWidth = document.documentElement.clientWidth;
    var windowHeight = document.documentElement.clientHeight;
    var popupHeight = $(divname).height();
    //document.write(document.getElementById(divname.replace('#', '')).innerHTML);
    var popupWidth = $(divname).width();
    $(divname).css({ "position": "absolute", "top": (windowHeight / 2 - popupHeight / 2) + y, "left": (windowWidth / 2 - popupWidth / 2) + x });
    $("#editBackground").css({ "height": windowHeight });
}
function SelectImage(imgtype, id, controlid) {
    var div = document.getElementById('div' + imgtype + controlid);
    var imgs = div.getElementsByTagName("img");
    for (var i = 0; i < imgs.length; i++) {
        if (imgs[i].id == imgtype + id) {
            imgs[i].style.border = "3px solid black";
        }
        else {
            imgs[i].style.border = "0px";
        }
    }

    imgs = div.getElementsByTagName("div");
    for (i = 0; i < imgs.length; i++) {
        if (imgs[i].id == imgtype + id) {
            imgs[i].style.border = "3px solid black";
        }
        else {
            imgs[i].style.border = "0px";
        }
    }
    var hdn = document.getElementById('TFAMasterPage_editviewer' + controlid + '_hdnSelectedImage');
    hdn.value = id;

}

function ShowImage(id) {
    $get('TFAMasterPage_ContentPlaceHolder2_PhotoGalleryPlaceholder1_ImageGalleryDetail1_hdnImageId').value = id;
    CFA.OW.Model.Photo.Model.getfullimage(id, ScriptCallback);
}
function ScriptCallback(result) {
    $("#divfullimage").hide();
    $get('divfullimage').innerHTML = result;
}
function fadein(id) {
    $("#divfullimage").fadeIn("def");
}
