//=============================================================
// dyn_menu.js
//
// ESTABLISH BROWSER AND PLATFORM
// ADAPTED FROM NETSCAPE WITH PERMISSION
//=============================================================
var detect = navigator.userAgent.toLowerCase();
var OS,browser,version,total,thestring;
var redriectUrl = "/browser_update.html";
var e;

if (checkIt('konqueror')) {
	browser = "Konqueror";
	OS = "Linux";
}
else if (checkIt('safari')) browser = "Safari";
else if (checkIt('omniweb')) browser = "OmniWeb";
else if (checkIt('opera')) browser = "Opera";
else if (checkIt('webtv')) browser = "WebTV";
else if (checkIt('icab')) browser = "iCab";
else if (checkIt('msie')) browser = "Internet Explorer";
else if (!checkIt('compatible')) {
	browser = "Netscape Navigator";
	version = detect.charAt(8);
}
else browser = "An unknown browser";

if (!version) version = detect.charAt(place + thestring.length);

if (!OS) {
	if (checkIt('linux')) OS = "Linux";
	else if (checkIt('x11')) OS = "Unix";
	else if (checkIt('mac')) OS = "Mac";
	else if (checkIt('win')) OS = "Windows";
	else OS = "an unknown operating system";
}

function checkIt(string) {
	place = detect.indexOf(string) + 1;
	thestring = string;
	return place;
}

var agt = navigator.userAgent.toLowerCase();
var is_major = parseInt(navigator.appVersion);
var is_minor = parseFloat(navigator.appVersion);

var is_nav    = ((agt.indexOf('mozilla')!=-1) && (agt.indexOf('spoofer')==-1) && (agt.indexOf('compatible') == -1) && (agt.indexOf('opera')==-1) && (agt.indexOf('webtv')==-1));
var is_nav4   = (is_nav && (is_major == 4));
var is_nav4up = (is_nav && (is_major >= 4));
var is_nav5   = (is_nav && (is_major == 5));
var is_nav5up = (is_nav && (is_major >= 5));

var is_nav5dn = (is_nav && (is_major <= 5));

var is_ie    = (agt.indexOf("msie") != -1);
var is_ie4   = (agt.indexOf("msie 4")!= -1) ;
var is_ie4up = (is_ie && (is_major >= 4));
var is_ie5   = (is_ie && (is_major == 4) && (agt.indexOf("msie 5")!=-1) );
var is_ie5up = (is_ie && !is_ie4);

var is_aol   = (agt.indexOf("aol") != -1);
var is_aol4  = (is_aol && is_ie4);

var is_opera = (agt.indexOf("opera") != -1);
var is_webtv = (agt.indexOf("webtv") != -1);

var is_win = ( (agt.indexOf("win")!=-1) || (agt.indexOf("16bit")!=-1) );
var is_mac = (agt.indexOf("mac")!=-1);

var nscp4 = is_nav4;
var ie4   = is_ie4;
var dom1  = (is_nav5up || is_ie5up);
var is_ns622up;

if (is_mac && is_ie5) {
    dom1 = false;
}

//send a style sheet to fix mac spacing issues
if (is_mac) {
    document.write('<link rel="STYLESHEET" type="text/css" href="' + uwsserver + '/sites/styles/mac_margins.css">');
}

if (nscp4) {
    //send a style sheet to fix NS4 spacing issues
    document.write('<link rel="STYLESHEET" type="text/css" href="' + uwsserver + '/sites/styles/ns_margins.css">');
    //call function to write cookie and show popup
    oldbrowser();
} else if (is_ie4) {
    //call function to write cookie and show popup
    oldbrowser();
} else if (!nscp4 != true || is_ie != true ) {
    // subversion of netscape 6
    v = navigator.vendorSub;
    //clean up the agent
    var e = v.replace(/\./g,'');
    // do a little math
    //Empty string check added by shrinath to address mozilla browser issue
    if(e!="")
    {	
	    while (e<100) e*=10;
	    if (e < 622) {
	        //call function to write cookie and show popup if 6.2.1 or lower
	        is_ns622up = false; 
	        oldbrowser();
	    } else {
	        is_ns622up = true; 
	    }
    }//End of Empty String check	    
}

