<?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 ZacWare

Released under the GNU General Public License
*/
// Set flag that this is a parent file
	define( '_FEXEC', 1 );

  require('includes/application_top.php');
  require('includes/classes/split_page_results_event.php');
  require(DIR_WS_CLASSES . 'currencies.php');

  tep_get_last_access_file();// get input entries to find type of entry
  $currencies = new currencies();
  $server_date = getServerDate(true);	
  $action = (isset($HTTP_GET_VARS['action']) ? $HTTP_GET_VARS['action'] : '');
  $page = (isset($HTTP_GET_VARS['page']) ? (int)$HTTP_GET_VARS['page'] :1);
  $currency_id=(isset($HTTP_GET_VARS['cID'])?(int)$HTTP_GET_VARS['cID']:''); 

  if($action!=""){
   	  if($action=='get_details'){
   	  	  echo_get_details();
     }else if($action=='page_navigation'){ 
	     echo $action;
		 table_write(); 
    }else if($action=='delete_currency'){
		 $location_string = 'delete';
		 $location_string .="<table border='0' cellspacing='2' cellpadding='2' width='100%'><tr><td width='17' align='center'>".tep_image('images/template/img_trash.gif').'</td>';
		 $location_string .='<td width="500" align="left" class="inner_title">'.TEXT_INFO_HEADING_DELETE_CURRENCY. '</td></tr>';
		 $location_string .='<tr><td></td><td width="500" align="left" class="main">'.TEXT_INFO_DELETE_INTRO. '<br></td></tr>';
		 $location_string .='<tr><td colspan="2">'.tep_draw_separator("pixel_trans.gif",50,10).'</td></tr></table>';
		 echo $location_string;
    }else if($action=='delete_confirm'){   	    
	    $currency_query = tep_db_query("select currencies_id from " . TABLE_CURRENCIES . " where code = '" . tep_db_input(DEFAULT_CURRENCY) . "'");
        $currency = tep_db_fetch_array($currency_query);
		if ($currency['currencies_id'] == $curreny_id) {
           tep_db_query("update " . TABLE_CONFIGURATION . " set configuration_value = '' where configuration_key = 'DEFAULT_CURRENCY'");
        }
		tep_db_query("delete from " . TABLE_CURRENCIES . " where currencies_id = '" . (int)$currency_id . "'");
	    echo 'success_delete';	     
	  }else if($action=='edit_currency'){ 
		    $cnt=0;
		    $currency_info=array('code'=>'',
		                          'title'=>'',
		                          'symbol_left'=>'',
								  'symbol_right'=>'',
								  'decimal_point'=>'',
								  'thousands_point'=>'',
								  'decimal_places'=>'',
								  'value'=>''
					 				);	
			if($currency_id){
		        $currency_info_query=tep_db_query("SELECT * from " . TABLE_CURRENCIES . " where currencies_id='" . (int)$currency_id . "'");
			 	$currency_info=tep_db_fetch_array($currency_info_query);	
				$cnt=tep_db_num_rows($currency_info_query);
			} 
		    $cInfo=new objectInfo($currency_info);	
		    echo 'edit';

		?>        				   		
			<table border="0" cellspacing="2" cellpadding="4" width="100%">
			   <tr><td><?php echo tep_draw_separator('pixel_trans.gif', '100%', '10'); ?></td></tr>
			    <tr>
				 <td width="50%">
				  <table border="0" cellspacing="2" cellpadding="4" width="100%">							     
					<tr valign="top">
						<td class="main" width="50"><?php echo TEXT_INFO_CURRENCY_TITLE;?></td>
						<td class="main"><?php echo tep_draw_input_field('currency_name',$cInfo->title,'size=40 maxlength=50');?></td>
					</tr>
					<tr valign="top">
						<td class="main" width="50"><?php echo TEXT_INFO_CURRENCY_CODE;?></td>
						<td class="main"><?php echo tep_draw_input_field('currency_code',$cInfo->code,'size=40 maxlength=50');?></td>
					</tr>
					<tr valign="top">
						<td class="main" width="50" nowrap="nowrap"><?php echo TEXT_INFO_CURRENCY_SYMBOL_LEFT; ?></td>
						<td class="main"><?php echo tep_draw_input_field('symbol_left',$cInfo->symbol_left,'size=40 maxlength=50');?></td>
					</tr>	
					<tr valign="top">
						<td class="main" width="100"><?php echo TEXT_INFO_CURRENCY_SYMBOL_RIGHT; ?></td>
						<td class="main"><?php echo tep_draw_input_field('symbol_right',$cInfo->symbol_right,'size=40 maxlength=50');?></td>
					</tr>	
				</table>
			</td>
			<td width="50%">
				  <table border="0" cellspacing="2" cellpadding="4" width="100%">
				 	<tr valign="top">
						<td class="main"><?php echo TEXT_INFO_CURRENCY_DECIMAL_POINT; ?></td>
						<td class="main"><?php	echo tep_draw_input_field('decimal_point',$cInfo->decimal_point,'size=40 maxlength=50'); ?></td>
					</tr>				 	 
					<tr valign="top">
						<td class="main"><?php echo TEXT_INFO_CURRENCY_THOUSANDS_POINT; ?></td>
						<td class="main"><?php echo tep_draw_input_field('thousands_point',$cInfo->thousands_point,'size=40 maxlength=50') . '&nbsp;'; ?></td>						
					</tr>
					<tr valign="top">
						<td class="main"><?php echo TEXT_INFO_CURRENCY_DECIMAL_PLACES; ?></td>
						<td class="main"><?php echo tep_draw_input_field('decimal_places',$cInfo->decimal_places,'size=40 maxlength=50'); ?></td>
					</tr>
					<tr valign="top">
						<td class="main"><?php echo TEXT_INFO_CURRENCY_VALUE; ?></td>
						<td class="main"><?php echo tep_draw_input_field('value',$cInfo->value,'size=40 maxlength=50'); ?></td>
					</tr>							 
				</table>
			</td>
		</tr>
		<?php if (DEFAULT_CURRENCY != $cInfo->code){
		?>
		<tr valign="top" class="main">
			<?php echo tep_draw_checkbox_field('default'). ' ' . TEXT_INFO_SET_AS_DEFAULT; ?>
		</tr>
		<?php } ?>							 
		<tr><td><?php echo tep_draw_separator('pixel_trans.gif', '100%', '10'); ?></td></tr>		
	 </table>      
<?php   }else if($action=='update_currency'){
			$currency_name=(isset($HTTP_POST_VARS['currency_name'])?$HTTP_POST_VARS['currency_name']:'');
			$currency_code=(isset($HTTP_POST_VARS['currency_code'])?$HTTP_POST_VARS['currency_code']:'');
			$symbol_left=(isset($HTTP_POST_VARS['symbol_left'])?$HTTP_POST_VARS['symbol_left']:'');
			$symbol_right=(isset($HTTP_POST_VARS['symbol_right'])?$HTTP_POST_VARS['symbol_right']:'');
			$decimal_point=(isset($HTTP_POST_VARS['decimal_point'])?$HTTP_POST_VARS['decimal_point']:'');
			$thousands_point=(isset($HTTP_POST_VARS['thousands_point'])?$HTTP_POST_VARS['thousands_point']:''); 
			$decimal_places	=(isset($HTTP_POST_VARS['decimal_places'])?$HTTP_POST_VARS['decimal_places']:'');
			$value=(isset($HTTP_POST_VARS['value'])?$HTTP_POST_VARS['value']:'');
			$last_update=$server_date;

			$sql_data_array = array('code'=>$currency_code,
		                          'title'=>$currency_name,
		                          'symbol_left'=>$symbol_left,
								  'symbol_right'=>$symbol_right,
								  'decimal_point'=>$decimal_point,
								  'thousands_point'=>$thousands_point,
								  'decimal_places'=>$decimal_places,
								  'value'=>$value,
								  'last_updated'=>$last_update
					 			);
		  $sql_history_array =array('update_time'=> $server_date,
									'update_status'=>'U');		     

		if ($currency_id>0 && $HTTP_POST_VARS['action_type']=='edit') {
           tep_db_perform(TABLE_CURRENCIES, $sql_data_array, 'update', "currencies_id = '" .(int)$currency_id . "'");
		   $update_status_query=tep_db_query("select * from " . TABLE_CURRENCY_UPDATE_HISTORY . "  order by update_time desc limit 1 ");
		   $update_status_result=tep_db_fetch_array($update_status_query);
		   $update_time=$update_status_result['update_time'];
		   tep_db_perform(TABLE_CURRENCY_UPDATE_HISTORY,$sql_history_array, 'update', "update_time = '" . $update_time . "' ");
		}else  if($HTTP_POST_VARS['action_type']=='new'){
			tep_db_perform(TABLE_CURRENCIES, $sql_data_array);
		    tep_db_perform(TABLE_CURRENCY_UPDATE_HISTORY,$sql_history_array);
			$currency_id = tep_db_insert_id();
			echo 'new_currency';				
		}
		
	   if(isset($HTTP_POST_VARS['default']) && ($HTTP_POST_VARS['default'] == 'on')) {
	   		$find_prev_id_query = tep_db_query("select currencies_id from " . TABLE_CURRENCIES . " where code='" . tep_db_input(DEFAULT_CURRENCY) ."'");
			if(tep_db_num_rows($find_prev_id_query)>0){
				$find_result = tep_db_fetch_array($find_prev_id_query);
				$prev_id = $find_result['currencies_id'];
	   		}
          tep_db_query("update " . TABLE_CONFIGURATION . " set configuration_value = '" . tep_db_input($currency_code) . "' where configuration_key = 'DEFAULT_CURRENCY'");
        	 echo 'page_navigation';
			table_write();
		 }else
		echo_get_details();	  		
   	 }else if($action=='update'){
        $server_used = CURRENCY_SERVER_PRIMARY;

        $currency_query = tep_db_query("select currencies_id, code, title from " . TABLE_CURRENCIES);
        while ($currency = tep_db_fetch_array($currency_query)) {
          $quote_function = 'quote_' . CURRENCY_SERVER_PRIMARY . '_currency';
          $rate = $quote_function($currency['code']);
          if (empty($rate) && (tep_not_null(CURRENCY_SERVER_BACKUP))) {
            $messageStack->add_session(sprintf(WARNING_PRIMARY_SERVER_FAILED, CURRENCY_SERVER_PRIMARY, $currency['title'], $currency['code']), 'warning');

            $quote_function = 'quote_' . CURRENCY_SERVER_BACKUP . '_currency';
            $rate = $quote_function($currency['code']);

            $server_used = CURRENCY_SERVER_BACKUP;
          }

          if (tep_not_null($rate)) {
            tep_db_query("update " . TABLE_CURRENCIES . " set value = '" . $rate . "', last_updated ='" . $server_date . "' where currencies_id = '" . (int)$currency['currencies_id'] . "'");

            $messageStack->add_session(sprintf(TEXT_INFO_CURRENCY_UPDATED, $currency['title'], $currency['code'], $server_used), 'success');
          } else {
            $messageStack->add_session(sprintf(ERROR_CURRENCY_INVALID, $currency['title'], $currency['code'], $server_used), 'error');
          }
        }
	  echo 'update'; 
	 }
  exit;
  }	
  function echo_get_details(){
  	 global $currency_id, $currencies,$prev_id;
	 	$currency_sql = "select currencies_id, title, code, symbol_left, symbol_right, decimal_point, thousands_point, decimal_places, last_updated, value from " . TABLE_CURRENCIES . " where currencies_id='".(int)$currency_id."'  order by currencies_id desc ";
  		 $currency_query = tep_db_query($currency_sql);
		 if(tep_db_num_rows($currency_query)>0){
			$currency=tep_db_fetch_array($currency_query);
			$last_update = format_date($currency['last_updated']);			 																							 	
			if(DEFAULT_CURRENCY==$currency['code']){
				$title = '<b>'.$currency['title'] .'('.TEXT_DEFAULT.')</b>';	
				}		
			else
				$title = $currency['title'];
				$str_vals.= $currency['currencies_id']."||".$title."||".$currency['code']."||".$currency['symbol_left']."||".$currency['symbol_right']."||".$currency['decimal_point']."||".$currency['thousands_point']."||".$currency['decimal_places']."||".$last_update."||".$currency['value']."||";	
		}if(DEFAULT_CURRENCY)
		  	$str_vals.=$currencies->format('30', false, DEFAULT_CURRENCY) . ' = ' . $currencies->format('30', true, $currency['code']);
        else $str_vals="No Record Found";	
		echo 'get_details'.$str_vals.'||'.$prev_id;
   }

 function table_write(){
  global $page;
  ?>	       	   		
  <table border="0" cellpadding="0" cellspacing="0" width="100%">
	 <?php
 		$currency_query_raw = "select currencies_id, title, code, symbol_left, symbol_right, decimal_point, thousands_point, decimal_places, last_updated, value from " . TABLE_CURRENCIES . " order by currencies_id desc";
  		$currency_split = new splitPageResultsEvent($page, MAX_DISPLAY_SEARCH_RESULTS, $currency_query_raw, $currency_query_numrows);
		$currency_query = tep_db_query($currency_query_raw);
	
	   if(tep_db_num_rows($currency_query)>0){ 
		while ($currency = tep_db_fetch_array($currency_query)) {					 
			 $class="dataTableRowEven";
			 if($rows%2==0) $class="dataTableRowOdd"; 					
			 $rows++;
			 echo '  <tr style="height:25" class="'.$class.'" onmouseover="rowOverEffect(this)" onmouseout="rowOutEffect(this)" onclick="javascript:if(document.getElementById(\'head_'.$currency['currencies_id'].'\').style.display==\'none\') expand_category(' . $currency['currencies_id'] . ',3);">' . "\n"; 
		   ?>  			      
			  <td colspan="4" width="100%">
				<div id="data_<?php echo $currency['currencies_id'];?>">
				 <table border="0" cellspacing="0" cellpadding="0" width="100%">
					<tr>
				<?php	//echo 'DEfault:'.DEFAULT_CURRENCY;
						$config_query = tep_db_query("select configuration_value from " . TABLE_CONFIGURATION ." where configuration_key='DEFAULT_CURRENCY'");
						if(tep_db_num_rows($config_query)){
							$config_result = tep_db_fetch_array($config_query);
							$configuration_value = $config_result['configuration_value'];
						}
						if ($configuration_value == $currency['code']) { 
						  echo '                <td class="dataTableContent" width="30%" id="lname.$currency["'.currencies_id.'"]"><b>' . $currency['title'] . ' (' . TEXT_DEFAULT . ')</b></td>' . "\n";
						} else {
						  echo '                <td class="dataTableContent" width="30%">' . $currency['title'] . '</td>' . "\n";
				       } ?>
						<td class='dataTableContent' width="30%" align="left"><?php echo $currency['code']; ?></td>
               	        <td class="dataTableContent" align="left" width="40%"><?php echo number_format($currency['value'],8); ?></td>
					</tr>
				 </table>
			    </div>
				<div class="openContent" id="head_<?php echo $currency['currencies_id'];?>" style="display:none"></div>
			 </td>					      
			</tr>
      	<?php 
			  ?>
		<?php } //end of while
	    	} else{
       		  echo '<tr><td id="empty_currency" class="smallText">'.TEXT_EMPTY_CURRENCY.'</td></tr>'; ?>
	   <?php } ?>
	   
	   		  <tr id="new_currency" style="display:none" class="openContent">
			<td colspan="5" class="openContent_top">	
				<table cellpadding="1" cellspacing="0" border="0" width="100%">
					<tr>
						<td class="inner_title"><?php echo 'New Payment Currency';?></td>
						<td width='40%' align='right' ><input type='image' src='images/template/img_savel.gif' alt='save' title='save' border='0'>&nbsp;&nbsp;<a href='javascript:drop_new_currency();'><img src='images/template/img_closel.gif' alt='close' title='close' border='0'></a>&nbsp;&nbsp;</td>
					</tr>
					<tr><td colspan='5' ><div id="span_new" style="display:none"></div></td></tr>
				</table>
			</td>
		</tr>
       
		</table>
		<table border="0" cellspacing="0" cellpadding="0" width="100%">
			<tr>			  
		         <td class="smallText" valign="top"><?php echo $currency_split->display_count($currency_query_numrows, MAX_DISPLAY_SEARCH_RESULTS, $page,TEXT_DISPLAY_NUMBER_OF_CURRENCIES); ?></td>
		    	 <td class="smallText" align="right"><?php echo $currency_split->display_script_links($currency_query_numrows, MAX_DISPLAY_SEARCH_RESULTS, MAX_DISPLAY_PAGE_LINKS, $page,1,'expand_category(\'\'','\'\''); ?></td>
		    </tr>
	   </table>
<?php  }
//$char="utf-8";
$query=tep_db_query("select symbol_left from currencies where currencies_id=8");
$array=tep_db_fetch_array($query);
?>
<!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; ?>">

