///////////////////////////////////////////////////////////////////////////////////////////
///////////// FUNCION PARA 
function EA_validateLogin( f ){
	if(isBlanco(f.email_ea.value)||!isEmail(f.email_ea.value)){
		alert("ERROR: el e-mail es obligatorio!");
		f.email_ea.focus();
		return false;	
	}
	if(isBlanco(f.pass_ea.value) || f.pass_ea.value.length <= 3){
		alert("ERROR: la contraseña es obligatoria!");
		f.pass.focus();
		return false;	
	}
	return true;
}
//--------------------------------------------------------------------------------------


///////////////////////////////////////////////////////////////////////////////////////////
///////////// Abre una nueva ventana de registro de usuarios
function openNuevoUsuarioRegistrado( ) {
	openPopUp( window, './index.php?s=nuevoUsuario', 420, 380, 1, 1 );
}
//--------------------------------------------------------------------------------------

///////////////////////////////////////////////////////////////////////////////////////////
///////////// FUNCION PARA 
function EA_validateNuevoUsuarioRegistrado( f ){
	var error = "";
	new Effect.Pulsate($('divUsuario'), { pulses: 2 });
	
	if(isBlanco(f.nombre_ea.value)|| f.nombre_ea.value.length <= 3)
		error+= "ERROR: Ingrese su nombre \n";

	if(isBlanco(f.apellido_ea.value)|| f.apellido_ea.value.length <= 3)
		error+="ERROR: Ingrese su apellido \n";

	if(isBlanco(f.email_ea.value)|| !isEmail(f.email_ea.value))
		error+="ERROR: Ingrese su e-mail \n";

	if(isBlanco(f.pass_ea.value) || f.pass_ea.value.length <= 3)
		error+="ERROR: Ingrese la contraseña \n";
		
	if(isBlanco(f.telefono_ea.value))
		error+="ERROR: Ingrese su nro de telefono \n";

	if(error != ''){
		alert(error);
		return false;
	}else
		return true;
}
//--------------------------------------------------------------------------------------

///////////////////////////////////////////////////////////////////////////////////////////
///////////// FUNCION PARA MOSTRAR LAS SUBCATEGORIAS DE UNA CATEGORIA
function EA_getOptionListSubCategorias( id_seccion ){
	if(!$('id_categoria')){
		alert("Error, sin lista de subcategorias");
		return false;
	}
	else{
		EA_AJAXRefreshContenido( 'divSubCategoriaOptionList', 'accion=getOptionListSubCategorias&id_seccion=' + id_seccion );
	}
}
//--------------------------------------------------------------------------------------

///////////////////////////////////////////////////////////////////////////////////////////
///////////// FUNCION PARA MOSTRAR LAS SUBCATEGORIAS DE UNA CATEGORIA
function EA_getOptionListLocalidades( provincia_id ){
	if(!$('provincia_id')){
		alert("Error, sin lista de localidades");
		return false;
	}
	else{
		EA_AJAXRefreshContenido( 'divLocalidadesOptionList', 'accion=getOptionListLocalidades&provincia_id=' + provincia_id );
	}
}
//--------------------------------------------------------------------------------------

///////////////////////////////////////////////////////////////////////////////////////////
///////////// FUNCION PARA VALIDAR PUBLICAR_AVISO
function EA_validateAviso( f ){

	var error = "";
	new Effect.Pulsate($('divAviso'), { pulses: 2 });
	
	if(f.id_categoria.value == '-1') {
		error+="Error: Ingrese la categoria. \n";
	}
	
	if(f.id_subcategoria.value == '-1') {
		error+="Error: Ingrese la subcategoria. \n";
	}
		
	if(isBlanco(f.titulo_ea.value)){
		error+="Error: Ingrese el titulo. \n";	
	}else if((f.titulo_ea.value.length <= 3) || (f.titulo_ea.value.length > 50)){
		error+="Error: La longitud del titulo debe ser entre 3 y 50 caracteres. \n";
	}

	if(f.p.value!="ma")
	{	
		if(f.tipo_aviso_id.value == '-1') {
			error+="Error: Ingrese el periodo de publicacion. \n";
		}
	}
	
	if(isBlanco(f.descripcion_ea.value)|| f.descripcion_ea.value.length <= 3){
		error+="Error: Ingrese la descripcion del aviso. \n";
	}
	
	if(f.modalidad_pago_id.value == '-1') {
		error+="Error: Ingrese la modalidad de pago. \n";
	}
	else
	{
		// Si no selecciona localidad Goya, la modalidad no puede ser "A Domicilio"
		if( (f.modalidad_pago_id.value == '2') && (f.localidad_id.value != '2247') ) 
		{
			error+="Error: Si eligió la modalidad de pago A Domicilio, debe seleccionar la localidad Goya (Corrientes). \n";
		}
		else{ if( (f.modalidad_pago_id.value == '2') && isBlanco(f.domicilio_ea.value)  )
				error+="Error: Si eligió la modalidad de pago A Domicilio, debe ingresar su domicilio. \n";
			if( (f.modalidad_pago_id.value == '2') && isBlanco(f.horario_ea.value) )
				error+="Error: Si eligió la modalidad de pago A Domicilio, debe ingresar el horario para que pase a cobrarle. \n";
		}
	}	
	
	if(f.destacado_ea.checked){
		if(f.aviso_id.value == ''){
			if(isBlanco(f.imagen1.value))
				error+="Error: Si eligió que sea destacado, debe ingresar la primer imagen. \n";
		}
		else{ 
			if($('eliminar_imagen1').value == 1){
				if(isBlanco(f.imagen1.value))
					error+="Error: Si eligió que sea destacado, debe ingresar la primer imagen. \n";
			}
			else{
				if(f.imagen_1_nombre.value == 'img_default_lis.jpg')
					error+="Error: Si eligió que sea destacado, debe ingresar la primer imagen. \n";
			}			
		}
	}
	
	if(error != "")
	{
		alert(error);
	 	return false;
	}
	else
	{
		if(!(f.publicar_nombre.checked) && !(f.publicar_email.checked) && !(f.publicar_telefono.checked) && !(f.publicar_direccion.checked))
		{
			if(confirm("No se han elegido datos del contacto del aviso para publicar. Está seguro que desea continuar? \n\n"))
				return true;
			else
		 		return false;
		}	
		else
			return true;
	}
}
//--------------------------------------------------------------------------------------


