function writeDate(data){
	var date = data;
	var splitdate = new Array();
	splitdate = date.split("/");
	
	document.write('<p class="dte"><span> '+splitdate[0]+' </span> '+splitdate[1]+'.'+splitdate[2]+'</p>');
}

function searchTagBlogPost(){
	
		document.getElementById('tagsSearchForm').action='/cautare-taguri-blogpost.aspx';
		document.getElementById('tagsSearchForm').submit();
	
}
	
function doHitEnterTagsBlog(e) {
	var keynum;
	if(window.event){ // IE
		keynum = e.keyCode;
	} else if(e.which){ // Netscape/Firefox/Opera
		keynum = e.which;
	}
	if (keynum == 13){
		if(document.getElementById('src_string').value.length == 0){
			alert('Introduceti cuvantul cautat!');
			document.getElementById('src_string').focus();
			return false;
		} else {
			searchTagBlogPost();
		}
		return false;
	} else {
		return true;
	}
}

function postComment(status){
	var sw=0;
	if ((document.getElementById('comm_nume').value.length == 0 || document.getElementById('comm_nume').value == 'Nume') && (sw==0)){
		alert('Va rugam introduceti numele!');
		document.getElementById('comm_nume').focus();
		sw=1;
	} 
	if ((isEmail(document.getElementById('comm_email').value) == false) && (sw==0)){
		alert('Va rugam introduceti o adresa de e-mail valida!');
		document.getElementById('comm_email').focus();
		sw=1;
	}
	if ((document.getElementById('comm_mesaj').value.length == 0 || document.getElementById('comm_mesaj').value == 'Parerea ta...') && (sw==0)){
		alert('Va rugam introduceti comentariul!');
		document.getElementById('comm_mesaj').focus();
		sw=1;
	} 	
	if ((document.getElementById('recaptcha_response_field').value.length == 0) && (sw==0)){
		alert('Va rugam introduceti codul de securitate!');
		document.getElementById('recaptcha_response_field').focus();
		sw=1;
	} 	
	if (sw==0){
		document.getElementById('commentFormPost').submit();
	}
}

function editComment(status, cid){
	if (status == "Approuve") {
		$('#actionText').val('Approuve');
		$('#commentId').val(cid);
	} else if (status == "Disapprouve") {
		$('#actionText').val('Disapprouve');
		$('#commentId').val(cid);
	} else if (status == "Delete") {
		$('#actionText').val('Delete');
		$('#commentId').val(cid);
	}
	document.getElementById('commentFormEdit').submit();
}

function votePoll(logged){
	//alert(window.location);
	//alert(window.location.pathname);
	document.getElementById('formPoll').action=window.location.pathname+"#sondaj";
	document.getElementById('formPoll').submit();
}

/** users login **/

function doLogin(eventL){
	var sw=0;
	if(eventL=='login'){
		var user = document.getElementById('UserName').value;
		var passwd = document.getElementById('Password').value;
		
		if (((user.length==0) || (user =='Utilizator')) && (sw==0)){
			alert('Va rugam introduceti utilizatorul!');
			$('#UserName').focus();
			sw = 1;
			return false;
		} 
		if (((passwd.length==0) || (passwd=='Parola')) && (sw==0)){
			alert('Va rugam introduceti parola!');
			$('#Password').focus();
			sw=1;
			return false;
		}
		if(sw==0){	
			document.getElementById('actionLogin').value='Login';
			document.getElementById('loginForm').submit();
		}
	}
	if(eventL=='forgot_password'){
		if(sw==0){
			document.getElementById('usrname_forgot').value = (document.getElementById('usrname_forgot').value).replace(/^\s*|\s*$/g,'');
			if (document.getElementById('usrname_forgot').value.length == 0 || (document.getElementById('usrname_forgot').value=='Adresa email')){
				alert('Va rugam introduceti utilizatorul!');
				document.getElementById('usrname_forgot').focus();
				return false;
			}
			else{
				document.getElementById('actionLogin').value='ForgotPassword';
				document.getElementById('loginForm').submit();	
			}	
		}		
	}	
	if(eventL=='logout'){
		if(sw==0){	
			document.getElementById('logoutForm').submit();
		}		
	}
}

