﻿
function GetNextArticle(pCategoryID,pDirection)
{
    lBikingCat = 2;
    lRunCat = 3;
    lSwimCat = 1;
    if (pCategoryID == lSwimCat)
    {
        lArticleID = document.getElementById("ctl00_ContentPlaceHolder1_hf_SwimBlogID").value;
    }
    else if (pCategoryID == lBikingCat)
    {
        lArticleID = document.getElementById("ctl00_ContentPlaceHolder1_hf_BikeBlogID").value;
    }
    else if (pCategoryID == lRunCat)
    {
        lArticleID = document.getElementById("ctl00_ContentPlaceHolder1_hf_RunBlogID").value;
    }
    if (lArticleID != null)
    {
        lresult = Home.GetArticle(lArticleID, pCategoryID, pDirection);
        if (lresult.value != null && lresult.value != "")
        {
            lresultArray = lresult.value.split("~");
            if (pCategoryID == lSwimCat)
            {
                document.getElementById("ctl00_ContentPlaceHolder1_hf_SwimBlogID").value = lresultArray[0];
                document.getElementById("ctl00_ContentPlaceHolder1_SwimBlog").innerHTML = 
                "<div class=\"excerpt_image\"><a href=\"Gear.aspx?BLOGID=" + lresultArray[0] + "\">" + lresultArray[3] +"</a></div>";
                document.getElementById("ctl00_ContentPlaceHolder1_SwimBlog").innerHTML += lresultArray[1];
                if (lresultArray.length > 2)
                {
                    document.getElementById("ctl00_ContentPlaceHolder1_NextSwimBlog").innerHTML = "&nbsp;" + lresultArray[2];
                }
                else 
                {
                    document.getElementById("ctl00_ContentPlaceHolder1_NextSwimBlog").innerHTML = "&nbsp;"                
                }
            }
            else if (pCategoryID == lBikingCat)
            {
                document.getElementById("ctl00_ContentPlaceHolder1_hf_BikeBlogID").value = lresultArray[0];
                document.getElementById("ctl00_ContentPlaceHolder1_BikeBlog").innerHTML = 
                "<div class=\"excerpt_image\"><a href=\"Gear.aspx?BLOGID=" + lresultArray[0] + "\">" + lresultArray[3] + "</a></div>";
                document.getElementById("ctl00_ContentPlaceHolder1_BikeBlog").innerHTML += lresultArray[1];
                if (lresultArray.length > 2)
                {
                    document.getElementById("ctl00_ContentPlaceHolder1_NextBikeBlog").innerHTML = "&nbsp;" + lresultArray[2];
                }
                else 
                {
                    document.getElementById("ctl00_ContentPlaceHolder1_NextBikeBlog").innerHTML = "&nbsp;"                
                }
            }
            else if (pCategoryID == lRunCat)
            {
                document.getElementById("ctl00_ContentPlaceHolder1_hf_RunBlogID").value = lresultArray[0];
                document.getElementById("ctl00_ContentPlaceHolder1_RunBlog").innerHTML = 
                "<div class=\"excerpt_image\"><a href=\"Gear.aspx?BLOGID=" + lresultArray[0] + "\">" + lresultArray[3] + "</a></div>";
                document.getElementById("ctl00_ContentPlaceHolder1_RunBlog").innerHTML += lresultArray[1];
                if (lresultArray.length > 2)
                {
                    document.getElementById("ctl00_ContentPlaceHolder1_NextRunBlog").innerHTML = "&nbsp;" +lresultArray[2];
                }
                else 
                {
                    document.getElementById("ctl00_ContentPlaceHolder1_NextRunBlog").innerHTML = "&nbsp;"                
                }
            }
        }
    }
}

function registerclick(pAdID)
{
    Global.RecordClick(pAdID);
}

function sethighlighted(pThisRow)
{
    pThisRow.style.color ="#ffffff";
    pThisRow.style.backgroundColor="#003366";
}

function resethighlight(pThisRow)
{
    pThisRow.style.color ="#ffffff";
    pThisRow.style.backgroundColor="#5b5b5b";
}

var FVideoID = 0;
var preview_interval = null;

function changeProgramHome(pVideoID, pCategoryID)
{
   lresult = Home.ChangeProgram(pVideoID,pCategoryID);
   if (lresult.value != null && lresult.value != "")
   {
        FVideoID = pVideoID;
        lAllInfo = lresult.value.split("|");
        lVideoInfo = lAllInfo[0].split("~");
        lProgramInfo = lVideoInfo[0];
        lEmbedCode = lVideoInfo[1]+"&autoplay=1";//autostart the program when loaded
        var s1 = new SWFObject( lEmbedCode,"ply","320","248","9","#ffffff");//this SWFObject is 1.5, this code doesn"t work with the 2.0 version
         s1.addParam("allowfullscreen","true");
         s1.addParam("allowscriptaccess","always");
         s1.addParam("wmode","opaque");
         s1.addParam("usecaptions", "true");
         s1.addParam("flashvars","repeat=always&playlist=right&playlistsize=440&fullscreen=false");
         s1.write("preview");
   }
 
}

