/* AUXILIARY FUNCTIONS */

// IE BackgroundImageCache Fix
(function(){ 
	/*Use Object Detection to detect IE6*/ 
	var m = document.uniqueID /*IE*/ && document.compatMode /*>=IE6*/ && !window.XMLHttpRequest /*<=IE6*/ && document.execCommand ; 
	try{ if(!!m) m("BackgroundImageCache", false, true) /* = IE6 only */ }
	catch(oh){};
})();

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}



// POPUP LAUNCHER
function popup(url,ancho,alto,id,extras){
	if(navigator.userAgent.indexOf("Mac")>0){ancho=parseInt(ancho)+15;alto=parseInt(alto)+15;}
	var left = (screen.availWidth-ancho)/2;
	var top = (screen.availHeight-alto)/2;
	if(extras!=""){extras=","+extras;};
	var ventana = window.open(url,id,'width='+ancho+',height='+alto+',left='+left+',top='+top+',screenX='+left+',screenY='+top+extras);
	//var bloqueado = "AVISO:\n\nPara ver este contenido es necesario que desactive\nel Bloqueo de Ventanas para este Sitio."
	var bloqueado = "WARNING:\n\nIn order to use this functionality, you need\nto deactivate Popup Blocking for this site."
	if(ventana==null || typeof(ventana.document)=="undefined"){ alert(bloqueado) }else{ return ventana; };
}

function inspect(obj) {
	var str = "";
	for (var k in obj)
		str += "obj." + k + " = " + obj[k] + "<br>";
	(window.open('about:blank')).document.write(str);
}

function readCookie(name){
	var cookieValue = "";
	var search = name + "=";
	if(document.cookie.length > 0){ 
		offset = document.cookie.indexOf(search);
		if (offset != -1){ 
			offset += search.length;
			end = document.cookie.indexOf(";", offset);
			if (end == -1) end = document.cookie.length;
			cookieValue = unescape(document.cookie.substring(offset, end))
		}
	}
	return cookieValue;
}

function writeCookie(name, value, hours){
	var expire = "";
	if(hours != null){
		expire = new Date((new Date()).getTime() + hours * 3600000);
		expire = "; expires=" + expire.toGMTString();
	}
	document.cookie = name + "=" + escape(value) + expire;
}

/* SITE FUNCTIONS */

var Epak = {}; // site namespace

Epak.Menu = {
	goTo: function(url){
		location.href = url;
	},
	mOver: function(div){
		YAHOO.util.Dom.addClass(div,'navButtonTdOver');
	},
	mOut: function(div){
		YAHOO.util.Dom.removeClass(div,'navButtonTdOver');
	}
};




Epak.Navegacion = {
	// Items posibles de la navegación
	secciones: new Array("canal","programas","guias","descripcion","colorMenu3" ,"colorMenu2" ,"colorMenu6" ,"colorMenu7" ,"colorMenu4" ,"colorMenu5" ,"colorMenu1"),
	classe1: "navButtonTd", // Class del nav comun
	classe2: "navButtonTdSelected", // Class del nav activo
	marcar: function(){
		for (var i=0; i < Epak.Navegacion.secciones.length; i++) { 
			obj = MM_findObj(Epak.Navegacion.secciones[i]);
			if(obj){ // Si existe el obj (puede no tener contenido)
				if( Epak.Navegacion.getPartUrl( Epak.Navegacion.secciones[i] ) ){ // Y si ese id no esta en la url
					obj.className = Epak.Navegacion.classe1; // lo pinto como nav común
				}else{
					obj.className = Epak.Navegacion.classe1 +" "+ Epak.Navegacion.classe2 ; // Sino, esta en la url, y se pinta como activo
				}
			}
		}	
	},
	getPartUrl: function (part) {
			var query = self.location.href;
			if( query.indexOf(part) == -1 ){
				return true;
			}else{
				return false;
			}	
		}	
	
}