<!--<meta http-equiv="Content-Type" content="text/html; charset=<?php //echo $char; ?>">
-->
<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 type="text/javascript" src="htmlarea/htmlarea.js"></script>
<script type="text/javascript" src="htmlarea/editor.js"></script>
<script language="javascript">
var img_src="<?php echo HTTP_SERVER.DIR_WS_ADMIN.'images/';?>";
var max_display="<?php echo MAX_DISPLAY_SEARCH_RESULTS;?>";
var server_date="<?php echo getServerDate();?>";
var currency_prmy="<?php echo CURRENCY_SERVER_PRIMARY;?>";
  function validateForm(cfrm){
      var error_result="";
      if(cfrm.action_type) var action_type=cfrm.action_type.value;
	  if(cfrm && cfrm.currency_id) id=cfrm.currency_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)
	  	details=span_edit;	
	  else details=span_new;   	
	  if(details.style.display==""){	
	  		var obj=cfrm.currency_name.value;
	 		var	obj1=cfrm.currency_code.value;
	  
			  if (obj=="" || str_trim(obj)=="") 
				   error_result+="<?php echo tep_output_string(ERR_EMPTY_CURRENCY_NAME); ?>\n";		      
			  if (obj1=="" || str_trim(obj1)=="")
				   error_result+="<?php echo tep_output_string(ERR_EMPTY_CURRENCY_CODE); ?>\n";	
			  if (cfrm.value.value=="" || cfrm.value.value<=0 ) 
				   error_result+="<?php echo tep_output_string(ERR_INVALID_CURRENCY_VALUE); ?>\n";	
			  if ( isNaN(cfrm.value.value) )
			  	   error_result+="<?php echo tep_output_string(ERR_INVALID_CURRENCY) ; ?>\n";		   	       		  
      if (error_result!=""){
         alert(error_result);
	 	 return false;
      }else	{      							
			if(cfrm.action_type && cfrm.action_type.value=='edit')  ids="&cID="+id;
			command="<?php echo tep_href_link(FILENAME_CURRENCIES,'action=update_currency');?>"+ids;
			if(loadings) loadings.style.display="";
			if(span_edit) span_edit.style.display="none";
			if(document.getElementById("new_currency")){document.getElementById("new_currency").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.style.display==""){      							
			ids="&cID="+id;
			command="<?php echo tep_href_link(FILENAME_CURRENCIES,'action=delete_confirm');?>"+ids;
			if(loadings) loadings.style.display="";
			if(span_delete) span_delete.style.display="none";
     }
	do_post_command('currency_detail',command);
    return false;
   }   
   var previous_id='';
   function expand_category(id,category,r_type,sta){ 
   
    if(id==0 && category==2){
 	if(document.getElementById('empty_currency'))
		document.getElementById('empty_currency').style.display='none';
	display_flag=0;
	}
	if(id==0 && category==1){
 	if(document.getElementById('empty_currency'))
		document.getElementById('empty_currency').style.display='';
	document.getElementById('img_new').firstChild.src=document.getElementById('img_new').firstChild.src.replace('_hover.gif','.gif');
	display_flag=1;
	}	 
     document.getElementById('span_new').style.display="none";
  	document.getElementById('new_currency').style.display="none";
	document.getElementById('span_new').innerHTML='';
		//if(category==3 && document.getElementById('head_'+id) && document.getElementById('head_'+id).style.display!='none' && document.getElementById("span_edit") && document.getElementById("span_edit").style.display=='none' && document.getElementById("span_delete") && document.getElementById("span_delete").style.display=='none') return;
		var sta;
		if(!sta) sta="";
		var frm=document.currency_detail;
		if(category=='1' && document.getElementById("page_''") && sta!=""){
 	 		id=parseInt(document.getElementById("page_''").options[document.getElementById("page_''").selectedIndex].value);
 	 		if(sta=='next' && document.getElementById("page_''")) {
 	 			if(document.getElementById("page_''").length==document.getElementById("page_''").selectedIndex+1) return;
 	 			id+=1;
 	 		}else if(sta=='prev') {
 	 			if(document.getElementById("page_''").selectedIndex==0) return;
 	 			id-=1;
 	 		}
 	 		if(id<=1) id=1;
 	 	}else if(category=='1' && sta=="") id="";
 	 	var res_display=document.getElementById("res_display"); 	 	 	 	 	 	 	 	 	 		 	  	 	
 	 	if(res_display) res_display.style.display="none"; 	 		 	 	
 	 	 if(frm && frm.currency_id && frm.currency_id.value>0)  {
			var old_ids=frm.currency_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 && frm.currency_id.value>0 && frm.currency_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="";
			   frm.currency_id.value=id;			   
			}							
		if(category!=1 && frm && frm.currency_id && frm.currency_id.value=="") frm.currency_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);						
			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_CURRENCIES,'action=page_navigation');?>"+page;
 	 			   	   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";
					 if(document.getElementById('img_update'))
			         document.getElementById('img_update').style.display='none';
					 span_edit.innerHTML="<img src='images/24-1.gif' alt='Loading...' title='Loading...'>";
 	 				 if(frm.action_type) frm.action_type.value='new'; 	 					
 	 				 command="<?php echo tep_href_link(FILENAME_CURRENCIES,'action=edit_currency');?>"; 	 				  	 					 	 					 	 					 	 				 	 		
 	 			break; 	 			
 	 			case 3:
				 if(document.getElementById("new_currency")){ document.getElementById("new_currency").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"; 
 	 			   	  	if(document.getElementById('img_update'))
			       		  document.getElementById('img_update').style.display='';
						span_details.style.display="";
 	 			   	  	if(img_save) img_save.style.visibility="hidden"; 
					  	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';
 	 			   	  		if(tr_obj.childNodes[3].childNodes[0].src==img_src+'template/update3.gif')	
 	 			   	  			tr_obj.childNodes[3].childNodes[0].src=img_src+'template/update2.gif';	 	 			   	  			
 	 			   	  	}	 			   	  	  	 			   	  	 	 			   	  	
 	 			   	  }	 	 			    			   	   	 			   
 	 			 }else { 	 		
				 	if(previous_id!='')
						if(document.getElementById('head_'+previous_id))
							document.getElementById('head_'+previous_id).innerHTML='';	 	 	 			 	
 	 			 	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_CURRENCIES,'action=get_details');?>&cID="+id; 	 			 	
					previous_id=id;
				 }
 	 			break;
 	 			case 4:
 	 					span_edit.style.display=""; 	 					
 	 					span_details.style.display=span_delete.style.display="none";
						if(document.getElementById('img_update'))
			        		 document.getElementById('img_update').style.display='none';
 	 					span_edit.innerHTML="<img src='images/24-1.gif' alt='Loading...' title='Loading...'>";
 	 					if(frm.action_type) frm.action_type.value='edit'; 	 					
 	 					command="<?php echo tep_href_link(FILENAME_CURRENCIES,'action=edit_currency');?>&cID="+id; 	 		 	 					 	 					 	 				 	 		
 	 			break; 	 			
 	 			case 5:	 	 				 	 				 	 		 	 				
 	 					span_delete.style.display="";
 	 					span_edit.style.display=span_details.style.display="none";
 	 					if(document.getElementById('img_update'))
			                document.getElementById('img_update').style.display='none';
						span_delete.innerHTML="<img src='images/24-1.gif' alt='Loading...' title='Loading...'>";
 	 					command="<?php echo tep_href_link(FILENAME_CURRENCIES,'action=delete_currency');?>&cID="+id; 	 	 	 					 	 					 	 			
 	 			break; 
 	 			case 6:
 	 				  document.getElementById('img_update').style.display='';
					 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(frm.action_type) frm.action_type.value='update'; 	 					
 	 				 command="<?php echo tep_href_link(FILENAME_CURRENCIES,'action=update');?>&cID="+id; 
 	 			break; 	 		
				case 7:
		 	 			  if(head && data_id){
		 	 			  	head.style.display="none";
		 	 			  	head.innerHTML="";
		 	 			  	data_id.style.display="";	
		 	 			  } 
		 	 			break;		
					
 	 		}
		   if(command!="") do_get_command(command);
 	 	}		
 	 }  	
	 
 	function do_result(result){ 
	
		 if(result.substr(0,11)=='get_details'){ 
		 print_details('get_details',result.substr(11));}
		 else if(result.substr(0,14)=='success_delete') print_details('success_delete',result.substr(14));
	     else  if(result.substr(0,4)=='edit') print_details('edit',result.substr(4));
		 else if(result.substr(0,6)=='delete') print_details('delete',result.substr(6));
		 else if(result.substr(0,12)=='new_currency') print_details('new_currency',result.substr(23));	
		 else if(result.substr(0,15)=='page_navigation') print_details('page_navigation',result.substr(15));
		 else if(result.substr(0,6)=='update') print_details('update',result.substr(6));
 	}
  
   function print_details(category,result){  	 	 	 	 	 	 	 	 	
 	 	var no_result="";
 	 	var frm=document.currency_detail;
		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 currency_id="";
			var title = "";
			var code="";
			var symbol_left="";						
			var symbol_right="";
			var decimal_point="";
			var thousands_point="";																			
			var decimal_places="";
			var last_updated="";
			var value="";

 	 		currency_id=splt_str[0];
			title = splt_str[1];	 		
 	 		code=splt_str[2];
 	 		symbol_left=splt_str[3]; 	 		 	 		 	 								
 	 		symbol_right=splt_str[4];
			decimal_point=splt_str[5];
			thousands_point=splt_str[6];
			decimal_places=splt_str[7];
			last_updated=splt_str[8];
			value = splt_str[9];
			ex_output = splt_str[10];
			pp_id = splt_str[11];
			//alert(pp_id);
 	 	}	  	 		  	 		 	 	 	  	 		 	  	 
 		if(frm && frm.currency_id) var id=frm.currency_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 equip=document.getElementById("equip");
 		var img_save=document.getElementById("img_save");
		if(document.getElementById('lname_' + pp_id)) {
					var innerhtml=document.getElementById('lname_' + pp_id).innerHTML;
					var obj=document.getElementById('lname_' + pp_id);
					//alert(innerhtml);
					str=obj.innerHTML;
					obj.innerHTML=str.replace('(default)',''); 
					}
		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>'+
						         	'<td class="dataTableContent" width="30%" align="left" id="lname_'+currency_id+'">'+title+'</td>'+
						         	'<td class="dataTableContent" width="30%" align="left">'+code+'</td>'+			         	
					  			 	'<td class="dataTableContent" width="40%" align="left">'+value+'</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='400' class='inner_title' colspan='2' onclick='javascript:expand_category("+currency_id+",7);'>"+title+"</td>"+
				  "<td width='150' align='left' class='main' valign='top'>"+
				  	"<table border='0' cellspacing='0' cellpadding='0' style='width:70;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("+currency_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("+currency_id+",5);' onmouseover='javascript:change_class(this,2);' onmouseout='javascript:change_class(this,3);'><img alt='Delete' title='Delete' src='images/template/img_trash.gif'></td>"+				  	    
				  	    "<td width='10%' id='img_update' onclick='javascript:change_class(this,1);expand_category("+currency_id+",6);' onmouseover='javascript:change_class(this,2);' onmouseout='javascript:change_class(this,3);'><img alt='Update' title='Update' src='images/template/update2.gif'></td>"+				  	    
						"<td class='cell_bg_popm_right' width='10'>&nbsp;</td>"+
				  	  "</tr>"+
				  	"</table>"+
				  "</td>"+"<td  width='250' style='cursor:pointer;cursor:hand;' onclick='javascript:expand_category("+currency_id+",7);'>&nbsp;</td>"+
				 "<td width='65' align='right'><span 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("+currency_id+",3);'><img src='images/template/img_closel.gif' alt='close' title='close' border='0'></a></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='40'>&nbsp;</td>"+	!-->			  							  			
							"<td width='50%'>"+				  							  			
				  				"<table width='100%' border='0' cellspacing='0' cellpadding='2' class='main'>";				  														
									if(title!=""){
									include+="<tr>"+
											"<td align='left' width='10%'><b><?php echo TEXT_INFO_CURRENCY_TITLE;?></b></td>"+
											"<td align='left' width='20%'>"+title+"</td>"+
										"</tr>";
									}
									if(code!=""){
										include+="<tr>"+
											"<td align='left' width='10%'><b><?php echo TEXT_INFO_CURRENCY_CODE;?></b></td>"+
											"<td align='left' width='20%'>"+code+"</td>"+
										"<tr>";
									}
									if(symbol_left!=""){
										include+="</tr>"+
											"<td align='left' width='10%'><b><?php echo TEXT_INFO_CURRENCY_SYMBOL_LEFT;?></b></td>"+
											"<td align='left' width='20%'>"+symbol_left+"</td>"+
										"</tr>";
									}
									//if(symbol_right!=""){
										include+="</tr>"+
											"<td align='left' width='10%'><b><?php echo TEXT_INFO_CURRENCY_SYMBOL_RIGHT;?></b></td>"+
											"<td align='left' width='20%'>"+symbol_right+"</td>"+
										"</tr>";
									//}
									if(last_updated!=""){
										include+="</tr>"+
											"<td align='left' width='10%'><b><?php echo TEXT_INFO_CURRENCY_LAST_UPDATED;?></b></td>"+
											"<td align='left' width='20%'>"+last_updated+"</td>"+
										"</tr>";
									}

				  			  include+="</table></td>"+
							 "<td width='30'></td>"+
							 "<td width='50%'>"+				  							  			
				  				"<table width='100%' border='0' cellspacing='0' cellpadding='2' class='main'>";				  														
									if(decimal_point!=""){
									include+="<tr>"+
											"<td align='left' width='20%'><b><?php echo TEXT_INFO_CURRENCY_DECIMAL_POINT;?></b></td>"+
											"<td align='left' width='20%'>"+decimal_point+"</td>"+
										"</tr>";
									}
									if(thousands_point!=""){
										include+="<tr>"+
											"<td align='left' width='20%'><b><?php echo TEXT_INFO_CURRENCY_THOUSANDS_POINT;?></b></td>"+
											"<td align='left' width='20%'>"+thousands_point+"</td>"+
										"<tr>";
									}
									if(decimal_places!=""){
										include+="</tr>"+
											"<td align='left' width='10%'><b><?php echo TEXT_INFO_CURRENCY_DECIMAL_PLACES;?></b></td>"+
											"<td align='left' width='20%'>"+decimal_places+"</td>"+
										"</tr>";
									}
									if(value!=""){
										include+="</tr>"+
											"<td align='left' width='10%'><b><?php echo TEXT_INFO_CURRENCY_VALUE;?></b></td>"+
											"<td align='left' width='20%'>"+value+"</td>"+
										"</tr>";
									}

									include+="</tr>"+
											"<td align='left' width='10%'><b><?php echo TEXT_INFO_CURRENCY_EXAMPLE;?></b></td>"+
											"<td align='left' width='20%'>"+ex_output+"</td>"+
									"</tr>";
							
							  include+="</table></td>"+
							  
							  
							  "</tr><tr><td>&nbsp;</td></tr>"+
							  "<tr height='15'></tr>"+
							 "</table>"; 
							 /* "<tr>"+
				  				"<td width='50'>&nbsp;</td><td align='left' valign='middle' class='main'>&nbsp;<div style='width:1050;height:50;overflow:auto;'>"+
				  					details
				  				"</div></td>"+
							  "</tr>"+	*/						  							  							
					"</span>"+
				  "</td>"+
				"</tr>"+
			"</table>";
			head.innerHTML=include;
 	 		} 	 			 	 		
 	 	break;
 	 	case 'edit': 	
		    if(document.getElementById('img_save'))
				document.getElementById('img_save').style.visibility='visible'; 		 	 		 	 		 	 		
			if(span_edit) span_edit.style.display="";			
 	 		if(span_edit && span_details){ 	 			 	 			
 	 			span_edit.innerHTML=result; 	 			
 	 			span_details.style.display='none';
 	 		}									  
 	// 	toggle_panel('Equipment:_','false','','0');	     					 		  												
 	 	break;
 	 	case 'delete': 	
		
		    if(document.getElementById('img_save'))
				document.getElementById('img_save').style.visibility='visible'; 		 	 		 	 		 	 		
 	 		if(span_delete) span_delete.style.display="";
 	 		if(span_delete){ 	 			
 	 			span_delete.innerHTML=result; 	 			
 	 			span_details.style.display=span_edit.style.display='none';
 	 		} 	 								   			   
 	 	break; 	 	
 	 	case 'success_delete':			 
 	    	 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_CURRENCY_DELETE_SUCCESS;?>";
 	    	 	res_display.style.display="";
				var obj=document.getElementById("page_''");
 	    	 	if(obj) 
				    len=obj.options[obj.selectedIndex].value;
 	    	 		command="<?php echo tep_href_link(FILENAME_CURRENCIES,'action=page_navigation');?>&page="+len;
					do_get_command(command); 
			 } 	    	  	    	 			 			 			
 	 	break;	
 	 	case 'page_navigation':
 	 		if(document.getElementById("ajax_details"))
 	 		 document.getElementById("ajax_details").innerHTML=result;
 	 	break;	 	 	
		case 'new_currency':
		display_flag=0;			
				var len=1;
				if(result!=""){
					result_splt=result.split('||');
					if(result_splt[0]>0){
						var id=result_splt[0];
						var title=result_splt[1];	
						var code=result_splt[2];
						var value = result_splt[9];					
						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="30%" align="left">'+title+'</td>'+
						         	'<td class="dataTableContent" width="30%" align="left">'+code+'</td>'+			         	
					  			 	'<td class="dataTableContent" width="40%" align="left">'+value+'</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 TEXT_CURRENCY_INSERT_SUCCESS;?>";
				 	    	 res_display.style.display=""; 	    	 	
 	    	 				}
						}    					
					}
				command="<?php echo tep_href_link(FILENAME_CURRENCIES,'action=page_navigation');?>&page="+len;
				if(command!="") do_get_command(command);
			}	
		break;
		
		case 'update':			
 	    	 var len=1;
 	    	 command="<?php echo tep_href_link(FILENAME_CURRENCIES,'action=page_navigation');?>&page="+len;
			 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_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';		    		    		     		   	
	
			    if(img_get_src.src==img_src+'template/update2.gif') { 
					if(span_edit && span_edit.style.display=="" && eve==1 || eve==2){
					 	img_get_src.src=img_src+'template/update3.gif';
					}  		   		 	 			 	 			
			    }else if(eve==3 && img_get_src.src==img_src+'template/update3.gif' && span_edit && span_edit.style.display=="none") img_get_src.src=img_src+'template/update2.gif';		    		    		     		   	
		    }
		 }		 
	  }	
	  
	  function new_currency(){
	  	if(document.getElementById('empty_currency'))
			document.getElementById('empty_currency').style.display='none';
		display_flag=0;
		var frm=document.currency_detail;
			id=frm.currency_id.value;
		
		  if(frm && frm.currency_id && frm.currency_id.value>0)  {
			var old_ids=frm.currency_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( pre_head && pre_head.innerHTML!='') pre_head.innerHTML="";									
		 }		 	 
			if(id>0 && frm.currency_id.value>0 && frm.currency_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="";
			   frm.currency_id.value=id;			   
			}
	
	  document.getElementById('span_new').style.display="";

	 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.getElementById('span_new').innerHTML="";
	  document.getElementById('new_currency').style.display="";
	  if(frm.action_type) frm.action_type.value='new'; 
	  
	  document.getElementById('span_new').innerHTML='<table border="0" cellspacing="2" cellpadding="4" width="100%"  class="openContent"> '+
			  ' <tr ><td><?php echo tep_draw_separator('pixel_trans.gif', '100%', '10'); ?></td></tr> <tr> '+
				 '<td width="50%"> <table border="0" cellspacing="2" cellpadding="4" width="100%" ><tr valign="top"> '+
				  '<td class="main" width="50"><?php echo TEXT_INFO_CURRENCY_TITLE;?></td> '+
						'<td class="main"><?php echo tep_draw_input_field('currency_name','','size=40 maxlength=50');?></td> '+
					'</tr><tr valign="top"> '+
					'<td class="main" width="50"><?php echo TEXT_INFO_CURRENCY_CODE;?></td> '+
						'<td class="main"><?php echo tep_draw_input_field('currency_code','','size=40 maxlength=50');?></td> '+
					'</tr><tr valign="top">' +
						'<td class="main" width="50" nowrap="nowrap"><?php echo TEXT_INFO_CURRENCY_SYMBOL_LEFT; ?></td>'+
						'<td class="main"><?php echo tep_draw_input_field('symbol_left','','size=40 maxlength=50');?></td>'+
					'</tr>	<tr valign="top">'+
						'<td class="main" width="100"><?php echo TEXT_INFO_CURRENCY_SYMBOL_RIGHT; ?></td> '+
						'<td class="main"><?php echo tep_draw_input_field('symbol_right','','size=40 maxlength=50');?></td> '+
					'</tr></table></td><td width="50%">'+
				 ' <table border="0" cellspacing="2" cellpadding="4" width="100%"><tr valign="top"> '+
						'<td class="main"><?php echo TEXT_INFO_CURRENCY_DECIMAL_POINT; ?></td> '+
						'<td class="main"><?php	echo tep_draw_input_field('decimal_point','','size=40 maxlength=50'); ?></td> '+
					'</tr><tr valign="top">	'+			 	 
						'<td class="main"><?php echo TEXT_INFO_CURRENCY_THOUSANDS_POINT; ?></td>'+
						'<td class="main"><?php echo tep_draw_input_field('thousands_point','','size=40 maxlength=50') . '&nbsp;'; ?></td>	'+					
					'</tr><tr valign="top">'+
						'<td class="main"><?php echo TEXT_INFO_CURRENCY_DECIMAL_PLACES; ?></td> '+
						'<td class="main"><?php echo tep_draw_input_field('decimal_places','','size=40 maxlength=50'); ?></td>'+
					'</tr><tr valign="top">'+
						'<td class="main"><?php echo TEXT_INFO_CURRENCY_VALUE; ?></td>'+
						'<td class="main"><?php echo tep_draw_input_field('value','','size=40 maxlength=50'); ?></td>'+
					'</tr>	</table></td></tr>	<tr valign="top" class="main">'+
						'<?php echo tep_draw_checkbox_field('default'). ' ' . TEXT_INFO_SET_AS_DEFAULT; ?>	</tr><tr><td>&nbsp;</td></tr>	'+		
							 
		        
				' </table>  ';
	  
	  
	  }
	  function drop_new_currency(){
	  if(document.getElementById('empty_currency'))
		document.getElementById('empty_currency').style.display='';
	  change_new_image(document.getElementById('img_new'));
	  document.getElementById('new_currency').style.display="none"
	  
	  }
