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

$query=mysql_query("select * from customer where userID='$user'");
$display=mysql_fetch_array($query);
$ID = $display['userID'];
$email = $display['email'];
$fname = $display['fname'];
$lname = $display['lname'];
$street = $display['street'];
$postcode = $display['postcode'];
$state = $display['state'];
$country = $display['country'];
$phone = $display['phone'];
?>
<html>
<head>
<link rel="stylesheet" type="text/css" href="website.css" />
<style>
.styled-select4 select {
   background: transparent;
   width: 158px;
   padding: 3px;
   font-size: 12px;
   border: 1px solid #ccc;
   height: auto;
}
</style>
</head>
<body class="client">
<h2>Update your main address</h2>
<table cellpadding=5>
<tr>
	<td valign=top><p><b>Your current name and address is </b></p></td>
	<td><?php echo $fname." ".$lname;?><br/><?php echo $street."<br/>".$postcode." ".$state."<br/>".$country;?></td>
	</tr>
	</table>
<a href="accountAddress.php"><< Back</a>
<table class="inner2" style="background-color:#EFEFEF" width=80%>
<tr>
	<td><h3>Enter your new name and address</h3>
		<form action="updatingAddress.php" method="POST" onsubmit="return finalcheck()">
		<table cellpadding=5>
		<tr>
			<td>First Name :</td>
			<td>
			<!-------------inner------------>
			<table>
			<tr><td>
			<input type="text" name="fname" style="width:200" onblur="vali(this.name,this.value)"/>
			</td><td>
			<div id="fnamefield"></div>
			</td></tr>
			</table>
			<!---->
			</td>
			</tr>
		<tr>
			<td>Last Name :</td>
			<td>
			<!---------------inner------------->
			<table>
			<tr><td>
			<input type="text" name="lname" style="width:200" onblur="vali(this.name,this.value)"/>
			</td><td>
			<div id="lnamefield"></div>
			</td></tr>
			</table>
			<!---->
			</td>
			</tr>
		<tr>
			<td>Street address :</td>
			<td colspan=3>
			<!--------------inner----------->
			<table>
			<tr><td>
			<input type="text" name="street" style="width:300" onblur="vali(this.name,this.value)"/>
			</td><td>
			<div id="streetfield"></div>
			</td></tr>
			</table>
			<!---->
			</td>
			</tr>
		<tr>
			<td>Postcode :</td>
			<td colspan=3>
			<!--------------inner----------->
			<table>
			<tr><td>
			<input type="text" name="postcode" style="width:300"onblur="vali(this.name,this.value)"/>
			</td><td>
			<div id="postcodefield"></div>
			</td></tr>
			</table>
			<!---->
			</td>
			</tr>
		<tr>
			<td>State :</td>
			<td colspan=3>
			<!--------------inner----------->
			<table>
			<tr><td>
			<input type="text" name="state" style="width:300"onblur="vali(this.name,this.value)"/>
			</td><td>
			<div id="statefield"></div>
			</td></tr>
			</table>
			<!---->
			</td>
			</tr>
		<tr>
			<td>Country :</td>
			<td colspan=3>
			<!--------------inner----------->
			<table>
			<tr><td>
			<div class="styled-select4">
			<select name="country" onchange="vali(this.name,this.value)"><?php include("country.php")?></select>
			</div>
			</td><td><div id="countryfield"></div>
			</td></tr>
			</table>
			<!---->
			</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("fnamefield");
	var data2 = document.getElementById("lnamefield");
	var data3 = document.getElementById("streetfield");
	var data4 = document.getElementById("postcodefield");
	var data5 = document.getElementById("statefield");
	var data6 = document.getElementById("countryfield");

	if(data1.innerHTML!="OK"){
		alert("Please fill in your first name");
		return false;
	}
	if(data2.innerHTML!="OK"){
		alert("Please fill in your last name");
		return false;
	}
	if(data3.innerHTML!="OK"){
		alert("Please fill in your street address");
		return false;
	}
	if(data4.innerHTML!="OK"){
		alert("Please fill in your postcode correctly");
		return false;
	}
	if(data5.innerHTML!="OK"){
		alert("Please fill in State");
		return false;
	}
	if(data6.innerHTML!="OK"){
		alert("Please select your country");
		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','valiEdit.php?name='+name+'&value='+value,true);

xmlhttp.send();

}

</script>

</body>
</html>