<?php
	ini_set('error_reporting', E_ALL | E_STRICT);
	$tag_header = 'set';
	include 'head.php';
	$obj = json_decode(trim($output[2]));//var_dump($obj);
	$system = json_decode(trim($output[0]),true);//var_dump($obj);
	$ModelName = $system['ModelName'];
	$SerialNumber = $system['SerialNumber'];
	$InternetConn='';
	switch ($obj->{'InternetConn'}){
		case 0:
			$InternetConn='disconnected';
			break;
		case 1:
			$InternetConn='connected';
			break;
	}
	$WifiNetworkConn='';
	switch ($obj->{'WifiNetworkConn'}){
		case 0:
			$WifiNetworkConn='disconnected';
			break;
		case 1:
			$WifiNetworkConn='connected';
			break;
	}
	$TelcomNetworkConn='';
	switch ($obj->{'TelcomNetworkConn'}){
		case 0:
			$TelcomNetworkConn='disconnected';
			break;
		case 1:
			$TelcomNetworkConn='connected';
			break;
	}
	$TelcomSimStatus='';
	switch ($obj->{'TelcomSimStatus'}){
		case 0:
			$TelcomSimStatus='no SIM card is found';
			break;
		case 1:
			$TelcomSimStatus='valid SIM card';
			break;
		case 2:
			$TelcomSimStatus='invalid SIM card';
			break;
	}
	$TelcomModemMode='';
	switch ($obj->{'TelcomModemMode'}){
		case 0:
			$TelcomModemMode='No services';
			break;
		case 1:
			$TelcomModemMode='CDMA';
			break;
		case 2:
			$TelcomModemMode='GSM/GPRS';
			break;
		case 3:
			$TelcomModemMode='WCDMA';
			break;
		case 4:
			$TelcomModemMode='GSM/WCDMA';
			break;
		case 5:
			$TelcomModemMode='TD_SCDMA mode';
			break;
		case 6:
			$TelcomModemMode='Unknow';
			break;
	}
?>
<style>
img {
  display: block;
  margin-left: auto;
  margin-right: auto;
}
</style>
	<div class="envor-content">
		<!--
		Page Title start
		//-->
		<section class="envor-page-title-1" data-stellar-background-ratio="0.5">
			<div class="container">
				<div class="row">
					<div class="col-lg-9 col-md-9 col-sm-9">
						<h1><?php echo $lang->showWord("network"); ?></h1>
					</div>
				</div>
			</div>
		<!--
		Page Title end
		//-->
		</section>
		<!--
		Main Content start
		//-->
		<a id="loadinghref"><div id="loading" style="display:none;"><img src="img/giphy.gif"/></div></a>
		<section class="envor-section">
			<div class="container">
				<div class="row">
					<div class="col-lg-12">
						<div class="envor-sorting" id="faq-sorting">
							<div class="envor-toggle">
								<!--Network Status-->
								<article class="envor-sorting-item css">
									<header><?php echo $lang->showWord("network_status"); ?><i class="fa fa-plus"></i></header>
									<section>
										<div class="form-group" style="display:<?php echo $am101;?>">
											<label>Internet Connection Status</label>
											<input type="text" readonly class="form-control" placeholder="<?php echo $InternetConn;?>">
											<input type="hidden" name="InternetConn" id="InternetConn" value="<?php echo $obj->{'InternetConn'};?>">
										</div>
