

/**************************************
@Clase jsRecordControl
***************************************
@Autor: jmartin@inout.tv
@Fecha: 2008/08/26
*/

var jsRecordControl = Class.create();

jsRecordControl.prototype = {
	/**********************************************************************************************
	* Construct
	**********************************************************************************************/
	initialize: function(){},
	/**********************************************************************************************
	* whoIam
	**********************************************************************************************/
	whoIam: function(){
		alert("jsRecordControl.js");
	},
	step1: function(UserId,IdEvent,Channel,Titles,mydate,command,couponId,topleft){
				initialHTML='<div id="panelPopupContent"></div>'; 
			  p = Create.popup(initialHTML,'panelPopup',-1,false,"contained");
			  var jsCode = "if (typeof( GBL_CLOSE_PAGE ) != 'undefined') if (GBL_CLOSE_PAGE==true){window.close();return true;} if(IOContainer) IOContainer.hide();";
			  var closeBtn = '<p class="cerrarCtn"><a href="javascript:;" onclick="'+jsCode+'"><img src="/cobranded/inout/ima/remotas/close.gif" class="closebtn"/></a></p>';
			  
			  p.setHeader(closeBtn);
				if (!topleft)
					p.center();
		    if (UserId=='-'){
  			  	this.drawUserPass(UserId,IdEvent,Channel,Titles,mydate,command,couponId);
			  }
			  else{
			  	var user2="-";
			  	var pass2="-";
			  	this.step2(UserId,IdEvent,Channel,Titles,mydate,command,couponId,user2,pass2);
			  }	
	},
	drawUserPass : function(UserId,IdEvent,Channel,Titles,mydate,command,couponId){
				this.ajx = new clsAjx()
				this.ajx_TxtCargando="... cargando ...";
				var params = "do=ajax@Grabar&accion=drawNoValidate&UserId="+UserId+"&IdEvent="+IdEvent+"&Channel="+Channel+"&Titles="+Titles+"&mydate="+mydate+"&command="+command+"&couponId="+couponId;
				this.ajx.setTxtCargando("&nbsp;&nbsp;Cargando...");
				this.ajx.objOwner = this;
				this.ajx.setValores(params);
				this.ajx.setURL("index.php");
				this.ajx.ResultinTA(false);
				this.ajx.setCapa("panelPopupContent");
				this.ajx.setCallBack("");
				this.ajx.runAjx();
	},
	checkUser: function(UserId,IdEvent,Channel,Titles,mydate,command,couponId,user,pass){
	      
				if (document.getElementById("usuario2"))
		    	var user=document.getElementById("usuario2").value;
		    if (document.getElementById("password2"))	
		    	var pass=document.getElementById("password2").value;
				this.ajx = new clsAjx()
				this.ajx_TxtCargando="... cargando ...";
				var params = "do=ajax@Grabar&accion=getCheckUser&usuario="+user+"&password="+pass+"&UserId="+UserId+"&IdEvent="+IdEvent+"&Channel="+Channel+"&Titles="+Titles+"&mydate="+mydate+"&command="+command+"&couponId="+couponId+"&user="+user+"&pass="+pass;
				this.ajx.setTxtCargando("&nbsp;&nbsp;Cargando...");
				this.ajx.objOwner = this;
				this.ajx.setValores(params);
				this.ajx.setURL("index.php");
				this.ajx.ResultinTA(false);
				this.ajx.setCapa("panelPopupContent");
				this.ajx.setCallBack("");
				this.ajx.runAjx();
	},
	step2: function(UserId,IdEvent,Channel,Titles,mydate,command,couponId,user,pass){
				this.ajx = new clsAjx()
				this.ajx_TxtCargando="... cargando ...";
				var params = "do=ajax@Grabar&accion=getPVRUser&UserId="+UserId+"&IdEvent="+IdEvent+"&Channel="+Channel+"&Titles="+Titles+"&mydate="+mydate+"&command="+command+"&couponId="+couponId+"&user="+user+"&pass="+pass;
				this.ajx.setTxtCargando("&nbsp;&nbsp;Cargando...");
				this.ajx.objOwner = this;
				this.ajx.setValores(params);
				this.ajx.setURL("index.php");
				this.ajx.ResultinTA(false);
				this.ajx.setCapa("panelPopupContent");
				this.ajx.setCallBack("");
				this.ajx.runAjx();
	},
	step3: function(UserId,IdEvent,Channel,Titles,mac,mydate,command,couponId,user,pass,prodDesc,pid){
		    this.ajx = new clsAjx()
				this.ajx_TxtCargando="... cargando ...";
				var params = "do=ajax@Grabar&accion=getAccept&UserId="+UserId+"&IdEvent="+IdEvent+"&Channel="+Channel+"&Titles="+Titles+"&mac="+mac+"&mydate="+mydate+"&command="+command+"&couponId="+couponId+"&user="+user+"&pass="+pass+"&prodDesc="+prodDesc+"&pid="+pid;
				this.ajx.setTxtCargando("&nbsp;&nbsp;Cargando...");
				this.ajx.objOwner = this;
				this.ajx.setValores(params);
				this.ajx.setURL("index.php");
				this.ajx.ResultinTA(false);
				this.ajx.setCapa("panelPopupContent");
				this.ajx.setCallBack("");
				this.ajx.runAjx();
	} ,
	step4: function (UserId,IdEvent,Channel,Titles,mac,mydate,command,couponId,user,pass,pid){
		 		this.ajx = new clsAjx()
				this.ajx_TxtCargando="... cargando ...";
				var params = "do=ajax@webRecordingManager&accion=addRecording&UserId="+UserId+"&IdEvent="+IdEvent+"&Channel="+Channel+"&Titles="+Titles+"&mac="+mac+"&mydate="+mydate+"&command="+command+"&couponId="+couponId+"&user="+user+"&pass="+pass+"&pid="+pid;
				this.ajx.setTxtCargando("&nbsp;&nbsp;Cargando...");
				this.ajx.objOwner = this;
				this.ajx.setValores(params);
				this.ajx.setURL("index.php");
				this.ajx.ResultinTA(false);
				this.ajx.setCapa("panelPopupContent");
				this.ajx.setCallBack("");
				this.ajx.runAjx();
	},
	validateInWeb: function (usuario, pass){
				var params="do=Usuario&accion=login&usuario="+usuario+"&password="+pass;
				this.ajx = new clsAjx()
				this.ajx_TxtCargando="... cargando ...";
				this.ajx.setTxtCargando("&nbsp;&nbsp;Cargando...");
				this.ajx.objOwner = this;
				this.ajx.setValores(params);
				this.ajx.setURL("index.php");
				this.ajx.ResultinTA(false);
				this.ajx.setCapa("panelPopupContent");
				this.ajx.setCallBack("");
				this.ajx.runAjx();
				window.location.reload()
				//window.history.go(0); 
	},
	conditionsuse: function(UserId,IdEvent,Channel,Titles,mac,mydate,command,couponId,pass2,user){
				this.ajx = new clsAjx()
				this.ajx_TxtCargando="... cargando ...";
				var params = "do=ajax@Grabar&accion=getConditions&UserId="+UserId+"&IdEvent="+IdEvent+"&Channel="+Channel+"&Titles="+Titles+"&mac="+mac+"&mydate="+mydate+"&command="+command+"&couponId="+couponId+"&user="+user+"&pass="+pass2;
				this.ajx.setTxtCargando("&nbsp;&nbsp;Cargando...");
				this.ajx.objOwner = this;
				this.ajx.setValores(params);
				this.ajx.setURL("index.php");
				this.ajx.ResultinTA(false);
				this.ajx.setCapa("panelPopupContent");
				this.ajx.setCallBack("");
				this.ajx.runAjx();
	}

};


