 function getTop(el) {
	iPos = 0;
	while (el!=null) {
	 	iPos += el.offsetTop;
		el = el.offsetParent;
	}
	return iPos;
}

function getLeft(el) {
	iPos = 0;
	while (el!=null) {
	 	iPos += el.offsetLeft;
		el = el.offsetParent;
	}
	return iPos;
}

function addEvent (el, evName, evFunction) {
	if (isIE) {
		eval("el.attachEvent('" + evName + "'," + evFunction + ")"); 
	} else {
		eval("el." + evName + " = " + evFunction);
	}
}

function getTarg (e) {
	var targ;
	if (!e) var e = window.event;
	if (e.target) targ = e.target;
	else if (e.srcElement) targ = e.srcElement;
	if (targ.nodeType == 3) // defeat Safari bug
		targ = targ.parentNode;
	return targ;
}

function itemOver(e) {
	var targ = getTarg(e);
	targ.style.backgroundColor = targ.parentNode.onColor;
}

function itemOut(e) {
	var targ = getTarg(e);
	targ.style.backgroundColor = targ.parentNode.offColor;
}

function itemClick(e) {
	var targ = getTarg(e);
	location.href = targ.URL;
}

function menuOver(e) {
	clearTimeout(lastTimeout);
}

function menuOut(e) {
	var targ = getTarg(e);
	while (!targ.chanCode) {
		targ = targ.parentNode;
	}
	menuOffProcess(targ.chanCode);
}

function menuOffNow (chanCode) {
	getEl(chanCode).style.visibility = hid;
	if (isIE) selectVis(vis);
}

function menuOffProcess (chanCode) {
	lastTimeout = setTimeout("menuOffNow('" + chanCode + "Menu')", 1000);
}

function menuOnProcess (el) {
	clearTimeout(lastTimeout);
	if (el.style.visibility != vis) {
		rfrshMenuAd(el.chanCode);
		if (actMenu != "") getEl(actMenu+"Menu").style.visibility = hid;
		actMenu = el.chanCode;
		el.style.visibility = vis;
		if (isIE) selectVis(hid);
	}
}

function selectVis(state) {
	selects = document.getElementsByTagName("select");
	for (selectIndex = 0; selectIndex < selects.length; selectIndex++) {
		selects[selectIndex].style.visibility = state;
	}
}

function areaOver (e) {
	var targ = getTarg(e);
	menu = getEl(targ.chanCode + "Menu");
	menuOnProcess(menu);
}

function areaOut (e) {
	var targ = getTarg(e);
	menu = getEl(targ.chanCode + "Menu");
	menuOffProcess(targ.chanCode);
}

function newMenu (chanCode) {
	var menuDiv = makeEl("DIV");
	menuDiv.className = "outerMenu";
	menuDiv.id = chanCode + "Menu";
	menuDiv.chanCode = chanCode;
	menuDiv.offColor = (chanCode == activeTab) ? cColor : oColor;
	menuDiv.onColor = (chanCode == activeTab) ? hlActColor : actColor;
	menuDiv.style.zIndex = zInd++;
	menuDiv.style.visibility = hid;
	menuDiv.style.position = "absolute";
	addEvent (menuDiv, mOv, "menuOver");
	addEvent (menuDiv, mOt, "menuOut");
	addTopEl(menuDiv);
	positionMenu(menuDiv);
	var area = getEl(chanCode + "Area");
	area.chanCode = chanCode;
	addEvent(area, mOv, "areaOver");
	addEvent(area, mOt, "areaOut");
	return menuDiv;
}

function positionMenu(el) {
	var area = getEl(el.chanCode + "Area");
	if (area) {
		var menuTop = getTop(chanGif) + 17;
		var coords = area.coords.split(",");
		var width = 93;
		var left = ((getLeft(chanGif)) + parseInt(coords[0]));
		el.style.top = menuTop + px;
		el.style.width = width + px;
		//if (isIE) el.ieWidth = width;
		el.style.left = left + px;
	}
}

