$(document).ready(function () {
  var validateUsername = $('#validateUsername');
   $('#username').blur(function () {
    var t = this; 
	id = t.value;
	 id = id.replace("<", "&lt;");
			id  = id.replace(">", "&gt;");
			id  = id.replace("eval\\((.*)\\)", "");
			id  = id.replace("[\\\"\\\'][\\s]*((?i)javascript):(.*)[\\\"\\\']", "\"\"");
			id  = id.replace("((?i)script)", "");
    if (id != t.lastValue) {
      if (t.timer) clearTimeout(t.timer);
      validateUsername.removeClass('error').html('<img src="nt_images/preloader.gif" /> ');
      
      this.timer = setTimeout(function () {
        $.ajax({
          url: 'regtest.php',
          data: 'action=check_username&username=' + id,
          dataType: 'json',
          type: 'post',
          success: function (j) {
            validateUsername.html(j.msg);
          }
        });
      }, 200);
      
      this.lastValue = this.value;
    }
  });
  var validatePassword = $('#validatePassword');
  $('#password').blur(function () {
    var p = this; 
	id = p.value;
	 id = id.replace("<", "&lt;");
			id  = id.replace(">", "&gt;");
			id  = id.replace("eval\\((.*)\\)", "");
			id  = id.replace("[\\\"\\\'][\\s]*((?i)javascript):(.*)[\\\"\\\']", "\"\"");
			id  = id.replace("((?i)script)", "");
    if (this.value != this.lastValue) {
      if (this.timer) clearTimeout(this.timer);
      validatePassword.removeClass('error').html('<img src="nt_images/preloader.gif" />');
      
      this.timer = setTimeout(function () {
        $.ajax({
          url: 'regtest.php',
          data: 'action=check_pass&password=' + id,
          dataType: 'json',
          type: 'post',
          success: function (j) {
            validatePassword.html(j.msg);
          }
        });
      }, 200);
      
      this.lastValue = this.value;
    }
  });
  var cnfirmPass = $('#confirmpass');
  $('#confirm').blur(function () {
    var x = this;
	id = x.value;
	 id = id.replace("<", "&lt;");
			id  = id.replace(">", "&gt;");
			id  = id.replace("eval\\((.*)\\)", "");
			id  = id.replace("[\\\"\\\'][\\s]*((?i)javascript):(.*)[\\\"\\\']", "\"\"");
			id  = id.replace("((?i)script)", "");
			
	var p =  $('#password').val();
	p = p.replace("<", "&lt;");
			p  = p.replace(">", "&gt;");
			p  = p.replace("eval\\((.*)\\)", "");
			p  = p.replace("[\\\"\\\'][\\s]*((?i)javascript):(.*)[\\\"\\\']", "\"\"");
			p  = p.replace("((?i)script)", "");
			
    if (this.value != this.lastValue) {
      if (this.timer) clearTimeout(this.timer);
      cnfirmPass.removeClass('error').html('<img src="nt_images/preloader.gif" />');
      
      this.timer = setTimeout(function () {
        $.ajax({
          url: 'regtest.php',
          data: 'action=check_cnfrm&password=' + p + '&confirm=' + id,
          dataType: 'json',
          type: 'post',
          success: function (j) {
            cnfirmPass.html(j.msg);
          }
        });
      }, 200);
      
      this.lastValue = this.value;
    }
  });
   var valemail = $('#valemail');
  $('#emailadd').blur(function () {
    var x = this;
	p = x.value;
	p = p.replace("<", "&lt;");
			p  = p.replace(">", "&gt;");
			p  = p.replace("eval\\((.*)\\)", "");
			p  = p.replace("[\\\"\\\'][\\s]*((?i)javascript):(.*)[\\\"\\\']", "\"\"");
			p  = p.replace("((?i)script)", "");
	clearTimeout(this.timer);
	if (this.value != this.lastValue) {
      if (this.timer) clearTimeout(this.timer);
      valemail.removeClass('error').html('<img src="nt_images/preloader.gif" />');
      
      this.timer = setTimeout(function () {
        $.ajax({
          url: 'regtest.php',
          data: 'action=check_email&emailadd=' + p,
          dataType: 'json',
          type: 'post',
          success: function (j) {
            valemail.html(j.msg);
          }
        });
      }, 200);
      
      this.lastValue = this.value;
    }
  });
   var valmob = $('#validatemob');
  $('#mobile2').blur(function () {
    var x = this;
	p = x.value;
	p = p.replace("<", "&lt;");
			p  = p.replace(">", "&gt;");
			p  = p.replace("eval\\((.*)\\)", "");
			p  = p.replace("[\\\"\\\'][\\s]*((?i)javascript):(.*)[\\\"\\\']", "\"\"");
			p  = p.replace("((?i)script)", "");
	var code = $('#code').val();
	code = code.replace("<", "&lt;");
			code  = code.replace(">", "&gt;");
			code  = code.replace("eval\\((.*)\\)", "");
			code  = code.replace("[\\\"\\\'][\\s]*((?i)javascript):(.*)[\\\"\\\']", "\"\"");
			code  = code.replace("((?i)script)", "");
	clearTimeout(this.timer);
	if (this.value != this.lastValue) {
      if (this.timer) clearTimeout(this.timer);
      valmob.removeClass('error').html('<img src="nt_images/preloader.gif" />');
      
      this.timer = setTimeout(function () {
        $.ajax({
          url: 'regtest.php',
          data: 'action=valmob&code=' + code + '&mobile=' + p,
          dataType: 'json',
          type: 'post',
          success: function (j) {
            valmob.html(j.msg);
          }
        });
      }, 200);
      
      this.lastValue = this.value;
    }
  });
});



