//create the namespace for this site
YAHOO.namespace ("mysite");

/**
 * With this function, simply add the attribute: rel="external" to the href tag for window popups
 */
function externalLinks() {
 if (!document.getElementsByTagName) return;
 var anchors = document.getElementsByTagName("a");
 for (var i=0; i<anchors.length; i++) {
   var anchor = anchors[i];
   if (anchor.getAttribute("href") &&
     anchor.getAttribute("rel") == "external") {
     anchor.onclick = function() {return launchWindow(this.href)}
	 } else if (anchor.getAttribute("href") &&
     anchor.getAttribute("rel") == "external_image") {
     anchor.onclick = function() {return launchImageWindow(this.href)}
	 }
 }
}

/**
 * @param string href to open in new window
 */
function launchWindow(href) {
	if(href=="" || !href)
		return;
	window.open(href);
	return false;
}

/**
 * @param string href to open in new window
 */
function launchImageWindow(src) {
	if(src=="" || !src)
		return;
	var myImage = new Image();
	myImage.src = src;
	var width=0
	var height=0;
	if(myImage.width!="" && myImage.height!="") {
		width = myImage.width+20;
		height = myImage.height+20;
	}
	if(width==0 || height==0)
		return;
		
	window.open(src,'','width='+width+',height='+height+',location=yes,toolbar=yes,menubar=yes,scrollbars=yes,resizable=yes');
	return false;
}

var _SITE_CONTAINER_REGION;
var _SITE_CONTAINER_ID;

//Function to set the content of a site div to be full height of window
function setFullHeight() {
	var containerDiv = document.getElementById(_SITE_CONTAINER_ID);
	if(!containerDiv)
		return;
	
	if(_SITE_CONTAINER_REGION) {		
		if((_SITE_CONTAINER_REGION.bottom - _SITE_CONTAINER_REGION.top) < YAHOO.util.Dom.getViewportHeight()) 
			containerDiv.style.height = YAHOO.util.Dom.getViewportHeight()+'px';
		else if((_SITE_CONTAINER_REGION.bottom - _SITE_CONTAINER_REGION.top) > YAHOO.util.Dom.getViewportHeight())
			containerDiv.style.height = (_SITE_CONTAINER_REGION.bottom - _SITE_CONTAINER_REGION.top)+'px';
	} 
	
}

//same as setFullHeight function, except, this only occurs on load, performing some initializations
function initSetFullHeight(args) {
	if(args.length<1)
		return;
	_SITE_CONTAINER_ID = args[0];
	var containerDiv = document.getElementById(_SITE_CONTAINER_ID);
	if(!containerDiv)
		return;
	var main = YAHOO.util.Dom.getElementsByClassName(args[1]);
	_SITE_CONTAINER_REGION = YAHOO.util.Dom.getRegion(args[1]);
	
	if(_SITE_CONTAINER_REGION) {
		if((_SITE_CONTAINER_REGION.bottom - _SITE_CONTAINER_REGION.top) < YAHOO.util.Dom.getViewportHeight()) 
			containerDiv.style.height = YAHOO.util.Dom.getViewportHeight()+'px';
	} 
}


function focusSearch(default_text,inputId) {
	var input = document.getElementById(inputId);
	if(input) {
		if(input.value==default_text)
			input.value='';
		else if(input.value=='')
			input.value=default_text;
	}
}


function stripHTML(oldString) {

   var newString = "";
   var inTag = false;
   for(var i = 0; i < oldString.length; i++) {
   
        if(oldString.charAt(i) == '<') 
					inTag = true;
        if(oldString.charAt(i) == '>') {
          inTag = false;
          i++;
        }
   
        if(!inTag) newString += oldString.charAt(i);

   }

   return newString;
}

/*
 * List of listener functions
 */

YAHOO.util.Event.onDOMReady(externalLinks); 
YAHOO.util.Event.onAvailable('content_pane_background',initSetFullHeight,['content_pane_background','main']);
YAHOO.util.Event.addListener(window, 'resize', setFullHeight);

