function submitWillVote() {
	var willVote = $('input[name=willvote]:checked').val();
	var userAnswer = 0;
	if (willVote === undefined) {
		alert("hm...nu vrei sa selectezi ceva totusi inainte sa apesi pe buton ?");
		return;
	}

	var twitterAnswerId = Math.floor(Math.random() * 10) + 1;

	if ('yes' == willVote) {
		userAnswer = "yes";
		$("#twittermesajda").text('Eu merg la vot pentru ca ' + $("#mtda" + twitterAnswerId).html() + ' - tu ? - http://www.votornot.ro');
	}
	if ('no' == willVote) {
		userAnswer = "no";
		$("#twittermesajnu").text('Eu nu merg la vot pentru ca ' + $("#mtnu" + twitterAnswerId).html() + ' - tu ? - http://www.votornot.ro');
		 
	}

	if ('yes' == willVote) {
		$('#left').html($('#twitterda').html());
		$('#twitterda').html("");
		$("#rmtda" + twitterAnswerId).attr('checked', true);
		
	}
	if ('no' == willVote) {
		$('#left').html($('#twitternu').html());
		$('#twitternu').html("");
		$("#rmtnu" + twitterAnswerId).attr("checked", true);
	}

	// $('#left').html($('#responseaftervotelogo').html());

	if ('yes' == willVote) {
		$('#yesvote').fadeOut("slow", function() {
			$('#yesvote').html(parseInt($('#yesvote').html()) + 1);
		}).fadeIn("slow");

	}

	if ('no' == willVote) {
		$('#novote').fadeOut("slow", function() {
			$('#novote').html(parseInt($('#novote').html()) + 1);
		}).fadeIn("slow");
	}

	$.post("vote.php", {
		what : userAnswer
	}, function(data) {
	}, "text");

}

function submitVoteForPresident(what, fake) {

	var presidentId = $('#presidentId').html();

	if (fake == 0) {
		var htmlTemp = $('#submitVoteDiv').html();
		$('#submitVoteDiv').html($('#commentinput').html());
		$('#commentinput').html(htmlTemp);
		$('#comment').focus();
	} else {
		$('#submitVoteDiv').html($('#trisat').html());
	}

	$.post("vote4us.php", {
		what : what,
		presidentId : presidentId
	}, function(data) {

	}, "text");

}

function submitEmail() {

	var email = $('#contactEmail').val();
	var subject = $('#contactSubject').val();
	var message = $('#contactMessage').val();

	if (email.length == 0) {
		$('#contactEmail').focus();
		return;
	}
	if (subject.length == 0) {
		$('#contactSubject').focus();
		return;
	}
	if (message.length == 0) {
		$('#contactMessage').focus();
		return;
	}

	$('#contactform').html($('#aftercontact').html());

	$.post("contactUs.php", {
		email : email,
		subject : subject,
		message : message
	}, function(data) {

	}, "text");
}

function updateChars() {
	var length = $("#comment").val().length;
	if (length > 140) {
		$("#comment").val($("#comment").val().substring(0, 140));
	} else {
		$("#charCount").html(140 - length);
	}
}

function sendComment(fake) {

	var name = $("#name").val();
	var comment = $("#comment").val();
	var presidentId = $('#presidentId').html();

	if (name.length == 0) {
		$("#name").focus();
		return;
	}

	if (name == "cum te cheama ?") {
		$("#name").focus();
		return;
	}
	if (comment.length == 0) {
		$("#comment").focus();
		return;
	}

	// var htmlTemp = $('#submitVoteDiv').html();
	// $('#submitVoteDiv').html($('#another').html());
	// $('#commentinput').html(htmlTemp);

	if (fake == 1) {
		$('#commentinput').html($('#another').html());
	} else {
		$('#submitVoteDiv').html($('#another').html());
	}

	$('#topCommentName').html(name);
	$('#topCommentMessage').html(comment);

	$.post("comment.php", {
		name : name,
		message : comment,
		presedinteID : presidentId
	}, function(data) {
		$('#comments').load('getcomments.php?presidentId=' + presidentId);
	}, "text");
}

function refreshComment() {
	var presidentId = $('#presidentId').html();

	$.get("presedinti/getonecomment.php", {
		presidentId : presidentId
	}, function(data) {
		var retArr = data.split("__#__#__");
		$('#topCommentName').html(retArr[0]);
		$('#topCommentMessage').html(retArr[1]);
	}, "text");
}

function showPage(page) {
	var presidentId = $('#presidentId').html();
	$('#comments').load(
			'getcomments.php?presidentId=' + presidentId + "&pageno=" + page);
}

function closeThankYouMessage() {
	$('#left').html($('#voteresults').html());
}

function submitComanda() {

	var email = $('#tricouEmail').val();
	var marime = $('#tricouMarime').val();
	var culoare = $('#tricouCuloare').val();
	var tipOm = $('#tricouTipOm').val();

	if (email.length == 0) {
		$('#tricouEmail').focus();
		return;
	}

	$('#comandaForm').html($('#aftercomanda').html());

	$.post("comandaTricouri.php", {
		email : email,
		marime : marime,
		culoare : culoare,
		tipOm : tipOm
	}, function(data) {

	}, "text");
}

function refreshCities() {
	var presidentId = $('#presidentId').html();
	var firstCity = $('#orase1').val();
	var secondCity = $('#orase2').val();
	$("#cities").load(
			"presedinti/httpgetcitynumbers.php?firstCity=" + firstCity
					+ "&secondCity=" + secondCity + "&presedinteId="
					+ presidentId);
}