
// show a div and hide divs specified in an array of strings
function displayDiv(showDivs, hideDivs){
	if (hideDivs != null){
		for (i = 0; i < hideDivs.length; i++){
			div = document.getElementById(hideDivs[i]);
			if (div != null) {
				div.style.display="none";
			}
		}
	}
	if (showDivs != null){
		for (i = 0; i < showDivs.length; i++){
			div = document.getElementById(showDivs[i]);
			if (div != null) {
				div.style.display="";
			}
		}
	}
}

// show elements and hide elements specified in an array of strings
// basically, this is the same as displayDiv above ... but to avoid confusion, this function can be used with different types of elements
function displayElements(showElements, hideElements) {
	if (hideElements != null){
		for (i = 0; i < hideElements.length; i++){
			ele = document.getElementById(hideElements[i]);
			if (ele != null) {
				ele.style.display="none";
			}
		}
	}
	if (showElements != null){
		for (i = 0; i < showElements.length; i++){
			ele = document.getElementById(showElements[i]);
			if (ele != null) {
				ele.style.display="";
			}
		}
	}
}

function moveElement(parentId, moveId, beforeId) {
	pElement = document.getElementById(parentId);
	mElement = document.getElementById(moveId);
	bElement = document.getElementById(beforeId);
	
	if (pElement != null && mElement != null && bElement != null) {
		pElement.insertBefore(mElement, bElement);
	}
}

function setSelectList(select, value){
 options = select.options;
 if (options != null){
 	for (i = 0; i < options.size; i++){
 		if (options[i].value.equals(value)){
 			options[i].selected=true;
 			break;
 		}
 	}
 }
}

function highlightBadWordFields(form) {
//	alert("highlighting bad word fields...");
	for (iter=0; iter < form.elements.length; ++iter) {
		param = form.elements[iter];
		//if (param != null)	alert("param.name="+param.name+", param.value="+param.value);
		if (param != null && param.value == "****") {
			paramName = param.name;
//			alert("paramName="+paramName);
			index = paramName.indexOf("address2");
			if (index >= 0) {
				prefix = paramName.substring(0, index);
				suffix = paramName.substring(index+"address2".length, paramName.length);
				if(document.getElementById("caption_address2"+suffix) == null){
					paramName = prefix + "address1" + suffix;
				}
			}
			captionObj = document.getElementById("caption_"+paramName);
			captionObj.style.color = 'red';
		}
	}
}
function get_url_param(url, name)
{  
	name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");  
	var regexS = "[\\?&]"+name+"=([^&#]*)";  
	var regex = new RegExp( regexS );  
	var results = regex.exec( url );  
	if( results == null )    
		return "";  
	else return results[1];
} 
