
function openNewWindow(url) {
    var newwindow;
    newwindow = (url,
 'open_window',
 'toolbar=yes,location=yes,directories=yes,status=yes,menubar=yes,scrollbars=yes,copyhistory=yes,resizable=yes, width=640, height=640, left=0, top=0');
}



// 06/14/2010 : TJV : Provide a popup window that excepts width and height vars..
function PopUpWindow(url, varWidth, varheight) {
    var configPopup = "'menubar=0, resizable=1, scrollbars=1, status=0, width=" + varWidth + ",height=" + varheight + "'";
    window.open(url, 'newwindow', configPopup);
}


//03/14/2009 - KJV
function jumpTo(ID) {
    //This is all about trying your best to support FireFox, IE and Safari
    try {
        //alert('scrollintoview');
        document.getElementById(ID).scrollintoview(); //IE 6
    }
    catch (e) {
        try {
            // 10/23/2009 KG: Bug with IE offsetTop... position relative to parent(s), so add up offsets.
            obj = document.getElementById(ID);
            var y = obj.offsetTop;
            while (obj = obj.offsetParent) y += obj.offsetTop
            window.scrollTo(0, y);
        }
        catch (e) {
            try {
                //alert('node scroll');
                var nodes = document.getElementsByName(ID); //Safari
                setTimeout(window.scrollTo(0, nodes[0].offsetTop), 1);
            }
            catch (e) { }

        }
    }
}

/* 
02/09/2010 - TJV
Added functionality to redirect user to another page..
Used to make everything clickable within a panel.  Handy if
they all share the same location when clicked and a hyperlink is not used.
*/
function urlRedirect(ctrlName) {
    var url = document.getElementById(ctrlName);
    window.location = url;
}


/* 02/10/2010 - TJV  speed up the time the popup menu appears  */
var addthis_config = {
    ui_click: true,
    services_exclude: 'print,email',
    services_compact: 'favorites, linkedin, twitter, facebook, digg, delicious, myspace, google, live, blogger'
}


/* TJV : 02/10/2011 : Set a general cookie using javascript */
function SetClientCookie(cookieName, cookieValue, hoursToExpire) {

    try{
        if (hoursToExpire) {
            var date = new Date();
            date.setTime(date.getTime() + (1 * hoursToExpire * 60 * 60 * 1000));
            
            var exp = "; expires=" + date.toGMTString();
            document.cookie = cookieName + "=" + cookieValue + exp + "; path=/";
        }
    }catch(e){
       /* User may not allow cookies.. .Net code will warn user.
          I want to avoid error being shown */
    }
}


/* TJV : 01/11/2011 : Forces popup in front of Philips
  search, country and command bars.. */
function OverlayNavBarsOnPage() {

    if ($("#p-header-localeselector")) $('#p-header-localeselector').css('z-index', '12');
    if ($("#p-ls-hover-0")) $('#p-ls-hover-0').css('z-index', '11');
    if ($("#p-headernav-innerwrapper")) $('#p-headernav-innerwrapper').css('z-index', '11');
    if ($("#p-search-sayt")) $('#p-search-sayt').css('z-index', '11');
    if ($("#p-searchquery")) $('#p-searchquery').css('z-index', '11');
    if ($("#p-header-search")) $('#p-header-search').css('z-index', '11');
}


/* ------------- 07:11:10: Trebly : Dynamic jquery functionality for fancybox ---------------
Wraps object in hyperlink then asigns jquery css class.*/

