// Buscador
var id_marca = 0;
var activeCmb = 0;

function submitForm(){
	var error = "";
	/*if( document.prodSerch.marca.value == "indistinto" ){
		error+=" Debe seleccionar marca \n";
	}*/
	if( document.prodSerch.search.length < 1 || document.prodSerch.search.value == ""){
		
		if( document.prodSerch.searchType.value == "indistinto" ){
			error+=" Debe seleccionar al menos un criterio de búsqueda o ingresar una palabra clave \n";
		}else{
			if( document.prodSerch.searchType.value == "tipo-producto" && document.prodSerch.categoria.value == "indistinto" ){
				error+=" Debe seleccionar un Tipo de Producto en particular \n";
			} else if ( document.prodSerch.searchType.value == "aplicacion" && document.prodSerch.categoria.value == "indistinto" ) {
				error+=" Debe seleccionar una Aplicación en particular \n";
			}
		}
	}
	
	if( error.length > 0){
		alert(error);
	}else{
		//alert( error.length );
		document.prodSerch.submit();
	}
}

function changeMarca(value){
	id_marca = value;
	if(activeCmb > 0){
		$.ajax({
				async:true,
				type: "POST",
				dataType: "html",
				contentType: "application/x-www-form-urlencoded",
				url:"ajax.php",
				data:"ajax="+activeCmb+"&id_marca="+id_marca,
				success:addSelect,
				timeout:4000,
				error:problemas
		});
	}
}

function searchCategorias(value){
	if( value=="tipo-producto"){
		var num = 3;
	}
	if( value=="aplicacion"){
		var num = 4;
	}
	activeCmb = num;
	$.ajax({
			async:true,
			type: "POST",
			dataType: "html",
			contentType: "application/x-www-form-urlencoded",
			url:"ajax.php",
			data:"ajax="+num+"&id_marca="+id_marca,
			success:addSelect,
			timeout:4000,
			error:problemas
    });
}
function addSelect(data){
	$("#ajaxType").html(data);
	$('#categoria').sSelect();
}
function addSelect2(data){
	$("#ajaxTypesub").html(data);
	$('#subcategoria').sSelect();
}
function problemas(data){
	alert(data);
}
function SearchSubcate(data,cate){
	if( data=="tipo-producto"){
		var num = 5;
	$.ajax({
			async:true,
			type: "POST",
			dataType: "html",
			contentType: "application/x-www-form-urlencoded",
			url:"ajax.php",
			data:"categoria="+cate+"&ajax="+num,
			success:addSelect2,
			timeout:4000,
			error:problemas
    });
	}
	
	if( data=="aplicacion"){
		var num = 6;
	$.ajax({
			async:true,
			type: "POST",
			dataType: "html",
			contentType: "application/x-www-form-urlencoded",
			url:"ajax.php",
			data:"categoria="+cate+"&ajax="+num,
			success:addSelect2,
			timeout:4000,
			error:problemas
    });
	}
}
