/*
-------------------------------------------------------------------------
	JavaScript cross-browser solution for "get an Element by ID"
	Credits: lobo235 (http://www.netlobo.com/javascript_get_element_id.html) 
-------------------------------------------------------------------------  
*/

function returnObjById(id) 
{ 

    if (document.getElementById) {
		var returnVar=document.getElementById(id);
	} else {
		if (document.all) {
			var returnVar=document.all[id];
		} else {
			if (document.layers) {
				var returnVar = document.layers[id];
			}
		}
	}
	
	return returnVar;
}

function empty_fields(no)
{
	returnObjById('txtNume').value="";
	returnObjById('txtEmail').value="";
	returnObjById('cboSesiune').value=0;
	returnObjById('cboCategorie').value=0;
	returnObjById('txtContent').value="";
}

function getURLParam(strParamName)
{
	var strReturn = "";
	var strHref = window.location.href;
	
	if ( strHref.indexOf("?") > -1 )
	{
		var strQueryString = strHref.substr(strHref.indexOf("?")).toLowerCase();
		var aQueryString = strQueryString.split("&");
		
		for ( var iParam = 0; iParam < aQueryString.length; iParam++ )
		{
			if (aQueryString[iParam].indexOf(strParamName + "=") > -1 )
			{
				var aParam = aQueryString[iParam].split("=");
				strReturn = aParam[1];
				break;
			}
		}
	}
return strReturn;
}

function showThanks(mesaj)
{
	if (getURLParam(mesaj)!="")
	{
		if (getURLParam(mesaj)=="ok")
		{
			strAlert = "Intrebarea/sesizarea Dvs. a fost inregistrata cu succes! \n \n ";
			strAlert = strAlert + "In cel mai scurt timp ea va fi redirectata catre o persoana ";
			strAlert = strAlert + "\n competenta, care poate sa va ofere informatiile solicitate.";
			strAlert = strAlert + "\n \n Va multumim!";
			
			alert(strAlert);
		}
	}
}
		
function isEmail(fldval)
{
    if (fldval.length <= 0)
	{
		return true;
	}
	
    var splitted = fldval.match("^(.+)@(.+)$");
    
	if (splitted == null) return false;
	
	if(splitted[1] != null)
    {
		var regexp_user=/^\"?[\w-_\.]*\"?$/;
		
		if(splitted[1].match(regexp_user) == null) return false;
    }
    
	if (splitted[2] != null)
    {
		var regexp_domain=/^[\w-\.]*\.[A-Za-z]{2,4}$/;
		
		if(splitted[2].match(regexp_domain) == null)
		{
			var regexp_ip =/^\[\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\]$/;
			
			if(splitted[2].match(regexp_ip) == null) return false;
		}
      return true;
    }
return false;
}

function getValidare()
{
	var msgErr = "";
	var thisFrm = returnObjById('frmContact');
	
	/* nume si prenume */
	if (returnObjById('txtNume').value.length<3)
	{
		msgErr = msgErr+"\n - Numele Dvs. ar trebui sa aiba mai mult de 3 caractere!";
	} else {
		if (returnObjById('txtNume').value.indexOf(" ") == -1 || returnObjById('txtNume').value.indexOf(" ") == (returnObjById('txtNume').value.length - 1))
		{
		msgErr = msgErr+"\n - Trebuie sa va introduceti numele si prenumele (2 cuvinte)!";
		}
	}
	
	/* email */
	if (returnObjById('txtEmail').value.length<3)
	{
		msgErr = msgErr+"\n - Introduceti o adresa de email valida la care doriti sa primiti raspunsul!";
	} else {
		if (isEmail(returnObjById('txtEmail').value) == false)
		{
			msgErr = msgErr+"\n - Introduceti o adresa de email valida la care doriti sa primiti raspunsul!";
		}
	}

	/* sesiune */
	if (returnObjById('cboSesiune').value == "--- alege ---")
	{
		msgErr = msgErr+"\n - Alegeti o sesiune de concurs de rezidentiat!";
	}
	
	/* categorie */
	if (returnObjById('cboCategorie').value == "--- alege ---")
	{
		msgErr = msgErr+"\n - Alegeti o categorie pentru intrebarea/sesizarea Dvs.!";
	}
	
	/* continut */
	if (returnObjById('txtContent').value.length<3)
	{
		msgErr = msgErr+"\n - Trebuie sa formulati o intrebare clara!";
	}
	
	if (msgErr!="") {
		alert("ERORI CRITICE: \n"+msgErr);
	} else {
		thisFrm.submit();
	}

/* end function */	
}