function remoteRecord(UserId,IdEvent,Channel,Titles,mydate,command,couponId,topleft){
	 var control= new jsRecordControl();
	 mydate=mydate.replace("_"," ");
   control.step1(UserId,IdEvent,Channel,Titles,mydate,command,couponId,topleft);
}

function showError(mac)
{
	if (Sexy && mac)
	{
		Sexy.error('<p><b>'+mac+'</b> no tiene servicio de Sincrogu&iacute;a Premium. Para poder usar las grabaciones remotas en este equipo, debes <a href="http://www.inout.tv/servicios" target="_new" class="linkServicios">ampliar tu servicio</a></p>');
	}
}

function checkMail2(valor)
{
	if(valor!="" && /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(valor))
		return true;
	return false;
}

function ShowPwdRe()
{
	var texto = '<h1>&iquest;Has olvidado tu contrase&ntilde;a?</h1>';
			texto+= '<p>Introduce tu <b>e-mail</b> y te recordaremos tu nombre de usuario y tu contrase&ntilde;a.<br /><br /></p>';
	if (Sexy && texto!="")
	{
		Sexy.prompt(texto,'',{onComplete:
    function(returnvalue) {
    	
      if (returnvalue) {
      	if (checkMail2(returnvalue))
      	{
        	ajx = new clsAjx()
  				var params = "?do=Usuario&accion=recordarmail2&mail="+returnvalue;
  				ajx.setTxtCargando("...consultando...");
  				ajx.objOwner = this;
  				ajx.setValores(params);
  				ajx.setURL("index.php"+"?do=Usuario&accion=recordarmail2&mail="+returnvalue);
  				ajx.ResultinTA(false);
  				ajx.setCapa("pwdResult");
  				ajx.setCallBack("");
  				ajx.runAjx();
				}
				else
				{
					Sexy.error("Mail incorrecto");
				}
      }
      else
      {
					//Sexy.error("Mail incorrecto");
      }
    }
  	});
  }
}

