var obj;

function add2 ( form, showcounty, showcity ) {
	if ( form.inactive.value.length == 0 ) {
		if(form.adtitle.value.length == 0){
			alert("Va rugam completati titlul anuntului...");
			form.adtitle.focus();
			return;
		}
		if(form.adtext.value.length == 0){
			alert("Va rugam completati textul anuntului...");
			form.adtext.focus();
			return;
		}
	
		if ( typeof ( form.price ) != "undefined" ) {
		
			if(form.price.value.length > 0 && !isReal(form.price)){
				alert("Va rugam introduceti un pret corect...");
				form.price.focus();
				return;
			}
		
			if(form.price.value.length > 0 && form.valuta.selectedIndex == 0){
				alert("Va rugam selectati valuta corespunzatoare pretului introdus...");
				form.valuta.focus();
				return;
			}
			
		}
		
		if ( showcounty + "" == "1" ) {
			if(form.countyid.selectedIndex == 0){
				alert("Va rugam selectati un judet...");
				form.countyid.focus();
				return;
			}
		}		
		obj = document.getElementById("countyid").options[form.countyid.selectedIndex]	
	
		if(obj.text != "Bucuresti"){
			if(form.city.value.length == 0 && showcity + "" == "1"){
				alert("Va rugam completati localitatea...");
				form.city.focus();
				return;
			}
		}
		if(form.contactname.value.length == 0){
				alert("Va rugam completati numele de contact...");
				form.contactname.focus();
				return;
		}
		if ( form.contactphone.value.length == 0 && form.contactmail.value.length == 0 ) {
				alert("Va rugam completati numarul de telefon sau adresa de e-mail...");
				form.contactphone.focus();
				return;
		}
		if ( form.contactmail.value.length > 0 && !isMail ( form.contactmail ) ) {
				alert("Va rugam introduceti o adresa de mail corecta...");
				form.contactmail.focus();
				return;
		}
		
		if ( form.validation.value.length > 0) {
			ret = false;
			eval ( form.validation.value );
			if ( ret ) return;
		}
		
		if ( !form.accord.checked ) {
				alert("Pentru a depune un anunt pe AnuntGratis.ro trebuie sa fiti de acord cu termenii si conditile de utilizare!");
				form.accord.focus();
				return;
		}
	
		form.inactive.value = "1";
		
		form.act.value = "addAd";
		form.submit();
	}
}

function changeCounty ( form ) {

	obj = document.getElementById("countyid").options[form.countyid.selectedIndex]
	if(obj.text == "Bucuresti"){
		document.getElementById("tr_city").style.display = "none";
		document.getElementById("tr_sector").style.display = "";
	}
	else{
		document.getElementById("tr_city").style.display = "";
		document.getElementById("tr_sector").style.display = "none";
	}

}

function keyUp ( form, maxcharsno ) {
	no = form.adtext.value.length;
	count = maxcharsno - no;
	if ( count < 0 ) {
		form.adtext.value = form.adtext.value.substr(0, maxcharsno);
		count = 0;
	}
	form.charscount.value = count + "";
}

function keyDown ( form, maxcharsno ) {
	no = form.adtext.value.length;
	count = maxcharsno - no;
	if ( count < 0 ) {
		form.adtext.value = form.adtext.value.substr(0, maxcharsno);
		count = 0;
	}
	form.charscount.value = count + "";
}

function keyUpField ( field, counter, maxcharsno ) {
	no = field.value.length;
	count = maxcharsno - no;
	if ( count < 0 ) {
		field.value = field.value.substr(0, maxcharsno);
		count = 0;
	}
	counter.value = count + "";
}

function keyDownField ( field, counter, maxcharsno ) {
	no = field.value.length;
	count = maxcharsno - no;
	if ( count < 0 ) {
		field.value = field.value.substr(0, maxcharsno);
		count = 0;
	}
	counter.value = count + "";
}

function proposeField ( form ) {
	if ( form.fieldproposal.value.length == 0 ) {
		alert ( "Va rugam scrieti propunerea dumneavoastra!" );
		form.fieldproposal.focus();
		return;
	}
	if ( form.fieldproposal.value.length > 500 ) {
		alert ( "Propunerea dumneavoastra nu trebuie sa contina mai mult de 500 caractere!" );
		form.fieldproposal.focus();
		return;
	}
	if ( form.nume.value.length == 0 ) {
		alert ( "Va rugam introduceti numele dumneavoastra!" );
		form.nume.focus();
		return;
	}
	if ( form.email.value.length == 0 ) {
		alert ( "Va rugam introduceti adresa de e-mail!" );
		form.email.focus();
		return;
	}
	
	if ( !isMail ( form.email ) ) {
		alert ( "Va rugam introduceti o adresa de e-mail corecta !" );
		form.email.focus();
		return;
	}
	
	form.act.value = "proposeField" ;
	form.submit();
}


function deleteContact ( form ) {
	form.contactname.value = '';
	form.contactphone.value = '';
	form.contactmail.value = '';
	form.pastreazadatele.checked = false;
}