//write specfic styles for NS and Macs based on section
// mainly used to put the dropdowns in the right spot
// section = var set in page corresponds to name of style sheet
function getNSstyles(section){
	if (nscp4){
		document.write('<link rel="STYLESHEET" type="text/css" href="' + uwsserver + '/sites/styles/' + section + '_ns.css">');
	} else if (is_mac) {		
		if (is_ns622up){
			document.write('<link rel="STYLESHEET" type="text/css" href="' + uwsserver + '/sites/styles/' + section + '_mac_ns6+.css">');
		} else {
			document.write('<link rel="STYLESHEET" type="text/css" href="' + uwsserver + '/sites/styles/' + section + '_mac.css">');
		}	
	}
}

// follow link
// called by <TD> onClick event  
	
function follow_url(url) {
    //alert("inside follow_url-->"+url);
	document.location.href=url;
}
	
// initialize menu timer
// used in DHTML menus 
menuTimer = "";
menuSelected = "";

//used to display the login and download modules
function showMod(ele) {
	minus = (ele + "minus");
	plus = (ele + "plus");

	searchOpen(ele,1);
	searchOpen(minus,1);
	searchOpen(plus,0);
	createCookie('uwscookie','',-1);
}

function hideMod(ele) {
	minus = (ele + "minus");
	plus = (ele + "plus");

	searchOpen(ele,0);
	searchOpen(minus,0);
	searchOpen(plus,1);
	createCookie('uwscookie',ele,7);
}

function searchOpen(menunum, state) {
	value = (state==1) ? "block" : "none" ;
	
    if (is_ie) {
        document.all[menunum].style.display= value;		
    } else {
        if (is_nav5up) {		       	            
     	   var myLayer = document.getElementById(menunum);
           if (typeof myLayer != 'undefined' && myLayer != '' && myLayer != null) {
		myLayer.style.display = value;	
	    }
            //document.layers[menunum].visibility="hide";
        } else {
            document.layers[menunum].display= value;
            //document.layers[menunum].visibility="hide";	
            //document.layers[menunum].style.visibility="hide";
        }
    }	
}

//Setting separate cookie names for showing and hiding modules.
function showMod(ele,cookieName){	
	minus = (ele + "minus");
	plus = (ele + "plus");

	searchOpen(ele,1);
	searchOpen(minus,1);
	searchOpen(plus,0);
	createCookie(cookieName,'',-1);
}

function hideMod(ele,cookieName){	
	minus = (ele + "minus");
	plus = (ele + "plus");

	searchOpen(ele,0);
	searchOpen(minus,0);
	searchOpen(plus,1);
	createCookie(cookieName,ele,7);	
}

// menu controller
// menu_name = name of menu (= id) of layer to be turned on
// ele = element to get background color changed usually "this"
// style = which background color does it get.
function uwsMenu(menu_name, ele, style) {
    menuClose();
    
    if (currsection != menu_name){
        menuOpen(menu_name);
        if (style != 0) {
            slink(ele,style,style);
        }
    }
    setClose(false);
}

// open menus 
function menuOpen(menu_name){
    if (is_ie){
        var myLayer = document.all[menu_name];
        if (typeof myLayer != 'undefined') {
            myLayer.style.visibility = 'visible';		
        }
    } else {
        if (is_nav5up) {
            var myLayer = document.getElementById(menu_name);
            if (typeof myLayer != 'undefined') {
                myLayer.style.visibility = 'visible';
            }
        } else {
            var myLayer = document.layers[menu_name];
            if (typeof myLayer != 'undefined') {
                myLayer.visibility = 'visible';
            }
        }
    }	
}