function showCondicionesGenerales(from)
{
		var f = "la web de Sincrogu&iacute;aTV";
		var f2 = " de SincroGuíaTV";
		if (from!=1)
		{
				f = " la web de El Mundo, gracias al servicio de SincroGu&iacute;aTV";
				f2 = "";
		}			
		var list='<h1>Condiciones del servicio de grabaciones</h1><p class="titulos">';
				list+='<br/><p clas+="extra">';
				list+='Ahora puedes grabar en tu PVR tus programas favoritos de TV, desde '+f+'. A continuación te indicamos las especificaciones para poder disfrutar de este servicio:<br /><br />';
				list+='<b>1</b>.	Para poder programar grabaciones debes disponer de un equipo InOutTV MediaCenter 4G HD, OKI MediaTank 1G, OKI SoundBar 1G, M665T PVR o M685T PVR. Puedes encontrar más información de estos equipos y cómo adquirirlos en <a href="http://www.inout.tv" target="_new" class="cuso" style="color:#000; text-decoration:underline;"><b>www.inout.tv</b></a>.<br />';
				list+='<b>2</b>.	Para poder programar grabaciones en tu PVR debes activarlo en <a href="http://www.inout.tv/activacion/" class="cuso" target="_new" style="color:#000; text-decoration:underline;"><b>la secci&oacute;n de activaci&oacute;n de nuestra web</a></b><br />Además, si tu equipo es un M665T PVR o un M685T PVR, debes activar el servicio en tu PVR, accediendo a <b>Men&uacute;/Configuraci&oacute;n /Servicios/Servicio Web/Activar</b><br/>';
				list+='<b>3</b>.	Puedes programar un máximo de dos grabaciones en la misma franja horaria.<br />';
				list+='<b>4</b>.	Las grabaciones programadas a través de este servicio online tienen prioridad sobre las que ya están programadas en tu PVR. Recuerda que las grabaciones remotas no detectan qué grabaciones hay pendientes en tu PVR.<br />';
				list+='<b>5</b>.	Por ahora las grabaciones a través de la web'+f2+' no pueden ser canceladas. Sí que podrán ser canceladas desde tu PVR.<br />';
				list+='<b>6</b>.	Podrás programar una grabación siempre y cuando empiece 2 horas más adelante de la hora actual. Ej.: Si son las 10h, podrás empezar a grabar programas que empiecen a partir de las 12h, pero no antes.<br />';
				list+='<b>7</b>.	Con este servicio puedes grabar capítulos concretos de series, pero no todos los capítulos de una serie con un sólo clic (opción disponible sólo en el PVR).<br />';
				list+='<b>8</b>.	Debes mantener el equipo encendido para que reciba, a través de la señal de antena, la orden de una nueva grabación programada desde la web.<br />';
				list+='<b>9</b>.	Por motivos técnicos y concretos, puede ser que el PVR no reciba la orden mandada desde la web (si ya están los dos sintonizadores ocupados, si se produce algún conflicto de grabaciones, etc.)<br />';
				if (Sexy)
				{
					Sexy.info(list);		
				}	
}	
					    
function confirmRecording(program,pvr,UserId,IdEvent,Channel,Titles,mac,mydate,command,couponId,user,pass,pid)
{
	var jsCode = "control=new jsRecordControl();control.step4(\'"+UserId+"\',\'"+IdEvent+"\',\'"+Channel+"\',\'"+Titles+"\',\'"+mac+"\',\'"+mydate+"\',\'"+command+"\',\'"+couponId+"\',\'"+user+"\',\'"+pass+"\','"+pid+"');";
	
	var img = "";
	if (pid)
		img = "<center><img src='/ima/productos/"+pid+".png'><br/>";
	var warn = img+"&iquest;Est&aacute;s seguro de que deseas grabar<br><b>'"+program+"'</b><br/>en tu PVR <b>'"+pvr+"'</b>?</center>";
	if (Sexy && warn!="")
	{
		Sexy.confirm(warn, {
  	textBoxBtnOk: 'Aceptar',
		textBoxBtnCancel: 'Cancelar',
		onComplete:
    function(returnvalue) {
      if (returnvalue) {
        eval(jsCode);
      } else {
        //alert('presionaste Cancelar');
      }
    }
  	});
	}	
}