function doHitEnterLogin(e,eventL) {
var keynum;
	if(window.event) { // IE
		keynum = e.keyCode;
	} else if(e.which) { // Netscape/Firefox/Opera
		keynum = e.which;
	}
	if (keynum == 13){
		var sw=0;
		
		if(eventL=='login'){
			var user = document.getElementById('UserName').value;
			var passwd = document.getElementById('Password').value;
			
			if (((user.length==0) || (user =='Utilizator')) && (sw==0)){
				alert('Va rugam introduceti utilizatorul!');
				$('#UserName').focus();
				sw = 1;
				return false;
			} 
			if (((passwd.length==0) || (passwd=='Parola')) && (sw==0)){
				alert('Va rugam introduceti parola!');
				$('#Password').focus();
				sw=1;
				return false;
			}
			if(sw==0){	
				document.getElementById('loginForm').submit();
			}
		}
		return false;
	}
return true;
}



/** forgot password **/

function writeMonth(selected_month, selected_year, hasArticleLastYear){
	var d = new Date();
	var current_year = d.getFullYear();
	var last_year = current_year - 1;
	
	var months = new Array("", "Ianuarie", "Februarie", "Martie", "Aprilie", "Mai", "Iunie", "Iulie", "August", "Septembrie", "Octombrie", "Noiembrie", "Decembrie");
	for ((hasArticleLastYear > 0)?i=last_year:i=current_year;i<=current_year;i++){
		if(hasArticleLastYear > 0){
			if(i == last_year){
				document.write('<ul class="categs" style="display: none;" id="tab_a1">');
			} else {
				document.write('<ul class="categs" id="tab_a2">');
			}
			
			for (var m=1;m<=12;m++) {
				if(selected_month.length == 0) {
					document.write('<li><a href="arhiva-blogposturi.aspx?luna='+m+'&amp;an='+i+'" title="'+months[m]+'">'+months[m]+'</a></li>');
				} else {
					document.write('<li><a href="arhiva-blogposturi.aspx?luna='+m+'&amp;an='+i+'" '+(selected_month==m && selected_year==i ? ' style="text-decoration: underline;" ' : '') + ' title="'+months[m]+'">'+months[m]+'</a></li>');
				}
			}
			document.write('</ul>');
		} else {
			document.write('<ul class="categs" id="tab_a1">');
		
			for (var m=1;m<=12;m++) {
				if(selected_month.length == 0) {
					document.write('<li><a href="arhiva-blogposturi.aspx?luna='+m+'&amp;an='+i+'" title="'+months[m]+'">'+months[m]+'</a></li>');
				} else {
					document.write('<li><a href="arhiva-blogposturi.aspx?luna='+m+'&amp;an='+i+'" '+(selected_month==m && selected_year==i ? ' style="text-decoration: underline;" ' : '') + ' title="'+months[m]+'">'+months[m]+'</a></li>');
				}
			}
			document.write('</ul>');			
		}
	}
}

function insertYear(an){
	document.getElementById("currentYear").value=an;	
}

function writeYear(selected_year,hasArticleLastYear){
	var d = new Date();
	var current_year = d.getFullYear();
	var last_year = current_year - 1;
	document.write('<ul id="tabs_a">')
	
	if(selected_year.length == 0){
		if(hasArticleLastYear > 0){
			document.write('<li><a href="javascript: void(0);" id="a1">'+last_year+'</a></li>')
			document.write('<li><a href="javascript: void(0);" id="a2" class="on">'+current_year+'</a></li>')
		} else {
			document.write('<li><a href="javascript: void(0);" id="a1" class="on">'+current_year+'</a></li>')
		}
	} else {
		if(hasArticleLastYear > 0){
			document.write('<li><a href="javascript: void(0);" id="a1" '+(selected_year==last_year ? ' class="on" ' : '') + '>'+last_year+'</a></li>')
			document.write('<li><a href="javascript: void(0);" id="a2" '+(selected_year==current_year ? ' class="on" ' : '') + '>'+current_year+'</a></li>')
		} else {
			document.write('<li><a href="javascript: void(0);" id="a1" '+(selected_year==current_year ? ' class="on" ' : '') + '>'+current_year+'</a></li>')
		}
	}	

	document.write('</ul>')
}

$(document).ready(function() {
	$('#tabs_a a').click(function () {
		$('#tabs_a a').removeAttr('class');
		$(this).attr('class','on');
	
		var a_id = $(this).attr('id');
		var sel_div = '#tab_'+a_id;
	
		$('#tabs .categs').attr('style','display: none;');
		$(sel_div).attr('style','display: block;');
	});
});

