﻿/* -------------------------------
//#region Channel
--------------------------------*/
// hp_CBColorsArray: array is built in transformation code (docType:Channel;Transformation:Title).
// structure of the array - [[color1][channelID1],[color2][channelID2],...]

var hp_GselectedChannelIndex = 1;
var hp_GSelectedChannelColor = null;
var hp_GRotationTimeOutIntervalHandler = null;
var hp_CBColorsArray = new Array();
$(document).ready(function () {
    var rotationDelay = $("input[id*='inputHiddenAnonymousHomepageRotationDelay']").val();
    hp_channel_rotateChannels_onload(rotationDelay);
});

function hp_channelOnclick(color, index,channelID) {
    
    if (hp_GRotationTimeOutIntervalHandler)
        clearInterval(hp_GRotationTimeOutIntervalHandler);

    if (hp_GselectedChannelIndex != index) {

        $(".hp_channelTitle_" + hp_GselectedChannelIndex).removeClass("hp_channelTitle_" + hp_GSelectedChannelColor + "_Selected hp_channelTitle_Selected");

        hp_GselectedChannelIndex = index;

        $(".hp_channelTitle_" + index).addClass("hp_channelTitle_" + color + "_Selected hp_channelTitle_Selected");

        hp_GSelectedChannelColor = color;

        var strParams = "DocumentID=" + channelID + "&color=" + color;
        $("div.hp_channelContentVideo").remove();

        retrieveUrlAJAX(strPathAjaxPages + "AnonymousHomepageChannelContent.aspx", "AJAXChannelContent", strParams, true, "hp_getChannelContentAjax_complete()");
    }

}

function hp_channelMouseOver(divObj, color, index) {

    if (index != hp_GselectedChannelIndex)
        $(divObj).addClass("hp_channelTitle_" + color + "_Selected hp_channelTitle_Selected");

}

function hp_channelMouseOut(divObj, color, index) {

    if (index != hp_GselectedChannelIndex)
        $(divObj).removeClass("hp_channelTitle_" + color + "_Selected hp_channelTitle_Selected");

}

function hp_channel_rotateChannels_onload(delay_ms) {

    hp_GSelectedChannelColor = hp_CBColorsArray[0][0];

    hp_channel_loadContent();

    hp_GRotationTimeOutIntervalHandler = setInterval(hp_channelRotate, delay_ms);
}

function hp_channel_loadContent() {

    var strParams = "DocumentID=" + hp_CBColorsArray[hp_GselectedChannelIndex - 1][1] + "&color=" + hp_GSelectedChannelColor;

    retrieveUrlAJAX(strPathAjaxPages + "AnonymousHomepageChannelContent.aspx", "AJAXChannelContent", strParams, true, "hp_getChannelContentAjax_complete()");
}

function hp_channelRotate() {

    $(".hp_channelTitle_" + hp_GselectedChannelIndex).removeClass("hp_channelTitle_" + hp_GSelectedChannelColor + "_Selected hp_channelTitle_Selected");

    var nextIndex = (hp_GselectedChannelIndex + 1) % hp_CBColorsArray.length;

    if (nextIndex == 0) nextIndex = hp_CBColorsArray.length;

    hp_GselectedChannelIndex = nextIndex;
    hp_GSelectedChannelColor = hp_CBColorsArray[hp_GselectedChannelIndex - 1][0];
   
    $(".hp_channelTitle_" + hp_GselectedChannelIndex).addClass("hp_channelTitle_" + hp_GSelectedChannelColor + "_Selected hp_channelTitle_Selected");

    var strParams = "DocumentID=" + hp_CBColorsArray[hp_GselectedChannelIndex - 1][1] + "&color=" + hp_GSelectedChannelColor;

    retrieveUrlAJAX(strPathAjaxPages + "AnonymousHomepageChannelContent.aspx", "AJAXChannelContent", strParams, true, "hp_getChannelContentAjax_complete()");

}

function hp_gotoMinisiteUrl(url) {
    window.location = url;
}

