<?	 include "../inc/top.php";  ?>

<SCRIPT LANGUAGE="JavaScript">
//========================================================//
// JAVA Script code
//========================================================//
var gPhp = new Array("../php/system_get_network.php","../php/system_set_network.php", "../php/service_get_timemachine.php","../php/service_set_timemachine.php","../php/service_get_browserinfo.php");
var gIdTable=new Array('idTable_HOST_EDIT','idTable_INTERFACE_EDIT','idTable_DOMAIN_EDIT','idTable_POPUP');

var gNetworkInfo = new NetworkInfo('0','0','0','0','0','0','0','0','0','0','0','0','0','0','0');
var gTimeMachine;

function NetworkInfo(HOSTNAME,HOSTDESC,IP_TYPE,IPADDR,NETMASK,GATEWAY,DNS1,DNS2,MTU,DOMAIN_TYPE,WORKGROUP,DOMAIN,DOMAINUSER,DOMAINPASS,MACADDR)
{
	this.HOSTNAME 		= HOSTNAME;
	this.HOSTDESC 		= HOSTDESC;
	this.IP_TYPE  		= IP_TYPE;
	this.IPADDR 		= IPADDR;
	this.NETMASK 		= NETMASK;
	this.GATEWAY 		= GATEWAY;
	this.DNS1 		= DNS1;
	this.DNS2 		= DNS2;
	this.DOMAIN_TYPE 	= DOMAIN_TYPE;
	this.WORKGROUP 		= WORKGROUP;
	this.DOMAIN 		= DOMAIN;
	this.DOMAINUSER 	= DOMAINUSER;
	this.DOMAINPASS 	= DOMAINPASS;
	this.MACADDR       = MACADDR;
}

function display_POPUP(mode)
{

	//alert("display_POPUP");
  	var popup_header = new String();
	var popup_footer = new String();
	var popup_contents = new String();
	var popup_button = new String();
	var popup_button_header = new String();
	var popup_button_link = new String();
	var popup_button_footer = new String();
	
	
	popup_header 	= "<table width=\"420\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\" >"
			+"<tr><td height=\"120\" align=\"center\" class=\"red_s2\">"
	popup_footer 	= "</td></tr>";
	popup_button_header = "<tr><td align=\"center\"><img class=\"buttons\" border=\"0\" onclick=\""; 
	popup_button_footer = "\" src=\"../images/btn/btn_confirm.gif\"></td>"
        			+"</tr></table>";
	
	var popup = new String();


	if(mode == 'samehost'){
		popup_contents = "<?php echo lang_get('network_msg_2')?>"
		popup_button_link = "showTable('idTable_HOST_EDIT');";
	}
        
	if(mode == 'host'){

		popup_contents = "<?php echo lang_get('TimeMachine_3')?>"
		popup_button_link = "Get_TimeMachine_check_enabled();showTable('idTable_HOST_EDIT');";
	}

	if(mode == 'host_err'){

		popup_contents = "<?php echo lang_get('host_name_rule')?>"
		popup_button_link = "showTable('idTable_HOST_EDIT');";
	}

	if(mode == 'desc_err'){

		popup_contents = "<?php echo lang_get('network_msg_6')?>"
		popup_button_link = "showTable('idTable_HOST_EDIT');";
	}

	if(mode == 'apply_host'){

		popup_contents = "<?php echo lang_get('TimeMachine_2')?>"
		popup_button = 'off';
	}
	if(mode == 'timemachine'){
		popup_contents = "<?php echo lang_get('TimeMachine_2')?>"
		popup_button = 'off';	

	}
	if(mode == 'tm_err'){
		popup_contents = "<?php echo lang_get('TimeMachine_5')?>"
		popup_button_link = "showTable('idTable_HOST_EDIT');";

	}
	if(mode == 'tm_ok'){
		popup_contents = "<?php echo lang_get('TimeMachine_3')?>"
		popup_button_link = "Get_TimeMachine_check_enabled();showTable('idTable_HOST_EDIT');";

	}
	if(mode =='invalid_os'){
		popup_contents = "<?php echo lang_get('TimeMachine_4')?>"
		popup_button = 'off';
	}

	if(popup_button == 'off') 
		popup = popup_header + popup_contents + popup_footer + "</table>";
	else 
		popup = popup_header + popup_contents + popup_footer + popup_button_header + popup_button_link + popup_button_footer;
		
	
	
	//if(mode =='invalid_os'){
	//	showTable('invalid_os');
	//}
	//else
	//{
		showTable('processing');
	//}

	document.getElementById('system_message').innerHTML = popup;
	
	//}
	
	//gprevious_mode = mode;

}

