var public_continue = true;
/**
 *the front page invoke interface.
 *@param the actionID.
 */
function gEventManager(actionID) {
	
	if (actionID=="-1") return false;
	try{
        var root = ctrlSrc.documentElement;        
	}catch(e){
		alert("Can't find out the action ctrl file !");
		return false;
	}
	var ctrlXML = queryByNodeName(root,"actions");	
	if(!ctrlXML) {	
		alert("can't find out actions element:"+root.xml);
		return false;	
	}
	var actionRoot=queryByAttributeValue(ctrlXML,'id',actionID);	
	
	if (!actionRoot) {	
		alert("Can't find out the actionID:"+actionID);
		return false;
	}	
	var fun_code = actionRoot.getAttribute("type");

	if (fun_code!="") {	

	 	if(public_continue) {
	    	eval("eventProcessor_"+fun_code+"(actionRoot)");	    
	    } else {	    
	    	public_continue  = true;
	    }
		return true;
	} else {	
		alert("Can't find out the action type,please check the ctrl file!");
	}
}

/**
 *The front page invoke interface that give servURL.
 *@param the actionID set in the ctrl.xml
 *@param the servURL
 */
function gEventManagerServURL(actionID,servURL) {
	if (actionID=="-1") return false;
	
	try{
        var root = ctrlSrc.documentElement;
	}catch(e){
		alert("Can't find out the action ctrl file !");
		return false;
	}
	
	var ctrlXML = queryByNodeName(root,"actions");	
	if(!ctrlXML) {	
		alert("can't find out actions element:"+root.xml);
		return false;	
	}
	var actionRoot=queryByAttributeValue(ctrlXML,'id',actionID);		
	if (!actionRoot) {	
		alert("Can't find out the actionID:"+actionID);
		return false;
	}	
	var fun_code = actionRoot.getAttribute("type");

	if (fun_code!="") {	
    	eval("eventProcessor_"+fun_code+"(actionRoot,servURL)");	    	    
		return true;
	} else {	
		alert("Can't find out the action type,please check the ctrl file!");
	}
} 

/**
 *compose the post param from formname.
 *@param formName
 */
function eventManagerComposeParam(formName,eleNameArr) {	
	var paramStr = "";
	try{												
		var execType = 0;
		var formObj = document.getElementById(formName).elements;		
		var formLength = formObj.length;
		for(var i=0;i<formLength;i++) {					
			var obj = formObj[i];												
			var condStr = false;
			if (eleNameArr!="") {			
				for (var a=0;a<eleNameArr.length;a++) {				
					if (obj.name==eleNameArr[a]) {					
						condStr = true;
					}	
				}
			} else {
				if (obj.name.substr(0,11)!='DonotSubmit')
					condStr = true;
				else
					condStr = false;
			}
			
			if (condStr) {							
				switch (obj.type) {
					case "button":
						break;
					case "reset":
						break;
					case "radio":
						execType = 1;
						break;
					case "select-one":
						execType = 1;
						break;
					case "select-multiple":
						execType = 1;
						break;				
					case "checkbox": 
						if (obj.checked)
							execType = 1;
						break;
					case "text":
						execType = 1;
						break;
					case "textarea":
						execType = 1;
						break;
					case "password":
						execType = 1;
						break;					
					case "hidden":
						execType = 1;
						break;
					}
				if (execType==1) {
					if(obj.name!="") {					
						var tempName = obj.name;						
						var tempValue = encodeURIComponent(obj.value);						
						paramStr = paramStr + tempName+"="+tempValue+"&";
						
					}
				}
			execType=0;
			}	
		}
	} catch(err) {	
		alert("the post data error!" + err.description );
	}	
	return paramStr;
}


/**
 *auto deal the next action.
 */ 
function eventManagerDoNextAction(nextActionID) {	
	if (nextActionID == "") {
		return;
	}
	try {
		//setTimeOut("eventManagerKeepTrack()",1);		
		gEventManager(nextActionID);		
	} catch (err) {		
		//alert("Do the next action error----"+err.description);	
		return false;
	}
	return true;	
}



 