function hp_getChannelContentAjax_complete() {
    var assetId = document.getElementById("hiddenVideoAssetId").value;
    if (assetId != ""){
        var strVideoHTML = "<div id=\"div"+assetId+"\" class=\"hp_VideoContainer\">&nbsp;</div>\n";
        var strVideoScript = "<script type=\"text/javascript\" src=\"http://services.fliqz.com/smart/20100401/applications/eaedf2470a8f4429a10780765034ee17/assets/" + assetId + "/containers/div" + assetId + "/smarttag.js\"></script>";
        $("div.divVideoHTMLContent").html(strVideoHTML+strVideoScript);
    }
    $("div.hp_VideoContainer").css("background-image", "url('http://previews.fliqz.com/" + assetId + ".jpg?width=183')");
}

//#endregion
/* -------------------------------
//#region Survey
--------------------------------*/

//TODO:remove this function (hp_channelContent_surveyOnclick) after removing it from cms
function hp_channelContent_surveyOnclick() {

    if (hp_GRotationTimeOutIntervalHandler)
        clearInterval(hp_GRotationTimeOutIntervalHandler);
    
    $("div.hp_channels").flip({
        direction: 'rl',        
        content: retrieveUrlAJAX(strPathAjaxPages + "AnonymousHomepageChannelsSurvey.aspx", "divChannels", ""),
        color: '#f0f1f1',
        speed: 'fast'
    });
    //alert($('#target2').html());
}

function hp_moreChannelOnclick() {

    $(".hp_surveyChannelMore").toggle();

    if ($(".hp_surveyChannelMore").is(":visible"))
        document.getElementById("hp_surveyMoreLess").innerHTML = "Less ...";
    else
        document.getElementById("hp_surveyMoreLess").innerHTML = "More ...";
}

function hp_submitSurvey()
{

    //collect survey data
    var strParams = "";

    var inputsArr = document.getElementsByTagName("input");
    for (i = 0; i < inputsArr.length; i++) {
        if (inputsArr[i].name.indexOf("DLUserType", 0) != -1) {
            strParams += (inputsArr[i].checked ? "UserType=" + inputsArr[i].value + "&" : "");
        }
        if (inputsArr[i].name.indexOf("DLChannelInterests", 0) != -1) {
            strParams += (inputsArr[i].checked ? "ChannelInterests=" + inputsArr[i].value + "&" : "");
        }
    }
   
    //create web request 
    var webReq = new Sys.Net.WebRequest;
    webReq.add_completed(hp_surveySaveCompleted);
    webReq.set_url(strPathHandlersPinnacle + "AnonymousHomepageSurveySaveSession.ashx");
    webReq.set_httpVerb("POST");
    webReq.set_body(strParams);
    webReq.get_headers()["Content-Length"] = strParams.length;
    webReq.invoke();
}

function hp_surveySaveCompleted(executor, eventArgs)
{
    window.location = window.location;
    /*
    if (executor.get_responseAvailable) {
        //if (executor.get_responseData() != "EMPTY")
    }
    */
}

function hp_flipToChannels(bSubmit) {

    if (bSubmit)
        hp_submitSurvey();
    else {  // cancel, go back to channels
        //if fold is working (some explorer browsers don't work)
        if ($('#turn_object').length != 0) {            
            $('#turn_fold').show();
            $('#turn_object').stop().animate({
                width: 150,
                height: 150
            });
                   
        }
        else {
              $("div.hp_channels").flip({
            direction: 'rl',
            content: retrieveUrlAJAX(strPathAjaxPages + "AnonymousHomepageChannels.aspx", "divChannels", "DocumentID=" + hp_CBColorsArray[hp_GselectedChannelIndex - 1][1],true, "hp_getChannelContentAjax_complete()"),
            color: '#f0f1f1',
            speed: 'fast'
            }); 
           
        }
    }      

//        $("div.hp_channels").flip({
//            direction: 'rl',
//            content: retrieveUrlAJAX(strPathAjaxPages + "AnonymousHomepageChannels.aspx", "divChannels", "DocumentID=" + hp_CBColorsArray[hp_GselectedChannelIndex - 1][1]),
//            color: '#f0f1f1',
//            speed: 'fast'
//        });

    if (hp_GselectedChannelIndex != 1) {
        $(".hp_channelTitle_" + hp_CBColorsArray[0][0]).removeClass("hp_channelTitle_" + hp_CBColorsArray[0][0] + "_Selected hp_channelTitle_Selected");
        $(".hp_channelTitle_" + hp_GselectedChannelIndex).addClass("hp_channelTitle_" + hp_GSelectedChannelColor + "_Selected hp_channelTitle_Selected");
    }

}

