//++ filter functions START
   function filter_display_change(pos, type, cnt)
   {
	//var filter_icon = document.getElementById("filter_icon_"+pos);
	for(i=1; i<=cnt; i++)
	{
		var details = document.getElementById("filter_values_"+i);
		
		if (details.style.display == "none" && i==pos)
		{
			//filter_icon.innerHTML = "";
			details.style.display = "inline";
		}
		else
		{
			//filter_icon.innerHTML = "";
			details.style.display = "none";
		}
	}
	
   }
   
   function clear_filters(){
   	
  	 x = document.getElementById('filterBody').getElementsByTagName("input");
  	 
  	 for(i=0; i<=x.length; i++ ){
  	 if(x[i].checked) document.getElementById(x[i].id).checked = false;
  	 }
   		
   }
   
   function show_filter_opt(iter,action){
   		key = 'filter_opt_';
   		if(action==1){
   			key = key + iter
   			show_lnk = 'show_lnk_'+ iter
   			document.getElementById(key).style.display = "inline";
   			
   			document.getElementById(show_lnk).style.display = "none";
   		}
   		else{
   			key = key + iter
   			show_lnk = 'show_lnk_'+ iter
   			document.getElementById(key).style.display = "none";
   			document.getElementById(show_lnk).style.display = "inline";
   		}
   }
//-- filter functions END

//++ firms START
function goToUrl(url){
	document.location = url;
}
//++ firms START

//++ sort START
function set_sort_order(field, order){
	var frm = document.forms['sort'];
	frm.sort_order.value = field + " " + order;
	frm.submit();
}
//-- sort END

//++ autogugest START (global)
function enable_autosugest(){
	// daca categoria nu e selectata
	var options1 = {
	script: "search_product_ajax2.php?json=true&ccid_advsearch=&",
	varname: "prodsearch2",
	json: true
	};
	var as1 = new bsn.AutoSuggest('prodsearch2', options1);
	
	//Pentru cautare normala
	var options2 = {
	script: "search_product_ajax.php?json=true&",
	varname: "prodsearch",
	json: true
	};
	var as2 = new bsn.AutoSuggest('prodsearch', options2);

	//autosugest pentru localitatea de facturare / livrare
	var options3 = {
	script: "search_city_ajax.php?json=true&",
	varname: "localitate",
	json: true
	};
	var as31 = new bsn.AutoSuggest('b_localitate', options3);
	var as32 = new bsn.AutoSuggest('s_localitate', options3);		
}
function enable_autosugest_ajax(){
   setTimeout("enable_autosugest()", 1000);
}

//-- autosugest END

//++ basket START
/* - ca sa o folosesc dau replace la numele functiei reloadpage_ajax in tot fisierul basket_ajax.tpl */
function reloadpage_ajax_dummy(action)
{
	frm = document.getElementById("basket");
	//frm.action = debug_frm_ajax_action
	frm.reload_page.value = action;
	frm.submit();
}
/**/ 
function cart_display_change(pos, type){
	var details = document.getElementById("cart_values_"+pos);
	if (details.style.display == "none"){
		details.style.display = "inline";
	}else{
		details.style.display = "none";
	}
}
		
function check_user_type(val){
	
	if (val == 1){
		document.getElementById('contact_info_firma').style.display = 'none';								
		document.getElementById('contact_info_pf').style.display = 'inline';				
		
		//keep just one field with the correct name
		document.getElementById('b_cui_firma').name = 'b_cui_firma';
		document.getElementById('b_cui_pf').name = 'b_cui';
		
		
	}else {
		document.getElementById('contact_info_firma').style.display = 'inline';
		document.getElementById('contact_info_pf').style.display = 'none';
		//keep just one field with the correct name
		document.getElementById('b_cui_pf').name = 'b_cui_pf';
		document.getElementById('b_cui_firma').name = 'b_cui';
		
	}
}

function check_address_type(){
	
	value = document.getElementById('adresa_livrare').style.display;
	if (value == 'block'){
		document.getElementById('adresa_livrare').style.display = 'none';
	}else if (value == 'none') {
		document.getElementById('adresa_livrare').style.display = 'block';
	}
}