function posAllMenus() {
	for (menu in cm) {
		positionMenu(cm[menu]);
	}
	if (pCnt == 0) window.clearInterval(posLoop);
	
	pCnt--;
}

function makeEl(tagName) { return document.createElement(tagName); }
function makeTextEl (text) { return document.createTextNode(text) }
function addText (el, text) { el.appendChild( makeTextEl(text) ) }
function getEl (elName) { return document.getElementById(elName) }
function addTopEl (el) { document.body.insertBefore(el, document.body.firstChild) }
function areaExists (chanCode) { return (getEl(chanCode + "Area") ? true : false); }

function nIt ( menu, itemName, itemURL) {
	var itemDiv = makeEl("DIV");
	//if (isIE) itemDiv.style.width = menu.ieWidth - 1 + px;
	itemDiv.className = "item";
	addText(itemDiv, itemName);
	itemDiv.URL = itemURL;
	itemDiv.style.backgroundColor = menu.offColor;
	itemDiv.align="left";
	addEvent (itemDiv, mOv, itemOver)
	addEvent (itemDiv, mOt, itemOut)
	addEvent (itemDiv, "onclick", itemClick)
	menu.appendChild(itemDiv);
}

function rfrshMenuAd (chanCode) {
	var menuHierarchy247 = (adValues[chanCode] ? adValues[chanCode] : "");
	var adVars = menuHierarchy247;
	//var adVars = "chan=" + chanCode + "&sub=" + chanCode + "menu&adsize=88x31&pagepos=8&var=" + (Math.random() * 1000000000000000000);
	if (getEl(chanCode + "MenuAdLink")) getEl(chanCode + "MenuAdLink").href = adVars;
	getEl(chanCode + "MenuAdTrack").src = adVars;
}

function addAd ( menu, imgSrc ) {
	var chanCode = menu.chanCode;

	var adTrack = makeEl("IMG");
	adTrack.className = "menuAdTrack"
	adTrack.id = chanCode + "MenuAdTrack";
	addTopEl(adTrack);

	var adHref = makeEl("A");
	adHref.setAttribute ("HREF", "#");
	adHref.target = "_blank";
	adHref.id = menu.chanCode + "MenuAdLink";

	if ( imgSrc != "") {
		var adImg = makeEl("IMG");
		adImg.src = imgSrc;
		adImg.className = "menuAdImg";

		var itemDiv = makeEl("DIV");
		//if (isIE) itemDiv.style.width = menu.ieWidth - 1 + px;
		itemDiv.className = "item sponsorText";
		itemDiv.style.backgroundColor = (menu.chanCode == activeTab) ? cColor : oColor;
		addText(itemDiv, "Patrocinado por:");
		itemDiv.appendChild(makeEl("BR"));

		adHref.appendChild(adImg)
		itemDiv.appendChild(adHref);
		menu.appendChild(itemDiv);
	}
}

UA = navigator.userAgent;
chanGif = getEl ("channelGif");