//#endregion
/* -------------------------------
//#region Share
--------------------------------*/
function hp_shareParticipateClick()
{
    var divParticipateOverlay = document.getElementById("divParticipateOverlay");
    
    if (divParticipateOverlay.style.display == "none")
    {
        divParticipateOverlay.style.display = "inline";
    }
    else
    {
        divParticipateOverlay.style.display = "none";
    }
    
}

//#endregion
/* -------------------------------
//#region Find
--------------------------------*/

var hp_findSelectedTab = "";
function hp_findTabHover(obj)
{
    if (hp_findSelectedTab == "")
    {
        var li = $("li.hp_findTabOn");

        if (li.length > 0)
        {
            hp_findSelectedTab = li[0].id;
        }
        else
        {
            // in case the querystring has 'tab' but it's incorrect
            var li = $("li.hp_findTabOff");
            hp_findSelectedTab = li[0].id;
        }

    }

    obj.className = "hp_findTabOn";
}

function hp_findTabOut(obj)
{
    if (obj.id == hp_findSelectedTab)
    {
        return;
    }

    obj.className = "hp_findTabOff";
}

function hp_findTabClick(obj, aliasPath)
{
    if (obj.id == hp_findSelectedTab)
    {
        return;
    }

    if (hp_findSelectedTab == "")
    {
        var li = $("li.hp_findTabOn");
        hp_findSelectedTab = li[0].id;
    }

    document.getElementById(hp_findSelectedTab).className = "hp_findTabOff";
    hp_findSelectedTab = obj.id;
    var strParams = "&Path=" + aliasPath;
    retrieveUrlAJAX(strPathAjaxPages + "AnonymousHomepageFind" + obj.id.replace("liFindTab", "") + ".aspx", "divFindMain", strParams, true);
}

function hp_findTabDoctorSearchTextboxKeypress(ev, obj)
{
    if (ev.keyCode == 13)
    {
        hp_findTabDoctorSearchButtonClick();
        return false;
    }

}

function hp_findTabDoctorSearchTextboxClick(obj)
{
    if (obj.value == Dictionary_AnonymousHP_FindDoctor_LabelSearch)
    {
        obj.value = "";
    }
}

function hp_findTabDoctorSearchButtonClick(obj)
{
    var txtDoctorSearch = $("input.hp_findDoctorsSearch");
   
    if (txtDoctorSearch.val() != "" && txtDoctorSearch.val() != Dictionary_AnonymousHP_FindDoctor_LabelSearch)
    {
        var reAmp = new RegExp("&", "ig");
        location.href = Params_PageDoctorsResultByName + txtDoctorSearch.val().replace(reAmp, "%26");
    }
    else
    {
        var divDoctorSearchError = $("div.hp_findDoctorsSearchError");
        divDoctorSearchError.show();
    }
}


function hp_findTabServiceSearchTextboxKeypress(ev, obj)
{
    if (ev.keyCode == 13) {
        hp_findTabServiceSearchButtonClick();
        return false;
    }

}

function hp_findTabServiceSearchTextboxClick(obj)
{
    if (obj.value == Dictionary_AnonymousHP_FindService_LabelSearch)
    {
        obj.value = "";
    }
}

function hp_findTabServiceSearchButtonClick(obj)
{
    var txtServiceSearch = $("input.hp_findServiceSearch");

    if (txtServiceSearch.val() != "" && txtServiceSearch.val() != Dictionary_AnonymousHP_FindService_LabelSearch) {
        var reAmp = new RegExp("&", "ig");
        window.location = Params_PageServiceResultByName.replace("{2}", txtServiceSearch.val().replace(reAmp, "%26"));
    }
    else
    {
        var divServiceSearchError = $("div.hp_findServiceSearchError"); 
        divServiceSearchError.show();
    }
}

function hp_findTabClassSearchButtonChanged(obj)
{
    location.href = Params_PageClassesResultByCategory.replace("{2}", obj.value);
}

function hp_findTabLocationsSearchButtonChanged(obj)
{
    location.href = Params_PageLocationsResultByCategory.replace("{0}", obj.value);
}

//WL change by eran for video problems check
//var testindex = 1; 
function onVideoPlay() {
    //WL change by eran for video problems check
    //$("#lblIE7TestMessage").html("start count:" + testindex);
    // label removed from html <label id="lblIE7TestMessage"></label>

    if (hp_GRotationTimeOutIntervalHandler)
        clearInterval(hp_GRotationTimeOutIntervalHandler);
}

