/* submit a form with checking */
function addnewForm() {
	try {
		if(arguments.length==1) {
			var formobj = arguments[0]
			for(var i=0; i<formobj.length; i++) {
				var currobj = formobj[i]					
				var txttmp = currobj.parentNode.innerText || currobj.parentNode.textContent
			
				if(txttmp!="undefined") {
					if(txttmp && /[\*]+/.test(txttmp)) {
						if(!currobj.value) {
							alert('Please input this field')
							formobj[i].focus()
							return false
						}
					}
				}
			}
			
			if(/.*op.*/i.test(formobj.action)) {
			}
			else
				formobj.action = formobj.action+'?op=addnew'
			return true
		}
	} catch(e) {
		return false
	}
	return false
}


/* Delete a record */
/* <a href="javascript:void(0)" onClick="delreg('<?=$_row['id']?>', this,'<?=basename($_SERVER['PHP_SELF'])?>')"><img src="image/del.gif" width="16" align="absmiddle" height="16" border="0" alt="Delete"></a> */
var lockopa = false
function delreg() {
	if(lockopa) {
		alert("operation executing ...")
		return
	}
	
	var curr_TDobj = null
	var usid = null
	var exerestore = false
	
	if(confirm('Are you sure to delete this customer?')) {
		if(arguments.length==3) {
			lockopa = true
			
			if(isNaN(arguments[0])) {
				alert("That's can not find this id no.!")
				return false
			}
			
			try {
				curr_TDobj = arguments[1].parentNode
				usid = arguments[0]
				curr_TDobj.style.backgroundColor="yellow"
				curr_TDobj.innerHTML = "operation executing ... <img src=\"image/waiting.gif\" border=\"0\" align=\"absmiddle\">"
				curr_TDobj.style.paddingRight="4px"								
				
				var ajax = new Ajax(null,"html")
				if(ajax) {
					ajax.post(arguments[2],"op=delu&usid="+usid,function(res) {
						var ans = res.split(":")
						if(Number(ans[0])==200) {
							lockopa = false
							location.reload()
						}
						else {
							lockopa = false
							curr_TDobj.style.backgroundColor="#F5E9C3"
							curr_TDobj.innerHTML = "<b>ID: "+usid+"</b> <a href=\"javascript:void(0)\" onClick=\"delreg('"+usid+"', this)\"><img src=\"image/del.gif\" width=\"16\" align=\"absmiddle\" height=\"16\" border=\"0\" alt=\"Delete\"></a>"
						}
					},true)
				}
			} catch(e) {
				exerestore = true
			}
		}
		
	} else
		exerestore=true
	
	if(exerestore) {
		lockopa = false
		curr_TDobj.style.backgroundColor="#F5E9C3"
		curr_TDobj.innerHTML = "<b>ID: "+usid+"</b> <a href=\"javascript:void(0)\" onClick=\"delreg('"+usid+"', this)\"><img src=\"image/del.gif\" width=\"16\" align=\"absmiddle\" height=\"16\" border=\"0\" alt=\"Delete\"></a>"
	}
}