





/*
	テキストボックス or コンボボックスが入力されているかどうかを判断し、
	されていなければ警告を出す
*/
function checkBlank( obj )
{
	if(typeof(obj) != "object"){
		console.warn("オブジェクトが認識できません");
		return false;
	}
	if(typeof(obj.tagName) == "undefined" || obj.tagName == null || typeof(obj.type) == "undefined"){
		console.warn("オブジェクトが認識できません");
		return false;
	}
	if( (! (obj.tagName == "INPUT" && (obj.type == "text" || obj.type == "password"))) && (obj.tagName != "SELECT") && (obj.tagName != "TEXTAREA")){
		console.warn("テキストボックスかセレクトボックスにしか使用できません");
		return false;
	}
	
	
	

	if(obj.value == ""){
		appendAlert(obj , "入力がありません");
		
		return false;
	}else{
		removeAlert(obj);
		
		return true;
	}
}




/* チェックボックス or ラジオボタンにおいて、選択されているかどうかをチェックする */
function checkSelected( collection )
{
	if(typeof(collection) != "object" || typeof(collection.length) == "undefined"){
		console.warn("オブジェクトが認識できません");
		return false;
	}
	if(typeof(collection[0].tagName) == "undefined" || collection[0].tagName == null || typeof(collection[0].type) == "undefined"){
		console.warn("オブジェクトが認識できません");
		return false;
	}
	if( (! (collection[0].tagName == "INPUT" && collection[0].type == "radio")) && (! (collection[0].tagName == "INPUT" && collection[0].type == "checkbox"))){
		console.warn("ラジオボタンか、チェックボックスにしか使用できません");
		return false;
	}
	
	var isChecked = false;
	var obj;
	
	//
	for(i=0; i<collection.length; i++){
		obj = collection[i];
		
		if(obj.checked == true){
			isChecked = true;
			break;
		}
	}
	
	
	var lastNode = collection[collection.length - 1];
	
	
	if(isChecked == true){
		removeAlert( lastNode );
		
		return true;
	}else{
		appendAlert( lastNode , "選択されていません");
		
		return false;
	}
	
}






















/*
	ある要素の要素に警告メッセージを追加する
*/
function appendAlert( obj , msg )
{

	if(typeof(obj.isAlert) != "undefined" && obj.isAlert == true){
		return;
	}


	//親のノードを取得して、class名がinput_alert_messageである要素を取得する
	var parent = obj.parentNode;
	var i;
	var child;
	
	
	
	
	//input_alert_messageが存在しない
	var div1 , txt1;
	
	txt1 = document.createTextNode( msg );
	
	div1 = document.createElement('DIV');
	div1.className = 'input_alert_message';
	div1.appendChild(txt1);
	
	
	parent.appendChild(div1);
	
	
	
	
	obj.isAlert = true;
	
	
	if( (obj.tagName == "INPUT" && (obj.type == "text" || obj.type == "password") && obj.tagName == "TEXTAREA")){
		if(typeof(obj.className) == "undefined"){
			//obj.preClassName = "";
			//obj.className = "input_alert";
			Element.addClassName(obj,"input_alert");
		}else{
			//obj.preClassName = obj.className;
			//obj.className = obj.className + " input_alert";
			Element.addClassName(obj,"input_alert");
		}
	}else{
		obj.preClassName = "";
	}
}


/*
	ある要素にappendAlertで追加した警告メッセージを削除する
*/
function removeAlert( obj )
{	
	//親のノードを取得して、class名がinput_alert_messageである要素を取得する
	var parent = obj.parentNode;
	var i;
	var child;
	var isBlank;
	
	for(i=0; i<parent.childNodes.length; i++){
		child = parent.childNodes[i];
		
		if(typeof(child.className) != "undefined" && child.className == "input_alert_message"){
			if(isBlank != true){
				//child.removeNode(true);
				parent.removeChild(child);
			}
			
			obj.isAlert = false;
			
			if( (obj.tagName == "INPUT" && (obj.type == "text" || obj.type == "password") && obj.tagName == "TEXTAREA")){
				//obj.className = obj.preClassName;
				Element.removeClassName(obj,"input_alert");
			}
			
			return;
		}
	}
}