<?php /*										<div class="form-group" style="display:<?php echo $am101;?>">
											<label>FtpServer</label>
											<input type="text" name="FtpServer" id="FtpServer" class="form-control" value="<?php echo $obj->{'FtpServer'};?>">
										</div>*/?>
									</section>
								</article>
								<!--Ethernet Interface0-->
								<article class="envor-sorting-item css" style="display:<?php echo $am101;?>">
									<header><?php echo $lang->showWord("ethernet_interface"); ?><i class="fa fa-plus"></i></header>
									<section>
										<div class="form-group">
											<label>DHCP Client</label>
											<select class="form-control" id="Eth0DhcpClient" name="Eth0DhcpClient" onchange="EthDhcp_changed();">
												<option value="0" <?php echo $obj->{'Eth0DhcpClient'}=="0"?"selected":""?>>enable</option>
												<option value="1" <?php echo $obj->{'Eth0DhcpClient'}=="1"?"selected":""?>>disable</option>
											</select>
										</div>
										<div class="form-group">
											<label>Mac Address</label>
											<input type="text" readonly class="form-control" placeholder="<?php echo $obj->{'Eth0MacAddress'};?>">
											<input type="hidden" name="Eth0MacAddress" id="Eth0MacAddress" value="<?php echo $obj->{'Eth0MacAddress'};?>">
										</div>
										<div class="form-group">
											<label>IP Address</label>
											<input type="text" name="Eth0IpAddress" id="Eth0IpAddress" class="form-control" value="<?php echo $obj->{'Eth0IpAddress'};?>">
										</div>
										<div class="form-group">
											<label>Submask Address</label>
											<input type="text" name="Eth0SubmaskAddress" id="Eth0SubmaskAddress" class="form-control" value="<?php echo $obj->{'Eth0SubmaskAddress'};?>">
										</div>
										<div class="form-group">
											<label>Gateway Address</label>
											<input type="text" name="Eth0GatewayAddress" id="Eth0GatewayAddress" class="form-control" value="<?php echo $obj->{'Eth0GatewayAddress'};?>">
										</div>
									</section>
								</article>
<?php /*								<!--Ethernet Interface1-->
								<article class="envor-sorting-item css" style="display:<?php echo $am101;?>">
									<header><?php echo $lang->showWord("ethernet_interface"); ?><i class="fa fa-plus"></i></header>
									<section>
										<div class="form-group">
											<label>Eth1DhcpClient</label>
											<select class="form-control" id="Eth1DhcpClient" name="Eth1DhcpClient">
												<option value="0" <?php echo $obj->{'Eth1DhcpClient'}=="0"?"selected":""?>>enable</option>
												<option value="1" <?php echo $obj->{'Eth1DhcpClient'}=="1"?"selected":""?>>disable</option>
											</select>
										</div>
										<div class="form-group">
											<label>Eth1MacAddress</label>
											<input type="text" readonly class="form-control" placeholder="<?php echo $obj->{'Eth1MacAddress'};?>">
											<input type="hidden" name="Eth1MacAddress" id="Eth1MacAddress" value="<?php echo $obj->{'Eth1MacAddress'};?>">
										</div>
										<div class="form-group">
											<label>Eth1IpAddress</label>
											<input type="text" name="Eth1IpAddress" id="Eth1IpAddress" class="form-control" value="<?php echo $obj->{'Eth1IpAddress'};?>">
										</div>
										<div class="form-group">
											<label>Eth1SubmaskAddress</label>
											<input type="text" name="Eth1SubmaskAddress" id="Eth1SubmaskAddress" class="form-control" value="<?php echo $obj->{'Eth1SubmaskAddress'};?>">
										</div>
										<div class="form-group">
											<label>Eth1GatewayAddress</label>
											<input type="text" name="Eth1GatewayAddress" id="Eth1GatewayAddress" class="form-control" value="<?php echo $obj->{'Eth1GatewayAddress'};?>">
										</div>
									</section>
								</article>*/?>
								<!--WiFi Module-->
								<article class="envor-sorting-item css" style="display:<?php echo $showWifi;?>">
									<header><?php echo $lang->showWord("WiFi_module"); ?><i class="fa fa-plus"></i></header>
									<section>
										<div class="form-group">
											<label>Mode</label>
											<select class="form-control" id="WifiMode" name="WifiMode" onchange="WifiMode_changed();">
												<option value="0" <?php echo $obj->{'WifiMode'}=="0"?"selected":""?>>disable</option>
												<option value="1" <?php echo $obj->{'WifiMode'}=="1"?"selected":""?>>station</option>
												<option value="2" <?php echo $obj->{'WifiMode'}=="2"?"selected":""?>>Access Point</option>
