/*
 *  Copyright (c) 2008, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
 *
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *        http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 */

function onTypeSelectionChange(benTypeElementName, nsLinkType) {
	var propertyType = getSelectedValue(benTypeElementName);
	if (propertyType != null) {
		settypeBeanType(propertyType, benTypeElementName, nsLinkType);
	}
}

function settypeBeanType(type, name, nsLinkType) {
	var nsEditorButtonTD = document.getElementById(nsLinkType);
	if (nsEditorButtonTD == null || nsEditorButtonTD == undefined) {
		return;
	}
	if ("expression" == type) {
		nsEditorButtonTD.style.display = "";
	} else {
		nsEditorButtonTD.style.display = "none";
	}
}

function getSelectedValue(id) {
	var propertyType = document.getElementById(id);
	var propertyType_indexstr = null;
	var propertyType_value = null;
	if (propertyType != null) {
		propertyType_indexstr = propertyType.selectedIndex;
		if (propertyType_indexstr != null) {
			propertyType_value = propertyType.options[propertyType_indexstr].value;
		}
	}
	return propertyType_value;
}

function beanMediatorValidate() {
	var clazz = document.getElementById("clazz");
	if (clazz && clazz.value == "") {
		CARBON.showErrorDialog(beani18n["mediator.bean.clazz.value.empty"]);
		return false;
	} 
		
	var beanVar = document.getElementById("beanVar");
	if (beanVar && beanVar.value == "") {
		CARBON.showErrorDialog(beani18n["mediator.bean.beanVar.value.empty"]);
		return false;
	} 
	return true;

}
