/*      
       function getCityList(sel)
      {
        var countryCode = sel.options[sel.selectedIndex].value;
        document.getElementById('town').options.length = 0;    // Empty city select box
        var opts = document.getElementById('town').options;
        if(countryCode.length>0){
             var obj = document.getElementById('town');
             jQuery.getJSON('/js/getCities.php?countryCode=' + countryCode, function(data) {
                jQuery.each(data.opts, function(i,item){
                  if (item.selected)
                    opts[opts.length] = new Option(item.name,item.id,true);
                  else
                   opts[opts.length] = new Option(item.name,item.id,false);
                 
                });
              
             });
        }
      }
  */    
      $(function(){
        $("#signupForm").validate({
          rules: {
            password:{ 
              required:true,
              minlength:6
            },
            confirm_password: {
              equalTo: "#password"
            }
          },
          submitHandler: function(form) {
            // do other stuff for a valid form
            form.submit();
          },
          invalidHandler: function(form, validator) {
            var errors = validator.numberOfInvalids();
            if (errors) {
              var message = errors == 1
                ? 'You missed 1 field. It has been highlighted'
                : 'You missed ' + errors + ' fields. They have been highlighted';
              $("div.error span").html(message);
              $("div.error").show();
            } else {
              $("div.error").hide();
            }

          }
        }); //validate
        
        jQuery("#signupForm li").mouseover(function(){
          jQuery(this).find(".h_info").show();
        }).mouseout(function(){
          jQuery(this).find(".h_info").hide();
        });
        
        
      }); //doc ready
      
      function u_exists(val){
      if (val=="") return;
      jQuery("#validateUsername").removeClass('error').html("checking availability...").show();
        jQuery.ajax({
          url : "index.php",
          type : "POST",
          dataType : "json",
          data : "action=check_username&email=" + val,
          success : function(res){
            if(!res.ok){
              jQuery("#email").addClass("error");
              jQuery("#validateUsername").addClass('error').html(res.msg).show();
            }else if(res.ok){
              jQuery("#validateUsername").html(res.msg).show();
            }
            
          },
          error : function(){
             jQuery("#validateUsername").removeClass('error').html("an error occurred. Please try again").show();
          }
        });
      }

