<?php
/*
  osCommRes, Services Online
  http://www.oscommres.com

  Copyright (c) 2005 osCommRes

  Released under the GNU General Public License
  Freeway eCommerce from ZacWare
http://www.zac-ware.com/freeway

Copyright 2007 ZacWare Pty. Ltd 
*/
// Set flag that this is a parent file
	define( '_FEXEC', 1 );
require ('includes/application_top.php');
tep_get_last_access_file();
require (DIR_WS_CLASSES . 'currencies.php');
require ('includes/classes/split_page_results_event.php');
$currencies = new currencies();
$server_date = getServerDate(true);
$band_id = tep_db_prepare_input($HTTP_GET_VARS['band_id']);
$current_date = date('Y-m-d');
$page = isset ($HTTP_GET_VARS['page']) ? $HTTP_GET_VARS['page'] : 1;
$action = (($HTTP_GET_VARS['action']) ? $HTTP_GET_VARS['action'] : '');
	if ($action != "") {
	$band_id = tep_db_prepare_input($HTTP_GET_VARS['band_id']);
	if($action=='zone_list') zone_list($band_id);
	#get tax descriptions to display in tax selection	
	if ($action == 'get_details')
		echo_get_details();
	else if ($action == 'update') {
		$band_id = tep_db_prepare_input($HTTP_GET_VARS['band_id']);
		if ($action == 'update') {
			if(!$HTTP_POST_VARS['zone_from'] && !$HTTP_POST_VARS['zone_to']){
			   $sql_data_array = array('basic'=>$HTTP_POST_VARS['basic'],'per_kg'=>$HTTP_POST_VARS['per_kg']);
			   tep_db_perform(TABLE_SKYNET_RATES, $sql_data_array,"update","band='".(int)$band_id."'");
			   $action='get_details';
			   echo_get_details();					
			}else if($HTTP_POST_VARS['zone_from'] && $HTTP_POST_VARS['zone_to']){
				$sql_data_array = array('band'=>$band_id,'zone_from'=>$HTTP_POST_VARS['zone_from'],'zone_to'=>$HTTP_POST_VARS['zone_to']);
				$check_exists=tep_db_query("select zone_from from ".TABLE_SKYNETZONES_BANDS." where band='".$band_id."' and zone_from='".$HTTP_POST_VARS['zone_from']."' and zone_to='".$HTTP_POST_VARS['zone_to']."'");
				if(tep_db_num_rows($check_exists)>0) echo "error^^".TEXT_ERROR_ZONE_ALREADY_EXISTS;
				else {
					tep_db_perform(TABLE_SKYNETZONES_BANDS, $sql_data_array);
					$action='zone_list';
					zone_list($band_id);
				}									
			}				
		}						
		/*if (!$HTTP_GET_VARS['band_id']) echo 'new_skynet^^' . $band_id . '||' . $HTTP_POST_VARS['band'] . '||' . $currencies->format($HTTP_POST_VARS['basic']);*/
		//else echo_get_details();
	} else if ($action == 'edit') {
		$band = array ('band' => '','basic' => '','per_kg' => '');
		if($band_id){
			$band_query=tep_db_query("select basic,per_kg from ".TABLE_SKYNET_RATES." where band='".(int)$band_id."'");
			$band=tep_db_fetch_array($band_query);	
		}
	}else if ($action == 'delete_confirm') {
		tep_db_query("delete from " . TABLE_SKYNETZONES_BANDS . " where band = " . (int) $band_id . " and zone_from='".$HTTP_GET_VARS['z_from']."' and zone_to='".$HTTP_GET_VARS['z_to']."'");
		$action='zone_list';
		zone_list($band_id);							
	}
	if ($action == 'page_navigation' || $action == 'sel_service') {
		echo $action . '^^';
		table_write();
	}
	if ($action == 'edit') {	
		if (!$HTTP_GET_VARS['band_id'])
			echo 'new^^';
		else echo "edit^^";
		create_new_band();
	}
	exit;
}
function echo_get_details() {
   global $band_id, $currencies;
	$band_query = tep_db_query("select band,basic,per_kg from " . TABLE_SKYNET_RATES . " where band='" . (int) $band_id . "'");
	if (tep_db_num_rows($band_query) > 0) {
		$band = tep_db_fetch_array($band_query);
		while (list ($key, $vals) = each($band)){
		    if($key=='basic' || $key=='per_kg') $vals = $currencies->format($vals);
		 	  $str_vals .= $vals."||";
		}
	} else $str_vals = "No Record Found";	
	echo 'get_details^^' . $str_vals;
}

