
jQuery(document).ready(function() {

		function TrimString(sInString) {	   
		   if ( sInString ) {
			  sInString = sInString.replace( /^\s+/g, "" );// strip leading
			  return sInString.replace( /\s+$/g, "" );// strip trailing
		   }
		}

		var flist = '\
		1~email~You must type the email. Must have the format xxxxx@domain.com~&nbsp;~error|\
		1~email~You must type a valid Email. Must have the format xxxxx@domain.com~&nbsp;~error|\
		1~email~This email is already registered~<img style="float:left; padding:0 10px 10px 0" src="images/invalid.png" alt="" /><b>Email registered</b>~error|\
		1~email~This email is available~<img style="float:left; padding:0 10px 3px 0" src="images/passed.png" alt="" />~ok|\
		2~username~You must type the username and must be 5 or more letters~&nbsp;~error|\
		2~username~This username is already taken, please choose another~<img style="float:left; padding:0 10px 10px 0" src="images/invalid.png" alt="" />Username is already taken~error|\
		2~username~This username is available~<img style="float:left; padding:0 10px 3px 0" src="images/passed.png" alt="" />~ok|\
		3~alias~You must type the alias and must be 5 or more letters~&nbsp;~error|\
		3~alias~This screen alias is already taken, please choose another~<img style="float:left; padding:0 10px 10px 0" src="images/invalid.png" alt="" />Screen Alias is already taken~error|\
		3~alias~This screen alias is available~<img style="float:left; padding:0 10px 3px 0" src="images/passed.png" alt="" />~ok|\
		3~captcha~Please re-enter the security code~<img style="float:left; padding:0 10px 10px 0" src="images/invalid.png" alt="" />~error|\
		3~captcha~Valid~<img style="float:left; padding:0 10px 3px 0" src="images/passed.png" alt="" />|\
		';

		function getMsgField(fString,foption,fstyle) {
			fStr = TrimString(fString)
			fOpt = TrimString(foption)
			fSty = TrimString(fstyle)
			var fLArray = flist.split('|');     								 // Split into lines
			for (var loop = 0; loop < fLArray.length; loop++) {
				flineArray = fLArray[loop].split('~');
				fCode  = TrimString(flineArray[0]);
				fType  = TrimString(flineArray[1]);
				fName  = TrimString(flineArray[2]);
				fInput = TrimString(flineArray[3]);
				fStatus = TrimString(flineArray[4]);
				if ( (fType ==  fOpt) && (fName ==  fStr) ) {
					$("#"+ fSty +"").removeClass();

					$("#"+ fSty +"").fadeTo(400,0.1,function() 					//start fading the messagebox
					{ 
				  //add message and change the class of the box and start fading
						$(this).html( fInput ).fadeTo(200,1);
					});
					break;
					fCode = "";
					fType  = "";
					fName  = "";
					fInput = "";
					fStatus = "";					
				}
			}
		}


		$("#month").focus(function (){
			$("#month").blur(function (){
				$("#msgboxmonth").fadeOut(100);
			});
		});

		$("#remail").focus(function (){
			$("#remail").blur(function (){
				$("#msgboxemail").fadeOut(100);
				$("#msgboxemail").removeClass().html('<img src="images/icon-loading.gif" alt="" />').fadeIn(400);
				//check the username exists or not from ajax
				$.post("process.php",{ email:$('#remail').val() } ,function(data)
				{
					getMsgField(data,'email','msgboxemail');
				});
			});
		});		

		$("#rusername").focus(function (){
			$("#rusername").blur(function (){
				$("#msgboxusername").fadeOut(100);
				$("#msgboxusername").removeClass().html('<img src="images/icon-loading.gif" alt="" />').fadeIn(400);
				//check the username exists or not from ajax
				$.post("process.php",{ username:$('#rusername').val() } ,function(data)
				{
					getMsgField(data,'username','msgboxusername');
				});
			});
		});		
 
		$("#alias").focus(function (){
			$("#alias").blur(function (){
				$("#msgboxalias").fadeOut(100);
				$("#msgboxalias").removeClass().html('<img src="images/icon-loading.gif" alt="" />').fadeIn(400);
				$.post("process.php",{ alias:$('#alias').val() } ,function(data)
				{
					getMsgField(data,'alias','msgboxalias');
				});
			});
		});		

		$("#rcaptchanum").focus(function (){
			$("#rcaptchanum").blur(function (){
				$("#msgboxcaptcha").fadeOut(100);
				$("#msgboxcaptcha").removeClass().html('<img src="images/icon-loading.gif" alt="" />').fadeIn(400);
				$.post("process.php",{ captcha:$('#rcaptchanum').val() } ,function(data)
				{
					getMsgField(data,'captcha','msgboxcaptcha');
				});
			});
		});		

		$("#demail").focus(function (){
			$("#msgboxemail").removeClass().html('<div class="box-info"><table border="0" cellpadding="0" cellspacing="0"><tbody><tr><td class="tl"></td><td class="t"></td><td class="tr"></td></tr><tr><td class="l"></td><td class="c"><p>Please enter a valid Email Address.</p></td><td class="r"></td></tr><tr><td class="bl"></td><td class="b"></td><td class="br"></td></tr></tbody></table></div>').fadeIn(1500);
			$("#demail").blur(function (){
				$("#msgboxemail").fadeOut(100);
			});
		});		
		
		$("#countrySelect").focus(function (){
			$("#msgboxcountry").removeClass().html('<div class="box-info"><table border="0" cellpadding="0" cellspacing="0"><tbody><tr><td class="tl"></td><td class="t"></td><td class="tr"></td></tr><tr><td class="l"></td><td class="c"><p>Please enter your Country</p></td><td class="r"></td></tr><tr><td class="bl"></td><td class="b"></td><td class="br"></td></tr></tbody></table></div>').fadeIn(1500);
			$("#countrySelect").blur(function (){
				$("#msgboxcountry").fadeOut(100);
			});
		});

		$("#phone").focus(function (){
			$("#msgboxphone").removeClass().html('<div class="box-info"><table border="0" cellpadding="0" cellspacing="0"><tbody><tr><td class="tl"></td><td class="t"></td><td class="tr"></td></tr><tr><td class="l"></td><td class="c"><p>Please enter 10 digits or more </p></td><td class="r"></td></tr><tr><td class="bl"></td><td class="b"></td><td class="br"></td></tr></tbody></table></div>').fadeIn(1500);
			$("#phone").blur(function (){
				$("#msgboxphone").fadeOut(100);
			});
    	});
				
}); 

