// Get the domain - cookie functions will need this variable - mharen 12/26/01
thisdomain = document.location +"";
thisdomain = thisdomain.substring(thisdomain.indexOf('//')+2,thisdomain.length);
thisdomain = thisdomain.substring(0,thisdomain.indexOf('/'));
thisdomain = (navigator.appName != "Netscape")? thisdomain.substring(thisdomain.indexOf('.')+1,thisdomain.length): thisdomain;

//this function is used for email addresses to hide from spambots.
//example usage:
//<!-- Begin foil spambots -->
//<script language="Javascript">
//WriteEa ('car','eer-i','nfo');
//</script>
//<noscript>
//career&#45;info
//&#64;&#32;&#106;&#117;&#110;&#105;&#112;&#101;&#114;&#32;&#46;&#32;&#110;&#101;&#116;
//</noscript>
//<!-- End foil spambots -->
function WriteEa (first, second, third, disptext, subject) {
		var display, ema, ea;
		
		//if no subject is present
		if (subject == null){
			ema = first + second + third + '\&\#64\;' + 'otmcorp' + '\&\#46\;' + 'com';
			if (disptext == null) {
			display = ema;
			} else {
			display = disptext;
			}
		}
		else {
			display = first + second + third + '\&\#64\;' + 'otmcorp' + '\&\#46\;' + 'com' //text to display
			ema = first + second + third + '\&\#64\;' + 'otmcorp' + '\&\#46\;' + 'com' + '?subject=' + subject //actual go-to link
		} 		
		ea = '<a href=\"ma' + 'ilto:' + ema + '"' + '>' + display + '</a>' //writes href code and displays
		document.write (ea);
}

// This is for opening pop-up windows in a way that addresses usability complaints. Use this instead of target="_blank" 
// It guarentees that pop-up windows will be smaller than the parent window in both dimensions- mharen 7/13/01

// example usage: <a href="javascript:new_window('/video/corporate/','620','420','chrome=yes');">link</a> - with chrome
//                         <a href="javascript:new_window('/video/corporate/','620','420');"> - without chrome
function new_window(page, width, height, chrome)
{
if (chrome == "chrome=yes") {chrome="yes"} else {chrome="no"}
var w = width, h = height, docw = width, doch = height;
if (document.all) {
// the following is only available after onLoad
// get current window size for ie
  docw = document.body.clientWidth;
  doch = document.body.clientHeight;
}
// get window size for Netscape
else if (document.layers) {
   docw = window.innerWidth;
   doch = window.innerHeight;
}
if (docw <= w) {
w = (docw - 40)
}
if (doch <= h) {
h = (doch - 40)
}
var leftPos = (screen.width / 2) - (w / 2);
var topPos = (screen.height / 2) - (h / 2);    
OpenWin = this.open(page,"CtrlWindow","top="+topPos+",screenX="+topPos+", left="+leftPos+", screenY="+leftPos+",width="+w+",height="+h+", toolbar="+chrome+",menubar="+chrome+",location="+chrome+",status="+chrome+",scrollbars=yes,resizable=yes,");
}

//getCookie -- kevin 02/12/04
function getCookie(Name) {
   var search = Name + "="
   if (document.cookie.length > 0) { // if there are any cookies
      offset = document.cookie.indexOf(search) 
      if (offset != -1) { // if cookie exists 
         offset += search.length 
         // set index of beginning of value
         end = document.cookie.indexOf(";", offset) 
         // set index of end of cookie value
         if (end == -1) 
            end = document.cookie.length
         return unescape(document.cookie.substring(offset, end))
      } 
   }
}

// Cookie functions - mharen 12/21/01
function setCookie (name, value, hours, path, domain, secure) {
// This next little bit of code tests whether the user accepts cookies.
var acceptsCookies = false;
if(document.cookie == '') {
    document.cookie = 'acceptsCookies=yes'; // Try to set a cookie.
    if(document.cookie.indexOf('acceptsCookies=yes') != -1) {
	acceptsCookies = true; 
    }// If it succeeds, set variable
} else { // there was already a cookie
  acceptsCookies = true;
}
    if (acceptsCookies) { // Don't waste your time if the browser doesn't accept cookies.
	var not_NN2 = (navigator && navigator.appName 
		       && (navigator.appName == 'Netscape') 
		       && navigator.appVersion 
		       && (parseInt(navigator.appVersion) == 2))?false:true;

	if(hours && not_NN2) { // NN2 cannot handle Dates, so skip this part
	    if ( (typeof(hours) == 'string') && Date.parse(hours) ) { // already a Date string
		var numHours = hours;
	    } else if (typeof(hours) == 'number') { // calculate Date from number of hours
		var numHours = (new Date((new Date()).getTime() + hours*3600000)).toGMTString();
	    }
	}
	
	document.cookie = name + '=' + escape(value) + ((numHours)?(';expires=' + numHours):'') + ((path)?';path=' + path:'') + ((domain)?';domain=' + domain:'') + ((secure && (secure == true))?'; secure':''); // Set the cookie, adding any parameters that were specified.
    }
} // setCookie


//setCookie -- kevin 02/12/04 -- much simpler version
function setCookie2(name, value, expire) {
   document.cookie = name + "=" + escape(value)
   + ((expire == null) ? "" : ("; expires=" + expire.toGMTString()))
}

function readCookie(name) {
    if(document.cookie == '') { // there's no cookie, so go no further
	return false; 
    } else { // there is a cookie
	var firstChar, lastChar;
	var theBigCookie = document.cookie;
	firstChar = theBigCookie.indexOf(name);	// find the start of 'name'
	var NN2Hack = firstChar + name.length;
	if((firstChar != -1) && (theBigCookie.charAt(NN2Hack) == '=')) { // if you found the cookie
	    firstChar += name.length + 1; // skip 'name' and '='
	    lastChar = theBigCookie.indexOf(';', firstChar); // Find the end of the value string (i.e. the next ';').
	    if(lastChar == -1) lastChar = theBigCookie.length;
	    return unescape(theBigCookie.substring(firstChar, lastChar));
	} else { // If there was no cookie of that name, return false.
	    return false;
	}
  }	
} // readCookie

function killCookie(name, path, domain) {
  var theValue = readCookie(name); // We need the value to kill the cookie
  if(theValue) {
      document.cookie = name + '=' + theValue + '; expires=Fri, 13-Apr-1970 00:00:00 GMT' + ((path)?';path=' + path:'') + ((domain)?';domain=' + domain:''); // set an already-expired cookie
  }
} // killCookie

