﻿jQuery(document).ready(function($) {
    $('a[rel*=facebox]').livequery(function(){
        $(this).facebox();
    });
    $("#header input[id*='txtSearch']").focus(function() {
        if($(this).val().length === 0 || $(this).val() === "- Search here -"){
            $(this).removeClass("watermarkOn").val("");
        }
    }).blur(function() {
        if($(this).val().length === 0){
            $(this).addClass("watermarkOn").val("- Search here -");
        }
    }).addClass("watermarkOn").val("- Search here -");
    $(".search a").click(function(){
        var searchTerm = $("input[id*='txtSearch']").val();
        if (searchTerm.length > 0 && searchTerm != "- Search here -"){
            window.location = "/search?q=" + searchTerm;
        }else{
            window.location = "/search?q=*";
        }
        return false;
    });
    $(".a_logout").live("click",function(){
        createPageView("Compass: Connect: Logout","Compass: Connect","Compass: Connect","Compass: Connect: Logout","Form","","event17");
        AuthService.logoutUser(window.location.href);
        return false;
    });
    if($("div[id*='pnlLogin']").length === 0 && $("div[id*='pnlRegister']").length === 0){
        $(".a_register").click(function(){
            jQuery.facebox({ ajax: "/register-lite.aspx"});
            return false;
        });
        $(".a_login").click(function(){
            jQuery.facebox({ ajax: "/login-lite.aspx?ReturnUrl=" + $.URLEncode(window.location)});
            return false;
        });
    };
    if($.cookie("timeOffset") === null){
        var d = new Date();
        var offset = d.getTimezoneOffset()/60;
        $.cookie("timeOffset", offset);
    }
    if($.browser.msie && ((window.location.toString().indexOf("cancer-atlas") > -1) || (window.location.toString().indexOf("animation") > -1))){
        $(document).bind("close.facebox", function(){
            location.reload(true);
        });
    }
    if($.browser.msie && $.browser.version.toString().indexOf("6") > -1){
        $("#topNav li").hover(function(){
            $(this).addClass("sfhover");
        },function(){
            $(this).removeClass("sfhover");
        });
        $(window).scroll(function() {
            $("#feedBack").css("top", (($(window).scrollTop() + $(window).height())-$("#feedBack").height()) + "px");
        });
    }
    if($.cookie("feedback") === "never"){
        $("#feedBack").css("display","none");
    }else{
        $("#feedBack a.open").toggle(function(){
            $(this).next().slideDown("slow",function(){
                if($.browser.msie && $.browser.version.toString().indexOf("6") > -1){        
                    $("#feedBack").css("top", (($(window).scrollTop() + $(window).height())-$("#feedBack").height()) + "px");
                }
            });
            setTimeout("$('#txtFeedback').focus()",500);
        },function(){
            $(this).next().slideUp("slow",function(){
                $("#feedBack").css("top", (($(window).scrollTop() + $(window).height())-$("#feedBack").height()) + "px");
            });
        });
        
        $("#feedBack a.close").click(function(){
            $.cookie("feedback", "never");
            $(this).parent().hide("slow");
            return false;
        });
        $("#btnFeedback").click(function(){
            $.ajax({
                type: "POST",
                contentType: "application/json; charset=utf-8",
                url: "/common/webservices/survey.asmx/LeaveFeedback",
                data: "{'comment':'" + $("#txtFeedback").val().replace(/\'/g,"\\'") + "','page':'" + window.location + "'}",
                dataType: "json",
                success: function(data, textStatus){
                    $(".feedbackForm").html("<p>Thank you for your feedback! We really appreciate you taking your time to tell us how we can improve CancerCompass.</p>");
                },
                error: function(xhr, textStatus, errorThrown){
                    alert(xhr.responseText);
                },
                complete: function(XMLHttpRequest, textStatus){
                    setTimeout("$('#feedBack').hide('slow')",4500);
                }
            });
        });    
    }
    //append the blue version of the logo that will only show when printed
    $(".logoLink").append("<img src='/images/logo-blue.gif' alt='CancerCompass' class='logoBlue' />");
});
function clientVal(ValidationGroup, scroll){
    Page_ClientValidate(ValidationGroup);
    if(!Page_IsValid && scroll){
        window.scroll(0,0);
    }
    return Page_IsValid;
}
function createPageView(pageName, section, subSection, subSubSection, pageType, cancerType, events){
    if(typeof(s) === "undefined" || s.toString().indexOf("addthis") > -1){
        jQuery.getScript("/common/scripts/s_code_h19_1.js", function(){
            // Clears all existing Omniture variables
            s.pageType = "",s.pageName = "",s.channel = "",s.prop1 = "",s.prop2 = "",s.prop3 = "",s.prop4 = "",s.prop5 = "",s.prop6 = "",s.prop7 = "",s.prop8 = "",s.prop9 = "",s.prop10 = "",s.prop11 = "",s.prop12 = "",s.prop13 = "",s.prop14 = "",s.prop15 = "",s.prop16 = "",s.prop17 = "",s.prop18 = "",s.prop19 = "",s.prop20 = "",s.eVar1 = "",s.eVar2 = "",s.eVar3 = "",s.eVar4 = "",s.eVar5 = "",s.eVar6 = "",s.eVar7 = "",s.eVar8 = "",s.eVar9 = "",s.eVar10 = "",s.server = "",s.events = "",s.campaign = "";
            //Set Omniture Variables
            s.pageName = pageName;
            s.channel = section;
            s.prop16 = subSection;
            s.prop18 = subSubSection;
            s.prop17 = pageType;
            s.prop19 = cancerType;
            s.events = events; 
            //Send data to Omniture
            void(s.t());    
        });
    }else{
        // Clears all existing Omniture variables
        s.pageType = "",s.pageName = "",s.channel = "",s.prop1 = "",s.prop2 = "",s.prop3 = "",s.prop4 = "",s.prop5 = "",s.prop6 = "",s.prop7 = "",s.prop8 = "",s.prop9 = "",s.prop10 = "",s.prop11 = "",s.prop12 = "",s.prop13 = "",s.prop14 = "",s.prop15 = "",s.prop16 = "",s.prop17 = "",s.prop18 = "",s.prop19 = "",s.prop20 = "",s.eVar1 = "",s.eVar2 = "",s.eVar3 = "",s.eVar4 = "",s.eVar5 = "",s.eVar6 = "",s.eVar7 = "",s.eVar8 = "",s.eVar9 = "",s.eVar10 = "",s.server = "",s.events = "",s.campaign = "";
        //Set Omniture Variables
        s.pageName = pageName;
        s.channel = section;
        s.prop16 = subSection;
        s.prop18 = subSubSection;
        s.prop17 = pageType;
        s.prop19 = cancerType;
        s.events = events; 
        //Send data to Omniture
        void(s.t());
    }   
}