function writeMonths(selected_month, selected_year){

	var d = new Date();
	var current_year = d.getFullYear();
	
	var months = new Array("", "Ianuarie", "Februarie", "Martie", "Aprilie", "Mai", "Iunie");

	document.write('<ul class="month_one">');
	for (var m=1;m<=6;m++) {
		if(selected_month.length == 0) {
			document.write('<li><a href="arhiva-blogposturi.aspx?luna='+m+'&amp;an='+current_year+'" title="'+months[m]+'">'+months[m]+'</a></li>');
		} else {
			document.write('<li><a href="arhiva-blogposturi.aspx?luna='+m+'&amp;an='+current_year+'" '+(selected_month==m && selected_year==current_year ? ' style="text-decoration: underline;" ' : '') + ' title="'+months[m]+'">'+months[m]+'</a></li>');
		}
	}
	document.write('</ul>');
	
	var months2 = new Array("", "Iulie", "August", "Septembrie", "Octombrie", "Noiembrie", "Decembrie");

	document.write('<ul class="month_two">');
	for (var m=1,x=7;m<=6;m++,x++) {
		if(selected_month.length == 0) {
			document.write('<li><a href="arhiva-blogposturi.aspx?luna='+x+'&amp;an='+current_year+'" title="'+months2[m]+'">'+months2[m]+'</a></li>');
		} else {
			document.write('<li><a href="arhiva-blogposturi.aspx?luna='+x+'&amp;an='+current_year+'" '+(selected_month==x && selected_year==current_year ? ' style="text-decoration: underline;" ' : '') + ' title="'+months2[m]+'">'+months2[m]+'</a></li>');
		}
	}
	document.write('</ul>');	
	
}

/** blogRoll **/

function addBlogRoll(){
	var sw=0;
	if((document.getElementById('titleBlogRoll').value.length == 0 || document.getElementById('titleBlogRoll').value == "Nume") && (sw==0)){
		$('#titleBlogRoll').focus();
		sw = 1;
		return false;
	} 
	if((document.getElementById('linkBlogRoll').value.length == 0 || document.getElementById('linkBlogRoll').value == "Adresa website") && (sw==0)){
		$('#linkBlogRoll').focus();
		sw = 1;
		return false;
	} 
	if(sw==0){	
		document.getElementById('addBlogRoll').submit();
	}
}

/** add article **/

function addBlogpost(){
	document.getElementById('fromBlogpost').submit();
}

/** newsletter **/

function isEmail(string){
	if (string.search(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/) != -1){
		return true;
	} else {
		return false;
	}
}

function newsletter(){	
	var sw=0;
	if ((isEmail(document.getElementById('email_newsletter').value) == false) && (sw==0)){
		alert('Va rugam introduceti o adresa de e-mail valida!');
		document.getElementById('email_newsletter').focus();
		sw=1;
	}
	if (sw==0){	
		document.getElementById('newsletterForm').action='#newsletter';
		document.getElementById('newsletterForm').submit();
	}
}

/** contact **/

function checkForm(){
	var sw=0;	
	if ((document.getElementById('c_nume').value.length == 0 || document.getElementById('c_nume').value == "Numele") && (sw==0)){
		alert('Va rugam introduceti numele! \n');
		document.getElementById('c_nume').focus();
		sw=1;
		return false;
	}
	if (isEmail(document.getElementById('c_email').value) == false && (sw==0)) {
		alert('Va rugam introduceti o adresa de e-mail valida! \n');
		document.getElementById('c_email').focus();
		sw=1;
		return false;
	}
	if ((document.getElementById('c_mesaj').value.length == 0)){
		alert('Va rugam introduceti mesajul! \n');
		document.getElementById('c_mesaj').focus();
		sw=1;
		return false;
	}
	if (sw==0) {
		document.getElementById('formContact').submit();
	} else {
		alert('Eroare trimitere formular!');
	}		
}

function deleteItem(id){
	document.getElementById('itemToDelete').value=id;
	document.getElementById('formItemDelete').action='#blogroll';
	document.getElementById('formItemDelete').submit();
}

function deleteBlogpost(){
	document.getElementById('fromBlogpost').submit();
}
