function preguntar(preg,URL) {
	if(confirm(preg)) {
		location = URL;
	}
}

function $(id) {
	return document.getElementById(id);	
}


function popup(URL,w,h,vars) {
	
    var left = (screen.width - w) / 2;
    var top  = (screen.height - h) / 2
	
	window.open(URL,"","left="+left+",top=" + top + ",width="+w+",height="+h+vars);
	
}

function post(url, vars){
	var xml = null;
	try {
		xml = new ActiveXObject('Microsoft.XMLHTTP');
	}catch(exception){
		xml = new XMLHttpRequest();
	}
	xml.open('POST',url,false);
	xml.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
	xml.send (vars);
	if(xml.status == 404) alert('Url no valida');
	return xml.responseText;
}

/*
Se le pasa el ID del elemento que se quiere verificar.
Devuelve TRUE o FALSE
*/
function isMail(id){
    var s = document.getElementById(id);
    var filter=/^[A-Za-z][A-Za-z0-9_.-]*@[A-Za-z0-9_.-]+\.[A-Za-z0-9]+[A-za-z]$/;
    if (s.length == 0 ) return true;
    
    if (filter.test(s.value)){
	return true;
    }else{
	return false;
    }
}




function html_decode(data){
    var span = document.createElement('span');
    span.innerHTML = data;
    return span.innerHTML;
}

function NumOnly(e) {
    var KeyCode = (e.keyCode) ? e.keyCode : e.which;
    return ((KeyCode == 8) // backspace
	    || (KeyCode == 9) // tab
	    || (KeyCode == 37) // left arrow
	    || (KeyCode == 39) // right arrow
	    || (KeyCode == 46) // delete
	    || ((KeyCode > 47) && (KeyCode < 58)) // 0 - 9
	    );
}

/*############################################################################*/
/* CONTACTO 								     ##*/
/*#############################################################################*/

function contactar() {
	
   var nombres_campos = new Array(); 
   nombres_campos['nombre']   = 'Nombre';
   nombres_campos['apellido'] = 'Apellido';
   nombres_campos['email']    = 'Email';
   nombres_campos['mensaje']    = 'Mensaje';
   nombres_campos['empresa']    = 'Empresa';

   var ok = Validator.validar(document.frm,nombres_campos);
	
   if(ok) {
   	 document.frm.submit();
   }
   else {
   	  Validator.imprimir_mensajes();
   }	
   
}

/*################################################################################*/
/* REGISTRAR								        ##*/
/*################################################################################*/

function registrar() {
	
   var nombres_campos = new Array(); 
   nombres_campos['nombre']   = 'Nombre';
   nombres_campos['apellido'] = 'Apellido';
   nombres_campos['email']    = 'Email';

   var ok = Validator.validar(document.frm,nombres_campos);
	
   if(ok) {
   	 document.frm.submit();
   }
   else {
   	  Validator.imprimir_mensajes();
   }	
   
}

function recuperar_clave() {
	
   var nombres_campos = new Array(); 
   nombres_campos['email']    = 'Email';

   var ok = Validator.validar(document.frm,nombres_campos);
	
   if(ok) {
   	 document.frm.submit();
   }
   else {
   	  Validator.imprimir_mensajes();
   }	
   
}

function login() {
	document.frmlogin.submit();	
}

/*###############################################################################
## ANIMALATAS                                                                  ##
/*#############################################################################*/

function votar_animalata(){
    var f = $('form_animalata');
    var msg = '';
    //obtengo los campos de votacion de animalatas.
    var ids_animalatas = document.getElementsByName('id_animalatas');
    var aseleccionado = false;
    //recorro la lista de animalatas para ver si el usuario selecciono alguno.
    for(var i=0;i< ids_animalatas.length; i++){
	if(ids_animalatas[i].checked){
	    aseleccionado = true;
	    break;
	}
    }
    
    if(! aseleccionado) msg += 'Debe seleccionar un animalata \n';
    if(isNaN(f.edad.value) || ! f.edad.value || parseInt(f.edad.value) > 99) 
	msg += 'El valor del campo edad no es correcto \n';

    if( ! f.email.value ){
	msg += html_decode('Debe ingresar un valor para el campo Direcci&oacute;n de correo electr&oacute;nico \n');
    }else if( ! isMail('email22')){
	msg += html_decode('Debe ingresar una Direcci&oacute;n de correo electr&oacute;nico v&aacute;lida \n');
    }
    
    if(msg)
	alert(msg);
    else
	f.submit();
}