//if(typeof Prototype=='undefined') {
//	function $() {
//	  var elements = new Array();
//	
//	  for (var i = 0; i < arguments.length; i++) {
//	    var element = arguments[i];
//	    if (typeof element == 'string')
//	      element = document.getElementById(element);
//	
//	    if (arguments.length == 1)
//	      return element;
//	
//	    elements.push(element);
//	  }
//	
//	  return elements;
//	}
//}


//saco blancos al principio y al final
function trim(cadena) {
	
   cadena = cadena.replace(/^\s+/, '');
   cadena = cadena.replace(/\s+$/, '');
	return cadena;
}

// Limpia los spans de verificacion del form_login
function limpiar() {
    $("#verif_nombre").html(''); 
    $("#verif_apellido").html(''); 
    $("#verif_email").html(''); 
    $("#verif_telefono").html(''); 
    $("#verif_usuario").html(''); 
    $("#verif_clave").html(''); 
    $("#verif_re_clave").html(''); 
    $("#verif_anio_nac").html(''); 
    $("#verif_direccion").html(''); 
    $("#verif_localidad").html(''); 
    $("#verif_cp").html(''); 
    $("#verif_provincia").html(''); 
    $("#verif_fax").html(''); 
    $("#verif_nombre_fact").html(''); 
    $("#verif_cuit").html(''); 
    $("#verif_dni").html(''); 
    $("#verif_organizacion").html(''); 
}

function evaluar_form(){	
	var verif;
	var bool = false;
	var email = trim($('#form_login input#email').val());
	//var email_sms = trim($('input#clave').val().email_sms.value);
	var clave = trim($('#form_login input#clave').val());
	var re_clave = trim($('#form_login input#clave').val());

    limpiar();

    if(trim($('#form_login input#nombre').val()) == "") { 
        bool = true;
        $("#verif_nombre").html('ingrese su nombre<br>'); 
    }
    
    if(trim($('#form_login input#apellido').val()) == "") {
        bool = true;
        $("#verif_apellido").html('ingrese su apellido<br>'); 
    }

    if(trim($('#form_login input#anio_nac').val()) == "") {
        bool = true;
        $("#verif_anio_nac").html('ingrese su fecha de nac.<br>');
    }
    
    if(trim($('#form_login input#direccion').val()) == "") {
        bool = true;
        $("#verif_direccion").html('ingrese su dirección<br>'); 
    }
    
   if(trim($('#form_login #provincia option:selected').val()) == 0) {
        bool = false;
        $("#verif_provincia").html("ingrese su provincia<br>"); 
       
    }
     else {
     	if(trim($('#form_login #localidad option:selected').val()) == 0)
     	 {
		        bool = false;
		        $("#verif_localidad").html("ingrese su localidad<br>"); 
		      
		   }
		}
   if(trim($('#form_login input#telefono').val()) == "") {
        bool = true;
        $("#verif_telefono").html('ingrese un tel&eacute;fono<br>'); 
    }
    
     if(trim($('#form_login input#fax').val()) == "") {
        bool = true;
        $("#verif_fax").html('ingrese su numero de Movil<br>'); 
    }
    
    
//      if(trim($('#form_login input#organizacion').val()) == "") {
//        bool = true;
//        $("#verif_organizacion").html('ingrese su organización<br>');
//    }
    
    
	if(email == ""){
		bool = true;
		$("#verif_email").html('ingrese su e-mail<br>'); 
	}
	else if(!validarEmail(email)){
		bool = true;
		$("#verif_email").html('el e-mail ingresado no es v&aacute;lido<br>');
	}
	if(trim($('#form_login input#usuario').val()) == ""){
		bool = true;
		$("#verif_usuario").html('ingrese su usuario<br>'); 
	}
	if(clave == ""){
		bool = true;
		$("#verif_clave").html('ingrese una contrase&ntilde;a<br>'); 
	}
	else if(re_clave == "") {
		bool = true;
		$("#verif_re_clave").html('repita su contrase&ntilde;a<br>'); 
    }
    else if(clave != re_clave) {
        bool = true;
        $("#verif_re_clave").html('la contrase&ntilde;a y su verificaci&oacute;n no concuerdan<br>');
    }
    
    //DATOS DE FACTURACION SI ELIGIO FORMA DE PAGO ANUAL
//    alert($("#abono").is('checked'));
    if ($('#form_login input#tipo_abono').val() == 1)
    {
    	if(trim($('#form_login input#nombre_fact').val()) == "") {
        bool = true;
        $("#verif_nombre_fact").html('ingrese un nombre<br>');
    }
    
     if(trim($('#form_login input#cuit').val()) == "") {
        bool = true;
        $("#verif_cuit").html('ingrese su numero de cuit<br>'); 
    }
    
    
      if(trim($('#form_login input#dni').val()) == "") {
        bool = true;
        $("#verif_dni").html('ingrese su dni<br>'); 
    }
    }
	return (bool)? false : true;
}
//valida un email
function validarEmail(valor) { 
	valor = trim(valor);

	if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(valor)){
		return true
	} 
	else {
    	return false;
	}
}


function mostrar_pago(val)
{  
	limpiar();
	if (val==1) { 
		$('#form_login #iva').attr('disabled',false);
		$('#cuit').attr('disabled',false);
		$('#nombre_fact').attr('disabled',false);
		$('#pago_opciones').attr('disabled',false);
		$('#dni').attr('disabled',false);
		$('#tipo_abono').val(1);
	            }
		
	else {
	$('#form_login #iva').attr('disabled',true);
	$('#cuit').attr('disabled',true);
	$('#nombre_fact').attr('disabled',true);
	$('#pago_opciones').attr('disabled',true);
	$('#dni').attr('disabled',true);
	$('#tipo_abono').val(0);
	
//			$("#iva").disabled = true;
//	       $("#cuit").disabled = true;
//	       $("#nombre_fact").disabled = true;
//	       $("pago_opciones").disabled = true;
//	       $("dni").disabled = true;
	}
}
