var W3CDOM = "document.createElement && document.getElementsByTagName"; // object detection for DOM scripting
var IFrameObj; // new IFrame object

function callToServer(sz) { // create iFrame to update session variables, courtesy of Apple at http://developer.apple.com/internet/webcontent/iframe.html
  if (!document.createElement) {return true};
  var IFrameDoc;
  var URL = '/includes/session.php?sz='+sz;
  if (!IFrameObj && document.createElement) {
    // create the IFrame and assign a reference to the
    // object to our global variable IFrameObj.
    // this will only happen the first time 
    // callToServer() is called
   try {
      var tempIFrame=document.createElement('iframe');
      tempIFrame.setAttribute('id','RSIFrame');
      tempIFrame.style.border='0px';
      tempIFrame.style.width='0px';
      tempIFrame.style.height='0px';
      IFrameObj = document.body.appendChild(tempIFrame);
      
      if (document.frames) {
        // this is for IE5 Mac, because it will only
        // allow access to the document object
        // of the IFrame if we access it through
        // the document.frames array
        IFrameObj = document.frames['RSIFrame'];
      }
    } catch(exception) {
      // This is for IE5 PC, which does not allow dynamic creation
      // and manipulation of an iframe object. Instead, we'll fake
      // it up by creating our own objects.
      iframeHTML='\<iframe id="RSIFrame" style="';
      iframeHTML+='border:0px;';
      iframeHTML+='width:0px;';
      iframeHTML+='height:0px;';
      iframeHTML+='"><\/iframe>';
      document.body.innerHTML+=iframeHTML;
      IFrameObj = new Object();
      IFrameObj.document = new Object();
      IFrameObj.document.location = new Object();
      IFrameObj.document.location.iframe = document.getElementById('RSIFrame');
      IFrameObj.document.location.replace = function(location) {
        this.iframe.src = location;
      }
    }
  }
  
  if (navigator.userAgent.indexOf('Gecko') !=-1 && !IFrameObj.contentDocument) {
    // we have to give NS6 a fraction of a second
    // to recognize the new IFrame
    setTimeout('callToServer()',10);
    return false;
  }
  
  if (IFrameObj.contentDocument) {
    // For NS6
    IFrameDoc = IFrameObj.contentDocument; 
  } else if (IFrameObj.contentWindow) {
    // For IE5.5 and IE6
    IFrameDoc = IFrameObj.contentWindow.document;
  } else if (IFrameObj.document) {
    // For IE5
    IFrameDoc = IFrameObj.document;
  } else {
    return true;
  }
  
  IFrameDoc.location.replace(URL);
  return false;
}

function chgSize(e) {
	var zBody = document.getElementsByTagName("body")[0];
	if(!zBody.style.fontSize) zBody.style.fontSize = "62.5%";
	var cSize = zBody.style.fontSize;
	var cLength = cSize.length;
	var cTrim = parseFloat(cSize.substring(0,cLength-1));
	var element = Event.element(e);
	var newSz;
	if (element.getAttribute('id') == 'fontLg') {
		newSz = (cTrim + 5);
	}
	if (element.getAttribute('id') == 'fontSm') {
		newSz = (cTrim - 5);
	}
	zBody.style.fontSize = newSz+"%";
	callToServer(newSz);
}

function addChgSize() {
	if(!document.getElementById || !document.getElementsByTagName) return false;
	var bodyId = document.getElementsByTagName("body")[0].getAttribute('id');
	var div = document.getElementById('textsize');
	var addBtn = document.getElementById('fontLg');
	var subBtn = document.getElementById('fontSm');
	if(addBtn.nodeName.toUpperCase() == "A" && subBtn.nodeName.toUpperCase() == "A") {
		addBtn.setAttribute("href","javascript:void(0);");
		subBtn.setAttribute("href","javascript:void(0);");
		Event.observe(addBtn, 'click', chgSize, false); // prototype event listener
		Event.observe(subBtn, 'click', chgSize, false);
		/*if(Effect.Appear && bodyId == 'home') { // fade in text size buttons if homepage
			div.style.display = 'none';
			Effect.Appear('textsize', { duration: 1.0 });
		}*/
	} else {
		return false;
	}
}

/*addHoverSlide = function(tabId,dropdId){
	if(!document.getElementById) return false;
	tab = document.getElementById(tabId);
	dropd = document.getElementById(dropdId);
	uls = dropd.getElementsByTagName('ul');
	ul = uls[0];
	var display = false;
	tab.onmouseover = function() {
		if(!display) {
			dropd.style.display = "none";
			Effect.SlideDown(dropdId);
			display = true;
		}
	}
	tab.onmouseout = function() {
			
	}
}*/

function searchText() {
		if(!W3CDOM) return false;
		var sBox = document.getElementById('searchBox');
		if(!sBox) return false;
		sBox.style.color = "#999"; // IE doesn't like setAttribute on style
		sBox.setAttribute("value", "Enter your search");
		Event.observe(sBox, 'focus', clearSearch, false);
	}
	
function clearSearch() {
	if(!W3CDOM) return false;
	var sBox = document.getElementById('searchBox');
	if(sBox.getAttribute("value") == null || sBox.getAttribute("value") == "") {
		return false; 
	} else {
		sBox.setAttribute("value", ""); // IE doesn't like removeAttribute
		sBox.style.color = "#000";
	}
}

Event.observe(window, 'load', addChgSize, false);
Event.observe(window, 'load', searchText, false);