<?php /*												<option value="3" <?php echo $obj->{'WifiMode'}=="3"?"selected":""?>>Ad-Hoc</option>*/?>
											</select>
										</div>
										<div class="form-group" id="WifiSsidDiv">
											<label>SSID</label>
											<input type="text" name="WifiSsid" id="WifiSsid" class="form-control" value="<?php echo $obj->{'WifiSsid'};?>">
											<input type="button" value="Scan" class="form-control" onClick="scan_wifi()">
										</div>
										<div class="form-group" id="WifiPasswordDiv">
											<label>Password</label>
											<input type="text" name="WifiPassword" id="WifiPassword" class="form-control" value="<?php echo $obj->{'WifiPassword'};?>">
										</div>
										<div class="form-group" id="WifiRssiDiv">
											<label>RSSI</label>
											<input type="text" readonly class="form-control" placeholder="<?php echo $obj->{'WifiRssi'};?> dBm">
											<input type="hidden" name="WifiRssi" id="WifiRssi" value="<?php echo $obj->{'WifiRssi'};?>">
										</div>
										<div class="form-group" id="WifiDhcpServerDiv">
											<label>DHCP Server</label>
											<select class="form-control" id="WifiDhcpServer" name="WifiDhcpServer">
												<option value="0" <?php echo $obj->{'WifiDhcpServer'}=="0"?"selected":""?>>enable</option>
												<option value="1" <?php echo $obj->{'WifiDhcpServer'}=="1"?"selected":""?>>disable</option>
											</select>
										</div>
										<div class="form-group" id="WifiDhcpClientDiv">
											<label>DHCP Client</label>
											<select class="form-control" id="WifiDhcpClient" name="WifiDhcpClient" onchange="WifiDhcp_changed();">
												<option value="0" <?php echo $obj->{'WifiDhcpClient'}=="0"?"selected":""?>>enable</option>
												<option value="1" <?php echo $obj->{'WifiDhcpClient'}=="1"?"selected":""?>>disable</option>
											</select>
										</div>
										<div class="form-group" id="WifiMacAddressDiv">
											<label>Mac Address</label>
											<input type="text" readonly class="form-control" placeholder="<?php echo $obj->{'WifiMacAddress'};?>">
											<input type="hidden" name="WifiMacAddress" id="WifiMacAddress" value="<?php echo $obj->{'WifiMacAddress'};?>">
										</div>
										<div class="form-group" id="WifiIpAddressDiv">
											<label>IP Address</label>
											<input type="text" name="WifiIpAddress" id="WifiIpAddress" class="form-control" value="<?php echo $obj->{'WifiIpAddress'};?>">
										</div>
										<div class="form-group" id="WifiSubmaskAddressDiv">
											<label>Submask Address</label>
											<input type="text" name="WifiSubmaskAddress" id="WifiSubmaskAddress" class="form-control" value="<?php echo $obj->{'WifiSubmaskAddress'};?>">
										</div>
										<div class="form-group" id="WifiGatewayAddressDiv">
											<label>Gateway Address</label>
											<input type="text" name="WifiGatewayAddress" id="WifiGatewayAddress" class="form-control" value="<?php echo $obj->{'WifiGatewayAddress'};?>">
										</div>
										<div class="form-group" id="WifiNetworkConnDiv">
											<label>Network Connection Status</label>
											<input type="text" readonly class="form-control" value="<?php echo $WifiNetworkConn;?>">
											<input type="hidden" name="WifiNetworkConn" id="WifiNetworkConn" value="<?php echo $obj->{'WifiNetworkConn'};?>">
										</div>
									</section>
								</article>
								<!--3G/4G Module-->
								<article class="envor-sorting-item css" style="display:<?php echo $showTelcom;?>">
									<header><?php echo $lang->showWord("3G/4G_module"); ?><i class="fa fa-plus"></i></header>
									<section>
										<div class="form-group">
											<label>Mode</label>
											<select class="form-control" id="TelcomEnabled" name="TelcomEnabled">
												<option value="0" <?php echo $obj->{'TelcomEnabled'}=="0"?"selected":""?>>Disable</option>
												<option value="1" <?php echo $obj->{'TelcomEnabled'}=="1"?"selected":""?>>Enable</option>
											</select>
										</div>
										<div class="form-group">
											<label>APN</label>
											<input type="text" name="TelcomApn" id="TelcomApn" class="form-control" value="<?php echo $obj->{'TelcomApn'};?>">
										</div>
										<div class="form-group">
											<label>RSSI</label>
											<input type="text" readonly class="form-control" placeholder="<?php echo $obj->{'TelcomRssi'};?> dBm">
											<input type="hidden" name="TelcomRssi" id="TelcomRssi" value="<?php echo $obj->{'TelcomRssi'};?>">
										</div>
										<div class="form-group">
											<label>Chap Pap Id</label>
											<input type="text" name="TelcomChapPapId" id="TelcomChapPapId" class="form-control" value="<?php echo $obj->{'TelcomChapPapId'};?>">
										</div>
										<div class="form-group">
											<label>Chap Pap Pwd</label>
											<input type="text" name="TelcomChapPapPwd" id="TelcomChapPapPwd" class="form-control" value="<?php echo $obj->{'TelcomChapPapPwd'};?>">
										</div>
										<div class="form-group">
											<label>Modem IMEI</label>
											<input type="text" readonly class="form-control" placeholder="<?php echo $obj->{'TelcomModemImei'};?>">
											<input type="hidden" name="TelcomModemImei" id="TelcomModemImei" value="<?php echo $obj->{'TelcomModemImei'};?>">
										</div>
										<div class="form-group">
											<label>SIM IMSI</label>
											<input type="text" readonly class="form-control" placeholder="<?php echo $obj->{'TelcomSimImsi'};?>">
											<input type="hidden" name="TelcomSimImsi" id="TelcomSimImsi" value="<?php echo $obj->{'TelcomSimImsi'};?>">
										</div>
										<div class="form-group">
											<label>SIM ICCID</label>
											<input type="text" readonly class="form-control" placeholder="<?php echo $obj->{'TelcomSimIccid'};?>">
											<input type="hidden" name="TelcomSimIccid" id="TelcomSimIccid" value="<?php echo $obj->{'TelcomSimIccid'};?>">
										</div>
										<div class="form-group">
											<label>SIM Status</label>
											<input type="text" readonly class="form-control" placeholder="<?php echo $TelcomSimStatus;?>">
											<input type="hidden" name="TelcomSimStatus" id="TelcomSimStatus" value="<?php echo $obj->{'TelcomSimStatus'};?>">
										</div>
										<div class="form-group">
											<label>Modem Mode</label>
											<input type="text" readonly class="form-control" placeholder="<?php echo $TelcomModemMode;?>">
											<input type="hidden" name="TelcomModemMode" id="TelcomModemMode" value="<?php echo $obj->{'TelcomModemMode'};?>">
										</div>
										<div class="form-group">
											<label>IP Address</label>
											<input type="text" name="TelcomIpAddress" id="TelcomIpAddress" class="form-control" value="<?php echo $obj->{'TelcomIpAddress'};?>">
										</div>
										<div class="form-group">
											<label>Network Connection Status</label>
											<input type="text" readonly class="form-control" value="<?php echo $TelcomNetworkConn;?>">
											<input type="hidden" name="TelcomNetworkConn" id="TelcomNetworkConn" value="<?php echo $obj->{'TelcomNetworkConn'};?>">
										</div>
									</section>
								</article>
								<!--Bluetooth Module-->
