/* ----------------------------------------------
Author: Domingo A. Rodriguez S.
Mail: domingo_a_rodriguez@codetel.com.do
      domingo.a.rodriguez@gmail.com
-------------------------------------------------- */
var pl= false;
var ccol= 1;
var crow= 1;
function checkScroll(doc){
   if(document.getElementById('programid')!=null && document.getElementById('programid')!=undefined){
      if(coalesce(doc.getElementById('srchid').title,'')=='scws')
      scw(this,'s','o',
         coalesce(document.getElementById('serieid').title,''),
         coalesce(document.getElementById('programid').title,''),
         coalesce(document.getElementById('channelnumber').title,''),
         coalesce(document.getElementById('channeltype').title,''),
         coalesce(document.getElementById('promo').title,''),
         coalesce(document.getElementById('currentkey').title,''),
         coalesce(document.getElementById('nop').title,''), 50, 100);
     else
      sc(this,'s','o',
         coalesce(document.getElementById('serieid').title,''),
         coalesce(document.getElementById('programid').title,''),
         coalesce(document.getElementById('channelnumber').title,''),
         coalesce(document.getElementById('channeltype').title,''),
         coalesce(document.getElementById('promo').title,''),
         coalesce(document.getElementById('currentkey').title,''),
         coalesce(document.getElementById('nop').title,''));
    }
}
function dsb(obj){
  obj.onclick=function(){
                  obj.disabled=true;
                  return false;
                  };
}
function on(td,xstyle){
   if(td!=null && td!=undefined) td.className=xstyle+'on';
}
function off(td,xstyle){
   if(td!=null && td!=undefined) td.className=xstyle;
}
function f(val,n,fill){
    var res= '';
    for(var r=0;r<n;r++){
       if((val+res).length==n) break;
       res+=fill;
    }
    res+=val;
    return res;
}
function sc(td,s,o,sid,pid,cx,ct,promo,currentkey,nop){
   var ydelta= 0;
   var xdelta= 0;
    var obbj= null;
    obbj= parent.document.getElementById('gobacklink');
    obbj.style.visibility="hidden";
    obbj.style.display="none";
    obbj= parent.document.getElementById('p_d');
    obbj.style.visibility="hidden";
    obbj.style.display="none";
    obbj= parent.document.getElementById('p_s');
    obbj.style.visibility="hidden";
    obbj.style.display="none";
    obbj= parent.document.getElementById('uparrow');
    obbj.style.visibility="hidden";
    obbj.style.display="none";
    obbj= parent.document.getElementById('downarrow');
    obbj.style.visibility="hidden";
    obbj.style.display="none";
    obbj= parent.document.getElementById('leftarrow');
    obbj.style.visibility="hidden";
    obbj.style.display="none";
    obbj= parent.document.getElementById('rightarrow');
    obbj.style.visibility="hidden";
    obbj.style.display="none";
    var x=0;
    var y=0;
    try{
     x= window.pageXOffset;
     y= window.pageYOffset;
     if(x==undefined){
        y= document.documentElement.scrollTop;
        x= document.documentElement.scrollLeft;
     }
   }catch(err){
        y= document.documentElement.scrollTop;
        x= document.documentElement.scrollLeft;
   }
   //obviate when moving screen
   if(s!='s'){
       var spbtn= document.getElementById('saveplnk');
       var ssbtn= document.getElementById('saveslnk');       
       var dlbtn= document.getElementById('delelnk');
       var splch= document.getElementById('serieid');
       document.getElementById("currentkey").title=currentkey;
       document.getElementById("nop").title=nop;
       //reattaching delegates will reuse duration..
       if(s!='x') document.getElementById('duration').title=s;
       spbtn.style.visibility="hidden";
       spbtn.style.display="none";
       ssbtn.style.visibility="hidden";
       ssbtn.style.display="none";
       dlbtn.style.visibility="hidden";
       dlbtn.style.display="none";
       pl= true;
       var rowvalues;
       if(td.parentElement){
          rowvalues= td.parentElement.id.split('@');
//          document.getElementById('pchannel').innerHTML= rowvalues[1]+' / '+td.parentElement.title;
          document.getElementById('pchannel').innerHTML= cx+' '+rowvalues[1];
       }else{
          rowvalues= td.parentNode.id.split('@');          
//          document.getElementById('pchannel').innerHTML=rowvalues[1]+' / '+td.parentNode.title;
          document.getElementById('pchannel').innerHTML= cx+' '+rowvalues[1];
       }
	   var values= td.id.split('@');
	   document.getElementById('channelnumber').title=cx;
	   document.getElementById('stationid').title=values[1];
	   document.getElementById('programid').title=pid;
	   retrieveProgramInfo();
       document.getElementById("progtype").title=o;
       if(nop=='0'){
	       document.getElementById('starttime').title=values[2];
		   var sechs= parseFloat(values[2]);
		   var psd1= new Date();
		   psd1.setTime(sechs);
		   document.getElementById('programstartdate').innerHTML= shortDateFormat(psd1)+'&nbsp;-';
		   var psd2= new Date();
		   psd2.setTime(sechs+(parseFloat(s)*1000));
		   document.getElementById('programenddate').innerHTML= shortDateFormatEnd(psd2,psd1);
	   }
	   // saved as program or serie or not saved at all?
	   if(td.getAttribute("name")!=null && td.getAttribute("name")!=undefined && td.getAttribute("name").length>2){
	      var savvalue= td.getAttribute("name").split('@');
	      document.getElementById("schedrdid").title= savvalue[1];
          if(savvalue[0].toUpperCase()=='P'){
             splch.title='';
	         document.getElementById('schedstatus').className="poprecp";
	         document.getElementById('schedstatus').style.backgroundColor="transparent";
             spbtn.style.visibility="hidden";
             spbtn.style.display="none";
             ssbtn.style.visibility="hidden";
             ssbtn.style.display="none";
             dlbtn.style.visibility="visible";
             dlbtn.style.display="inline";
          }else{
             splch.title= sid;
	         document.getElementById("schedstatus").className="poprecs";
	         document.getElementById('schedstatus').style.backgroundColor="transparent";
             spbtn.style.visibility="hidden";
             spbtn.style.display="none";
             ssbtn.style.visibility="hidden";
             ssbtn.style.display="none";
             dlbtn.style.visibility="visible";
             dlbtn.style.display="inline";
          }
	   } else {
           document.getElementById("schedstatus").className='nok';
           document.getElementById('schedstatus').style.backgroundColor="transparent";
           spbtn.style.visibility="visible";
           spbtn.style.display="inline";
           dlbtn.style.visibility="hidden";
           dlbtn.style.display="none";
	       if(o.toUpperCase()=='P'){
	          splch.title=''; 
              ssbtn.style.visibility="hidden";
              ssbtn.style.display="none";
	       }else{
	          splch.title= sid; 
              ssbtn.style.visibility="visible";
              ssbtn.style.display="inline";
	       }
	   }
	   if(ct.toUpperCase()=='PPV'){
          spbtn.style.visibility="hidden";
          spbtn.style.display="none";
          ssbtn.style.visibility="hidden";
          ssbtn.style.display="none";
          dlbtn.style.visibility="hidden";
          dlbtn.style.display="none";
	   }
	   if(nop=='1'){
          spbtn.style.visibility="hidden";
          spbtn.style.display="none";
          ssbtn.style.visibility="hidden";
          ssbtn.style.display="none";
          dlbtn.style.visibility="hidden";
          dlbtn.style.display="none";
	   }
	   if(promo=='0'){
          spbtn.style.visibility="hidden";
          spbtn.style.display="none";
          ssbtn.style.visibility="hidden";
          ssbtn.style.display="none";
          dlbtn.style.visibility="hidden";
          dlbtn.style.display="none";
          document.getElementById('promochannel').style.visibility="visible";
          document.getElementById('promochannel').style.display="inline";
	   }else{
          document.getElementById('promochannel').style.visibility="hidden";
          document.getElementById('promochannel').style.display="none";
	   }
   }
   if(pid>1 && pl){
      if(screen.height>599 && screen.height<801) {
         ydelta= -65;
         if(screen.width<900) xdelta= -40; else xdelta= 0;
      }
      if(screen.height>801 && screen.height<1051) {
         ydelta= 60;
         if(screen.width>1400) xdelta= 40; else xdelta= 0;
      }
      if(screen.height>1050 && screen.height<1500) {
         ydelta= 150;
         if(screen.width>1400) xdelta= 40; else xdelta= 0;
      }
      if(screen.height>1500) {
         ydelta= 200;
         if(screen.width>1400) xdelta= 40; else xdelta= 0;
      }
      drawCSSMessageBox(document.getElementById('cssform'), x-xdelta-150, y-ydelta-150, 600, 400);
   }
}
function scw(td,s,o,sid,pid,cx,ct,promo,currentkey,nop,xdelta,ydelta){
    var obbj= null;
    obbj= parent.document.getElementById('gobacklink');
    obbj.style.visibility="hidden";
    obbj.style.display="none";
    obbj= parent.document.getElementById('p_d');
    obbj.style.visibility="hidden";
    obbj.style.display="none";
    obbj= parent.document.getElementById('p_s');
    obbj.style.visibility="hidden";
    obbj.style.display="none";
    obbj= parent.document.getElementById('uparrow');
    obbj.style.visibility="hidden";
    obbj.style.display="none";
    obbj= parent.document.getElementById('downarrow');
    obbj.style.visibility="hidden";
    obbj.style.display="none";
    obbj= parent.document.getElementById('leftarrow');
    obbj.style.visibility="hidden";
    obbj.style.display="none";
    obbj= parent.document.getElementById('rightarrow');
    obbj.style.visibility="hidden";
    obbj.style.display="none";
    var x=0;
    var y=0;
    try{
      x= window.pageXOffset;
      y= window.pageYOffset;
      if(x==undefined){
         y= document.documentElement.scrollTop;
         x= document.documentElement.scrollLeft;
      }
    }catch(err){
        y= document.documentElement.scrollTop;
        x= document.documentElement.scrollLeft;
    }
   //obviate when moving screen
   if(s!='s'){
       var spbtn= document.getElementById('saveplnk');
       var ssbtn= document.getElementById('saveslnk');       
       var dlbtn= document.getElementById('delelnk');
       var splch= document.getElementById('serieid');
       document.getElementById("currentkey").title=currentkey;
       document.getElementById("nop").title=nop;
       //reattaching delegates will reuse duration..
       if(s!='x') document.getElementById('duration').title=s;
       spbtn.style.visibility="hidden";
       spbtn.style.display="none";
       ssbtn.style.visibility="hidden";
       ssbtn.style.display="none";
       dlbtn.style.visibility="hidden";
       dlbtn.style.display="none";
       pl= true;
       var rowvalues;
       if(td.parentElement){
          rowvalues= td.parentElement.id.split('@');
          document.getElementById('pchannel').innerHTML= cx+' '+rowvalues[1];
       }else{
          rowvalues= td.parentNode.id.split('@');          
          document.getElementById('pchannel').innerHTML= cx+' '+rowvalues[1];
       }
	   var values= td.id.split('@');
	   document.getElementById('channelnumber').title=cx;
	   document.getElementById('stationid').title=values[1];
	   document.getElementById('programid').title=pid;
	   retrieveProgramInfo();
       document.getElementById("progtype").title=o;
       if(nop=='0'){
	       document.getElementById('starttime').title=values[2];
		   var sechs= parseFloat(values[2]);
		   var psd1= new Date();
		   psd1.setTime(sechs);
		   document.getElementById('programstartdate').innerHTML= shortDateFormat(psd1)+'&nbsp;-';
		   var psd2= new Date();
		   psd2.setTime(sechs+(parseFloat(s)*1000));
		   document.getElementById('programenddate').innerHTML= shortDateFormatEnd(psd2,psd1);
	   }
	   // saved as program or serie or not saved at all?
	   if(td.getAttribute("name")!=null && td.getAttribute("name")!=undefined && td.getAttribute("name").length>2){
	      var savvalue= td.getAttribute("name").split('@');
	      document.getElementById("schedrdid").title= savvalue[1];
          if(savvalue[0].toUpperCase()=='P'){
             splch.title='';
	         document.getElementById('schedstatus').className="poprecp";
	         document.getElementById('schedstatus').style.backgroundColor="transparent";
             spbtn.style.visibility="hidden";
             spbtn.style.display="none";
             ssbtn.style.visibility="hidden";
             ssbtn.style.display="none";
             dlbtn.style.visibility="visible";
             dlbtn.style.display="inline";
          }else{
             splch.title= sid;
	         document.getElementById("schedstatus").className="poprecs";
	         document.getElementById('schedstatus').style.backgroundColor="transparent";
             spbtn.style.visibility="hidden";
             spbtn.style.display="none";
             ssbtn.style.visibility="hidden";
             ssbtn.style.display="none";
             dlbtn.style.visibility="visible";
             dlbtn.style.display="inline";
          }
	   } else {
           document.getElementById("schedstatus").className='nok';
           document.getElementById('schedstatus').style.backgroundColor="transparent";
           dlbtn.style.visibility="hidden";
           dlbtn.style.display="none";
           spbtn.style.visibility="visible";
           spbtn.style.display="inline";
	       if(o.toUpperCase()=='P'){
	          splch.title=''; 
              ssbtn.style.visibility="hidden";
              ssbtn.style.display="none";
	       }else{
	          splch.title= sid; 
              ssbtn.style.visibility="visible";
              ssbtn.style.display="inline";
	       }
	   }
	   if(ct.toUpperCase()=='PPV'){
          spbtn.style.visibility="hidden";
          spbtn.style.display="none";
          ssbtn.style.visibility="hidden";
          ssbtn.style.display="none";
          dlbtn.style.visibility="hidden";
          dlbtn.style.display="none";
	   }
	   if(nop=='1'){
          spbtn.style.visibility="hidden";
          spbtn.style.display="none";
          ssbtn.style.visibility="hidden";
          ssbtn.style.display="none";
          dlbtn.style.visibility="hidden";
          dlbtn.style.display="none";
	   }
	   if(promo=='0'){
          spbtn.style.visibility="hidden";
          spbtn.style.display="none";
          ssbtn.style.visibility="hidden";
          ssbtn.style.display="none";
          dlbtn.style.visibility="hidden";
          dlbtn.style.display="none";
	      document.getElementById('promochannel').style.visibility="visible";
	      document.getElementById('promochannel').style.display="inline";
	   }else{
          document.getElementById('promochannel').style.visibility="hidden";
          document.getElementById('promochannel').style.display="none";
	   }
   }
   if(pid>1 && pl){
      if(screen.height>599 && screen.height<801) {
         ydelta= -65;
         if(screen.width<900) xdelta= -40; else xdelta= 0;
      }
      if(screen.height>801 && screen.height<1051) {
         ydelta= 60;
         if(screen.width>1400) xdelta= 40; else xdelta= 0;
      }
      if(screen.height>1050 && screen.height<1500) {
         ydelta= 150;
         if(screen.width>1400) xdelta= 40; else xdelta= 0;
      }
      if(screen.height>1500) {
         ydelta= 200;
         if(screen.width>1400) xdelta= 40; else xdelta= 0;
      }
      drawCSSMessageBox(document.getElementById('cssform'), x-0-xdelta-50, y-25-ydelta-150, 600, 400);
   }
}
function htmlenc(value){
        if(value==undefined || value==null) return "";
		value= value.replace(/&/g, "&amp;");
		value= value.replace(/ñ/g, "n");
		value= value.replace(/Ñ/g, "N");
		value= value.replace(/á/g, "a");
		value= value.replace(/Á/g, "A");
		value= value.replace(/é/g, "e");
		value= value.replace(/É/g, "E");
		value= value.replace(/í/g, "i");
		value= value.replace(/Í/g, "I");
		value= value.replace(/ó/g, "o");
		value= value.replace(/Ó/g, "O");
		value= value.replace(/ú/g, "u");
		value= value.replace(/Ú/g, "U");
		value= value.replace(/ü/g, "u");
		return value;
}
function handleRetrieveProgramInfo(ret){
   try{
     document.getElementById('title').innerHTML=htmlenc(coalesce(ret["title"],'Sin Titulo').replace(/;/g,':'));
     document.getElementById('prating').innerHTML=htmlenc(coalesce(ret["rating"],'NR').replace(/;/g,':'));
	 document.getElementById('serieid').title=coalesce(ret["serieid"],'');
     document.getElementById('longdescription').innerHTML=htmlenc(coalesce(coalesce(ret["longdescription"], ret["title"]),'Sin Descripcion').replace(/;/g,':'));
     document.getElementById('staff').innerHTML=htmlenc(coalesce(ret["staff"],' ').replace(/!/g,':').replace(/;/g,':'));
     document.getElementById('category').innerHTML=htmlenc(coalesce(ret["category"],' '));
     if(document.getElementById('avisocell')!=undefined)
        document.getElementById('avisocell').checked=coalesce(ret["avisocell"],'false')=='true';
   }catch(err){
       alert('Respuesta de busqueda itinerario ha fallado con: '+err);
   }
}
function retrieveProgramInfo(){
   try{
      var programid= parseFloat(document.getElementById('programid').title);
      var params= {"nativepid":document.getElementById('programid').title,
                   "accountid":document.getElementById('accountid').title,
                   "lsh":document.getElementById('lsh').title}
      if(programid>0)
         ErdvrService.retrieveProgramInfo(params, 
	            {callback:function(ret){
	                handleRetrieveProgramInfo(ret);
	                }, timeout:10000});
    }catch(err){
       alert('Busqueda itinerario ha fallado con: '+err);
    }
}
//-------------------- schedules
function handleNotification(ret){
    try{
	    if(coalesce(ret["result"],'false')=="true"){
	       var cur= document.getElementById("schedbtn");
	       var itm= document.getElementById(ret["currentkey"]);
	       if(cur!=null && cur!=undefined) {
              cur.style.visibility="hidden";
              cur.style.display="none";
	       }
           alert('Titulo '+ret["title"]+' sera notificado antes de comenzar..');
	    }
    }catch(err){
       alert('Respuesta de grabacion de notificacion ha fallado con: '+err);
    }
}
function scheduleNotification(){
   try{
	    var params= {"nativepid":document.getElementById('programid').title,
                     "title":coalesce(document.getElementById('title').innerHTML,'Notificacion'),
                     "currentkey":document.getElementById('currentkey').title,
	                 "channelnumber":document.getElementById('channelnumber').title,
	                 "accountid":document.getElementById('accountid').title,
	                 "lsh":document.getElementById('lsh').title};
	    if(document.getElementById('programid').title!=null && document.getElementById('stationid').title!=null)
	       ErdvrService.scheduleNotification(params, 
	            {callback:function(ret){
	                handleNotification(ret);
	                }, timeout:10000});
    }catch(err){
       alert('Notificacion de programa ha fallado con: '+err);
    }
}
//-------------------- Programs
function handleSaveProgram(ret){
    try{
        var cur= document.getElementById(ret["nativepid"]+'@'+ret["stationid"]+'@'+ret["starttime"]);
	    if(coalesce(ret["outcome"],'false')=="true"){
	       if(cur!=null && cur!=undefined){
		      cur.className='recp';
		      cur.onmouseover= function(){on(this,'recp');}
		      cur.onmouseout= function(){off(this,'recp');}
	          cur.setAttribute('name', 'P@'+ret["recording_definition_id"]);
           }
	    }else{
	       if(cur!=null && cur!=undefined){
	          cur.className='sd';
	          cur.onmouseover= function(){on(this,'sd');}
	          cur.onmouseout= function(){off(this,'sd');}
              cur.setAttribute('name',"");
           }
	        var cntc=0;
	        for(var recording in ret)
	           if((recording+"").indexOf("conflict")==0 && (recording+"").length>8) cntc++;
	        if(cntc>0)
               alert('Grabacion de programa ha fallado por conflicto con '+cntc+' programa'+(cntc>1?'s':''));
            else
               alert('Grabacion de programa ha fallado..');
	    }
    }catch(err){
       alert('Respuesta de grabacion de programa ha fallado con: '+err);
    }
}
function saveProgram(){
   try{
        var frequency= 'Once';          //document.getElementById('frequency');
        var keepuntil= 'SpaceIsNeeded'; //document.getElementById('keepuntil');
	    var params= {"nativepid":document.getElementById('programid').title,
	                 "channelnumber":document.getElementById('channelnumber').title,
	                 "stationid":document.getElementById('stationid').title,
	                 "starttime":document.getElementById('starttime').title, 
	                 "keepuntil":keepuntil,
	                 "frequency":frequency,
	                 "accountid":document.getElementById('accountid').title,
	                 "lsh":document.getElementById('lsh').title};
	    if(document.getElementById('programid').title!=null && document.getElementById('stationid').title!=null)
	       ErdvrService.scheduleProgram(params, 
	            {callback:function(ret){
	                handleSaveProgram(ret);
	                }, timeout:10000});
    }catch(err){
       alert('Grabacion de programa ha fallado con: '+err);
    }
}
//-------------------- Series
function handleSaveSeries(ret){
    try{
	    if(coalesce(ret["outcome"],'false')=="true"){
	       for(var recording in ret){
	           if(recording.indexOf('dars_')==0){//process only the direct-addressed-record-series..
	              var cur= document.getElementById(recording.substring(5));
	              if(cur!=null && cur!=undefined){
	                 cur.className='recs';
	                 cur.onmouseover= function(){on(this,'recs');}
	                 cur.onmouseout= function(){off(this,'recs');}
	                 cur.setAttribute('name',ret[recording]);
                  }
	           }
	        }
	      }else{
	        var cntc=0;
	        for(var recording in ret)
	           if((recording+"").indexOf("conflict")==0 && (recording+"").length>8) cntc++;
	        if(cntc>0)
     	       alert('Grabacion de serie ha fallado por conflicto con '+cntc+' programa'+(cntc>1?'s':''));
     	    else
     	       alert('Grabacion de serie ha fallado..');     	    
	      }
    }catch(err){
       alert('Respuesta de grabacion de series ha fallado con: '+err);
    }
}
function saveSeries(){
   try{
        var frequency= 'EveryDay';      // document.getElementById('frequency');
        var keepuntil= 'SpaceIsNeeded'; // document.getElementById('keepuntil');
        var showtype= 'Any';            // document.getElementById('showtype');
        var airtimedomain= 'AnyTime';   // document.getElementById('airtimedomain');
        var channeldomain= 'CanonicalChannel'; //document.getElementById('channeldomain');
	    var params= {"channeldomain":channeldomain,    // AnyChannel, CanonicalChannel 
	                 "airtimedomain":airtimedomain,    // AnyTime, AnyTimeOncePerDay, CanonicalTime 
	                 "showtype":showtype,              // Any, FirstRunOnly
	                 "canonicalchannelnumber":document.getElementById('channelnumber').title,
	                 "utccanonicalstarttime":document.getElementById('starttime').title,
	                 "canonicalseriesid":document.getElementById('serieid').title, 
	                 "canonicalstationid":document.getElementById('stationid').title,
	                 "accountid":document.getElementById('accountid').title,
	                 "keepuntil":keepuntil,
	                 "frequency":frequency,
	                 "nativepid":document.getElementById('programid').title,
	                 "lsh":document.getElementById('lsh').title};
	    if(document.getElementById("accountid").title!=null 
	       && document.getElementById("stationid").title!=null
   	         && document.getElementById("starttime").title!=null)
	       ErdvrService.scheduleSeries(params, 
	            {callback:function(ret){
	                handleSaveSeries(ret);
	                }, timeout:10000});
    }catch(err){
       alert('Grabacion de series ha fallado con: '+err);
    }
}
//-------------------- cancelschedule
function cancelSchedule(){
     try{
	    var params= {"rdid":document.getElementById('schedrdid').title, 
	                 "accountid":document.getElementById('accountid').title,
                     "nativepid":document.getElementById('programid').title,
	                 "stationid":document.getElementById('stationid').title,
	                 "starttime":document.getElementById('starttime').title,
	                 "lsh":document.getElementById('lsh').title};
	    if(document.getElementById("schedrdid").title!=null){
 	          ErdvrService.unscheduleRecording(params, 
 	               {callback:function(ret){
 	                  handleUnscheduleRecording(ret);
 	                  }, timeout:10000});
	    }
    }catch(err){
       alert('Cancelacion de grabacion ha fallado con: '+err);
    }
}
function handleUnscheduleRecording(ret){
    try{
	    if(coalesce(ret["outcome"],'false')=="true"){
	       for(var recording in ret){
	           if(recording.indexOf('dars_')==0){
	             var cur= document.getElementById(recording.substring(5));
    	         if(cur!=null && cur!=undefined){
	                cur.className='sd';
	                cur.onmouseover= function(){on(this,'sd'); }
	                cur.onmouseout= function(){off(this,'sd'); }
	                cur.setAttribute('name','');
                 }
	          }
	       }
	    } else {
	      alert('No se pudo cancelar grabacion..');
	    }
    }catch(err){
       alert('Respuesta de cancelacion de grabacion ha fallado con: '+err);
    }
}
function dateFormat(psd){
  return f(psd.getDate(),2,'0')+'/'+
         f((psd.getMonth()+1),2,'0')+' '+
         f(psd.getHours(),2,'0')+':'+
         f(psd.getMinutes(),2,'0');
}
function shortDateFormat(psd){
  var dia=new Array("Dom","Lun","Mar","Mie","Jue","Vie","Sab");
  if(psd.getHours()<=12){
     var hours= psd.getHours()==0?"12":psd.getHours();
     return (dia[psd.getDay()]+' '+f(hours,2,'0')+':'+f(psd.getMinutes(),2,'0')+' am');
  }
  return (dia[psd.getDay()]+' '+f((psd.getHours()-12),2,'0')+':'+f(psd.getMinutes(),2,'0')+' pm');
}
function shortDateFormatEnd(psd2,psd1){
  var dia=new Array("Dom","Lun","Mar","Mie","Jue","Vie","Sab");
  var day= dia[psd2.getDay()]+' ';
  if(psd1.getDay()==psd2.getDay()) day='';
  if(psd2.getHours()<=12) {
     var hours= psd2.getHours()==0?"12":psd2.getHours();
     return (day+f(hours,2,'0')+':'+f(psd2.getMinutes(),2,'0')+' am');
  }
  return (day+f((psd2.getHours()-12),2,'0')+':'+f(psd2.getMinutes(),2,'0')+' pm');
}
function bless(val){
  if(val==undefined || val==null) return "";
  return val.replace(/[\"\'<>\\]/g,"")
            .replace(/[\"\'][\s]*javascript:(.*)[\"\']/gi, "\"\"")
            .replace(/</g, "&lt;")
            .replace(/>/g, "&gt;")
            .replace(/eval\((.*)\)/gi,"");
}
function coalesce(val,rep){
   try{
      if(val!=undefined && val!=null) return bless(val);
   }catch(err){}
   return bless(rep);
}
function ob(id) {
  return document.getElementById(id);
}
function closeCSSMessageBox(){
  if(coalesce(document.getElementById('srchid').title,'')!='scws'){
    parent.document.getElementById('p_d').style.visibility="visible";
    parent.document.getElementById('p_d').style.display="inline";
    parent.document.getElementById('p_s').style.visibility="visible";
    parent.document.getElementById('leftarrow').style.visibility="visible";
    parent.document.getElementById('rightarrow').style.visibility="visible";
    parent.document.getElementById('p_s').style.display="inline";
    parent.document.getElementById('leftarrow').style.display="inline";
    parent.document.getElementById('rightarrow').style.display="inline";
  }
  parent.document.getElementById('gobacklink').style.visibility="visible";
  parent.document.getElementById('uparrow').style.visibility="visible";
  parent.document.getElementById('downarrow').style.visibility="visible";
  parent.document.getElementById('gobacklink').style.display="inline";
  parent.document.getElementById('uparrow').style.display="inline";
  parent.document.getElementById('downarrow').style.display="inline";
  document.getElementById('stationid').title='';
  document.getElementById('programid').title='';
  var fscr = document.getElementById('FullScreen');
  if(fscr){
     fscr.style.position = "absolute";
     fscr.style.left = "1px";
     fscr.style.top = "1px";
     fscr.className = "trans50";
     fscr.style.backgroundColor="#FFFFFF";
     fscr.style.zIndex = 9999;
     fscr.style.width = "0px";
     fscr.style.height = "0px";
     fscr.style.visibility="hidden";
     fscr.style.display="none";
 }
 pl= false;
}
// Inspiration from nsftools.com (http://www.nsftools.com/tips/NotesTips.htm#datepicker)
function drawCSSMessageBox(data, x, y, pwidth, pheight) {
  dimScreen();
  resizeFrame(parent.document.getElementById('ifr'),pheight+100,pheight+200);
  if(!document.getElementById('cssform')){
     var newNode = document.createElement("div");
     newNode.setAttribute("id", 'cssform');
     newNode.setAttribute("style", "visibility: hidden; display: none;");
     document.body.appendChild(newNode);
  }
  var cssform = document.getElementById('cssform');
  cssform.style.position = "absolute";
  cssform.className = "popup";
  cssform.style.width = pwidth + "px";
  cssform.style.height = pheight + "px";
  cssform.style.zIndex = 10000;
  cssform.innerHTML = data.innerHTML;
  cssform.style.visibility = "visible";
  cssform.style.display = "block" ;
  try{
     cssform.style.left = (((window.screen.availWidth/2.0)-(pwidth/2.0))+x)+ "px";  
     cssform.style.top = (((window.screen.availHeight/2.0)-(pheight/2.0))+y-10)+ "px";
  }catch(ex){
     cssform.style.left = (((screen.width/2)-(pwidth/2))+x)+ "px";  
     cssform.style.top = (((screen.height/2)-(pheight/2))+y-10)+ "px";
  }
}
function dimScreen(){
  if(!document.getElementById('FullScreen')){
     var newNode = document.createElement("div");
     newNode.setAttribute("id", 'FullScreen');
     newNode.setAttribute("style", "visibility: hidden;");
     document.body.appendChild(newNode);
  }
// move cssformScreen to cover the entire page with its dim-ness-ocity
  var fscr = document.getElementById('FullScreen');
  fscr.style.position = "absolute";
  fscr.style.left = "1px";
  fscr.style.top = "1px";
  fscr.className = "trans50";
  fscr.style.backgroundColor="#FFFFFF";
  fscr.style.zIndex = 9999;
  fscr.style.width = (document.getElementById('epgtable').clientWidth+20)+"px";
  fscr.style.height = (document.getElementById('epgtable').clientHeight+120)+"px";
  fscr.style.visibility = "visible"; 
  fscr.style.display = "block";
}
function signin(f){
 f.pwd.value=MD5(f.pwd.value.toLowerCase());
 f.route.value="l";
 f.submit();
}
function presignup(f){
 f.route.value="s";
 f.submit();
}
function prereset(f){
 f.route.value="r";
 f.submit();
}
function checkpresignup(f){
 var msg= "Errores encontrados:\n";
 if(trim(f.acct.value).length!=10)    msg +='- La cuenta debe ser el #telefono de 10 dígitos..\n';
 if(f.pwd1.value!=f.pwd2.value)       msg +='- Deben coincidir las contraseñas..\n';
 if(trim(f.pwd1.value).length==0)     msg +='- Debe digitar una contraseña..\n';
 if(f.mail1.value.toLowerCase()!=
    f.mail2.value.toLowerCase())      msg +='- Deben coincidir las direcciones de correo..\n';
 if(!validateMail(f.mail1.value) || 
     trim(f.mail1.value).length==0)   msg +='- Debe digitar un correo valido..\n';
 if(coalesce(f.cellphone.value,'').length>0 &&
    coalesce(f.cellphone.value,'').length!=10)   msg +='- #celular debe ser de 10 digitos..\n';
 if(trim(f.guid.value).length!=4)    msg +='- Debe digitar los últimos 4 caracteres del GUID de una de las cajitas..\n';
 if(msg.length>22) return msg;
 return '';
}
function checkpresignin(f){
 var msg= "Errores encontrados:\n";
 if(trim(f.acct.value).length!=10) msg +='- La cuenta debe ser el #teléfono de 10 dígitos..\n';
 if(trim(f.pwd.value).length==0)   msg +='- Debe digitar una contraseña..\n';
 if(msg.length>22) return msg;
 return '';
}
function checkpresearch(f){
 var msg= "";
 if(trim(f.term.value).length<3) msg +='Que desea buscar realmente?';
 if(msg.length>22) return msg;
 return '';
}
function trim(v){
 if(v==undefined || v==null) return "";
 return v.replace(/^\s*|\s*$/g,"");
}
function validateMail(v){
 return (v.match(/^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/));
}
function signup(f){
 f.pwd1.value=MD5(f.pwd1.value.toLowerCase());
 f.pwd2.value=MD5(f.pwd2.value.toLowerCase());
 f.guid.value=MD5(f.guid.value.toLowerCase());
 presignup(f);
}
function checkprereset(f,s){
 var msg= "Errores encontrados:\n";
 if(trim(f.acct.value).length!=10)    msg +='- La cuenta debe ser el #teléfono de 10 dígitos..\n';
 if((!validateMail(f.mail1.value) || 
     trim(f.mail1.value).length==0))  msg +='- Debe digitar un correo válido..\n';
 if(s.toLowerCase()=='on'){
	if(f.pwd1.value!=f.pwd2.value)    msg +='- Deben coincidir las contraseñas..\n';
	if(trim(f.pwd0.value).length==0)  msg +='- Debe digitar la contraseña actual..\n';
	if(trim(f.pwd1.value).length==0)  msg +='- Debe digitar la contraseña nueva..\n';
    if(f.mail1.value.toLowerCase()!=
       f.mail2.value.toLowerCase())   msg +='- Deben coincidir las direcciones de correo..\n';
    if(coalesce(f.cellphone.value,'').length>0 
    && coalesce(f.cellphone.value,'').length!=10) msg +='- #celular debe ser de 10 dígitos..\n';
 }
 if(msg.length>22) return msg;
 return '';
}
function checkpreresetoff(f){
 var msg= "Errores encontrados:\n";
 if(trim(f.acct.value).length!=10)  msg +='- La cuenta debe ser el #teléfono de 10 dígitos..\n';
 if(f.pwd1.value!=f.pwd2.value)     msg +='- Deben coincidir las contraseñas..\n';
 if(trim(f.pwd0.value).length==0)   msg +='- Debe digitar la contraseña anterior..\n';
 if(trim(f.pwd1.value).length==0)   msg +='- Debe digitar la contraseña nueva..\n';
 if(msg.length>22) return msg;
 return '';
}
function resetoff(f){
  f.pwd0.value=MD5(f.pwd0.value.toLowerCase());
  f.pwd1.value=MD5(f.pwd1.value.toLowerCase());
  f.pwd2.value=MD5(f.pwd2.value.toLowerCase());
  prereset(f);
}
function hidemsg(){
  var lo= document.getElementById('loading');
  if(lo!=null && lo!=undefined) lo.className='loading-invisible';
}
function hidemsgifr(doc){
  var lo= doc.getElementById('loading');
  if(lo!=null && lo!=undefined) lo.className='loading-invisible';
}
function showmsg(){
  var lo= document.getElementById('loading');
  if(lo!=null && lo!=undefined) lo.className='loading-visible';
}
function resend(){
  var id= window.setTimeout('showmsg();document.frmctl.submit()',(1800*1000)); // 1800 secs
}
function resizeFrame(f,min,max) {
  if(f==null || f==undefined) return;
  var h= 0;
  try{
     h= f.contentWindow.document.body.scrollHeight;
  }catch(er1){
     try{
        h= f.contentWindow.document.body.document.height;  
     }catch(er2){
        try{
           h= f.contentWindow.document.OffsetHeight;
        }catch(er3){
           alert(er3);
        }
     }
  }
  if(h==undefined) h= f.contentWindow.document.body.document.height;
  if(h==undefined) h= f.contentWindow.document.OffsetHeight;
  if(h<min) h=min;
  if(h>max) h=max;
  f.style.height = h+"px";
}
function resetParent(f){
  if(f==null || f==undefined) return;
  if(!ends(f.location.href,'welcome.html')) f.location='welcome.html';
}
function ends(str,sub){
  return (str.match(sub+"$")==sub);
}
function starts(str,sub){
  return (str.match("^"+sub)==sub);
}
function reloc(doc){
var f=doc.location; 
 if(!ends(f.href,'welcome.html')){
   doc.location='welcome.html'; 
   return true;
 }else{
   return false;
 }
}
function addoption(doc,selid,label,value){
  var opt = doc.createElement('option');
  opt.text = label;
  opt.value = value;
  var sel= doc.getElementById(selid);
  try {
    sel.add(opt, null);
  }catch(ex) {
    try{
       sel.add(opt);
    }catch(ex2){
       alert('2 '+ex2);
    }
  }
}
