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

$user=$_SESSION['agent'];
//echo "admin success!!!";


		$str = "SELECT Max(id) FROM company";
	
		$result2 = mysql_query ($str,$login);
		list($result2)=mysql_fetch_array($result2);
		$number = ++$result2;
			
		if($number == "1")
		{
			$number = "C000001";
		}
				
?>
<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>

</head>
</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>>>
			&nbsp;New SignUp&nbsp;
			</div></td>
	</tr>
<tr>
	<td valign=top>
	<!--------------------Inner table 2----------------------->
	<table class=corners cellspacing=1 cellpadding=10 width=98% align=right>
	<tr>
		<td>
			<form action="<?php echo "viewRegister.php";?>" method="POST" onSubmit="return finalCheck();">
	<fieldset>
		<legend>Register Form</legend>
		<table align=center width=600 cellpadding=5 cellspacing=3 border=0 style = 'border-color:white'>
		<tr>
			<td class="tdA">Company ID :</td>
			<td width=340 class="tdA"><input type="hidden" name="id" value="<?php echo $number; ?>" /><b><?php echo $number;?></b></td>
			</tr>
		<tr>
			<td class="tdA"><b>Class :</b></td>
			<td class="tdA"><select name="class" onchange="vali(this.name, this.value)">
					<option value="@">Select Class</option>
					<option value="High">High</option>
					<option value="Medium High">Medium High</option>
					<option value="Medium">Medium</option>
					<option value="Medium Low">Medium Low</option>
					<option value="Low">Low</option>
				</select>
				<div id="classfield"></div>
					</td>
			</tr>
		<tr>
			<td class="tdA">Company Name :</td>
			<td class="tdA"><input type="text" name="cName" size=50 id="name" onchange="vali(this.name, this.value)"/>
				</td>
			<td><div id="cNamefield"></div></td>
			</tr>
		<tr>
			<td valign=top class="tdA">Company Address :</td>
			<td class="tdA"><textarea name="address" cols=45 rows=4 id="address" onchange="vali(this.name,this.value)"></textarea>
				</td>
			<td><div id="addressfield"></div></td>
			</tr>
		<tr>
			<td class="tdA">POST CODE :</td>
			<td class="tdA"><input type="text" name="post" size=15 onchange="vali(this.name,this.value)"/>
				</td>
			<td><div id="postfield"></div></td>
			</tr>
		<tr>
			<td class="tdA">Country :</td>
			<td class="tdA">
			<select name="country" onchange="vali(this.name,this.value)">
			<?php include("country.php");?>
			</select>
			</td>
			<td><div id="countryfield"></div></td>
			</tr>
		<tr>
			<td class="tdA">Contact No :</td>
			<td class="tdA">
			<select name="codeCountry" onchange="mobileCodeFun(this.value)" >
			<?php include("mobileCode.php");?>
			</select><br/>
			<input type="text" name="code" id="codes" size=10 readonly="readonly"/>
			<input type="text" name="cNo" size=30 id="contact" onchange="vali(this.name,this.value)" />
				</td>
			<td><div id="cNofield"></div></td>
			</tr>
		<tr>
			<td class="tdA">Email :</td>
			<td class="tdA"><input type="text" name="email" size=50 id="email" onchange="vali(this.name,this.value)" />
				</td>
			<td><div id="emailfield"></div></td>
			</tr>
		<tr>
			<td class="tdA">Confirm Email :</td>
			<td class="tdA"><input type="text" name="fEmail" size=50 id="email2" onchange="valiMail(email.value,this.value)"/>
				</td>
			<td><div id="fEmailfield"></div></td>
			</tr>
		<tr>
			<td class="tdA">In Charge Person :</td>
			<td class="tdA"><input type="text" name="person" size=50 id="person" onchange="vali(this.name,this.value)"/>
				</td>
			<td><div id="personfield"></div></td>
			</tr>
		<tr class="menu">	
			<td colspan=2 align=center >
				<input type="submit" value="Submit" />
				</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;
}
function vali(name,value){

if(value==''){
document.getElementById(name+'field').innerHTML='x invalid';
myObj=document.getElementById(name+"field");
myObj.style.color = "red";

 return;
}

if(name=='email'){
	var fmail= document.getElementById('email2').value;
	if((value!=fmail)&&(fmail!="")){
		document.getElementById('fEmailfield').innerHTML='*Not match email ';
	}else if(value==fmail){
		document.getElementById('fEmailfield').innerHTML='OK';
	}
}

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();
}

function valiMail(value,value2){

if(value2==''){
	document.getElementById('fEmailfield').innerHTML='*Please fill in';
	return;
}

if(value2!=value){
	document.getElementById('fEmailfield').innerHTML='*Not match email';
	myObj=document.getElementById("fEmailfield");
	myObj.style.color = "red";
	return;
}else{
	document.getElementById('fEmailfield').innerHTML='OK';
	myObj=document.getElementById("fEmailfield");
	myObj.style.color = "green";
}

}
</script>
<script type="text/javascript">
function finalCheck(){
var error=0;
var div = document.getElementById('cNamefield');
var div2 = document.getElementById('addressfield');
var div3 = document.getElementById('cNofield');
var div4 = document.getElementById('emailfield');
var div5 = document.getElementById('fEmailfield');
var div6 = document.getElementById('postfield');
var div7 = document.getElementById('classfield');
var div8 = document.getElementById('countryfield');



if(div.innerHTML!='OK'){
	
	//document.form1.name.value='';
	document.getElementById('cNamefield').innerHTML='*Please fill in';
	myObj=document.getElementById('cNamefield');
	myObj.style.color = "red";
	error++;
}

 if(div2.innerHTML!='OK'){
	//document.form1.ic.value='';
	document.getElementById('addressfield').innerHTML='*Please fill in';
	myObj=document.getElementById("addressfield");
	myObj.style.color = "red";
	error++;
} 
 if(div3.innerHTML!='OK'){
	//document.form1.dateOfBirth.value='';
	document.getElementById('cNofield').innerHTML='*Please fill in';
	myObj=document.getElementById("cNofield");
	myObj.style.color = "red";
	error++;
}
 if(div4.innerHTML!='OK'){
	//document.form1.gender.value='';
	document.getElementById('emailfield').innerHTML='*Please fill in';
	myObj=document.getElementById("emailfield");
	myObj.style.color = "red";
	error++;
}
 if(div5.innerHTML!='OK'){
	//document.form1.phoneNo.value='';
	document.getElementById('fEmailfield').innerHTML='*Please fill in';
	myObj=document.getElementById("fEmailfield");
	myObj.style.color = "red";
	error++;
}
 if(div6.innerHTML!='OK'){
	//document.form1.phoneNo.value='';
	document.getElementById('postfield').innerHTML='*Please fill in';
	myObj=document.getElementById("postfield");
	myObj.style.color = "red";
	error++;
}
  if(div7.innerHTML!='OK'){
	//document.form1.email.value='';
	document.getElementById('classfield').innerHTML='*Please select';
	myObj=document.getElementById("classfield");
	myObj.style.color = "red";
	error++;
}
 if(div8.innerHTML!='OK'){
	//document.form1.email.value='';
	document.getElementById('countryfield').innerHTML='*Please select';
	myObj=document.getElementById("countryfield");
	myObj.style.color = "red";
	error++;
}
 /*if(div8.innerHTML!='OK'){
	document.form1.file.value='';
	document.getElementById('filefield').innerHTML='*Please fill in';
	
	error++;
} */


if(error>0){
	alert('Please make sure all fields are properly completed.');
	return false;
}
else return true;
}
</script>


</body>
</html>