       function disable() 
	{	
	document.user_register.register.disabled=true;
	}
	
		
	function enable() 
	{	
	document.user_register.register.disabled=false;
	}
	function check(a,b,c)
	{
	if(a==1 && b==1 && c==1)
	{
	enable();
	}
	else
	{
	disable();
	}
	}
	
	
$(document).ready(function()
{
 var a=0;
 var b=0;
 var c=0;

	
$("#passcode").blur(function()
	{

	var newusername = document.user_register.passcode.value; 
	var user_null = trim(newusername);
	var emailRegex = /^[""]+/;
	var error=0;
  

  if(newusername.match(emailRegex) || user_null=="") 
	{

		$("#passbox").removeClass();
		$("#passbox").addClass('messageboxpasserror');
		$("#passbox").html('<img align="absmiddle" src="images/Error.png" /> Invalid Pass code format...').show().fadeTo(1900,1);
		error=1;
		disable();
	}
	
	if(error!=1)
	{
		disable();
		//remove all the class add the messagebox classes and start fading
		$("#passbox").removeClass();
		$("#passbox").addClass('msgboxpass');
		$("#passbox").html('<img align="absmiddle" src="images/loader.gif" /> Checking Pass code availability...').show().fadeTo(1900,1);
		//check the username exists or not from ajax
		$.post("ajax/pass_availability.php",{ pass_code:$('#passcode').val(),club:$('#club').val(),product_id:$('#p_id').val()} ,function(data)
        {
		  if(data=='no') //if username not avaiable
		  {
		  	$("#passbox").fadeTo(200,0.1,function() //start fading the messagebox
			{ 
			  //add message and change the class of the box and start fading
			   $(this).removeClass();
			  $(this).addClass('messageboxpasserror');
			  $(this).html('<img align="absmiddle" src="images/Error.png" /> Invalid Pass Code...').show().fadeTo(1900,1);
			  disable();
			});		
          }
		  else
		  {
		  	$("#passbox").fadeTo(200,0.1,function()  //start fading the messagebox
			{ 
			  //add message and change the class of the box and start fading
			  $(this).removeClass();
			  $(this).addClass('messageboxpassok');
			  $(this).html('<img align="absmiddle" src="images/accepted.png" /> Pass code validated...').show().fadeTo(1900,1);
			  //enable();
           a=1;	
           check(a,b,c);				  
			});
		  }
				
        });
 }
 
  
 
 // sponer check
 
 	var newusername = document.user_register.sponser_office.value; 
	var user_null = trim(newusername);
	var emailRegex = /^[""]+/;
	var error=0;
  

  if(newusername.match(emailRegex) || user_null=="") 
	{

		$("#msgboxsponsor").removeClass();
		$("#msgboxsponsor").addClass('messageboxsponsorerror');
		$("#msgboxsponsor").html('<img align="absmiddle" src="images/Error.png" /> Invalid sponsor code or <br /> sponsor office name...').show().fadeTo(1900,1);
		error=1;
		disable();
	}
	
	if(error!=1)
	{
		disable();
		//remove all the class add the messagebox classes and start fading
		$("#msgboxsponsor").removeClass();
		$("#msgboxsponsor").addClass('msgboxsponsor');
		$("#msgboxsponsor").html('<img align="absmiddle" src="images/loader.gif" /> Checking Sponsor data...').show().fadeTo(1900,1);
		//check the username exists or not from ajax
		$.post("ajax/sponsor_availability.php",{ user_name:$('#sponser_office').val(), user_id:$('#father_id').val()} ,function(data)
        {
		  if(data=='no') //if username not avaiable
		  {
		  	$("#msgboxsponsor").fadeTo(200,0.1,function() //start fading the messagebox
			{ 
			  //add message and change the class of the box and start fading
			   $(this).removeClass();
			  $(this).addClass('messageboxsponsorerror');
			  $(this).html('<img align="absmiddle" src="images/Error.png" /> Invalid Sponsor data...').show().fadeTo(1900,1);
			  disable();
			});		
          }
		  else
		  {
		  	$("#msgboxsponsor").fadeTo(200,0.1,function()  //start fading the messagebox
			{ 
			  //add message and change the class of the box and start fading
			  $(this).removeClass();
			  $(this).addClass('messageboxsponsorok');
			  $(this).html('<img align="absmiddle" src="images/accepted.png" /> Sponsor data validated...').show().fadeTo(1900,1);
			  //enable();	
			  b=1;	
check(a,b,c);	
			});
		  }
				
        });
 }
 //sponser check
 
 //sponser ID check
    var newusername111 = document.user_register.sponser_office.value; 
	var user_null11 = trim(newusername111);
		if(user_null11!="")
		$("#father_id").trigger('blur');
  //sponser ID Check
 
 //position check
 
 	var error=0;
	if(error!=1)
	{
		//remove all the class add the messagebox classes and start fading
		$("#msgboxleg").removeClass();
		$("#msgboxleg").addClass('messagebox');
		$("#msgboxleg").html('<img align="absmiddle" src="images/loader.gif" /> Checking Your Position...').show().fadeTo(1900,1);
		//check the username exists or not from ajax
		$.post("ajax/leg_availability.php",{ sponserleg:$('#position').val(), sponserid:$('#father_id').val() } ,function(data)
        {
		  if(data=='no') //if username not avaiable
		  {
		  	$("#msgboxleg").fadeTo(200,0.1,function() //start fading the messagebox
			{ 
			  //add message and change the class of the box and start fading
			   $(this).removeClass();
			  $(this).addClass('messageboxerror');
			  $(this).html('<img align="absmiddle" src="images/Error.png" />This Position is not Usable ...').show().fadeTo(1900,1);
			  disable();
			});		
          }
		  else
		  {
		  	$("#msgboxleg").fadeTo(200,0.1,function()  //start fading the messagebox
			{ 
			  //add message and change the class of the box and start fading
			  $(this).removeClass();
			  $(this).addClass('messageboxok');
			  $(this).html('<img align="absmiddle" src="images/accepted.png" />Position Available...').show().fadeTo(1900,1);
			  //enable();
c=1;	
check(a,b,c);				  
			});
		  }
				
        });
 }
 
 //position check
 

 
 
	});
	
	$("#father_id").blur(function()
	{
		var newusername1 = document.user_register.sponser_office.value; 
	    var user_null = trim(newusername1);
		if(user_null!="")
		$("#sponser_office").trigger('blur');
	});
	
	

	
$("#sponser_office").blur(function()
	{

	var newusername = document.user_register.sponser_office.value; 
	var user_null = trim(newusername);
	var emailRegex = /^[""]+/;
	var error=0;
  

  if(newusername.match(emailRegex) || user_null=="") 
	{

		$("#msgboxsponsor").removeClass();
		$("#msgboxsponsor").addClass('messageboxsponsorerror');
		$("#msgboxsponsor").html('<img align="absmiddle" src="images/Error.png" /> Invalid sponsor code or <br /> sponsor office name...').show().fadeTo(1900,1);
		error=1;
		disable();
	}
	
	if(error!=1)
	{
		disable();
		//remove all the class add the messagebox classes and start fading
		$("#msgboxsponsor").removeClass();
		$("#msgboxsponsor").addClass('msgboxsponsor');
		$("#msgboxsponsor").html('<img align="absmiddle" src="images/loader.gif" /> Checking Sponsor data...').show().fadeTo(1900,1);
		//check the username exists or not from ajax
		$.post("ajax/sponsor_availability.php",{ user_name:$('#sponser_office').val(), user_id:$('#father_id').val()} ,function(data)
        {
		  if(data=='no') //if username not avaiable
		  {
		  	$("#msgboxsponsor").fadeTo(200,0.1,function() //start fading the messagebox
			{ 
			  //add message and change the class of the box and start fading
			   $(this).removeClass();
			  $(this).addClass('messageboxsponsorerror');
			  $(this).html('<img align="absmiddle" src="images/Error.png" /> Invalid Sponsor data...').show().fadeTo(1900,1);
			  disable();
			});		
          }
		  else
		  {
		  	$("#msgboxsponsor").fadeTo(200,0.1,function()  //start fading the messagebox
			{ 
			  //add message and change the class of the box and start fading
			  $(this).removeClass();
			  $(this).addClass('messageboxsponsorok');
			  $(this).html('<img align="absmiddle" src="images/accepted.png" /> Sponsor data validated...').show().fadeTo(1900,1);
			  //enable();	
			  b=1;	
check(a,b,c);	
			});
		  }
				
        });
 }
	});
	
$("#position").blur(function()
	{

	var error=0;
	if(error!=1)
	{
		//remove all the class add the messagebox classes and start fading
		$("#msgboxleg").removeClass();
		$("#msgboxleg").addClass('messagebox');
		$("#msgboxleg").html('<img align="absmiddle" src="images/loader.gif" /> Checking Your Position...').show().fadeTo(1900,1);
		//check the username exists or not from ajax
		$.post("ajax/leg_availability.php",{ sponserleg:$('#position').val(), sponserid:$('#father_id').val() } ,function(data)
        {
		  if(data=='no') //if username not avaiable
		  {
		  	$("#msgboxleg").fadeTo(200,0.1,function() //start fading the messagebox
			{ 
			  //add message and change the class of the box and start fading
			   $(this).removeClass();
			  $(this).addClass('messageboxerror');
			  $(this).html('<img align="absmiddle" src="images/Error.png" />This Position is not Usable ...').show().fadeTo(1900,1);
			  disable();
			});		
          }
		  else
		  {
		  	$("#msgboxleg").fadeTo(200,0.1,function()  //start fading the messagebox
			{ 
			  //add message and change the class of the box and start fading
			  $(this).removeClass();
			  $(this).addClass('messageboxok');
			  $(this).html('<img align="absmiddle" src="images/accepted.png" />Position Available...').show().fadeTo(1900,1);
			  //enable();
c=1;	
check(a,b,c);				  
			});
		  }
				
        });
 }
	});

	
	
	});
	