/* Add delay to top nav drop down */
function attachHooks() {
	var menu = document.getElementById('navbar');
	var menuItems = menu.getElementsByTagName('li');
	var thisSubMenu;
	
	for (var i=0; i<menuItems.length; i++)
	{
    	menuItems[i].onmouseover = function() {activateMenuWithDelay();};
    	menuItems[i].onmouseout = function() {deactivateMenuWithDelay();};
	}
}

function activateMenuWithDelay() {
	var menu = document.getElementById('navbar');
	if (menu.timer) {
		clearTimeout(menu.timer);
	}
	menu.timer = setTimeout("activateMenu()", 400);
}

function activateMenu() {
	var menu = document.getElementById('navbar');
	menu.setAttribute('class', 'activeMenu');
}


function deactivateMenu() {
	var menu = document.getElementById('navbar');
	menu.setAttribute('class', 'inactiveMenu');
}

function deactivateMenuWithDelay() {
	var menu = document.getElementById('navbar');
	if (menu.timer) {
		clearTimeout(menu.timer);
	}
	menu.timer = setTimeout("deactivateMenu()", 500);
}

function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      oldonload();
      func();
    }
  }
}

addLoadEvent(attachHooks);
addLoadEvent(deactivateMenu);


/* Code to all hover dropdown for IE6 - Currently used for country nav and top navigation dropdown */

//Conditional to put script in IE6 browsers
var isIE6 = (navigator.userAgent.toLowerCase().substr(25,6)=="msie 6") ? true : false;

if (isIE6 == true ) {

	// JS used to make 
	
	function sfHover(element_id) {
		  var sfEls = document.getElementById(element_id).getElementsByTagName("li");
		  for (var i=0; i<sfEls.length; i++) {
              sfEls[i].onmouseover=function() {
                 this.className+=" sfhover";
              }
              sfEls[i].onmouseout=function() {
                 this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
    	}
 	  }
	}
// Add the IDs that you want to use the hover function below - CSS must have a hover "sfhover" class too
	function sfStart() {
	  sfHover("countrynav");
	  sfHover("navbar");
	}
	if (window.attachEvent) window.attachEvent("onload", sfStart);
}

/* Pop-up Window */
function openWindow ( url, width, height, options, name ) {
  if ( ! width ) width = 640;
  if ( ! height ) height = 420;
  if ( ! options ) options = "scrollbars=yes,menubar=yes,toolbar=yes,location=yes,status=yes,resizable=yes";
  if ( ! name ) name = "outsideSiteWindow";
  var newWin = window.open( url, name, "width=" + width + ",height=" + height + "," + options );
} // end function openWindow

function checkSiteSearchLanguage(){
  var form_name = 'search';
  var lang = document.forms[form_name].elements['search_lang_selection'].value;

  if (lang == 'en'){
     document.forms[form_name].setAttribute("target","_blank");
     submit_action = 'http://www.mathworks.com/cgi-bin/texis/webinator/search/';
  }else{
     document.forms[form_name].removeAttribute("target");
     submit_action = '/cgi-bin/texis/webinator/search_jp/';
  }

  document.forms[form_name].action = submit_action;
}

/* Print this Page */
function printWindow () {
   bV = parseInt(navigator.appVersion)
   if (bV >= 4) window.print()
} // end function printWindow


/* Onclick Omniture Code for Auto-Redirect testing */
function addOmnitureCode(txt) {
	 var s =s_gi(s_account);  
	s.linkTrackVars='prop36';
//	s.linkTrackEvents='event56';
	
	s.prop36= domain + "_" + txt; //please pick appropriate value from the spreadsheet
	//s.events='event56';
	s.tl(this,'o','Redirects Cookie');
	
}