function submitform(){ 

	//$('#div_ajax_msg').hide();

 	if($.trim($('#username').val())==''){  

 		$('#div_registration_msg').html("Please Enter a valid UserName");

		$('#div_registration_msg').show();

		$('#username').focus();

		return false ;

 	}


	if($.trim($('#password').val())==''){  

 		$('#div_registration_msg').html("Please Enter a valid Password");

		$('#div_registration_msg').show();

		$('#password').focus();

		return false ;

 	}

 	if($.trim($('#r_pass').val())==''){  

 		$('#div_registration_msg').html("Please Confirm the Password");

		$('#div_registration_msg').show();

		$('#r_pass').focus();

		return false ;

 	}

 	if($.trim($('#password').val())!=$.trim($('#r_pass').val())){  

 		$('#div_registration_msg').html("Passwords don't match");

		$('#div_registration_msg').show();

		$('#password').focus();

		return false ;

 	}

 	if($.trim($('#email').val())==''){  

 		$('#div_registration_msg').html("Please Enter a valid Email Address");

		$('#div_registration_msg').show();

		$('#email').focus();

		return false ;

 	}

	if(!validateEmail($.trim($('#email').val()))){

		 $('#div_registration_msg').html("Invalid Email Address");

		$('#div_registration_msg').show();

		$('#email').focus()

		 return false ;

	}


	if($.trim($('#captcha').val())==''){  

 		$('#div_registration_msg').html("Please Enter the Captcha");

		$('#div_registration_msg').show();

		$('#captcha').focus();

		return false ;

 	}



}//function
//---------------Validtiob Registration-------------
function validateRegistration(){ 

 
	$('#div_action_loading').hide();
	$('#div_registration_msg').hide();
	$('#div_ajax_msg').hide();
	
 	if($.trim($('#username_r').val())==''){  
  		$('#div_registration_msg').html("<div class='error'>Please Enter a UserName</div>");
 		$('#div_registration_msg').show();
 		$('#username_r').focus();
		return false ;
 	}

 	if($.trim($('#email_r').val())==''){  
 		$('#div_registration_msg').html("<div class='error'>Please Enter an Email Address</div>");
		$('#div_registration_msg').show();
		$('#email_r').focus();
		return false ;
 	}

	if(!validateEmail($.trim($('#email_r').val()))){
		$('#div_registration_msg').html("<div class='error'>Invalid Email Address</div>");
		$('#div_registration_msg').show();
		$('#email_r').focus()
		return false ;
	}

	if($.trim($('#password_r').val())==''){  
 		$('#div_registration_msg').html("<div class='error'>Please Enter a Password</div>");
		$('#div_registration_msg').show();
		$('#password_r').focus();
		return false ;
 	}

 	if($.trim($('#r_pass').val())==''){  
 		$('#div_registration_msg').html("<div class='error'>Please Confirm Password</div>");
		$('#div_registration_msg').show();
		$('#r_pass').focus();
		return false ;
 	}

 	if($.trim($('#password_r').val())!=$.trim($('#r_pass').val())){  
 		$('#div_registration_msg').html("<div class='error'>Passwords don't match</div>");
		$('#div_registration_msg').show();
		$('#password_r').focus();
		return false ;
 	}

	if($.trim($('#user_channel').val())==''){  
 		$('#div_registration_msg').html("<div class='error'>Please Enter a channel to join/div>");
		$('#div_registration_msg').show();
		$('#user_channel').focus();
		return false ;
 	}
 	
 	if($.trim($('#captcha').val())==''){  
 		$('#div_registration_msg').html("<div class='error'>Please Enter Captcha</div>");
		$('#div_registration_msg').show();
		$('#captcha').focus();
		return false ;
 	}

	if(document.getElementById("terms").checked == false){
 		$('#div_registration_msg').html("<div class='error'>Please agree to our terms & conditions</div>");
		$('#div_registration_msg').show();
 		return false ;
	}
//-----------------------do Regisrration------------------------
 		var username 	 =  $.trim($('#username_r').val()) ; 
		var email        =  $.trim($('#email_r').val()) ; 
		var password     =  $.trim($('#password_r').val()) ; 
		var user_channel     =  $.trim($('#user_channel').val()) ;
    var captcha		 =  $.trim($('#captcha').val()) ; 								
		$('#div_action_loading').show();
		var URL = baseurl+"/register.php?action=ADDUSER&username="+username+"&email="+email+"&password="+password+"&user_channel="+user_channel+"&captcha="+captcha
 			jQuery.ajax({
			type: "POST",
			url : URL,  
			dataType : "html",
			success : function(response){ 
				var result =  response.replace(/^\s\s*/, '').replace(/\s\s*$/, '')  ; 
				//alert(result);
 				$('#div_registration_msg').show();	
				$('#div_registration_msg').html(result);			
				$('#div_action_loading').hide();
				setTimeout("$('#div_registration_msg').hide()", 9000);
			},
			error: function(){
				alert("Error occured during Ajax request...");
				$('#div_action_loading').hide();
			}
		});					  



}//function

