function init() {
document.onkeydown = doOnKeyDown;
  getSAHeight();
  $("#sa").ajaxStart(function(){
    $(this).append('<div id="loading"></div>');
    $(this).show();
  });
  $("#sa").ajaxStop(function(){
    $(this).html('');
  });
}

function getSAHeight() {
    h = (document.body.scrollHeight > document.body.offsetHeight)?document.body.scrollHeight:document.body.offsetHeight;
    document.getElementById('sa').style.height = h + "px";
}
function doOnKeyDown (e) {
  e = e || window.event;
  if (e.keyCode == 27){
    hideRe();
  }
}

function hideRe() {
    $('#sa').hide();
    $('#advance').hide();
}

function signCheck(mod) {
  if (mod == "request") {
    if ($("#assoc").val()=="") {
        alert( "Please enter Association" );
        $("#assoc").focus();
        return false ;
    }
  }

    if ($("#fname").val()=="") {
        alert( "Please enter Your Name" );
        $("#fname").focus();
        return false ;
    }
    if ($("#lname").val()=="") {
        alert( "Please enter Your Last Name" );
        $("#lname").focus();
        return false ;
    }


  if (mod == "request") {
    if ($("#address1").val()=="") {
        alert( "Please enter Your Address" );
        $("#address1").focus();
        return false ;
    }
    if ($("#city").val()=="") {
        alert( "Please enter Your City" );
        $("#city").focus();
        return false ;
    }
    if ($("#state").val()=="") {
        alert( "Please enter Your State" );
        $("#state").focus();
        return false ;
    }
    if ($("#zip").val()=="") {
        alert( "Please enter Your Zip" );
        $("#zip").focus();
        return false ;
    }
  }


    if ($("#email").val()=="") {
        alert( "Please enter Your Email" );
        $("#email").focus();
        return false ;
    } else {
        if (!(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,4})+$/.test($("#email").val()))) {
            alert('Email address you entered appears to be in the wrong format.\nPlease use xxxx@xxx.xxx');
            $("#email").select();
        return false;
        } 
    }

  if (mod != "profile") {
    if ($("#pass").val()=="") {
        alert( "Please enter Password" );
        $("#pass").focus();
        return false ;
    } else {
      if ($("#pass").val() != $("#repass").val()) {
        alert( "The passwords aren't the same!" );
        $("#pass").focus();
        return false ;
      }
    }
  }
}

  function getOneMore(id){
    var txt = $('#assoc :selected').text();
    str = "<span id='d"+id+"'>&#151; "+txt+" (<strong class='red go' onclick='deleteAssoc("+id+")'>x</strong>) <input type=hidden name=assoclist[] value="+id+"></span>";

    if ($("#list").text() == "Empty") $("#list").html('');
    $("#list").append(str);
    $("#d"+id).hide();
    $("#d"+id).show("slow");
  }
  function deleteAssoc(id)
  {
    $("#d"+id).animate({opacity: "hide", height: "0"}, "slow", function(){$("#d"+id).remove();});
  }

function getUser(tempId){
    $.post('/_content/signup/valid.user.php',{tempId:tempId},function(response){
        var data = eval("(" + response + ")");
        if (data.t0 == 1){
          $('#OwnerId').val(data.tid); $('#OwnerId').attr('readonly', true);
          $('#fname').val(data.t1); $('#fname').attr('readonly', true);
          $('#lname').val(data.t2); $('#lname').attr('readonly', true);
          $("#list").html(data.t3);
          $("#reg-step1").hide(); $("#reg-step2").show('400');
        }

        if (data.t0 > 1){
          $("#noid .err big").html('Select Association.');
          $("#noid").show('400');
          $("body").click(function(){ 
            $("#noid").hide('400'); $('#tempId').focus();
          });
        }

        if (data.t0 == 0){
          $("#noid .err big").html('Wrong OwnerID, try again.');
          $("#noid").show('400');
          $("body").click(function(){ 
            $("#noid").hide('400'); $('#tempId').focus();
          });
        }

    });
  }

function ReloadCaptcha(){
  $('#mycaptcha').attr("src", "/inc/captcha/captcha.php?foo="+Math.random());
}

function getPopup(mfile, mode, id, frm) {
    var options = {
    url:      '/_content/'+mfile+'.php',
    type:     'POST',
    data:     {mode:mode, id:id},
    success:  function(answer) { 
                $('#advance').html(answer);  
                $('#advance').show();
              } 
    }
    if(mode=='withform'){
      $("#"+frm).ajaxSubmit(options);
    } else {
      $.ajax(options);
    }
}
