﻿$(document).ready(function () {

    $(".gTrack").each(function () {
        $(this).click(function () {

            return recordOutboundLink($(this).attr("href"), $(this).attr("name"), $(this).attr("href"))
           
        });
    });

    $(".popupWindow").each(function () {
        $(this).attr("link", $(this).attr("href"));
        $(this).attr("href", "#");
        $(this).click(function () {
            setDialogLoading();

            if ($(this).attr("pupheight") != undefined) {
                popUp($(this).attr("title"), $(this).attr("link"), $(this).attr("pupwidth"), $(this).attr("pupheight"));
            }
            else {
                popUpMini($(this).attr("title"), $(this).attr("link"));
            }
            return false;
        });
    });

    $("a.lightbox").lightbox({
        fitToScreen: true,
        imageClickClose: false
    });

    $('.newsItemsHolder').cycle({
        fx: 'scrollLeft',
        timeout: 10000,
        speed: 500
    });



    var d = new Date();

    var curr_date = d.getDate();

    var curr_month = d.getMonth();

    var curr_year = d.getFullYear();

    $(".datePicker").val(curr_year + "-" + curr_month + "-" + curr_date);
    $(".datePicker").datepicker({ dateFormat: 'yy-mm-dd' });

    $(".datePickeruk").datepicker({ dateFormat: 'dd-mm-yy' });

    $(".validateForm").validate();

    $("#footerTabHolder a").click(function () {
        return showFooterTab($(this).attr("id"));
    });


});

function closeDialog() {
    setDialogLoading();
    $("#dialog").dialog("destroy")
}

function callJGrowlAdmin(message, title, sticky, userMessageID) {

    if (top.location != self.location) {
        window.parent.callJGrowlAdmin(message, title, sticky, userMessageID);
    }
    else {
        $.jGrowl(message,
        { header: title,
            sticky: sticky,
            beforeClose: function (e, m) {
                $.get("/_ajax/readMessage.aspx?userMessageID=" + userMessageID);
            }
        });

    }
}


function showFooterTab(tabID) {

    $("#footerTabHolder a").each(function () {
        $(this).removeClass("selected");
    });
    $("#" + tabID).addClass("selected");


    $("#footerTabContentHolder .holder").each(function () {
        $(this).addClass("none");
    });

    $("#" + tabID + "Content").removeClass("none");

    return false;
}



function popUpMini(title, url) {
    popUp(title, url, 450, 350);
    
}

function popUp(title, url, w, h) {
    //alert(w);
    //alert(h);
    if (w == undefined) {
        w = 350;
    }
    if (h == undefined) {
        h = 250;
    }
 
    setDialogLoading();
    $("#dialog").dialog("destroy")
    $("#dialog").dialog({ autoOpen: false, width: w + 'px', height: h, modal: true });
    $("#dialog").dialog("option", "title", title);
    $("#dialog").dialog("open");


    /*$.get(url, function (data) {
        $("#dialogHTML").html(data);
    });*/
    $("#dialogFrame").attr("src", url);
}

function setDialogLoading() {
    $("#dialogHTML").data('<div style="text-align:center;"><img src="/images/loading.gif" alt="Loading" /></div>');
}

