function submit_form(user_action,id){
   window.document.forms['mf'].elements['ALLFIELDS'].value ='';
   for (var i=0; i < window.document.forms['mf'].length; i++)
   {
   	//alert(window.document.forms['mf'].elements[i].name);
   
   	if (window.document.forms['mf'].elements[i].name.substr(0,2)=='FD' && window.document.forms['mf'].elements[i].disabled==false)
   	{
   		if (window.document.forms['mf'].elements['ALLFIELDS'].value == '')
   		window.document.forms['mf'].elements['ALLFIELDS'].value = window.document.forms['mf'].elements[i].name;
   		else
   		window.document.forms['mf'].elements['ALLFIELDS'].value +=','+window.document.forms['mf'].elements[i].name;
   	}
   }
   
   //above set input name for sql query.

   if (user_action != '')
   window.document.forms['mf'].elements['act'].value = user_action;

   if (id != '')
   window.document.forms['mf'].elements['id'].value = id;
   
   window.document.forms['mf'].submit();
}

function gotopage(pagenum){
   window.document.forms['mf'].elements['offset'].value = (pagenum - 1) * window.document.forms['mf'].elements['pagesize'].value;
   window.document.forms['mf'].elements['act'].value = 'list';
   window.document.forms['mf'].submit();
}

function setPassword(xbool){
   window.document.forms['mf'].elements['FDP_Password'].disabled = xbool;
}

function do_frmCancel(){
	submit_form('cancel','0');	
}

function checkAll(form) {
	for(var i = 0;i < form.length; i++) {
		var em = form.elements[i];
		if (em.name != 'chkall' && em.type=='checkbox' && em.disabled != true) {
			em.checked = form.chkall.checked;
		}
	}
}

function getSelectedItem(form){
	form.selectedItems.value = '';
	for(var i = 0;i < form.length; i++) {
		var em = form.elements[i];
		if (em.name !='chkall' && em.checked) {
			form.selectedItems.value += ','+ em.value;
		}
	}
}

function redirect(url) {
	window.location.replace(url);
}

function toggleDisplay(xDivID){
	if (document.all[xDivID].style.display=="block"){
		document.all[xDivID].style.display="none";
	}
	else {
		document.all[xDivID].style.display="block";
	}
}

function getLocation(PId,CId,frmName,frmElementPId,frmElementCId,frmElementPName,frmElementCName,frmAction)
{
	if (!frmAction) frmAction = 'input';		//input,search
	var strURL = "/common/getlocation.php?pid="+ PId +"&cid="+ CId +"&type=" + frmAction;
	var returnValue = window.showModalDialog(strURL,'','dialogWidth=300px;dialogHeight=150px');
	if (returnValue)
	{
		var t = returnValue.split('-');
		var form = document.forms[frmName];
		form.elements[frmElementPId].value 		= t[0];
		form.elements[frmElementCId].value 		= t[1];
		form.elements[frmElementPName].value	= t[2];
		form.elements[frmElementCName].value 	= t[3];
	}
}

var xopwin;
function opwin(pageurl,h,w)
{
	if (!h) h = 500;
	if (!w) w = 700;
	if (h > window.screen.height) h=window.screen.height;
	if (w > window.screen.width) h=window.screen.width;
	
	var t = (window.screen.height - h)/2;
	var l = (window.screen.width - w)/2;
	
	//alert(t);
	xopwin = window.open(pageurl,'xopwin','top=' + t +',left='+ l +',height='+ h +',width='+ w +',toolbar=no,resizable=no,scrollbars=yes');
	if (window.focus) xopwin.focus();
}