// ---
ELO.functionsToCallOnload.push("applyDropdownBtnEvents()");
// ---
function getElementsByClassName(oElm, strTagName, strClassName){
	var arrElements = (strTagName == "*" && oElm.all)? oElm.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 applyDropdownEvents(){
	var dropDownLists = getElementsByClassName(document, "select", "pagelistdropdown");
     
	for(var i=0; i<dropDownLists.length; i++){
    	dropDownLists[i].onchange = indexChanged;
    }
}
// ---
function indexChanged(){
	var url = this.options[this.selectedIndex].value;
	if(url != "-1"){
		var targetKey = 'target=';
		if(url.length > 0){
			if(url.search(targetKey) != -1){
				var target = url.replace(/.*target=(\d+)/, "$1");
				var targetUrl = url.replace(/\&target=1.*/, "");
				targetUrl = targetUrl.replace(/\?target=1.*/, "");
	
				if(target == 0){
					location.href = targetUrl;
				}
				else{
					window.open(targetUrl);
				}
			}
			else{
				location.href = url;
			}
		}
	}
}
// ---
function applyDropdownBtnEvents(){
    var i = 0;
	var dropDownButtons = getElementsByClassName(document, "input", "dropdown_button");
	for(i; i<dropDownButtons.length; i++){
    	dropDownButtons[i].onclick = openWebSite;
    	dropDownButtons[i].id = i;
    }
}

// ---
//If the user has popup blocked, the handbook shall be shown in the same window as the rest of the application
//function openWebSitePopup(targetUrl)
//{
//    var handle = window.open(targetUrl, "popup", "width=700, height=500, toolbar=yes, menubar=yes, scrollbars=yes, location=yes, directories=yes, status=yes");
//    if(handle == null || typeof(handle)=="undefined"){
//        window.open(location.href = targetUrl, "_self"); 
//    }
//    else{
//        window.open(targetUrl, "popup", "width=700, height=500, toolbar=yes, menubar=yes, scrollbars=yes, location=yes, directories=yes, status=yes");
//    }

//	return false;
//}



function openWebSite(){
    var dropDownLists = getElementsByClassName(document, "select", "pagelistdropdown");
    var id = this.id;
    var url = dropDownLists[id].options[dropDownLists[id].selectedIndex].value;
    var targetUrl = "";

	if(url != "-1"){
		var targetKey = 'target=';
		if(url.length > 0){
			if(url.search(targetKey) != -1){
				var target = url.replace(/.*target=(\d+)/, "$1");
				//var targetUrl = url.replace(/\&target=1.*/, "");
				//targetUrl = targetUrl.replace(/\?target=1.*/, "");
				if(target == 2){
				    targetUrl = url.replace(/\&target=2.*/, "");
				    targetUrl = targetUrl.replace(/\?target=2.*/, "");					
					window.open(location.href = targetUrl, "_self");
					return false;
				}
				else{
				    targetUrl = url.replace(/\&target=1.*/, "");
				    targetUrl = targetUrl.replace(/\?target=1.*/, "");
//				    if(this.id == 2){
//				        openWebSitePopup(targetUrl); 
//				        }
//				    else{
				        window.open(targetUrl);
//				    }
					return false;
				}
			}
			else{
			    window.open(window.location.protocol + "//" + window.location.host + url, "_self");
			    return false;
			}
		}
	}
	return false; 
}

// ---