//==============Email Validation

function validateEmail(email){

		var splitted = email.match("^(.+)@(.+)$");

		if(splitted == null) return false;

		if(splitted[1] != null )

		{

		var regexp_user=/^\"?[\w-_\.]*\"?$/;

		if(splitted[1].match(regexp_user) == null) return false;

		}

		if(splitted[2] != null)

		{

		var regexp_domain=/^[\w-\.]*\.[A-Za-z]{2,4}$/;

		if(splitted[2].match(regexp_domain) == null) 

		{

		var regexp_ip =/^\[\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\]$/;

		if(splitted[2].match(regexp_ip) == null) return false;

		}// if

		return true;

		}

		return false;

}//end function

function checkAvailability(type){
	$('#div_registration_msg').hide();		
	if(type =='username'){
		var username = $.trim($('#username_r').val()) ; 	
		var user_name =  username.replace(/^\s\s*/, '').replace(/\s\s*$/, '')  ; 
		if(user_name==''){  
			$('#div_ajax_msg').show();
			$('#div_ajax_msg').html("<div class='error'>Please Enter a UserName</div> ");
			$('#username_r').focus();
			return false;
		}
	} else {
		var email = $.trim($('#email_r').val()) ; 	
		var email_address =  email.replace(/^\s\s*/, '').replace(/\s\s*$/, '')  ; 
	 	if(email_address==''){  
			$('#div_ajax_msg').show();
			$('#div_ajax_msg').html("<div class='error'>Please Enter an Email Address</div> ");
			$('#email_r').focus();
			return false;
		}
		if(!validateEmail($.trim($('#email_r').val()))){
			$('#div_ajax_msg').show();
			$('#div_ajax_msg').html("<div class='error'>Invalid Email Address</div> ");			
			$('#email').focus() ; 
			return false;
		}
 	}
		var username 	 =  $.trim($('#username_r').val()) ; 
		var email 		 =  $.trim($('#email_r').val()) ; 
		if(type =='username'){
			$('#div_username_loading').show();	
			var URL = baseurl+"/register.php?action=checkUserName&type="+type+"&username="+username
  		}else{
			$('#div_email_loading').show();		
			var URL = baseurl+"/register.php?action=checkUserName&type="+type+"&username="+email
		}
   		jQuery.ajax({
			type: "GET",
			url : URL,  
			dataType : "html",
			success : function(response){ 
				var result =  response.replace(/^\s\s*/, '').replace(/\s\s*$/, '')  ; 
			//	alert(  result   ) ; 
				$('#div_username_loading').hide();	
				$('#div_email_loading').hide();	
				$('#div_display_name_loading').hide();	
				$('#div_ajax_msg').show();
				if(type == 'username'){ 
					if(result == 'taken'){
						$('#div_ajax_msg').show();	
						$('#div_ajax_msg').html('<div class="error">Sorry that Username is not available</div>'); 		
					}else{
						$('#div_ajax_msg').show();	
						$('#div_ajax_msg').html('<div class="success">This Username is available</div>'); 		
					}
				}else {
					if(result == 'taken'){
					$('#div_ajax_msg').show();	
			$('#div_ajax_msg').html('<div class="error">That Email Address is not available</div>'); 		
					}else{
						$('#div_ajax_msg').show();
			$('#div_ajax_msg').html('<div class="success">That Email Address is available</div>'); 		
					}
				}
			},
			error: function(){
				alert("Error occured during Ajax request...");
			}
		});					  
}//function

//---------------------------------------

function validateLogin(){
	
	$('#div_login_msg').hide();	
	
	if($.trim($('#username').val())==''){  

 		$('#div_login_msg').html("<div class='error'>Please Enter a UserName</div>");

		$('#div_login_msg').show();

		$('#username').focus();

		return false ;

 	}

 	if($.trim($('#password').val())==''){  

 		$('#div_login_msg').html("<div class='error'>Please Enter a Password</div> ");

		$('#div_login_msg').show();

		$('#password').focus();

		return false ;

 	}
//----------------------------------------------------\
			var username 	 =  $.trim($('#username').val()) ; 
			var password     =  $.trim($('#password').val()) ; 
 			
			$('#div_login_action_loading').show();
			var URL = baseurl+"/login.php?action=doLogin&username="+username+"&password="+password
 			jQuery.ajax({
			type: "POST",
			url : URL,  
			dataType : "html",
			success : function(response){ 
				var result =  response.replace(/^\s\s*/, '').replace(/\s\s*$/, '')  ; 
 				$('#div_login_msg').show();	
				$('#div_login_msg').html(result);
				$('#div_login_action_loading').hide();
  			},
			error: function(){
				alert("Error occured during Ajax request...");
				$('#div_login_action_loading').hide();
			}
		});					  
}//function
