/**
* ProspectHandler
* Handler class used to handle requests all requests regarding Prospect entites.
*
* @author: Christian Vejrich
* @date: 2007-05-30
**/
function ProspectHandler(uri, args, projectName){
	  this.uri = uri+"/";
}

/**
* createProspect
*
*/
ProspectHandler.prototype.createProspect = function(id,address){

	var rpc = new RPC();
	rpc.draw = function(){

		//check status.	
		var xml = this.request.responseXML;
		var rootElementList = xml.getElementsByTagName("rater"); 
		var rootTag = rootElementList[0];
		var status = rootTag.getAttribute("status");
	
		if(status!="ok"){
			this.showErrorMessage(xml);
		
		}else{
			ProspectListRender.onCheckedFirm(id);
		
		}
  	}

 	rpc.load(this.uri+"createProspect","firmid="+id+"&address="+address,this);
 	
 	return;
}

/**
* removeProspect
*
*/
ProspectHandler.prototype.removeProspectByFirmId = function(id,boxId){

	var rpc = new RPC();
	rpc.draw = function(){

		//check status.	
		var xml = this.request.responseXML;
		var rootElementList = xml.getElementsByTagName("rater"); 
		var rootTag = rootElementList[0];
		var status = rootTag.getAttribute("status");
	
		if(status!="ok" && status=="warn"){
			alert(rootTag.getAttribute("message"));
		}else if(status!="ok" && status=="error"){
			this.showErrorMessage(xml);
		}else{
			ProspectListRender.onCheckedFirmRemoved(id);
		}
  	}

 	rpc.load(this.uri+"removeProspectByFirmId","prospectId="+id,this);
 	
 	return;

}


/**
* saveValue
*
*/
ProspectHandler.prototype.saveValue = function(fieldName,htmlValueId,prospectId,firmId){

	//show about change notifier.
	var flashLoader = new ContentRenderListener(null,htmlValueId,null);
	
	flashLoader.notifyAboutIncomingChange();

	var inputField = document.getElementById(htmlValueId);

	var rpc = new RPC();
	rpc.draw = function(){

		//check status.	
		var xml = this.request.responseXML;
		var rootElementList = xml.getElementsByTagName("rater"); 
		var rootTag = rootElementList[0];
		var status = rootTag.getAttribute("status");
	
		flashLoader.notifyAboutIncomingChangeStop();
	
		if(status!="ok"){
			this.showErrorMessage(xml);
		}else{
			//do success here.
			listenerHandler.notifyListenersToSubject(subjectKey,this.request.responseXML);
		}
		
  	}

 	rpc.load(this.uri+"saveValue","attribute="+fieldName+"&value="+inputField.value+"&prospectId="+prospectId+"&firmid="+firmId,this);
 	
 	return;
}

/**
* getProProspectsList
*
*/
ProspectHandler.prototype.getProProspectsList = function(subjectKey){

	var rpc = new RPC();
	rpc.draw = function(){

		//check status.	
		var xml = this.request.responseXML;
		var rootElementList = xml.getElementsByTagName("rater"); 
		var rootTag = rootElementList[0];
		var status = rootTag.getAttribute("status");
	
		if(status!="ok"){
			this.showErrorMessage(xml);
		}else{
			//do success here.
			listenerHandler.notifyListenersToSubject(subjectKey,this.request.responseXML);
			
		}
  	}

 	rpc.load(this.uri+"getProspects","",this);
 	
 	return;
}



