//<!---------------------------------+
//  Developed by Roshan Bhattarai 
//  Visit http://roshanbh.com.np for this script and more.
//  This notice MUST stay intact for legal use
// --------------------------------->
$(document).ready(function()
{
  $('#nickname').blur(function () {
    var t = this; 
    if (this.value != this.lastValue) {
      if (this.timer) clearTimeout(this.timer);
		document.getElementById('loginmsg').innerHTML = '<img src="'+script_path+'images/ajax-loader.gif" height="16" width="16" />';
      
      this.timer = setTimeout(function () {
        $.ajax({
          url: 'ajax/validation.php',
          data: 'action=login_availability&login=' + t.value,
          dataType: 'json',
          type: 'post',
          success: function (j) {
			if (j.ok)
				document.getElementById('loginmsg').innerHTML = '<strong>'+j.msg+'</strong>';
			else
				document.getElementById('loginmsg').innerHTML = '<strong class=error>'+j.msg+'</strong>';
          }
        });
      }, 200);
      
      this.lastValue = this.value;
    }
  });

$('#email').blur(function () {
    var t = this; 
    if (this.value != this.lastValue) {
      if (this.timer) clearTimeout(this.timer);
		document.getElementById('emailmsg').innerHTML = '<img src="'+script_path+'images/ajax-loader.gif" height="16" width="16" />';
      
      this.timer = setTimeout(function () {
        $.ajax({
          url: 'ajax/validation.php',
          data: 'action=email_check&email=' + t.value,
          dataType: 'json',
          type: 'post',
          success: function (j) {
			if (j.ok)
				document.getElementById('emailmsg').innerHTML = '<strong>'+j.msg+'</strong>';
			else
				document.getElementById('emailmsg').innerHTML = '<strong class=error>'+j.msg+'</strong>';
          }
        });
      }, 200);
      
      this.lastValue = this.value;
    }
  });


$('#phone').blur(function () {
    var t = this; 
    if (this.value != this.lastValue) {
      if (this.timer) clearTimeout(this.timer);
		document.getElementById('phonemsg').innerHTML = '<img src="'+script_path+'images/ajax-loader.gif" height="16" width="16" />';
      
      this.timer = setTimeout(function () {
        $.ajax({
          url: 'ajax/validation.php',
          data: 'action=phone_check&phone=' + t.value,
          dataType: 'json',
          type: 'post',
          success: function (j) {
			if (j.ok)
				document.getElementById('phonemsg').innerHTML = '<strong>'+j.msg+'</strong>';
			else
				document.getElementById('phonemsg').innerHTML = '<strong class=error>'+j.msg+'</strong>';
          }
        });
      }, 200);
      
      this.lastValue = this.value;
    }
  });

$('#mobile').blur(function () {
    var t = this; 
    if (this.value != this.lastValue) {
      if (this.timer) clearTimeout(this.timer);
		document.getElementById('mobilemsg').innerHTML = '<img src="'+script_path+'images/ajax-loader.gif" height="16" width="16" />';
      
      this.timer = setTimeout(function () {
        $.ajax({
          url: 'ajax/validation.php',
          data: 'action=mobile_check&mobile=' + t.value,
          dataType: 'json',
          type: 'post',
          success: function (j) {
			if (j.ok)
				document.getElementById('mobilemsg').innerHTML = '<strong>'+j.msg+'</strong>';
			else
				document.getElementById('mobilemsg').innerHTML = '<strong class=error>'+j.msg+'</strong>';
          }
        });
      }, 200);
      
      this.lastValue = this.value;
    }
  });

$('#address').blur(function () {
    var t = this; 
    if (this.value != this.lastValue) {
      if (this.timer) clearTimeout(this.timer);
		document.getElementById('addressmsg').innerHTML = '<img src="'+script_path+'images/ajax-loader.gif" height="16" width="16" />';
      
      this.timer = setTimeout(function () {
        $.ajax({
          url: 'ajax/validation.php',
          data: 'action=address_check&address=' + t.value,
          dataType: 'json',
          type: 'post',
          success: function (j) {
			if (j.ok)
				document.getElementById('addressmsg').innerHTML = '<strong>'+j.msg+'</strong>';
			else
				document.getElementById('addressmsg').innerHTML = '<strong class=error>'+j.msg+'</strong>';
          }
        });
      }, 200);
      
      this.lastValue = this.value;
    }
  });

$('#zip').blur(function () {
    var t = this; 
    if (this.value != this.lastValue) {
      if (this.timer) clearTimeout(this.timer);
		document.getElementById('zipmsg').innerHTML = '<img src="'+script_path+'images/ajax-loader.gif" height="16" width="16" />';
      
      this.timer = setTimeout(function () {
        $.ajax({
          url: 'ajax/validation.php',
          data: 'action=zip_check&zip=' + t.value,
          dataType: 'json',
          type: 'post',
          success: function (j) {
			if (j.ok)
				document.getElementById('zipmsg').innerHTML = '<strong>'+j.msg+'</strong>';
			else
				document.getElementById('zipmsg').innerHTML = '<strong class=error>'+j.msg+'</strong>';
          }
        });
      }, 200);
      
      this.lastValue = this.value;
    }
  });

$('#city').blur(function () {
    var t = this; 
    if (this.value != this.lastValue) {
      if (this.timer) clearTimeout(this.timer);
		document.getElementById('citymsg').innerHTML = '<img src="'+script_path+'images/ajax-loader.gif" height="16" width="16" />';
      
      this.timer = setTimeout(function () {
        $.ajax({
          url: 'ajax/validation.php',
          data: 'action=city_check&city=' + t.value + '&zip=' + $('#zip').val() + '&country=' + $('#country').val(),
          dataType: 'json',
          type: 'post',
          success: function (j) {
			if (j.ok)
				document.getElementById('citymsg').innerHTML = '<strong>'+j.msg+'</strong>';
			else
				document.getElementById('citymsg').innerHTML = '<strong class=error>'+j.msg+'</strong>';
          }
        });
      }, 200);
      
      this.lastValue = this.value;
    }
  });

$('#vat').blur(function () {
    var t = this; 
    if (this.value != this.lastValue) {
      if (this.timer) clearTimeout(this.timer);
		document.getElementById('vatmsg').innerHTML = '<img src="'+script_path+'images/ajax-loader.gif" height="16" width="16" />';
      
      this.timer = setTimeout(function () {
        $.ajax({
          url: 'ajax/validation.php',
          data: 'action=vat_check&vat=' + t.value + '&domicil=' + $('#domicil').val(),
          dataType: 'json',
          type: 'post',
          success: function (j) {
			if (j.ok)
				document.getElementById('vatmsg').innerHTML = '<strong>'+j.msg+'</strong>';
			else
				document.getElementById('vatmsg').innerHTML = '<strong class=error>'+j.msg+'</strong>';
          }
        });
      }, 200);
      
      this.lastValue = this.value;
    }
  });

$('#comreg').blur(function () {
    var t = this; 
    if (this.value != this.lastValue) {
      if (this.timer) clearTimeout(this.timer);
		document.getElementById('comregmsg').innerHTML = '<img src="'+script_path+'images/ajax-loader.gif" height="16" width="16" />';
      
      this.timer = setTimeout(function () {
        $.ajax({
          url: 'ajax/validation.php',
          data: 'action=comreg_check&comreg=' + t.value,
          dataType: 'json',
          type: 'post',
          success: function (j) {
			if (j.ok)
				document.getElementById('comregmsg').innerHTML = '<strong>'+j.msg+'</strong>';
			else
				document.getElementById('comregmsg').innerHTML = '<strong class=error>'+j.msg+'</strong>';
          }
        });
      }, 200);
      
      this.lastValue = this.value;
    }
  });


$('#password').blur(function() {
	var strenght = passwordStrength($('#password').val(),$('#nickname').val())
	
	if (strenght < 34 )  message = '<span style=\'color:red\'>'+strenght+'%</span>'
    else if (strenght < 68 )  message = '<span style=\'color:orange\'>'+strenght+'%</span>'
    else message = '<span style=\'color:green\'>'+strenght+'%</span>'
	
	$('#passmsg').html(message)
	})


$('#password2').blur(function () {
    var t = this; 
    if (this.value != this.lastValue) {
      if (this.timer) clearTimeout(this.timer);
		document.getElementById('pass2msg').innerHTML = '<img src="'+script_path+'images/ajax-loader.gif" height="16" width="16" />';
      
      this.timer = setTimeout(function () {
        $.ajax({
          url: 'ajax/validation.php',
          data: 'action=password2_check&password=' + t.value + '&pass=' + $('#password').val(),
          dataType: 'json',
          type: 'post',
          success: function (j) {
			if (j.ok)
				document.getElementById('pass2msg').innerHTML = '<strong>'+j.msg+'</strong>';
			else
				document.getElementById('pass2msg').innerHTML = '<strong class=error>'+j.msg+'</strong>';
          }
        });
      }, 200);
      
      this.lastValue = this.value;
    }
  });

$('#securecode').blur(function () {
    var t = this; 
    if (this.value != this.lastValue) {
      if (this.timer) clearTimeout(this.timer);
		document.getElementById('secmsg').innerHTML = '<img src="'+script_path+'images/ajax-loader.gif" height="16" width="16" />';
      
      this.timer = setTimeout(function () {
        $.ajax({
          url: 'ajax/checkSecureCode.php',
          data: 'secure_code=' + t.value,
          dataType: 'json',
          type: 'post',
          success: function (j) {
			if (j.ok)
				document.getElementById('secmsg').innerHTML = '<strong>'+j.msg+'</strong>';
			else
				document.getElementById('secmsg').innerHTML = '<strong class=error>'+j.msg+'</strong>';
          }
        });
      }, 200);
      
      this.lastValue = this.value;
    }
  });

$('#securecodeinv').blur(function () {
    var t = this; 
    if (this.value != this.lastValue) {
      if (this.timer) clearTimeout(this.timer);
		document.getElementById('secinvmsg').innerHTML = '<img src="'+script_path+'images/ajax-loader.gif" height="16" width="16" />';
      
      this.timer = setTimeout(function () {
        $.ajax({
          url: 'ajax/checkSecureCodeInvitation.php',
          data: 'secure_code=' + t.value + '&email=' + $('#email').val(),
          dataType: 'json',
          type: 'post',
          success: function (j) {
			if (j.ok)
				document.getElementById('secinvmsg').innerHTML = '<strong>'+j.msg+'</strong>';
			else
				document.getElementById('secinvmsg').innerHTML = '<strong class=error>'+j.msg+'</strong>';
          }
        });
      }, 200);
      
      this.lastValue = this.value;
    }
  });

$('#secureimage').blur(function () {
    var t = this; 
    if (this.value != this.lastValue) {
      if (this.timer) clearTimeout(this.timer);
		document.getElementById('secimgmsg').innerHTML = '<img src="'+script_path+'images/ajax-loader.gif" height="16" width="16" />';
      
      this.timer = setTimeout(function () {
        $.ajax({
          url: 'ajax/checkSecureImage.php',
          data: 'secure_image=' + t.value,
          dataType: 'json',
          type: 'post',
          success: function (j) {
			if (j.ok)
				document.getElementById('secimgmsg').innerHTML = '<strong>'+j.msg+'</strong>';
			else
				document.getElementById('secimgmsg').innerHTML = '<strong class=error>'+j.msg+'</strong>';
          }
        });
      }, 200);
      
      this.lastValue = this.value;
    }
  });

});


