function openVideo(candidate){

	var settings = 'scrollbars=yes,width=345,height=290,scrollbar=no,resizable=yes,screenY=0,screenX=0,left=50,top=50';
	var windowName = 'video' + candidate;
	var videoWindow = window.open('video.php?candidate=' + candidate, windowName, settings);
	videoWindow.focus()

}

function vote(){

	var email;
	var zipcode;
	var vote;
	var optin;
	var message = '';

	if (document.ballot.email.value){
		email = document.ballot.email.value;
		if (!email.match('^.*?@.*?\..*?$'))	message += "\n" + 'A Valid Email Address';
	} else {
		message += "\n" + 'Email Address';
	}

	if (document.ballot.zipcode.value){
		zipcode = document.ballot.zipcode.value;
		if (zipcode.match('\d')){
			 message += "\n" + 'A Valid Zip Code';
		} else if (zipcode.length != 5) {
			 message += "\n" + 'A Valid Zip Code';
		}
	} else {
		message += "\n" + 'Zipcode';
	}


	if (document.ballot.candidate[0].checked || document.ballot.candidate[1].checked || document.ballot.candidate[2].checked){
		for (var i=0;i<document.ballot.candidate.length;i++) {
			if (document.ballot.candidate[i].checked) {
				vote = document.ballot.candidate[i].value;
			}
		}
	} else {
		message += "\n" + 'Ballot Choice';
	}

	if (document.ballot.privacy.checked){
		optin = document.ballot.optin.value;
	} else {
		message += "\n" + 'Acknolwedge and Agree to the Privacy Policy';
	}



	if (message){
		alert('Please provide the following to have your vote counted' + "\n" + '---' + message);
	} else {

		document.ballot.submit();

/*		var req = newXMLHttpRequest();

		// non-asynchronous, since we can't (and souldn't) do anything until we
		// get a response back from this request
		req.open("POST", "count.php", false);
		req.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
		req.send('email=' + email + '&zipcode=' + zipcode + '&vote=' + vote + '&optin=' + optin);

		if ( req.responseXML.getElementsByTagName('response') ){
	
			var response = req.responseXML.getElementsByTagName('response')[0];
	
			if ( response.getAttribute('result') == 'failed' ){
				alert('Voting failed!');
			} else {
				document.getElementById('vote').style.display = 'none';
				switch( response.getAttribute('result') ){
					case 'edwards':
						document.getElementById('candidate_choice').appendChild( document.createTextNode('Elizabeth Edwards') );
						break;
					case 'clinton':
						document.getElementById('candidate_choice').appendChild( document.createTextNode('Hillary Clinton') );
						break;
					case 'obama':
						document.getElementById('candidate_choice').appendChild( document.createTextNode('Barak Obama') );
						break;
				}
				document.getElementById('thankyou').style.display = 'block';
			}
	
		} else {
	
			alert('Voting failed!');
	
		}*/


	}

}