<?php /*								<article class="envor-sorting-item css">
									<header><?php echo $lang->showWord("bluetooth_module"); ?><i class="fa fa-plus"></i></header>
									<section>
										<div class="form-group" style="display:<?php echo $am101;?>">
											<label>LoginCentralID</label>
											<input type="text" readonly class="form-control" placeholder="<?php echo $obj->{'LoginCentralID'};?>">
											<input type="hidden" name="LoginCentralID" id="LoginCentralID" value="<?php echo $obj->{'LoginCentralID'};?>">
										</div>
										<div class="form-group" style="display:<?php echo $am101;?>">
											<label>isLogin</label>
											<input type="text" readonly class="form-control" placeholder="<?php echo $obj->{'isLogin'};?>">
											<input type="hidden" name="isLogin" id="isLogin" value="<?php echo $obj->{'isLogin'};?>">
										</div>
										<div class="form-group" style="display:<?php echo $am101;?>">
											<label>isRequestStart</label>
											<input type="text" readonly class="form-control" value="<?php echo $isRequestStart;?>">
											<input type="hidden" name="isRequestStart" id="isRequestStart" value="<?php echo $obj->{'isRequestStart'};?>">
										</div>
										<div class="form-group" style="display:<?php echo $am101;?>">
											<label>isRequestStop</label>
											<input type="text" readonly class="form-control" value="<?php echo $isRequestStop;?>">
											<input type="hidden" name="isRequestStop" id="isRequestStop" value="<?php echo $obj->{'isRequestStop'};?>">
										</div>
									</section>
								</article>  */?>
								<article class="envor-sorting-item css">
									<div align="center"><button id="save"><?php echo $lang->showWord("set")?></button></div>
								</article>
							</div>
						</div>
					</div>
				</div>
			</div>
		</section>
	</div>

