<?php
	/*
		osCommerce, Open Source E-Commerce Solutions 
		http://www.oscommerce.com 
		
		Copyright (c) 2003 osCommerce
		
		osCommRes, Services Oline 
		http://www.oscommres.com 
		Copyright (c) 2005 osCommRes 
		
		Freeway eCommerce 
		http://www.zac-ware.com/freeway 
		Copyright (c) 2007 Zac Inc 
		
		Released under the GNU General Public License
	*/
	// Set flag that this is a parent file
	define( '_FEXEC', 1 );

	require('includes/application_top.php');
	$server_date = getServerDate(true);
	require('includes/classes/split_page_results_event.php');
	require(DIR_WS_CLASSES . 'currencies.php');
	$currencies = new currencies();	
	$page=isset($HTTP_GET_VARS['page'])?$HTTP_GET_VARS['page']:1;	
	$action=isset($HTTP_GET_VARS['action'])?$HTTP_GET_VARS['action']:'';
	$fID=isset($HTTP_GET_VARS['fID'])?$HTTP_GET_VARS['fID']:$HTTP_POST_VARS['freight_id'];
	$zID=(isset($HTTP_GET_VARS['zID'])?$HTTP_GET_VARS['zID']:0);	
	$text="";
	$geo_zone_sql = "select geo_zone_name from " . TABLE_GEO_ZONES . " where geo_zone_id=" . $zID;
	$geo_zone_query = tep_db_query($geo_zone_sql);
	$geo_zone_result = tep_db_fetch_array($geo_zone_query);
	$text = $geo_zone_result['geo_zone_name'];
	$pack_array=array(array('id' => 1,'text'=>TEXT_UPTO_500G), array('id' => 2, 'text' =>TEXT_UPTO_2KG),array('id' =>3, 'text' =>TEXT_UPTO_20KG));
    $packarray=array("1"=>TEXT_UPTO_500G,"2"=>TEXT_UPTO_2KG,"3"=>TEXT_UPTO_20KG);    
	define('HEADING_TITLE','Products Freight of '.$text); 
	// echo $zID;
	if($action!=""){		
		if($action=='get_details'){
			echo_get_details();	
		}else if($action=='page_navigation'){ 
			echo 'page_navigation';
			table_write();	 	
		}else if($action=='edit'){ 
			if($fID>0){				
				$product_query = tep_db_query("select pf.countries_id,pf.price_pack,pf.price_kg,pf.pack_type,pf.freight_id from " . TABLE_PRODUCTS_FREIGHT ." pf  where  pf.freight_id = '" . $fID . "' ");
      			$product = tep_db_fetch_array($product_query);
				 $sInfo = new objectInfo($product);   
			}  
      	      	          	    
      		if($fID>0)echo 'edit';	      		
			else echo 'new';
			
	 $text="";
	 $geo_zone_sql = "select geo_zone_name from " . TABLE_GEO_ZONES . " where geo_zone_id='" . $HTTP_GET_VARS['cID'] ."' ";
	$geo_zone_query = tep_db_query($geo_zone_sql);
	$geo_zone_result = tep_db_fetch_array($geo_zone_query);
	$text = $geo_zone_result['geo_zone_name'];
		?>
		<table border="0" cellspacing="5" cellpadding="5" width="100%">
		 <?php if(!$fID>0) {?>
		  <tr>
		  	<td width="10%"></td>
			<td width="15%">&nbsp;</td>
		  	<td align="right" colspan="2" ><input type="image" src="images/template/img_savel.gif" alt="save" title="save" border="0">&nbsp;&nbsp;<a href="javascript:expand_new('close');"><img src="images/template/img_closel.gif" alt="close" title="close" border="0"></a></td>
		  </tr><?php } ?>
		  <table border="0" cellspacing="5" cellpadding="5" width="100%">
         
		<tr>
		  	<td class="main" align="right"><?php echo TEXT_PACK_TYPE;?></td>
			<td class="main"><?php echo tep_draw_pull_down_menu('pack_type',$pack_array,$sInfo->pack_type);?></td>
		  </tr>	
         <!-- <tr>
            <td class="main"><?php //echo TEXT_ZONE; ?>&nbsp;</td>
            <td class="main"><?php 
		
			//echo $text;//echo ($sInfo->country_name) ? $sInfo->countries_name : tep_draw_pull_down_menu('country_id',tep_get_country_all_zones(13), $sInfo->countries_id);  ?></td>
          </tr> -->
          <tr>
            <td class="main" align="right"><?php echo TEXT_PRICE_PER_PACK; ?>&nbsp;</td>
            <td class="main"><?php echo tep_draw_input_field('price_pack', $sInfo->price_pack) ; ?></td>
		  </tr>	
		  <tr>
		  	<td class="main" align="right"><?php echo TEXT_PRICE_PER_KG;?></td>
			<td class="main"><?php echo tep_draw_input_field('price_kg', $sInfo->price_kg) ; ?></td>
          </tr>
		  <tr><td><img src='images/pixel_trans.gif' border='0' alt='' width='5' height='15'></td></tr>
        </table>
  <?php	}else if($action=='update'){
 
  			if(!$HTTP_GET_VARS['fID']){  															
				tep_db_query("insert into " . TABLE_PRODUCTS_FREIGHT . " (countries_id, price_pack, price_kg, pack_type) values ('" . $HTTP_GET_VARS['cID'] . "', '".$HTTP_POST_VARS['price_pack']."', '".$HTTP_POST_VARS['price_kg']."', '" . $HTTP_POST_VARS['pack_type'] . "')");
				echo 'new_freight';			
				$fID=tep_db_insert_id();
  			}else if($HTTP_GET_VARS['fID'])  	{	// print_r($HTTP_POST_VARS);
				//echo "update " . TABLE_PRODUCTS_FREIGHT . " set countries_id='". (int)$HTTP_GET_VARS['cID'] ."', price_pack='".$HTTP_POST_VARS['price_pack']."',price_kg='".$HTTP_POST_VARS['price_kg']."',pack_type='".$HTTP_POST_VARS['pack_type']."' where freight_id='" . $fID . "'";	
				 tep_db_query("update " . TABLE_PRODUCTS_FREIGHT . " set countries_id='". (int)$HTTP_GET_VARS['cID'] ."', price_pack='".$HTTP_POST_VARS['price_pack']."',price_kg='".$HTTP_POST_VARS['price_kg']."',pack_type='".$HTTP_POST_VARS['pack_type']."' where freight_id='" . $fID . "'");
				 		//echo "select pf.freight_id,pf.countries_id,pf.price_pack,pf.price_kg,pf.pack_type from " . TABLE_PRODUCTS_FREIGHT . " pf  where pf.freight_id ='" . (int)$fID . "'  order by pf.pack_type";

  			}	echo_get_details();  			
  		}else if($action=='delete'){	  		
	  		$featured = 'delete';
			$featured.="<table border='0' cellspacing='2' cellpadding='1' width='100%'><tr><td width='17' align='center'>".tep_image('images/template/img_trash.gif').'</td>';
				$featured.='<td width="500" align="left" class="inner_title">'.'Delete ' . '</td></tr>';
				$featured.='<tr><td></td><td width="500" align="left" class="main">'.TEXT_INFO_DELETE_INTRO. '</td></tr>';
				$featured.='<tr><td></td><td  width="500" align="left" class="main"><b>'.$sInfo->pack_type. '</b></td></tr>';	  		
			echo $featured.='</table>';
  		}else if($action=='delete_confirm'){  					 
			tep_db_query("delete from " . TABLE_PRODUCTS_FREIGHT . " where freight_id = '" . tep_db_input($fID) . "'");
			echo 'delete_success';
  		}
		exit;
	}		
	function echo_get_details(){
   	 global $languages_id,$fID,$zID,$packarray,$HTTP_GET_VARS;
	// echo $languages_id; 
   	   $str_vals="";
	    $text="";
	 //$geo_zone_sql = "select geo_zone_name from " . TABLE_GEO_ZONES . " where geo_zone_id=" . $HTTP_GET_VARS['cID'];
	// echo $geo_zone_sql;
	//$geo_zone_query = tep_db_query($geo_zone_sql);
	//$geo_zone_result = tep_db_fetch_array($geo_zone_query);
	//$text = $geo_zone_result['geo_zone_name'];
	  $product_query = tep_db_query("select pf.freight_id,pf.countries_id,pf.price_pack,pf.price_kg,pf.pack_type from " . TABLE_PRODUCTS_FREIGHT . " pf  where pf.freight_id ='" . (int)$fID . "'  order by pf.pack_type");    
	   if(tep_db_num_rows($product_query)>0){
		  $featured = tep_db_fetch_array($product_query);
				$str_vals.=$featured['freight_id']."||".$featured['countries_id']."||".$featured['price_pack'] ."||".$featured['price_kg']."||".$featured['pack_type']."||".$packarray[$featured['pack_type']]."||".$text."||";
		echo 'get_details'.$str_vals;
	  }else $str_vals="No Record Found";
		
  }
