<?php
include("../session.php");
include("../connect.php");

$user=$_SESSION['agent'];
$idid=$_POST["id"];
//echo "admin success!!!";
				
?>
<html>
<head>
<link href="header.css" rel="stylesheet" type="text/css"/>
<link type="text/css" rel="stylesheet" href="overflow.css" />
<script type="text/javascript" src="jquery.js"></script>
 
<style type="text/css"> 
div.panel,p.flip
{
margin:0px;
padding:5px;
text-align:center;
background:#e5eecc;
border:solid 1px #c3c3c3;
}
p.flip2,div.panel2,p.flip3,div.panel3
{
margin:0px;
padding:5px;
text-align:left;
background:#FFFFFF;
border:solid 1px #c3c3c3;
}
div.panel
{
height:70px;
display:none;
}
div.panel2,div.panel3
{
height:70px;
}
</style>
</head>
<body>
<div id="content2">
<!-----------------Outer table--------------->
<table width=1000 border=0 cellspacing=10 cellpadding=3>
<tr>
	<td colspan=2>
	<?php include("head.php");?>
	</td>
	</tr>
<tr>
	<td colspan=2>
			<div class=main>&nbsp;&nbsp;>>
			<a href="<?php echo"agent.php";?>">&nbsp;Home&nbsp;</a>>>
			<a href="<?php echo"viewCompany.php";?>">&nbsp;Listing Company&nbsp;</a>>>
			&nbsp;Edit <?php echo $idid; ?> Info&nbsp;
			</div></td>
	</tr>
<tr>
	<td valign=top colspan=2>
	<!--------------------Inner table 2----------------------->
	<?php
		$query=mysql_query("select * from company where id='$idid' ");
		$display=mysql_fetch_array($query);
		
		$name=$display['cName'];
		$address=$display['address'];
		$post=$display['postcode'];
		$country=$display['country'];
		$code=$display['countryCode'];
		$telNo=$display['telNo'];
		$email=$display['email'];
		$cPerson=$display['cPerson'];
		$rDate=$display['registerDate'];
		$eDate=$display['expireDate'];
	?>
	<table class=corners cellspacing=1 cellpadding=10 width=98% align=right>
	<tr>
		<td>
			<form action="<?php echo "infoEditing.php";?>" method="POST" onSubmit="return finalCheck();">
	<fieldset>
		<legend><h3>Edit Info</h3></legend>
		<table align=center width=600 cellpadding=5 cellspacing=3 border=0>
		<tr>
			<td width=180 class="tdA">Company ID :</td>
			<td width=250 class="tdA"><input type="hidden" name="id" value="<?php echo"$idid"; ?>" /><b><?php echo $idid;?></b></td>
			</tr>
		<tr>
			<td class="tdA">Company Name :</td>
			<td class="tdA"><input type="text" name="cName" size=35 id="name" value="<?php echo $name;?>" onchange="vali(this.name, this.value)"/>
				</td>
			<td><font color=green><div id="cNamefield">OK</div></font></td>
			</tr>
		<tr>
			<td class="tdA">Company Address :</td>
			<td class="tdA"><input type="text" name="address" id="address" size=35 value="<?php echo "$address";?>" onchange="vali(this.name,this.value)"/></td>
			<td><font color=green><div id="addressfield">OK</div></font></td>
			</tr>
		<tr>
			<td class="tdA">Post code :</td>
			<td class="tdA"><input type="text" name="post" id="postID" size=35 value="<?php echo $post;?>" onchange="vali(this.name,this.value)"/>
				</td>
			<td><font color=green><div id="postfield">OK</div></font></td>
			</tr>
		<tr>
			<td class="tdA">Country :</td>
			<td class="tdA">
			<select name="country" value="<?php echo $country;?>" onchange="vali(this.name,this.value)">
			<option value='<?php echo $country;?>'><?php echo $country;?></option>
			<?php include("country.php");?>
			</select>
			</td>
			<td><font color=green><div id="countryfield">OK</div></font></td>
			</tr>
		<tr>
			<td class="tdA">Contact No :</td>
			<td colspan=1 class="tdA">
			<select name="codeCountry" onchange="mobileCodeFun(this.value)" >
			<?php include("mobileCode.php");?>
			</select><br/>
			<input type="text" name="code" id="codes" size=5 readonly="readonly" value="<?php echo $code;?>"/>
			<input type="text" name="cNo" id="contact" size=22 value="<?php echo $telNo;?>" size=20 onchange="vali(this.name,this.value)"/>
			</td>
			<td><font color=green><div id="cNofield">OK</div></font></td>
			</tr>
		<tr>
			<td class="tdA">Email :</td>
			<td class="tdA"><input type="text" name="email" size=35 id="email" value="<?php echo $email;?>" onchange="vali(this.name,this.value)"/>
				</td>
			<td><font color=green><div id="emailfield">OK</div></font></td>
			</tr>
		<tr>
			<td class="tdA">In Charge Person :</td>
			<td class="tdA"><input type="text" name="person" size=35 id="person" value="<?php echo $cPerson;?>"onchange="vali(this.name,this.value)"/>
				</td>
			<td><font color=green><div id="personfield">OK</div></font></td>
			</tr>
		<tr>
			<td class="tdA">Join Date :</td>
			<td class="tdA"><b><?php echo $rDate;?></b></td>
			</tr>
		<tr>
			<td class="tdA">Expire Date :</td>
			<td class="tdA"><b><?php echo $eDate;?></b></td>
			</tr>
		<tr>	
			<td colspan=2 align=center class="tdB">
				<input type="submit" value="Edit" />
				<input type="reset" value="Reset" onclick="resetFun()"/></td>
			</tr>
		</table>
	</fieldset>
	</form>
		
		</td>
		</tr>
	</table>
	<!----------------------End inner table 2-------------------->
	
	</td>
	</tr>
