document.onclick = leftHoverMenu_close;

	// this script creates a side border to .contentBoxTop the same color as .contentBox background color
        $(document).ready(function() {
                var $color = $(".siteBackColorLight").css("background-color");
                // test to check what color we got
                //alert($color);
                $('.contentBoxTop').css({'border-left': '10px solid ' + $color});
        });

var timeout    = 500;
var closetimer = 0;
var ddmenuitem = 0;

function leftHoverMenu_open()
{  leftHoverMenu_canceltimer();
   leftHoverMenu_close();
   ddmenuitem = $(this).find('ul').css('visibility', 'visible');}

function leftHoverMenu_close()
{  if(ddmenuitem) ddmenuitem.css('visibility', 'hidden');}

function leftHoverMenu_timer()
{  closetimer = window.setTimeout(leftHoverMenu_close, timeout);}

function leftHoverMenu_canceltimer()
{  if(closetimer)
   {  window.clearTimeout(closetimer);
      closetimer = null;}}

$(document).ready(function()
{  $('#leftHoverMenu > li').bind('mouseover', leftHoverMenu_open)
   $('#leftHoverMenu > li').bind('mouseout',  leftHoverMenu_timer)

// create the white dotted separators in the nav
	$('#zz1_GlobalNav td[id!=""]:not(:last)').css('border-right', '1px dashed #a7cd80');

	// create a new colored bar under the nav that will correctly create the bottom color
	$('#zz1_GlobalNav > tbody:last').append('<tr> <td id="cc"></td> <td></td><td></td> <td id="hw"></td> <td></td><td></td> <td id="ri"></td> <td></td><td></td> <td id="su"></td> <td></td><td></td> <td id="gl"></td> <td></td><td></td> <td id="dri"></td> <td></td> </tr>');
	
	// finally... outright remove the empty cells in the nav. They are useless and not needed
	$('#zz1_GlobalNav > tbody > tr > td').filter('[id=""]').remove();


});


function GetSearchResults()
{
	window.location.href = window.location.protocol + "//" + window.location.host + "/" + "fast/Pages/results.aspx?k=" + $('input#txtSearchBox').val();
	//window.location.href = window.location.protocol + "//" + window.location.host + "/" + "pages/Results.aspx?k=" + $('input#txtSearchBox').val()+'&s=USDairy';
}

function checkEnter(e)
{ 
	var characterCode; 
	
	if(e && e.which) 
	{ 
		e = e;
		characterCode = e.which; 
	}
	else
	{
		e = event;
		characterCode = e.keyCode;
	}
	if (characterCode == 13)
	{ 
	// disable default form submit.
		$("form").submit(function() {
		return false;
	});
				
	window.location.href = window.location.protocol + "//" + window.location.host + "/" + "fast/pages/results.aspx?k=" + $('input#txtSearchBox').val();
	//window.location.href = window.location.protocol + "//" + window.location.host + "/" + "pages/Results.aspx?k=" + $('input#txtSearchBox').val()+'&s=USDairy';	
	return false;
	}
	else 
	{
		return true;
	}
}

function rewriteUserGreeting() {
                var spanTag = document.getElementById("ctl00_CLCId_LoginView1_LoginName1");
                if(spanTag != null) {
                                var rawUserName = spanTag.innerHTML;
                                if(rawUserName != null && rawUserName.indexOf("dmi\\") != -1) {
                                                spanTag.innerHTML = rawUserName.substring(rawUserName.indexOf("\\") + 1, rawUserName.length);
                                } else {
                                                if(rawUserName != null && rawUserName.indexOf("usdairymembershipprovider") != -1) {
                                                                spanTag.innerHTML = rawUserName.substring(rawUserName.indexOf("usdairymembershipprovider") + 26, rawUserName.length);
                                                }
                                }
                }
}

_spBodyOnLoadFunctionNames.push("rewriteUserGreeting");
		


  var _gaq = _gaq || [];
  _gaq.push(['_setAccount', 'UA-273739-23']);
  _gaq.push(['_trackPageview']);

  (function() {
    var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
    ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
    var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
  })();
  
   function toggle_visibility() {
       document.getElementById('Loginarea2').style.display = ''; 
       document.getElementById('newLogin').style.display = 'none';
       }


       function ChangeHrefURLsForDocuments() {
           // first, grab the url's protocol and hostname
		   try{
			   var site = window.location.protocol + "//" + window.location.hostname;

			   var isITFast = window.location.pathname.toLowerCase().indexOf("/fast/");
			   
				// not fast web site
				if(isITFast != 0){
				   // now filter the anchor tags based on their href value and loop through them
				   $("a").filter(function () {
					   return /(ppt|pptx|doc|docx|pdf|xls|xlsx)$/i.test($(this).attr('href'));
				   }).each(function (index, e) {
					   // build the new url to replace the old one
					   var NewURL = "javascript:STSNavigate('" + site + "/_layouts/download.aspx?SourceUrl=" + $(e).attr("href") + "');";

					   // alert the URL for testing
					   //alert(NewURL);

					   // finally set the href value
					   $(e).attr("href", NewURL);
					   $(e).attr("target", "");
				   });
			   }
		   }
		   catch(e) { 
		   }
       }

       _spBodyOnLoadFunctionNames.push("ChangeHrefURLsForDocuments");

function commTools()
{
            window.location.href = window.location.protocol + "//" + window.location.host + "/" +"fast/Pages/CommunicationTools.aspx?k=ContentSource:\"UsDairy Prod\"";            
}




