$(document).ready(function(){

$('.btSus').click(function(){
	$('html, body').animate({scrollTop:0}, 'slow');
});
	
/*formulare*/
	
	$('#addComments').click(function(){
	  $('<div class="blackBox"></div>').appendTo('body'),
	$('#wComment').show();
	  $('.blackBox').css('height',$(document).height());
   });
	$('#closeComment').click(function(){
		$('#loadingSendComment').hide();
		$('#addcomment1').show();
		$('#finishcomment').hide()
		$('#wComment').hide();
		$('.blackBox').hide();
   });
	
	$('#sendContact').click(function(){
	  $('<div class="blackBox"></div>').appendTo('body'),
	$('#wContact').show();
	  $('.blackBox').css('height',$(document).height());
   });
	$('#closeContact').click(function(){
     $('#wContact').hide();
	  $('.blackBox').hide();
   });
	
/*search input*/
	
	$('.inputSearch , .searchForm input, .newsletterForm input').each(function() {
		 var default_value = this.value;
		 $(this).focus(function() {
			  if(this.value == default_value) {
					this.value = '';
			  }
		 });
		 $(this).blur(function() {
			  if(this.value == '') {
					this.value = default_value;
			  }
		 });
	});

/*galerie foto*/
	

	
/*lightbox*/




});

function addComment(){
//	document.getElementById('comentariuliadd').innerHTML = 'Trimitere...';
	$('#addcomment1').hide();
	$('#loadingSendComment').show();
	nume = document.getElementById('nume').value;
	mesaj = document.getElementById('mesaj').value;
	articol = document.getElementById('articol').value;
//	captcha = document.getElementById('captcha').value;
	$.ajax({
		type: "POST",
		url: "ajaxresponses/addComment.html",
//		data: "nume="+nume+"&mesaj="+mesaj+"&captcha="+captcha,
		data: "nume="+nume+"&mesaj="+mesaj+"&articol="+articol,
		success: function(msg){
			switch (msg){
				case 'succes':    	//$('#wComment').hide();
								  	//$('.blackBox').hide();
/*
									nrcomentarii = document.getElementById('nrComentarii').value;
									nrcomentarii++;
									if (nrcomentarii == 1){
										newTextComent = "1 comentariu";
									} else {
										newTextComent = nrcomentarii+" comentarii";
									}
									document.getElementById('nrComents').innerHTML = newTextComent;
									document.getElementById('nrComentarii').value = nrcomentarii;
									document.getElementById('nume').value = '';
									document.getElementById('mesaj').value = '';
//									document.getElementById('captcha').value = '';
									document.getElementById('eroare_comment').innerHTML = '';
									document.getElementById('eroare_comment').style.display = 'none';
									oldComent = document.getElementById('newComment').innerHTML;
									document.getElementById('newComment').innerHTML = '<div class="commentEntry" style="margin-bottom:10px;"><div class="commentEntryAutor" style="margin:0 0 5px">'+nume+'<span class="commentEntryReport" style="padding-bottom:1px;"> | acum mai putin de un minut</span></div><p>'+mesaj+'</p></div>'+oldComent;
*/
									
									$('#addcomment1').hide();
									$('#loadingSendComment').hide();
									$('#finishcomment').show();



								  	break;
								  
				case 'error_nume':	
									$('#loadingSendComment').hide();
									$('#addcomment1').show();
									document.getElementById('eroare_comment').innerHTML = 'Introdu numele tau.';
									document.getElementById('eroare_comment').style.display = 'block';
								  	break;
									
				case 'error_mesaj':	
									$('#loadingSendComment').hide();
									$('#addcomment1').show();
									document.getElementById('eroare_comment').innerHTML = 'Introdu mesajul tau.';
									document.getElementById('eroare_comment').style.display = 'block';
								  	break;
									
				case 'error_cap':	
									$('#loadingSendComment').hide();
									$('#addcomment1').show();
									document.getElementById('eroare_comment').innerHTML = 'Codul captcha nu este corect.';
									document.getElementById('eroare_comment').style.display = 'block';
								  	break;
									
				default:		  	$('#loadingSendComment').hide();
									$('#addcomment1').show();
									$('#addcomment1').hide();
									$('#finishcomment').show();
									window.setTimeout(function() {
										$('#addcomment1').show();
										$('#finishcomment').hide()
										$('#wComment').hide();
									  	$('.blackBox').hide();
									}, 3000);
								  	break;
			}
		}
	});
}

function addRating(vote){
	articol = document.getElementById('articol').value;
	$.ajax({
		type: "POST",
		url: "ajaxresponses/addVote.html",
		data: "vote="+vote+"&articol="+articol,
		success: function(msg){
			document.getElementById('vot_inregistrat').style.display = 'block';
		}
	});
}

function abonate(){
	mail = document.getElementById('newsletter_mail').value;
	if ((mail == 'adresa e-mail') || (mail == '')){
		mesajtext = 'Introdu o adresa de email valida.';
		document.getElementById('errorNl').innerHTML = mesajtext;
	} else {
		$.ajax({
			type: "POST",
			url: "ajaxresponses/abonare.html",
			data: "email="+mail,
			success: function(msg){

				switch (msg){
					case 'ok': 			mesajtext = '<font color="#129006">Va multumim pentru abonare.</font>';
										document.getElementById('errorNl').innerHTML = mesajtext;
										break;
					case 'bad_mail':	mesajtext = 'Adresa de e-mail invalida.';
										document.getElementById('errorNl').innerHTML = mesajtext;
										break;
					default:			mesajtext = 'Aceasta adresa este deja abonata la newsletter.';
										document.getElementById('errorNl').innerHTML = mesajtext;
										break;
				}
			}
		});
	}
	

}
