// javascript routines for univision.com
// *** NOTE this is version 1.1 - file must be lib_1_10.js,
// ***      to avoid conflicts with 1.0 pages
var bannerToggle = 1; // this is set dynamically
var isNav, isIE;
if (navigator.appName == "Netscape") {
    isNav = true;
} else {
    isIE = true;
}

// function defines variables for cross-browser compatibility
function init(){
    if (isNav) {
	layerStyleRef="layer.";
	layerRef="document.layers";
	styleSwitch="";
	visiblevar="show";
    } else {
	layerStyleRef="layer.style.";
	layerRef="document.all";
	styleSwitch=".style";
	visiblevar="visible";
    }
} // function init()

// following functions manipulate image mouseovers
function lnavOn(v) {
    eval("document.images."+v+".src = "+v+"on.src");
}
function lnavOff(v) {
    eval("document.images."+v+".src = "+v+"off.src");
}

// manipulate layers
function showLayer(layerName){
    eval(layerRef+'["'+layerName+'"]'+styleSwitch+'.visibility="visible"');
}
function hideLayer(layerName){
    eval(layerRef+'["'+layerName+'"]'+styleSwitch+'.visibility="hidden"');
}

// following function toggles pull-down menus on and off
function menuToggle(layerName){
    if (eval(layerRef+'["'+layerName+'"]'+styleSwitch+'.visibility == visiblevar')){
	hideLayer(layerName);
	// show the subsection selector if present
	if (eval(layerRef+'["subsectionMenu"]')) showLayer("subsectionMenu");
    } else {
	showLayer(layerName);
	// hide any other menus if necessary
	menus = ['canMenu','comMenu','busMenu'];
	for (i in menus) {
	    if (menus[i] != layerName) {
		hideLayer(menus[i]);
	    }
	}
	// hide the subsection selector if present
	if (eval(layerRef+'["subsectionMenu"]')) hideLayer("subsectionMenu");
    }
    return false;
}

// returns the value of the named cookie, or null
function getCookie(name) {
    var allcookies = document.cookie;
    var pos = allcookies.indexOf(name+"=");
    if (pos == -1) {
        return null;
    } else {
        var start = pos + (name.length + 1);
	var end = allcookies.indexOf(";",start);
	if (end == -1) end = allcookies.length;
	return (unescape(allcookies.substring(start,end)));
    }
} // getCookie()
function setCookie(name,value,expires) {
    var expStr = "";
    if (expires) expStr = "; expires=" + expires.toGMTString();
    document.cookie = name + "=" + value + "; path=/" + expStr;
} // setCookie()
function delCookie(name) {
    var domain = location.hostname;
    var today = new Date();
    var expires = new Date();
    expires.setTime(today.getTime() - (1000*60*60*24*365));
    document.cookie = name + "=adios; expires=" + expires.toGMTString() + 
	"; path=/; domain=" + domain;
    // also get rid of them in www.* domains
    if (domain.substr(0,3) == "www") {
	domain = domain.substr(4);
	document.cookie = name + "=adios; expires=" + expires.toGMTString() + 
	    "; path=/; domain=" + domain;
    }
} // delCookie

// login/registration functions
var _wndLogin = null;
function doLoginPopUp(strDestUrl) {
    if ( _wndLogin != null && !_wndLogin.closed ) { _wndLogin.focus(); return false; }
    if ( (strDestUrl == null) || (strDestUrl == '') ) { 
	strDestUrl = location.href; 
    }
    strWndFeatures = 'toolbar=no,location=no,status=no,menubar=no,scrollbars=no,' +
	'width=400,height=225,screenX=100,screenY=100';
    _wndLogin=window.open('http://' + location.hostname + 
			  '/registration/univisionregistration.nsf/Login?OpenForm&DestUrl=' + 
			  strDestUrl,'LoginPopUp', strWndFeatures);
    _wndLogin.focus();
    return false;
}
function doInscribete() {
    top.location.href = 'http://' + location.hostname + 
	'/registration/univisionregistration.nsf/RegistrationIntro?OpenForm&' + 
	location.href;		
}

// temporary code to convert old-format cookies to new
if (getCookie("birthyear")) { // that's an old one!!
    var today = new Date();
    var expires = new Date();
    expires.setTime(today.getTime() + 1000*60*60*24*365*10); // 10 yrs
    // first, convert weather
    var COOKIE_FIELD_DELIMITER = "~";
    var ccode = getCookie("weathercitycurrent");
    var fcode = getCookie("weathercityforecast");
    var city = getCookie("weathercitytext");
    // if the old ones are still there, make the new one 
    if (ccode && fcode && city) {
	var value = fcode + COOKIE_FIELD_DELIMITER + ccode + COOKIE_FIELD_DELIMITER + city;
	setCookie("w",value,expires);
	// delete the old ones
	delCookie("weathercitycurrent");
	delCookie("weathercityforecast");
	delCookie("weathercitytext");
    }
    // now horoscope
    var birthmonth = getCookie("birthmonth");
    var birthday = getCookie("birthday");
    // if the old ones are still there, make the new one 
    if (birthmonth && birthday) {
	if (birthmonth.length < 2) birthmonth = "0" + birthmonth;
	if (birthday.length < 2) birthday = "0" + birthday;
	setCookie("h",birthmonth + birthday,expires);
	// delete the old ones
	delCookie("birthmonth");
	delCookie("birthday");
    }
    // now delete the old ones we never used anyhows
    delCookie("country");
    delCookie("state");
    delCookie("title");
    delCookie("zipcode");
    delCookie("gender");
    delCookie("language");
    delCookie("origincountry");
    delCookie("numericuserid");
    delCookie("birthyear");
} // if old cookies exist