function table_write(){
	global $page,$languages_id,$zID,$packarray,$HTTP_GET_VARS,$action;
	echo '<table border="0" width="100%" cellspacing="0" cellpadding="0">';
	if($action=='page_navigation') {$featured_query_raw = "select pf.freight_id,pf.countries_id,pf.price_pack,pf.price_kg,pf.pack_type from " . TABLE_PRODUCTS_FREIGHT . " pf  where pf.countries_id ='" . (int)$HTTP_GET_VARS['cID']. "'  order by pf.pack_type";    }
	else {
	$featured_query_raw = "select pf.freight_id,pf.countries_id,pf.price_pack,pf.price_kg,pf.pack_type from " . TABLE_PRODUCTS_FREIGHT . " pf  where pf.countries_id ='" . (int)$zID . "'  order by pf.pack_type";    
	}
	
	$featured_split = new splitPageResultsEvent($page, MAX_DISPLAY_FEATURED_PRODUCTS_LISTING, $featured_query_raw, $featured_query_numrows);
	$featured_query = tep_db_query($featured_query_raw);
	$i=0;
	if(tep_db_num_rows($featured_query)>0) {
	while ($featured = tep_db_fetch_array($featured_query)) {
		$class="dataTableRowEven";
		if($i%2==0) $class="dataTableRowOdd";
		$i++;	      
		echo '<tr height="20" class="'.$class.'" onmouseover="rowOverEffect(this)" onmouseout="rowOutEffect(this)" onclick="javascript:if(document.getElementById(\'head_'.$featured['freight_id'].'\').style.display==\'none\') expand_category(' . $featured['freight_id'] . ',3);">' . "\n";    
?>
	 
			 <td valign="top" width="100%">
			 <div id="data_<?php echo $featured['freight_id'];?>">
			  <table border="0" cellspacing="0" cellpadding="3" width="100%">
			  
			   <tr>
				<td  class="dataTableContent" align="left" width="40%"><?php echo $packarray[$featured['pack_type']]; ?></td>
				<td  class="dataTableContent" align="right" width="15%"><?php echo $featured['price_pack'];?></td>
				<td  class="dataTableContent" align="left" width="15%"></td>
				<td  class="dataTableContent" align="right" width="15%"><?php echo $featured['price_kg'];?></td>	
				<td  class="dataTableContent" align="left" width="15%"></td>
			    </tr>
			    </table>
			    </div>
			   <div style="display:none" class="openContent" id="head_<?php echo $featured['freight_id'];?>"></div> 
			   </td>
       		   </tr>   
<?php 		
	}
	}else { echo '<tr><td class="smallText" align="center"> No Freight found </td></tr>'; }
	 ?>
	
	<tr>
       <td class="smallText" valign="top"><?php echo $featured_split->display_count($featured_query_numrows, MAX_DISPLAY_FEATURED_PRODUCTS_LISTING, $page, TEXT_DISPLAY_NUMBER_OF_FREIGHT); ?></td>
       <td class="smallText" align="right"><?php echo $featured_split->display_script_links($featured_query_numrows, MAX_DISPLAY_FEATURED_PRODUCTS_LISTING, MAX_DISPLAY_PAGE_LINKS, $page,1,'expand_category(\'\'','1'); ?></td>        
    </tr>
    </table>
<?php } ?>
<!doctype html public "-//W3C//DTD HTML 4.01 Transitional//EN">
<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/date-picker.js"></script>
<script language="javascript" src="includes/general.js"></script>
<script type="text/javascript" src="includes/http.js"></script>
<?php require('includes/date_format_js.php');?>
<script languages="javascript">
var max_display="<?php echo MAX_DISPLAY_FEATURED_PRODUCTS_LISTING;?>";
var img_src="<?php echo HTTP_SERVER.DIR_WS_ADMIN.'images/';?>";
var server_date="<?php echo getServerDate();?>";
var cid='<?php echo $HTTP_GET_VARS['zID'];?>';
var prev_id='';

 function ValidateForm(frm){ 
 //for(i=0;i<document.frm_freight.length;i++)
 	//alert(document.frm_freight[i].name + document.frm_freight[i].value);
	var frm=document.frm_freight;
	var command="";
	if(frm && frm.freight_id) id=frm.freight_id.value;					 
	if(document.getElementById("span_details")) var span_details=document.getElementById("span_details");
	if(document.getElementById("span_edit")) var span_edit=document.getElementById("span_edit");				
	if(document.getElementById("span_delete")) var span_delete=document.getElementById("span_delete");		
	if(document.getElementById("loading")) var loadings=document.getElementById("loading");
	if(document.getElementById("prd_new")) var prd_new = document.getElementById("prd_new");
	//alert (prd_new);
	var error_result="";
	if(frm.action_type) var action_type=frm.action_type.value;
	if(span_details && span_details.style.display!="" && span_edit.style.display==''){	
	  	    if	(frm.price_pack && frm.price_pack.value=="")
				error_result="<?php echo ERR_PRICE_PACK;?>\n";  
			else if	(frm.price_kg && frm.price_kg.value=="")
				error_result="<?php echo ERR_PRICE_KG;?>\n";		    	
			if(error_result!=""){
				alert(error_result);
				return false;
			}else if(span_edit.style.display==''){
				span_details.innerHTML=span_delete.innerHTML="";
		  		var ids="";
		  		if(action_type=='edit') ids="&fID="+id+"&cID="+cid;
				command="<?php echo tep_href_link(FILENAME_PRODUCTS_FREIGHT,'action=update');?>"+ids;
				if(loadings) loadings.style.display="";
				if(span_edit) span_edit.style.display="none";
			}
	}else if(document.getElementById("span_delete")){ 
		if(span_delete.style.display==""){
			span_details.innerHTML=span_edit.innerHTML="";
			command="<?php echo tep_href_link(FILENAME_PRODUCTS_FREIGHT,'action=delete_confirm');?>&fID="+id+"&cID="+cid;
			if(loadings) loadings.style.display="";
			if(span_delete) span_delete.style.display="none";
		}
	}else if(prd_new.style.display==""){ 
	
	//alert (prd_new);
	//alert ('hi');
	  	   if(frm.price_pack && frm.price_pack.value=="")
				error_result="<?php echo ERR_PRICE_PACK;?>\n";  
			else if	(frm.price_kg && frm.price_kg.value=="")
				error_result="<?php echo ERR_PRICE_KG;?>\n";	  	    	
			if(error_result!=""){
				alert(error_result);
				return false;
		}else {
		command="<?php echo tep_href_link(FILENAME_PRODUCTS_FREIGHT,'action=update');?>&cID="+cid;
		}
		
	}
	do_post_command('frm_freight',command);	
    return false;
} 
function expand_new(perform){
/*	if(document.getElementById("freight_id")) 
	f_id=document.getElementById("freight_id").value;
	if(f_id && document.getElementById("head_"+f_id)){
		document.getElementById("head_"+f_id).style.display="none";
		document.getElementById("data_"+f_id).style.display="";		
	}*/
	if(prev_id!=''){
		if(document.getElementById("head_"+prev_id)){
			document.getElementById("head_"+prev_id).style.display="none";
			document.getElementById("head_"+prev_id).innerHTML="";
			document.getElementById("data_"+prev_id).style.display="";		
		}
	}
		
	switch(perform){	
	case 'add_new':
		display_flag=0;


		document.getElementById("prd_new").style.display='';
		document.getElementById('prd_new').innerHTML="<img src='images/24-1.gif' alt='Loading...' title='Loading...'>";
		command="<?php echo tep_href_link(FILENAME_PRODUCTS_FREIGHT,'action=edit');?>";
		//alert (command);
		do_get_command(command);
		
	break;
	case 'close':
		change_new_image();	
		document.getElementById("prd_new").style.display='none';
	break;
	}
}
function change_new_image(){
document.getElementById('header_new_operation').firstChild.src=document.getElementById('header_new_operation').firstChild.src.replace('_hover.gif','.gif');
display_flag=1;
}
function expand_category(id,category,r_type,sta){ 
		prev_id=id;
		if(!sta) sta="";
		var obj=document.getElementById("page_1");
		if(category=='1' && obj && sta!=""){
 	 		id=parseInt(obj.options[obj.selectedIndex].value);
 	 		if(sta=='next') {
 	 			if(obj.length==obj.selectedIndex+1) return;
 	 			id+=1;
 	 		}else if(sta=='prev') {
 	 			if(obj.selectedIndex==0) return;
 	 			id-=1;
 	 		}
 	 		if(id<=1) id=1;
 	 	}else if(category=='1' && sta=="") id=""; 	 	
 	 	if(document.getElementById("prd_new") && document.getElementById("prd_new").style.display=="") { //alert('1111');
 	 		document.getElementById("prd_new").innerHTML="";
 	 		document.getElementById("prd_new").style.display="none";	
 	 	}
 	 	var res_display=document.getElementById("res_display"); 	 	 	 	 	 	 	 	 	 		 	  	 	
 	 	if(res_display) res_display.style.display="none"; 	 		 	 	
 	 	 if(category!=1 && document.frm_freight && document.frm_freight.freight_id && document.frm_freight.freight_id.value>0)  {
			var old_ids=document.frm_freight.freight_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(document.frm_freight.freight_id && id>0 && document.frm_freight.freight_id.value>0 && document.frm_freight.freight_id.value!=id){			   			   
			   if(pre_head && pre_head.style.display=="") pre_head.style.display="none";
			   if(pre_data_id && pre_data_id.style.display=="none") pre_data_id.style.display="";			   			   			  
			   document.frm_freight.freight_id.value=id;			   
			}
			
				
		if(id>0 && category!=1 && document.frm_freight && document.frm_freight.freight_id) document.frm_freight.freight_id.value=id;									 								 	 	 	 
 	 	if(category){
 	 		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);	
			//alert (data_id);					
			var head=document.getElementById("head_"+id);
			var img_save=document.getElementById("img_save");			
			var command="";																		 
 	 		switch(category){ 	 			
 	 			case 1: 	 
 	 			       var page=""; 	 			       
 	 			       if(id!="") page="&page="+id; 
 	 			       command="<?php echo tep_href_link(FILENAME_PRODUCTS_FREIGHT,'action=page_navigation');?>"+page+"&cID="+cid;;
 	 			   	   if(document.getElementById("ajax_details")) document.getElementById("ajax_details").innerHTML="<img src='images/24-1.gif' alt='Loading...' title='Loading...'>"; 	 			   	    	 			   					   
 	 			break;
 	 			case 2:

 	 					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.frm_freight.action_type) document.frm_freight.action_type.value='new';
 	 					command="<?php echo tep_href_link(FILENAME_PRODUCTS_FREIGHT,'action=edit');?>";
 	 			break; 	 			 	 			
 	 			case 3:
 	 			   if(document.getElementById("prd_new")){ 
 	 			    document.getElementById("prd_new").style.display="none"; 	 			   
				   	document.getElementById('header_new_operation').firstChild.src=document.getElementById('header_new_operation').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_PRODUCTS_FREIGHT,'action=get_details');?>&fID="+id+"&cID="+cid; 	 			 	 	 			 	
 	 			 }
				change_new_image();
 	 			break; 	 			 	 			
 	 			case 4:	 	 		
						
 	 					span_edit.style.display="";
 	 					span_delete.style.display=span_details.style.display="none";
 	 					span_edit.innerHTML="<img src='images/24-1.gif' alt='Loading...' title='Loading...'>";
 	 					if(document.frm_freight.action_type) document.frm_freight.action_type.value='edit';
 	 					command="<?php echo tep_href_link(FILENAME_PRODUCTS_FREIGHT,'action=edit');?>&fID="+id+"&cID="+cid;
 	 			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_INFO_HEADING_DELETE_FEATURED;?></td></tr>'+
											  '<tr><td></td><td width="500" align="left" class="main"><?php echo TEXT_INFO_DELETE_INTRO;?></td></tr>'+
											  '<tr><td colspan="2"><?php echo tep_draw_separator('pixel_trans.gif',50,10);?></td></tr></table>';
 	 					if(img_save) img_save.style.display="";
 	 			break;
 	 		}
			
			//alert (command);
 	 		if(command!="") do_get_command(command);
			
			
 	 	}		
 	 }  	
   function do_result(result){
  //alert (result);
  
			    
 document.getElementById("prd_new").style.display='none';
   	  if(result!=""){
   	    if(result.substr(0,11)=='get_details') print_details('get_details',result.substr(11));
   	    else if(result.substr(0,4)=='edit') print_details('edit',result.substr(4));  	
   	    else if(result.substr(0,14)=='delete_success') print_details('delete_success',result.substr(14)); 		 				 						
   	    else if(result.substr(0,6)=='delete') print_details('delete',result.substr(6));
		else if(result.substr(0,15)=='page_navigation') print_details('page_navigation',result.substr(15));
		else if(result.substr(0,11)=='new_freight') print_details('new_freight',result.substr(11));	
		else if(result.substr(0,3)=='new') print_details('new',result.substr(3));							 	 			 	 			 	 				 	 											   	
   	  }
   }
      
   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  freight_id="";
			var  product_name="";
			var  price_pack="";						
			var  price_kg="";
			var  pack_type="";
			var  type="";
			var  name="";
		
 	 		freight_id=splt_str[0];
			product_name=splt_str[1];
			price_pack=splt_str[2];						
			price_kg=splt_str[3];
			pack_type=splt_str[4];
			type=splt_str[5];
			name=splt_str[6];
			
 	 	}	  	 		 	 	 	 	  	 		 	  	 
 		if(document.frm_freight && document.frm_freight.freight_id) var id=document.frm_freight.freight_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="";		
		 //data_id.style.display="none";
 	 	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="3" cellspacing="0" width="100%">'+
						         '<tbody><tr>'+
						         	'<td class="dataTableContent" width="40%" align="left">'+type+'</td>'+
									'<td class="dataTableContent" width="15%" align="right">'+price_pack+'</td>'+
									'<td class="dataTableContent" width="15%" align="left"></td>'+
									'<td class="dataTableContent" width="15%" align="right">'+price_kg+'</td>'+
									'<td class="dataTableContent" width="15%" align="left"></td>'+
							    '</tr>'+
						      '</tbody></table>';	
	 	 		}	
	 	 			 	 		
	 	 		include="<table width='100%' border='0' cellspacing='0' cellpadding='0' class='openContent_top'>"+
				"<tr heigth='40' >"+
				  "<td align='left' valign='middle' width='350' class='inner_title'>&nbsp;&nbsp;"+type+ name +"</td>"+
				  "<td width='470' 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 width='10%' onclick='javascript:change_class(this,1);expand_category("+freight_id+",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 width='10%' onclick='javascript:change_class(this,1);expand_category("+freight_id+",5);' onmouseover='javascript:change_class(this,2);' onmouseout='javascript:change_class(this,3);'><img alt='delet' title='delete' src='images/template/img_trash.gif'></td>"+				  	    				  	    
				  	    	"<td class='cell_bg_popm_right' width='10'>&nbsp;</td>"+
						"</tr>"+
					 "</table>"+
				  "</td>"+
				 "<td width='240' align='right' id='img_save' style='display:none'><input type='image' src='images/template/img_savel.gif' alt='save' title='save' border='0'>&nbsp;&nbsp;<a href='javascript:expand_category("+freight_id+",3);'><img src='images/template/img_closel.gif' alt='close' title='close' border='0'></a>&nbsp;&nbsp;</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='5' 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='600' valign='top'>"+				  							  			
				  				"<table width='50%' border='0' cellspacing='0' cellpadding='3' class='main'>";
				  					if(pack_type!=""){
				  						include+="<tr>"+
					  						"<td align='right' width='20%' valign='top'><b><?php echo 'Pack Type:';?></b></td>"+
					  						"<td align='left' width='30%' valign='top'>"+type+"</td>"+
				  						"</tr>";
				  					}	
				  					if(price_pack!=""){		  					
					  					include+="<tr>"+
					  						"<td align='right' width='20%'><b><?php echo 'Price/pack:';?></b></td>"+
					  						"<td align='left' width='30%'>"+price_pack+"</td>"+
					  					"</tr>";						
				  					}							  					
				  					if(price_kg!=""){		  					
					  					include+="<tr>"+
					  						"<td align='right' width='20%'><b><?php echo 'Price/Kg:';?></b></td>"+
					  						"<td align='left' width='30%'>"+price_kg+ "</td>"+
					  					"</tr>";						
				  					}
				  							  									  			  						  							
					include+="<tr><td>&nbsp;</td></tr></span>"+
				  "</td>"+
				"</tr>"+
			"</table>";
			head.innerHTML=include;
 	 		} 	 			 	 		
 	 	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 'page_navigation':
 	 		if(document.getElementById("ajax_details"))
 	 		 document.getElementById("ajax_details").innerHTML=result;
 	 	break;
 	 	case 'delete':
 	 		if(span_delete) span_delete.style.display="";			
 	 		if(span_delete && span_details){ 	 			 	 			
 	 			span_delete.innerHTML=result; 	 			
 	 			span_details.style.display='none';
 	 		}
 	 	break; 	 	
 	 	case 'delete_success':			  	    	  	    	
			 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 'Deleted Successfully';?>";
 	    	 	res_display.style.display="";
 	    	 	var obj=document.getElementById("page_1");
 	    	 	var len=1;
 	    	 	if(obj) len=parseInt(obj.options[obj.selectedIndex].value); 	    	 							 	    	 	 	
 	    	 	command="<?php echo tep_href_link(FILENAME_PRODUCTS_FREIGHT,'action=page_navigation');?>&page="+len+"&cID="+cid;    	 	 	    	 	
 	    	 }			 
 	    	 if(command!="") do_get_command(command);
 	 	break;
		case 'new':
				document.getElementById('prd_new').style.display='';
				document.getElementById('prd_new').innerHTML=result;
				
		break;
 	 	
				case 'new_freight': //alert(result);
				var len=1;
				//document.getElementById('prd_new').style.display='none';
				if(result!=""){
					result_splt=result.split('||');
					if(result_splt[0]>0){						
						var id=result_splt[0];
						var tax_class_title=result_splt[1];	
						var tax_class_description=result_splt[2];						
						if(head) {    						
    						var tbl_obj=head.parentNode.parentNode.parentNode.parentNode;    						
    						var row_obj=tbl_obj.insertRow(tbl_obj.rows.length);
    						var row_cell=row_obj.insertCell(0);
    						row_cell.innerHTML='<div id="data_'+id+'">'+
						       '<table border="0" cellpadding="0" cellspacing="0" width="100%">'+
						         '<tbody><tr>'+
						         	'<td class="dataTableContent" width="150" align="left">'+type+'</td>'+
						          '</tr>'+
						      '</tbody></table>'+
						      '</div>'+
						      '<div style="display:none;" class="openContent" id="head_'+id+'"></div>';						    						      
    						var rows_cnt=tbl_obj.rows.length-1;
    						var tbl=tbl_obj.rows[rows_cnt];
    						tbl.onclick=function () {((document.getElementById("head_"+id) && document.getElementById("head_"+id).style.display=='none')?expand_category(id,3):'')};
    						tbl.style.height="25px"; 
    						if(rows_cnt%2==0) tbl.className="dataTableRowOdd";
    						else tbl.className="dataTableRowEven";
    						tbl.onmouseover=function (){rowOverEffect(this)};
    						tbl.onmouseout=function (){rowOutEffect(this)};
    						if(head && data_id){
    							head.style.display="none";
    							data_id.style.display="";
    						}
    						if(res_display){
					    	 res_display.innerHTML="<?php echo 'insert success';?>";
				 	    	 res_display.style.display=""; 	    	 	
 	    	 				}
						}    					
					}
					document.getElementById('header_new_operation').firstChild.src=document.getElementById('header_new_operation').firstChild.src.replace('_hover.gif','.gif');
					display_flag=1;
					command="<?php echo tep_href_link(FILENAME_PRODUCTS_FREIGHT,'action=page_navigation');?>&page="+len+"&cID="+cid;
					do_get_command(command);
				}		
		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_copy.gif') {
					if(span_edit && span_edit.style.display=="" && eve==1 || eve==2){
					 	img_get_src.src=img_src+'template/img_copy_hover.gif';
					}  		   		 	 			 	 			
			    }else if(eve==3 && img_get_src.src==img_src+'template/img_copy_hover.gif' && span_edit && span_edit.style.display=="none") img_get_src.src=img_src+'template/img_copy.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;
	} 
