function fillIt(obiect)
{
	if (obiect.value == '')
	{
		obiect.value = 'cauta un produs';
	}
}

function clearIt(obiect)
{
	if (obiect.value == 'cauta un produs')
	{
		obiect.value = '';
	}
}

function formAction(obi)
{
	cauta = document.getElementById('cauta-prod').value;
	cauta=cauta.split(" / ").join("-");
	cauta=cauta.split(" - ").join("-");
	cauta=cauta.split("- ").join("-");
	cauta=cauta.split(" -").join("-");
	cauta=cauta.split("   ").join("-");
	cauta=cauta.split("  ").join("-");
	cauta=cauta.split(" ").join("-");
	cauta=cauta.split("/").join("-");
	cauta=cauta.split(";").join("-");
	cauta=cauta.split("'").join("-");
	cauta=cauta.split("&").join("-si-");
	cauta=cauta.split("--").join("-");
	
	
	obi.action = obi.action + "cautare-"+cauta;
	
	if((cauta == "cauta-produs") || (cauta == ""))
		return false;
	
	cauta2 = document.getElementById('cauta-prod');
	if(cauta2.value.length < 3)
	{
		alert("Cuvantul cautat trebuie sa aiba minim 3 caractere.");
		cauta2.focus();
		return false;
	}
}


// cos

function modifCart(url,cheie,buc)
{
	document.location.href = url+'cosul-tau/modif-'+cheie+'-'+buc;
}

// comanda

function checkComanda()
{
	nume = document.getElementById('nume');
	if (nume.value == '')
	{
		alert("Va rugam completati numele");
		nume.focus();
		return false;
	}	

	cnp = document.getElementById('cnp');
	if (cnp.value == '')
	{
		alert("Va rugam completati CNP-ul");
		cnp.focus();
		return false;
	}	
	
	telefon = document.getElementById('telefon');
	if (!check_number(telefon.value,10))
	{
		alert("Va rugam completati numarul de telefon, 10 cifre");
		telefon.focus();
		return false;
	}	

	email = document.getElementById('email');
	if (email.value == '')
	{
  		alert("Va rugam completati adresa de e-mail");
		email.focus();		
		return false;	
	}
	
	if (email.value != '')
	{
		if(!check_email(email.value))
		{
			alert("Adresa de e-mail este incorecta");
		 	email.focus();
			return false;
		}	
	}	
	
	judet = document.getElementById('judet');
	if (judet.options[judet.selectedIndex].text == '...')
	{
		alert("Va rugam alegeti judetul");
		judet.focus();
		return false;
	}	
	
	loc = document.getElementById('loc');
	if (loc.value == '')
	{
		alert("Va rugam completati localitatea");
		loc.focus();
		return false;
	}	
	
	adresa = document.getElementById('adresa');
	if (adresa.value == '' || adresa.value.length < 5)
	{
		alert("Va rugam completati adresa");
		adresa.focus();
		return false;
	}
	
	termeni = document.getElementById('termeni');
	if(termeni.checked == false)
	{
		alert("Pentru a putea comanda trebuie sa fiti de acord cu termenii si conditiile rapunzel.ro");
		termeni.focus();
		return false;		
	}
}

function check_email(e) 
{
	ok = "1234567890qwertyuiop[]asdfghjklzxcvbnm.@-_QWERTYUIOPASDFGHJKLZXCVBNM";
	for(i=0; i < e.length ;i++)
	{
		if(ok.indexOf(e.charAt(i))<0)
		{ 
			return (false);
		}
	} 
	
	if (document.images) 
	{
		re = /(@.*@)|(\.\.)|(^\.)|(^@)|(@$)|(\.$)|(@\.)/;
		re_two = /^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$/;
		if (!e.match(re) && e.match(re_two)) 
		{
			return (-1);		
		} 
	}
}

function check_number(e,lung) 
{
	ok = "1234567890";
	if(e.length < lung)
	{
		return false;
	}
	for(i=0; i < e.length ;i++)
	{
		if(ok.indexOf(e.charAt(i))<0)
		{ 
			return (false);
		}
	}
	return (true);
}
		