function toogle_shipping_address(isSame){
	if (isSame)
		document.getElementById('adresa_livrare').style.display="none";
	else 
		document.getElementById('adresa_livrare').style.display="block";		
}

function hide_transport(x){
	var val = x
	if (val == '0'){						
		document.getElementById("no_shipping_box").style.display="none";
	}
	if (val == '1'){						
		document.getElementById("no_shipping_box").style.display="block";						
	}
}

function ajax_validation(type){
	document.getElementById('ajax_validation_message').innerHTML = VALIDATION_MSG_PLEASE_WAIT
	document.getElementById('ajax_validation_message').style.display = "block";				
	setTimeout("basket_ajax_validation('"+type+"', " + VALIDATION_MAX_RETRIES + ")", 100);
}	
//NOTE: functia foloseste niste variabile care sunt setate in basket_nou / basket_confirmation
function basket_ajax_validation(type, iterations) {
	xmlHttp1=GetXmlHttpObject()
	if (xmlHttp1==null) {
		alert ("Browser does not support HTTP Request")
		return
	}		
	//NOTE: am pus functia sa lucreze sincron pentru ca oricum nu doresc 
	// sa fac alte operatii cat timp se executa

	var isValid = false;
	var params;
	var response;
	
	params = "type="+type;
	//open connection, set headers and send parameters
	xmlHttp1.open("post", "basket_ajax_validation.php", false);
	//Send the proper header information along with the request
	xmlHttp1.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	xmlHttp1.setRequestHeader("Content-length", params.length);
	xmlHttp1.setRequestHeader("Connection", "close");	 
	xmlHttp1.send(params);

	response = xmlHttp1.responseText;
	if (response == "[_RESULT_NOT_AVAILABLE_]"){		
		if (iterations > 1){
			setTimeout("basket_ajax_validation('"+type+"', " + (iterations - 1)+ ")", VALIDATION_RETRY_TIMEOUT);
			return
		} else {
			response = VALIDATION_MSG_TIMEOUT
		}
	} else if (response == "[_SYNCHRONIZATION_COMPLETE_]"){
		document.location = document.location;
	} else {
		document.getElementById('ajax_validation_message').innerHTML = response;
	}
}

function update_tooltip(ctrl_id){
	var ctrl = document.getElementById(ctrl_id);
	var ctrl_info = document.getElementById(ctrl_id + "_info");
	ctrl.title = ctrl.options[ctrl.selectedIndex].title;
	if (ctrl_info) ctrl_info.innerHTML = ctrl.title;
}
//-- basket END

//++ manage_company_oreders START
function change_status_item(id, current_status, new_status){
	var frm = document.getElementById("frm_manage_orders");
	frm.action.value = 'change_item_status';
	frm.order_id.value = id;
	frm.current_status.value = current_status;
	frm.new_status.value = new_status;
	frm.submit();
}
function edit_order(id, current_status){
	var frm = document.getElementById("frm_manage_orders");
	frm.action.value = 'edit_order';
	frm.order_id.value = id;
	frm.current_status.value = current_status;
	frm.submit();	
}
function export_orders(){
	var frm = document.getElementById("frm_manage_orders");
	frm.action.value = 'export_orders';
	frm.submit();	
}
//-- manage_company_oreders END

//++ product_detail START
function liciteaza_form(product){
	var exp = product.split("_");
	var pcid = exp[1]
	var qty = document.getElementById("nr_buc").value;
	
	if(isNaN(qty) || qty == ''){
	 alert("Cantitatea nu este valida!");
	 return false;
	}
	//if(qty == ''){
	// alert("Cantitatea nu este valida!");
	// return false;
	//}
	
	//alert(product);
	document.forms[product].action = "catalog_licitate.php";
	document.forms[product].submit();
	
}
//-- product_detail START

//++ advanced_search START
//just submit the form, it will refresh because no button was pressed
function adv_search_refresh(){
	frm = document.forms["form_advanced_search"];
	frm.submit();
}
//-- advanced_search END
