﻿if (typeof (BasePath) == "undefined") BasePath = "";
var FormValidator, Errors = "", NewRedirectURL = "";
var a = new Image(); a.src = BasePath + "images/MsgBg.png";
var b = new Image(); b.src = BasePath + "images/blank.png";
var c = new Image(); c.src = BasePath + "images/loading.gif";
var d = new Image(); d.src = BasePath + "images/Info.png";
var e = new Image(); e.src = BasePath + "images/Error.png";
var f = new Image(); f.src = BasePath + "images/Warning.png";
var g = new Image(); g.src = BasePath + "images/Transparent.png";
var h = new Image(); h.src = BasePath + "images/RedD.png";
var i = new Image(); i.src = BasePath + "images/BlueD.png";
var j = new Image(); j.src = BasePath + "images/GreenD.png";
var k = new Image(); k.src = BasePath + "images/BlackD.png";
var l = new Image(); l.src = BasePath + "images/ajax_wait.gif";

var OverlayZIndex = 10000;
var ControlHTML = new Array();
function ShowHTMLOnOverlay(html, w, h, cn) {
    EnableOverlay();
    //if cn=false then we have to replace the existing overlay control other open it in another box.
    if ($(".OverlayBox").length > 0 && !cn) $(".OverlayBox").hide("fast").remove();
    
    var OverlayBox = $("<div></div>").addClass("OverlayBox").css({
        left: ($(document).width() - w) / 2 + "px",
        top: "100px",
        zIndex: OverlayZIndex + 1,
        width: w + "px"
    }).hide().html(html);
    
    if ($.browser.version == "6.0")
        OverlayBox.css({position:"absolute"});
    else
        OverlayBox.css({position:"fixed"});
    
    
    if (h > 0) OverlayBox.find(".Body").css({ height: h + "px", overflow: "auto" });
    $("#Overlay").append(OverlayBox);
    OverlayBox.css({ top: ($(window).height() - OverlayBox.height()) / 2 + "px" });
    OverlayBox.fadeIn("slow", function() {
        if (h > 0) OverlayBox.find(".Body").jScrollPane({ showArrows: true, scrollbarWidth: 19, arrowSize: 19 });
    });

    OverlayBox.find("h2 span").click(function() {
        $(this).parent().parent().remove();
        if ($(".OverlayBox").length == 0) DisableOverlay();
    });
}

function ShowImageOnOverlay(title,url) {
    EnableOverlay();
    if ($(".OverlayBox").length > 0) $(".OverlayBox").hide("fast").remove();
    var OverlayBox = $("<div></div>").addClass("OverlayBox").css({
        id: "OverlayBox",
        left: ($(document).width() - 300) / 2 + "px",
        top: ($(window).height() - 300) / 2 + "px",
        zIndex: OverlayZIndex + 1,
        width: "200px",
        height: "200px",
        border:"solid 1px white"
    }).html("<h2>" + title + "<span></span></h2>");
        
    if ($.browser.version == "6.0")
        OverlayBox.css({position:"absolute"});
    else
        OverlayBox.css({position:"fixed"});
    
    $("#Overlay").append(OverlayBox);
    OverlayBox.find("h2 span").click(function() {
        $(this).parent().parent().remove();
        if ($(".OverlayBox").length == 0) DisableOverlay();
    });
    var img = new Image();
    $(img).load(function() {
        var w = $(this).attr("width");
        var h = $(this).attr("height");
        OverlayBox.css({ background: "#000000 url(" + url + ") no-repeat center center" }).animate({
            width: w + "px",
            height: h + "px",
            left: ($(document).width() - w) / 2 + "px",
            top: ($(window).height() - h) / 2 + "px"
        });
    });
    img.src = url;
    return false;
}


