
function isCreditCard(textObj) {
 /*
  *  This function validates a credit card entry.
  *  If the checksum is ok, the function returns true.
  */
   var ccNum;
   var odd = 1;
   var even = 2;
   var calcCard = 0;
   var calcs = 0;
   var ccNum2 = "";
   var aChar = '';
   var cc;
   var r;
   
   ccNum = textObj.value;
   for(var i = 0; i != ccNum.length; i++) {
      aChar = ccNum.substring(i,i+1);
      if(aChar == '-') {
         continue;
      }

      ccNum2 = ccNum2 + aChar;
   }
   
   cc = parseInt(ccNum2);
   if(cc == 0) {
      return false;
   }
   r = ccNum.length / 2;
   if(ccNum.length - (parseInt(r)*2) == 0) {
      odd = 2;
      even = 1;
   }
   
   for(var x = ccNum.length - 1; x > 0; x--) {
      r = x / 2;
      if(r < 1) {
         r++;
      }
      if(x - (parseInt(r) * 2) != 0) {
         calcs = (parseInt(ccNum.charAt(x - 1))) * odd;
      }
      else {
         calcs = (parseInt(ccNum.charAt(x - 1))) * even;
      }
      if(calcs >= 10) {
         calcs = calcs - 10 + 1;
      }
      calcCard = calcCard + calcs;
   }
   
   calcs = 10 - (calcCard % 10);
   if(calcs == 10) {
      calcs = 0;
   }
   
   if(calcs == (parseInt(ccNum.charAt(ccNum.length - 1)))) {
      return true;
   }
   else {
      return false;
   }
}

function createXMLHttp() {

    if (window.ActiveXObject) {
      var aVersions = [ "MSXML2.XMLHttp.5.0",
        "MSXML2.XMLHttp.4.0","MSXML2.XMLHttp.3.0",
        "MSXML2.XMLHttp","Microsoft.XMLHttp"
      ];

      for (var i = 0; i < aVersions.length; i++) {
        try {
            var oXmlHttp = new ActiveXObject(aVersions[i]);         
            return oXmlHttp;
        } catch (oError) {
            //Do nothing
        }
      }
    }else if (typeof XMLHttpRequest != "undefined") {                           
        return new XMLHttpRequest();
    } 
    return new XMLHttpRequest();
}

function ReloadEPG( sURL , dt, shift, period, site, u_id, u_pwd )
{
    var xmlHTTP = createXMLHttp();
    xmlHTTP.open("GET", sURL + "?time=" + dt + "&period=" + period + "&shift=" + shift + "&siteID=" + site + "&UID=" + u_id + "&PWD=" + u_pwd, false, null, null);
    xmlHTTP.send(null) ;
    return xmlHTTP.responseText;
}




function Date2String( aDate )
{
  return ( new String(aDate.getFullYear()) + "-" + new String(aDate.getMonth() + 1) + "-" + new String(aDate.getDate()));
}
 
function GenerateDateSelect()
{
    var sRes = "";
    var dt = new Date();    
    dt = new Date(dt.getFullYear(), dt.getMonth(), dt.getDate()-16);

    for(var d = 0; d < 19; d++)
    {
        var dtCur = dt;
    sRes += '<option value="' + Date2String( dt ) + '">' + dt.toLocaleDateString() + '</option>';
    dt = new Date(dt.getTime() + 86400000);
    }
    return sRes;

}



function removeText(id,text) {
    if (document.getElementById(id).value == text){
        document.getElementById(id).value = "";
    }
}
function writeText(id,text) {
    if (document.getElementById(id).value == ""){
        document.getElementById(id).value = text;
    }
}


function popUp(URL) {
    day = new Date();
    id = day.getTime();
    eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=0,width=720,height=320,left = 362,top = 284');");
}

function openPlayer(chID, siteID, username, password)

{
    var wd = (screen.width/2 - 520);
    var ht = (screen.height/2 - 290);
    
    var status = "'scrollbars=no,width=800,height=590, top="+ ht + ", left=" + wd + ",resizable=yes,menubar=no,status=no,toolbar=no'"
    
    window.open("/api/player/?type=tv&ch="+ chID +"&siteID="+ siteID +"&PHONENO="+ username +"&PWD="+ password +"",'PLAYER', status)

}


