function handle_cached_embed_user() {
    var login_cookie = readCookie('ss_embed_login');
    var logged_in = document.getElementById('embed_logged_in');
    var logged_out = document.getElementById('embed_logged_out');
    if(login_cookie == null) {
      logged_in.style.display = 'none';
      logged_out.style.display = 'block';
    } else {
      var login_link = document.getElementById('login_link');
      if (login_link) {
         login_link.href = '/users/' + login_cookie;
      }
      else {
         login_link.href = login_link.href + login_cookie;
      }
      logged_out.style.display = 'none';
      logged_in.style.display = 'block';
    }
}

function showspinner(el) {
  el.style.display = 'none';
  el2 = document.getElementById(el.id + '-spinner');
  if (el2) { el2.style.display = 'inline'; }
}

function OnCalendarUpdate(objDate) { window.open("/collegebasketball/game_list?date=" + objDate.getPHPDate('Y-n-j'),"_top"); }
function OnCalendarUpdateNascar(objDate) { window.open("/nascar/race_list?" + objDate.getPHPDate('Y-n-j'),"_top"); }
function OnCalendarUpdateNfl(objDate) { window.open("/nfl/game_list?date=" + objDate.getPHPDate('Y-n-j'),"_top"); }
function OnCalendarUpdateNba(objDate) { window.open("/nba/game_list?date=" + objDate.getPHPDate('Y-n-j'),"_top"); }
function OnCalendarUpdateCfb(objDate) { window.open("/collegefootball/game_list?date=" + objDate.getPHPDate('Y-n-j'),"_top"); }

var NS4 = (navigator.appName == "Netscape" && parseInt(navigator.appVersion) < 5);

function selectAllOptions(selStr) {
  var selObj = document.getElementById(selStr);
  for (var i=0; i<selObj.options.length; i++) {
    selObj.options[i].selected = true;
  }
}

function addOption(theSel, theText, theValue) {
  var newOpt = new Option(theText, theValue);
  var selLength = theSel.length;
  theSel.options[selLength] = newOpt;
}

function deleteOption(theSel, theIndex) { 
  var selLength = theSel.length;
  if(selLength>0)
  {
    theSel.options[theIndex] = null;
  }
}

function moveOptions(theSelFrom, theSelTo) {
  var selLength = theSelFrom.length;
  var selectedText = new Array();
  var selectedValues = new Array();
  var selectedCount = 0;
  
  var i;
  
  // Find the selected Options in reverse order
  // and delete them from the 'from' Select.
  for(i=selLength-1; i>=0; i--)
  {
    if(theSelFrom.options[i].selected)
    {
      selectedText[selectedCount] = theSelFrom.options[i].text;
      selectedValues[selectedCount] = theSelFrom.options[i].value;
      deleteOption(theSelFrom, i);
      selectedCount++;
    }
  }
  
  // Add the selected text/values in reverse order.
  // This will add the Options to the 'to' Select
  // in the same order as they were in the 'from' Select.
  for(i=selectedCount-1; i>=0; i--)
  {
    addOption(theSelTo, selectedText[i], selectedValues[i]);
  }
  
  if(NS4) history.go(0);
}

var iframeids=["iframeid"]

//Should script hide iframe from browsers that don't support this script (non IE5+/NS6+ browsers. Recommended):
var iframehide="no"

var getFFVersion=navigator.userAgent.substring(navigator.userAgent.indexOf("Firefox")).split("/")[1]
var FFextraHeight=parseFloat(getFFVersion)>=0.1? 16 : 0 //extra height in px to add to iframe in FireFox 1.0+ browsers

function resizeCaller() {
var dyniframe=new Array()
for (i=0; i<iframeids.length; i++){
if (document.getElementById)
resizeIframe(iframeids[i])
//reveal iframe for lower end browsers? (see var above):
if ((document.all || document.getElementById) && iframehide=="no"){
var tempobj=document.all? document.all[iframeids[i]] : document.getElementById(iframeids[i]);
if (! tempobj) {
break;
}
tempobj.style.display="block";
} } }

function resizeIframe(frameid){
var currentfr=document.getElementById(frameid)
if (currentfr && !window.opera) {
  currentfr.style.display="block"
  if (currentfr.contentDocument && currentfr.contentDocument.body.offsetHeight) {//ns6 syntax
    currentfr.height = currentfr.contentDocument.body.offsetHeight+FFextraHeight + "px";
    // currentfr.width = (currentfr.contentDocument.body.offsetWidth + 200) + "px";
  } else if (currentfr.Document && currentfr.Document.body.scrollHeight) {//ie5+ syntax
    currentfr.height = currentfr.Document.body.scrollHeight + "px";
    // currentfr.width = (currentfr.Document.body.scrollWidth + 200) + "px";
  }
  if (currentfr.addEventListener) {
    currentfr.addEventListener("load", readjustIframe, false)
  } else if (currentfr.attachEvent){
    currentfr.detachEvent("onload", readjustIframe) // Bug fix line
    currentfr.attachEvent("onload", readjustIframe)
  }
} }

function readjustIframe(loadevt) {
var crossevt=(window.event)? event : loadevt
var iframeroot=(crossevt.currentTarget)? crossevt.currentTarget : crossevt.srcElement
if (iframeroot) { resizeIframe(iframeroot.id); }
}

function loadintoIframe(iframeid, url){ if (document.getElementById) { document.getElementById(iframeid).src=url; } }

if (window.addEventListener) { window.addEventListener("load", resizeCaller, false); }
else if (window.attachEvent) {window.attachEvent("onload", resizeCaller); }
else { window.onload=resizeCaller }

function ClearOptions(OptionList) { for (x = OptionList.length; x >= 0; x = x - 1) { OptionList[x] = null; } }
function AddToOptionList(OptionList, OptionValue, OptionText) { OptionList[OptionList.length] = new Option(OptionText, OptionValue); }

function afterEmbedRemove(element,hidid) {
   var form = document.forms['embedform'];
   if (form) {
      var hid = document.getElementById(hidid);
      if (hid) { form.removeChild(hid); }
      var hidinput = document.getElementById(hidid);
      if (hidinput) { hidinput.style.display="block"; }
   }
   element.parentNode.style.display = 'none';
   var hido = document.getElementById(hidid + '_search');
   if (hido) {hido.style.display = 'inline';}
}

function afterEmbedSearch(element,selectedElement){
 if (document.getElementById) {
    var hid;
    var form = document.forms['embedform'];
    if (form) {
       var num = element.id.replace(/item|_search/g,"");
       var hid = document.getElementById('item' + num);
       if (hid) {
          hid.value = selectedElement.id;
       } else {
          hid = document.createElement("input");
          hid.type ="hidden";
          hid.name = "item" + num
          hid.id = hid.name
          hid.value = selectedElement.id;
          form.appendChild(hid);
       }

       var hido = document.getElementById( element.id );
       if (hido) {hido.style.display = 'none';}

       var ei = document.getElementById('embeditem' + num);
       if (ei && hid) {
         ei.style.display = 'block';
         ei.innerHTML = "<b> " + selectedElement.innerHTML + "</b> <a onclick='afterEmbedRemove(this,\"" + hid.id + "\");' href='javascript:void(0);'><img src='/images/cross.png' height='13' width='13' border='0' /></a>";
       }

       element.value='Type another name';
       element.blur();
    }
 }
}

