function axc(enviar, idrecibir, btn){
	var divrecibir=$(idrecibir);
	var botonsub=$(btn);
	var prueboRequest = new Request({
		method: 'get', 
		url: enviar,
		onRequest: function() {divrecibir.innerHTML='<img src="/images/loader.gif" />'; botonsub.disabled=true;}, 
		onSuccess: function(texto, xmlrespuesta){divrecibir.innerHTML = texto; botonsub.disabled=false;},
		onFailure: function(){ alert('Could not complete the operation, try again later\nDetails:\n\nDatabase conection failed.');return 0;}
	}).send(); 
}

function axc_1(enviar){
	var prueboRequest = new Request({
		method: 'get', 
		url: enviar,
		onRequest: function() {}, 
		onSuccess: function(texto, xmlrespuesta){},
		onFailure: function(){ alert('Could not complete the operation, try again later\nDetails:\n\nDatabase conection failed.');return 0;}
	}).send(); 
}

function axc_2(enviar, idrecibir, btn){
	var divrecibir=$(idrecibir);
	var botonsub=$(btn);
	var prueboRequest = new Request({
		method: 'get', 
		url: enviar,
		onRequest: function() {botonsub.disabled=true;}, 
		onSuccess: function(texto, xmlrespuesta){divrecibir.innerHTML = texto; botonsub.disabled=false;},
		onFailure: function(){ alert('Could not complete the operation, try again later\nDetails:\n\nDatabase conection failed.');return 0;}
	}).send(); 
}

function show_year(div_mostrar,div_recibir,make,model)
{
	//mostrar el div
		plieg(div_mostrar);
			axc('/ajax/show_year.php?make='+make+'&model='+model,div_recibir,'buSubmit');

	//y los demas si estan abiertos
		if($('search_cabtype').style.display!='none'){
			dplieg('search_cabtype');
			}
		if($('search_submit').style.display!='none'){
			dplieg('search_submit');
			}
	}
function show_model(div_mostrar,div_recibir,value)
{
	//mostrar el div
		plieg(div_mostrar);
		if(value!='')
			axc('/ajax/show_model.php?make='+value,div_recibir,'buSubmit');
		//si los demas estan abiertos ocultarlos
	if($('search_model').style.display!='none' && value=='')
			dplieg('search_model');
	if($('search_year').style.display!='none'){
			dplieg('search_year');
			}
	if($('search_cabtype').style.display!='none'){
			dplieg('search_cabtype');
			}
		if($('search_submit').style.display!='none'){
			dplieg('search_submit');
			}
	}
function show_cab_type(div_mostrar,div_recibir,value)
{
	//mostrar el div
		plieg(div_mostrar);
	//mostrar el submit
	plieg('search_submit');
		axc('/ajax/show_cabtype.php?id='+value,div_recibir,'buSubmit');
			
	}
	
function show_(div)
{
	plieg(div);
	}
	
function show_details(div_mostrar)
{
	if($(div_mostrar).style.display!='none'){
			dplieg(div_mostrar);
			}
	else
	{
		plieg(div_mostrar);
		}
	}
	
function addBasket(divrecibir,id_price,id_part,type_bakflip)
{
	//realizar la accion
	//cambiar el texto a processin
	$('btn_'+id_price).value='processing...';
	//cambiar el texto del div recibir
	$('btn_'+id_price).disabled=true;
		axc_2('/ajax/add_basket.php?id_price='+id_price+'&id_part='+id_part+'&type_bak='+type_bakflip,divrecibir,'show_cart');
	}
function deleteBasket(divrecibir,id_price,id_part,type_bakflip)
{
	//realizar
	$('btn_'+id_price).value='processing...';
	//cambiar el texto del div recibir
	$('btn_'+id_price).disabled=true;
		axc_2('/ajax/delete_basket.php?id_price='+id_price+'&id_part='+id_part+'&type_bak='+type_bakflip,divrecibir,'show_cart');
	}
	
function update_num_item(id_price,value)
{
	if ((!/^([0-9])*$/.test(value)) || (value=='0') || (value==''))
	{
		//no es numero entonces tenemos que validar otro numero
		alert('Please enter a whole number greater than zero');
		//devolver el focus al text
		$('txt_quantiti_'+id_price).focus();
		}
	else
	{
		//valor introducido correcto
		axc_1('/ajax/update_num_item.php?id='+id_price+'&num='+value);
		}
	}

function eliminar_item(id){
		//mandar a que se agregue en llista de ids a eliminar
		axc_1('/ajax/delete_item.php?id='+id);
	}
	
function update_basket(div_recibir)
{
		axc('/ajax/update_basket.php',div_recibir,'bu_chkout');
	}
	
function show_states(div_recibir,value,div_city,name)
{
	//axc
	axc('/ajax/states.php?value='+value+'&id_city='+div_city+'&name='+name,div_recibir,'bu_submit');
	//is is diferent of United States
	if(value!='United States')
	{
		$(div_city).innerHTML='<input type="text" name="city" id="city" value=""  />';
		}

	}
	
function show_cities(div_recibir,value,name)
{
		axc('/ajax/cities.php?state='+value+'&name='+name,div_recibir,'bu_submit');
	}
