var zlocale = '';
function setLocale(){
    if (document.getElementById('locale_lang')) zlocale = document.getElementById('locale_lang').value;
    return zlocale;
}


var scriptString;
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 findPos(obj) {
	var curleft = curtop = 0;
	if (obj.offsetParent) {
		curleft = obj.offsetLeft
		curtop = obj.offsetTop
		while (obj = obj.offsetParent) {
			curleft += obj.offsetLeft
			curtop += obj.offsetTop
		}
	}
	return [curleft,curtop];
}

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';}
		}
	}
}

function collapseEvents(){
	var collapseBody;
	var arrCollapse = getElementsByClassName(document.getElementsByTagName('body')[0],'div','collapse');
	for(var i=0; i<arrCollapse.length; i++){
		arrCollapseH3 = arrCollapse[i].getElementsByTagName('h3')[0];
		if (arrCollapseH3 !=null)
		{
			arrCollapseH3.onmouseover = function(){
				this.style.cursor = 'pointer';
				};
		};
		arrCollapse[i].getElementsByTagName('div')[0].style.display = 'none'; 
		if (arrCollapseH3 !=null)
		{
			arrCollapseH3.onclick = function(){
				var div = this.parentNode.getElementsByTagName('div')[0];
				var divStyle = div.style;
				divStyle.display = (divStyle.display == 'block' ? 'none' : 'block');
				var headingStyle = this.style;
				headingStyle.backgroundImage = (divStyle.display == 'block' ? closeImgUrl : openImgUrl);
				collapseStates(this.parentNode.parentNode.id);
				var action = (divStyle.display == 'block') ? 'expand' : 'collapse';
				var nameFromDiv = div.parentNode.id;
				if (nameFromDiv==null || (nameFromDiv.length==0))
					nameFromDiv = div.parentNode.parentNode.id;
				var actionName = nameFromDiv+'-'+action;
				recordClientSideClick(actionName, false);	
			};

		arrCollapseH3.style.backgroundImage = openImgUrl ;
		arrCollapseH3.style.paddingLeft = '20px';
		};
	}
}

function allCollapse(elementID,action){
	var container = document.getElementById(elementID);
	var arrCollapse = getElementsByClassName(container,'div','collapse');
	for(var i=0; i<arrCollapse.length; i++){
		arrCollapse[i].getElementsByTagName('div')[0].style.display = (action == 1 ? 'block' : 'none');
		headingStyle = arrCollapse[i].getElementsByTagName('h3')[0].style;
		headingStyle.backgroundImage = (action == 1 ? closeImgUrl  : openImgUrl );
	}
	collapseStates(elementID);
}

function collapseModule(btn,el){
	var btn_open_path = btnOpen;
	var btn_close_path = btnClose;

	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;
}
Array.prototype.push = function(value) {
  this[this.length] = value;
};

function helpOverlayInit( topOffset ) {
	if( document.getElementById('help') ){
		Event.addEvent('help','click', getParamsFilter1Step1);
	}
	Event.addEvent('help', "mouseover", function() {this.style.cursor = "pointer";},this);
}

function savedHelpOverlayInit() {
	Event.addEvent('help-saved', 'click', getSavedParamsStep1);
	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 showFlash(idName, swfURL, swfWidth, swfHeight, swfColor,altPath, flashVars, openSiteTour) {
	
	var newFlashVars = "swfLinks=" + flashVars;
	if(openSiteTour == "true"){
		newFlashVars += "&openSiteTour=true";
	} else {
		newFlashVars += "&openSiteTour=false";
	}
	var node = document.getElementById(idName);
	var children = node.getElementsByTagName('div');
		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="../../../www.macromedia.com/go/getflashplayer" flashvars="' + newFlashVars + '" width="' + swfWidth + '" height="' + swfHeight + '" scale="noscale" ></embed>';
		}
}

function showFlashGeneral(idName, swfURL, swfWidth, swfHeight, swfColor,altPath) {
    alert('showFlashGeneral');
	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="../../../www.macromedia.com/go/getflashplayer" flashvars="' + flashVars + '" width="' + swfWidth + '" height="' + swfHeight + '" scale="noscale" ></embed>';
}

function resizeFlashDiv(elFlash,elText,action){
	var flashDiv = document.getElementById(elFlash);
	var textDiv = document.getElementById(elText);
	if (action == 'expand') {
		flashDiv.style.width = '408px';
		flashDiv.style.height = '217px';
		flashDiv.style.zIndex = '20';
		textDiv.style.zIndex = '10';
	}
	if (action == 'contract') {
		flashDiv.style.width = '176px';
		flashDiv.style.height = '80px';
		flashDiv.style.zIndex = '10';
		textDiv.style.zIndex = '20';
	}
}

function showPointer() { this.style.cursor = "pointer";};
function showDefaultCursor() { this.style.cursor = "default";};