// close all menus
function menuClose() {
    if (is_ie){
        // if you're leaving a level1 or 2 elelent 
        // turn off the bg color of the level one nav		
        for (var i=0; i < n1_keys.length; i++) {
            var myLayer = document.all['menu_'+n1_keys[i]];
            if (typeof myLayer != 'undefined') {
                myLayer.style.visibility = 'hidden';
            }
        }
    } else {
        if (is_nav5up){
            for (var i=0; i < n1_keys.length; i++) {
                var myLayer = document.getElementById('menu_'+n1_keys[i]);
                if (typeof myLayer != 'undefined') {
                    myLayer.style.visibility = 'hidden';
                }
            }
        } else {
            for (var i=0; i < n1_keys.length; i++) {
                var myLayer = document.layers['menu_'+n1_keys[i]];
                if (typeof myLayer != 'undefined') {
                    myLayer.visibility = 'hidden';
                }
            }
        }
    }
}

//changes row bgcolor on rollover
var on;
var off;

// show menu link highlighted
// ele = the element usually "this"
// style_num = the nav style 
// level1nav = which level1 element do you want to hightlight
function slink(ele, style_num, level1nav) {
	on = eval("bgnav" + style_num + "_on");
	setClose(false);
	
	//slinkL1(style_num,level1nav);
	
	if (is_ie){
		  ele.style.backgroundColor= on;
	} else {
		if(is_nav5up){
			ele.style.backgroundColor= on;
		} else {
			//do nothing
		}
	}
}

function slinkE(style_num, level1nav) {
	on = eval("bgnav" + style_num + "_on");
	setClose(false);
	
	slinkL1(style_num,level1nav);
}

//highlights the related levelone nav
function slinkL1(num, level1nav) {
	on2 = bgnav1_on;
	if (num == 2){
		if (is_ie) {
    		o = eval("document.all.level" + level1nav);
		} else if (is_nav5up) {
	        o = eval("document.getElementById('level" + level1nav + "')");
		}
		o.style.backgroundColor = on2;
	}	
}

// changes the level 1 nav back to the off state
// level1nav = the # portion of the level1 nav  TD id ( "level" + level1nav ) = "leveln 
// to change
function hlinkL1(level1nav) {
    off2 = bgnav1_off;
    if (level1nav != 0) {
        if (is_ie) {
            o = eval("document.all.level" + level1nav);
        } else if (is_nav5up) {
            o = eval("document.getElementById('level" + level1nav + "')");
        }	
        o.style.backgroundColor = off2;
    }	
}

// show menu link highlighted
//ele = the element usually "this"
//style = the nav style 
function slink2(ele, style) {
	// choose the color 
	on = eval("nav" + style + "_on");
	
	// don't close the menu
	setClose(true);
	// change the font color to the highlighted state
	if (is_ie){
		o = eval("document.all.s_" + ele);
		o.style.color = on;
	} else {
		if(is_nav5up){
			o = eval("document.getElementById('s_" + ele +"')");
			o.style.color = on;
		} else {
			//do nothing
		}
	}
}

// hide menu link highlighted
// ele = the element to change (generally 'this')
// num = the nav level used to set the correct style
// level1nav = used to compute the id of the TD 
function hlink(ele, num, level1nav) {
    setClose(true);
	off = eval("bgnav" + num  + "_off");
	off2 = bgnav1_off ;//alert("hlink-->off2-->"+off2);
	//alert("hlink-->currsection, level1nav-->"+currsection+" ,"+level1nav);
//	if (currsection == level1nav){
		if (level1nav == 0 || level1nav == 1 || level1nav == 2 || level1nav == 3 || level1nav == 4 || level1nav == 5 || level1nav == 6){
		//call function to control the first level nav bg color
		hlinkL1(level1nav);
		// change the bgcolor of "this" element back to the off state
        if (is_ie){
            ele.style.backgroundColor= off;	
            ele.style.cursor='hand';
        } else if (is_nav) {
    		if(is_nav5up){
			    ele.style.backgroundColor= off;	
	        } else {
			    // do nothing
		    }
		}
    } 
}

// hide menu link highlighted
// changes font color of second nav link
// on TD mouseout
// ele = the element to change usually an <a> who's id begins with "s"
// style corresponds to the color to change it to. 
function hlink2(ele, style) {
  setClose(true);
  off = eval("nav" + style  + "_off");
	if (is_ie) {
		o = eval("document.all.s_" + ele);
		o.style.color= off;
	    o.style.cursor='hand';
	} else if (is_nav) {
		if (is_nav5up) {
		    o = eval("document.getElementById('s_" + ele +"')");
	        o.style.color= off;
	    } else {
	        // ele.bgColor=off;
	    }
	}
}

