function check_comment_form(form, captcha)
{
	var errors = '';
	if (form.comment_title.value.length < 5)
		errors += "Titlul este prea scurt.\r\n";
	if (form.comment.value.length < 5)
		errors += "Comentariul este prea scurt.\r\n";
	if (form.comment_rating.value == 0)
		errors += "Este necesar sa dati o nota articolului.\r\n";
//	if (form.captcha.value.length == 0)
//		errors += "Nu ati introdus codul din imagine.\r\n";

	if (errors.length)
	{
		alert(errors);
		return false;
	}

	return true;
}

function check_login(form)
{
	var errors = '';
	if (form.username.value.length == 0)
		errors += 'Campul "Nume utilizator" este obligatoriu'+"\r\n";
	if (form.password.value.length == 0)
		errors += 'Campul "Parola" este obligatoriu.'+"\r\n";

	if (errors.length)
	{
		alert(errors);
		return false;
	}

	return true;
}

function check_signup(form)
{
	var errors = '';
	if (form.username.value.length == 0)
		errors += 'Campul "Nume utilizator" este obligatoriu'+"\r\n";
	if (form.password.value.length == 0)
		errors += 'Campul "Parola" este obligatoriu.'+"\r\n";
	if (form.password2.value.length == 0)
		errors += 'Campul "Reintroduceti parola" este obligatoriu.'+"\r\n";
	if (form.password.value != form.password2.value)
		errors += '"Parola" si "Reintroduceti parola" trebuie sa fie identice.'+"\r\n";

	var email_err = check_email(form.email.value);
	if (email_err > 0)
		switch(email_err)
		{
			case 1 : errors += 'Campul "Email" este obligatoriu.'+"\r\n";
					break;
			case 2 : errors += 'Campul "Email" introdus nu este valid.'+"\r\n";
		}

	if (errors.length)
	{
		alert(errors);
		return false;
	}

	return true;
}

function change_rate(rate)
{
	document.add_comment.comment_rating.value = rate;

	for (var i = 1; i <= rate; i++)
		document.getElementById("rate_" + i).src = 'i/articol/stea_mare_portocalie.gif';

	for (var i = rate + 1; i <= 5; i++)
		document.getElementById("rate_" + i).src = 'i/articol/stea_mare.gif';
}

function highlight_rate(rate)
{
	for (var i = 1; i <= rate; i++)
		document.getElementById("rate_" + i).src = 'i/articol/stea_mare_portocalie.gif';

	for (var i = rate + 1; i <= 5; i++)
		document.getElementById("rate_" + i).src = 'i/articol/stea_mare.gif';
}

function out_highlight_rate(rate)
{
	for (var i = 1; i <= document.add_comment.comment_rating.value; i++)
		document.getElementById("rate_" + i).src = 'i/articol/stea_mare_portocalie.gif';

	for (var i = parseInt(document.add_comment.comment_rating.value) + 1; i <= 5; i++)
		document.getElementById("rate_" + i).src = 'i/articol/stea_mare.gif';
}