function EA_validateRenovar( f ){
	var error = "";
	new Effect.Pulsate($('divAviso'), { pulses: 2 });
	

	if(f.tipo_aviso_id.value == '-1') {
		error+="Error: Ingrese el periodo de publicacion. \n";
	}
	
	if(error != ""){
		alert(error);
	 	return false;
	}
	else{
		$('form_renovar').submit() ;
		return true;
	}
}
//--------------------------------------------------------------------------------------

///////////////////////////////////////////////////////////////////////////////////////////
///////////// FUNCION PRINCIPAL PARA RECARGAR EL CENTRO DE LA PAGINA
///////////// parametros: params -> los parametros a enviar, string
function AJAXSendContacto( params ) {

	if(params && !isBlanco(params)){
		new Ajax.Updater('divAviso', './cuerpo.php', 
					{
  						method: 'post',
						parameters: params,
						onLoading: showLoadingAviso( $('divAviso') ),
						onFailure: showErrorContacto						
					}
				);
		return true;
	}
	else{
		return false;
	}
}
//--------------------

///////////////////////////////////////////////////////////////////////////////////////////
///////////// FUNCION PARA MENSAJES INFORMATIVOS, formulario de contacto
function showLoadingAviso( obj ) {
	obj.innerHTML =	'<div align="center" style="height:180px; padding:10px; overflow:hidden"><img src="./img/loading.gif" border="0"></div>';	
}
//--------------------


//----------
function showErrorAviso( msg ) { 
	$('divAviso').innerHTML = '<div align="center" style="height:145px; overflow:visible; padding:65px 0px 0px 35px">Conexión no disponible.</div>';	
	return false; 
}
//----------
//////////////////////////////////////////////////////////////////////////////////
//// funcion que pregunta si eliminar o no un registro
function confirmar_eliminar(id){
	if(confirm("Esta seguro que quiere eliminar la imagen "+id+"? \n\n")){
		$('eliminar_imagen'+id).value = 1;
		$('examinar_'+id).show();
		$('eliminar_'+id).hide();
	}else
 		return false;
}
//--------------------------------------------------------------------------------------

/// funcion para el calculo del valor del aviso
function calculo_valor(){
	if($('modalidad_pago_id').value == '2')
		$('domicilio_ea').show();
	else
		$('domicilio_ea').hide();
		
		
	var id_subcateg = $('id_subcategoria').value;
	if(id_subcateg != '-1'){
		var desta=0.00;
		if($('destacado_ea').checked)
			desta= $('destacado_ea').value;
			
		var news=0.00;
		if($('enviar_newsletter_ea').checked)
			news = $('enviar_newsletter_ea').value;
			
		var modalidad = 0.00;
		if($('modalidad_pago_id').value != '-1')
			modalidad = arre_mod[$('modalidad_pago_id').value];
		
		var id= $('tipo_aviso_id').value;
		if(id > 0)
			$('valor_aviso_ea').value= parseFloat(arre_sub[id_subcateg]) * parseFloat(arre[id]) + parseFloat(desta) + parseFloat(news) + parseFloat(modalidad);
		else
			$('valor_aviso_ea').value= parseFloat(desta);
	}
}





