<?php
include("includes/site_info.php");

if(isset($_REQUEST['check_id']) && !empty($_REQUEST['check_id'])){

	$check_id = $_REQUEST['check_id']; 
	$check_value = $_REQUEST['check_value'];

	if($check_id=="WUsername") { 

	$count = mysql_num_rows(mysql_query("SELECT * FROM `members` WHERE `mem_username`='".$check_value."'"));
	
	if($count > 0) {
		echo "<font color=\"red\">This username already exists, please try another one.<span id=\"error\">&nbsp;</span></font>";
	} else if(!preg_match("/^[a-zA-Z0-9]+$/", $check_value)) {
		echo "<font color=\"red\">Limit to Alphanumeric character set only.</font>";
	} else if(strlen($check_value)<5) {
		echo "<font color=\"red\">Limit between 5-20 characters.</font>";
	} else { ?>
		<font color='Green'>This username is available.</font>
		<?php 
   } 
} 

	if($check_id=="WAuthEmail") {
		if(get_magic_quotes_gpc()) {
			$email = $check_value;
		} else {
			$email = addslashes($check_value);
		}
	
		$count = mysql_num_rows(mysql_query("SELECT * FROM `members` WHERE `mem_email`='".$email."'")); 
	
		if(!ereg( "^[-a-zA-Z0-9_\\.]+\\@([0-9A-Za-z][0-9A-Za-z-]+\\.)+[A-Za-z]{2,5}\$", $email)) {
			echo "<font color=\"red\">Invalid  Authorize Email!</font>";
		} elseif($count > 0) {
			echo "<font color=\"red\">This Email already exists, please try another one.</font>";
		} elseif(strlen($email)<5) {
			echo "<font color=\"red\">Limit to 5 characters and above.</font>";
		} else { ?>
			<font color='Green'>This Email address is available.</font>
			<?php 
		} 
	} 


	if($check_id=="WMyMobile") { 

	$count = mysql_num_rows(mysql_query("SELECT * FROM `members` WHERE `mem_mobile`='".$check_value."'"));
	
	if($count > 0) {
		echo "<font color=\"red\">This mobile number already exists, please try another one.</font>";
	} else if(!preg_match("/^[0-9]+$/", $check_value)) {
		echo "<font color=\"red\">Limit to digits only.</font>";
	} else if((strlen($check_value)<9) || (strlen($check_value)>20)) {
		echo "<font color=\"red\">Invalid Mobile Number.</font>";
	} else { ?>
		Format (without any special characters (+ or -) or leading zeros at the front of the number): <br />[Area code + Phone Number] E.g. 127654321.
		<?php 
   } 
} 

	if($check_id=="WIntroducer") { 

	$count = mysql_num_rows(mysql_query("SELECT * FROM `members` WHERE `mem_mobile`='".$check_value."'"));
	
	if($count > 0) {
		echo "<font color=\"Green\">This is a valid Introducer.</font>";
	} else if(!preg_match("/^[0-9]+$/", $check_value)) {
		echo "<font color=\"red\">Limit to digits only.</font>";
	} else if((strlen($check_value)<9) || (strlen($check_value)>20)) {
		echo "<font color=\"red\">Invalid Mobile Number.</font>";
	} else { ?>
			<font color='red'>Please enter a valid mobile number.</font>
		<?php 
   } 
} 

} else { 
	echo '<font color=\"red\">Error, Can\'t be blank!</font>'; 
}

?>
