<?php
include("sessionLogin.php");
include("connect.php");
$user=$_SESSION['client'];

$query=mysql_query("select * from customer where userID='$user'");
$display=mysql_fetch_array($query);
$userID = $display['userID'];

?>
<html>
<head>
<link rel="stylesheet" type="text/css" href="website.css" />
</head>
<body class="client">
<h2>Update your user ID</h2>

<p>Your current user ID is <?php echo $userID;?></p>
<a href="account.php"><< Back</a>
<table class="inner2" style="background-color:#EFEFEF" width=80%>
<tr>
	<td><h3>Enter your new user ID</h3>
		<form action="updatingUserID.php" method="POST" onsubmit="return finalcheck()">
		<table cellpadding=5>
		<tr>
			<td>Enter new user ID :</td>
			<td><input type="text" name="userID" id="userID" style="width:300" onblur="vali(this.name,this.value)"/>
				<div id="userIDfield"></div></td>
			</tr>
		<tr>
			<td colspan=2><input type="submit" value="Submit" style="background-color:#4f85bb;width:100;height:30;font-weight:bolder;color:#fff"/></td>
			</tr>
			</table>
		</form>
	
	</td>
	</tr>
	</table>
<script type="text/javascript">
function finalcheck(){
	var data1 = document.getElementById("userIDfield");
	
	if(data1.innerHTML!="OK"){
		alert("Please fill in new user ID","Alert");
		return false;
	}
	
	return true;

}
function vali(name,value){
	if(value.length==""){
		document.getElementById(name+"field").innerHTML = "*Please fill in";
		myObj=document.getElementById(name+"field");
		myObj.style.color = "red";	
		return;
	}
	
	if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject('Microsoft.XMLHTTP');
  }
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
    document.getElementById(name+'field').innerHTML=xmlhttp.responseText;
	myObj=document.getElementById(name+"field");
	
	if(xmlhttp.responseText=="OK"){
		myObj.style.color = "green";
	}else{
		myObj.style.color = "red";
	}
    }
  }
  
xmlhttp.open('GET','valiSignUp.php?name='+name+'&value='+value,true);

xmlhttp.send();


}


</script>


</body>
</html>