/*=========================================================================
#
#    $Id: display_page.js,v 1.3 2007/01/08 21:06:48 acrosman Exp $
#
#=========================================================================
#
#    Copyright 2006 American Friends Service Committee
#
#===============================- GPL Header -=================================
#
#    This program is free software; you can redistribute
#    it and/or modify it under the terms of the GNU General Public License
#    as published by the Free Software Foundation; either version 2 of
#    the License, or (at your option) any later version.
#
#    This program is distributed in the hope that it
#    will be useful, but WITHOUT ANY WARRANTY; without even the implied
#    warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
#    See the GNU General Public License for more details.
#
#    You should have received a copy of the GNU General Public License
#    along with AFSC Vigil Registration System; if not, write to the Free Software
#    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
#
#    
#========================================================================= */

function updateVoting(){
	// Find the link to update
	var a = document.getElementById('fav_anchor');
	var linkattrs = a.attributes;
	
	var old_link_text = linkattrs.getNamedItem("href").value;
	
	var new_link_text = "javascript: onclick=sendVote('" + old_link_text +  "')";

	a.removeAttribute('href');	
	a.setAttribute('href', new_link_text);

}

window.onload=function() {
	
	updateVoting();	

}

function sendVote( voteURL ) {
	
	if (document.getElementById) {
		var x = (window.ActiveXObject) ? new ActiveXObject("Microsoft.XMLHTTP") : new XMLHttpRequest();
	}

	if (x){
		x.onreadystatechange = function()			
		{		
			if (x.readyState == 4 && x.status == 200){
					el = document.getElementById('favorite');					
					el.innerHTML = "<span>Vote Processed</span>";
			}
		}
				
		x.open("GET", voteURL, true);	
		x.send(null);
	}

}
