var LOGIN_volvera;
function mostrarLogin(noLoadLogin,volvera,HidePlayer){
	//alert("mostrarLogin");
	LOGIN_volvera=volvera;
	/*
	if(document.getElementById("player")){		
		document.getElementById("player").style.display='none';
	}
	if(document.getElementById("playlist")){		
		document.getElementById("playlist").style.display='none';
	}
	if(document.getElementById("buscadorcontenidos_cinta")){		
		document.getElementById("buscadorcontenidos_cinta").style.display='none';
	}	
	if(document.getElementById("region_player")){
		document.getElementById("region_player").style.display = 'none';
	}
	*/
	if(document.getElementById("content")){
		document.getElementById("content").style.realdisplay=document.getElementById("content").style.display;
		document.getElementById("content").style.display="none";		

	
	}
	if(typeof HidePlayer=="undefined"){		
		HidePlayer=noLoadLogin;
	}	
	/*ESTO SE SACA PARA VOLVER A HACER A HTV OCULTAR EL PLAYER COMO FTV, MUCH, ETC.*/
	//if(HidePlayer){
		if(document.getElementById("content_player")){
			document.getElementById("content_player").style.realdisplay=document.getElementById("content_player").style.display;
			document.getElementById("content_player").style.display="none";
		}	
	//}
	if(document.getElementById("region_playerlogin")){
		if(!noLoadLogin){
			FWK.loadAppInto("region_playerlogin","login_ajax|principal|principal|principal","&principal[accion]=login&principal[type]=over&principal[goto_frame]=player","noocultarplayer");

		}
		document.getElementById("region_playerlogin").style.padding = '0px';
		document.getElementById("region_playerlogin").style.display = 'block';			
	}	
}

function ocultarLogin(){	
	/*
	if(document.getElementById("player")){
		document.getElementById("player").style.display='block';		
	}
	if(document.getElementById("playlist")){
		document.getElementById("playlist").style.display='block';
	}
	if(document.getElementById("buscadorcontenidos_cinta")){		
		document.getElementById("buscadorcontenidos_cinta").style.display='block';
	}		
	if(document.getElementById("region_player")){
		document.getElementById("region_player").style.display = 'block';	
	}
	if(document.getElementById("region_playerlogin")){
		document.getElementById("region_playerlogin").style.display = 'none';
	}	
	*/	
	/*
	if(typeof goCMaterial!="undefined"){
		//alert("ACA");
		//if(document.getElementById("region_playerlogin")){
		//	document.getElementById("region_playerlogin").style.display = 'none';
		//}		
		//ocultarPlayer();
		//return;
	}
	*/
		if(document.getElementById("content")){
			if(document.getElementById("content").style.realdisplay){
				//*DEBUG*//alert("Valor 1"+document.getElementById("content").style.realdisplay);
				document.getElementById("content").style.display=document.getElementById("content").style.realdisplay;
			}else{
				//*DEBUG*//alert("Valor 2");
				document.getElementById("content").style.display="none";		
			}
		}
	/*ESTO ESTABA COMENTADO PARA 4C*/
		if(document.getElementById("content_player")){
			if(document.getElementById("content_player").style.realdisplay){
				//*DEBUG//alert("Valor 3"+document.getElementById("content_player").style.realdisplay);
				document.getElementById("content_player").style.display=document.getElementById("content_player").style.realdisplay;
			}else{
				//*DEBUG//alert("Valor 4");
				document.getElementById("content_player").style.display="block";		
			}
		}		
	/**/		
		if(document.getElementById("region_playerlogin")){
			document.getElementById("region_playerlogin").style.display = 'none';
		}	
	
}

