// JavaScript Document


function formCheck_i(formobj,fieldRequired,fieldDescription){

	var alertMsg = "กรุณากรอกข้อมูลต่อไปนี้ให้ครับถ้วน:\n";
	var l_Msg = alertMsg.length;
	var errColor = '#FFFFCC'; 
	
	for (var i = 0; i < fieldRequired.length; i++){
		var req = fieldRequired[i];
		if(req.substr(0,1) == '*'){
			if(!formCheck_i_ext(eval("document."+req.substr(1)))){
				alertMsg += " i.. " + fieldDescription[i] + "\n";
			}
			continue;
		}
		var obj = formobj.elements[req];
		obj.style.backgroundColor = "#FFFFFF";
		if (obj){
			switch(obj.type){
			case "select-one":
				if (obj.selectedIndex == -1 || obj.options[obj.selectedIndex].text == "" || obj.options[obj.selectedIndex].value == ""  || obj.options[obj.selectedIndex].value == 0){
					alertMsg += " i.. " + fieldDescription[i] + "\n";
					obj.style.backgroundColor = errColor;
				}
				break;
			case "select-multiple":
				if (obj.selectedIndex == -1){
					alertMsg += " i.. " + fieldDescription[i] + "\n";
					obj.style.backgroundColor = errColor;
				}
				break;
			case "checkbox":
				if (obj.checked == false){
					alertMsg += " i.. " + fieldDescription[i] + "\n";
				}
				break;
			case "text":
			case "textarea":
				if (obj.value == "" || obj.value == null){
					alertMsg += " i.. " + fieldDescription[i] + "\n";
					obj.style.backgroundColor = errColor;
				}
				break;
			default:
				if (obj.value == "" || obj.value == null){
					alertMsg += " i.. " + fieldDescription[i] + "\n";
					obj.style.backgroundColor = errColor;
				}
			}
		}
	}


	if (alertMsg.length == l_Msg){	
		return true;
	}else{
		alert(alertMsg);
		return false;
	}
}

function formCheck_i_ext(obj){
	for(var i =0;i<obj.length;i++){
		if(obj[i].checked)return true;
		//if(obj[i].value)return true;
	}
	return false;
}

function isObji(id) {
	return document.getElementById(id);
}


