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

$WUserID = $_SESSION['Sess_UserId'];
$WUserType = $_SESSION['Sess_UserType'];
$WUserLastVisit = $_SESSION['Sess_LastVisit'];
$WUsername = $_SESSION['Sess_UserName'];

$result=mysql_query("SELECT * FROM members LEFT JOIN adverts ON (mem_userid=adv_userid) WHERE mem_userid=$WUserID",$link);
$sql_array = mysql_fetch_object($result);
	
$result2=mysql_query("SELECT * FROM market_Account WHERE mem_userid=$WUserID",$link);
$sql_array2 = mysql_fetch_object($result2);

 if(isset($_REQUEST['check_id'])){
 $check_id = $_REQUEST['check_id']; 
 $check_value = $_REQUEST['check_value'];
if($check_id=="check_nickname") { 
    
        if(get_magic_quotes_gpc()) { 
            $mem_profileid = $check_value; 
        }else{ 
            $mem_profileid = addslashes($check_value); 
        } 
        $count = mysql_num_rows(mysql_query("SELECT * FROM market_Account WHERE mem_AccountNick='".$mem_profileid."' and mem_AccountNick!='".$sql_array2->mem_profileid."'")); 
	
		$invalid_string = "admin support join help test testing tester wau wauhaha wauhh administrator mkt";


        if($count > 0) { 
            echo "This Account Name already exists, please choose another one."; 
        }
		else if(strlen($check_value)<3){
			echo "Limit to 3 characters and above.";
		}
		else if(stristr($invalid_string, $check_value) == true){
			echo "This Account Name was not available, please choose another one.";
		}
		else if (strripos($check_value, "mkt") == 0) {
			echo "This Account Name was not available, please choose another one.";
		}
        else if($check_value == $sql_array->mem_profileid) { 
            echo "<font color='Green'>This is your current Account Name.</font>"; 
        }
		else{ ?>

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

<font color='Green'><?php echo "This Email address is available."; ?></font>
<?php 
        } 
      } 
} else { 
	echo 'Error, Can\'t be blank!'; 
}

?>