var LOGIN_reply;
function loginAjaxHandlerReply(reply,otherParams){
	
	if(reply){
		LOGIN_reply=reply;
	}else{
		reply=LOGIN_reply;
	}
	switch(reply){
		case "OK":
			//alert("LOGIN OK");
			FWK.loadAppInto("registroModOnlyLogin","login|principal|principal|principal","","noocultarplayer");
			//SIN ACTIVEX por ahora
			versionActiveX=0;
			/*PARA PONERLO SACAR LA LINEA ANTERIOR QUE FIJA QUE NO ES ACTIVEX (=0) y DESCOMENTAR EL IF SIGUIENTE*/
			//if(!flujoDescargaActiveX(loginAjaxHandlerReply)){
			//	return;
			//} 
			/***/
			//alert("SIGO ACA");			
			ocultarLogin();
			//try{
				if(LOGIN_volvera){
					if(FWK.debug){
						alert("Llamo a login_Volvera");
					}
					LOGIN_volvera();
				}else{
					if(FWK.debug){
						alert("Llamo a Play:"+currentMaterial);
					}										
					if(typeof currentMaterial!="undefined"&&currentMaterial!=null){	
						mostrarPlayer();
						cargarMaterialPlayer(null); //hacer que vuelva a intentar reproducir el Material
					}else{
						if(wmp_isonlinestore()){
							ocultarPlayer();							
						}else{
							ocultarPlayer();
							//mostrarPrimeroPlayList();
						}
					}
				}
			//}catch(e){
			//	alert("Error en login"+e.description);
			//	window.status="Er loginajaxHandler";
			//}
			return false;	//no haga lo que haria por default
		break;
		case "USUARIO_NO_HABILITADO":
			if(typeof otherParams!="undefined")
				FWK.loadAppInto("content","html_estatico|principal|principal|principal","&principal[html]=cargadorregistrofase2.html&principal[replace_escape][src]="+escape("/scripts/app/framework.php?APP=mp|principal|principal|principal&principal[fase]="+otherParams.xmlFase+"&principal[action]="+otherParams.xmlAction+"&principal[id_usuario]="+otherParams.xmlIdUsuario)+"");			
			return false; //no haga lo quer haria por default
		break;
		default:
			return true;	//haga lo que haria por default ej: mostrar el mensaje de error
	}
}
var DESCARGA_volvera;
var DESCARGA_mostrandomensaje;
var bYaRefresque=0;
function refresh_setCookie(sCookieName,sValue,bSession){
	var today = new Date();
	var zero_date = new Date(0,0,0);
	today.setTime(today.getTime() - zero_date.getTime());
	if(!bSession){
		var cookie_expire_date = new Date(today.getTime() + (8 * 7 * 86400000));	
		var cookieString = sCookieName + "=" + escape(sValue) + ";expires=" + cookie_expire_date.toGMTString() + ";domain=" + document.location.hostname;
	}else{
		var cookieString = sCookieName + "=" + escape(sValue) + ";domain=" + document.location.hostname;
	}
	document.cookie = cookieString;	
}
function refresh_getCookie(sCookieName){
	var start = document.cookie.indexOf(sCookieName+"=");
	var len = start + sCookieName.length + 1;
	if ((!start) && (sCookieName != document.cookie.substring(0,sCookieName.length))) return null;
	if (start == -1) return null;
	var end = document.cookie.indexOf(";",len);
	if (end == -1) end = document.cookie.length;
	//Valido si el ultimo caracter es una \
	var sReturn = unescape(document.cookie.substring(len,end));
	return sReturn;
}
function saveCookieMaterial(id_material){
	var idMaterialTmp=id_material?id_material:(goCMaterial["id_material"]?goCMaterial["id_material"]:currentMaterial["id_material"]);	
	refresh_setCookie("esdcsavedmaterial",""+idMaterialTmp,true);
}
function loadFromCookieMaterial(){
	var oMaterialTmp;
	var idMaterialTmp;
	idMaterialTmp=refresh_getCookie("esdcsavedmaterial");
	if(idMaterialTmp){
		mostrarPlayer();
		oMaterialTmp=obtenerMaterialDwl("","","",idMaterialTmp);
		goCMaterial=oMaterialTmp;
		currentMaterial=oMaterialTmp;
		//cargarMaterialPlayer(oMaterialTmp);
		cargarPlayListContenido(oMaterialTmp["id_contenido"],false);		
		boton_downloaddirecto();
		return true;
	}
	return false;
}
function flujoDescargaActiveX(volvera){		
	//var oDownloader = getDownloader("downloader");
	var ret=1;
	DESCARGA_volvera=volvera;
	if(wmp_isonlinestore()){
		versionActiveX=0;
		ret=1;
	}else{
			switch(top.downloader.oDownloader.estaActivado()){
				case "si":			
					if(top.downloader.oDownloader&&top.downloader.oDownloader.estaInstalado()){
						if(!top.downloader.oDownloader.yaRefresque()){	
							versionActiveX=0;
							top.downloader.oDownloader.yaRefresque(1);
							refrescarFrameDescarga();					
							ret=0;
						}else{
							versionActiveX=1;
							ret=1;				
						}								
					}else{
						versionActiveX=0;
						//Mostrar HTML ayuda instalacion
						mostrarMensajeDescarga("downloader_preguntainstalacion.html");
						ret=0;
					}
				break;
				case "no":
					versionActiveX=0;
					ret=1;
				break;
				case "nunca":
				default:
					versionActiveX=0;
					//Mostrar HTML pregunta Uso
					mostrarMensajeDescarga("downloader_preguntainstalacion.html");
					ret=0;
				break;
			}
	} 
	return ret;
}