//#endregion
/* -------------------------------*/
//#region flip 

//            string strRoataionDelay = (Settings.GetIntValue("HPAnonymous.Channels.RotationDelay") * 1000).ToString();//delay seconds to miliseconds
//            bufScript.Append("\n$(document).ready(hp_channel_rotateChannels_onload(" + strRoataionDelay + "););\n");


/*
(function ($) {
if (false) {
    $.fn.fold = function () {

        var ie55 = (navigator.appName == "Microsoft Internet Explorer" && parseInt(navigator.appVersion) == 4 && navigator.appVersion.indexOf("MSIE 5.5") != -1);
        var ie6 = (navigator.appName == "Microsoft Internet Explorer" && parseInt(navigator.appVersion) == 4 && navigator.appVersion.indexOf("MSIE 6.0") != -1);
        var ie7 = (navigator.appName == "Microsoft Internet Explorer" && parseInt(navigator.appVersion) == 4 && navigator.appVersion.indexOf("MSIE 7.0") != -1);

        if (ie55 || ie6 || ie7) //don't work in ie5 & ie6 & ie7
        {
            this.remove();
            return true;
        }

        // Default awesomeness

        var defaults = {

            directory: strPathMedia + 'Anonymous%20Homepage',         // The directory we're in

            side: 'bottomRight',           // change me to "right" if you want rightness

            turnImage: 'fold-sw.png',  // The triangle-shaped fold image

            maxHeight: 1500,         // The maximum height. Duh.

            maxWidth: 800,         // The maximum height. Duh.

            starting_width: 150,     // The height and width 

            starting_height: 150,    // with which to start (these should probably be camelCase, d'oh.)

            autoCurl: true,         // If this is set to true, the fold will curl/uncurl on mouseover/mouseout.

            handle: 'sw' //sw-topright  nw-bottom_right

        };

        // Set up the wrapper objects

        var turn_hideme = $('<div id="turn_hideme">');

        var turn_wrapper = $('<div id="turn_wrapper">');

        var turn_object = $('<div id="turn_object">');

        var img = $('<img id="turn_fold" src="' + (defaults.directory + "/" + defaults.turnImage) + '" >');


        // Set starting width and height of our turn-o-ma-bob

        turn_object.css({

            width: defaults.starting_width,

            height: defaults.starting_height

        });

        // There are different CSS considerations for a top-right fold.

        turn_wrapper.addClass('right');

        if (defaults.handle == "nw") //bottom_right
        {
            turn_wrapper.addClass('topRight')
        }
        else {
            turn_wrapper.addClass('bottomRight')
        }

        // Rappin', I'm rappin' - I'm rap-rap-rappin'.

        this.wrap(turn_wrapper).wrap(turn_object).after(img).wrap(turn_hideme);

        // If you want autoCurl, you don't get scrolling. Why? Because it looks silly.
        turn_wrapper = $('#turn_wrapper');
        turn_object = $('#turn_object');

        //resize with the mouse
        if (!defaults.autoCurl) {

            // Hit 'em with the drag-stick because it ain't gonna curl itself!

            turn_object.resizable({

                aspectRatio: false,

                ratio: true,

                border: false,

                handles: defaults.handle,

                maxWidth: defaults.maxWidth,

                maxHeight: defaults.maxHeight,

                stop: function () {

                    var currentHeight = $(this).height();

                    if (currentHeight == defaults.maxHeight) {

                        $("#target", this).css("z-index", "9999");

                    } else {

                        $("#target", this).css("z-index", "0");

                    }

                },

                resize: function () {

                    $("#target", this).css("z-index", "0")

                }

            });

        }
        //resize on hover
        else {

            // Thanks to @zzzrByte for this bit!

            turn_wrapper.hover(function () {
                turn_object.stop().animate({
                    width: defaults.maxHeight,
                    height: defaults.maxHeight
                },
                    500,
                    function () {
                        $('#turn_fold').delay(40000).hide();
                    },
                    function () {
                        //           $('#turn_fold').show();
                        //            turn_object.stop().animate({
                        //                width: defaults.starting_height,
                        //                height: defaults.starting_height
                    });
            });
        }
    }
}
}
//(jQuery);


//#endregion
*/