if (//UA.indexOf("Opera") == -1 && 
	//UA.indexOf("Safari") == -1 && 
	!(UA.indexOf("MSIE") != -1 && UA.indexOf("Mac") != -1) &&
	chanGif &&
	getEl("channelMap")) {
	
	var lastTimeout;
	actMenu = "";
	actColor = "#FFFFFF";		// rollover color for regular menus
	hlActColor = "#dfdfdf";	// rollover color for highlighed menus
	cColor = "#FFFFFF";	// highlighted menu item color
	oColor = "#D3EEF8";	// regular menu item bgcolor
	isIE = (UA.indexOf("MSIE") != -1) ? true : false;
	activeTab = getEl("channelGif").src;
	activeTab = activeTab.substring(activeTab.lastIndexOf("/")+1, activeTab.lastIndexOf("/")+3);
	mOv = "onmouseover";
	mOt = "onmouseout";
	px = "px";
	hid = "hidden";
	vis = "visible";
	zInd = 605;
	b = "http://www.diariodigital.com.do";
	
	adValues = new Object();
	adValues["xt"] = "http://www.quefresa.com";
	adValues["de"] = "#";
	adValues["ec"] = "#";
	adValues["en"] = "http://www.presidente.com.do";
	adValues["nt"] = "#";
	adValues["pt"] = "#";
	
	cm = new Object();
	
	ch = "pt";
	if (areaExists(ch)) {
	cm[ch] = newMenu(ch);
	nIt(cm[ch],"Mi Diario",b+"?module=archives&format=html&op=accountstatus");
	nIt(cm[ch],"Login",b+"?module=users&op=accountlogin&format=html");
	nIt(cm[ch],"Registro en Boletines",b+"?module=users&format=html&op=registrationform");
	nIt(cm[ch],"Búsqueda",b+"?module=archives&format=html");
	addAd(cm[ch],"");
	}
	
	ch = "nt";
	if (areaExists(ch)) {
	cm[ch] = newMenu(ch);
	nIt(cm[ch],"Nacionales",b+"?module=displaysection&section_id=49&format=html");
	nIt(cm[ch],"El Mundo",b+"?module=displaysection&section_id=10&format=html");
	nIt(cm[ch],"Política",b+"?module=displaysection&section_id=4&format=html");
	nIt(cm[ch],"Justicia",b+"?module=displaysection&section_id=8&format=html");
	nIt(cm[ch],"Policiales",b+"?module=displaysection&section_id=17&format=html");
	addAd(cm[ch],"");
	}
	
	ch = "en";
	if (areaExists(ch)) {
	cm[ch] = newMenu(ch);
	nIt(cm[ch],"Cine",b+"?module=displaysection&section_id=29&format=html");
	nIt(cm[ch],"Cultura",b+"?module=displaysection&section_id=28&format=html");
	nIt(cm[ch],"Columnas",b+"?module=displaysection&section_id=32&format=html");
	nIt(cm[ch],"Espectaculos",b+"?module=displaysection&section_id=33&format=html");
	nIt(cm[ch],"Farandula",b+"?module=displaysection&section_id=45&format=html");
	nIt(cm[ch],"Teatro",b+"?module=displaysection&section_id=30&format=html");
	nIt(cm[ch],"Television",b+"?module=displaysection&section_id=34&format=html");
	addAd(cm[ch],"http://www.diariodigitalrd.com/ads/ad-presidente-88.gif");
	}



	
	ch = "ec";
	if (areaExists(ch)) {
	cm[ch] = newMenu(ch);
	nIt(cm[ch],"Notas Economicas",b+"?module=displaysection&section_id=6&format=html");
	nIt(cm[ch],"Empresariales",b+"?module=displaysection&section_id=39&format=html");
	nIt(cm[ch],"Bienes Raices",b+"?module=displaysection&section_id=23&format=html");
	addAd(cm[ch],"");
	}
	
	ch = "de";
	if (areaExists(ch)) {
	cm[ch] = newMenu(ch);
	nIt(cm[ch],"Deportivas",b+"?module=displaysection&section_id=18&format=html");
	addAd(cm[ch],"http://www.diariodigital.com.do/ads/ad-presidente-88.gif");
	}
	
	ch = "xt";
	if (areaExists(ch)) {
	cm[ch] = newMenu(ch);
	nIt(cm[ch],"Gente",b+"?module=displaysection&section_id=35&format=html");
	nIt(cm[ch],"Turismo",b+"?module=displaysection&section_id=16&format=html");
	nIt(cm[ch],"Ciencia y Tecnologia",b+"?module=displaysection&section_id=19&format=html");
	nIt(cm[ch],"Salud",b+"?module=displaysection&section_id=13&format=html");
	nIt(cm[ch],"Moda y Belleza",b+"?module=displaysection&section_id=37&format=html");
	nIt(cm[ch],"Sociales",b+"?module=displaysection&section_id=40&format=html");
	nIt(cm[ch],"Gastronomia",b+"?module=displaysection&section_id=14&format=html");
	nIt(cm[ch],"Religion",b+"?module=displaysection&section_id=12&format=html");
	addAd(cm[ch],"");
	}	

	pCnt = 10;
	posLoop = window.setInterval("posAllMenus()", 1000);

}