/* I don't want to change jquery.fancybox.css path. We want all title backgrounds
to be the same when created from TeamSite.  Using global siteURL from javasctipt function*/
function BuildImageButtonPath() {

        //Only if created from TeamSite.. Title must allways come from this location.
        $("#fancy_title_main").css('background-image', 'url(' + siteURL + 'images/buttons/fancy_title_main.png)');
        $("#fancy_title_left").css('background-image', 'url(' + siteURL + 'images/buttons/fancy_title_left.png)');
        $("#fancy_title_right").css('background-image', 'url(' + siteURL + 'images/buttons/fancy_title_right.png)');
        $("#fancy_close").css('background-image', 'url(' + siteURL + 'images/buttons/fancy_closebox.png)');

        /* by class specific to div */
        $('div.fancy_bg_n').css('background', 'transparent url(' + siteURL + 'images/fancy_shadow_n.png) repeat-x');
        $('div.fancy_bg_e').css('background', 'transparent url(' + siteURL + 'images/fancy_shadow_e.png) repeat-y');
        $('div.fancy_bg_s').css('background', 'transparent url(' + siteURL + 'images/fancy_shadow_s.png) repeat-x');
        $('div.fancy_bg_w').css('background', 'transparent url(' + siteURL + 'images/fancy_shadow_w.png) repeat-y');
        $('div.fancy_bg_ne').css('background', 'transparent url(' + siteURL + 'images/fancy_shadow_ne.png) no-repeat');
        $('div.fancy_bg_nw').css('background', 'transparent url(' + siteURL + 'images/fancy_shadow_nw.png) no-repeat');
        $('div.fancy_bg_sw').css('background', 'transparent url(' + siteURL + 'images/fancy_shadow_sw.png) no-repeat');
        $('div.fancy_bg_se').css('background', 'transparent url(' + siteURL + 'images/fancy_shadow_se.png) no-repeat');
}


//Read meta tag metric and get division attribute
function SetDivisonPathIn(currentObjPath) {

    var newUrl;
    var division = $('meta[name=PHILIPS.METRICS.DIVISION]').attr("content");

    if (division == 'HC') {
        newUrl = currentObjPath.replace('TEMP_DIVISION', "pwc_hc");
    } else if (division == 'LI') {
        newUrl = currentObjPath.replace('TEMP_DIVISION', "pwc_li");
    } else if (division == 'CO') {
        newUrl = currentObjPath.replace('TEMP_DIVISION', "pwc_nc"); 
    } else if (division == 'CP') {
        newUrl = currentObjPath.replace('TEMP_DIVISION', "pwc_cp");
    } else {
        newUrl = currentObjPath;
    }
    return newUrl;
}


function ShowFancyBox(objID, objPath, objHeight, objWidth, popupTitle, shadeBackground) {

    $(document).ready(function() {
        var overlayShowVar = shadeBackground;
        var updatedPath = SetDivisonPathIn(objPath); 	//Need metatag information
        var objectPath = updatedPath.toString().split('.');
        var fileType = objectPath.reverse();

        if ($("#divFancy").length) $("#divFancy").remove();
        if ($("#dynamicWm").length) $("#dynamicWm").remove();
        if ($("#dynamicVideo").length) $("#dynamicVideo").remove();

        BuildImageButtonPath();
        if (popupTitle != "") $('#' + objID + '').attr("title", popupTitle);  //Set tag title

        IsFlashDiv(updatedPath, objHeight, objWidth, fileType[0]);  //Create dynamic objects

        $('a#' + objID + '').live('click', function() {
            $('a#' + objID + '').fancybox({
                'titleShow': true,
                'titlePosition': 'outside',
                'frameWidth': parseFloat(objWidth),
                'frameHeight': parseFloat(objHeight),
                'overlayShow': overlayShowVar,
                'showCloseButton': true,
                'enableEscapeButton': true,
                'hideOnContentClick': false,
                'zoomSpeedIn': 0,
                'zoomSpeedOut': 0,
                'callbackOnClose': function() {
                    $("#videoObject").remove();
                    $("#imageObject").remove();
                    $("#winMediaPlayer").remove();
                },
                'callbackOnShow': function() {
                    $("#fancy_close").css('z-index', '100'); 
                    $('#fancy_content').css('background-color', '#ffffff');
                    $('#fancy_bg').css('background-color', '#ffffff');
                    $('#fancy_div').css('background-color', '#ffffff');
                    $('#fancy_div').css('text-align', 'center');
                    if (popupTitle != "") $('#fancy_title').show();
                }
            }).trigger('click');  //trigger the click event immediately after assigning.
            return false;
        })
    });
}


