
/************** **************/

function setDate(){
var d_names = ["Sunday", "Monday", "Tuesday","Wednesday", "Thursday", "Friday", "Saturday"];

var m_names = ["January", "February", "March","April", "May", "June", "July", "August", "September","October", "November", "December"];

var d = new Date();
var curr_day = d.getDay();
var curr_date = d.getDate();
var curr_month = d.getMonth();
var curr_year = d.getFullYear();
$('.dateset').text(d_names[curr_day] + ' ' + curr_date +' ' + m_names[curr_month] + ' ' + curr_year);

}

var searchCookieName = 'savedCCSearch';

var bookmarkCookieName = 'savedCCBookmark';

    $(document).ready(function()
	{
        setDate();
        $(".addPageBookmark").click(function(event){
            event.preventDefault();
            var val = $.cookie(bookmarkCookieName);
            var newVal = location.pathname + location.search;
            if (val === null || val.indexOf(newVal) < 0){
                val = val === null ? newVal: val + "||" + newVal;
                $.cookie(bookmarkCookieName, val, {path : '/', expires : 2000});
                var val = $.cookie(bookmarkCookieName);
                if (val === null){
                    alert("Bookmarks require cookies to be enabled")
                }
                else {
                    updateBookmarks($("#viewBookMark"), val);
                }
            }

        });
        $(".addSearchBookmark").click(function(event){
            event.preventDefault();
            var val = $.cookie(searchCookieName);
var newVal = location.pathname + location.search;
            if (val === null || val.indexOf(newVal) < 0){
                val = val === null ? newVal : val + "||" + newVal;
                $.cookie(searchCookieName, val, {path : '/', expires : 2000});
                var val = $.cookie(searchCookieName);
                if (val === null){
                    alert("Bookmarks require cookies to be enabled")
                }
                else {
                    updateBookmarks($("#viewSavedSearch"), val);
                }
            }

        });
	    updateBookmarks($("#viewBookMark"),$.cookie(bookmarkCookieName));
        updateBookmarks($("#viewSavedSearch"),$.cookie(searchCookieName) );

        $("#headersearchformQuery").blur(function(event){
            if ($(this).val() == ''){
                $(this).val('Enter keywords');
            }
        });
        $("#headersearchformQuery").focus(function(event){
            if ($(this).val() == 'Enter keywords'){
                $(this).val('');
            }
        });
        $("#headersearchformPubs, #headersearchformNews, #headersearchformPeople").change(function(){
            if ($(this).is(":checked")){
                $("#headersearchformAll").attr('checked', false);
            }
        });
        $("#headersearchformClose").click(function(event){
            event.preventDefault();
            $(this).closest('.hover').removeClass('hover');
        });
        $("#headersearchformSubmit").click(function(){
            if ($("#headersearchformQuery").val() =='Enter keywords' || $("#headersearchformQuery").val() ==''){
                return false;
            }
        });
	});

function updateBookmarks(element , val){

    if (val === null || val === 0){
       $(element).html('');
    }
    else{
        $(element).html('(' + val.split("||").length + ')');
    }
}





/****************************** END USER TOOLBAR/BOOKMARKING JAVASCRIPT *************************/

var popupItem;

