function getProvincias(){
	var idpais = $('paises')[$('paises').selectedIndex].id;
	if (idpais != '---'){
		//si cambia pais, agrego provincias y blanqueo el resto
		var url =  "/tasador/tasar/getProvincias/" + idpais;
		new Ajax.Updater($('container'), url, { method: 'post'});
		Effect.Appear('containier');
	}else{
		$('provincias').disable();
	}
	submitForm();
}

function getDataForm (){
	var idpais    = $('paises')[$('paises').selectedIndex].id;
	var xmlParam  = '';
	if (idpais   != '---'){
		xmlParam += '&pais=' + idpais;
	}

	var idpprov   = $('provincias')[$('provincias').selectedIndex].id;
	if (idpprov  != '---'){
		xmlParam += '&provincia=' + idpprov;
	}

	var idciud    = $('ciudades')[$('ciudades').selectedIndex].id;
	if (idciud  != '---'){
		xmlParam += '&ciudad=' + idciud;
	}

	var idbarrio  = $('barrios')[$('barrios').selectedIndex].id;
	if (idbarrio != '---'){
		xmlParam += '&barrio=' + idbarrio;
	}
	
	/*SUPERFICIES*/

	var cub       = $('cub').value;
	var semicub   = $('semicub').value;
	var descub    = $('descub').value;
	xmlParam += '&cub=' + cub;
	xmlParam += '&semicub=' + semicub;
	xmlParam += '&descub=' + descub;
	

	var cochera  = ($('cochera').checked) ? 1 : '';
	xmlParam += '&cochera=' + cochera;

	return xmlParam;
}

function submitForm(){
	var xmlParam  = 'action=paso0';
	var url =  "/tasador_beta/tasar/";
	xmlParam += getDataForm();
	new Ajax.Updater($('container'), url, { method: 'post', parameters : xmlParam, evalScripts: true});
	Effect.Appear('container');
}

function firstStep(valid){
    var result = valid.validate();
	if (result){
    	var xmlParam  = 'action=pasoa';
		var url =  "tasar/";
			xmlParam += getDataForm();
			new Ajax.Updater($('container'), url, { method: 'post', parameters : xmlParam, evalScripts: true});
			Effect.Appear('container');
	}
}

function secondStep(){
	var xmlParam  = 'action=paso2';
		var url =  "/tasador_beta/tasar/";
			xmlParam += getDataForm2();
			new Ajax.Updater($('container'), url, { method: 'post', parameters : xmlParam, evalScripts: true});
			Effect.Appear('container');
	
}

function thirdStep(){
	var result = valid.validate();
	if (result){
    	var xmlParam  = '';
			
     		xmlParam = 'action=paso3';
    		var url =  "/tasador_beta/tasar/";
			new Ajax.Updater($('container'), url, { method: 'post', parameters : xmlParam, evalScripts: true});
			Effect.Appear('container');
	}
	
}
function mailMe(valid){
	var result = valid.validate();	
		if (result){
    	var xmlParam  = '';
    		xmlParam = 'action=mailme&mail=' + $('email').value + '&nombre=' + $('nombre').value;;
    		var url =  "/tasador_beta/tasar/";
			new Ajax.Updater($('respuesta'), url, { method: 'post', parameters : xmlParam});
			Effect.Appear('respuesta');
		}
}



function showFila(id){
	if( ($('fila_' + id).style.display) != 'none'){
				 $('fila_' + id).style.display = 'none';			
	}else{
				 $('fila_' + id).style.display = '';
	}
}

function deleteRows(str){
	var xmlParams = 'action=delete';
	var urllocation = '';
	if (str == 'pais'){
		urllocation = '/tasador_beta/admin';
	}else if (str == 'provincia') {
		urllocation = '/tasador_beta/admin/viewPais';
	}else if (str == 'ciudad'){
		urllocation = '/tasador_beta/admin/viewProvincia';	
	}else if (str == 'variables'){
		urllocation = '/tasador_beta/admin/variables';	
	}else {
		urllocation = '/tasador_beta/admin/viewCiudad';
	}
	 $$('[id^="' + str + '_id_"]').each(function (user){
		if (user.checked){
			xmlParams += '&' + str + '_id[]=' + user.value; 
		}								
	});
	str = str.slice(0,1).toUpperCase() + str.slice(1);
	var url =  "/tasador_beta/admin/delete" + str;
	new Ajax.Request(url, { method: 'post', parameters : xmlParams,
					 onComplete: function (){
						 location.href=urllocation;
					 }});	
	
}
function checkAll (str){
	 $$('[id^="' + str + '_id_"]').each(function (user){
		if (user.checked){
			user.checked = false;
		}else{
			user.checked = true;
		}								
	});
}