function GetXmlHttpObject()
{
	var xmlHttp = null;
	try
	{
		xmlHttp=new XMLHttpRequest();
	}
	catch (e)
	{
		try
		{
			xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (e)
		{
			xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
		}
	}
	return xmlHttp;
}

function vote_comment(vote, id_comment, id_user)
{
	var xmlHttp = GetXmlHttpObject();
	if (xmlHttp == null)
	{
		alert ("Your browser does not support AJAX!");
		return;
	}
	xmlHttp.onreadystatechange = function()
	{
		if(xmlHttp.readyState == 4)
		{
			var votes = xmlHttp.responseText;
			var votes_div = document.getElementById('comm_'+id_comment);
			var imgs = votes_div.getElementsByTagName('img');

			for (var i = 0; i < imgs.length; i++)
				imgs[i].setAttribute('onclick', 'alert(\"Ati votat deja acest comentariu.\");');

			var span = votes_div.getElementsByTagName('span')[0];
			span.innerHTML = votes;
			if (votes < 0)
				span.className = 'negative';
			else
				span.className = '';
		}
	}
	var vars = "?vote=" + vote + "&comment=" + id_comment + "&user=" + id_user;
	xmlHttp.open ("GET", "_vote_comment.php" + vars, true); // add vars
	xmlHttp.send (null);
}

function check_email(email)
{
	errors = 0;
	var ero="`=[];\',/\\#$%^&*()+{}:\"<>?| ";
	var ned="@.";
	var er=0;

	var a = email;
	if (a.length==0)
		errors = 1;
	else
		if (a.length<4)
			errors = 2;
		else
		{
			for (j=0; j<=ero.length-1; j++)
				if (a.indexOf(ero.substring(j,j+1))!=-1)
					er=1;
			for (j=0; j<=ned.length-1; j++)
			{
				aos = a.split(ned.substring(j,j+1));
				for (var i=0; i < aos.length-1; i++)
					if (aos[i]<1)
						er=1;
				if (a.indexOf(ned.substring(j,j+1))==-1)
					er=1;
			}
			if (er==1)
			errors = 2;
		}

	return errors;
}

var images = [];
var images_pos = 0;
var images_count = 0;

function slide_next_img()
{
	if ((images_pos + 1) < images_count)
	{
		images_pos++;
	}
	else
	{
		images_pos = 0;
	}
	if (images[images_pos])
	{
		document.getElementById("slide_big_image").src = images[images_pos]["path"];
		document.getElementById("img_desc").innerHTML = images[images_pos]["info"];
	}
}

function slide_prev_img()
{
	if ((images_pos - 1) >= 0)
	{
		images_pos--;
	}
	else
	{
		images_pos = images_count - 1;
	}
	if (images[images_pos])
	{
		document.getElementById("slide_big_image").src = images[images_pos]["path"];
		document.getElementById("img_desc").innerHTML = images[images_pos]["info"];
//		document.getElementById("slide_big_href").href = base_href + images[images_pos]["orig_path"];		
//		document.getElementById("MB_caption").innerHTML = images[images_pos]["name"];
	}
}

var oss_timerid = 0;
var oss_status = "stop";

function play_pause_ss()
{
	if (oss_status == "stop")
	{
		oss_status = "play";
		document.getElementById("play_pause_ss").innerHTML = "Pause";
		slideshow_me();
	}
	else
		pause_ss();
}

function pause_ss()
{
	oss_status = "stop";
	document.getElementById("play_pause_ss").innerHTML = "Play";
	clearTimeout(oss_timerid);
	oss_timerid = 0;
}

function slideshow_me()
{
	slide_next_img();
	clearTimeout(oss_timerid);
	oss_timerid = setTimeout("slideshow_me()", 3000);
}

function gallery_zoom(title, id, img_id, table, rel_path)
{
	Modalbox.show(rel_path + "_prod_gal.php?id=" + id + "&img_id=" + img_id + "&table=" + table,
		{title: title,
		width: 800 + 20,
		height: 625 + 70});
}

function change_page_article(article_id, page, div_id)
{
	var pages_div = document.getElementById(div_id);	
	var all_pages = 0;
	
	var pc = pages_div.getElementsByTagName('div');
	
	for (var i = 0; i < pc.length; i++)
		if (pc[i].id.substr(0, 5) == 'page_')
		{
			pc[i].style.display = 'none';
			all_pages++;
		}
			
	document.getElementById('page_'+page).style.display = 'block';
	var pages_content = '';
	if (page > 1)
		pages_content += '<a href="javascript://" onclick="change_page_article('+article_id+', '+(page-1)+', \''+div_id+'\');">pagina anterioara</a>';
	for (i = 1; i <= all_pages; i++)
	{
		if (i == page)
			pages_content += '<span>'+i+'</span>';
		else
			pages_content += '<a href="javascript://" onclick="change_page_article('+article_id+', '+i+', \''+div_id+'\');">'+i+'</a>';
	}
	if (page < all_pages)
		pages_content += '<a href="javascript://" onclick="change_page_article('+article_id+', '+(page+1)+', \''+div_id+'\');">pagina urmatoare</a>';
	
	document.getElementById('pages_links').innerHTML = pages_content + '<div style="clear: both;"><!-- --></div>';
	
	/*
	var xmlHttp = GetXmlHttpObject();
	if (xmlHttp == null)
	{
		alert ("Your browser does not support AJAX!");
		return;
	}
	xmlHttp.onreadystatechange = function()
	{
		if(xmlHttp.readyState == 4)
		{
			document.getElementById(div_id).innerHTML = xmlHttp.responseText;
		}
	}
	var vars = "?article=" + article_id + "&page=" + page +"&path=" + path;
	xmlHttp.open ("GET", path + "_article_pages.php" + vars, true); // add vars
	xmlHttp.send (null);
	*/
}

function modalbox_admin(href, table_id, row_id)
{
	var height = document.documentElement.clientHeight;
	var width  = document.documentElement.clientWidth;

	Modalbox.show("<iframe src='"+ href +"?collection=forum_topics&col_id_name=topic_id&table_id="+ table_id +"&row_id="+row_id+"&from_site=true' style='width: "+(width-120)+"px; height: "+(height-100)+"px; border: none;'></iframe>",
		{title: 'Admin Edit',
		width: width - 100,
		height: height - 50,
		overlayClose: true});
}