var old,skn,iex=(document.all);

var ns4=document.layers;
var ns6=document.getElementById&&!document.all;
var ie4=document.all;
var x,y,image_left,image_top,msg;
document.onmousemove = mouseMoveHandler;

function dekInit()
{
  var ns4=document.layers;
  if (ns4)
    skn=document.dek;
  else if (ns6)
    skn=document.getElementById("dek").style;
  else if (ie4)
    skn=document.all.dek.style;
  if(ns4)
    document.captureEvents(Event.MOUSEMOVE);
  else
  {
    skn.visibility="visible";
    skn.display="none";
  }
}

function mouseMoveHandler (evt) {
    x=(ns4||ns6)?evt.pageX:event.x+document.body.scrollLeft;
    y=(ns4||ns6)?evt.pageY:event.y+document.body.scrollTop;
}

function killPopup(){
    if(ns4){
        skn.visibility="hidden";
    }
    else if (ns6||ie4)
        skn.display="none";
}

function popup(msg,id){
    // Pre-load the popup image
    popupimg = new Image();
    popupimg.src=msg;

    msg = "<IMG SRC='" + msg + "'>";
    image_object = 'preview_' + id;

    var content="<TABLE CELLPADDING=0 CELLSPACING=0><TD ALIGN=center>"+msg+"</TD></TABLE>";

    // Display popup according to where the original image lives
    if (ns4) {
        element = eval('document.' + image_object);

        // First handle the vertical placement
        pageheight = top.document.height;

        image_top = element.y;

        if (pageheight > (image_top + element.height + popupimg.height + 2))
            image_top += element.height + 2;  // Added the + 2 to make images line up better
        else
            image_top = image_top - popupimg.height - 2; // Place the popup image above the other image


        // Now handle horizontal placement
        pagewidth = top.document.width

        image_left = element.x; // - 2;  // Add the - 2 to make the images line up better

        if (pagewidth < (image_left + popupimg.width))
            image_left = image_left - (popupimg.width - element.width) // Pin to bottom-right corner
        else
            image_left = image_left - 2; // Pin to bottom-left corner, add the - 2 to make the images line up better
    }
    else {
        // First handle the vertical placement
        pageheight = document.body.scrollHeight;

        image_top = document.getElementById(image_object).offsetTop;
        tempEl1 = document.getElementById(image_object).offsetParent;
        while (tempEl1 != null) {
  	        image_top += tempEl1.offsetTop;
  	        tempEl1 = tempEl1.offsetParent;
        }

        // Check if there's room to put it underneath
        if (pageheight > (image_top + document.getElementById(image_object).height + popupimg.height + 4))
            image_top += document.getElementById(image_object).height + 4;
        else
            image_top = image_top - popupimg.height - 2; // place the popup image above the other image


        // Now handle horizontal placement
        pagewidth = document.body.scrollWidth;

        image_left = document.getElementById(image_object).offsetLeft;
        tempEl2 = document.getElementById(image_object).offsetParent;
        while (tempEl2 != null) {
  	        image_left += tempEl2.offsetLeft;
  	        tempEl2 = tempEl2.offsetParent;
        }

        if (pagewidth < (image_left + popupimg.width))
            image_left = image_left - (popupimg.width - document.getElementById(image_object).width); // Pin to bottom-right corner
        else
            image_left += 0; // Pin to bottom-left corner
    }
    skn.top = image_top;
    skn.left= image_left;

    if(ns4){
        skn.document.write(content);
        skn.document.close();
        skn.visibility="visible";
    }
    if(ns6){
        document.getElementById("dek").innerHTML=content;
        skn.display='';
    }
    if(ie4){
        document.all("dek").innerHTML=content;
        skn.display='';
    }
}