function ShowVideoOnOverlay(title, vURL, vSrc, iURL, str) {
    EnableOverlay();
    if ($(".OverlayBox").length > 0) $(".OverlayBox").hide("fast").remove();
    var OverlayBox = $("<div></div>").addClass("OverlayBox").css({
        id: "OverlayBox",
        left: ($(document).width() - 300) / 2 + "px",
        top: ($(window).height() - 300) / 2 + "px",
        zIndex: OverlayZIndex + 1,
        width: "200px",
        height: "200px",
        border: "solid 1px white"
    }).html("<h2>" + title + "<span></span></h2><div id='PreviewVideoContainer'></div>");

    if ($.browser.version == "6.0")
        OverlayBox.css({ position: "absolute" });
    else
        OverlayBox.css({ position: "fixed" });

    $("#Overlay").append(OverlayBox);
    OverlayBox.find("h2 span").click(function() {
        $(this).parent().parent().remove();
        if ($(".OverlayBox").length == 0) DisableOverlay();
    });
    if (vSrc == "Local") {
        var so = new SWFObject('flash/player.swf', 'flvplayer', '640', '385', '8.0.0', '#000000');
        so.addParam("allowfullscreen", "true");
        so.addParam("allowscriptaccess", "always");
        so.addParam("wmode", "transparent");
        so.addVariable("skin", "flash/stijl.swf");
        so.addVariable("type", "http");
        so.addVariable("file", vURL + ".flv");
        so.addVariable("streamer", str);
        so.addVariable("image", iURL);
        so.addVariable("start", "0");
        so.addVariable("title", title);
        so.write("PreviewVideoContainer");
    } else if (vSrc == "YouTube") {
        var so = new SWFObject("http://www.youtube.com/v/" + vURL, 'flvplayer', '640', '385', '8.0.0', '#000000');
        so.addParam("allowfullscreen", "true");
        so.addParam("allowscriptaccess", "always");
        so.addParam("wmode", "transparent");
        so.write("PreviewVideoContainer");
    }
    OverlayBox.animate({
        width: "640px",
        height: "420px",
        left: ($(document).width() - 640) / 2 + "px",
        top: ($(window).height() - 416) / 2 + "px"
    });
    return false;
}


function ShowMessageOnOverlay(m) {
    EnableOverlay();
    $("#Overlay").append($("<div></div>").attr("id", "OverlayMessage").css({
        left: ($(document).width() - 430) / 2 + "px",
        top: ($(window).height() - 139) / 2 + "px",
        zIndex: OverlayZIndex + 1,
        backgroundColor: "Transparent",
        backgroundRepeat: "repeat-x",
        border: "solid 1px #777",
        fontSize: "30px",
        paddingTop: "50px",
        paddingBottom: "50px",
        paddingLeft: "100px",
        paddingRight: "100px",
        color: "White"
    }).html("<img src='" + BasePath + "images/loading.gif' align='absmiddle'/>&nbsp;" + m));
    
    if ($.browser.version == "6.0")
        $("#OverlayMessage").css({position:"absolute", filter: "progid:DXImageTransform.Microsoft.AlphaImageLoader(src=" + BasePath + "images/MsgBg.png,sizingmethod=scale)" });
    else
        $("#OverlayMessage").css({position:"fixed", backgroundImage: "url(" + BasePath + "images/MsgBg.png)" });
};

function ShowControlOnOverlay(c, w, h, cn, p) {
    p = p == undefined ? "" : p;
    if (ControlHTML[c + p.replace('=', '')] == undefined) {
        ShowMessageOnOverlay("Please wait..");
        $.post("Controller.ashx", { Action: "GetControl", Control: c, qs: p }, function(data) {
            DisableOverlayMessage();
            ControlHTML[c + p.replace('=', '')] = $(data).html();
            ShowHTMLOnOverlay($(data).html(), w, h, cn);
        });
    } else {
        ShowHTMLOnOverlay(ControlHTML[c + p.replace('=', '')], w, h, cn);
    }
    return false;
}

function DisableOverlay() {
    $("#Overlay").animate({
        left: $(document).width() / 2 + "px",
        top: $(window).height() / 2 - 20 + "px",
        width: "0px",
        height: "0px"
    }, 100, function() {
        $(this).remove();
        //$("body").css("overflow", "auto");
    });
    OverlayZIndex -= 2;
}

function DisableOverlayMessage() {
    $("#OverlayMessage").remove();
}

function EnableOverlay() {
    if ($("#Overlay").length > 0) return;
    //$("body").css("overflow", "hidden");
    $(theForm).prepend($("<div></div>").attr("id", "Overlay").css({
        position: "absolute",
        left: $(document).width() / 2 + "px",
        top: $(window).height() / 2 - 20 + "px",
        zIndex: OverlayZIndex,
        width: "0px",
        height: "0px"
    }).animate({
        left: "0px",
        top: "0px",
        width: "100%",
        height: $(document).height() + "px"
    }, 0));
    
    if ($.browser.version == "6.0")
        $("#Overlay").css({ filter: "progid:DXImageTransform.Microsoft.AlphaImageLoader(src=" + BasePath + "images/blank.png,sizingmethod=scale)" });
    else
        $("#Overlay").css({ backgroundImage: "url(" + BasePath + "images/blank.png)" });
        
    OverlayZIndex += 2;
}

