function doAjax(){
	createXMLHttpRequest();
	xmlHttp.onreadystatechange = commentStateChange; //when call function 'commentStateChange' must not have ()						

	callPost(document.forms[0]);
}

function commentStateChange(){	
	if(xmlHttp.readyState == 4){
		if(xmlHttp.status == 200){			
			document.getElementById("resultSubmit").innerHTML = xmlHttp.responseText;
		}	
	}
}

function setResultSubmit(input){
	document.getElementById("resultSubmit").innerHTML = input;
}

function SubmitForm(frmObj, strFor, strActionURL){
	if(strFor != "") frmObj.caller.value = strFor;	
	if(strActionURL != "") frmObj.action = strActionURL;
	frmObj.submit();
}

function isEmpty(input){
	input = trim(input);
	if((input == "") || (input == "nochoose")){
		return true;
	}else{
		return false;
	}
}

function trim(stringToTrim) {
	return stringToTrim.replace(/^\s+|\s+$/g,"");
}

function ltrim(stringToTrim) {
	return stringToTrim.replace(/^\s+/,"");
}

function rtrim(stringToTrim) {
	return stringToTrim.replace(/\s+$/,"");
}

function newObj(	input_id	
				, input_name	
				, input_value	
				, input_size	
				, input_length
				, input_class	
				, input_type 	
				, input_onclick	
				, input_onblur
				, input_onchange
				, input_checked){
	var inputObj = document.createElement("input");	
	if(input_type 	 != "") inputObj.setAttribute("type"	, input_type);
	if(input_id 	 != "") inputObj.setAttribute("id"		, input_id);
 	if(input_name 	 != "") inputObj.setAttribute("name"	, input_name);	
	if(input_value 	 != "") inputObj.setAttribute("value"	, input_value);
	if(input_size 	 != "") inputObj.setAttribute("size"	, input_size);
	if(input_length  != "") inputObj.setAttribute("length"	, input_length);
	if(input_checked != "") inputObj.setAttribute("checked" , input_checked);			
	inputObj.onClick 	= new Function(input_onclick+";");
	inputObj.onBlur 	= new Function(input_onblur+";");
	inputObj.onChange 	= new Function(input_onchange+";");

	return inputObj;
}

function createInput(name, value, size, length, style, type ,onclick, onblur, onchange){
	var inputObj = document.createElement("<input name='"+ name + "' onclick='"+ onclick + "' onblur='" + onblur + "' onchange='" + onchange + "'>");
	inputObj.setAttribute("value",  value);
	inputObj.setAttribute("size", size);
	inputObj.setAttribute("length", length);
	inputObj.className = style;
	inputObj.setAttribute("type", type);

	return inputObj;
}

function toggleCheckAll(parent, children){
	if(children[1] == null){//not array
		children = new Array(children);//make to array
	}
	
	for(i=0; i < children.length; i++){
		children[i].checked = parent.checked;
	}
}

function callPrint(){		
	window.print();
}

function callClose(){		
	window.close();
}

var xmlHttp;
function createXMLHttpRequest(){
	if(window.ActiveXObject){
		xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
	}else if(window.XMLHttpRequest){
		xmlHttp = new XMLHttpRequest();
	}
}

function getRequestBody(pForm){
	var nParams = new Array();
	
	for(var i = 0; i < pForm.elements.length; i++){
		var pParam = encodeURIComponent(pForm.elements[i].name);
		pParam += "=";
		pParam += encodeURIComponent(pForm.elements[i].value);
		nParams.push(pParam);
	}
	return nParams.join("&");
}

function callPost(objForms){
	/*
	var pForm = document.forms[0];
	var pBody = getRequestBody(pForm);	
	xmlHttp.open("post",pForm.action,true);
	xmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
	xmlHttp.send(pBody);
	*/	
	
	var pForm = objForms;
	var pBody = getRequestBody(pForm);	
	xmlHttp.open("post",pForm.action,true);
	xmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
	xmlHttp.send(pBody);
}