function checkLaunch()
{
    // strip off the URL parameters
    var url_params = window.location.search.substr(1);
    var custID = "";
    var contID = "";
    var catID = "";
    var template = "";
    var pageforward = "";
    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] == 'tf')
                template = temp[1];
            else if (temp[0] == 'Category_ID')
              catID = temp[1];
            else if (temp[0] == 'url')
                pageforward = temp[1];
            else if (temp[0] == 'Customer_ID')
              custID = temp[1];
            else if (temp[0] == 'Contract_ID')
              contID = temp[1];

        }
    }

    //alert(window.location.href);
    var url_regex = window.location.href.replace(/http:\/\//g,"");
    //alert(url_regex);
    var url_array = url_regex.split("/");
var disable_ad = url_array[3];
if (disable_ad =='0')
{
alert('this is a test');
}
    if (url_array[1])
    {
        if (url_array[2])
        {
            if((url_array[1]=='launcher') && (url_array[2]!=''))
            {
                //alert('calling LaunchArticle with '+url_array[2]);
                LaunchSyndicateArticle(url_array[2],template,custID,contID,catID);
                if (pageforward == "")
                   loc = 'http://www.fox6.com/';
                else
                   loc = 'http://' + pageforward + '/';
                window.location=loc;
            }
        }
    }
}

function BuildVideoLink(type,hasvideo,article,articlename)
{
    // If this article does not have video, stop right now
    if (hasvideo == 'false')
        return true;

    // Setup the values to be used in the strings
    var LinkText = 'View Video of the ' + articlename + ' story';
    var VideoImage = 'http://videoimg.whptv.com/img/video1.gif';
    var VideoText = 'Watch video';

    switch(type)
    {
        case "image":
            var LinkValue = '<img src="' +VideoImage+ '" border="0" alt="'+LinkText+'">';
        break;

        case "text":
            var LinkValue = VideoText;
        break;

        case "combo":
            var LinkValue = VideoText + '</a>&nbsp;<a href="/" onclick="LaunchArticle('+article+'); return false;" title="'+LinkText+'" class="DayPortVideoLink"><img src="' +VideoImage+ '" border="0" alt="'+LinkText+'">';
        break;

        default:
            return false;
        break;
    }
    document.write('&nbsp;<a href="/" onclick="LaunchArticle('+article+'); return false;" title="'+LinkText+'" class="DayPortVideoLink">');
    document.write(LinkValue);
    document.write('</a>');         
    return true;
}

function FormattedDate(created_def)
{
      created_arr2 = created_def.split(" ");
      created_arr = created_arr2[0].split("-");
      montharg = created_arr[0] - 1;
      created = new Date(created_arr[2], montharg, created_arr[1]);
      switch(created.getDay())
      {
        case 0:
          day = "Sunday";
        break;
        case 1:
          day = "Monday";
        break;
        case 2:
          day = "Tuesday";
        break;
        case 3:
          day = "Wednesday";
        break;
        case 4:
          day = "Thursday";
        break;
        case 5:
          day = "Friday";
        break;
        case 6:
          day = "Saturday";
        break;
      }
      document.write("<font class=\"PublishDate\">" + day + ", " + created_arr[0] + "/" + created_arr[1] + "/" + created_arr[2] + "</font>");
	return true;
}

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;
}

function rtnElem(elemName, addStyle, isParent, parentID)
{
  //alert("in rtnElem()");
  var elemObj;
  var styleStr = '';

  if (addStyle)
    styleStr = '.style';

  if (ie4)
    elemObj = eval('document.all.' + elemName + styleStr);
  else if (ns6)
    elemObj = eval('document.getElementById("' + elemName + '")' + styleStr);
  else if (ns4)
  {
    if (isParent)
      elemObj = eval('document.' + elemName);
    else
      elemObj = eval('document.' + parentID + '.document.' + elemName);
  }

  return elemObj;
}

function changeDivPosition(divID,newleft,newtop)
{  
  var tempElemObj = rtnElem(divID, true, true);
  if (tempElemObj)
  {
    //alert("Yep");
    var newContent = "";
    tempElemObj.left = newleft;
    tempElemObj.top = newtop;

    return true;
  }
  else
  {
    //alert("Nope");
    return false;
  }
}
