var $jQ=jQuery.noConflict();
henworx.Widgets={}

henworx.Widgets.SendAFriend=function(){
	
	var _container="henworx_widget_send_a_friend_container"
	this.formId="widgetSendAFriend-form";
	var _responseHolder=this.formId+"-response";
	var _location_id=0;
	this.showHide=function(){
		$jQ("#"+_container).toggle(); 
	}
	
	this.setLocationId=function(_location_id){
		if(typeof(_location_id)=='undefined'){_location_id=gMapCms.currentLocation.id;}
			if(_location_id>0){
				this.formId="detailSendAFriend-form";
				document.getElementById(this.formId).elements['send-a-friend-location-id'].value=_location_id;
				_responseHolder=this.formId+"-response";
			}
			
			
			
	}
	

	var _this=this;
	this.send=function(){
		$jQ.ajax({
			type: "POST",
			url: gPluginUrl+"/admin/includes/widgets/send-a-friend/send-a-friend-send.php",
			data: $jQ("#"+_this.formId).serialize(),
			success: function(msg){	
				document.getElementById(_responseHolder).innerHTML=msg;
				if(msg.indexOf("error",0)<0){_this.hideForm();}
			}
		});
		
		
	}
	
	this.reSend=function(){
	document.getElementById(_responseHolder).innerHTML="";
	//reset the fields
	document.getElementById(this.formId).elements['send-a-friend-friend-name'].value="";
	document.getElementById(this.formId).elements['send-a-friend-friend-email'].value="";
	//show the form again.
	this.showForm();
	}
	
	this.hideForm=function(){
		alert(this.formId);
		$jQ("#"+this.formId).hide();
	}
	
	this.showForm=function(){
		$jQ("#"+this.formId).show();
	}
}