</table>
</div>
<!-----------------------End outer table-------------------------->
<script type="text/javascript">
function mobileCodeFun(no){
	document.getElementById("codes").value=no;
}
//--------------Final Check---------------------//
function finalCheck(){
var div=document.getElementById("name").value;
var div2=document.getElementById("address").value;
var postID=document.getElementById("postID").value;
var div3=document.getElementById("contact").value;
var div4=document.getElementById("email").value;
var div5=document.getElementById("person").value;

if(div==""){
	alert("Please fill in Company Name");
	return false;
}else if(div2==""){
	alert("Please fill in Company address");
	return false;
}else if(div3==""){
	alert("Please fill in Contact No.");
	return false;
}else if(div4==""){
	alert("Please fill in Email address");
	return false;
}else if(div5==""){
	alert("Please fill in In charge person");
	return false;
}else if(postID==""){
	alert("Please fill in post code");
}

var data1=document.getElementById("cNamefield");
var data3=document.getElementById("postfield");
var data4=document.getElementById("countryfield");
var data5=document.getElementById("cNofield");
var data6=document.getElementById("emailfield");
var data7=document.getElementById("personfield");

if(data1.innerHTML!="OK")
{
	alert("Please make sure all of your fill are correct");
	return false;
}
if(data3.innerHTML!="OK")
{
	alert("Please make sure all of your fill are correct");
	return false;
}
if(data4.innerHTML!="OK")
{
	alert("Please make sure all of your fill are correct");
	return false;
}
if(data5.innerHTML!="OK")
{
	alert("Please make sure all of your fill are correct");
	return false;
}
if(data6.innerHTML!="OK")
{
	alert("Please make sure all of your fill are correct");
	return false;
}
if(data7.innerHTML!="OK")
{
	alert("Please make sure all of your fill are correct");
	return false;
}


return true;
}//end finalcheck


//-----------------------Validate---------------------------//
function vali(name,value){

if(value==''){
document.getElementById(name+'field').innerHTML='*Please fill in';
myObj2=document.getElementById(name+"field");
myObj2.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','valiRegister.php?q='+name+'&q2='+value,true);

xmlhttp.send();
}

//------------------------Reset----------------------//
function resetFun(){

document.getElementById("cNamefield").innerHTML="OK";
myObjA=document.getElementById("cNamefield");
myObjA.style.color = "green";

document.getElementById("addressfield").innerHTML="OK";
myObjB1=document.getElementById("addressfield");
myObjB1.style.color = "green";

document.getElementById("postfield").innerHTML="OK";
myObjB=document.getElementById("postfield");
myObjB.style.color = "green";

document.getElementById("countryfield").innerHTML="OK";
myObjC=document.getElementById("countryfield");
myObjC.style.color = "green";

document.getElementById("cNofield").innerHTML="OK";
myObjD=document.getElementById("cNofield");
myObjD.style.color = "green";

document.getElementById("emailfield").innerHTML="OK";
myObjE=document.getElementById("emailfield");
myObjE.style.color = "green";

document.getElementById("personfield").innerHTML="OK";
myObjF=document.getElementById("personfield");
myObjF.style.color = "green";
}
</script>


</body>
</html>