$(document).ready(function(){/* 
	$("#level-three").css("display", "block");
	$('#tdcategory').html('<h1>My Account</h1>');	
		 // var arr = [ 4, "Pete", 8, "John" ];*/
		  $('#frmregister').submit(function() {	   			
				   var options = {
				   target:        '#status', 
				   beforeSubmit:  ChkRegisterRequest,
				   success:       ShowregisterResponse,        
				   url:           'admin/controller/register_controller.php?CMD=add', 
				   type:          'post',
				   timeout:       3000
				   };		   
		   			$('#status').fadeIn();
	   				$("#status").html("<b> Updating details.Please wait...</b>");		   
					$(this).ajaxSubmit(options);
					return false;
		    });
});


function ShowregisterResponse(responseText, statusText)
{
    $('#status').fadeIn();
	if(responseText == 1)
	{
		 $("#status").html("<b>You are registered successfully.You can now login.</b>");
		 setTimeout(function(){ $('#status').fadeOut('slow'); }, 1000);
		 window.location='index.php';//return true;
	}
	else if(responseText == 2)
	{
		$("#status").html("<b>Username already exists, please choose another one.</b>");
		setTimeout(function(){ $('#status').fadeOut('slow'); }, 1000);
	}
	else if(responseText == 3)
	{
		$("#status").html("<b>Email id already exists, please choose another one.</b>");
		setTimeout(function(){ $('#status').fadeOut('slow'); }, 1000);
	}
	else
	{
		$("#status").html("<b>Error in registration!</b>");
		setTimeout(function(){ $('#status').fadeOut('slow'); }, 1000);
	}
	return false;	
}

function chk_phone(strString,typ)
{
	var strValidChars;
	
	if(typ == 'mob')
	{
		strValidChars = "0123456789";
		if(strString.length != 10)
		{
			return false;
		}
	}
	else
	{
		strValidChars = "0123456789-";
	}
	
	var strChar;
	var blnResult = true;
	
	if (strString.length == 0) return false;
	
	// test strString consists of valid characters listed above
	for (i = 0; i < strString.length && blnResult == true; i++)
	{
		strChar = strString.charAt(i);
		if (strValidChars.indexOf(strChar) == -1)
		{
			blnResult = false;
		}
	}
	return blnResult;
}


function ChkRegisterRequest(accountData, registerForm, options)
{
		var chq;
		var flg=false;
		
		$('[id^=txt]', registerForm).each(function() {
			if(this.type=='text' || this.type=='textarea' || this.type=='password')
			 { 
				if (!CheckNull(this.value))
				{
					$('#status').fadeIn();	
					$("#status").html("<b> Please enter ...</b>"+ $('#lbl'+ this.id +'')[0].innerHTML.substring(2));				
					this.style.border='2px solid red';
					flg=false;
					return false;				
				} 
				else
				{
					flg=true;
					this.style.border='1px solid #FFFFFF';
				}
			} 
   		});
		
		if(!flg)
			return flg;
		
		$('[id^=ddl]:input').each(function() { 
			if(this.selectedIndex == 0)
			{
				$('#status').fadeIn();		   
				$("#status").html("<b> Please select ...</b>"+ $('#lbl'+ this.id +'')[0].innerHTML.substring(2));				
				this.style.border='2px solid red';
				flg=false;
				return false;				
			}
			else
			{
				flg=true;
				this.style.border='1px solid #FFFFFF';
			}
		});

		if(!flg)
			return flg;
		
		if($("#txtbpass").val() != $("#txtbconfpass").val())
		{
			$('#status').fadeIn();		   
			$("#status").html("<b> Please retype Confirm Password</b>");				
			$("#txtbpass")[0].style.border='2px solid red';
			$("#txtbconfpass")[0].style.border='2px solid red';
			flg=false;
			return false;	
				
		}
		else
		{
			flg=true;
			$("#txtbpass")[0].style.border='1px solid #FFFFFF';
			$("#txtbconfpass")[0].style.border='1px solid #FFFFFF';
		}
		
		if(!flg)
			return flg;
		
		$('[id$=phone]:text').each(function() { 
			if(!chk_phone(this.value,'base'))
			{
				$('#status').fadeIn();		   
				$("#status").html("<b> Please enter valid phone number ...</b>");				
				this.style.border='2px solid red';
				flg=false;
				return false;				
			}
			else
			{
				flg=true;
				this.style.border='1px solid #FFFFFF';
			}
		});


		if(!flg)
			return flg;


		$('[id$=mbl]:text').each(function() { 
			if(!chk_phone(this.value,'mob'))
			{
				$('#status').fadeIn();		   
				$("#status").html("<b> Please enter valid mobile number ...</b>");				
				this.style.border='2px solid red';
				flg=false;
				return false;				
			}
			else
			{
				flg=true;
				this.style.border='1px solid #FFFFFF';
			}
		});
		
		if(!flg)
			return flg;
		
		$('[id$=zip]:text').each(function() { 
			if(!chk_phone(this.value,'base'))
			{
				$('#status').fadeIn();		   
				$("#status").html("<b> Please enter valid zip number ...</b>");				
				this.style.border='2px solid red';
				flg=false;
				return false;				
			}
			else
			{
				flg=true;
				this.style.border='1px solid #FFFFFF';
			}
		});
		
		if(!flg)
			return flg;
		
		var filter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
		$('#frmregister [id$=email]:text').each(function() { 
			if(!filter.test(this.value))
			{
				$('#status').fadeIn();		   
				$("#status").html("<b> Please enter valid Email Address ...</b>");				
				this.style.border='2px solid red';
				flg=false;
				return false;				
			}
			else
			{
				flg=true;
				this.style.border='1px solid #FFFFFF';
			}
		});
		
		if($('#accept').is(':checked'))
		{
			flg=true;
			$('#lblaccept')[0].style.border='none';
		}
		else
		{
			$('#status').fadeIn();	
			$("#status").html("<b> Please accept terms & condiitons</b>");				
			$('#lblaccept')[0].style.border='2px solid red';
			flg=false;
			return false;				
		}
		
	return flg;
}



function load_city(stateid,db_state_id)
{
	$.get("admin/controller/register_controller.php", {CMD: "ld_city",sid: db_state_id},city_resp);
}

function city_resp(data)
{
	$("#city_dd_b").html(data);
}
