var xmlHttp=createXmlHttpRequestObject();

function createXmlHttpRequestObject(){

	var xmlHttp;

	try{
		xmlHttp=new XMLHttpRequest();
	}catch(e){
		xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
	}
	
	if(!xmlHttp)
		alert("Error creating the XMLHttpRequest object.");
	else
		return xmlHttp;
		
}

function sendReqest(id){
	var validate=confirm('Please press OK to confirm this selection.');
	if(validate){
		if(xmlHttp.readyState == 4 || xmlHttp.readyState == 0){
			xmlHttp.open("GET","ajax_ballot?id="+id,true);
//			xmlHttp.onreadystatechange=receiveResponse;
			xmlHttp.send(null);
		}
		alert('Ballot Successed!\nThank you for your ballot!');
	}
}

function favourite(id){
	var validate=confirm('Are you sure you would like to add this candidate as one of your Favorites?');
	if(validate){
		if(xmlHttp.readyState == 4 || xmlHttp.readyState == 0){
			xmlHttp.open("GET","ajax_favourite.php?action=insert&id="+id,true);
			xmlHttp.send(null);
		}
		/* alert('This candidate has been added to your Favorites.\n(Select Our Favorites from the main menu to view all saved Favorites.)'); */
	}
}

function redirectjs(link)
{
	window.location.href = 'my_favourite_nanny.php';
}

function unfavourite(id){
	var validate=confirm('Are you sure you would not like to keep this candidate as a Favorite?');
	if(validate){
		if(xmlHttp.readyState == 4 || xmlHttp.readyState == 0){
			xmlHttp.open("GET","ajax_favourite.php?action=delete&id="+id,true);
			xmlHttp.send(null);
		}
		alert('This candidate has been removed from your Favorites.\n(Select Browse Candidates from the main menu to browse our list of candidates.)');
		document.getElementById('1949').style.display = "none";
		alert('blablabla');
	}
}


/*
function receiveResponse(){
	var str='<select id=\'sec\' name=\'sec\'>';
	if(xmlHttp.readyState==4){
		if(xmlHttp.status==200){
			xmlResponse=xmlHttp.responseXML;
			xmlDocumentElement=xmlResponse.documentElement;
			data=xmlDocumentElement.lastChild.lastChild.firstChild.data;
			var root=xmlResponse.documentElement;
			for(var i=0;i<root.childNodes.length;i++){
				var ele=root.childNodes[i];
				str+="<option value="+ele.firstChild.firstChild.data+">"+ele.lastChild.firstChild.data+"</optioin>";
			}
			str+="</select>";
			document.getElementById('test').innerHTML=str;
		}
	}
}
*/
//http://61.241.19.117:8080/America_design