function ShowResult(data,s,f) {
    try {
        data = eval('(' + data + ')');
        if (data.Status == "Ok") {
            if (data.RedirectURL) {
                if (NewRedirectURL != "")
                    document.location.href = BasePath + NewRedirectURL;
                else {
                    if (data.RedirectURL=="Reload")
                        document.location.reload();
                    else
                        document.location.href = BasePath + data.RedirectURL;
                }
            } else if (data.Msg) {
                ShowDialog("Info", "Find Your Place", data.Msg, "ok", s);
            }
            return true;
        } else if (data.Status == "Info") {
            ShowDialog("Warning", "Find Your Place", data.Msg, "ok", f);
        } else {
            ShowDialog("Error", "Find Your Place", data.Msg, "ok", f);
        }
    } catch (e) {
        ShowDialog("Error", "Find Your Place", data + "<br/><br/>" + e, "ok", f);
    }
    return false;
}


$(function () {
    if (typeof (theForm) == "undefined") theForm = document.forms[0];
    if (typeof (theForm) == "undefined") theForm = document.forms['form1'];
    if (typeof (theForm) == "undefined") theForm = document.form1;
    if (typeof (theForm) == "undefined") theForm = document.forms['aspnetForm'];
    if (typeof (theForm) == "undefined") theForm = document.aspnetForm;
    AlignImages($("body"));
    $("*[disabled]").css({opacity:"0.5"});
});

$(window).load(function() {
    AlignImages($("body"));
});

function AlignImages(obj) {
    obj.find(".VMiddle").each(function () {
        if ($(this).height() > 0 && $(this).attr("complete")) {
            if ($(this).parent().get(0).tagName.toLowerCase() == "a") {
                var mt = ($(this).parent().parent().height() - $(this).height()) / 2;
                $(this).parent().css({ marginTop: mt + 'px', textAlign: "center", marginLeft: "auto", marginRight: "auto", display: "inline-block" });
            } else {
                var mt = ($(this).parent().height() - $(this).height()) / 2;
                $(this).css({ marginTop: mt + 'px', textAlign: "center", marginLeft: "auto", marginRight: "auto" });
            }
        }
    });
}


function ShowDialog(t, title, message, bt, f) {
    $(theForm).prepend($("<div></div>").attr("id", "DialogOverlay").css({
        position: "absolute",
        zIndex: OverlayZIndex+1,
        left: "0px",
        top: "0px",
        width: "100%",
        height: $(document).height() + "px"
    }));
    
    var DialogType = "BlackD";
  /*  DialogType = t == "Info" ? "BlackD" : DialogType;
    DialogType = t=="Error" ? "RedD":DialogType;
    DialogType = t=="Warning" ? "BlueD":DialogType; */

    var Dialog = $("<div></div>").attr("id", "DialogBox").css({
        left: ($(document).width() - 310) / 2 + "px",
        top: ($(window).height() - 170) / 2 + "px",
        zIndex: OverlayZIndex+2,
        background: "url(" + BasePath + "images/" + DialogType + ".png)"
    });
    
    $("#DialogOverlay").append(Dialog).keypress(function(e) {
        if (e.which == 13) {
            RemoveDialog();
            if (typeof (f) == "function") f();
        }
        return false;
    });
    
    OverlayZIndex += 3;

    if ($.browser.version == "6.0") {
        $("#DialogOverlay").css({ filter: "progid:DXImageTransform.Microsoft.AlphaImageLoader(src=" + BasePath + "images/Transparent.png,sizingmethod=scale)" });
        Dialog.css({ position: "absolute" });
    } else {
        $("#DialogOverlay").css({ backgroundImage: "url(" + BasePath + "images/Transparent.png)" });
        Dialog.css({ position: "fixed" });
    }
    
    var OkButton = $("<a id='OkButton' class='Button'>" + bt + "</a>");
    OkButton.click(function() {
        RemoveDialog();
        if (typeof (f) == "function") f();
    });
    Dialog.append("<h2>" + title + "</h2>");
    var DialogBody = $("<div></div>").attr("id", "DialogBody").addClass("Body");
    DialogBody.append($("<div></div>").addClass("Message").html("<span id='DialogIcon'></span>" + message));
    DialogBody.append($("<div></div>").addClass("Buttons").append(OkButton));
    Dialog.append(DialogBody);

    if ($.browser.version == "6.0")
        $("#DialogIcon").css({ filter: "progid:DXImageTransform.Microsoft.AlphaImageLoader(src=" + BasePath + "images/" + t + ".png,sizingmethod=scale)" });
    else
        $("#DialogIcon").replaceWith("<img src='" + BasePath + "images/" + t + ".png' style='margin-right:15px;' align='left' />");

    Dialog.focus();
}

