function do_resize() {

	if ( opener ) {

		var w = mainTable.clientWidth - document.body.clientWidth + document.body.clientLeft;

		window.resizeBy(w, 0);

		var h = mainTable.clientHeight - document.body.clientHeight + document.body.clientTop;

		window.resizeBy(0, h);

	}

}



function open_input_form(url, title) {

	window.open(url, title, "width=600,height=400,toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=1");

}





function open_select_form(url, title, element) {

	window.src_element = element;

	window.open(url, title, "width=460,height=280,toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=1");

}





function checkSingleSelect(check_me) {

    if(isMultiSelect)

        return ;

    if(check_me.checked == false)

        return ;

	var inp = document.all.tags("INPUT");

	for(var i = 0; i < inp.length; i++)	{

		if( inp[i].type == "checkbox" && inp[i] != check_me) {

			if(inp[i].checked){

			    inp[i].checked = false;

			    return;

			}

	    }

	}

    

}



function checkbox_init(key) {

	var A = key.split(",");

	var inp = document.all.tags("INPUT");

	for(var i = 0; i < inp.length; i ++)	{

		if( inp[i].type == "checkbox" ) {

			var id = inp[i].value;

			for(var j = 0; j < A.length; j++) {

				if ( id == A[j] ) {

					inp[i].checked = true;

				}

			}

		}

	}

}



function document_loaded() {

	if ( document.all.bnDelete ) {

		document.all.bnDelete.onclick = delete_confirm;

	}

	if ( opener && opener.src_element ) {

		if ( opener.src_element.value != "" ) {

			var A = opener.src_element.value.split(",");

			var inp = document.all.tags("INPUT");

			for(var i=0; i<inp.length; i++) {

				if( inp[i].type == "checkbox" )	{

					var id = inp[i].name.substring(4);

					for(var j=0; j<A.length; j++) {

						if ( id == A[j] ) {

							inp[i].checked = true;

						}

					}

				}

			}

		}

	}

}



function add_element(A, key) {

	var exist = false;

	for(var i=0; i<A.length; i++) {

		if ( A[i] == key ) {

			exist = true;

			break;

		}

	}

	if ( !exist ) {

		A[A.length] = key;

	}

}



function remove_element(A, key) {

	var B = new Array();

	for(var i=0; i<A.length; i++) {

		if ( A[i] != key ) {

			B[B.length] = A[i];

		}

	}

	return B;

}



function select_save() {

        

	if ( opener && opener.src_element ) {



		var A = new Array();

		if ( isMultiSelect && opener.src_element.value != "" ) {

			A = opener.src_element.value.split(",");

		}

		var inp = document.all.tags("INPUT");

		for(var i=0; i<inp.length; i++)	{

			if( inp[i].type == "checkbox" )	{

				var id = inp[i].value;

				if ( inp[i].checked ) {

					add_element(A,id);

				} else {

					A = remove_element(A,id);

				}

			}

		}

		opener.src_element.value = A.join(",");

	}

	//self.close();

}



function xmlEncode(value) {

	var A = new Array();

	A = value.split("&");

	str = A.join("&amp;");

	A = str.split("<");

	str = A.join("&lt;");

	A = str.split(">");

	str = A.join("&gt;");

	A = str.split("\"");

	str = A.join("&quot;");

	A = str.split("\'");

	str = A.join("&apos;");

	return str;

}



function getSingleControlValue(obj) {

	if ( obj.tagName == "INPUT" && obj.type == "checkbox" ) {

		if ( obj.checked == true )

			obj.value = 'Y';

		else

			obj.value = 'N';

	}

	return obj.value;

}



function getControlValue(obj) {

	if ( obj != null ) {

		if ( obj.tagName ) {

			return getSingleControlValue(obj);

		} else {

			if ( obj.length ) {

				for (var i=0; i<obj.length; i++) {

					if ( obj[i].tagName == "INPUT" ) {

						if ( obj[i].type == "radio" ) {

							if ( obj[i].checked ) {

								return obj[i].value;

							}

						} else 

						if ( obj[i].type == "checkbox" ) {

							if ( obj[i].checked ) {

								return obj[i].value;

							}

						}

					}

				}

			}

		}

	}

}



function getXML(obj, tag) {

	var strXml = "";

	if ( obj != null ) {

		var v = getControlValue(obj);

		if ( v != null && v != '' ) {

			strXml = "<" + tag + ">";

			strXml += xmlEncode(v);

			strXml += "</" + tag + ">";

		}

	}

	return strXml;

}



function getBooleanXML(obj, tag) {

	var strXml = "";

	if ( obj != null ) {

		var v = getControlValue(obj);

		strXml = "<" + tag + ">";

		strXml += (v == "Y") ? "true" : "false";

		strXml += "</" + tag + ">";

	}

	return strXml;

}



function getDateXML(obj, tag) {

	

}



function getDetailXML(obj, tag, tag2) {

	var strXml = "";

	if ( obj != null ) {

		if ( obj.tagName ) {

			if ( obj.value != '' ) {

				var keys = new Array();

				keys = obj.value.split(",");

				for(var i=0; i<keys.length; i++)

				{

					strXml += "<" + tag + "><" + tag2 + ">" + keys[i] + "</" + tag2 + "></" + tag + ">";

				}

			}

		} else {

			if ( obj.length ) {

				for(var j=0; j<obj.length; j++) {

					if ( obj[j].tagName == "INPUT" ) {

						if ( obj[j].type == "checkbox" ) {

							if ( obj[j].checked ) {

								strXml += "<" + tag + "><" + tag2 + ">" + obj[j].value + "</" + tag2 + "></" + tag + ">";

							}							

						}

					} 

				}

			}

		}

	}

	return strXml;

}



function input_form_init(f, query) {

	var A = new Array();

	A = query.split("&");

	for(var i=0; i<A.length; i++) {

		if ( A[i].charAt(0) == '_' ) {

			var index = A[i].indexOf("=");

			if ( index != -1 ) {

				var ename = A[i].substring(0,index);

				var e = f[ename];

				if ( e != null ) {

					var v = A[i].substring(index+1);

					if ( e.tagName == "SELECT" ) {

						var opts = e.options;

						for(var j=0; j<opts.length; j++) {

							if ( v == opts[j].value ) {

								opts[j].selected = true;

								break;

							}

						}

					} else {

						e.value = v;

					}

					e.disabled = true;

				}

			}

		}

	}

	

}



function setOrderBy(f, n) {

	if ( f.orderby.value == n ) {

		f.orderby.value += " DESC";

	} else {

		f.orderby.value = n

	}

	f.submit();

	return false;

}



function disableAll() {

	a = document.all.button;

	if(a) {

	    for(var i =0; i < a.length; i++) {

		    a[i].disabled = true;

	    }

	}

	return true;

}