</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="2" cellpadding="2">
  <tr> 
<!-- body_text //-->   
             <td valign="top">
             <?php echo tep_draw_form('currency_detail',FILENAME_CURRENCIES, '' ,'post','onsubmit="javascript:return validateForm(this);"');?>
	       		<table border="0" cellspacing="0" cellpadding="0" width=100%>
				
		<?php 
		$sql="select * from " . TABLE_CURRENCY_UPDATE_HISTORY . "  order by update_time desc limit 1";
		 $sql_query=tep_db_query($sql);
		 if(tep_db_num_rows($sql_query)>0)
		 {
			$row_c=tep_db_fetch_array($sql_query);
			if($row_c['update_status']=='F') //last failure
			{?>
			<tr><td>
			<table class="messageStackError" width="100%">
			<tr><td> 
				<?php 
					$sql_t="select * from " . TABLE_CURRENCY_UPDATE_HISTORY . " order by update_time desc";
					$sql_query_t=tep_db_query($sql_t);
					$cunt=0;
					$to_date="";
					while($row=tep_db_fetch_array($sql_query_t))
					{
						if($row['update_status']=='U' && $cunt!=0)
							break;
						elseif($row['update_status']=='F' && $cunt==0)
						{
							$max_date=$row['update_time'];
							$cunt++;
								/*if($cunt==3) {
									$from_date=$row['update_time'];
									$err_message=sprintf(ERROR_CURRENCY_UPDATE_DATE,STORE_NAME,$from_date,$to_date);
								} else if($cunt==2) {
									$from_date=$row['update_time'];
									$err_message=sprintf(ERROR_CURRENCY_UPDATE_DATE,STORE_NAME,$from_date,$to_date);
								} else if($cunt==1) {
									$to_date=$row['update_time'];
									$err_message=sprintf(ERROR_CURRENCY_UPDATE_ONE,STORE_NAME,$to_date);
								} */
						}
						$min_date=$row['update_time'];
					}
				echo tep_image(DIR_WS_ICONS . 'error.gif') . '&nbsp;' ;
				if($min_date==$max_date)
					echo sprintf(ERROR_CURRENCY_UPDATE_ONE,STORE_NAME,$min_date);
				else
					echo sprintf(ERROR_CURRENCY_UPDATE,STORE_NAME,$min_date,$max_date);
			?>
				</td></tr>
			</table>
			</td></tr> 
			<?php 
			}
		 }?>
				
		
		 <tr><td id="res_display" class="main" style="display:none"></td></tr>
		 	 <tr><td > <div id="new_class_button" align="left">
				<?php echo '<a href="javascript:void new_currency();" id="img_new" onMouseOver="javascript:do_hover_change(this,2);" onMouseOut="javascript:do_hover_change(this,1);">' . tep_image('images/template/img_new.gif','New Payment Currency','22','22') . '</a>'; ?>
			</div></td></tr>
                 <tr class="dataTableRow" height=20 valign="top">
					<td class="dataTableHeadingContent" width="30%"><?php echo TABLE_HEADING_CURRENCY_NAME; ?></td>
					<td class="dataTableHeadingContent" width="30%"><?php echo TABLE_HEADING_CURRENCY_CODES; ?></td>
					<td class="dataTableHeadingContent" width="40%" align="left"><?php echo TABLE_HEADING_CURRENCY_VALUE; ?></td>
                 </tr>
                 <tr>
                  	<td colspan="3" id="ajax_details">
	       	   			 <?php table_write(); ?>	       	   		
		   			</td>
		 		</tr>        
       	<tr><td><?php echo tep_draw_separator('pixel_trans.gif', '2', '10'); ?></td></tr>	
        </table>
        <input type="hidden" name="currency_id" id="currency_id">
	    <input type="hidden" name="action_type" id="action_type">
	    <input type="hidden" name="icnt" id="icnt">
        </form>
        </td>      
<!-- body_text_eof //-->
<!-- body_eof //-->
	</tr>
  </table>
<!-- footer //-->
<?php require(DIR_WS_INCLUDES . 'footer.php'); ?>
<!-- footer_eof //-->
</body>
</html>
<?php require(DIR_WS_INCLUDES . 'application_bottom.php'); ?>
<script language="javascript">
	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 change_new_image(element){
	display_flag=1;
	element.firstChild.src=element.firstChild.src.replace('_hover.gif','.gif');
	}
</script>