function showTable(id)
{
	if(id == 'processing')
     	{
     		document.getElementById('idTable_POPUP').style.display = "block";
     		document.getElementById('idTable_Title').style.display = "none";
		document.getElementById('idTable_box').style.display = "none";		
	}
	else if(id == 'invalid_os')
     	{
     		document.getElementById('idTable_POPUP').style.display = "none";
     		document.getElementById('idTable_Title').style.display = "block";
		document.getElementById('idTable_box').style.display = "none";		
	}	
	else
	{	
		document.getElementById('idTable_POPUP').style.display = "none";	
     		document.getElementById('idTable_Title').style.display = "block";
		document.getElementById('idTable_box').style.display = "block";
	}
		
}

function Set_Timemachine_Info()
{
/*
	var 	TIMEMACHINE;
	if (document.getElementsByName('rdoTimeMachine_enable').checked) 
		TIMEMACHINE = 'on';
	else  	
		TIMEMACHINE = 'off';	
*/
		
	if(HostCheck()){
		display_POPUP('timemachine');				
		Set_TimeMachine('timemachine');
	} 
	else 
	{
	       display_POPUP('host_err');
	}
/*	if(gTimeMachine != TIMEMACHINE)
	{
		display_POPUP('apply_host');
		Set_TimeMachine('timemachine');
	}
*/	
}

function containsCharsOnly(input,chars) {

    	var non_start_char = "-_";
    	if(!(non_start_char.indexOf(input.value.charAt(0)) == -1)) return false;

    	for (var inx = 0; inx < input.value.length; inx++) {
       		if (chars.indexOf(input.value.charAt(inx)) == -1)
           	return false;
    	}
    	return true;
}


function containsCharsOnlyHOST(input,chars) {

    	var non_start_char = "-_0123456789";
    	if(!(non_start_char.indexOf(input.value.charAt(0)) == -1)) 
    		return false;
    	for (var inx = 0; inx < input.value.length; inx++) {
       		if (chars.indexOf(input.value.charAt(inx)) == -1)
           	return false;
    	}

	var non_end_char = "-_";
	var len = input.value.length;
	len = len-1;
		
    	if(!(non_end_char.indexOf(input.value.charAt(len)) == -1))
    		return false;
    	return true;
}


function valid_name(input) {
    	var chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-";
    	if(input.value.length<3) return false;	
	//if(input.value.length>12) return false;	
    	return containsCharsOnly(input,chars);
}

function valid_description(input) {
    	var chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_ ";
	if(input.value.length<3) return false;
	if(input.value.length>24) return false;	
    	return containsCharsOnly(input,chars);
}
function Set_Network_Info(mode)
{	
	var 	HOSTNAME,HOSTDESC,IP_TYPE,IPADDR,NETMASK,GATEWAY,WORKGROUP,DNS1,DNS2,MTU,DOMAIN_TYPE,WORKGROUP,DOMAIN,DOMAINUSER,DOMAINPASS,MACADDR;

	HOSTNAME 	= document.getElementById('txtHOSTNAME').value;
	MACADDR 	= document.getElementById('txtMACADDR').value;

	var _txText =	'&txtHostName='+HOSTNAME
			+"&txtMacAddress="+MACADDR
			+"&txtMode="+mode;

	sendRequest(onLoadST,_txText,'post',gPhp[1],true,true);
	

	return true;

	
}
function onLoadST(oj)
{
	var res = new String();
	var code = new Array();
	res = decodeURIComponent(oj.responseText);
	
	code = res.split(':');
	//alert(code);
	if(code[0] == 'ok') {display_POPUP(code[1]);}

	//display_POPUP('apply_host');

	
}

function HostCheck() {
	
	var hostname = document.getElementById('txtHOSTNAME').value;
	if(!(valid_name(document.getElementById('txtHOSTNAME')))) {
		//alert('The entered hostname is not valid\nHostname may include at least 3 and up to 12 alphanumeric character including hypen and underscore');	
		return false;
	}
	return true;
}
/*
function DescCheck() {
	var hostdesc = document.getElementById('txtHOSTDESC').value;
	alert(hostdesc);
	if(!(valid_description(document.getElementById('txtHOSTDESC')))) {
		//alert('The entered descriptionn is not valid\nDescription may include at least 3 and up to 12 alphanumeric character including hypen, space, and underscore');	
		return false;
	}
	return true;
}
*/