function zone_list($band_id){
	global $action;
	echo $action.'^^';
	//$zone_query=tep_db_query("select b.zone_from,b.zone_to,z.zone_name from ".TABLE_SKYNETZONES_BANDS." b,".TABLE_ZONES." z where b.band='".(int)$band_id."' and z.zone_code=substring(b.zone_from,1,2)");	
	$zone_query=tep_db_query("select zone_from,zone_to from ".TABLE_SKYNETZONES_BANDS ." where band='".(int)$band_id."' order by zone_from,zone_to asc");
	if(tep_db_num_rows($zone_query)>0){ ?>
	<table border="0" cellspacing="0" cellpadding="0" width="100%">
	 <tr>	 
	 <td valign="top">	
	 <table border="0" cellspacing="0" cellpadding="1" width="100%">	
	  <tr  style="height:30" valign="bottom" class="openContent_top">
        <td width="30%" class="dataTableHeadingContent" align="center"><?php echo TEXT_FROM_ZONE; ?></td>
	    <td width="20%"></td>		  
		<td width="27%" align="center" class="dataTableHeadingContent"><?php echo TEXT_TO_ZONE;?></td>
		<td width='34%' align="center"></td>												
      </tr>
      <tr>	 
	  <td colspan="4">	
	  <div style="overflow:auto;width:100%;height:200;">
	  <table border="0" cellspacing="0" cellpadding="1" width="100%">
	<?php while($zone=tep_db_fetch_array($zone_query)){
			$class = "dataTableRowEven";
			if ($it_total % 2 == 0) $class = "dataTableRowOdd";
			$it_total++;
			echo ' <tr class="' . $class . '" onmouseover="rowOverEffect(this)" onmouseout="rowOutEffect(this)">' . "\n";?>
			    <td>
			       <table border="0" cellspacing="0" cellpadding="0" width="100%">
			         <tr height="25">
			         	<td class="dataTableContent" align="center" width="30%"><?php echo $zone["zone_from"] ; ?></td>
			         	<td width="20%">&nbsp;</td>
			         	<td class="dataTableContent" align="center" width="30%"><?php echo $zone["zone_to"]; ?></td>
						<td class="dataTableContent" align="center" width="30%"><a href="javascript:expand_category(<?php echo $band_id;?>,5,'<?php echo $zone["zone_from"];?>','<?php echo $zone["zone_to"];?>');"><img src='images/template/img_trash.gif' alt='Delete' title='Delete' border='0'></a></td>
			         </tr>
			      </table>
			    </td>
	       </tr>	       
 	<?php } ?> 	
 	  </table>
 	  </div>
 	  </td>	
	  </tr>
	   </table>	  
	 </td>
	</tr>
	<tr><td id="new_create"></td></tr>
	</table>	
	<?php }
}

function table_write() {
	global $HTTP_GET_VARS, $page, $currencies, $action;
?>
   <table border="0" cellpadding="0" cellspacing="0" width="100%">	       	   
  <?php
	$type = 'DP';
	if ($HTTP_GET_VARS['service_type'] != "")
		$type = $HTTP_GET_VARS['service_type'];
	$band_query = "select band,basic,per_kg from " . TABLE_SKYNET_RATES . " where service='" . $type . "'";
	$band_split = new splitPageResultsEvent($page, MAX_DISPLAY_SEARCH_RESULTS, $band_query, $band_query_numrows);
	$band_result_query = tep_db_query($band_query);
	$total_rows = tep_db_num_rows($band_result_query);
	$it_total = 0;
	if ($total_rows > 0) {
		while ($band = tep_db_fetch_array($band_result_query)) {
			$class = "dataTableRowEven";
			if ($it_total % 2 == 0)
				$class = "dataTableRowOdd";
			$it_total++;
			echo '  <tr class="' . $class . '" onmouseover="rowOverEffect(this)" onmouseout="rowOutEffect(this)" onclick="javascript:if(document.getElementById(\'head_' . $band['band'] . '\').style.display==\'none\') expand_category(' . $band['band'] . ',3);">' . "\n";
?>
			    <td>
			      <div id="data_<?php echo $band['band'];?>">
			       <table border="0" cellspacing="0" cellpadding="0" width="100%">
			         <tr height="25">		         	
			         	<td class="dataTableContent" width="30%"><?php echo '&nbsp;' . $band["band"] ; ?></td>
			         	<td class="dataTableContent" width="30%"><?php echo $currencies->format($band["basic"]); ?></td>
			         	<td class="dataTableContent" align="right" width="10%"><?php echo '&nbsp;' . $currencies->format($band["per_kg"]) ; ?></td>			         		  			 	 
			         	<td class="dataTableContent" align="right" width="25%"></td>
			         </tr>
			      </table>
			      </div>
			      <div style="display:none" class="openContent" id="head_<?php echo $band["band"];?>"></div> 
			    </td>		 		  	 	  	
	       </tr>              
		 <?php
		   
		}
	} else {
?>
		<table border="0" cellspacing="0" cellpadding="0" width="100%">			
			<tr><td class="main" align="center"><?php echo N0_SEARCH_RESULT;?></td></tr>
		</table>		      	
   <?php } ?>
   			  <tr><td colspan="4"><?php echo tep_draw_separator('pixel_trans.gif','1','10');?></td></tr>
                <tr>
                	<td colspan="4">
                		<table border="0" width="100%" cellspacing="0" cellpadding="2">
		                  <tr>				  
		                    <td class="smallText" valign="top"><?php echo (($total_rows)?$band_split->display_count($band_query_numrows, MAX_DISPLAY_SEARCH_RESULTS, $page,TEXT_DISPLAY_NUMBER_OF_BAND):''); ?></td>
		                    <td class="smallText" align="right"><?php echo (($total_rows)?$band_split->display_script_links($band_query_numrows, MAX_DISPLAY_SEARCH_RESULTS, MAX_DISPLAY_PAGE_LINKS, $page,1,'expand_category(\'\'','1'):''); ?></td>		                    
		                  </tr>
		  				  <tr><td><?php  echo tep_draw_separator('pixel_trans.gif',5,10); ?></td></tr>		  		 			 	
				  		  <tr>
				  		  	 <td align="right"><?php echo (($search_fnd)?'<a href="javascript:expand_category(1,\'1\',\'reset\');">' . tep_image_button('button_reset.gif', IMAGE_RESET) . '</a>':'');?></td>
				  		  </tr>
             		   </table>
             		</td>
                </tr>
		</table>		
 <?php

	}
