$(document).ready(function() {	
	$('#email').bind('keyup click blur focus change paste', function() {
       var itemValue = $('#email').val();
        var emailData = {sEmail: itemValue, test: 'email'}
         $.post('ajax/form_ck.php', emailData, function(data){
			if (data != false) {
				$(".custom-advice").addClass("error_div");
				$(".custom-advice").html('<p><em><strong>Error:</strong></em> This email address exist in database.</p>');
				$('#email').val('');
			}else{
				$(".custom-advice").removeClass("error_div");
				$(".custom-advice").html('&nbsp;');
			}
		})
    });
    
    $('#next_2').bind('click', function() {
    	
    	var checkValue = $('#tos:checked').val();
    	if(checkValue == null) {
    		$(".custom-advice").addClass("error_div");
			$(".custom-advice").html('<p><em><strong>Error:</strong></em> You must agree to the Terms and Conditions.</p>');
    		
    	}
    	
    	
    });
    
    $('#tos').bind('click', function() {
    	
    	var checkValue = $('#tos:checked').val();
    	if(checkValue != null) {
    		$(".custom-advice").removeClass("error_div");
				$(".custom-advice").html('&nbsp;');
    	}
    
    });
    
	
	$('#youtube').bind('blur change', function() {
       var itemValue = $('#youtube').val();
       var youtubeData = {sYoutube: itemValue, test: 'youtube'}
         $.post('ajax/form_ck.php', youtubeData, function(data){
			if (data != false) {
				$(".custom-advice").addClass("error_div");
				$(".custom-advice").html('<p><em><strong>Error:</strong></em> The Youtube code is incorect.</p>');
				$('#youtube').val('');
			}else{
				$(".custom-advice").removeClass("error_div");
				$(".custom-advice").html('&nbsp;');
			}
		})
    });
	
	
	$("#words_to").bind('keyup click blur focus change paste', function() {
		var maxWords = 1000;
		
		var numWords = jQuery.trim($(this).val()).split(' ').length;
		var numCh = jQuery.trim($(this).val()).length-2;
		if($(this).val() === '') {
			numWords = 0;
		}
		if(numWords <= maxWords) {
			var rWords = maxWords - numWords;
			$("#count_w").html(rWords + ' of 1000 words remaining');
		}else{
			$(this).val($(this).val().substr(0, numCh));
			return false;
		}
		
	});
			
});

function ch_vote(){
	$("#vote_content").html('<a href="record.php?go=error" class="tu_iframe simulare" toptions="width=534,height=158,title=YOU\'VE ALREADY VOTED,layout=quicklook,shaded=1,resizable=0" title="Vote" id="vote"><img src="images/vote_but.png" width="53" height="33" /></a>');
}