/****************************** VIEW MAP AND CONTACT PERSON POPUP WINDOWS ************************/
function contactCliffordChance(url){
        if ($("#contactCCForm").size() === 0){
            $("body").append('<div id="contactCCForm"><div style="display:block;"><a style="float:right" href="#" class="closePopup" title="Close Popup"><img src="/etc/designs/newcc/images/crossBtnBlack.gif" alt="Close Popup Window" /></a><div style="clear:both"></div></div><div id="contactCCHTML"></div></div>');
            $("#contactCCForm .closePopup").click(function(event){
                event.preventDefault();
                disablePopup($("#contactCCForm"));

            });
            if ($("#backgroundPopup").size() === 0){
                $("body").append('<div id="backgroundPopup" title="Click here to close popup"></div>');
                $("#backgroundPopup").click(function(event){
                    event.preventDefault();
                    disablePopup($("#contactCCForm"));
            });

            }
        }
        $.ajax({
                 type: "GET",
                 url: url,
            async : true,
                 success: function(data)
                 {
                       $("#contactCCHTML").html(data);
                     centerPopup($("#contactCCForm"));
            $("#backgroundPopup").css({"opacity": "0.7"});
            $("#backgroundPopup").fadeIn("slow");
            $("#contactCCForm").fadeIn("slow");
                 }                 
            });

    }

    function viewCliffordChanceOfficeMap(url, alt){
        if ($("#cliffordChanceOfficeMap").size() === 0){
            $("body").append('<div id="cliffordChanceOfficeMap"><div style="display:block;"><a style="float:right" href="#" class="closePopup" title="Close Popup"><img src="/etc/designs/newcc/images/crossBtnBlack.gif" alt="Close Popup Window" /></a><div style="clear:both"></div></div><img id="viewOfficeMap" src="" alt="" /></div>');
            $("#cliffordChanceOfficeMap .closePopup").click(function(event){
                event.preventDefault();               
                disablePopup($("#cliffordChanceOfficeMap"));
            });

            if ($("#backgroundPopup").size() === 0){
                $("body").append('<div id="backgroundPopup" title="Click here to close popup"></div>');
                $("#backgroundPopup").click(function(){
                    disablePopup($("#cliffordChanceOfficeMap"));
            });
            }
        }
        $("#viewOfficeMap").attr("src", url);
        $("#viewOfficeMap").attr("alt", alt);
        centerPopup($("#cliffordChanceOfficeMap"));
            $("#backgroundPopup").css({"opacity": "0.7"});
            $("#backgroundPopup").fadeIn("slow");
            $("#cliffordChanceOfficeMap").fadeIn("slow");

    }

    $(document).ready(function(){
        $(".contactPerson").click(function(event){
                event.preventDefault();
            popupItem = $(this);
           contactCliffordChance($(this).attr("href"));



        });
        $(".officeMap").click(function(event){
            event.preventDefault();
            popupItem = $(this);
            viewCliffordChanceOfficeMap($(this).attr("href"), $(this).attr("title"));

        });
    });

    function disablePopup(ele){
            $("#backgroundPopup").fadeOut("slow");
            ele.fadeOut("slow");
        $(popupItem).focus();
    }


    //centering popup
    function centerPopup(ele){
        //request data for centering
        var scrolledX = document.body.scrollLeft || document.documentElement.scrollLeft || self.pageXOffset || 0;
var scrolledY = document.body.scrollTop || document.documentElement.scrollTop || self.pageYOffset || 0;

var screenWidth = document.body.clientWidth || document.documentElement.clientWidth || self.innerWidth;
var screenHeight = document.documentElement.clientHeight;

        
var left = scrolledX + (screenWidth - ele.width())/2;
        if (left < 0){
            left = 0;
        }
var top = scrolledY + (screenHeight - ele.height())/2;
    if (top <0){
        top = 0;
    }

        $(ele).css({"position": "absolute","top": top,"left": left});
        //only need force for IE6
        $("#backgroundPopup").css({   "height": (document.body.clientHeight || document.documentElement.clientHeight || self.innerHeight)   });
    }

/****************************** END VIEW MAP AND CONTACT PERSON POPUP WINDOWS ************************/


/****************************** HOMEPAGE CAROUSEL ****************************************************/
        function carrouselStop(time){
            if (interval){
                clearInterval(interval);
                timeout = setTimeout(carrouselStart, time);
            }
            interval = null;

        }
        function carrouselStart(time){
            $(".pagingRight").click();
            clearTimeout(timeout);
            interval = setInterval(carrouselStart, time);


        }
        function updatePagination(curr, max){
            $("#pageNumbering").text(curr + " / " + max);
        }





/********************** Tabs ***********************/
$.fn.simpleTabs = function(){
//Default Action
    //On Click Event

    //$(this).find("ul.tabbed li .tabheader:first").click(); //Show first tab content    
};//end function

$(document).ready(function() {
  $("ul.tabbed li .tabheader").click(function(event) {
      event.preventDefault();      
        var simpleTabs = $(this).closest(".simpleTabs");
        $(this).closest("ul.tabbed").find("li.activeTab").removeClass("activeTab"); //Remove any "active" class
        $(this).parent().addClass("activeTab"); //Add "active" class to selected tab
        simpleTabs.find(".tabContent").hide(); //Hide all tab content
        var activeTab = $(this).parent().find("a").attr("href"); //Find the rel attribute value to identify the active tab + content
        var classTab = activeTab.replace("#", ".");
        simpleTabs.find(classTab).show(); //Fade in the active content      
      
      simpleTabs.find(classTab + ' a:first').focus();
      
        simpleTabs.find(classTab + " .simpleTabs .activeTab .tabheader").click();
        var hreflang = $(this).parent().find("a").attr('hreflang');
        if (hreflang !== undefined){
            hreflang = '&amp;cc_language=' + hreflang ;
        }
      else{
            hreflang = '';
        }
      classTab = '&amp;cc_tab=' + classTab.replace(".", "");
      sitestat(cliffordChanceCounterName +'&ns_type=hidden' + classTab + hreflang);
      //ns_onclick (this,'','countername','clickin')
    });

//$("div[class^='simpleTabs']").simpleTabs(); //Run function on any div with class name of "Simple Tabs"
});


/************* FEATURE TOPIC ********/
 var FEATURE_TOPIC_HASH = "#FeatureTopic";

function showFeatureTopic()
{
    $(".showfeaturetopic").click();

}

$(document).ready(function() {
        $(".block-form-btn").click(function(event){
            event.preventDefault();
            var href = $(this).closest("form").find("select").val();
            if (href != '')
                window.location= href;
        });
    });