// 07.14.2010 : Trebly : Creates div and video object for jquery fancybox
function IsFlashDiv(objectPath, height, width, fileType) {

    var divHld = document.createElement("div");
    divHld.setAttribute('id', "divFancy");  //Create div tag

    //Create video object
    if (fileType == 'swf' || (objectPath.indexOf('youtube') != -1)) {
        var flash = document.createElement("embed");
        flash.setAttribute('id', "videoObject");
        flash.setAttribute('height', height);
        flash.setAttribute('width', width);
        flash.setAttribute('src', objectPath);
        flash.setAttribute('type', "application/x-shockwave-flash");
        flash.setAttribute('pluginspace', "http://www.macromedia.com/go/getflashplayer");
        flash.setAttribute('allowscriptaccess', "always");
        flash.setAttribute('allowfullscreen', "true");
        flash.setAttribute('wmode', "transparent");
        divHld.appendChild(flash);   //Appdend flash object inside div tag
    } else if (fileType == 'wmv') {
        var wm = document.createElement('embed');
        wm.setAttribute('id', "winMediaPlayer");
        wm.setAttribute('name', "winMediaPlayer");
        wm.setAttribute('width', width);
        wm.setAttribute('height', height);
        wm.setAttribute('src', objectPath);
        wm.setAttribute('classid', "clsid:22d6f312-b0f6-11d0-94ab-0080c74c7e95");
        wm.setAttribute('codebase', "http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=5,1,52,701");
        wm.setAttribute('type', "application/x-oleobject");
        wm.setAttribute('autostart', "false");
        divHld.appendChild(wm); //addend object to display area.
    } else {
        var img = document.createElement("img");
        img.setAttribute('id', "imageObject");
        img.setAttribute("src", objectPath);
        img.setAttribute("alt", '');
        divHld.appendChild(img);     //Appdend img object inside div tag
    }
    document.body.appendChild(divHld); //Appdend div with embedded flash object to form
    divHld.style.display = "none";     //Hide div to be displayed
}
/* -------------------- End Dynamic jquery functionality ------------------*/





/* 10.07.2010 : Trebly : Creates dynamic div & iframe for jquery functionality */
function InitJqueryIframe(oID, oPath, oTitle, oShade) {

    var shadeBackGround = oShade;
    var updatePath = SetDivisonPathIn(oPath); //*******  REMEMBER TO UNCOMMENT WHEN NOT LOCAL

    try {
        if ($("#jquery_div").length) $("#jquery_div").remove();
        if ($("#dynamicVideo").length) $("#dynamicVideo").remove();
        if ($("#dynamicWm").length) $("#dynamicWm").remove();
        //if ($("#dynamicObject").length) $("#dynamicObject").remove();
        //if($("#divDummy").length) $("#divDummy").remove();
    } catch (e) {
        //This is an IE issue.. that I am ignoring  ;-/
    }

    BuildImageButtonPath();
    if (oTitle != "") $('#' + oID + '').attr("title", oTitle);

    var iframeNew = document.createElement("iframe");
    var divJquery = document.createElement("div");
    
    divJquery.setAttribute('id', "jquery_div");

    /* - Frame for full control.  Append to div -*/
    iframeNew.setAttribute('id', "fancybox_iframe");
    iframeNew.setAttribute('background-color', "#ffffff");
    iframeNew.setAttribute('height', '565');
    iframeNew.setAttribute('width', '750');
    iframeNew.setAttribute('frameBorder', '0');
    iframeNew.setAttribute('src', siteURL + oPath);
    iframeNew.setAttribute('scrolling', 'no');

    divJquery.appendChild(iframeNew);
    document.body.appendChild(divJquery);
    divJquery.style.display = "none";

    //------------ test without iframe --------------------------
    //var d = document.createElement("div");
    //divJquery.setAttribute('height', '565');
    //divJquery.setAttribute('width', '750');
    //divJquery.setAttribute('background-color', 'white');
    //d.setAttribute('id', "divDummy");
    //$('#divDummy').load('http://localhost/PublicWeb/Gallery.aspx');
    //divJquery.appendChild(d);
    //document.body.appendChild(divJquery);
    //divJquery.style.display = "none";
    //-------------------------------------------------------------

    $(document).ready(function() {
        $('a.' + oID + '').live('click', function() {
            $('a.' + oID + '').fancybox({
                'frameHeight': parseFloat(555),
                'frameWidth': parseFloat(750),
                'overlayShow': oShade,
                'autoScale': true,
                'showCloseButton': true,
                'enableEscapeButton': true,
                'hideOnContentClick': false,
                'zoomSpeedIn': 0,
                'zoomSpeedOut': 0,
                'callbackOnClose': function() {
                    $("#dynamicWm").remove();
                    $("#dynamicVideo").remove();
                    $("#jquery_div").remove();
                    //$("#dynamicObject").remove(); 
                    //$("#divDummy").remove();
                },//end callback
                'callbackOnShow': function() {
                    $('#fancy_content').css('background-color', '#ffffff');
                    $('#fancy_bg').css('background-color', '#ffffff');
                    $('#fancy_div').css('background-color', '#ffffff');
                } //end callback
            }).trigger('click');//end fancybox
        });//end live
    }); //end doc ready
} // end InitJqueryIframe method
/* -------------------- End Dynamic iframe jquery functionality ------------------*/


