var uiCategoria=0;
function fLimpiaCb(uiValor){
	
	if (uiValor==1){
		sGenera="";
		sGenera+="<select name=\"cmp2\" id=\"cmp2\" class=\"divList\" onchange=\"fCargaCategoria();\" >";
		sGenera+="<option value=\"-1\" >Seleccione una opci&oacute;n</option>";
		sGenera+="</select>";
	}else if (uiValor==2){
		sGenera="";
		sGenera+="<select name=\"cmp3\" id=\"cmp3\" class=\"divList\" onchange=\"fCargaSubCategoria();\" >";
		sGenera+="<option value=\"-1\" >Seleccione una opci&oacute;n</option>";
		sGenera+="</select>";
	}else if (uiValor==3){
		sGenera="";
		sGenera+="<select name=\"cmp4\" id=\"cmp4\" class=\"divList\" >";
		sGenera+="<option value=\"-1\" >Seleccione una opci&oacute;n</option>";
		sGenera+="</select>";
	}
	fGeneraDato("divTipo",sGenera);
}
function fLimpiar(){
	document.getElementById("cmpNombre").value="";
	document.getElementById("cmpTelefono").value="";
	document.getElementById("cmpMail").value="";
	document.getElementById("cmp1").value="";
	document.getElementById("cmp6").value="";
	document.getElementById("cmpImage").value="";
	document.getElementById("cmpImageDb").value="n/d";
}
function fAviso_carga_cb(){
	uiCategoria=0;
	uiCantidad = arrTipo.length
	//alert(uiCantidad);
	sGenera="";
	sGenera+="<select name=\"cmp2\" id=\"cmp2\" class=\"divList\" onchange=\"fCargaCategoria();\" >";
	sGenera+="<option value=\"-1\" >Seleccione una opci&oacute;n</option>";
	
	for (var n = 1; n<=uiCantidad; n++) {
		sValor = arrTipo[n-1];
		sValorNombre = arrTipoNombre[n-1];
		sGenera+="<option value=\""+sValor+"\" >"+sValorNombre+"</option>";
	}
	sGenera+="</select>";
	
	fGeneraDato("divTipo",sGenera);
	
}
function fCargaCategoria(){
	uiValor = document.getElementById("cmp2").value;
	//alert("uiValor= " + uiValor);
	if (uiValor=="inmuebles"){
		uiCategoria=1;
		sGenera="";
		sGenera+="<select name=\"cmp3\" id=\"cmp3\" class=\"divList\" onchange=\"fCargaSubCategoria();\" >";
		sGenera+="<option value=\"-1\" >Seleccione una opci&oacute;n</option>";
		uiCantidad = arrCat1.length
		for (var n = 1; n<=uiCantidad; n++) {
			sValor = arrCat1[n-1];
			sValorNombre = arrCat1Nombre[n-1];
			sGenera+="<option value=\""+sValor+"\" >"+sValorNombre+"</option>";
		}
		sGenera+="</select>";
		
		fGeneraDato("divCat",sGenera);
		
	}else if (uiValor=="empleos"){
		uiCategoria=2;
		sGenera="";
		sGenera+="<select name=\"cmp3\" id=\"cmp3\" class=\"divList\" onchange=\"fCargaSubCategoria();\" >";
		//sGenera+="<option value=\"-1\" >Seleccione una opci&oacute;n</option>";
		uiCantidad = arrCat2.length
		for (var n = 1; n<=uiCantidad; n++) {
			sValor = arrCat2[n-1];
			sValorNombre = arrCat2Nombre[n-1];
			sGenera+="<option value=\""+sValor+"\" >"+sValorNombre+"</option>";
		}
		sGenera+="</select>";
		
		fGeneraDato("divCat",sGenera);
		fCargaSubCategoria();
	}else if (uiValor=="vehiculos"){
		uiCategoria=3;
		sGenera="";
		sGenera+="<select name=\"cmp3\" id=\"cmp3\" class=\"divList\" onchange=\"fCargaSubCategoria();\" >";
		sGenera+="<option value=\"-1\" >Seleccione una opci&oacute;n</option>";
		uiCantidad = arrCat3.length
		for (var n = 1; n<=uiCantidad; n++) {
			sValor = arrCat3[n-1];
			sValorNombre = arrCat3Nombre[n-1];
			sGenera+="<option value=\""+sValor+"\" >"+sValorNombre+"</option>";
		}
		sGenera+="</select>";
		
		fGeneraDato("divCat",sGenera);
	}else if (uiValor=="varios"){
		uiCategoria=4;
		sGenera="";
		sGenera+="<select name=\"cmp3\" id=\"cmp3\" class=\"divList\" onchange=\"fCargaSubCategoria();\" >";
		//sGenera+="<option value=\"-1\" >Seleccione una opci&oacute;n</option>";
		uiCantidad = arrCat4.length
		for (var n = 1; n<=uiCantidad; n++) {
			sValor = arrCat4[n-1];
			sValorNombre = arrCat4Nombre[n-1];
			sGenera+="<option value=\""+sValor+"\" >"+sValorNombre+"</option>";
		}
		sGenera+="</select>";
		
		fGeneraDato("divCat",sGenera);
		fCargaSubCategoria();
	}
}
function fCargaSubCategoria(){
	uiValor = document.getElementById("cmp3").value;
	if (uiCategoria==1){
		if (uiValor=="renta"){
			sGenera="";
			sGenera+="<select name=\"cmp4\" id=\"cmp4\" class=\"divList\"  >";
			sGenera+="<option value=\"-1\" >Seleccione una opci&oacute;n</option>";
			uiCantidad = arrCat1_1.length
			for (var n = 1; n<=uiCantidad; n++) {
				sValor = arrCat1_1[n-1];
				sValorNombre = arrCat1_1Nombre[n-1];
				sGenera+="<option value=\""+sValor+"\" >"+sValorNombre+"</option>";
			}
			sGenera+="</select>";
			
			fGeneraDato("divSubCat",sGenera);
		}else if (uiValor=="venta"){
			sGenera="";
			sGenera+="<select name=\"cmp4\" id=\"cmp4\" class=\"divList\"  >";
			sGenera+="<option value=\"-1\" >Seleccione una opci&oacute;n</option>";
			uiCantidad = arrCat1_2.length
			for (var n = 1; n<=uiCantidad; n++) {
				sValor = arrCat1_2[n-1];
				sValorNombre = arrCat1_2Nombre[n-1];
				sGenera+="<option value=\""+sValor+"\" >"+sValorNombre+"</option>";
			}
			sGenera+="</select>";
			
			fGeneraDato("divSubCat",sGenera);
		}else if (uiValor=="traspasos-y-permutas"){
			sGenera="";
			sGenera+="<select name=\"cmp4\" id=\"cmp4\" class=\"divList\"  >";
			sGenera+="<option value=\"-1\" >Seleccione una opci&oacute;n</option>";
			uiCantidad = arrCat1_3.length
			for (var n = 1; n<=uiCantidad; n++) {
				sValor = arrCat1_3[n-1];
				sValorNombre = arrCat1_3Nombre[n-1];
				sGenera+="<option value=\""+sValor+"\" >"+sValorNombre+"</option>";
			}
			sGenera+="</select>";
			
			fGeneraDato("divSubCat",sGenera);
		}else if (uiValor=="servicios-inmoviliarios"){
			sGenera="";
			sGenera+="<select name=\"cmp4\" id=\"cmp4\" class=\"divList\"  >";
			sGenera+="<option value=\"-1\" >Seleccione una opci&oacute;n</option>";
			uiCantidad = arrCat1_4.length
			for (var n = 1; n<=uiCantidad; n++) {
				sValor = arrCat1_4[n-1];
				sValorNombre = arrCat1_4Nombre[n-1];
				sGenera+="<option value=\""+sValor+"\" >"+sValorNombre+"</option>";
			}
			sGenera+="</select>";
			
			fGeneraDato("divSubCat",sGenera);
		}
	}else if (uiCategoria==2){
		sGenera="";
		sGenera+="<select name=\"cmp4\" id=\"cmp4\" class=\"divList\"  >";
		sGenera+="<option value=\"-1\" >Seleccione una opci&oacute;n</option>";
		uiCantidad = arrCat2_1.length
		for (var n = 1; n<=uiCantidad; n++) {
			sValor = arrCat2_1[n-1];
			sValorNombre = arrCat2_1Nombre[n-1];
			sGenera+="<option value=\""+sValor+"\" >"+sValorNombre+"</option>";
		}
		sGenera+="</select>";
		
		fGeneraDato("divSubCat",sGenera);
	}else if (uiCategoria==3){
		if (uiValor=="venta-de-autos-refacciones-y-accesorios"){
			sGenera="";
			sGenera+="<select name=\"cmp4\" id=\"cmp4\" class=\"divList\"  >";
			sGenera+="<option value=\"-1\" >Seleccione una opci&oacute;n</option>";
			uiCantidad = arrCat3_1.length
			for (var n = 1; n<=uiCantidad; n++) {
				sValor = arrCat3_1[n-1];
				sValorNombre = arrCat3_1Nombre[n-1];
				sGenera+="<option value=\""+sValor+"\" >"+sValorNombre+"</option>";
			}
			sGenera+="</select>";
			
			fGeneraDato("divSubCat",sGenera);
		}else if (uiValor=="de-servicio"){
			sGenera="";
			sGenera+="<select name=\"cmp4\" id=\"cmp4\" class=\"divList\"  >";
			sGenera+="<option value=\"-1\" >Seleccione una opci&oacute;n</option>";
			uiCantidad = arrCat3_2.length
			for (var n = 1; n<=uiCantidad; n++) {
				sValor = arrCat3_2[n-1];
				sValorNombre = arrCat3_2Nombre[n-1];
				sGenera+="<option value=\""+sValor+"\" >"+sValorNombre+"</option>";
			}
			sGenera+="</select>";
			
			fGeneraDato("divSubCat",sGenera);
		}else if (uiValor=="de-carga-y-trabajo"){
			sGenera="";
			sGenera+="<select name=\"cmp4\" id=\"cmp4\" class=\"divList\"  >";
			sGenera+="<option value=\"-1\" >Seleccione una opci&oacute;n</option>";
			uiCantidad = arrCat3_3.length
			for (var n = 1; n<=uiCantidad; n++) {
				sValor = arrCat3_3[n-1];
				sValorNombre = arrCat3_3Nombre[n-1];
				sGenera+="<option value=\""+sValor+"\" >"+sValorNombre+"</option>";
			}
			sGenera+="</select>";
			
			fGeneraDato("divSubCat",sGenera);
		}else if (uiValor=="ligeros"){
			sGenera="";
			sGenera+="<select name=\"cmp4\" id=\"cmp4\" class=\"divList\"  >";
			sGenera+="<option value=\"-1\" >Seleccione una opci&oacute;n</option>";
			uiCantidad = arrCat3_4.length
			for (var n = 1; n<=uiCantidad; n++) {
				sValor = arrCat3_4[n-1];
				sValorNombre = arrCat3_4Nombre[n-1];
				sGenera+="<option value=\""+sValor+"\" >"+sValorNombre+"</option>";
			}
			sGenera+="</select>";
			
			fGeneraDato("divSubCat",sGenera);
		}else if (uiValor=="acuaticos-y-aereos"){
			sGenera="";
			sGenera+="<select name=\"cmp4\" id=\"cmp4\" class=\"divList\"  >";
			sGenera+="<option value=\"-1\" >Seleccione una opci&oacute;n</option>";
			uiCantidad = arrCat3_5.length
			for (var n = 1; n<=uiCantidad; n++) {
				sValor = arrCat3_5[n-1];
				sValorNombre = arrCat3_5Nombre[n-1];
				sGenera+="<option value=\""+sValor+"\" >"+sValorNombre+"</option>";
			}
			sGenera+="</select>";
			
			fGeneraDato("divSubCat",sGenera);
		}else if (uiValor=="compra-de-autos"){
			sGenera="";
			sGenera+="<select name=\"cmp4\" id=\"cmp4\" class=\"divList\"  >";
			sGenera+="<option value=\"-1\" >Seleccione una opci&oacute;n</option>";
			uiCantidad = arrCat3_6.length
			for (var n = 1; n<=uiCantidad; n++) {
				sValor = arrCat3_6[n-1];
				sValorNombre = arrCat3_6Nombre[n-1];
				sGenera+="<option value=\""+sValor+"\" >"+sValorNombre+"</option>";
			}
			sGenera+="</select>";
			
			fGeneraDato("divSubCat",sGenera);
		
		}
	}else if (uiCategoria==4){
		sGenera="";
		sGenera+="<select name=\"cmp4\" id=\"cmp4\" class=\"divList\"  >";
		sGenera+="<option value=\"-1\" >Seleccione una opci&oacute;n</option>";
		uiCantidad = arrCat4_1.length
		for (var n = 1; n<=uiCantidad; n++) {
			sValor = arrCat4_1[n-1];
			sValorNombre = arrCat4_1Nombre[n-1];
			sGenera+="<option value=\""+sValor+"\" >"+sValorNombre+"</option>";
		}
		sGenera+="</select>";
		
		fGeneraDato("divSubCat",sGenera);
	}
}


