function popUpImage(url, width, height) 
{
    var windowWidth = parseInt( width ) + 40;
    var windowHeight = parseInt(height) + 40;
    //alert ("url = " + url + "    width = " + width + "     height = " + height);
    var attributes = 'width=' + windowWidth + ',height=' + windowHeight + ',resizable=1';
    var newwindow=window.open(url,'', attributes);
}



	
	function positionSearchBox()
	{
//	    if (navigator.userAgent.indexOf("Firefox") == -1) {
//            document.getElementById('navSearchBox').style.zIndex = 1000;
//            document.getElementById('navSearchBox').style.width = 930;
//            document.getElementById('searchFrame').style.zIndex = 1000;
//        }
	}
	
	function loadJsOrCssFile(filename, filetype)
    {
         if (filetype=="js")
         { //if filename is a external JavaScript file
             var fileref=document.createElement('script')
             fileref.setAttribute("type","text/javascript")
             fileref.setAttribute("src", filename)
         }
         else if (filetype=="css")
         { //if filename is an external CSS file
             var fileref=document.createElement("link")
             fileref.setAttribute("rel", "stylesheet")
             fileref.setAttribute("type", "text/css")
             fileref.setAttribute("href", filename)
         }
         
         if (typeof fileref!="undefined")
             document.getElementsByTagName("head")[0].appendChild(fileref)
    }
    
    //dynamically load and add this .css file
    loadJsOrCssFile("/amalga/_assets/css/MedCMSHideChrome.css", "css") 

    function setup()
	{
	    setTimeout ('positionSearchBox()', 500);
        setTimeout ( 'setupFooter()', 20 );	
	    
	    document.getElementById('msviMasthead').style.visibility='hidden';
	    document.getElementById('masthead').style.display='block';
    	
//	    var silverlightLink = document.getElementById('msviMarketing');
//	    var silverlightContainer = document.getElementById('cps');
//	    silverlightLink = silverlightLink.childNodes[0];
//	    if (silverlightLink.href.indexOf("amalga/") == -1) 
//	        silverlightLink.target="_blank";
//	    Move.element(silverlightLink, silverlightContainer, 'move');

	    var globalToolbar = document.getElementById('msviGlobalToolbar');
	    var locationContainer = document.getElementById('location');
	    globalToolbar = globalToolbar.childNodes[0];
	    var anchors = globalToolbar.getElementsByTagName("a");
        for (i = 0; i < anchors.length; i++) {
            if (anchors[i].href.indexOf("amalga/") == -1) 
                anchors[i].target="_blank";
        }
	    Move.element(globalToolbar, locationContainer, 'move');


	    var searchform = document.getElementById('msviLSBForm');
	    var searchformContainer = document.getElementById('globalsearch');
	    Move.element(searchform, searchformContainer, 'move');
	    document.getElementById('msviLSBForm').style.display='inline';
	    //document.getElementById('msviLSBForm').childNodes[2].style.width=170;
	    //document.getElementById('msviLSBForm').childNodes[2].style.fontSize=10;
	    //document.getElementById('msviLSBForm').childNodes[2].style.height=15;
		//document.getElementById('msviLSBForm').childNodes[5].style.display='none';
	    
//	    if (navigator.userAgent.indexOf("Firefox") == -1 && navigator.userAgent.indexOf("Safari") == -1) {
//		    document.getElementById('msviLSBssearch').style.display='none';
//		    try {document.getElementById('msviLSBWeb').style.display='none';} catch(e) {}
//		    try {document.getElementById('msviLSBsweb').style.display='none';} catch(e) {}
//		    var newBtn = document.createElement("<INPUT TYPE='IMAGE' id='btnGo' SRC='" + localizedString_SearchGoButtonImagePath + "' height='" + localizedString_SearchGoButtonImageHeight + "' width='" + localizedString_SearchGoButtonImageWidth + "' style='margin-left:8px;' alt='" + localizedString_SearchGoButtonAltText + "' >");
//		    document.getElementById('msviLSBForm').appendChild(newBtn);
//	    }
//	    else {
//	        document.getElementById('msviLSBssearch').style.display='none';
//		    try {document.getElementById('msviLSBWeb').style.display='none';} catch(e) {}
//		    try {document.getElementById('msviLSBsweb').style.display='none';} catch(e) {}
//	        var newBtn = document.createElement('input');
//	        document.getElementById('msviLSBForm').appendChild(newBtn);
//            newBtn.setAttribute('type', 'IMAGE');
//            newBtn.setAttribute('id', 'btnGo');
//           
//            newBtn.setAttribute('SRC', localizedString_SearchGoButtonImagePath);
//            newBtn.style.margin = "2px 0px 0px 0px";
//	        document.getElementById('msviLSBForm').appendChild(newBtn);
//	    }
    }

	function setupFooter()
	{
	    //footer elements can take a while to render...may have to check again later
	    try {
	        document.getElementById('msviFooter').style.visibility='hidden';
	    //alert ("trying to do footer");
	        if (document.getElementById('pagetools') != null)
	            document.getElementById('pagetools').style.visibility='hidden';
	        var footer = document.getElementById('msviFooter');
	        //footer.style.visibility='hidden';
	        footer = footer.nextSibling;
	        footer.style.visibility='hidden';
	        footer = footer.nextSibling;
	        footer.style.visibility='hidden';
	    }
	    catch(e)
	    {
	        setTimeout ( 'setupFooter()', 20 );
	        return;
	    }

        //after this point, just retrying this function won't be of much help, 
        //so hopefully the catches above will be enough to allow elements to be rendered.
        

	    var footerGlobalTarget = document.getElementById('FooterRight');
	    var footerLocalTarget = document.getElementById('FooterLeft');
	    //alert ('localFooter = ' + document.getElementById('msviLocalFooter'));
	    var footerSourceElement = document.getElementById('msviLocalFooter');
	    if (footerSourceElement != null)
	    {
            var anchor = document.createElement("<a>");
            anchor.innerHTML = "HealthVault";
            anchor.className = "FooterLink";
            anchor.href = "http://www.healthvault.com";
            anchor.target="_blank";
	        footerSourceElement.appendChild(anchor);
            
            var separatorLocal = document.createElement("<span>");
            separatorLocal.className = 'Spacer';
            separatorLocal.innerHTML = "|";
            footerSourceElement.appendChild(separatorLocal);
            
            anchor = document.createElement("<a>");
            anchor.innerHTML = "Microsoft in Health";
            anchor.className = "FooterLink";
            anchor.href = "http://www.microsoft.com/health";
            anchor.target="_blank";
	        footerSourceElement.appendChild(anchor);
    	    
            separatorLocal = document.createElement("<span>");
            separatorLocal.className = 'Spacer';
            separatorLocal.innerHTML = "|";
            footerSourceElement.appendChild(separatorLocal);
            
            anchor = document.createElement("<a>");
            anchor.innerHTML = "Blogs";
            anchor.className = "FooterLink";
            anchor.href = "/amalga/library/default.mspx#blogs";
	        footerSourceElement.appendChild(anchor);
	    
    	    
	        var anchors = footerSourceElement.getElementsByTagName("a");
	        //alert ('# anchors = ' + anchors.length);

	        for (i = 0; i < anchors.length; i++) {
	            if (anchors[i].href.indexOf("amalga/") == -1) 
	                anchors[i].target="_blank";
	                
	            if (anchors[i].innerHTML.indexOf(localizedString_ManageYourProfile) == -1)
	            {
	            Move.element(anchors[i], footerLocalTarget, 'copy');
	            if (i < anchors.length-1) {
	                var separator = document.createElement("<span>");
	                separator.className = 'Spacer';
	                separator.innerHTML = "|";
	                footerLocalTarget.appendChild(separator);
	            }
	            }
	        }
	    }

        //move "Contact Us" link from Global to local, and change href
	    footerSourceElement = document.getElementById('msviGlobalFooter');
	    if (footerSourceElement != null)
	    {
	        anchors = footerSourceElement.getElementsByTagName("a");
	        //alert ('# anchors = ' + anchors.length);
	        for (i = 0; i < anchors.length; i++) {
	            if (anchors[i].href.indexOf("/amalga/") == -1) 
	                anchors[i].target="_blank";
	                
	            if (anchors[i].innerHTML.indexOf(localizedString_ContactUs) != -1)
	            {
		            separatorLocal = document.createElement("<span>");
	                separatorLocal.className = 'Spacer';
	                separatorLocal.innerHTML = "|";
	                footerLocalTarget.appendChild(separatorLocal);
	                anchors[i].target="_self";
	                anchors[i].href = localizedString_ContactUsURL; // "http://go.microsoft.com/?linkid=2028382";
	                Move.element(anchors[i], footerLocalTarget, 'copy');
                }
	        }
    	    
//	        var brk = document.createElement("<br>");
//	        footerTarget.appendChild(brk);

	        //alert ('globalFooter = ' + document.getElementById('msviGlobalFooter'));
	        footerSourceElement = document.getElementById('msviGlobalFooter');
	        anchors = footerSourceElement.getElementsByTagName("a");
	        //alert ('# anchors = ' + anchors.length);
	        for (i = 0; i < anchors.length; i++) {
	            if (anchors[i].href.indexOf("amalga/") == -1) 
	                anchors[i].target="_blank";
	                
	            if (anchors[i].innerHTML.indexOf(localizedString_ContactUs) == -1)
	            {
	                Move.element(anchors[i], footerGlobalTarget, 'copy');
	                if (i < anchors.length-1) {
	                    //alert ('processing anchor# ' + i);

	                    var separator = document.createElement("<span>");
	                    separator.className = 'Spacer';
	                    separator.innerHTML = "|";
	                    footerGlobalTarget.appendChild(separator);
	                }
	            }
	        }
	    }

	    try {
	        var footer = document.getElementById('msviFooter');
	        var footerbackground = footer.nextSibling;
	        footerbackground = footerbackground.nextSibling;
	        footer.parentNode.removeChild(footer);
	        footerbackground.parentNode.removeChild(footerbackground);
	        var pagetools = document.getElementById('pagetools');
	        if (pagetools != null)
	            pagetools.parentNode.removeChild(pagetools);
	    }
	    catch(e)
	    {
	    }

	}

	var Move =	{
	    copy	:   function(e, target)	{
	    var eId      = e;
	    var copyE    = eId.cloneNode(true);
	    var cLength  = copyE.childNodes.length -1;
	    copyE.id     = e.id+'-copy';
	    for(var i = 0; cLength >= i;  i++)	{
	        if(copyE.childNodes[i].id) {
	            var cNode   = copyE.childNodes[i];
	            var firstId = cNode.id;
	            cNode.id    = firstId+'-copy'; 
	        }
	    }
	    target.appendChild(copyE);
	    },
	    element:  function(e, target, type)	{
	        var eId =  e;
	        if(type == 'move') {
	            target.appendChild(eId);
	        }

	        else if(type == 'copy')	{
	            this.copy(e, target);
	        }
	    }
	}

