String.prototype.trim = function() {
return this.replace(/^\s+|\s+$/g, "");
}

String.prototype.rem_space = function()
{
	for (var i = this.length - 1; i>=0; i--)
	{
		return this.replace(/\s+/,"#");
	}
}


function sterge(id)
{
	var id;
	var url = "delete.php";
	var mytime = new Date().getTime();
	var valid_conf = confirm("Sterg inregistrarea cu numarul " + id+" ?");
	if (valid_conf == true)
	{
		new Ajax.Request(
			url,
			{ 
				method: 'post',
				parameters: { id:id,  mytime:mytime},
				onSuccess: function(transport)
				{
					var response = transport.responseText;
					$('raspuns').innerHTML = response;
					$('raspuns').show();
				}
			}
		);
	}
	else return false;
}

function caut_client()
{
	var id = $('nume_client').getValue();
	var nume = new Array();
	var adresa = $('adresa_client').getValue();
	var oras   = $('oras_client').getValue();
	var telefon = $('telefon_client').getValue();
	var email = $('email_client').getValue();
	//var categorie = $('categorie_client').getValue();
	var url = "cauta.php";
	var mytime = new Date().getTime();
	var client = 1;
	nume = id.trim();
	
	if (id && id.length > 3)
	{
		new Ajax.Request (
			url,
			{ 
				method: 'post',
				parameters: { client: client, id:id, nume:nume,  adresa: adresa, oras:oras, telefon:telefon, email:email,  mytime:mytime},
				onSuccess: function(transport)
				{
					var response = transport.responseText;
					$('raspuns').innerHTML = response;
					$('raspuns').show();
				}
			}
		);	
	}
	
	if (!id || id.length < 4)
	{
		$('raspuns').hide();
	}			
}

function caut_firma()
{
	var id = $('nume_firma').getValue();
	var url = "cauta.php";
	var cui = $('cui_firma').getValue();
	var nrc = $('nrc_firma').getValue();
	var adresa = $('adresa_firma').getValue();
	var oras   = $('oras_firma').getValue();
	var telefon = $('telefon_firma').getValue();
	var email = $('email_firma').getValue();
	//var categorie = $('categorie_firma').getValue();
	var mytime = new Date().getTime();
	var firma = 1;
	nume = id.trim();
	
	if (id && id.length > 3)
	{
		new Ajax.Request (
			url,
			{ 
				method: 'post',
				parameters: { firma:firma, id:id, nume:nume, adresa:adresa, oras:oras, telefon:telefon, email:email, cui: cui, nrc: nrc, mytime:mytime},
				onSuccess: function(transport)
				{
					var response2 = transport.responseText;
					$('raspuns').innerHTML = response2;
					$('raspuns').show(); 
				}
			}
		);	
	}
	
	if (!id || id.length < 3)
	{
		$('raspuns').hide();
	}
}

function set_client(client,oras,adresa,telefon,email,id)
{
	var client, oras, adresa, telefon, email, categorie, id;
	if (id)			$('id_client').value		= id;
	if (client)		$('nume_client').value 		= client;
	//if (categorie)	$('categorie_client').value = categorie;
	if (oras)		$('oras_client').value 		= oras;
	if (adresa)		$('adresa_client').value 	= adresa;
	if (telefon)	$('telefon_client').value 	= telefon;
	if (email)		$('email_client').value 	= email;
	//$('categorie_client').disable();
	$('oras_client').disable();
	$('adresa_client').disable();
	$('telefon_client').disable();
	$('email_client').disable();
	$('raspuns').hide();
}

function set_firma(firma,oras,adresa,telefon,email, cui, nrc, id)
{
	var id, firma, oras, adresa, telefon, email, categorie, cui, nrc;
	if (id)			$('id_firma').value			= id;
	if (firma)		$('nume_firma').value 		= firma;
	//if (categorie)	$('categorie_firma').value = categorie;
	if (oras)		$('oras_firma').value 		= oras;
	if (adresa)		$('adresa_firma').value 	= adresa;
	if (telefon)	$('telefon_firma').value 	= telefon;
	if (email)		$('email_firma').value 		= email;
	if (cui)		$('cui_firma').value		= cui;
	if (nrc)		$('nrc_firma').value		= nrc;
	//$('categorie_firma').disable();
	$('oras_firma').disable();
	$('adresa_firma').disable();
	$('telefon_firma').disable();
	$('email_firma').disable();
	$('cui_firma').disable();
	$('nrc_firma').disable();
	$('raspuns').hide();
}

function inchide(var_inchid)
{
	var var_inchid;
	if (var_inchid == 1)
	{
		//$('categorie_client').enable();
		$('oras_client').enable();
		$('adresa_client').enable();
		$('telefon_client').enable();
		$('email_client').enable();
	}
	if (var_inchid == 2)
	{
		//$('categorie_firma').enable();
		$('oras_firma').enable();
		$('adresa_firma').enable();
		$('telefon_firma').enable();
		$('email_firma').enable();
		$('cui_firma').enable();
		$('nrc_firma').enable();
	}
	$('raspuns').hide();
}


function mod_dict(dictionar, id)
{
	var url = "edit_dict.php";
	var dictionar, id;
	var mytime = new Date().getTime();
	new Ajax.Request(
	url,
	{ 
		method: 'post',
		parameters: { dictionar:dictionar, id:id,  mytime:mytime},
		onSuccess: function(transport)
		{
			var response = transport.responseText;
			$('tabele').hide();
			$('raspuns').innerHTML = response;
			$('raspuns').show(); 
		}
	}
	);
}


function campuri_obligatorii()
{
	var data = $('data').value;
	var comentariu = $('comentariu').value;
	if (!data && !comentariu)
	{
		alert ("Atentie! Campurile 'Data' si 'Comentariu' sunt obligatoriu de completat!");
		return false;
	}
	else 
	{
		if (!data)
		{
			alert ("Campul 'Data' este obligatoriu de completat!");
			return false;
		}
		if (!comentariu)
		{
			alert ("Campul 'Comentariu' este obligatoriu de completat!");
			return false;
		}
		if (data && comentariu)
		{
			return true;
		}
		//document.forms.adauga_inregistrare.submit();
	}
}

function submit_inreg()
{
	var nume_client = $('nume_client').value;
	var nume_firma = $('nume_firma').value;
	//var data = $('data').value;
	//var comentariu = $('comentariu').value;
	if (!nume_client && !nume_firma)
	{
		alert ("Atentie! Nu ati completat profilul clientului - persoana fizica sau juridica!");
		return false;
	}
	else
	{
		if (nume_firma)
		{
			var cui = $('cui_firma').value;
			if (!cui)
			{
				alert ("Campul 'CUI' este obligatoriu de completat pentru firme!");
				return false;
			}
			else 
			{
				var obligatorii = campuri_obligatorii();
				if (obligatorii == true)
				{
					document.forms.adauga_inregistrare.submit();
				}
				else
				{
					return false;
				}
			}
		}
		if (nume_client)
		{
			var obligatorii = campuri_obligatorii();
			if (obligatorii == true)
			{
				document.forms.adauga_inregistrare.submit();
			}
			else
			{
				return false;
			}
		}
	}
}



