function GetElementById(ename)
{
	var obj;

	if (document.all)
	{
		eval("obj = document.all[\"" + ename + "\"]");
	}
	else if (document.layers)
	{
		eval("obj = document.layers[\"" + ename + "\"]");
	}
	else if (document.getElementById)
	{
		eval ("obj = document.getElementById (\"" + ename + "\")");
	}
	else
		obj =  undefined;

	return obj;
}

function goToPage(pageURL)
{
	document.location.href = pageURL;
}

function LoginChangeInstitution(obj)
{	
	window.location = 'index.php?action=login&iid=' + obj.options[obj.selectedIndex].value;
}

function CreateAccountChangeInstitution(obj)
{	
	window.location = 'index.php?action=createaccount&iid=' + obj.options[obj.selectedIndex].value;
}

function CreateAccountChangeGroup(obj)
{
	var iid = gup('iid');
		
	if (iid == "")
	{		
		window.location = 'index.php?action=createaccount&gid=' + obj.options[obj.selectedIndex].value;
	}
	else
	{		
		window.location = 'index.php?action=createaccount&iid=' + iid + '&gid=' + obj.options[obj.selectedIndex].value;	
	}
}

function gup( name )
{
  name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
  var regexS = "[\\?&]"+name+"=([^&#]*)";
  var regex = new RegExp( regexS );
  var results = regex.exec( window.location.href );
  
  if( results == null )
    return "";
  else
    return results[1];
}

function CheckUserAndPassword(obj)
{
	isValidForm = true;
	
	if (obj.user_name.value.length == 0)
	{
		isValidForm = false;
		alert("Lipseste nume utilizator");
		obj.user_name.focus();		
	}
	
	if (isValidForm && obj.user_pass.value.length == 0)
	{	
		isValidForm = false;
		alert("Lipseste parola");
		obj.user_pass.focus();
	}
	
	return isValidForm;
}


function checkCreateAccountForm(obj)
{
	isValidForm = true;
		
	if (!IsValidEmail(obj.user_email.value))
	{
		alert("Adresa de email nu este valida!");
		obj.user_email.focus();
		isValidForm = false;		
	}
	
	if (isValidForm && obj.user_pass.value.length < 5)
	{
		alert("Parola trebuie sa fie alcatuita din minim 5 caractere");
		obj.user_pass.value = "";
		obj.user_pass_retype.value = "";
		obj.user_pass.focus();
		isValidForm = false;
	}
	
	if (isValidForm && obj.user_pass.value != obj.user_pass_retype.value)
	{
		alert("Parolele nu sunt identice");
		obj.user_pass.value = "";
		obj.user_pass_retype.value = "";
		obj.user_pass.focus();
		isValidForm = false;
	}
		
	return isValidForm;
}

function checkForm(obj)
{
	isValidForm = true;	
	
	if (!IsValidEmail(obj.to_email.value))
	{
		alert("Adresa de email nu este valida!");
		obj.to_email.focus();
		isValidForm = false;		
	}
		
	return isValidForm;
}

function IsValidEmail(email)
{	
	invalidChars = " /:,;";
	
	if (email == "")
	{
		isValidForm =  false;
	}
	
	for (i = 0; i < invalidChars.length; i++)
	{
		badChar = invalidChars.charAt(i);
		if (email.indexOf(badChar, 0) > -1)
		{
			return false;
		}		
	}
	
	atPos = email.indexOf("@", 1);
	if (atPos == -1)
	{
		return false;
	}
	
	if (email.indexOf("@", atPos + 1) > -1)
	{
		return false;
	}
	
	periodPos = email.indexOf(".", atPos);
	if (periodPos == -1)
	{
		return false;
	}
	
	if (periodPos + 3 > email.length)
	{
		return false;
	}
	
	return true;
}

function checkQuestionError()
{
	isFormValid = true;
	
	if (ReportQuestionError.from_name.value == "")
	{
		isFormValid = false;
		msg = "Lipseste numele";
	}
	
	if (isFormValid && !IsValidEmail(ReportQuestionError.from_email.value))
	{
		isFormValid = false;
		msg = "Lipseste adresa de e-mail sau nu este valida";		
	}
	
	if (isFormValid  && ReportQuestionError.user_message.value == "")
	{
		isFormValid = false;
		msg = "Lipseste mesaj";		
	}
	
	if (!isFormValid)
	{
		alert(msg);
	}
	
	return isFormValid;	
}

function checkSkyToAFriend()
{
	isFormValid = true;
	
	if (SkyToFriend.from_name.value == "")
	{
		isFormValid = false;
		msg = "Lipseste numele expeditorului";
	}
	
	if (SkyToFriend.to_email.value == "")
	{
		isFormValid = false;
		msg = "Lipseste adresa de e-mail a destinatarului";		
	}
	
	if (SkyToFriend.from_message.value == "")
	{
		isFormValid = false;
		msg = "Lipseste mesaj";		
	}
	
	if (!isFormValid)
	{
		alert(msg);
	}
	
	return isFormValid;	
}

function checkTestToAFriend()
{	
	isFormValid = true;
	
	if (TestToFriend.from_name.value == "")
	{
		isFormValid = false;
		msg = "Lipseste numele expeditorului";
	}
		
	if (TestToFriend.to_email.value == "")
	{
		isFormValid = false;
		msg = "Lipseste adresa de e-mail a destinatarului";		
	}
	
	if (TestToFriend.from_message.value == "")
	{
		isFormValid = false;
		msg = "Lipseste mesaj";		
	}
	
	if (!isFormValid)
	{
		alert(msg);
	}
	
	return isFormValid;	
}

function PopUpWindow(url)
{
	win = window.open(url, "POPUP", "width=800,height=600,left=0,top=0,scrollbars=yes");
	win.focus();
	return false;
}

function IsValidForDetails()
{
	isValidForm = true;

	if (RunTest.test.value == "")
	{
		isValidForm = false;
		msg = "Mai intai alegeti testul a carui detalii va intereseaza!";
	}

	if (!isValidForm)
	{
		alert(msg);
	}

	return isValidForm;
}

function IsValidForRun()
{
	isValidForm = true;

	if (RunTest.test.value == "")
	{
		isValidForm = false;
		msg = "Mai intai alegeti testul pe care doriti sa-l rulati!";
	}

	if (!isValidForm)
	{
		alert(msg);
	}

	return isValidForm;
}

function IsValidForModules()
{
	isValidForm = true;

	if (ViewCategory.category.value == "")
	{
		isValidForm = false;
		msg = "Mai intai alegeti domeniul (categoria) a carui module va intereseaza!";
	}

	if (!isValidForm)
	{
		alert(msg);
	}

	return isValidForm;
}

function IsValidForStatistics()
{
	isValidForm = true;

	if (ViewStatistics.statistic.value == "")
	{
		isValidForm = false;
		msg = "Mai intai alegeti una dintre statisticile disponibile!";
	}

	if (!isValidForm)
	{
		alert(msg);
	}

	return isValidForm;
}