// this keeps NS 6+ from closing the submenus when the ilayer is moused over
function nsSetClose(bool) {
    if (nscp4) {
        setClose(bool);
    }
}
function nsMenu(ele) {
    if (nscp4) {
        uwsMenu(ele, this, 1);
    }	
}

// begin timer to close menu
function setClose(bool) {
    m = "menuClose()";
    //	alert(m);
    
    switch(bool) {
        case true:
            menuTimer = setTimeout(m, 250);
            break;
        case false:
            if (typeof menuTimer != 'undefined') {
                clearTimeout(menuTimer);
            }
            break;
    }
}

// pop-up
function pop(url){
    var sOptions = 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes';
    sOptions += ',resizable=no,width=529,height=450,top=50,left=150'
    window.open(url, 'win', sOptions); 
}

// Cookie functions
function oldbrowser(){	
    // create an instance of the Date object
    var now = new Date();
    // fix the bug in Navigator 2.0, Macintosh
    fixDate(now);
    // cookie expires in one year (actually, 365 days)
	
    now.setTime(now.getTime() + 365 * 24 * 60 * 60 * 1000);
    var visits = getCookie("oldbrowser");
    // if the cookie wasn't found, this is your first visit
    if (!visits) {
        pop(redirectUrl) ;
    } else {
        // increment the counter
        visits = parseInt(visits) + 1;
    }
    // set the new cookie
    setCookie("oldbrowser", visits, now);
}

// name - name of the cookie
// value - value of the cookie
// [expires] - expiration date of the cookie (defaults to end of current session)
// [path] - path for which the cookie is valid (defaults to path of calling document)
// [domain] - domain for which the cookie is valid (defaults to domain of calling document)
// [secure] - Boolean value indicating if the cookie transmission requires a secure transmission
// * an argument defaults when it is assigned null as a placeholder
// * a null placeholder is not required for trailing omitted arguments
function setCookie(name, value, expires, path, domain, secure) {
  var curCookie = name + "=" + escape(value) +
      ((expires) ? "; expires=" + expires.toGMTString() : "") +
      ((path) ? "; path=" + path : "") +
      ((domain) ? "; domain=" + domain : "") +
      ((secure) ? "; secure" : "");
  document.cookie = curCookie;
}

// name - name of the desired cookie
// * return string containing value of specified cookie or null if cookie does not exist
function getCookie(name) {
  var dc = document.cookie;
  var prefix = name + "=";
  var begin = dc.indexOf("; " + prefix);
  if (begin == -1) {
    begin = dc.indexOf(prefix);
    if (begin != 0) return null;
  } else
    begin += 2;
  var end = document.cookie.indexOf(";", begin);
  if (end == -1)
    end = dc.length;
  return unescape(dc.substring(begin + prefix.length, end));
}

// name - name of the cookie
// [path] - path of the cookie (must be same as path used to create cookie)
// [domain] - domain of the cookie (must be same as domain used to create cookie)
// * path and domain default if assigned null or omitted if no explicit argument proceeds
function deleteCookie(name, path, domain) {
  if (getCookie(name)) {
    document.cookie = name + "=" + 
    ((path) ? "; path=" + path : "") +
    ((domain) ? "; domain=" + domain : "") +
    "; expires=Thu, 01-Jan-70 00:00:01 GMT";
  }
}

// date - any instance of the Date object
// * hand all instances of the Date object to this function for "repairs"
function fixDate(date) {
  var base = new Date(0);
  var skew = base.getTime();
  if (skew > 0)
    date.setTime(date.getTime() - skew);
}

//used to display instructional text in password field.
//just writes a password field without DHTML for NS 4x
function writePswdField() {
	if (nscp4){
		document.write("password<br><input type=\"password\" value=\"\" name=\"UserPassword\" size=\"12\">");
	}
	else{
        document.write("<input type=\"password\" style=\"position:absolute;visibility:hidden;\" value=\"\" name=\"UserPassword\" class=\"search\"><input type=\"text\" value=\"Password\" onFocus=\"this.style.visibility='hidden';document.login.UserPassword.style.visibility='visible';document.login.UserPassword.focus();\"name=\"dummy\" class=\"search\">");
	}	
}

