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

ProProspectHandler.prototype.purchaseProduct = function(product,target,target2){
	
	var rpc;
	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{
			alert("cathing...");
		}
  	};

 	rpc.load(this.uri+"purchaseProduct","product="+product+"&target="+prospectId+"&target="+projectId,this);
 	
 	return;


}

ProProspectHandler.prototype.changeStatusRequest = function(prospectId,projectId,statusId,func){
	
	var rpc;
	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{
			
			if(func)
				func();
			
		}
  	};
 	rpc.load(this.uri+"changeStatusRequest","projectId="+projectId+"&prospectId="+prospectId+"&statusId="+statusId,this);
 	return;
}

/**
* purchaseOpenTender
*/
ProProspectHandler.prototype.purchaseOpenTender = function(projectId,func){
	
	var rpc;
	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{
			if(func)
				func();
		}
  	}

 	rpc.load(this.uri+"createProspectForOpenTender","projectId="+projectId,this);
 	
 	return;

}



ProProspectHandler.prototype.purchaseTender = function(prospectId,projectId,func){

	var rpc;
	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{
			
			if(func)
				func();
			
		}
  	}

 	rpc.load(this.uri+"purchaseTender","prospectId="+prospectId+"&projectId="+projectId,this);
 	
 	return;
}


/**
* getProProspectsList
*
*/
ProProspectHandler.prototype.getProProspectsList = function(subjectKey,firmId){

	var rpc;
	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+"loadCustomerRequestsForThisUsersFirms","firmid="+firmId,this);
 	
 	return;

}

/**
* searchProjects

*/
ProProspectHandler.prototype.searchProjects = function(subjectKey,formName){

	var form = document.getElementById(formName);
  	var inputs = form.getElementsByTagName("input");
  	var selects = form.getElementsByTagName("select");
  	
  	var queryString = "";

	// var rpc = new RPC();
	var rpc;
	rpc = new RPC();
	
	queryString = rpc.buildQueryFromInput(queryString,inputs);
  	queryString = rpc.buildQueryFromSelect(queryString,selects);
  	
  	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+"searchProjects",queryString,this);
 	
 	return;
}


