﻿
var popupStatus=0;
var commentTypeID=0;
$(document).ready(function() {

    //Set textbox values to empty
    $(".sfNewsletterSubscriptionForm input.tbText").each(function() {
        $(this).val('');
    });

    if ($("#contentArea").html() != null && $("#contentArea").html().trim().length != 0) {
        $("#contentArea").css({ "padding-bottom": "20px", "margin-bottom": "20px", "border-bottom": "solid 1px #EEE" });
    }

    $(".sf_queryText").focus(function() {
        $(this).val('');
    });

    $(".sf_queryText").blur(function() {
        if ($(this).val() == '')
            $(this).val('Enter Search Term(s)');
    });

    //paging for admin side controls
    $(".rgPagePrev").val("Prev");
    $(".rgPageNext").val("Next");
    $(".PagerRight_Default").css({ "padding-top": "5px" });
    $(".rgPagePrev").css({ "padding-top": "0px", "padding-bottom": "0px" });
    $(".rgPageNext").css({ "padding-top": "0px", "padding-bottom": "0px" });


    var clickedOnVideoPreview = getQueryVariable("showvideo");
    var inHomePage = getQueryVariable("InHome");
    if (clickedOnVideoPreview == "true" && inHomePage != "true") {
        $("#divPageBorder").prepend('<img id="btnCloseVideo" style="display:none;" src="Images/btn_Close.gif" alt=" X " />');
        $("#btnCloseVideo").css("display", "inline");
    }
    else {
        $("#btnCloseVideo").css("display", "none");
    }

    function getQueryVariable(variable) {
        var query = window.location.search.substring(1);
        var vars = query.split("&");
        for (var i = 0; i < vars.length; i++) {
            var pair = vars[i].split("=");
            if (pair[0] == variable) {
                return pair[1];
            }
        }
    }

    $("#btnCloseVideo").click(function() {
        history.back();
    });


    //Apply styles for search results
    $(".searchResults dd:odd").css({ background: 'url(App_Themes/SageKotter/Images/ResourcesItemdivider-bg.png) no-repeat center bottom', padding: '5px 0px 10px 60px' });
    $(".searchResults dt:first").css({ "padding-top": "10px" });
    $(".sf_pager li:first").css({ "padding": "0px" });


    $(".searchResults em a").each(function() {
        $(this).text("read more ....");
        $(this).hover(function() {
            $(this).css({ "text-decoration": "none" });
        });
    })

    //remove right border for last link in footer list
    $("#footerText a:last").css({ "border-right": "none" });

    /*---------------styles for pagination in News page----------------*/

    var listItemsCount = $(".subLandingMaster ol.topPager").children().size() - 1;
    if (listItemsCount > 1) {
        if ($(".subLandingMaster ol.topPager li:nth-child(2) a").hasClass("sf_PagerSelItem")) {
            $(".subLandingMaster ol.topPager li:first").html('<img src="../App_Themes/SageKotter/Images/PreviousPage_Unselected.png"/>');
            $(".subLandingMaster ol.bottomPager li:first").html('<img src="../App_Themes/SageKotter/Images/PreviousPage_Unselected.png"/>');
        }

        if ($(".subLandingMaster ol.topPager li:nth-child(" + listItemsCount + ") a").hasClass("sf_PagerSelItem")) {
            $(".subLandingMaster ol.topPager li:last").html('<img src="../App_Themes/SageKotter/Images/NextPage_UnSelected.png"/>');
            $(".subLandingMaster ol.bottomPager li:last").html('<img src="../App_Themes/SageKotter/Images/NextPage_UnSelected.png"/>');
        }

        $(".subLandingMaster ol.topPager li").each(function() {
            $(this).css({ "border-right": "solid 2px #E9E9E9" });
        });

        $(".subLandingMaster ol.bottomPager li").each(function() {
            $(this).css({ "border-right": "solid 2px #E9E9E9" });
        });

        $(".subLandingMaster ol.topPager li:first").css({ "border-right": "none" });
        $(".subLandingMaster ol.topPager li:last").css({ "border-right": "none" });
        $(".subLandingMaster ol.topPager li:nth-child(" + listItemsCount + ")").css({ "border-right": "none" });
        $(".subLandingMaster ol.bottomPager li:first").css({ "border-right": "none" });
        $(".subLandingMaster ol.bottomPager li:last").css({ "border-right": "none" });
        $(".subLandingMaster ol.bottomPager li:nth-child(" + listItemsCount + ")").css({ "border-right": "none" });

    }
    
    
    /*---------------styles for tips in Tips page----------------*/
       $("#TipsAndResources #LeftIceBergContent #TipSnippet:last").css({"border-bottom":"none"});
       
    /*---------------styles for videos in Iceberg page----------------*/
       $("#videoList .IcebergVideoItem:last").css({"background":"none"});
       
       
     /**********functions for Send us your tip and Send us your quote*****************/
     
     $("#ancrTip").click(function(){   
        $("#popupContact #popupContactHeader").html($("#ancrTip").html());
        commentTypeID=1;
        //centering with css  
        CenterPopup();  
        //load popup  
        LoadPopup();
     
    });
    
    $("#ancrQuote").click(function(){
       $("#popupContact #popupContactHeader").html($("#ancrQuote").html());
        commentTypeID=2;
        //centering with css  
        CenterPopup();  
        //load popup  
        LoadPopup();
    });
    
     //CLOSING POPUP  
    //Click the x event!  
    $("#popupContactClose").live("click",function(){  
        DisablePopup();  
    });  

    //Click out event!  
    $("#backgroundPopup").click(function(){  
        DisablePopup();  
    });  

    //Press Escape event!  
    $(document).keypress(function(e){  
    if(e.keyCode==27 && popupStatus==1){  
        DisablePopup();}  
    }); 
    //Cancel Submit cheanges
    $("#btnCancel").click(function(){  
        DisablePopup();  
    }); 
    
    
    //phone validation
    validatePhone($("[id$='_tbPhone']"));
    validatePhone($("[id$='_tbPhoneNumber']"));
});
    
