
//This method create the first Popup. It can be validation popup or select PVR of user
//you must define on your CSS:
//'[JSRecorder.prototype.CSSPrefix]RECContainer' class for cobranding the DIV containing the link 
//'[JSRecorder.prototype.CSSPrefix]RECSpan' class for cobranding the span containing the disabled functionality
//'[JSRecorder.prototype.CSSPrefix]RECLink' class for cobranding the DIV containing the link
//
//(e.g, if you init the CSSPrefix property to "CUSTOMLNK_", you have to define this CSS classes:CUSTOMLNK_RECContainer,CUSTOMLNK_RECSpan,CUSTOMLNK_RECLink
//
// Also, you can customize the textual content of the link, qriting on 
// CONST_RECORD_STR = "Grabar #EVNAME# en tu PVR"; (this is the default value)
JSRecorder.prototype.pDate = ""; 
JSRecorder.prototype.EvId = "";                     //event id
JSRecorder.prototype.ChId = "";                     //channel id
JSRecorder.prototype.EvName = "";                   //event name. Optional.
JSRecorder.prototype.Enabled = false;               //object enabled or disabled (interface)
JSRecorder.prototype.DrawIfDisabled = false;        //object is drawn when it's disabled?
JSRecorder.prototype.DocumentWrite = true;          //document.write / getElement("[NAME]").innerHTML or we return an HTML string to the invoker 
JSRecorder.prototype.TargetLayer = "";              // if DocumentWrite ==true, this value decides if the draw method mades a document.write (empty value) or a getElement("[VALUE]").INNERhtml = strHTML 
JSRecorder.prototype.PageLink = "javascript:;";     //link to the onclick event
JSRecorder.prototype.PageLinkAdditionalParams = ""; //additional params passed to pageLink (pagename&EvId=this.EvId&this.pageLinkAdditionalParams)
JSRecorder.prototype._internalId = "";              //unique internal id for encapsulating purposes
JSRecorder.prototype.OnclickEventHandler = "";      //function executed on onclick event. Incompatible with PageLink !="" or "javascript:;"; e.g: myRecorder.checkRecording (put it without parenthesis, and you receive on the onclick method a invocation with EvId As Param
JSRecorder.prototype.CSSPrefix = "REC_"             //Preffix for CSS class definition

JSRecorder.prototype.CONST_RECORD_STR = "Grabar #EVNAME# en tu PVR";

JSRecorder.prototype.CONST_DIV_CSS = "";
JSRecorder.prototype.CONST_SPAN_CSS = "";
JSRecorder.prototype.CONST_LINK_CSS = "";

/// <summary>
/// Cosntructor::JSRecorder (pStrEvId,pBoolEnabled,pBoolDrawIfDisabled,pBoolDocumentWrite,pStrTargetLayer)
/// </summary>
/// <returns>object created</returns>
function JSRecorder (pStrEvId,pStrChId,pStrEvName,pDate,pBoolEnabled,pBoolDrawIfDisabled,pBoolDocumentWrite,pStrTargetLayer,pStrPageLink,pStrPageLinkAdditionalParams,pStrOnclickEventHandler,pStrCSSPrefix)
{
 this.pDate											= pDate;
 this.EvId                      = pStrEvId;
 this.ChId                      = pStrChId;
 this.EvName                    = pStrEvName;
 this._internalId               = pStrEvId;
 this.Enabled                   = pBoolEnabled;
 this.DrawIfDisabled            = pBoolDrawIfDisabled;
 this.DocumentWrite             = pBoolDocumentWrite;
 this.TargetLayer               = pStrTargetLayer;
 this.PageLink                  = pStrPageLink;
 this.PageLinkAdditionalParams  = pStrPageLinkAdditionalParams;
 this.OnclickEventHandler       = pStrOnclickEventHandler;
 if (pStrCSSPrefix!=null)
     this.CSSPrefix             = pStrCSSPrefix;
}

/// <summary>
/// gets str of the button
/// </summary>
/// <returns></returns>
JSRecorder.prototype._getStr = function(pBoolWithDiv)
{
 var divcss = this.CSSPrefix+"RECContainer";
 var spancss = this.CSSPrefix+"RECSpan";
 var linkcss = this.CSSPrefix+"RECLink";
 if (this.CONST_DIV_CSS!="")
   divcss = this.CONST_DIV_CSS;
 if (this.CONST_SPAN_CSS!="")
   spancss = this.CONST_SPAN_CSS;
 if (this.CONST_LINK_CSS!="")
   linkcss = this.CONST_LINK_CSS;
   
 var strBut = "";
 if (pBoolWithDiv)
    strBut += "<div id='REC_"+this._internalId+"' class='"+divcss+"'>";
 if (this.PageLink=="")
    this.PageLink="javascript:;";

 var strEvName = this.EvName; 

 if (strEvName!="")
    {
    strEvName = "'"+strEvName+"'";
    strEvName = this.CONST_RECORD_STR.replace("#EVNAME#",strEvName)
    }
 else
   strEvName = this.CONST_RECORD_STR.replace("#EVNAME#","")   


  strEvName ="<span class='"+spancss+"'>"+strEvName+"</span>";
 
if (!this.Enabled)
   strBut+=strEvName;
else       
{
   if (this.PageLink!="javascript:;")
   {
      if (this.PageLinkAdditionalParams!="")
        strBut +="<a class='"+linkcss+"' href='"+this.PageLink+"EvId="+this.EvId+"&"+this.PageLinkAdditionalParams+"'>"+strEvName+"</a>";
      else
         strBut +="<a class='"+linkcss+"' href='"+this.PageLink+"EvId="+this.EvId+"'>"+strEvName+"</a>";
   }
   else
      strBut +="<a class=\""+linkcss+"\" href=\""+this.PageLink+"\" onclick=\""+this.OnclickEventHandler+"('"+this.ChId+"','"+this.EvId+"','"+this.EvName+"','"+this.pDate+"')\">"+strEvName+"</a>";
}    
if (pBoolWithDiv)
   strBut += "</div>";
return strBut;
}



/// <summary>
/// draw element
/// </summary>
/// <returns></returns>
JSRecorder.prototype.draw = function()
{
  var writeElement = "";
  var withDiv = (document.getElementById("REC_"+this._internalId)==null);
  
  if (this.TargetLayer!="")
    withDiv = false;
  
  if (!this.Enabled && !DrawIfDisabled)
        writeElement = "[NOWRITE]";
  else
        writeElement = this._getStr(withDiv);

  if (writeElement!="[NOWRITE]" && writeElement!="")
  {
      if (this.DocumentWrite)
      {
        if (this.TargetLayer!="")
            document.getElementById(this.TargetLayer).innerHTML = writeElement;
        else
            {
            if (document.getElementById("REC_"+this._internalId)!=null)
                document.getElementById("REC_"+this._internalId).innerHTML = writeElement;
            else
                document.write(writeElement);
            }
      }
      else
        return writeElement;
  }
  else
    return "";
  
}

/// <summary>
/// setState: change status to enabled or disabled
/// </summary>
/// <returns></returns>
JSRecorder.prototype.setState = function(pBoolEnabled)
{
  this.Enabled = pBoolEnabled;
  this.draw();
}

