function noError(){return true;}
window.onerror = noError;

var vurl = window.top.location.toString();

// start my functions
// Strafe

function blog_add()
{
	var blogbody = document.getElementById('blog_form');
	if (blogbody.blog_titlu.value != "" && blogbody.blog_categorie.options[blogbody.blog_categorie.selectedIndex].value != "")
	{
		return true;
	}
	else
	{
		alert('Toate campurile sunt obligatorii !');
		return false;
	}
}

function poze_comentariu_sterge(o)
{
	document.getElementById('pozacomentariuhidden').value = o.value;
	o.value = "";
}
function poze_comentariu_revino(o)
{
	if (o.value == "")
	{
		o.value = document.getElementById('pozacomentariuhidden').value;
	}
}

// end my functions

window.onload = function() {



function preiaObjectDinHTTP() {
	var xhr = false;
	if (window.ActiveXObject) {
		try {
			xhr = new ActiveXObject("Msxml2.XMLHTTP");
		} catch(e) {
			try {
				xhr = new ActiveXObject("Microsoft.XMLHTTP");
			} catch(e) {
				xhr = false;
			}
		}
	} else if (window.XMLHttpRequest) {
		try {
			xhr = new XMLHttpRequest();
		} catch(e) {
			xhr = false;
		}
	}
	return xhr;
}

function isEmail(str) {
	var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	return (filter.test(str) ? true : false);
}


	if(document.getElementById('autentificare')) {
		var vrluser = document.getElementById('lutilizator');
		var vrlpass = document.getElementById('lparola');

		vrluser.onfocus = function()  { vrluser.style.cssText = 'background:#818181'; }
		vrluser.onblur = function()  { vrluser.style.cssText = ''; }
		vrluser.setAttribute("autocomplete", "off");

		vrlpass.onfocus = function()  { vrlpass.style.cssText = 'background:#818181'; }
		vrlpass.onblur = function()  { vrlpass.style.cssText = ''; }
		vrlpass.setAttribute("autocomplete", "off");

		document.getElementById('autentificare').onsubmit = function() {
			var er = '';
			var err = 'Va rugam completati campurile!';
			var vrluserv = vrluser.value;
			var vrlpassv = vrlpass.value;

			if (!isEmail(vrluserv)) {
				er = 'x';
				vrluser.style.cssText = "color: #000; background: #ECBFC6; border: 1px solid #91020C;";
				vrluser.onfocus = function()  { vrluser.style.cssText = 'color:#000;background:#F5E0E4'; }
				vrluser.onblur = function()  { vrluser.style.cssText = 'color:#000;background:#ECBFC6'; }
			} else {
				vrluser.style.cssText = '';
			}


			if (vrlpassv.replace(/^\s+|\s$/g, '').length < 6 || vrlpassv.replace(/^\s+|\s$/g, '').length > 50) {
				er = 'x';
				vrlpass.style.cssText = "color: #000; background: #ECBFC6; border: 1px solid #91020C;";
				vrlpass.onfocus = function()  { vrlpass.style.cssText = 'color:#000;background:#F5E0E4'; }
				vrlpass.onblur = function()  { vrlpass.style.cssText = 'color:#000;background:#ECBFC6'; }
			} else {
				vrlpass.style.cssText = '';
			}


			if (er != 'x') {
				var request = preiaObjectDinHTTP();
					if (request) {

						request.onreadystatechange = function() {
							if (request.readyState == 4) {
								if (request.status == 200) {
									if(request.responseText != "") {
										er = 'x';
										vrluser.style.cssText = "color: #000; background: #ECBFC6; border: 1px solid #91020C;";
										vrluser.onfocus = function()  { vrluser.style.cssText = 'color:#000;background:#F5E0E4'; }
										vrluser.onblur = function()  { vrluser.style.cssText = 'color:#000;background:#ECBFC6'; }

										vrlpass.style.cssText = "color: #000; background: #ECBFC6; border: 1px solid #91020C;";
										vrlpass.onfocus = function()  { vrlpass.style.cssText = 'color:#000;background:#F5E0E4'; }
										vrlpass.onblur = function()  { vrlpass.style.cssText = 'color:#000;background:#ECBFC6'; }

										alert('Date incorecte');

									} else {
										vrluser.style.cssText = '';
										vrlpass.style.cssText = '';
										window.location.href = vurl;
										return true;
									}
								}
							}
						};

						params = 'user='+vrluserv+'&pass='+strL(vrlpassv)+'&action=rlog';
						request.open("POST", "../server.php", true);
						request.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
						request.send(params);
						return false;
					}

			} else alert(err);


			return false;
		}
	}

	$('.showPicOnHover').hover(function(){
		try {

			var href = $(this).attr('href');
			var userId = href.substring(href.lastIndexOf('/') + 1, href.lastIndexOf('.'));

		  var response = $.ajax({
				url: "../ajax.php",
				type: "POST",
				async: false,
				data: ({getPhotoId : 1, userId : userId})
			 }
			).responseText;

			// document.write('poze/thumbs/' + userId + '_'  + photoId + '.jpg');

			var array = response.split('|')


			return overlib('<img src="' +  array[0] + '" alt="" style="margin:' + (48 + (100 - array[2]) / 2) +'px auto 0 auto;display:block;"/>',
										 BELOW, LEFT, TEXTCOLOR, '#ffffff', TEXTSIZE, 2,
										 BACKGROUND, '../bule_simple.png' , FGCOLOR, ' ',
										 WIDTH, 112, HEIGHT , 155
			);

		} catch (e) {
			alert(e);
		}
	} , function(){
		return nd();
	});

	try {

		if ($('.rating').length > 0) {

			function getRating(section, id)
			{

				var response =  $.ajax({
					type: 'POST',
					url: '../ajax.php',
					data: ({getRating: 1, section: section, id: id}),
					cache: false,
					async: false
				}).responseText;

				// alert(response);

				var arr = response.split('|');
				var rating = arr[0];
				var procent = rating * 20;
				var numar_voturi = arr[1];
				var text = rating + ' / 5; voturi: ' + numar_voturi;


				$('#' + section + '-' +  id).next('.rating-info').remove();
				$('#' + section + '-' +  id).after('<div class="rating-info" title="' + text + '">' + text + '</div>');
				$('#' + section + '-' +  id + ' .current-rating').css('width', procent + '%');

			}

			$('.rating').each(function(){
				var arr = $(this).attr('id').split('-');
				var section = arr[0];
				var id = arr[1];
				getRating(section, id);
			});

			$('.rating a').click(function() {

				var parent = 	$(this).parents('ul.rating');
				var arr = parent.attr('id').split('-');
				var section = arr[0];
				var id = arr[1];

				if ($.cookie(section + '-' + id) != 'votat') {
					var response = $.ajax({
						type: 'POST',
						url: '../ajax.php',
						data: ({voteaza: 1, section: section, id: id, vot: $(this).text()}),
						cache: false,
						async: false
					}).responseText;

					if (response == 'succes') {
						// $.cookie(section + '-' + id, 'votat');
						parent.find('li:not(.current-rating)').remove();
						getRating(section, id);
						alert('Va multumim pentru vot');
					} else if (response == 'notLoggedIn') {
						alert('Trebuie sa fiti logat pentru a vota');
					} else if (response == 'voteOwn') {
						alert('Nu va puteti vota propriul profil');
					}

				} else {
					alert('Ati votat deja..');
				}
			});

		}
	} catch (e) {
		alert(e);
	}

	$('#menu li').hover(function(){
		if ($(this).find('ul').css('display') == 'none') {
			$(this).find('ul').slideToggle();
		}
	}, function(){
		if ($(this).find('ul').css('display') == 'block') {
			$(this).find('ul').slideToggle();
		}
	});

	$('#menu li li').hover(function(){
		$(this).css('background-color', '#BF3E4D');
	}, function(){
		$(this).css('background-color', '');
	});

}