function NextPreviewHome()
{
    lNextPreview = Home.NextVideo(FVideoID);
    if (lNextPreview.value != null && lNextPreview.value !="")
    {
        lInfoArray = lNextPreview.value.split("~");
        //alert(lInfoArray);
        lresult = Home.ChangeProgram(lInfoArray[0],lInfoArray[1]);
           if (lresult.value != null && lresult.value != "")
           {
                
                FVideoID = lInfoArray[0];
                lAllInfo = lresult.value.split("|");
                lVideoInfo = lAllInfo[0].split("~");
                lProgramInfo = lVideoInfo[0];
                
                lEmbedCode = lVideoInfo[1]+"&autoplay=1";//autostart the program when loaded
                var s1 = new SWFObject( lEmbedCode,"ply","320","248","9","#ffffff");//this SWFObject is 1.5, this code doesn"t work with the 2.0 version
                 s1.addParam("allowfullscreen","true");
                 s1.addParam("allowscriptaccess","always");
                 s1.addParam("wmode","opaque");
                 s1.addParam("usecaptions", "true");
                 s1.addParam("flashvars","repeat=always&playlist=right&playlistsize=440&fullscreen=false");
                 s1.write("preview");
                 
                 lDesc = document.getElementById("ctl00_ContentPlaceHolder1_videoTitleDescription");
                 lDesc.innerHTML = lProgramInfo;

           }
    }
}

function changeProgram(pVideoID, pCategoryID)
{
   lresult = iTriTV.ChangeProgram(pVideoID,pCategoryID);
   if (lresult.value != null && lresult.value != "")
   {
        FVideoID = pVideoID;
        lAllInfo = lresult.value.split("|");
        lVideoInfo = lAllInfo[0].split("~");
        lProgramInfo = lVideoInfo[0];
        lEmbedCode = lVideoInfo[1]+"&autoplay=1";//autostart the program when loaded
        var s1 = new SWFObject( lEmbedCode,'ply','320','248','9','#ffffff');//this SWFObject is 1.5, this code doesn't work with the 2.0 version
         s1.addParam('allowfullscreen','true');
         s1.addParam('allowscriptaccess','always');
         s1.addParam('wmode','opaque');
         s1.addParam("usecaptions", "true");
         s1.addParam('flashvars','repeat=always&playlist=right&playlistsize=440&fullscreen=true');
         s1.write('preview');
         
         lDesc = document.getElementById("ctl00_ContentPlaceHolder2_program_info");
         lDesc.innerHTML = lProgramInfo;
         if (lAllInfo[2] != null && lAllInfo[2] != "")
         {
            lTopAd = document.getElementById("sponsor_ad_top");
            lTopAd.innerHTML = lAllInfo[2];
         }
   }
 
}

function StopPreview(pVideoID, pCategoryID)
{
     if (preview_interval != null)
     {
        clearInterval ( preview_interval);
       // alert("preview_stopped");
     }
    
    changeProgram(pVideoID, pCategoryID);
    
}

function NextPreview()
{
    
    lNextPreview = iTriTV.NextVideo(FVideoID);
    if (lNextPreview.value != null && lNextPreview.value !="")
    {
        lInfoArray = lNextPreview.value.split("~");
        lresult = iTriTV.ChangeProgram(lInfoArray[0],lInfoArray[1]);
           if (lresult.value != null && lresult.value != "")
           {
                
                FVideoID = lInfoArray[0];
                lAllInfo = lresult.value.split("|");
                lVideoInfo = lAllInfo[0].split("~");
                lProgramInfo = lVideoInfo[0];
                lEmbedCode = lVideoInfo[1]+"&autoplay=1";//autostart the program when loaded
                var s1 = new SWFObject( lEmbedCode,'ply','320','248','9','#ffffff');//this SWFObject is 1.5, this code doesn't work with the 2.0 version
                 s1.addParam('allowfullscreen','true');
                 s1.addParam('allowscriptaccess','always');
                 s1.addParam('wmode','opaque');
                 s1.addParam("usecaptions", "true");
                 s1.addParam('flashvars','repeat=always&playlist=right&playlistsize=440&fullscreen=true');
                 s1.write('preview');
                 
                 lDesc = document.getElementById("ctl00_ContentPlaceHolder2_program_info");
                 lDesc.innerHTML = lProgramInfo;

           }
    }
}

/*===========================================================================================

Date Functions For TriClub Calendar Export

============================================================================================*/

