var url = '/';
var timeout_newsletter;
function cauta_plus() {
	var cauta_div = $('cauta_licitatii_hot');
	var plus = $('plus');
	var h = cauta_div.getStyle("height").toInt();
	var new_h, alt, inner;
	if (h == 15) {
		new_h = 26;
		title = 'Mai Putine Produse Hot';
		inner = '-';
	}
	else {
		new_h = 15;
		title = 'Mai Multe Produse Hot';
		inner = '+';
	}
//	cauta_div.tween('height', new_h);
	cauta_div.setStyle("height").new_h;
	plus.innerHTML = inner;
	plus.title = title;
	return false;
}
function check_username(){
	new Ajax.Request(url + 'check-username/' + $('username').value + '/', {
	  method: 'get',
	  onSuccess: function(transport) {
	  	$('div_username').style.display = 'block';
	    var notice = $('div_username');
	    notice.update(transport.responseText);
	  }
	});
}
function adauga_cpv_cat(){
	selindex = $('cpv_cat').selectedIndex;
	cat_id = $('cpv_cat').options[selindex].value;
	new Ajax.Request(url + 'cauta-cpv-cat-add/' + cat_id + '/' + $('cpviduri_cat').value + '/', {
	  method: 'get',
	  onSuccess: function(transport) {
	  	$('cpv_cat_lista').style.display = 'block';
	    var notice = $('cpv_cat_lista');
	    notice.update(transport.responseText);
	  }
	});
}
function sterge_cpv_cat(cat_id){
	new Ajax.Request(url + 'cauta-cpv-cat-del/' + cat_id + '/' + $('cpviduri_cat').value + '/', {
	  method: 'get',
	  onSuccess: function(transport) {
	    var notice = $('cpv_cat_lista');
	    notice.update(transport.responseText);
	  }
	});
}
function refresh_cpv_cat(){
	new Ajax.Request(url + 'cauta-cpv-cat-refresh/' + $('cpviduri_cat').value + '/', {
	  method: 'get',
	  onSuccess: function(transport) {
	  	if ($('cpviduri_cat').value != '') $('cpv_cat_lista').style.display = 'block';
	    var notice = $('cpv_cat_lista');
	    notice.update(transport.responseText);
	  }
	});
}
function cauta_tip_anunt(){
	var selindex = $('tip_anunt').selectedIndex;
	var tip_anunt = $('tip_anunt').options[selindex].value;
	if (tip_anunt == '1' || tip_anunt == '4'){
		$('div_tip_achizitie_1').style.display = 'block';
		$('div_tip_achizitie_2').style.display = 'none';
		$('div_tip_achizitie_3').style.display = 'none';
		$('div_localitate').show();
	}
	else if (tip_anunt == '8') {
			$('div_tip_achizitie_1').style.display = 'none';
			$('div_tip_achizitie_2').style.display = 'none';
			$('div_tip_achizitie_3').style.display = 'block';
			$('div_localitate').hide();
	}
	else {
		$('div_localitate').show();
		if (tip_anunt == '6'){
			$('div_tip_achizitie_2').style.display = 'block';
			$('div_tip_achizitie_1').style.display = 'none';
			$('div_tip_achizitie_3').style.display = 'none';
		}
		else {
			$('div_tip_achizitie_1').style.display = 'none';
			$('div_tip_achizitie_2').style.display = 'none';
			$('div_tip_achizitie_3').style.display = 'none';
		}
	}
}
function newsletter_status(){
	new Ajax.Request(url + 'newsletter-status/', {
	  method: 'get',
	  onSuccess: function(transport) {
	    var notice = $('newsletter_status');
	    notice.update(transport.responseText);
	  }
	});
}
function newsletter_add_nelogat(){
	var email = $('newsletter_email').value;
	$('newsletter_mesaj').style.display = 'block';
	if (email == '') {
		$('newsletter_mesaj').innerHTML = 'Introduceti adresa de email.';
	}
	else {
		new Ajax.Request(url + 'newsletter-add-nelogat/' + email + '/' , {
		  method: 'get',
		  onSuccess: function(transport) {
		    var notice = $('newsletter_');
		    notice.update(transport.responseText);
		  }
		});
	}
}
function newsletter_add_logat(abonare){
	new Ajax.Request(url + 'newsletter-add-logat/' + abonare + '/' , {
	  method: 'get',
	  onSuccess: function(transport) {
	    var notice = $('newsletter_');
	    notice.update(transport.responseText);
	  }
	});
}
function hide_after_seconds(id, seconds){
	clearTimeout(timeout_newsletter);
	timeout_newsletter = setTimeout("hide('"+ id +"')", seconds);
}
function hide(id){
	$(id).style.display = 'none';
}
function localitate_autocomplete(){
	new Ajax.Autocompleter("localitate", "localitate_autocomplete", url + "localitate-autocomplete/");
}
function vezi_categorii(){
	if ($('categorii_cpv').style.display == 'block'){
		$('categorii_cpv').style.display = 'none';
		$('vezi_categorii').innerHTML = 'Vezi Categorii';
		$('vezi_categorii').title = 'Vezi Categorii';
	}
	else{
		$('categorii_cpv').style.display = 'block';
		$('vezi_categorii').innerHTML = 'Ascunde Categorii';
		$('vezi_categorii').title = 'Ascunde Categorii';
	}
}
function submitenter(myfield,e)
{
	var keycode;
	if (window.event) keycode = window.event.keyCode;
	else if (e) keycode = e.which;
	else return true;
	
	if (keycode == 13)
	   {
	   myfield.form.submit();
	   return false;
	   }
	else
	   return true;
}
