var scriptString;
// Find all tags with a particular classname within an element.
function getElementsByClassName(oElm, strTagName, strClassName){
		var arrElements = (strTagName == "*" && document.all) ? document.all : oElm.getElementsByTagName(strTagName);
		var arrReturnElements = new Array();
		strClassName = strClassName.replace(/\-/g, "\\-");
		var oRegExp = new RegExp("(^|\\s)" + strClassName + "(\\s|$)");
		var oElement;
		for(var i=0; i<arrElements.length; i++){
			oElement = arrElements[i];
			if(oRegExp.test(oElement.className)){
					arrReturnElements.push(oElement);
			}
		}
		return (arrReturnElements);
}


function collapseStates(elementID){
	var allOpen = true;
	var allClosed = true;
	var wrapper = document.getElementById(elementID + '-wrapper');
	var container = document.getElementById(elementID);
	var arrCollapse = getElementsByClassName(container,'div','collapse');
	for(var i=0; i<arrCollapse.length; i++){
		if (arrCollapse[i].getElementsByTagName('div')[0].style.display == 'block') allClosed = false;
		if (arrCollapse[i].getElementsByTagName('div')[0].style.display == 'none') allOpen = false;
	}
	if (wrapper) {
		var arrOpenSwitches = getElementsByClassName(wrapper,'div','collapse-1');
		var arrCloseSwitches = getElementsByClassName(wrapper,'div','collapse-0');
		for(i=0; i<arrCloseSwitches.length; i++){arrCloseSwitches[i].style.color = "#999";}
		if (allOpen) {
			for(i=0; i<arrOpenSwitches.length; i++){arrOpenSwitches[i].style.color = "#999";arrOpenSwitches[i].style.cursor = 'default';}
			for(i=0; i<arrCloseSwitches.length; i++){arrCloseSwitches[i].style.color = "#000";arrCloseSwitches[i].style.cursor = 'pointer';}
		}
		else if (allClosed) {
			for(i=0; i<arrCloseSwitches.length; i++){arrCloseSwitches[i].style.color = "#999";arrCloseSwitches[i].style.cursor = 'default';}
			for(i=0; i<arrOpenSwitches.length; i++){arrOpenSwitches[i].style.color = "#000";arrOpenSwitches[i].style.cursor = 'pointer';}
		}
		else {
			for(i=0; i<arrCloseSwitches.length; i++){arrCloseSwitches[i].style.color = "#000";arrCloseSwitches[i].style.cursor = 'pointer';}
			for(i=0; i<arrOpenSwitches.length; i++){arrOpenSwitches[i].style.color = "#000";arrOpenSwitches[i].style.cursor = 'pointer';}
		}
	}
}

//attaches show/hide events to all divs with class "collapse"
function collapseEvents(){
	var collapseBody;
	var arrCollapse = getElementsByClassName(document.getElementsByTagName('body')[0],'h3','clickable');
	for(var i=0; i<arrCollapse.length; i++){
		arrCollapse[i].onmouseover = function(){
			this.style.cursor = 'pointer';
		};
		arrCollapse[i].parentNode.getElementsByTagName('div')[0].style.display = 'none';
				
		//check url for section
		var is_input = document.URL.indexOf('section=');
		
		if ((is_input != -1)){ 
		addr_str = document.URL.substring(is_input+8, document.URL.length);
		if(arrCollapse[i].parentNode.getElementsByTagName('div')[0].id == addr_str){
		arrCollapse[i].parentNode.getElementsByTagName('div')[0].style.display = 'block';
		collapseStates('details');
		}
		}
		
		//end added code to check
		
		arrCollapse[i].onclick = function(){
			recordClientSideClick('actionName',false);
			var divStyle = this.parentNode.getElementsByTagName('div')[0].style;
			divStyle.display = (divStyle.display == 'block' ? 'none' : 'block');
			var headingStyle = this.style;
			headingStyle.backgroundImage = (divStyle.display == 'block' ? 'url(images/btn_close.gif)' : 'url(images/btn_open.gif)');
			collapseStates('details');
		};
		//show close button as default
		arrCollapse[i].style.backgroundImage = 'url(images/btn_open.gif)';
		
		if ((is_input != -1)){ 
		addr_str = document.URL.substring(is_input+8, document.URL.length);
		if(arrCollapse[i].parentNode.getElementsByTagName('div')[0].id == addr_str){
		arrCollapse[i].style.backgroundImage = 'url(images/btn_close.gif)';
		
		}
		}
		
		arrCollapse[i].style.paddingLeft = '20px';
	}
}

//expand/collapse all elements with class "collapse" within a given container
function allCollapse(elementID,action){
	var container = document.getElementById(elementID);
	var arrCollapse = getElementsByClassName(container,'div','collapse');
	for(var i=0; i<arrCollapse.length; i++){
		//if(i==n){			
			//document.getElementById(e).style.display = 'block';
			//arrCollapse[i].getElementsByTagName('h3')[0].backgroundImage = 'url(images/btn_close.gif)';
		//}else{
		arrCollapse[i].getElementsByTagName('div')[0].style.display = (action == 1 ? 'block' : 'none');
		headingStyle = arrCollapse[i].getElementsByTagName('h3')[0].style;
		headingStyle.backgroundImage = (action == 1 ? 'url(images/btn_close.gif)' : 'url(images/btn_open.gif)');
		//}
	}
	collapseStates(elementID);
}

//expand/collapse module, eg. filter 1
function collapseModule(btn,el){
	var btn_open_path = 'images/btn_open.gif';
	var btn_close_path = 'images/btn_close.gif';
	elStyle = document.getElementById(el).style;
	if (elStyle.display === '') {
		if (btn.src.indexOf(btn_close_path) > -1) elStyle.display = 'block';
		else elStyle.display = 'none';
	}
	if (elStyle.display == 'block'){
		elStyle.display = 'none';
		btn.src = btn_open_path;
	}
	else if (elStyle.display == 'none'){
		elStyle.display = 'block';
		btn.src = btn_close_path;
	}
}

