$(function(){
	var formname = "checkFrms";
	formname = "#" + formname + " div";
	$(formname).width("100%");
	var value;
	$(".jQueryHidden").empty();
  });

function checkFrm(value) {

	var ext = value.slice(-4);
	switch(ext) {
		case ("_smt"):
		var status = 0;
		
		for (var i=0; i < $("form div").get().length; i++) {
			var require = $($("form div").get()[i]).attr("id");
				if ( require.substring(0,4) == "req_" ) {
					if (checkNull(require)) {
					} else {
						var status = status+1;
					}
				}
		}
		
		if (status == 0 ) {
			return true;
		} else {
			return false;
		}
		
		break;
		
		case ("_chr"):
			checkChr(value);
		break;
		
		default:
			changeTrue(value);
		}

	if (value.substring(0,4) == "req_") {
		checkNull(value);
		return true;
	}
	
	return true;
}

function checkNull(value) {
	var id = "#" + value;
	var ext = value.slice(-4);
	
	var idValue;
	if (ext == "_txt") {
		idValue = $(id + " textarea").val();
		} else {
		idValue = $(id + " input").val();
	}

	
	if( idValue == "" || idValue == "コメントを入力してください。" ) {
		$(id).attr("class","boxFalse");
		$(id).width("100%");
		$(id + " span").text("必須項目です");
		
		return false;
		
	} else {
		
		if (ext == "_txt") {
				var id = "#" + value;
				var idWidth = $(id + " textarea").width() + 30;
				$(id).attr("class","boxTrue");
				$(id).width(idWidth);
				$(id + " span").text("入力チェック - OK");
				
				return true;
		}
		
	return true;
	
	}
}

function checkChr(value) {
	var id = "#" + value;
	var idValue = $(id + " input").val();

	if(idValue.match(/[^a-z|^0-9]/)) {
		$(id).attr("class","boxFalse");
		$(id).width("100%");
		$(id + " span").text("半角英数で入力");
		return false;
	} else {
		changeTrue(value);
		return true;
	}
}

function changeTrue(value) {
		var id = "#" + value;
		var idWidth = $(id + " input").width() + 30;
		
		$(id).attr("class","boxTrue");
		$(id).width(idWidth);
		$(id + " span").empty();
}
