AjaxTips = Class.create();

AjaxTips.prototype = {
	initialize:function() {
		
	},
	
	addTip:function(redirectPage) {
		if(redirectPage) {
			document.location = redirectPage;
		}else{
			if (FormValidation.validateForm(null,'addTipForm')) {
				currentTime = new Date();
				ajaxSetTimeOut("AjaxTips.addOnFailureHandler()");
				var goAjax = new Ajax.Request(
					'/global/ajax/ajaxResponse/tipsAjaxResponse.jsp', 
					{
						method: 'post',
						parameters: 'currentTime='+currentTime.getTime(),
						postBody: parseParamsforAjax('addTipForm'),
						onLoading: this.addOnLoadingHandler,
						onFailure: this.addOnFailureHandler,
						onComplete: this.addOnCompleteHandler
					});
			}
		}
	},
	
	addOnLoadingHandler:function() {
		$('addFav').style.display='block';
	},
	
	addOnFailureHandler:function() {
		clearTimeout(ajaxTimer);
		$('addFav').innerHTML = 'Adding not successful. Please Try Again.'
		$('addFav').style.display='block';
	},
	
	addOnCompleteHandler:function() {
		clearTimeout(ajaxTimer);
		$('addFav').innerHTML = 'Successfully added to: My Tips'
		$('addFav').style.display='block'; 
	},
	
	voteTip:function(vote) {
		$('vote').value = vote;
		if (FormValidation.validateForm(null,'voteTipForm')) {
			currentTime = new Date();
			ajaxSetTimeOut("AjaxTips.voteOnFailureHandler()");
			var goAjax = new Ajax.Request(
				'/global/ajax/ajaxResponse/tipsAjaxResponse.jsp', 
				{
					method: 'post',
					pars: 'currentTime='+currentTime.getTime(),
					postBody: parseParamsforAjax('voteTipForm'),
					onLoading: this.voteOnLoadingHandler,
					onFailure: this.voteOnFailureHandler,
					onComplete: this.voteOnCompleteHandler
				});
		}		
	},
	
	voteOnLoadingHandler:function() {

	},
	
	voteOnFailureHandler:function() {
		clearTimeout(ajaxTimer);
		$('voteError').innerHTML = "Voting not successful. Please Try Again."
		$('voteError').style.display='block'; 
	},
	
	voteOnCompleteHandler:function(oResponseMsg) {
		clearTimeout(ajaxTimer);
		try {$('dumpBox').innerHTML = oResponseMsg.responseText; } catch(err){}
		oResponseMsg = eval("(" + oResponseMsg.responseText.strip() + ")");
		$('voteContainer').style.fontWeight = 'bold';
		$('voteContainer').style.color='#FF3333';
		$('voteContainer').innerHTML = oResponseMsg.ajaxResponse.message; 
	}
}

var AjaxTips = new AjaxTips;