/******************functions for Send us your tip and Send us your quote*******************/

//loading popup with jQuery magic!  
function LoadPopup(){ 
    //loads popup only if it is disabled  
    if(popupStatus==0){ 
        $("#backgroundPopup").fadeIn("slow");
        $("#popupContact").show("slow");  
        popupStatus = 1;}  
}
//disabling popup with jQuery magic!  
function DisablePopup(){  
    //disables popup only if it is enabled  
    if(popupStatus==1){  
        $("#backgroundPopup").fadeOut("slow");  
        $("#popupContact").hide("slow");  
        popupStatus = 0;}  
}    

//centering popup  
function CenterPopup(){
    //request data for centering  
    var windowWidth = document.documentElement.clientWidth;  
    var windowHeight = document.documentElement.clientHeight;  
    var popupHeight = $("#popupContact").height();  
    var popupWidth = $("#popupContact").width(); 
    //centering  
    $("#popupContact").css({"position": "absolute","top": windowHeight/2-popupHeight/2,"left": windowWidth/2-popupWidth/2});  
    //only need force for IE6  
    $("#backgroundPopup").css({"height": windowHeight});  
}

function showvideo(id) {
    $('#popup').dialog({
        autoOpen: false,
        width: 540,
        height: 455,
        resizable: false,
        modal: true,
        zIndex: 9999,
        close: function (ev, ui) { document.getElementById("popup_content").src = "/blank.htm"; }
    });
    $('#popup').dialog('open');

    document.getElementById("popup_content").src = "/video.aspx?ID=" + id;
}
function showvimeo(id) {
    $('#popup').dialog({
        autoOpen: false,
        title: '',
        width: 540,
		height: 455,
        resizable: true,
        modal: true,
        zIndex: 9999,
        close: function (ev, ui) { document.getElementById("popup_content").src = "/blank.htm"; }
    });
    $('#popup').dialog('open');

    document.getElementById("popup_content").src = "/vimeo.aspx?ID=" + id;
	return false;
}

(function ($) {
// VERTICALLY ALIGN FUNCTION
$.fn.video_button_align = function(x) {
	return this.each(function(i){
		var ah = $(this).height();
		var ph = $('#play_anchor_' + x).parent().height();
		var mh = (ph - ah) / 2;
		$(this).css('padding-top', mh);
	});
};
})(jQuery);


/*---------------function for Adjusting Phone Number---------------*/
function validatePhone(object) 
{   
    if(object!=null && object!=undefined)
    { 
        object.keydown(function(event){
            objval = $(this).val();
            if ( event.keyCode == 46 || event.keyCode == 8 ){   
            // let it happen, don't do anything 
            }   
            else 
            {  
                if (!((event.keyCode >47 && event.keyCode <58) || (event.keyCode >95 && event.keyCode <106)) || (objval.length >11))
                {  
                    event.preventDefault();  
                }
                else
                {
                    if(objval.length == 3 || objval.length == 7)
                    {
                        $(this).val(objval + "-");
                    }
                }
            }   
        });
    }
}