function create_new_band() {
 global $band_id,$band;
 if(!$band_id){
 $zones_query=tep_db_query("select distinct zone from ".TABLE_SKYNETZONES_POSTCODES);
 $zones_array=array();
 if(tep_db_num_rows($zones_query)>0)
 	while($zones=tep_db_fetch_array($zones_query))
 		$zones_array[]=array('id'=>$zones['zone'],'text'=>$zones['zone']); 	 
?>
	<table border="0" cellspacing="3" cellpadding="3" width="100%">	   	
	   <tr style="height:5"><td class="errorText" id="insert_error"></td></tr>
	   <tr class="openContent_top">
	   	 <td colspan="3" class="main"><?php echo TEXT_INSERT_NEW_ZONE;?></td>
	   </tr>
	   <tr>
	   	 <td class="main"><?php echo TEXT_FROM_ZONE.'&nbsp;'.tep_draw_pull_down_menu('zone_from',$zones_array);?></td>
	   	 <td class="main"><?php echo TEXT_TO_ZONE.'&nbsp;'.tep_draw_pull_down_menu('zone_to',$zones_array);?></td>
	   	 <td align='right' id='img_save'><input type='image' src='images/template/img_savel.gif' alt='save' title='save' border='0'>&nbsp;&nbsp;<a href='javascript:expand_category(0,1);'><img src='images/template/img_closel.gif' alt='close' title='close' border='0'></a>&nbsp;&nbsp;</td>
	   </tr>
  	</table>
<?php } else if($band_id) { ?> 
	<table border="0" cellspacing="3" cellpadding="3" width="100%">
		<tr>
	   	 <td class="main"><?php echo TEXT_BASIC_RATE.'&nbsp;'.tep_draw_input_field('basic',$band['basic']);?></td>
	   	 <td class="main"><?php echo TEXT_PER_KG.'&nbsp;'.tep_draw_input_field('per_kg',$band['per_kg']);?></td>
	    </tr>
	    <tr><td><?php  echo tep_draw_separator('pixel_trans.gif',5,10); ?></td></tr>
	</table>	    
<?php }
} ?>	
<html <?php echo HTML_PARAMS; ?>>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=<?php echo CHARSET; ?>">
<title><?php echo TITLE; ?></title>
<link rel="stylesheet" type="text/css" href="includes/stylesheet.css">
<script language="javascript" src="includes/menu.js"></script>
<script language="javascript" src="includes/general.js"></script>
<script language="javascript" src="includes/http.js"></script>
<script language="javascript">				
	var max_display="<?php echo MAX_DISPLAY_SEARCH_RESULTS;?>";
	var img_src="<?php echo HTTP_SERVER.DIR_WS_ADMIN.'images/';?>";						
	function ValidateForm() 
	 {
	 var frm=document.skynet;
	 var error_result="";	 
	 if(document.skynet.action_type) var action_type=document.skynet.action_type.value;
	 if(frm && frm.band_id) id=frm.band_id.value;
	 var span_details=document.getElementById("span_details");
	 var span_edit=document.getElementById("span_edit");				
	 var span_delete=document.getElementById("span_delete");
	 var loadings=document.getElementById("loading");
	 var ids="";
	 if(span_edit && span_edit.style.display=="" || document.getElementById("new_create") && document.getElementById("new_create").innerHTML!=""){
		 if(document.getElementById("basic") && document.getElementById("basic").value<=0)
				error_result+="<?php echo tep_db_input(TEXT_BASIC_ERROR); ?>\n";	
		 else if(document.getElementById("per_kg") && document.getElementById("per_kg").value<=0)
				error_result+="<?php echo tep_db_input(TEXT_PERKG_ERROR); ?>\n";
		 if(error_result!="")
		 {
			alert(error_result);
			return false;
		 }else{
			if(span_edit && span_edit.style.display=="" || document.getElementById("new_create") && document.getElementById("new_create").style.display==""){
				if(frm.action_type && (frm.action_type.value=='edit' || frm.action_type.value=='new'))  ids="&band_id="+id;
				command="<?php echo tep_href_link(FILENAME_SKYNET_ZONESETTINGS,'action=update');?>"+ids;													
				if(document.getElementById("new_create") && document.getElementById("new_create").innerHTML!=""){
					var zone_frm_obj=document.getElementById("zone_from");
					var zone_to_obj=document.getElementById("zone_to");
					if(zone_frm_obj && zone_to_obj) command+="&zone_from="+zone_frm_obj.options[zone_frm_obj.selectedIndex].value+"&zone_to="+zone_to_obj.options[zone_to_obj.selectedIndex].value;									
				}
				//if(span_edit) span_edit.style.display="none";
				if(document.getElementById("new_create")){					
					//document.getElementById("new_create").style.display="none";
					document.getElementById('img_new').firstChild.src=document.getElementById('img_new').firstChild.src.replace('_hover.gif','.gif');
					display_flag=1;
				}
			} 					
		 }
	 }else if(span_delete && span_delete.style.display==""){								
				span_details.innerHTML=span_edit.innerHTML="";
				command="<?php echo tep_href_link(FILENAME_SKYNET_ZONESETTINGS,'action=delete_confirm');?>&band_id="+id;						
				if(loadings) loadings.style.display=""; 					
				if(span_delete) span_delete.style.display="none";			
	 }	 
	 do_post_command('skynet',command);
	 return false;
	}   	  
 function expand_category(id,category,r_type,sta_type){
   if(id==0 && category==2) display_flag=0;	 	 			
   if(id==0 && category==1){
     if(document.getElementById('img_new'))
 		 document.getElementById('img_new').firstChild.src=document.getElementById('img_new').firstChild.src.replace('_hover.gif','.gif');
	 display_flag=1;
	} 	 		
	var span_details=document.getElementById("span_details");
 	var span_edit=document.getElementById("span_edit");			
	var span_delete=document.getElementById("span_delete");								
	var data_id=document.getElementById("data_"+id);						
	var head=document.getElementById("head_"+id);
	var img_save=document.getElementById("img_save");
	if(!sta_type) sta_type="";
	var obj=document.getElementById("page_1");
	if(category=='1' &&  obj && sta_type!=""){
 		id=parseInt(obj.options[obj.selectedIndex].value);
 		if(sta_type=='next') {
 			if(obj.length==obj.selectedIndex+1) return;
 			id+=1;
 		}else if(sta_type=='prev') {
 			if(obj.selectedIndex==0) return;
 			id-=1;
 		}
 		if(id<=1) id=1;
 	}else if(category==1 && sta_type=="") id="";
 	if(category==1 && document.getElementById("new_create").style.display=="")	{
 		document.getElementById("new_create").innerHTML="";
 		document.getElementById("new_create").style.display="none";	
 	}
 	/*if(category!=2 && id==0 && document.skynet.band_id && document.skynet.band_id.value>0 && document.getElementById("head_"+document.skynet.band_id.value) && document.getElementById("data_"+document.skynet.band_id.value)){
		if(span_edit) span_edit.innerHTML="";
		//document.getElementById("head_"+document.skynet.band_id.value).style.display="none";
		//document.getElementById("data_"+document.skynet.band_id.value).style.display="";
		if(document.getElementById("new_create")) document.getElementById("new_create").style.display="";						
 	}*/		 
 	 	var res_display=document.getElementById("res_display");
 	 	if(res_display) res_display.style.display="none";
 	 	 if(category!=1 && document.skynet && document.skynet.band_id && document.skynet.band_id.value>0)  {
			var old_ids=document.skynet.band_id.value;			
			var pre_data_id=document.getElementById("data_"+old_ids);
			var pre_head=document.getElementById("head_"+old_ids);			
			var loadings=document.getElementById("loading");						
			//if(loadings) loadings.style.display="none";
			if(category==1 && pre_head && pre_head.innerHTML!='') pre_head.innerHTML="";									
		 }		 		 	 
		 if(id>0 && document.skynet.band_id.value>0 && document.skynet.band_id.value!=id){			   
			   if(pre_head && pre_head.style.display=="") {
			   		pre_head.innerHTML="";
			   		pre_head.style.display="none";
			   }
			   if(pre_data_id && pre_data_id.style.display=="none") pre_data_id.style.display="";
			   document.skynet.band_id.value=id;
		 }
		if(id>0 && category!=1 && document.skynet && document.skynet.band_id) document.skynet.band_id.value=id;								 								 	 	 	 
 	 	if(category){ 	 		
			var command="";
 	 		switch(category){
 	 			case '1':
 	 			       var ser="";
 	 			       var page="";
 	 			        if(document.getElementById("search") && document.getElementById("search").value!="" && sta_type=="" && r_type=='search') {
					   	ser="&search="+document.getElementById("search").value;
						id="";
					    }else if(document.getElementById("search") && document.getElementById("search").value!="" && sta_type=="" && r_type=='reset'){
					  		document.getElementById("search").value="";
					    }else if(document.getElementById("search") && document.getElementById("search").value=="" && sta_type=="" && r_type=='search'){
						display_flag=1;
						document.getElementById('img_new').firstChild.src=document.getElementById('img_new').firstChild.src.replace('_hover.gif','.gif');
						return;
					    }else if(document.getElementById("search") && document.getElementById("search").value=="" && sta_type=="" && r_type=='reset') id=1;
 	 			       if(id!="") page="&page="+id; 
 	 			       command="<?php echo tep_href_link(FILENAME_SKYNET_ZONESETTINGS,'action=page_navigation');?>"+page+ser;
 	 			   	   if(document.getElementById("ajax_details")) document.getElementById("ajax_details").innerHTML="<img src='images/24-1.gif' alt='Loading...' title='Loading...'>"; 	 			   	    	 			   					   
 	 			break;
 	 			case 2:
					 document.getElementById("new_create").style.display="";
					 if(span_details) span_details.style.display="";
					 if(span_edit) span_edit.style.display="none";
					 //document.getElementById("new_create").innerHTML="<img src='images/24-1.gif' alt='Loading...' title='Loading...'>";
 	 				 if(document.skynet.action_type) document.skynet.action_type.value='new'; 	 					
 	 				 command="<?php echo tep_href_link(FILENAME_SKYNET_ZONESETTINGS,'action=edit');?>";
 	 			break; 	 			
 	 			case 3:
 	 			   if(document.getElementById("new_create") && document.getElementById('img_new') && document.getElementById('img_new').firstChild) {
 	 			   		document.getElementById("new_create").innerHTML="";
 	 			   		document.getElementById("new_create").style.display="none";						
						document.getElementById('img_new').firstChild.src=document.getElementById('img_new').firstChild.src.replace('_hover.gif','.gif');
						display_flag=1;
 	 			   } 	 			   
 	 			   if(head && head.style.display==""){
 	 			   	  if(span_details.style.display==""){
 	 			   	    head.style.display="none"; 	 			   	    
 	 			   	  	data_id.style.display="";  	 			   	  		 			   	  
 	 			   	  }else {
 	 			   	  	if(span_edit.style.display=="") span_edit.style.display="none";
 	 			   	  	if(span_delete.style.display=="") span_delete.style.display="none"; 	 			   	  	 	 			   	  	
 	 			   	  	span_details.style.display=""; 	 			   	  	
 	 			   	  	if(img_save) img_save.style.display="none"; 
 	 			   	  	if(document.getElementById("img_ids")){
 	 			   	  		var tr_obj=document.getElementById("img_ids");
 	 			   	  		if(tr_obj.childNodes[1].childNodes[0].src==img_src+'template/img_edit_hover.gif')	
 	 			   	  			tr_obj.childNodes[1].childNodes[0].src=img_src+'template/img_edit.gif';
 	 			   	  		if(tr_obj.childNodes[2].childNodes[0].src==img_src+'template/img_trash_hover.gif')	
 	 			   	  			tr_obj.childNodes[2].childNodes[0].src=img_src+'template/img_trash.gif';	 	 			   	  			
 	 			   	  	}
 	 			   	  }
 	 			 }else {
 	 			 	if(data_id && data_id.style.display=="") data_id.style.display="none";
 	 			 	if(pre_head && pre_head.style.display=="") pre_head.style.display="none"; 	 			 	
 	 			 	if(head) {
 	 			 	 	head.style.display=""; 	 			 	 	 	 			 	  	 			
 	 			 		head.innerHTML="<img src='images/24-1.gif' alt='Loading...' title='Loading...'>";	 			 		
 	 			 	}
 	 			 	command="<?php echo tep_href_link(FILENAME_SKYNET_ZONESETTINGS,'action=get_details');?>&band_id="+id; 	 			 	 	 			 	
 	 			 }
 	 			break;
 	 			case 4:
						if(document.getElementById("new_create")) document.getElementById("new_create").innerHTML="";
 	 					span_edit.style.display=""; 	 					
 	 					span_details.style.display=span_delete.style.display="none";
 	 					span_edit.innerHTML="<img src='images/24-1.gif' alt='Loading...' title='Loading...'>";
 	 					if(document.skynet.action_type) document.skynet.action_type.value='edit'; 	 					
 	 					command="<?php echo tep_href_link(FILENAME_SKYNET_ZONESETTINGS,'action=edit');?>&band_id="+id; 	 		 	 					 	 					 	 				 	 		
 	 			break;
 	 			case 5:
 	 					/*span_delete.style.display="";
 	 					span_edit.style.display=span_details.style.display="none"; 	 					
 	 					span_delete.innerHTML='<table border="0" cellspacing="2" cellpadding="1" width="100%"><tr><td width="17" align="center"><?php echo tep_image('images/template/img_trash.gif')?></td>'+
											  '<td width="500" align="left" class="inner_title"><?php echo TEXT_HEADING_DELETE_SKYNET_BAND;?></td></tr>'+
											  '<tr><td></td><td width="500" align="left" class="main"><?php echo TEXT_DELETE_INTRO;?></td></tr>'+											  				      					       
											  '<tr><td colspan="2"><?php echo tep_draw_separator('pixel_trans.gif',50,10);?></td></tr></table>';*/
						if(confirm("<?php echo DELETE_ZONE_ALERT_MESSAGE;?>")){
							command="<?php echo tep_href_link(FILENAME_SKYNET_ZONESETTINGS,'action=delete_confirm');?>&band_id="+id+"&z_from="+r_type+"&z_to="+sta_type;											  
							if(img_save) img_save.style.display="";
						}
 	 			break;
 	 		}
 	 		if(command!="") do_get_command(command);
 	 	}
 	 }
   function do_result(result){
   	  if(result!="") result_split=result.split("^^");   	  
   	  if(result_split[0]!=""){
   	    id=result_split[0];
   	    val=result_split[1];   	    
   	    if(id.indexOf('get_details')>=0) print_details('get_details',val);
   	    else if(id.indexOf('edit')>=0) print_details('edit',val);
		else if(id.indexOf('delete_success')>=0) print_details('delete_success',val);
		else if(id.indexOf('page_navigation')>=0) print_details('page_navigation',val);
		else if(id.indexOf('sel_service')>=0) print_details('page_navigation',val);		
		else if(id.indexOf('new_skynet')>=0) print_details('new_skynet',val);
		else if(id.indexOf('zone_list')>=0) print_details('zone_list',val);
		else if(id.indexOf('new')>=0 && result!="" && document.getElementById("new_create")) {
			document.getElementById("new_create").style.display="";
			document.getElementById("new_create").innerHTML=val;			
		}else if(id.indexOf('error')>=0 && document.getElementById("insert_error"))
		  if(document.getElementById("insert_error")) {
   		  document.getElementById("insert_error").innerHTML=val;
		   setTimeout("document.getElementById('insert_error').innerHTML=''",2000);		    
		  }
		  clearTimeout();
   	  }	  
   }
   
   function print_details(category,result){ 	 	 	 	 	 	 	 	 	 	
 	 	var no_result="";
		if(result.substr(0,15)=='No Record Found')
 	 		no_result="No Record Found";
 	 	else if(result!='' && result.length>0 && category!='edit' && result.substr(0,15)!='No Record Found'){
 	 		splt_str=result.split("||");
 	 		var  band="";
			var  basic="";
			var  per_kg="";
 	 		band=splt_str[0];
 	 		basic=splt_str[1];
 	 		per_kg=splt_str[2];
 	 	}
 		if(document.skynet && document.skynet.band_id) var id=document.skynet.band_id.value;
 		var span_details=document.getElementById("span_details");
 		var span_edit=document.getElementById("span_edit");
 		var span_delete=document.getElementById("span_delete");
 		var head=document.getElementById("head_"+id);
 		var data_id=document.getElementById("data_"+id);
 		var res_display=document.getElementById("res_display");
 		var img_save=document.getElementById("img_save");
		if(img_save && category!='get_details') img_save.style.display="";
 	 	switch(category){
 	 		case 'get_details': 	 		
 	 		if(head  && no_result!="")
				head.innerHTML=no_result; 	 			 	 		
 	 		else if(head && no_result==""){
	 	 		if(data_id){
	 	 			data_id.innerHTML='<table border="0" cellpadding="0" cellspacing="0" width="100%">'+
						          '<tbody><tr style="height:25">'+
						         	'<td class="dataTableContent" width="30%">&nbsp;'+band+'</td>'+
						         	'<td class="dataTableContent" width="30%">'+basic+'</td>'+
						         	'<td class="dataTableContent" align="right" width="10%">'+per_kg+'</td>'+
						         	'<td class="dataTableContent" align="right" width="25%"></td>'+
						         '</tr>'+
						      	'</tbody></table>';
	 	 		}
	 	 		include="<table width='100%' border='0' cellspacing='0' cellpadding='0'>"+
				"<tr heigth='40' class='openContent_top'>"+
				  "<td align='left' valign='middle' width='10'></td>"+
				  "<td align='left' valign='middle' width='450' class='main'>"+band+"</td>"+				  							  				  				  
				  "<td width='50' align='left' class='main' valign='top'>"+
				  	"<table border='0' cellspacing='0' cellpadding='0' style='width:100;height:30px;display:inline;position:relative;'>"+
				  	  "<tr class='img_move' id='img_ids'>"+
				  	  	"<td class='cell_bg_popm_left' width='10'>&nbsp;</td>"+				  	    
						"<td align='center'  class='img_move' onmouseover='javascript:change_class(this,2);' onmouseout='javascript:change_class(this,3);' id='img_new'><img onClick='javascript:change_class(this,1);expand_category(0,2);'  alt='New Zone' border='0' title='New Zone' src='images/template/img_new.gif'></td>"+
						"<td width='10%' onclick='javascript:change_class(this,1);expand_category("+band+",4);' onmouseover='javascript:change_class(this,2);' onmouseout='javascript:change_class(this,3);'><img alt='Edit' title='Edit' src='images/template/img_edit.gif'></td>"+				  	    
				  	    "<td class='cell_bg_popm_right' width='10'>&nbsp;</td>"+
				  	  "</tr>"+
				  	"</table>"+
				  "</td>"+
				 "<td width='540' align='right'><span style='display:none' id='img_save'><input type='image' src='images/template/img_savel.gif' alt='save' title='save' border='0'>&nbsp;&nbsp;<a href='javascript:expand_category("+band+",3);'><img src='images/template/img_closel.gif' alt='close' title='close' border='0'></a>&nbsp;&nbsp;</span></td>"+
				"</tr>"+
				"<tr style='height:10'><td id='loading' style='display:none' colspan='5'><img src='images/24-1.gif' alt='Loading...' title='Loading...'></td></tr>"+				
				"<tr>"+
				  "<td colspan='8' class='main'><span style='display:none' id='span_edit'></span><span style='display:none' id='span_delete'></span><span id='span_details'>"+	"<table width='100%' border='0' cellspacing='0' cellpadding='0'>"+
				  		"<tr>"+
				  			"<td width='50'><img src='images/pixel_trans.gif' border='0' alt='' width='50' height='1'></td>"+				  							  			
							"<td width='100%'>"+				  							  			
				  				"<table width='50%' border='0' cellspacing='0' cellpadding='3' class='main'>";
				  					if(basic!=""){
				  						include+="<tr>"+
					  						"<td align='center' valign='top'><b><?php echo TEXT_BASIC_RATE;?></b></td>"+
					  						"<td align='left' valign='top'>"+basic+"</td>"+
					  						"<td align='center'><b><?php echo TEXT_PER_KG;?></b></td>"+
					  						"<td align='left'>"+per_kg+"</td>"+
				  						"</tr>";
				  					}					  					
				  			 }				  							
					include+="<tr><td colspan='8'><span id='zone_list'></span></td></tr><tr><td colspan='8'><img src='images/pixel_trans.gif' border='0' alt='' width='100%' height='20'></td></tr></span>"+
				  "</td>"+
				"</tr>"+
			"</table>";
			head.innerHTML=include;
			command="<?php echo tep_href_link(FILENAME_SKYNET_ZONESETTINGS,'action=zone_list');?>&band_id="+band;
			if(command!="") do_get_command(command);
 	 	break;
 	 	case 'edit': 	 		 	 		 	 		 	 		
			if(span_edit) span_edit.style.display="";			
 	 		if(span_edit && span_details){
 	 			span_edit.innerHTML=result; 	 			
 	 			span_details.style.display='none';
 	 		}
 	 	break; 	 
 	 	case 'zone_list': 	 		
 	 		if(document.getElementById("zone_list") && result) document.getElementById("zone_list").innerHTML=result;
 	 	break;
 	 	case 'delete_success':
 	    	 var len=1;
 	    	 if(head && data_id) {
			 	var tbl_obj=head.parentNode.parentNode.parentNode.parentNode;			 				 				 	
			 	if(tbl_obj) tbl_obj.deleteRow(head.parentNode.parentNode.rowIndex);
			 	data_id.innerHTML=head.innerHTML="";
			 	data_id.style.display=head.style.display="none";			 				 			
			 }
 	    	 if(res_display){
	    	 	res_display.innerHTML="<?php echo TEXT_SKYNETZONE_DELETE_SUCCESS;?>";
 	    	 	res_display.style.display="";
 	    	 	var obj=document.getElementById("page_1");
 	    	 	if(obj)	 len=obj.options[obj.selectedIndex].value; 	    	 		
 	    	 	 command="<?php echo tep_href_link(FILENAME_SKYNET_ZONESETTINGS,'action=page_navigation');?>&page="+len;
				 do_get_command(command);	    	 	
 	    	 }
			if(document.getElementById("search")) document.getElementById("search").value=""; 								   			   
 	 	break;
 	 	case 'page_navigation':
 	 		if(document.getElementById("ajax_details")) document.getElementById("ajax_details").innerHTML=result;
 	 	break;
		case 'new':	//<img src="images/icon_info.gif" alt="Info" title=" Info " border="0">		
				var obj=document.getElementById("page_1");
				var len=1;
				if(data_id) {
					var tbl_obj=data_id.parentNode.parentNode.parentNode.parentNode;
					var tbl_obj_rows=tbl_obj.rows.length-1; 		
				}			
				if(res_display){
		    	 	res_display.innerHTML="<?php echo TEXT_SKYNETBAND_INSERT_SUCCESS;?>";
	 	    	 	res_display.style.display=""; 	    	 	
 	    	 	}	
				if(obj && obj.options.length>0 || tbl_obj_rows==max_display){
				 	if(obj) len=obj.options.length;				 						 	
				 	if(!obj && tbl_obj_rows==max_display) len=2; 				 	
				}
				command="<?php echo tep_href_link(FILENAME_SKYNET_ZONESETTINGS,'action=page_navigation');?>&page="+len;
				do_get_command(command);
				if(document.getElementById("search")) document.getElementById("search").value=""; 								   			   
		break;
 	 	}
 	 	if(res_display.style.display=="") setTimeout("res_display.style.display='none'",2000); 	 	 	 	
 	 	clearTimeout();
	  } 
	  function change_class(obj,eve){ 		 		 	 	
		 var span_details=document.getElementById("span_details"); 
		 var span_edit=document.getElementById("span_edit");
		 var span_delete=document.getElementById("span_delete");				 		 			 
		 if(obj){
		    var img_get_src=obj.childNodes[0];		    
			if(img_get_src){
			   if(img_get_src.src==img_src+'template/img_new.gif'){				   		
			   		if(eve==1 || eve==2) img_get_src.src=img_src+'template/img_new_hover.gif';					
			   }else if(eve==3 && img_get_src.src==img_src+'template/img_new_hover.gif') 
			    	img_get_src.src=img_src+'template/img_new.gif';			   
			    if(img_get_src.src==img_src+'template/img_edit.gif') {
					if(span_edit && span_edit.style.display=="" && eve==1 || eve==2){
					 	img_get_src.src=img_src+'template/img_edit_hover.gif';
					}  		   		 	 			 	 			
			    }else if(eve==3 && img_get_src.src==img_src+'template/img_edit_hover.gif' && span_edit && span_edit.style.display=="none") img_get_src.src=img_src+'template/img_edit.gif';
			    if(img_get_src.src==img_src+'template/img_trash.gif') {
					if(span_delete && span_delete.style.display=="" && eve==1 || eve==2){
					 	img_get_src.src=img_src+'template/img_trash_hover.gif';
					}  		   		 	 			 	 			
			   }else if(eve==3 && img_get_src.src==img_src+'template/img_trash_hover.gif' && span_delete && span_delete.style.display=="none") img_get_src.src=img_src+'template/img_trash.gif';
		    }
		 }		 
	  }	
	 var display_flag=1;	
	function do_hover_change(element,mode){ 
	if(display_flag==1){
		if (element.mode && mode==element.mode) return;
		if (mode==2)
			element.firstChild.src=element.firstChild.src.replace(".gif","_hover.gif");
		else
			element.firstChild.src=element.firstChild.src.replace("_hover.gif",".gif");
	}
	element.mode=mode;
	} 
	function sel_type(){
		var obj=document.getElementById("service_type");
		var command="";
		if(obj && obj.options[obj.selectedIndex].value) 
			command="<?php echo tep_href_link(FILENAME_SKYNET_ZONESETTINGS,'action=sel_service&service_type=');?>"+obj.options[obj.selectedIndex].value;
		if(command!="") do_get_command(command);
	}