/* Display a pop-up message in a floating box... companyInfo and exit text can be null  */
function InstantMessage(message, companInfo, exitText, myHeight, myWidth, backShadow) {

    var aLink = document.createElement("a");
    aLink.setAttribute('id', "hyperLink");
    aLink.setAttribute('href', "#hyperLink");

    var popupDiv = document.createElement("div");
    popupDiv.setAttribute('id', "divPopup");
    document.body.appendChild(aLink).appendChild(popupDiv);

    try {
        $(document).ready(function() {
            $("#divPopup").css('font-size', '12px');
            $("#divPopup").css('color', 'black');
            $("#divPopup").html("<br/><div id=\"divMsg\">" + message + "</div>");
            $("#divPopup").append("<div style=\"position:absolute; bottom:0; right:0; text-align:right;\">" + companInfo + "</div>");
            $("#divPopup").append("<div style=\"position:absolute; top:25px; right:-5px; width:65px; text-align:right; \">" + exitText + "</div>");

            $("div#fancy_close").css('right', '5px');
            $("div#fancy_close").css('top', '5px');
            $("div#fancy_close").css('background-image', 'url(' + siteURL + 'images/buttons/fancy_closebox.png)');

            $("a#hyperLink").fancybox({
                'showCloseButton': true,
                'enableEscapeButton': false,
                'hideOnContentClick': false,
                'overlayShow': backShadow,
                'frameWidth': parseFloat(myWidth),
                'frameHeight': parseFloat(myHeight) + 50,
                'zoomSpeedIn': 0,
                'zoomSpeedOut': 0,
                'callbackOnShow': function() {
                    $('#fancy_div').css('background-color', '#ffffff');
                    $('#fancy_content').css('background-color', '#ffffff');
                    $('#fancy_bg').css('border', '1px blue solid');
                    OverlayNavBarsOnPage();
                }
            }).trigger('click');
            if ($("#hyperLink").length) $("#hyperLink").remove();
        });
    }
    catch (e) {
        if ($("#hyperLink").length) $("#hyperLink").remove();
        if ($("#divPopup").length) $("#divPopup").remove();
    }
}



/* IE7 will not print the whole document for multiple known reasons (i.e. browser bugs)
   One of the main reason is the "shrink to fit" by default.  MS recommends updating to IE8 or
   changing a setting in the registry..  Hear I am just removing the flash video image from print
   since it's normally the largest.. */
function IE7HideObject(theObject) {

    $(document).ready(function () {
        if ($.browser.msie && $.browser.version == "7.0") {
            if ($('#' + theObject + '').length) {

                $('#' + theObject + '').hide();
                setTimeout(function () {
                    jQuery('#' + theObject + '').show();
                }, 100);
            }
        }
    });

}