function getElementsByClassNameFromElement(strClass, strTag, objContElm) {
  strTag = strTag || "*";
  objContElm = objContElm || document;
  var objColl = (strTag == '*' && document.all) ? document.all : objContElm.getElementsByTagName(strTag);
  var arr = new Array();
  var delim = strClass.indexOf('|') != -1  ? '|' : ' ';
  var arrClass = strClass.split(delim);
  for (var i = 0, j = objColl.length; i < j; i++) {
    var arrObjClass = objColl[i].className.split(' ');
    if (delim == ' ' && arrClass.length > arrObjClass.length) continue;
    var c = 0;
    comparisonLoop:
    for (var k = 0, l = arrObjClass.length; k < l; k++) {
      for (var m = 0, n = arrClass.length; m < n; m++) {
        if (arrClass[m] == arrObjClass[k]) c++;
        if (( delim == '|' && c == 1) || (delim == ' ' && c == arrClass.length)) {
          arr.push(objColl[i]);
          break comparisonLoop;
        }
      }
    }
  }
  return arr;
}
// To cover IE 5.0's lack of the push method
Array.prototype.push = function(value) {
  this[this.length] = value;
};

// help overlay
/*
function helpOverlayInit() {

	var helpOverlay = document.getElementById("help-overlay");

	var leftOffset = new Point(-370,-130);
	var leftTailOffset = new Point(-48,-12);
	
	var helpOverlayLeft  = new Overlay("help-overlay", leftOffset , null);
	var tailOverlayLeft = new Overlay("help-overlay-tail", leftTailOffset , null);
	
	Event.addEvent("help-close", "click", helpOverlayLeft.hide, helpOverlayLeft);
	Event.addEvent("help-close", "click", tailOverlayLeft.hide, tailOverlayLeft);
	
	Event.addEvent('help', "click", helpOverlayLeft.show, helpOverlayLeft);
	Event.addEvent('help', "click", tailOverlayLeft.show, tailOverlayLeft);

	Event.addEvent('help', "mouseover", function() {this.style.cursor = "pointer";},this);
	Event.addEvent('help', "mouseout", function() {this.style.cursor = "default";},this);
	
	/*changeOverlayContent = function(obj) {
		
		return;
		
	}
	resultsOverlayRight.setChangeContentCallback(changeOverlayContent);
	resultsOverlayLeft.setChangeContentCallback(changeOverlayContent);*/
	//alert(strn);
//}*/
/*
function savedHelpOverlayInit() {

	var rightOffset = new Point(-199,39);
	var rightTailOffset = new Point(-135,16);
	
	var savedHelpOverlayRight  = new Overlay("help-overlay-saved", rightOffset , null);
	var tailOverlayRight = new Overlay("help-overlay-tail-saved", rightTailOffset , null);
	
	Event.addEvent("help-close-saved", "click", savedHelpOverlayRight.hide, savedHelpOverlayRight);
	Event.addEvent("help-close-saved", "click", tailOverlayRight.hide, tailOverlayRight);
	
	Event.addEvent('help-saved', "click", savedHelpOverlayRight.show, savedHelpOverlayRight);
	Event.addEvent('help-saved', "click", tailOverlayRight.show, tailOverlayRight);

	Event.addEvent('help-saved', "mouseover", function() {this.style.cursor = "pointer";},this);
	Event.addEvent('help-saved', "mouseout", function() {this.style.cursor = "default";},this);
	
} 
*/
function setCookie(cookieName,cookieValue) {
	if(cookieValue.length === 0) {
		document.cookie = cookieName+"=;path=/;expires=Fri, 02-Jan-1970 00:00:00 GMT";
	} else {
		var expires = new Date(new Date().getTime() + (7*2*24)*3600000);
		document.cookie = cookieName + "=" + cookieValue.sort().join(",") +";path=/;expires="+expires+";";
	}
}
function getCookie(cookieName) {
	var start = document.cookie.indexOf(cookieName+"=");
	if (start === null || start == -1) return null;
	var len = start + cookieName.length+1;
	var end = document.cookie.indexOf(";",len);
	if (end == -1) end = document.cookie.length;
	var cookie = document.cookie.substring(len,end).split(",");
	return cookie;
}

// function for dynamic Flash content
function showFlash(idName, swfURL, swfWidth, swfHeight, swfColor,altPath) {
	var flashVars = "";
	var node = document.getElementById(idName);
	var children = node.getElementsByTagName('div');
	for( var x = 0; x < children.length; x++ ) {
		flashVars += children[x].getAttribute("id") + "=" + children[x].innerHTML;
		if (x != children.length-1) flashVars += "&";
	}
		//node.innerHTML = '<embed src="' + swfURL + '" wmode="transparent" quality="high" bgcolor="' + swfColor + '" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" flashvars="' + flashVars + '" width="' + swfWidth + '" height="' + swfHeight + '"></embed>';
		/*Code to be uncommented if image swap for Safari is required*/
		if(checkIt('safari')) {
			node.innerHTML = '<img src="'+ altPath +'" alt=\"\" width=\"661\" height=\"251\" alt=\"\" ">';
		}else{
			node.innerHTML = '<embed src="' + swfURL + '" wmode="transparent" quality="high" bgcolor="' + swfColor + '" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" flashvars="' + flashVars + '" width="' + swfWidth + '" height="' + swfHeight + '"></embed>';
		}
}

function showPointer() { this.style.cursor = "pointer";};
function showDefaultCursor() { this.style.cursor = "default";};