</script>

</head>
<body marginwidth="0" marginheight="0" topmargin="0" bottommargin="0" leftmargin="0" rightmargin="0" bgcolor="#FFFFFF" onLoad="SetFocus();">
<div id="popupcalendar" class="text"></div>
<!-- header //-->
<?php require(DIR_WS_INCLUDES . 'header.php'); ?>
<!-- header_eof //-->

<!-- body //-->
<table border="0" width="100%" cellspacing="2" cellpadding="2">
  <tr>

    <td width="100%" valign="top">
	<table border="0" width="100%" cellspacing="0" cellpadding="2">            
          	<tr><td id="res_display" class="main" style="display:none"></td></tr>
          	<tr>
            	<td valign="top" colspan="5">
            	<?php echo tep_draw_form('frm_freight',FILENAME_PRODUCTS_FREIGHT,'','post','onsubmit="javascript:return ValidateForm(this);"'); ?>
	            	<table border="0" width="100%" cellspacing="0" cellpadding="2">
	              		<tr class="dataTableHeadingRow" style="height:26px">	              		
						<td valign="bottom"><?php echo '<a id="header_new_operation" href="javascript: expand_new(\'add_new\');" onMouseOut="javascript:do_hover_change(this,1);" onMouseOver="javascript:do_hover_change(this,2);">'.tep_image(DIR_WS_IMAGES.'template/img_new.gif','New','22','22').'</a>'; ?></td>
					   </tr>					   
					   	<tr>
	                	<td class="pageHeading"><?php echo 'Products Freight for ' . '' . $text; ?></td>
	              		</tr>
					   <tr><td><?php echo tep_draw_separator('pixel_trans.gif','1','10');?></td></tr>				
                	 <tr class="dataTableHeadingRow" height="20" valign="top">
					 <td valign="top" class="main" width="100%">
					 <table border="0" cellpadding="0" cellspacing="0" width="100%">
					 <tr>
				  	 <td class="main" align="left" width="40%"><b>weight</b></td>
				  	 <td class="main" align="right" width="15%"><b>Price/pack</b></td>
				  	 <td class="main" align="left" width="15%"></td>
				  	 <td class="main" align="right" width="15%"><b>Price/Kg</b></td>
				  	 <td class="main" align="left" width="15%"></td>
					 </tr>
					 </table>
					 </td>
					 </tr>
				        <tr><td ><?php  echo tep_draw_separator('pixel_trans.gif',5,10); ?></td></tr>						
	              		<tr>
	              			<td id="ajax_details"> <?php  table_write(); ?></td>    		
	          	 		</tr>	              
						<tr>
							<td id="prd_new" class="openContent" style="display:none" ></td>
						</tr>
	            	</table>
	            	<input type="hidden" name="freight_id" id="freight_id">  
	            	<input type="hidden" name="action_type" id="action_type">
          		</form>
           </td>
          </tr>
        </table></td>
      </tr>
    </table></td>
<!-- 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'); ?> 
