<?php
	include("../session.php");
	include("../connect.php");
	$user=$_GET["user"];
	$query=mysql_query("select * from company where id='$user'");
	$asd = mysql_fetch_array($query);
	$cPassword = $asd['password'];
	$cName = $asd['cName'];
	$cAddress = $asd['address'];
	$cTelno = $asd['telNo'];
	$cEmail = $asd['email'];
	$cPerson = $asd['cPerson'];
?>
<html>
<head>
<title>User Page(Company profile)</title>
<script type='text/javascript'>
function vali(str,str2)
{

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)
    {
	
			if(str=='cName'){
			document.getElementById('v1').innerHTML=xmlhttp.responseText;
			}
			else if(str=='phoneNo'){
			document.getElementById('v2').innerHTML=xmlhttp.responseText;
			}
			else if(str=='address'){
			document.getElementById('v3').innerHTML=xmlhttp.responseText;
			}
			else if(str=='contactName'){
			document.getElementById('v4').innerHTML=xmlhttp.responseText;
			}
			else if(str=='email'){
			document.getElementById('v6').innerHTML=xmlhttp.responseText;
			}
    }
} 
xmlhttp.open('GET','validate.php?q='+str+'&q2='+str2+'',true);
xmlhttp.send();
}
//---------------------------------------------------------------------
function finalcheck()
{
var div = document.getElementById('v1');
var div2 = document.getElementById('v2');
var div3 = document.getElementById('v3');
var div4 = document.getElementById('v4');
var div6 = document.getElementById('v6');

if((div.innerHTML!='OK')&&(div.innerHTML!='')){
	alert('Please make sure all fields are properly completed.');
	return false;
}
else if((div2.innerHTML!='OK')&&(div2.innerHTML!='')){
	alert('Please make sure all fields are properly completed.');
	return false;
}
else if((div3.innerHTML!='OK')&&(div3.innerHTML!='')){
	alert('Please make sure all fields are properly completed.');
	return false;
}
else if((div4.innerHTML!='OK')&&(div4.innerHTML!='')){
	alert('Please make sure all fields are properly completed.');
	return false;
}
else if((div6.innerHTML!='OK')&&(div6.innerHTML!='')){
	alert('Please make sure all fields are properly completed.');
	return false;
}
else return true;

}
//-------------------------------------------------------------
function backFunction(user){
		window.location='company.php?user='+user;
	}

</script>
</head>
<body>

<div id="header"  style="background-color:#FF2626">
	<center>
		<h1 style="margin-bottom:0">Easy shop Management</h1>
	</center>
</div>

</br>
</br>

<table align = "center" border = "1" cellpadding = "5" cellspacing = "2" width = "50%" style = "border:solid;border-color:white">
	<tr>
		<td style="background-color:#76888f"><h2 align='center' style="color:white;font-size:1cm">Edit Company Profile</h2></td>
	</tr>
</table>
<?php
echo" 
<form enctype='multipart/form-data' name='form1' action='updating.php?user=$user' onsubmit='return finalcheck()' method='post'>
<table align = 'center' border = '1' cellpadding = '5' cellspacing = '2' width = '50%' style = 'border:solid;border-color:white'>
	<tr>
		<th colspan='2' align='center' style='background-color:#76888f'>User ID : $user</th>
	</tr>
	<tr>
		<td align='right' width='40%' style='background-color:#76888f'><b>Company Name : </b></td>
		<td align='left' width='60%' style='background-color:#BDBDBD'><input type='text' name='cName' value='$cName' onchange='vali(this.name,this.value)'><div id='v1'></div></td>
	</tr>
	<tr>
		<td align='right' width='40%' style='background-color:#76888f'><b>Company Address : </b></td>
		<td align='left' width='60%' style='background-color:#BDBDBD'><input type='text' name='address' value='$cAddress' onchange='vali(this.name,this.value)'><div id='v3'></div></td>
	</tr>
	<tr>
		<td align='right' width='40%' style='background-color:#76888f'><b>Contact Nomber : </b></td>
		<td align='left' width='60%' style='background-color:#BDBDBD'><input type='text' name='phoneNo' value='$cTelno' onchange='vali(this.name,this.value)'><div id='v2'></div></td>
	</tr>
	<tr>
		<td align='right' width='40%' style='background-color:#76888f'><b>Contact Person : </b></td>
		<td align='left' width='60%' style='background-color:#BDBDBD'><input type='text' name='contactName' value='$cPerson' onchange='vali(this.name,this.value)'><div id='v4'></div></td>
	</tr>
	<tr>
		<td align='right' width='40%' style='background-color:#76888f'><b>Email Address : </b></td>
		<td align='left' width='60%' style='background-color:#BDBDBD'><input type='text' name='email' value='$cEmail' onchange='vali(this.name,this.value)'><div id='v6'></div></td>
	</tr>
	<tr>
		<td colspan='2' align='center' style='background-color:#BDBDBD'>		
			<input type='submit' value='Save Edit'>
			<input type='hidden' name='user' value='$user'/>
			<input type='button' value='Back' onClick='backFunction(user.value)'>
		</td>	
	</tr>
	
</table>
</form>"
?>

</body>
</html>
<?php 
include("../closeconnection.php");
?>