var SiteName = "wcbs.dayport.com";
var VLNFlag = 0;
var VLNParent = "";

function LaunchSyndicateArticle(ArtId,template,CustId,ContId,CatID)
{
  var SiteRegExp = new RegExp('@' + SiteName.replace(/\//g,"\\/"),"gi");
  var ArtString=unescape(ArtId.toString().replace(SiteRegExp,""));
  var TemplateFile="";
  var Customer_ID="";
  var Contract_ID="";
  var Category_ID="";
  var DomID="";
  // Default is now the chtopsviewer.tpl template that does not use ParentFile
  // So we do not want a default ParentFile anymore
  //var ParentFile="cbs2player.htm";
  var ParentFile="";
  var page;


  TemplateFile = '&tf=video_player.tpl';  
  DomID = "wcbs";
  kWidth = 764;
  kHeight = 414;
  var winName = "VideoViewer"; 

  if ((CustId != '') && (typeof CustId != "undefined"))
    Customer_ID = '&Customer_ID='+CustId;
  
if ((ContId != '') && (typeof ContId != "undefined") && (ContId == "0"))
    Contract_ID = '&NoAds=true';
  else if ((ContId != '') && (typeof ContId != "undefined")) 
    Contract_ID = '&Contract_ID='+ContId;
  

  if (VLNParent != '') {
	switch (VLNParent) {      
   		case "hdtvviewer":
			CatID = "15";
			DomID = "vln";
		break;      
   		case "winetvviewer.htm":
			CatID = "13";
			DomID = "vln";
		break;     
	}
  }
  
if ((CatID == '') || (typeof CatID == "undefined")) {
	if ((template != '') && (typeof template != "undefined"))   {
		switch (template) {      
   			case "chentviewer.tpl":
				CatID = "51";
				DomID = "wcbs";
			break;     
   			case "chhealthviewer.tpl":
				CatID = "49";
				DomID = "wcbs";
			break;     
   			case "chsprepviewer.tpl":
				CatID = "50";
				DomID = "wcbs";
			break;     
   			case "chsunedviewer.tpl":
				CatID = "82";
				DomID = "wcbs";
			break;     
   			case "chtonyviewer.tpl":
				CatID = "52";
				DomID = "wcbs";
			break;     
   			case "chtopsviewer.tpl":
				CatID = "48";
				DomID = "wcbs";
			break;     
   			case "chhnviewer.tpl":
				CatID = "88";
				DomID = "wcbs";
			break;     
   			case "chmettvviewer.tpl":
				CatID = "85";
				DomID = "wcbs";
			break;
		}
  	}else{
		CatID = "48";
		DomID = "wcbs";
	}
}
  
if ((CatID != '') && (typeof CatID != "undefined")) {
	switch(CatID) {
		case "13":
			URLstring = "&PreloadContract_DefID=5&Contract_DefID=6";
			break;		
		case "15":
			URLstring = "&PreloadContract_DefID=7&Contract_DefID=8";
			break;
		case "81":
			URLstring = "&PreloadContract_DefID=7&Contract_DefID=8";
			break;			
		case "88":
			URLstring = "&ExCust=6";
			break;			
		case "53":
			URLstring = "&Contract_DefID=11";
			break;
		case "0":
			URLstring = "&PreloadContract_DefID=9&Contract_DefID=10";
			break;
	
		default:
			URLstring = "";
	} 

} else {
	
	URLstring = "";
}
  
    Category_ID = '&Category_ID='+CatID;

    page = "http://" + DomID + ".dayport.com/viewer/viewerpage.php?Art_ID=" + ArtString + TemplateFile + Customer_ID + Contract_ID+ Category_ID + URLstring;

  var xPosition = 50;
  var yPosition = 50;
  var Params = "height=" + kHeight + ",width=" + kWidth + ",left=" + xPosition + ",top=" + yPosition + ",screenX=" + xPosition + ",screenY=" + yPosition;
  //window.scrollTo(0,0);
  var kWin=window.open(page,winName,Params); 
  kWin.opener = self;
  kWin.focus();
  //kWin.moveTo(xPosition, yPosition);  
  return true;
}

function LaunchVLNArticle(ArtId,template,CustId,ContId,Parent)
{
  VLNFlag = 1;
  if ((Parent!= '') && (typeof Parent != "undefined")) 
    VLNParent = Parent;
  LaunchSyndicateArticle(ArtId,template,CustId,ContId);
  VLNFlag = 0;
}

function BuildSyndicatePlaylist(template,CustId,ContId)
{
    var ArtString="";
    var ArtArray = new Array();
    var TemplateFile="";

    //alert(document.forms.length);
    for (var j=0; j<document.forms.length; j++)
    {
        //alert(document.forms[j].name);
        //alert(document.forms[j].name.substr(0,11));
        if (document.forms[j].name.substr(0,11) == 'ArticleList')
        {
            //alert('found a match '+document.forms[j].name)
            FORM = eval('document.'+document.forms[j].name);
            if (FORM.V1)
            {
                if ((!FORM.V1.length) && (FORM.V1.checked == true))
                { 
                    // When only one checkbox exists in form and it is checked
                    v = parseInt(FORM.V1.value);
                    if((!ArtArray[v]) || (ArtArray[v] != 1))
                    {
                        ArtArray[v] = 1;
                        if (ArtString=="")
                            ArtString=ArtString + FORM.V1.value;
                        else
                            ArtString=ArtString + "," + FORM.V1.value;
                    }
                }
                else
                {
                    //alert(FORM.V1.length);
                    for (i=0;i<FORM.V1.length;i++)
                    {
                        if (FORM.V1[i].checked==true)
                        {
                            v = parseInt(FORM.V1[i].value);
                            if((!ArtArray[v]) || (ArtArray[v] != 1))
                            {
                                ArtArray[v] = 1;
                                if (ArtString=="")
                                    ArtString=ArtString + FORM.V1[i].value;
                                else
	                            ArtString=ArtString + ","  + FORM.V1[i].value;
                            }
                        }
                    }
                }
            }
        }
    }

    if (ArtString=="")
    	alert("You must select a story to add to your playlist!");
    else
    	LaunchSyndicateArticle(ArtString,template,CustId,ContId);
}

function getURLVar(v)
{
    // strip off the URL parameters
    url_params = window.location.search.substr(1);

    var retn = '';
    if (url_params != '')
    {
        url_param_array = url_params.split('&');
        url_param_count = url_param_array.length;

        for(count = 0; count < url_param_count; count++)
        {
            temp = url_param_array[count].split('=');
            if (temp[0] == v)
                retn = temp[1];
        }
    }
    return retn;
}


function moreLink(catid)
{
    // strip off the URL parameters
    url_params = window.location.search.substr(1);

    var next = "";
    var cat = "";
    if (url_params != '')
    {
        //alert(url_params);
        url_param_array = url_params.split('&');
        url_param_count = url_param_array.length;

        for(count = 0; count < url_param_count; count++)
        {
            //alert(url_param_array[count]);
            temp = url_param_array[count].split('=');
            //alert(temp[0]); alert(temp[1]);
            if (temp[0] == 'next')
                next = temp[1];
            else if (temp[0] == 'prev')
                prev = temp[1];
            else if (temp[0] == 'cat')
                cat = temp[1];
        }
    }
    if (catid == cat)
        return next;
    else
        return 0;
}