function mostrarMensajeDescarga(mensaje,nocambiarAnchor){
	if(!nocambiarAnchor){
		if (typeof limpiarAnchor != "undefined") {
			limpiarAnchor();
		}
	}	
	FWK.loadAppInto(DIVVTC,"html_estatico|principal|principal|principal","&principal[html]="+mensaje,"noocultarplayer");
	mostrarLogin(true,LOGIN_volvera);
}
function ocultarMensajeDescarga(noPrepare){
	//var oDownloader;
	if(!noPrepare){
		top.downloader.oDownloader.prepareDownloader();
		//oDownloader = getDownloader("downloader");	
		//oDownloader.prepareDownloader();	
	}
	//ocultarLogin(true);
	if(DESCARGA_volvera){
		DESCARGA_volvera();
	}else{
		if(loadFromCookieMaterial()){
			if(typeof IRCOMPRAR_volvera=="undefined"){
				ocultarLogin();			
			}
		}else{
			treeOnStart();
		}				
	}
}
function refrescarFrameDescarga(){
	if (typeof cambiarAnchor != "undefined") {
		cambiarAnchor("ver-mensaje","instalacionActiveX","");
	}	
	top.downloader.document.location.href = "/scripts/app/framework.php?FRAME=downloader&rnd="+(new Date().getTime());
}
function setearActivado(valor){
	//var oDownloader = getDownloader("downloader");
	//oDownloader.setActivado(valor);
	top.downloader.oDownloader.setActivado(valor);
}
function mostrarOlvideMiContrasena(){
            //FWK.loadAppInto("region_playerlogin","mp|principal|principal|principal","&principal[fase]=recpwd&principal[action]=input","noocultarplayer");
            FWK.loadAppInto("region_playerlogin","mp|principal|principal|principal","&principal[fase]=recpwd&principal[action]=input");
            //mostrarLogin(true,undefined,false);
            mostrarLogin(true); 
}
function mostrarOlvideMiContrasenaRespuesta(pform){
	if(pform){
		if(pform.elements){
			if(pform.elements["principal[email]"]){
				if(pform.elements["principal[email]"].value){
					//FWK.loadAppInto("region_playerlogin","mp|principal|principal|principal","&principal[fase]=recpwd&principal[action]=checkmail&enviar=ok&principal[email]="+pform.elements["principal[email]"].value,"noocultarplayer");
					FWK.loadAppInto("region_playerlogin","mp|principal|principal|principal","&principal[fase]=recpwd&principal[action]=checkmail&enviar=ok&principal[email]="+pform.elements["principal[email]"].value);
					//mostrarLogin(true,undefined,false);
					mostrarLogin(true);
				}
			}
		}
	}
}
function ocultarOlvideMiContrasena(){
            ocultarLogin();
}
