/* text field functions */
var currentTextInputValue; // used to track value of text input fields

function clearTextBox(){
  currentTextInputValue=this.value;
  this.value='';
}

function checkTextBox(){
  var blanks=/^\s*$/;
  if(blanks.test(this.value)){
    this.value=currentTextInputValue;
  }
}







/* rainbow nav functions */
// the server side script will set a variable called "pagename" to the name of the current page
var pagename = '';
function rainbowNavMouseOver(which){
  var rainbowNav=document.getElementById("rainbowNav");
  if(rainbowNav!=null){
    rainbowNav.className=which;
  }
  return false;
}

function rainbowNavMouseOut(){
  var rainbowNav=document.getElementById("rainbowNav");
  if(rainbowNav!=null){
    rainbowNav.className=pagename;
  }
  return false;
}

function setRoleIndicator(){
  if(pagename=="home") return false;
  var selectedRole=document.getElementById(pagename);
  if(selectedRole!=null){
    selectedRole.className="selected";
  }
}

/* Window initialization */
$(document).ready(function(){ 
  
  // Set handlers to clear search box on focus
  // and restore on blur
  $("#query").focus(function() { $(this).val(""); });
  $("#query").blur(function() { $(this).val($(this).attr('default')); });

  rainbowNavMouseOver(pagename);
  setRoleIndicator();
});

/* encapsulate language code change behavior here */
jQuery.fn.updateLocale = function(){
	/* PLACEHOLDER CODE! */
	var l = $(this).attr("id");
	//alert("Placeholder Code: switched to '" + l + "'");
	
	
	setLocale(l);
	
	
	/* 1. update session across all subdomains */
	/* 2. refresh page content in selected language (can this be a simple page refresh?) */
}

function viewlets(type,lang,url){
      if (type=='2002'){
            window.open('/media/viewlets/english/'+url,'viewlet','width=699,height=570,status=0,menubar=0,scrollbars=0,toolbar=0');opener.focus();
      } else if(type=='X5'){
            window.open('/media/tutorials/english/flash/'+url,'viewlet','width=788,height=564,status=0,menubar=0,scrollbars=0,toolbar=0');opener.focus();
      } else if(type=='6'){
            window.open('/media/tutorials/'+lang+'/flash/'+url,'viewlet','width=792,height=568,status=0,menubar=0,scrollbars=0,toolbar=0');opener.focus();
      } else if(type=='7'){
            window.open('/media/tutorials/'+lang+'/flash/'+url,'viewlet','width=1100,height=700,status=0,menubar=0,scrollbars=0,toolbar=0');opener.focus();
      }
}


function popVideo(type,lang,url){
      if (type=='2002'){
            window.open('/media/viewlets/english/'+url,'viewlet','width=699,height=570,status=0,menubar=0,scrollbars=0,toolbar=0');opener.focus();
      } else if(type=='X5'){
            window.open('/media/tutorials/english/flash/'+url,'viewlet','width=788,height=564,status=0,menubar=0,scrollbars=0,toolbar=0');opener.focus();
      } else if(type=='6'){
            window.open('/media/tutorials/'+lang+'/flash/'+url,'viewlet','width=792,height=568,status=0,menubar=0,scrollbars=0,toolbar=0');opener.focus();
      } else if(type=='7'){
            window.open(url,'viewlet','width=680,height=520,status=0,menubar=0,scrollbars=0,toolbar=0');opener.focus();
      }
}

 
//ID of Daily Iframe tag:
var iframeids=["xml"]

var getFFVersion=navigator.userAgent.substring(navigator.userAgent.indexOf("Firefox")).split("/")[1]
var FFextraHeight=getFFVersion>=0.1? 16 : 22 //extra height in px to add to iframe in FireFox 1.0+ browsers

function startdyncode(){
dyniframesize()
}

function dyniframesize() {
var dyniframe=new Array()
for (i=0; i<iframeids.length; i++){
if (document.getElementById){ //begin resizing iframe procedure
dyniframe[dyniframe.length] = document.getElementById(iframeids[i]);
if (dyniframe[i] && !window.opera){
dyniframe[i].style.display="block"
if (dyniframe[i].contentDocument && dyniframe[i].contentDocument.body.offsetHeight) //ns6 syntax
dyniframe[i].height = dyniframe[i].contentDocument.body.offsetHeight+FFextraHeight; 
else if (dyniframe[i].Document && dyniframe[i].Document.body.scrollHeight) //ie5+ syntax
dyniframe[i].height = dyniframe[i].Document.body.scrollHeight;
}
}
}
}

if (window.addEventListener)
window.addEventListener("load", startdyncode, false)
else if (window.attachEvent)
window.attachEvent("onload", startdyncode)