function Set_TimeMachine(mode)
{	

	var TIMEMACHINE, HOSTNAME, MACADDR;

	if (document.getElementById('rdoTimeMachine_enable').checked) 
	{	
		TIMEMACHINE = 'on';
	}
	else 
	{
		TIMEMACHINE = 'off';	
	}
	HOSTNAME 	= document.getElementById('txtHOSTNAME').value;
	MACADDR 	= document.getElementById('txtMACADDR').value;
	
	
	var _txText =	'&timemachinOnOff='+TIMEMACHINE
	              +'&host_name='+HOSTNAME
	              +'&mac_addr='+MACADDR
			+"&txtMode="+mode;

	sendRequest(onLoad_SetTM,_txText,'post',gPhp[3],true,true);

	return true;
}


function onLoad_SetTM(oj)
{
	var res = new String();
	var code = new Array();
	res = decodeURIComponent(oj.responseText);
	
	code = res.split(':');
	//alert(code);
	if(code[0] == 'ok') 
		display_POPUP(code[1]);
	else
	{
		document.getElementById('rdoTimeMachine_enable').checked = false;
		document.getElementById('rdoTimeMachine_disable').checked = true;
		document.getElementById('txtHOSTNAME').value ='';
		document.getElementById('txtMACADDR').value ='';

		display_POPUP(code[1]);
	}

	//display_POPUP('apply_host');	
}

function Get_TimeMachine_Net_Info()
{
	sendRequest(onLoadDT,'','post',gPhp[2],true,true);
	return true;
}

function onLoadDT(oj)
{
	var res = decodeURIComponent(oj.responseText);
	//alert(res);
	var _item = res.split("=>");

	gNetworkInfo.HOSTNAME 		= _item[0];
	//gNetworkInfo.HOSTDESC 		= _item[1];
	gNetworkInfo.MACADDR		= _item[14];


	document.getElementById('txtHOSTNAME').value =gNetworkInfo.HOSTNAME;
	document.getElementById('txtMACADDR').value =gNetworkInfo.MACADDR;

}

function Get_TimeMachine_info()
{

	//Check valid OS (Mac)
	sendRequest(onLoad_GetWB,'','post',gPhp[4],true,true);
	return true;
}

function onLoad_GetWB(oj)
{
	var res = decodeURIComponent(oj.responseText);

	if(res.match('mac'))
	{
		Get_TimeMachine_check_enabled();
	}
	else
	{
		display_POPUP('invalid_os');
	}
}

function Get_TimeMachine_check_enabled()
{
	sendRequest(onLoad_GetTM,'','post',gPhp[2],true,true);
	return true;
}

function onLoad_GetTM(oj)
{
	var res = decodeURIComponent(oj.responseText);
	//alert(res);
	var _item = res.split('=>');
	
	if(_item[1] == 'on')
	{
		document.getElementById('rdoTimeMachine_enable').checked = true;
		document.getElementById('rdoTimeMachine_disable').checked = false;
	}
	else
	{
		document.getElementById('rdoTimeMachine_enable').checked = false;
		document.getElementById('rdoTimeMachine_disable').checked = true;;
	}
	document.getElementById('idCheck_enable').style.display = "block";

	gNetworkInfo.HOSTNAME 		= _item[2];
	gNetworkInfo.MACADDR		= _item[3];

	document.getElementById('txtHOSTNAME').value = gNetworkInfo.HOSTNAME;
	document.getElementById('txtMACADDR').value  = gNetworkInfo.MACADDR;

}
//========================================================//
// show_help
//========================================================//
function show_help()
{
	var _win = window.open('../help/service/help_machine.html','Help_ddns','titlebar=no,scrollbars=yes,status=no,toolbar=no,resizable=yes,location=no,menu=no,width=600px,height=500px,left=540,top=240');
  _win.focus();
	hPopWin = _win;
}



</SCRIPT>