function RemoveDialog() {
    $("#DialogOverlay").remove();
    OverlayZIndex -= 3;
    return false;
}

function FireDefaultButton(e, f) {
    if (e.keyCode == 13) {
        if (typeof (f) == "function") f();
        return false;
    }
}


function UpdateRecords(cn, qs) {
    if (ControlHTML[cn + qs] == undefined) {
        var RefreshDataOverlay = $("<div></div>").css({width: "100%", height:"100%", position: "absolute", zIndex: 10, left:"0px", top:"0px"});
    
        if ($.browser.version == "6.0")
            RefreshDataOverlay.css({ filter: "progid:DXImageTransform.Microsoft.AlphaImageLoader(src=" + BasePath + "images/blank.png,sizingmethod=scale)" });
        else
            RefreshDataOverlay.css({ backgroundImage: "url(" + BasePath + "images/blank.png)" });

        var RefreshingDataMsg = $("<div></div>").attr("id", "RefreshingData").html("<h1 style='font-size:20px'>Refreshing please wait...</h1>").css({
            width: "350px",
            height: "65px",
            backgroundColor: "Transparent",
            backgroundRepeat: "repeat-x",
            border: "solid 1px #777",
            top:"75px",
            left:"220px",
            color:"white",
            textAlign:"center",
            paddingTop:"35px",
            position: "absolute"
        });
        
        if ($.browser.version == "6.0")
            RefreshingDataMsg.css({ filter: "progid:DXImageTransform.Microsoft.AlphaImageLoader(src=" + BasePath + "images/MsgBg.png,sizingmethod=scale)" });
        else
            RefreshingDataMsg.css({ backgroundImage: "url(" + BasePath + "images/MsgBg.png)" });

        RefreshDataOverlay.append(RefreshingDataMsg);
        $("#DataContainer").append(RefreshDataOverlay);
        
        $.post("Controller.ashx", { Action: "GetControl", Control: cn, qs: qs }, function(data) {
            RefreshDataOverlay.remove();
            ControlHTML[cn + qs] = data;
            var NewData = $("<div></div>").html(data).hide();
            $("#DataContainer").append(NewData);
            $("#DataContainer .Record").slideToggle(function() { $(this).remove(); });
            NewData.slideToggle(function() { $(this).addClass("Record"); setTimeout(function() { AlignImages($("#DataContainer")); }, 100); });
        });
    } else {
        var data = ControlHTML[cn + qs];
        var NewData = $("<div></div>").html(data).hide();
        $("#DataContainer").append(NewData);
        $("#DataContainer .Record").slideToggle(function() { $(this).remove(); });
        NewData.slideToggle(function() { $(this).addClass("Record"); setTimeout(function() { AlignImages($("#DataContainer")); }, 100); });
    }
    return false;
}

function PrintContent(uid, id) {
    w = window.open("about:blank");
    w.document.write("<html>");
    w.document.write("<head><title>" + document.title + "</" + "title>");
    w.document.write("<link href='" + BasePath + "css/style.css' rel='stylesheet' type='text/css' />");
    w.document.write("</head>");
    w.document.write("<body><div id='Wrapper'><table width='98%' border='0' cellpadding='0' cellspacing='0'>");
    w.document.write("<tr><td><img src='images/find_your_place_logo.png'  hspace='12' /></td><td><img src='images/contact_email.png' alt='' hspace='4'  vspace='10' /></td></tr></table>");
    w.document.write("<div class='MidShadow' style='text-align:left;height:460px;valign:top;' >" + $('#' + uid).html() + $('#' + id).html() + "</div></div>");
    w.document.write("<script type='text/javascript'>print();</" + "script></body></html>");
    w.print();
}
