$.ajaxSetup({type: "POST"});
$("#iaj").ajaxStart(function() {$(this).show();});
$("#iaj").ajaxStop(function() {$(this).hide();});
$("#iaj").ajaxComplete(function() {$(this).hide();});

function aj(u,dt) {dt = dt || ""; $.ajax({url: u, data: dt, dataType: "script"});}
function bdis(id,zn)
{
 var o = $("#"+id); o.attr({disabled: zn});
 if (zn > 0) o.removeClass().addClass("bdis"); else o.removeClass().addClass("but");
}

function apply()
{
  document.frm.sub.disabled=true;
  if(document.frm.agr.checked==true)
  {
    document.frm.sub.disabled=false;
  }
  if(document.frm.agr.checked==false)
  {
    document.frm.sub.enabled=false;
  }
}

function k_fast(event)
{
 k = event.keyCode;
 if (k == 13) ent();
}

function u_info() {var lg = $.trim($("#info_lg").val()); if (lg != "") window.open("info.php?"+encodeURI(lg));}

var ch; var chk = ["","","","",""];
function reg_c() {aj("scripts/reg.php","act=reg_c");}
function reg_sh()
{
 var o = $("#mn_reg");
 if	(o.css("display") == "none")
 {
  o.html("<div id=ajaxi></div>").show();
  $.ajax({url: "scripts/reg.php", data: "act=reg_sh", success: function(res) {o.html(res); $("#reg_i").attr({src: "scripts/rcode.php?a=reg&n=reg&r"+Math.random()}); totip("1#reg_i"); $("#mn_cont").hide();}});
  chk[0] = ""; chk[1] = ""; chk[2] = ""; chk[3] = ""; chk[4] = "";
 } else {o.hide(); $("#mn_cont").show();}
}
function reg_chks() {if ($("#rsex").val() == "-1") $("#rsex_chk").show(); else $("#rsex_chk").hide();}
function reg_chk(n)
{
 switch (n)
 {
  case 0: ch = "lg"; break;
  case 1: ch = "pwd1"; break;
  case 2: ch = "pwd2"; break;
  case 3: ch = "email"; break;
  default: ch = "code";
 }
 var v = $.trim($("#r"+ch).val());
 if (v != chk[n])
 {
  if (ch.search(/pwd/) != -1) {ch = "pwd"; v = $.trim($("#rpwd1").val())+"&v2="+$.trim($("#rpwd2").val());}
  chk[n] = v; aj("scripts/reg.php","act=reg_chk&n="+n+"&v="+v);
 }
}
function reg()
{
 bdis("rreg",1);
 aj("scripts/reg.php","act=reg&lg="+$("#rlg").val()+"&fr="+$("#rfriend").val()+"&pwd1="+$("#rpwd1").val()+"&pwd2="+$("#rpwd2").val()+"&em="+$("#remail").val()+"&rasa="+$("#rrasa").val()+"&cl="+$("#rcl").val()+"&sex="+$("#rsex").val()+"&c="+$("#rcode").val());
}

var et;
function ent()
{
 bdis("entry",1);
 aj("scripts/entry.php","act=go&lg="+$("#ent_lg").val()+"&pwd="+$("#ent_pwd").val()+"&sv="+$("#ent_sv").attr("class"));
}
function entm(tx)
{
 $("#ent_res").html("<img id=alert src=n> "+tx).show();
 clearTimeout(et); et = setTimeout("$('#ent_res').hide()",5000);
}

function reco_c() {aj("scripts/reg.php","act=reco_c");}
function ref_sh()
{
  var o = $("#ref");
 if	(o.css("display") == "none")
 {
  o.html("<div id=ajaxi></div>").show();
  $.ajax({url: "scripts/reg.php", data: "act=ref_sh", success: function(res) {o.html(res); }});
 } else o.hide();
}
function reco_sh()
{
 var o = $("#reco");
 if	(o.css("display") == "none")
 {
  o.html("<div id=ajaxi></div>").show();
  $.ajax({url: "scripts/reg.php", data: "act=reco_sh", success: function(res) {o.html(res); $("#reco_i").attr({src: "scripts/rcode.php?a=reg&n=reco&r"+Math.random()}); totip("1#reco_i");}});
 } else o.hide();
}
function reco_go()
{
 bdis("reco_go",1);
 aj("scripts/reg.php","act=reco_go&lg="+$("#reco_lg").val()+"&c="+$("#reco_c").val());
}
var rc;
function recos(tx)
{
 $("#reco_res").html("<img id=alert src=n> "+tx).show();
 clearTimeout(rc); rc = setTimeout("$('#reco_res').hide()",5000);
}

// check box
$("label").live("click", function()
{
 var th = $(this);
 if (th.attr("class") == "n") th.removeClass().addClass("y"); else th.removeClass().addClass("n");
});
function chbox(id,zn)
{
 $("#"+id).removeClass().addClass(zn);
}
function chbox_zn(id) {return $("#"+id).attr("class");}

// button dis
function bdis(id,zn)
{
 $("#"+id).attr({disabled: zn});
 if (zn > 0)
 $("#"+id).removeClass().addClass("bdis"); else
 $("#"+id).removeClass().addClass("but");
}