function fUploadImagePreview(sCarpeta){
	cmpForm1="cmpImage";
	cmpForm2="cmpImageDb";
	
	cmpImageDb = document.getElementById("cmpImageDb").value;
	URL = "upload_file.php?folder=medios/"+sCarpeta+"&cmpImageDb="+cmpImageDb+"&cmpForm1="+cmpForm1+"&cmpForm2="+cmpForm2;
	window.open(URL, 'upload_pantalla', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=500,height=300,left = 240,top = 212');
}

function fAvisos_agregar(){
	bPasa = true;
	if(document.getElementById("cmpNombre").value == "" && bPasa == true) {
		alert("Por favor complete los campos antes de enviar la informaci\u00F3nn.");
		document.getElementById("cmpNombre").focus();
		bPasa = false;
	}
	if(document.getElementById("cmpTelefono").value == "" && bPasa == true) {
		alert("Por favor complete los campos antes de enviar la informaci\u00F3nn.");
		document.getElementById("cmpTelefono").focus();
		bPasa = false;
	}
	if(document.getElementById("cmpMail").value == "" && bPasa == true) {
		alert("Por favor complete los campos antes de enviar la informaci\u00F3nn.");
		document.getElementById("cmpMail").focus();
		bPasa = false;
	}
	
	if(document.getElementById("cmp1").value == "" && bPasa == true) {
		alert("Por favor complete los campos antes de enviar la informaci\u00F3nn.");
		document.getElementById("cmp1").focus();
		bPasa = false;
	}
	if(document.getElementById("cmp1").value == "" && bPasa == true) {
		alert("Por favor complete los campos antes de enviar la informaci\u00F3nn.");
		document.getElementById("cmp1").focus();
		bPasa = false;
	}
	if(document.getElementById("cmp2").value == "-1" && bPasa == true) {
		alert("Por favor complete los campos antes de enviar la informaci\u00F3nn.");
		bPasa = false;
	}
	if(document.getElementById("cmp3").value == "-1" && bPasa == true) {
		alert("Por favor complete los campos antes de enviar la informaci\u00F3nn.");
		bPasa = false;
	}
	if(document.getElementById("cmp4").value == "-1" && bPasa == true) {
		alert("Por favor complete los campos antes de enviar la informaci\u00F3nn.");
		bPasa = false;
	}
	if(document.getElementById("cmp6").value == "" && bPasa == true) {
		alert("Por favor complete los campos antes de enviar la informaci\u00F3nn.");
		document.getElementById("cmp6").focus();
		bPasa = false;
	}
	
	if (bPasa){
		sContenido = "?cmpNombre="+document.getElementById("cmpNombre").value;
		sContenido += "&cmpTelefono="+document.getElementById("cmpTelefono").value;
		sContenido += "&cmpMail="+document.getElementById("cmpMail").value;
		sContenido += "&cmpTitulo="+document.getElementById("cmp1").value;
		sContenido += "&cmpTipo="+document.getElementById("cmp2").value;
		sContenido += "&cmpCat="+document.getElementById("cmp3").value;
		sContenido += "&cmpSubCat="+document.getElementById("cmp4").value;
		
		sTexto =document.getElementById("cmp6").value;
		sTexto = sTexto.reemplazar("\n", "<br />");
		sContenido += "&cmpDesc="+sTexto;
		//alert(sTexto);	
		sContenido += "&cmpImage="+document.getElementById("cmpImageDb").value;
		
		
		sURL= "lib/anuncios_registrar.php"+sContenido;
		Spry.Utils.loadURL("POST", sURL, true, fAvisos_agregar_update, { postData: ""});
	}
}
function fAvisos_agregar_update(req){
	var resoponseDatos = eval(req.xhRequest.responseText);
	uiMsg = parseInt(resoponseDatos[0]);
	sMsg = resoponseDatos[1];
	//idRegsitro = resoponseDatos[2];
	alert(sMsg);
	if (uiMsg){
		document.pantalla.action = "avisos-de-ocasion-confirmacion.php";
		document.pantalla.submit();
		//fLimpiar();
	}
	
}

function fAvisosIr(tipo,cat,subcat){
	sParametros = "";
	sParametros = "?tipo="+tipo;
	sParametros += "&cat="+cat;
	sParametros += "&subcat="+subcat;
	document.pantalla.action = "avisos-de-ocasion-resultados.php"+sParametros;
	document.pantalla.submit();
}

