﻿$(document).ready(function () {


    $(".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;
        });
    });



    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' });

    $(".validateForm").validate();


    /*$('.newsSlideShow').cycle({
        fx: 'fade'
    });*/



    $(".newsSlideShow").each(function () {

        $(this).cycle({
            fx: 'fade',
            timeout: randomXToY(5000,7000,0)
        });

    });


    $(".gTrack").each(function () {
        $(this).click(function () {

            recordOutboundLink($(this).attr("href"), $(this).attr("category"), $(this).attr("action"))
            return false;
        });
    });

});


function randomXToY(minVal,maxVal,floatVal)
{
  var randVal = minVal+(Math.random()*(maxVal-minVal));
  return typeof floatVal=='undefined'?Math.round(randVal):randVal.toFixed(floatVal);
}

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>');
}