function removeText(obj) {
	obj.value = "";
}

function hideFormElements(val){
	// val says which drop down section
	// for our business in sm
	if ((currsection==3)&&(currsection2==1)) {
		var sturl = location.search;
		var le1= sturl.indexOf("theme=");
		le1=le1+6;
		var le2=le1+2;
		var strtheme=sturl.substring(le1,le2);
		if(strtheme=='T7') {
    		if(val==2){
    			document.getElementById("month").style.visibility="hidden";
    			document.getElementById("year").style.visibility="hidden";
    			document.getElementById("month1").style.visibility="hidden";
    			document.getElementById("year1").style.visibility="hidden";
    		}
    		// for investor relaions in sm
    		if(val==4) {
    			document.getElementById("selcat").style.visibility="hidden";
    			document.getElementById("pgno").style.visibility="hidden";
    		}
		}
	}
	// for Products & Applications in em
	if ((currsection==4)&&(currsection2==1)) {
		var sturl = location.search;
		var le1= sturl.indexOf("theme=");
		le1=le1+6;
		var le2=le1+2;
		var strtheme=sturl.substring(le1,le2);
		if(strtheme=='T7') {
        	if(val==2){
        		document.getElementById("month").style.visibility="hidden";
        		document.getElementById("year").style.visibility="hidden";
        		document.getElementById("month1").style.visibility="hidden";
        	}
		}
	}
	
	// to hide elements when control is in advanced search page
	var strurl = location.search;
	var l1= strurl.indexOf("page=");
	l1=l1+5;	// adding the length of "page="
	var l2=l1+9;
	var strpage = strurl.substring(l1,l2);
	if((strpage=='advsearch')&&(val==4)){
		document.getElementById("advs").style.visibility="hidden";	
	}
}

function showFormElements(val) {
	if((currsection==3)&&(currsection2==1)) {
		// for our business in sm
		var sturl = location.search;
		var le1= sturl.indexOf("theme=");
		le1=le1+6;
		var le2=le1+2;
		var strtheme=sturl.substring(le1,le2);
		if(strtheme=='T7') {
		if(val==2) {
			document.getElementById("month").style.visibility="visible";
			document.getElementById("year").style.visibility="visible";
			document.getElementById("month1").style.visibility="visible";
			document.getElementById("year1").style.visibility="visible";
		}
		// for investor relaions in sm
		if(val==4){
			document.getElementById("selcat").style.visibility="visible";
			document.getElementById("pgno").style.visibility="visible";
		}
		}
	}
	
	// for Products & Applications in em
	if((currsection==4)&&(currsection2==1)) {
		var sturl = location.search;
		var le1= sturl.indexOf("theme=");
		le1=le1+6;
		var le2=le1+2;
		var strtheme=sturl.substring(le1,le2);
		if(strtheme=='T7') {
		if(val==2) {
			document.getElementById("month").style.visibility="visible";
			document.getElementById("year").style.visibility="visible";
			document.getElementById("month1").style.visibility="visible";
		}
		}
	}
	// to show elements when control is in advanced search page
	var strurl = location.search;
	var l1= strurl.indexOf("page=");
	l1=l1+5;	// adding the length of "page="
	var l2=l1+9;
	var strpage = strurl.substring(l1,l2);
	if((strpage=='advsearch')&&(val==4)){
		document.getElementById("advs").style.visibility="visible";	
	}
}

function createCookie(name,value,days) {
    if (days) {
        var date = new Date();
        date.setTime(date.getTime()+(days*24*60*60*1000));
        var expires = "; expires="+date.toGMTString();
    }
    else var expires = "";
    document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
    var nameEQ = name + "=";
    var ca = document.cookie.split(';');
    for(var i=0;i < ca.length;i++) {
        var c = ca[i];
        while (c.charAt(0)==' ') c = c.substring(1,c.length);
        if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
    }
    return null;
}

function eraseCookie(name) {
	createCookie(name,"",-1);
}