<tr>
<td valign="top">
	<table width="100%" border="0" cellspacing="0" cellpadding="0">
	<tr>
	<td width="245" valign="top"><?php include "../inc/left.php";  ?></td>	<!-- left Navigation -->
	<td width="100%" valign="top">
		<table width="100%" border="0" cellspacing="0" cellpadding="0">
		<tr>
		<td width="100%" height="7" background="../images/Top/utility_shadow.gif"></td>
		</tr>
		<tr>
		<td style="padding:0 0 0 50px">


 			<!-- Message Table : Start -->	
			<div id="idTable_POPUP" style="width:670px; margin-top:40px; display:none" >
					<table width="420" height="260" align="center" cellspacing="0" cellpadding="0">
							<tr>
									<td height="54px"  background="../images/popup/txt_popup_bg_01.gif" style="padding-left:20px"><span class="popup_text"><?php echo lang_get('TimeMachine_1')?></span></td>
							</tr>
							<tr>
									<td align="center" valign="top" style="padding:0 0 0 0px">
										<div id="system_message"><?php echo lang_get('common_loading')?></div>
									</td>
							</tr>
					</table> 		
			</div>

			<div id="page_loading" align="center" style="position:absolute;left:450px;top:330px;width:300px;height:100px;display:none;background-color:#fff;">
				<table border="0" cellspacing="0" cellpadding="0" width="300px">	
				<tr>
				<td colspan="2" style="backgRound-color:#742625;color:#fff;height:25px;font-size:15px;font-weight:bold;padding-left:20px;"><?php echo lang_get('common_loading')?></td>
				</tr>
				<tr>
				<td style="border:1px solid #5d5d5d;border-right:none;height:75px;width:100px;" align="center">
				<img Id="img_page_loading" src="../images/Burn/file_box_loading.gif"/>
				</td>
				<td style="border:1px solid #5d5d5d;border-left:none;height:75px;width:200px;"><?php echo lang_get('common_wait')?></td>
				</tr>
				</table>
			</div>	  		

	  		
                  	<!-- 1. Page Title : Network -->
                  	<div id="idTable_Title";display:block" >
			<table width="670" cellspacing="0" cellpadding="0" style="margin:40px 0 10px 0;">
                    <tr>
                      <td height="50" valign="top"><img src="../images/headtitle/htit_time_machine.gif"/></td>
                    </tr>
			</table>
                     </div>
                     
                     <div id="idTable_box"; display:block" >
                  	<table width="670" border="0" cellspacing="0" cellpadding="0" class="basicTable">
                     	<tr>
			<td class="header" width="250px"><?php echo lang_get('TimeMachine_1')?></td>
			<td class="header" width="420px">

			<div id="idCheck_enable" style="display:none;">
			<input type="radio" name="rdoTimeMachine" id="rdoTimeMachine_enable" value="on" /><label for="rdoTimeMachine_enable"><?php echo lang_get('common_enable')?></label>	
			<input type="radio" name="rdoTimeMachine" id="rdoTimeMachine_disable" value="off" checked /><label for="rdoTimeMachine_disable"><?php echo lang_get('common_disable')?></label>
			</div>

			</td>
                    	</tr>
		
               <tr>
                    <td class="firstCol_250"><?php echo lang_get('network_host_2'); ?></td>
                     <td class="otherCol_420"><input name="txtHOSTNAME" type="text" class="inputtext" id="txtHOSTNAME" value="<?php echo lang_get('common_loading')?>" size="30" maxlength="12"></td>
                </tr>
                <tr>
                    <td class="firstCol_250"><?php echo lang_get('status_network_2'); ?></td>
                     <td class="otherCol_420"><input name="txtHOSTDESC" type="text" class="inputtext" id="txtMACADDR" value="<?php echo lang_get('common_loading')?>" size="30" maxlength="24"></td>
                </tr>
                
			<tr>
			<td colspan="2" align="right" style="padding:20 0 0 0px"><img src="../images/btn/btn_apply.gif" border="0" onclick="Set_Timemachine_Info();" class="buttons"/></td>
			</tr>				
                    	
                    	</table>   
                    	</div>
                    	</td>
		</tr>	
		<!--<tr>
		<td colspan="2" align="right" style="padding:20 0 0 0px"><img src="../images/btn/btn_apply.gif" border="0" onclick="Set_TimeMachine();" class="buttons"/></td>
		</tr>-->				
  		</table>
  	</td>
  	</tr>
	</table>		
</td>
</tr>        





<?php include "../inc/bottom.php";  ?>


<script language='javascript' charset='utf-8'>
       Get_TimeMachine_info();	
       
</script>

 
