

function getCookie(c_name) {
	if (document.cookie.length>0) {
		c_start=document.cookie.indexOf(c_name + "=");
		if (c_start!=-1) { 
			c_start=c_start + c_name.length+1; 
			c_end=document.cookie.indexOf(";",c_start);
			if (c_end==-1) c_end=document.cookie.length;
			return unescape(document.cookie.substring(c_start,c_end));
		} 
	}
	return "";
}
	
function voteThisStory(story_id) {
	username=getCookie('textnovel');	
	if(username==null || username=="") {	
		alert('Please login to vote this story');
	} else {
		var submitTo = 'ajaxPages/story_vote.php?story_id='+story_id;
	   	http('POST', submitTo, ajax_response_voting, document.form1);
	}
}
	
function ajax_response_voting(data) { 
	if(data==null) {
		alert('The system understand your request but unable to process at this moment!');
	} else {
		if(data['vote_given']=='yes') {
			$("#total_vote_subscription_"+data['story_id']).html(data['total_vote_subscription']);
			$("#div_vote_image_"+data['story_id']).html('<div class="vote-select"><img src="images/spacer.gif" alt="" width="45" height="49" border="0" /></div>');
			alert('You have successfully given vote to story');
		} else if(data['vote_given']=='no') {
			$("#total_vote_subscription_"+data['story_id']).html(data['total_vote_subscription']);
			$("#div_vote_image_"+data['story_id']).html('<div class="vote-select"><img src="images/spacer.gif" alt="" width="45" height="49" border="0" /></div>');
			alert('You have allready given vote to story');
			document.frm_opts.submit();
		} else {
			alert('The system is unable to process the request!')
		}
	}
}