function StartDateGreater(sender,args)
 {
 
    lFirstDate = document.getElementById("ctl00_ContentPlaceHolder1_edt_StartDate");
    lEndDate = document.getElementById("ctl00_ContentPlaceHolder1_edt_EndDate");
    if (lFirstDate.value != "" && lEndDate.value != "")
    {
        if (Date.parse(lFirstDate.value)> Date.parse(lEndDate.value) )
        {   
            
            document.getElementById("ctl00_hf_ErrorMessage").value = 'Start Date must be before End Date';
            CheckErrors(true);
            document.getElementById("ctl00_ContentPlaceHolder1_edt_StartDate").focus();
            
        }
        else 
        {
            dismissboxv2();
        }
    }
 }
 
function SetEndDateMin(sender,args)
{
    if ($find("cal_EndDate") )
    {
        $find("cal_EndDate").set_selectedDate(sender.get_selectedDate());
    }
 }

function SetEndDateMin_E()
{
   
    if (document.getElementById("ctl00_ContentPlaceHolder1_edt_StartDate") != null && document.getElementById("ctl00_ContentPlaceHolder1_edt_EndDate") != null)
    {
        if (document.getElementById("ctl00_ContentPlaceHolder1_edt_StartDate").value != "")
        {
            if (isDate(document.getElementById("ctl00_ContentPlaceHolder1_edt_StartDate").value) )
            {
               document.getElementById("ctl00_ContentPlaceHolder1_edt_EndDate").value = document.getElementById("ctl00_ContentPlaceHolder1_edt_StartDate").value;
               $find("cal_EndDate").set_selectedDate(document.getElementById("ctl00_ContentPlaceHolder1_edt_StartDate").value);
               document.getElementById("ctl00_hf_ErrorMessage").value ="";
               dismissboxv2();
            }
        }
         
    }
}

// Declaring valid date character, minimum year and maximum year
var dtCh= "/";
var minYear=1900;
var maxYear=2100;

function isInteger(s){
 var i;
    for (i = 0; i < s.length; i++){  
        // Check that current character is number.
        var c = s.charAt(i);
        if (((c < "0") || (c > "9"))) return false;
    }
    // All characters are numbers.
    return true;
}

function stripCharsInBag(s, bag){
 var i;
    var returnString = "";
    // Search through string’s characters one by one.
    // If character is not in bag, append to returnString.
    for (i = 0; i < s.length; i++){  
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }
    return returnString;
}

function daysInFebruary (year){
 // February has 29 days in any year evenly divisible by four,
    // EXCEPT for centurial years which are not also divisible by 400.
    return (((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0))) ? 29 : 28 );
}

function DaysArray(n) {
 for (var i = 1; i <= n; i++) {
  this[i] = 31
  if (i==4 || i==6 || i==9 || i==11) {this[i] = 30}
  if (i==2) {this[i] = 29}
   }
   return this
}

function isDate(dtStr){
 var daysInMonth = DaysArray(12)
 var pos1=dtStr.indexOf(dtCh)
 var pos2=dtStr.indexOf(dtCh,pos1+1)
 var strMonth=dtStr.substring(0,pos1)
 var strDay=dtStr.substring(pos1+1,pos2)
 var strYear=dtStr.substring(pos2+1)
 strYr=strYear
 if (strDay.charAt(0)=="0" && strDay.length>1) strDay=strDay.substring(1)
 if (strMonth.charAt(0)=="0" && strMonth.length>1) strMonth=strMonth.substring(1)
 for (var i = 1; i <= 3; i++) {
  if (strYr.charAt(0)=="0" && strYr.length>1) strYr=strYr.substring(1)
 }
 month=parseInt(strMonth)
 day=parseInt(strDay)
 year=parseInt(strYr)
 if (pos1==-1 || pos2==-1){
    document.getElementById("ctl00_hf_ErrorMessage").value = 'The date format should be : mm/dd/yyyy';
    CheckErrors(true);
  
  return false
 }
 if (strMonth.length<1 || month<1 || month>12){
    document.getElementById("ctl00_hf_ErrorMessage").value = 'Please enter a valid month';
    CheckErrors(true);
    return false
 }
 if (strDay.length<1 || day<1 || day>31 || (month==2 && day>daysInFebruary(year)) || day > daysInMonth[month]){
   document.getElementById("ctl00_hf_ErrorMessage").value = 'Please enter a valid day';
   CheckErrors(true);
  
  return false
 }
 if (strYear.length != 4 || year==0 || year<minYear || year>maxYear){
   document.getElementById("ctl00_hf_ErrorMessage").value = "Please enter a valid 4 digit year between "+minYear+" and "+maxYear;
   CheckErrors(true);
   return false
 }
 if (dtStr.indexOf(dtCh,pos2+1)!=-1 || isInteger(stripCharsInBag(dtStr, dtCh))==false){
    document.getElementById("ctl00_hf_ErrorMessage").value = "Please enter a valid date";
   CheckErrors(true);
   return false
 }
return true
}