<?php
	include 'foot.php';
?>

<script type="text/JavaScript">
	$(document).ready(function(){
		WifiMode_changed();
		EthDhcp_changed();
		WifiDhcp_changed();
	});

	document.getElementById("save").onclick = function() {
		if(formCheck())
		{
			window.location="#loadinghref";
			document.getElementById("loading").style.display="block";
			// 發送 Ajax 查詢請求並處理
			var request = new XMLHttpRequest();
			request.open("POST", "set_network_action.php");

			// POST 參數須使用 send() 發送
//			var data =  "FtpServer=" + document.getElementById("FtpServer").value +
			var data =  "Eth0DhcpClient=" + document.getElementById("Eth0DhcpClient").value+
						"&Eth0IpAddress=" + document.getElementById("Eth0IpAddress").value+
						"&Eth0SubmaskAddress=" + document.getElementById("Eth0SubmaskAddress").value+
						"&Eth0GatewayAddress=" + document.getElementById("Eth0GatewayAddress").value+
						// "&Eth1DhcpClient=" + document.getElementById("Eth1DhcpClient").value+
						// "&Eth1IpAddress=" + document.getElementById("Eth1IpAddress").value+
						// "&Eth1SubmaskAddress=" + document.getElementById("Eth1SubmaskAddress").value+
						// "&Eth1GatewayAddress=" + document.getElementById("Eth1GatewayAddress").value+
						"&WifiMode=" + document.getElementById("WifiMode").value+
						"&WifiSsid=" + document.getElementById("WifiSsid").value+
						"&WifiPassword=" + document.getElementById("WifiPassword").value+
						"&WifiDhcpServer=" + document.getElementById("WifiDhcpServer").value+
						"&WifiDhcpClient=" + document.getElementById("WifiDhcpClient").value+
						"&WifiIpAddress=" + document.getElementById("WifiIpAddress").value+
						"&WifiSubmaskAddress=" + document.getElementById("WifiSubmaskAddress").value+
						"&WifiGatewayAddress=" + document.getElementById("WifiGatewayAddress").value+
						"&TelcomApn=" + document.getElementById("TelcomApn").value+
						"&TelcomChapPapId=" + document.getElementById("TelcomChapPapId").value+
						"&TelcomChapPapPwd=" + document.getElementById("TelcomChapPapPwd").value+
						"&TelcomIpAddress=" + document.getElementById("TelcomIpAddress").value+
						"&TelcomEnabled=" + document.getElementById("TelcomEnabled").value;

			// POST 請求必須設置表頭在 open() 下面,send() 上面
			request.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
			request.send(data);

			request.onreadystatechange = function() {
				// 伺服器請求完成
				if (request.readyState == 4) {
					 document.getElementById("loading").style.display="none";
					// 伺服器回應成功
					if (request.status == 200 && JSON.parse(request.responseText).result=="Success") {
						alert("<?php echo $lang->showWord("done")?>");
						location.href="set_network.php";
					} else {
						alert(JSON.parse(request.responseText).message);
					}
					request = null;
				}
			}
		}
	}

	function formCheck()
	{
		if(document.getElementById("Eth0IpAddress").value != ""){
			if(!ValidateIPaddress("Eth0IpAddress")) return false;
		}
		if(document.getElementById("Eth0SubmaskAddress").value != ""){
			if(!ValidateIPaddress("Eth0SubmaskAddress")) return false;
		}
		if(document.getElementById("Eth0GatewayAddress").value != ""){
			if(!ValidateIPaddress("Eth0GatewayAddress")) return false;
		}
		// if(document.getElementById("Eth1IpAddress").value != ""){
			// if(!ValidateIPaddress("Eth1IpAddress")) return false;
		// }
		// if(document.getElementById("Eth1SubmaskAddress").value != ""){
			// if(!ValidateIPaddress("Eth1SubmaskAddress")) return false;
		// }
		// if(document.getElementById("Eth1GatewayAddress").value != ""){
			// if(!ValidateIPaddress("Eth1GatewayAddress")) return false;
		// }
		if(document.getElementById("WifiIpAddress").value != ""){
			if(!ValidateIPaddress("WifiIpAddress")) return false;
		}
		if(document.getElementById("WifiSubmaskAddress").value != ""){
			if(!ValidateIPaddress("WifiSubmaskAddress")) return false;
		}
		if(document.getElementById("WifiGatewayAddress").value != ""){
			if(!ValidateIPaddress("WifiGatewayAddress")) return false;
		}
		if(document.getElementById("TelcomIpAddress").value != ""){
			if(!ValidateIPaddress("TelcomIpAddress")) return false;
		}

		return true;
	}

	function WifiMode_changed(){
		if(document.getElementById("WifiMode").value=="0"){
			document.getElementById("WifiDhcpServer").disabled=true;
			document.getElementById("WifiDhcpClient").disabled=true;
			document.getElementById("WifiSsid").disabled=true;
			document.getElementById("WifiPassword").disabled=true;
			document.getElementById("WifiIpAddress").disabled=true;
			document.getElementById("WifiSubmaskAddress").disabled=true;
			document.getElementById("WifiGatewayAddress").disabled=true;
			document.getElementById("WifiDhcpServerDiv").style.display="none";
			document.getElementById("WifiDhcpClientDiv").style.display="none";
			document.getElementById("WifiSsidDiv").style.display="none";
			document.getElementById("WifiPasswordDiv").style.display="none";
			document.getElementById("WifiRssiDiv").style.display="none";
			document.getElementById("WifiMacAddressDiv").style.display="none";
			document.getElementById("WifiIpAddressDiv").style.display="none";
			document.getElementById("WifiSubmaskAddressDiv").style.display="none";
			document.getElementById("WifiGatewayAddressDiv").style.display="none";
			document.getElementById("WifiNetworkConnDiv").style.display="none";
		}
		if(document.getElementById("WifiMode").value=="1"){
			document.getElementById("WifiDhcpServer").disabled=true;
			document.getElementById("WifiDhcpClient").disabled=false;
			document.getElementById("WifiSsid").disabled=false;
			document.getElementById("WifiPassword").disabled=false;
			document.getElementById("WifiSsid").value="<?php echo $obj->{'WifiSsid'};?>";
			document.getElementById("WifiPassword").value="<?php echo $obj->{'WifiPassword'};?>";
			document.getElementById("WifiIpAddress").disabled=false;
			document.getElementById("WifiSubmaskAddress").disabled=false;
			document.getElementById("WifiGatewayAddress").disabled=false;
			document.getElementById("WifiIpAddress").value="<?php echo $obj->{'WifiIpAddress'};?>";
			document.getElementById("WifiSubmaskAddress").value="<?php echo $obj->{'WifiSubmaskAddress'};?>";
			document.getElementById("WifiGatewayAddress").value="<?php echo $obj->{'WifiGatewayAddress'};?>";
			document.getElementById("WifiDhcpServerDiv").style.display="none";
			document.getElementById("WifiDhcpClientDiv").style.display="block";
			document.getElementById("WifiSsidDiv").style.display="block";
			document.getElementById("WifiPasswordDiv").style.display="block";
			document.getElementById("WifiRssiDiv").style.display="block";
			document.getElementById("WifiMacAddressDiv").style.display="block";
			document.getElementById("WifiIpAddressDiv").style.display="block";
			document.getElementById("WifiSubmaskAddressDiv").style.display="block";
			document.getElementById("WifiGatewayAddressDiv").style.display="block";
			document.getElementById("WifiNetworkConnDiv").style.display="block";
		}
		if(document.getElementById("WifiMode").value=="2"){
			document.getElementById("WifiDhcpServer").disabled=false;
			document.getElementById("WifiDhcpClient").disabled=true;
			document.getElementById("WifiSsid").disabled=true;
			document.getElementById("WifiPassword").disabled=true;
			document.getElementById("WifiSsid").value="<?php echo $ModelName.$SerialNumber?>";
			document.getElementById("WifiPassword").value="";
			document.getElementById("WifiIpAddress").disabled=true;
			document.getElementById("WifiSubmaskAddress").disabled=true;
			document.getElementById("WifiGatewayAddress").disabled=true;
			document.getElementById("WifiDhcpServerDiv").style.display="block";
			document.getElementById("WifiDhcpClientDiv").style.display="none";
			document.getElementById("WifiSsidDiv").style.display="block";
			document.getElementById("WifiPasswordDiv").style.display="block";
			document.getElementById("WifiRssiDiv").style.display="block";
			document.getElementById("WifiMacAddressDiv").style.display="block";
			document.getElementById("WifiIpAddressDiv").style.display="none";
			document.getElementById("WifiSubmaskAddressDiv").style.display="none";
			document.getElementById("WifiGatewayAddressDiv").style.display="none";
			document.getElementById("WifiNetworkConnDiv").style.display="block";
		}
		WifiDhcp_changed();
	}
	function EthDhcp_changed(){
		if(document.getElementById("Eth0DhcpClient").value=="0"){
			document.getElementById("Eth0IpAddress").disabled=true;
			document.getElementById("Eth0SubmaskAddress").disabled=true;
			document.getElementById("Eth0GatewayAddress").disabled=true;
		}
		if(document.getElementById("Eth0DhcpClient").value=="1"){
			document.getElementById("Eth0IpAddress").disabled=false;
			document.getElementById("Eth0SubmaskAddress").disabled=false;
			document.getElementById("Eth0GatewayAddress").disabled=false;
			document.getElementById("Eth0IpAddress").value="<?php echo $obj->{'Eth0IpAddress'};?>";
			document.getElementById("Eth0SubmaskAddress").value="<?php echo $obj->{'Eth0SubmaskAddress'};?>";
			document.getElementById("Eth0GatewayAddress").value="<?php echo $obj->{'Eth0GatewayAddress'};?>";
		}
	}
	function WifiDhcp_changed(){
		if(document.getElementById("WifiDhcpClient").disabled===false && document.getElementById("WifiDhcpClient").value=="0"){
			document.getElementById("WifiIpAddress").disabled=true;
			document.getElementById("WifiSubmaskAddress").disabled=true;
			document.getElementById("WifiGatewayAddress").disabled=true;
		}
		if(document.getElementById("WifiDhcpClient").disabled===false && document.getElementById("WifiDhcpClient").value=="1"){
			document.getElementById("WifiIpAddress").disabled=false;
			document.getElementById("WifiSubmaskAddress").disabled=false;
			document.getElementById("WifiGatewayAddress").disabled=false;
			document.getElementById("WifiIpAddress").value="<?php echo $obj->{'WifiIpAddress'};?>";
			document.getElementById("WifiSubmaskAddress").value="<?php echo $obj->{'WifiSubmaskAddress'};?>";
			document.getElementById("WifiGatewayAddress").value="<?php echo $obj->{'WifiGatewayAddress'};?>";
		}
	}

	function isNumberKey(evt)
	{
		var charCode = (evt.which) ? evt.which : event.keyCode

		if (charCode > 31 && (charCode < 48 || charCode > 57) && (charCode != 46))
			return false;

		return true;
	}

	function ValidateIPaddress(id) {
		var ipaddress = document.getElementById(id).value;
		if (/^(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/.test(ipaddress)) {
			return true;
		}
		alert("You have entered an invalid IP address on " + id + "!")
		document.getElementById(id).focus();
		return false;
	}

	function scan_wifi()
        {
          window.open("scan_wifi.php","_blank","height=200,width=400, status=yes,toolbar=no,menubar=no,location=no");
        }

</script>


</html>