</script>		
</head>
<body marginwidth="0" marginheight="0" topmargin="0" bottommargin="0" leftmargin="0" rightmargin="0" bgcolor="#FFFFFF" onLoad="SetFocus();">
<!-- header //-->
<?php require(DIR_WS_INCLUDES . 'header.php'); ?>
<!-- header_eof //-->
<!-- body //-->
<table border="0" width="100%" cellspacing="5" cellpadding="4">
	<tr>
	<td width="100%" valign="top">
	<?php echo tep_draw_form('skynet', FILENAME_SKYNET_ZONESETTINGS, '', 'post', ' onsubmit="javascript:return ValidateForm();"'); ?>
	<table border="0" width="100%" cellspacing="0" cellpadding="0">	  
      <tr>
        <td>        
         <table border="0" width="100%" cellspacing="0" cellpadding="0">
          <tr class="dataTableHeadingRow" style="height:23px">
            <td class="dataTableHeadingContent" align="right" valign="absmiddle">
            <?php
				$service_type_array = array (array ('id' => 'DP','text' => 'Domestic Priority'),array ('id' => 'DS','text' => 'Domestic Standard'));
				echo TEXT_SERVICE_TYPE . ' ' . tep_draw_pull_down_menu('service_type', $service_type_array, '', 'onchange="javascript:sel_type();"') . '&nbsp;';?></td>			
          </tr>
		  <tr><td><?php  echo tep_draw_separator('pixel_trans.gif',5,10); ?></td></tr>	
        </table></td>
      </tr>	  	 
      <tr>
        <td>        
          <table border="0" width="100%" cellspacing="0" cellpadding="0">
          <tr><td id="res_display" class="main" style="display:none"></td></tr>
          <tr>
            <td valign="top">
			<table border="0" width="100%" cellspacing="0" cellpadding="2">
			  <tr class="dataTableHeadingRow">
                	<td class="dataTableHeadingContent" width="26%"><?php echo TEXT_BAND; ?></td>
					<td class="dataTableHeadingContent" width="30%"><?php echo TEXT_BASIC_RATE;?></td>								
					<td class="dataTableHeadingContent" width="30%"><?php echo TEXT_PER_KG;?></td>
         		</tr>                           
         		<tr>
         			<td colspan="3" id="ajax_details"><?php table_write();?></td>
  				</tr>
				<tr><td colspan="3" style="display:none" class="openContent" id="new_create"></td></tr>				
		  </table>  			
  		</td>
  	   </tr>
  	  </table>	
  	  <input type="hidden" name="band_id" id="band_id">
  	  <input type="hidden" name="action_type" id="action_type">  	    	  
</td>
</tr></table></td>
</form>
<!-- body_text_eof //-->
  </tr>
</table>
<!-- body_eof //-->

<!-- footer //-->
<?php require(DIR_WS_INCLUDES . 'footer.php'); ?>
<!-- footer_eof //-->
</body>
</html>
<?php require(DIR_WS_INCLUDES . 'application_bottom.php'); ?>