function openPlayerV2(playertype, chID, siteID, username, password)

{
    var wd = (screen.width/2 - 520);
    var ht = (screen.height/2 - 290);
    
    var status = "'scrollbars=no,width=800,height=590, top="+ ht + ", left=" + wd + ",resizable=yes,menubar=no,status=no,toolbar=no'"
    
    window.open("http://www.iptv-distribution.net/api/player/?type="+ playertype +"&ch="+ chID +"&siteID="+ siteID +"&PHONENO="+ username +"&PWD="+ password +"",'PLAYER', status)

}


function openPreview(chID, siteID, width, height)
    {
        newWin = window.open("http://www.iptv-distribution.net/api/player/?type=tv&preview=true&ch="+ chID +"&siteID="+ siteID+"","", "width="+ width +",height="+ height +",toolbar=no,menubar=no,location=no,scrollbars=yes,resizable=yes");
        newWin.focus();
    }


function Refresh(s)
{   
var Item = (s.options[s.selectedIndex].value);
    

    if(Item == "/")
    {
        window.open(Item ,'name','');
    }
    else
    {
        window.location.href = Item;
    }
}


function any_pop(url,width,height)
    {
        newWin = window.open(url, "", "width="+ width +",height="+ height +",toolbar=no,menubar=no,location=no,scrollbars=yes,resizable=yes");
        newWin.focus();
    }
    
function any_pop_no(url,width,height)
    {
        newWin = window.open(url, "", "width="+ width +",height="+ height +",toolbar=no,menubar=no,location=no,scrollbars=no,resizable=yes");
        newWin.focus();
    }

function xlaAFMlaunchv2(langid, siteID)
{
    xlaAFMopenwindowv2('','','', langid, siteID);
}

function xlaAFMopenwindowv2(faqid,topicid,question, langid, siteID)
{
    if (document.all) {
        windowheight = screen.availHeight;
        windowwidth=screen.availWidth;
        rightwidth=300;
        leftwidth=screen.availWidth-rightwidth-11;
        AFMwindow=window.open('/api/faq/afmmain.asp?lid='+ langid +'&siteID='+ siteID +'&topicid=' + topicid + '&faqid=' + faqid + '&question=' + question ,'xlaAFM','width='+rightwidth+',height='+windowheight+',screenX='+leftwidth+',screenY=0,top=0,left=' +leftwidth+',toolbar=0,location=0,status=1,menubar=0,resizable=1');
        AFMwindow.focus();
        
        // Resize Current Window //
        top.resizeTo(leftwidth,windowheight);
        top.moveTo(0,0);
        top.focus();
    } else {
        AFMwindow=window.open('/api/faq/afmmain.asp?lid='+langid+'&siteID='+ siteID +'&topicid=' + topicid + '&faqid=' + faqid + '&question=' + question  ,'','width=300,height=480,toolbar=0,location=0,status=1,menubar=0,resizable=1');
    }
}


function xlaAFMlaunch()
{
    xlaAFMopenwindow('','','');
}

function xlaAFMopenwindow(faqid,topicid,question)
{
    if (document.all) {
        windowheight = screen.availHeight;
        windowwidth=screen.availWidth;
        rightwidth=300;
        leftwidth=screen.availWidth-rightwidth-11;
        AFMwindow=window.open('/api/faq/afmmain.asp?lid=1&topicid=' + topicid + '&faqid=' + faqid + '&question=' + question ,'xlaAFM','width='+rightwidth+',height='+windowheight+',screenX='+leftwidth+',screenY=0,top=0,left=' +leftwidth+',toolbar=0,location=0,status=1,menubar=0,resizable=1');
        AFMwindow.focus();
        
        // Resize Current Window //
        top.resizeTo(leftwidth,windowheight);
        top.moveTo(0,0);
        top.focus();
    } else {
        AFMwindow=window.open('/api/faq/afmmain.asp?lid=1&topicid=' + topicid + '&faqid=' + faqid + '&question=' + question  ,'','width=300,height=480,toolbar=0,location=0,status=1,menubar=0,resizable=1');
    }
}




function inputMod(obj) 
{ 
 if (!obj.hlptext) obj.hlptext=obj.value 
 obj.value=(obj.hlptext==obj.value)?'':(obj.value=='')?obj.hlptext:obj.value 
} 

