function validate_user_form()
{
	var username = document.getElementById('username').value;
	var email = document.getElementById('email').value;
	var password = document.getElementById('password').value;
	var re_password = document.getElementById('re_password').value;
	
	error_string = "";
	
	if (username == null || username == "")
	{
		error_string += "Nu ati introdus username-ul.\r\n";
	}
	if (email == null || email == "")
	{
		error_string += "Nu ati introdus email-ul.\r\n";
	}
	else if (echeck(email)==false)
	{
		error_string += "Email-ul introdus nu este corect.\r\n";
	}
	if (password == null || password == "")
	{
		error_string += "Nu ati introdus parola.\r\n";
	}
	if (password != re_password)
	{
		error_string += "Parolele introduse nu coincid.\r\n";
	}
	
	if (error_string!="")
	{
		alert(error_string);
		return false;
	}
	else
	{
		return true;
	}
}

function validate_user_form_edit()
{
	var username = document.getElementById('username').value;
	var email = document.getElementById('email').value;
	var password = document.getElementById('password').value;
	var re_password = document.getElementById('re_password').value;
	
	error_string = "";
	
	if (username == null || username == "")
	{
		error_string += "Nu ati introdus username-ul.\r\n";
	}
	if (email == null || email == "")
	{
		error_string += "Nu ati introdus email-ul.\r\n";
	}
	else if (echeck(email)==false)
	{
		error_string += "Email-ul introdus nu este corect.\r\n";
	}
	if (password != re_password)
	{
		error_string += "Parolele introduse nu coincid.\r\n";
	}
	
	if (error_string!="")
	{
		alert(error_string);
		return false;
	}
	else
	{
		return true;
	}
}

function echeck(str) {

		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		if (str.indexOf(at)==-1){
		   return false;
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   return false;
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    return false;
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		    return false;
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    return false;
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		    return false;
		 }
		
		 if (str.indexOf(" ")!=-1){
		    return false;
		 }

 		 return true;				
}
function delete_this(id)
{
	document.getElementById('delete_id').value = id;
	document.getElementById('delete_form').submit();
}

function reset_this(id)
{
	document.getElementById('reset_id').value = id;
	document.getElementById('reset_form').submit();
}
function validate_answer(id)
{
	document.getElementById('selected_'+id).value = "yes";
}
function validate_poll_form(id)
{
	var ans = document.getElementById('selected_'+id).value;
	if (ans == "yes")
	{
		return true;
	}
	else
	{
		alert('Trebuie sa selectati un raspuns pentru a vota!');
		return false;
	}
}
function show_results(id,total)
{
	var height = total*50+150;
	var width = 344;
	
	window.open("/results/"+id, "results","menubar=0,scrollbars=1,resizable=0,width="+width+",height="+height+",left="+(screen.width-550)/2+",top="+(screen.height-550)/2);
}

// show floating div ********************************************************

var cX = 0; var cY = 0; var rX = 0; var rY = 0;
function UpdateCursorPosition(e){ cX = e.pageX; cY = e.pageY;}
function UpdateCursorPositionDocAll(e){ cX = event.clientX; cY = event.clientY;}
if(document.all) { document.onmousemove = UpdateCursorPositionDocAll; }
else { document.onmousemove = UpdateCursorPosition; }
function AssignPosition(d) {
if(self.pageYOffset) {
	rX = self.pageXOffset;
	rY = self.pageYOffset;
	}
else if(document.documentElement && document.documentElement.scrollTop) {
	rX = document.documentElement.scrollLeft;
	rY = document.documentElement.scrollTop;
	}
else if(document.body) {
	rX = document.body.scrollLeft;
	rY = document.body.scrollTop;
	}
if(document.all) {
	cX += rX; 
	cY += rY;
	}
d.style.left = (cX+10) + "px";
d.style.top = (cY+10) + "px";
}
function HideContent(d) {
if(d.length < 1) { return; }
document.getElementById(d).style.display = "none";
}
function ShowContent(d) {
if(d.length < 1) { return; }
var dd = document.getElementById(d);
AssignPosition(dd);
dd.style.display = "block";
}
function ReverseContentDisplay(d) {
if(d.length < 1) { return; }
var dd = document.getElementById(d);
AssignPosition(dd);
if(dd.style.display == "none") { dd.style.display = "block"; }
else { dd.style.display = "none"; }
}

// show floating div ********************************************************
