//12.04.06
var mDomain = getDomain(2);
var mDomainCall = mDomain.split('.');
var mCompany = "";

if (mDomainCall[0].indexOf("img") > 0) {
	mCompany = mDomainCall[0].slice(0,(mDomainCall[0].length-3));
}else{
	mCompany = mDomainCall[0];
}
mDomain = "xetv.dayport.com"
mCompany = "xetv";
var SiteName = "video.fox6.com";

// LaunchSyndicateArticle is the function to launch the video viewer. It takes 2 arguments:
// The first argument, ArtId, is a comma separated list of article id's
//	This argument is required
// The second argument, template, is the name of the video viewer template to use
//	This argument is optional. If not passed in, the default video viewer template will be used
// Both arguments should be passed into the function as strings

// For example, LaunchSyndicateArticle('3142','newviewer.tpl')
// would launch article #3142 in the newviewer.tpl template

// Another example, LaunchSyndicateArticle('3142,5612,1123');
// would launch a playlist of all 3 articles in the default video viewer template 

function LaunchSyndicateArticle(ArtId,template,CustId,ContId,CatID)
{
  var SiteRegExp = new RegExp('@' + SiteName.replace(/\//g,"\\/"),"gi");
  var ArtString=ArtId.toString().replace(SiteRegExp,"");
  var TemplateFile="";
  var Customer_ID="";
  var Contract_ID="";
  var Category_ID="";
  var ParentFile="";
  var kWidth = 0;
  var kHeight = 0;
  var winName = "XETVViewer";
  var page;
  if ((template != '') && (typeof template != "undefined"))
  {
     TemplateFile = '&tf='+template;
     switch (template)
     {
        case "weatherviewer.tpl":
          ParentFile = "";
          kWidth = 664;
          kHeight = 395;
          winName = "XETVWeatherViewer";
          break;
     }
  }
  
  if ((CustId != '') && (typeof CustId != "undefined"))
  {
    if (CustId.charAt(0) == "-")
      Customer_ID = '&ExCust='+CustId.slice(1);
    else      
      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_DefID='+ContId;


// Make height taller for banner ad
kWidth = 664;
kHeight = 475;

// If FOXROX then make height shorter, no banner ad
if (CatID == '223') {
kWidth = 664;
kHeight = 395;
}

  if ((CatID != '') && (typeof CatID != "undefined"))
      Category_ID = '&Category_ID='+CatID;
  else      
      Category_ID = '&Category_ID=5';

// If Top Videos then make height taller for banner ad
if (Category_ID == "&Category_ID=5") {
kWidth = 664;
kHeight = 475;
}

/* Hardcoded for Auto Finance Pros tied with AutoSpies
  if ((CatID == '179') && (typeof CatID != "undefined"))
      Contract_ID = '&Contract_DefID=4';
*/

// dental health, no preload ad
  if ((CatID == '163') && (typeof CatID != "undefined"))
    Contract_ID = '&NoAds=true';
//      Contract_ID = '&Contract_DefID=4';


  if ((CatID == '1644') && (typeof CatID != "undefined"))
    Contract_ID = '&NoAds=true';
/*      Contract_ID = '&Contract_DefID=4'; */

  if (ParentFile == "")
    page = "http://video.fox6.com/viewer/viewerpage.php?Art_ID=" + ArtString + TemplateFile + Customer_ID + Contract_ID + Category_ID;
  else
    page = "http://cdn.dayport.com/xetvimg/htm/"+ParentFile+"?Art_ID=" + ArtString + TemplateFile + Customer_ID + Contract_ID + Category_ID;

  if (kWidth == 0)
    kWidth = 664;  
  
  if (kHeight == 0) 
    kHeight = 395;

  var xPosition = screen.width/2-(kWidth/2);
  var yPosition = screen.height/2-(kHeight/2);
  var Params = "height=" + kHeight + ",width=" + kWidth + ",left=" + xPosition + ",top=" + yPosition + ",screenX=" + xPosition + ",screenY=" + yPosition;
//alert(Params);
  //window.scrollTo(0,0);
  var kWin=window.open(page,winName,Params); 
  kWin.opener = self;
  kWin.focus();
  //kWin.moveTo(xPosition, yPosition);  
  return true;
}

// BuildSyndicatePlaylist is the function to parse HTML forms and build the comma separated
// list of articles that can be passed into LaunchSyndicateArticle. It takes 1 argument:
// The fist argument, template, is the name of the video viewer template to use
//      This argument will be passed directly into LaunchSyndicateArticle
//	This argument is optional. If not passed in, the default video viewer template will be used

// BuildSyndicatePlaylist will parse the HTML on a page for all forms whose name attribute
// begins with the string 'ArticleList' (ie <form name="ArticleList_TopStories">).
// Within a matching FORM, the function will look for an array of checkboxes named V1.
// The value of a given checkbox should be the ID of the particular article.
// BuildSyndicatePlaylist will build a comma separated list of the values of all these checkboxes
// and pass that comma separated list into LaunchSyndicateArticle.
// If no matching forms or checkboxes are found, or if no boxes were checked,
// The function returns a message telling the user "You must select a story to add to your playlist!"

// Example HTML Form
// <form name="ArticleList_TopStories">
// <input type="button" onclick="BuildSyndicatePlaylist();" value="Launch Your Playlist"><br>
// <a href="/" onClick="LaunchSyndicateArticle('23'); return false;">Watch Story #23</a> 
// <input type="checkbox" name="V1" value="23">Add To Playlist<br>
// <a href="/" onClick="LaunchSyndicateArticle('29'); return false;">Watch Story #29</a> 
// <input type="checkbox" name="V1" value="29">Add To Playlist<br>
// <a href="/" onClick="LaunchSyndicateArticle('35'); return false;">Watch Story #35</a> 
// <input type="checkbox" name="V1" value="35">Add To Playlist<br>
// </form>

function BuildSyndicatePlaylist(template)
{
    var ArtString="";
    var ArtArray = new Array();
    var TemplateFile="";

    for (var j=0; j<document.forms.length; j++)
    {
        if (document.forms[j].name.substr(0,11) == 'ArticleList')
        {
            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
                {
                    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);
}


// getURLVar is a utility function for parsing the URL to return the value of a
// particular URL variable. It takes 1 argument:
// The first argument, v, is the name of the URL variable whose value to return

// For example, suppose the URL is this: http://www.dayport.com/?page=home&cat=33
// getURLVar('page') would return 'home' and getURLVar('cat') would return '33'

function getURLVar(v)
{
    // strip off the URL parameters
    var url_params = window.location.search.substr(1);

    var retn = '';
    if (url_params != '')
    {
        var url_param_array = url_params.split('&');
        var url_param_count = url_param_array.length;
        var temp;

        for(var count = 0; count < url_param_count; count++)
        {
            temp = url_param_array[count].split('=');
            if (temp[0] == v)
                retn = temp[1];
        }
    }
    return retn;
}


// moreLink is a function used by JavaScript syndication using DayPort-AL templates

function moreLink(catid)
{
    // strip off the URL parameters
    var url_params = window.location.search.substr(1);

    var next = "";
    var cat = "";
    if (url_params != '')
    {
        //alert(url_params);
        var url_param_array = url_params.split('&');
        var url_param_count = url_param_array.length;
        var temp;

        for(var 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;
}
  
function changeMenu(strMenu) {
	
    var strArray = strMenu.split(',');        
    CatID = strArray[0];       
    DomID = strArray[1];
  	<!-- alert("What is CatID? "+CatID); -->		

       if ((CatID == '69'))
       {
//        loc = "http://"+DomID+".dayport.com/article/category/"+CatID+"/?&tf=subcat2test.tpl";
        loc = "http://"+DomID+".dayport.com/article/category/"+CatID+"/?&tf=subrightmenu.tpl";
       } 
       else 
       {
       loc = "http://"+DomID+".dayport.com/article/archive/"+CatID+"/?Category_ID="+CatID+"&Limit=8&Offset=0&nc=1&tf=rightmenu.tpl";
         <!--http://video.fox6.com/nw/article/archive/'+CatID+'?Limit=6&tf=rightmenu.tpl" -->
        }

    window.location.href=loc;
    }

    <!-- window.location.href='http://video.fox6.com/article/archive/"+CatID+"/?Category_ID="+CatID+"&Limit=50&Offset=0&nc=1&tf=rightmenu.tpl'; -->
   
function video_search(srchtxt) {
	if (srchtxt == "") {
    	alert("You must enter a keyword in order to search.");		
		document.forms[1].SearchText.focus();
	} else {
		window.location.href='http://video.fox6.com/nw/article/search/?SearchText=' + srchtxt + '&tf=search_video.tpl';
	}
}

function video_search_home(srchtxt,width,height) {
if (width == "") width = "486";
if (height == "") height = "300";
	if (srchtxt == "") {
    	alert("You must enter a keyword in order to search.");		
		document.forms[1].SearchText.focus();
	} else {
		//window.location.href='http://video.fox6.com/nw/article/search/?SearchText=' + srchtxt + '&tf=search_video.tpl';
//window.location.href='search.aspx?find=' + srchtxt + '';
document.getElementById("searchtop").style.display = 'block';
document.getElementById("vidsearch").style.display = 'block';
document.getElementById("searchbottom").style.display = 'block';
//document.getElementById("searchdisplay").innerHTML = 'You searched for <b>' + srchtxt + '</b>.';
//document.getElementById("searchdisplay").innerHTML = 'Your search for <b>' + srchtxt + '</b> found {hit_count} video(s).';

document.getElementById("vidsearch").innerHTML = '<iframe name=vidsearchresults id=vidsearchresults src="http://video.fox6.com/nw/article/search/?SearchText=' + srchtxt + '&tf=image_tease_results.tpl&Limit=200" width=' + width + ' height=' + height + ' marginwidth=0 marginheight=0 frameborder=no></iframe>';
	}
}

var NS = (window.Event) ? 1 : 0;

// *** if enter key is hit instead of clicking button
function checkKey(e) {  
	var code = (NS) ? e.which : event.keyCode;
	if (code == 13)	{
//		video_search(document.forms[1].SearchText.value);
		return false;
	}
}
if (NS) document.captureEvents(Event.KEYPRESS)
	document.onkeypress = checkKey;
	
function getDomain(v)
{
	var strWin = window.location.href
	var winArray = strWin.split('/'); 

    var retn = winArray[v];
    return retn;
}


function checkHandler(checkbox_name, action) 
{
    if (action == "check") 
    {
            for (var i = 0; i < checkbox_name.length; i++) 
            {
                        checkbox_name[i].checked = true;
            }
    }
else if (action == "uncheck")
    {
            for (var i = 0; i < checkbox_name.length; i++) 
            {
                        checkbox_name[i].checked = false; 
            }
    }
else if (action == "toggle")
    {
            for (var i = 0; i < checkbox_name.length; i++) 
            {
                        if (checkbox_name[i].checked)
                                    checkbox_name[i].checked = false; 
                        else
                                    checkbox_name[i].checked = true; 
            }
    }
}
