<?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');
  tep_get_last_access_file();require(DIR_WS_CLASSES . 'currencies.php');
  require('includes/classes/split_page_results_event.php');
  $currencies = new currencies();
  $command=isset($HTTP_GET_VARS['command'])?$HTTP_GET_VARS['command']:'';
  $country=isset($HTTP_GET_VARS['country_id'])?(int)$HTTP_GET_VARS['country_id']:0;
  $affiliate_id = (($HTTP_GET_VARS['acID'])?tep_db_prepare_input($HTTP_GET_VARS['acID']):0);
  $page = isset($HTTP_GET_VARS['page'])?(int)$HTTP_GET_VARS['page']:'';
  $affiliates_id = isset($HTTP_GET_VARS['id'])?(int)$HTTP_GET_VARS['id']:'';

	 //ajax start
  if($command=='show_state'){
		  $zone_ids="";
		  $zone_name="";
	      $zones_query = tep_db_query("select zone_id,zone_name from " . TABLE_ZONES . " where zone_country_id = '" . tep_db_input($country) . "' order by zone_name");
	      while ($zones_values = tep_db_fetch_array($zones_query)) {
	         $zone_ids.=$zones_values['zone_id'].",";
	         $zone_name.=$zones_values['zone_name'].",";
	      }
	   $content='show_state'.substr($zone_ids,0,-1)."^".tep_output_string(substr($zone_name,0,-1))."^".$zone;    
	   echo $content; 
		exit;
  }  
 //ajax end
 
 
if($command != ''){
	if($command=='get_details'){
	echo get_default_details($affiliates_id);
		 
	
	}else if($command=='mail'){
		$affiliate_email_query = tep_db_query("select affiliate_email_address from " . TABLE_AFFILIATE . " where affiliate_id = " . (int)$affiliates_id );
		$affiliate_email = tep_db_fetch_array($affiliate_email_query);
		echo 'mail'.$affiliate_email['affiliate_email_address'];
	}else if($command=='delete'){
		$affiliate_delete_name_query = tep_db_query("select affiliate_firstname,affiliate_lastname from " . TABLE_AFFILIATE . " where affiliate_id =" . (int)$affiliates_id);
		$affiliate_name = tep_db_fetch_array($affiliate_delete_name_query);
		$affiliate_delete_string = 'delete';
		$affiliate_delete_string .= '<table border="0" cellspacing="0" cellpadding="0" width="100%">';
		$affiliate_delete_string .= '<tr><td class="main" align="center">'.tep_image('images/icons/delete_blue.gif').'</td><td class="inner_title">Delete Affiliate</td></tr>';
		$affiliate_delete_string .= '<tr><td>'.'&nbsp;'.'</td><td class="main">'.TEXT_DELETE_INTRO. '</td></tr>';
		$affiliate_delete_string .= '<tr><td>&nbsp;</td><td class="main"><b>'.$affiliate_name['affiliate_firstname'] . '&nbsp;'. $affiliate_name['affiliate_lastname'] .'</b></td></tr>';
		$affiliate_delete_string .='<tr><td colspan="2">'.tep_draw_separator('pixel_trans.gif',50,10).'</td></tr></table>';
		echo $affiliate_delete_string;
	}if($command=='delete_confirm'){
		$affiliate_delete_query = tep_db_query("delete  from " . TABLE_AFFILIATE . " where affiliate_id = " . (int)$affiliates_id);
		echo 'success_delete'; 
	}else if($command=='edit'){
			echo 'edit';
			echo edit_function($affiliates_id);
	}else if($command=='update_affiliate'){
		
		$update_string="update";
			
    	$affiliate_gender = tep_db_prepare_input($HTTP_POST_VARS['affiliate_gender']);
        $affiliate_firstname = tep_db_prepare_input($HTTP_POST_VARS['affiliate_firstname']);
        $affiliate_lastname = tep_db_prepare_input($HTTP_POST_VARS['affiliate_lastname']);      
		$affiliate_password = tep_db_prepare_input($HTTP_POST_VARS['affiliate_password']);
        $affiliate_dob = (isset($HTTP_POST_VARS['affiliate_dob'])?tep_db_prepare_input($HTTP_POST_VARS['affiliate_dob']):'0000-00-00 00:00:00');        
        $affiliate_email_address = tep_db_prepare_input($HTTP_POST_VARS['affiliate_email_address']);
        $affiliate_company = tep_db_prepare_input($HTTP_POST_VARS['affiliate_company']);
        $affiliate_company_taxid = tep_db_prepare_input($HTTP_POST_VARS['affiliate_company_taxid']);
        $affiliate_payment_check = tep_db_prepare_input($HTTP_POST_VARS['affiliate_payment_check']);
        $affiliate_payment_paypal = tep_db_prepare_input($HTTP_POST_VARS['affiliate_payment_paypal']);
        $affiliate_payment_bank_name = tep_db_prepare_input($HTTP_POST_VARS['affiliate_payment_bank_name']);
        $affiliate_payment_bank_branch_number = tep_db_prepare_input($HTTP_POST_VARS['affiliate_payment_bank_branch_number']);
        $affiliate_payment_bank_swift_code = tep_db_prepare_input($HTTP_POST_VARS['affiliate_payment_bank_swift_code']);
        $affiliate_payment_bank_account_name = tep_db_prepare_input($HTTP_POST_VARS['affiliate_payment_bank_account_name']);
        $affiliate_payment_bank_account_number = tep_db_prepare_input($HTTP_POST_VARS['affiliate_payment_bank_account_number']);
        $affiliate_street_address = tep_db_prepare_input($HTTP_POST_VARS['affiliate_street_address']);
        $affiliate_suburb = tep_db_prepare_input($HTTP_POST_VARS['affiliate_suburb']);
        $affiliate_postcode=tep_db_prepare_input($HTTP_POST_VARS['affiliate_postcode']);
        $affiliate_city = tep_db_prepare_input($HTTP_POST_VARS['affiliate_city']);
        $affiliate_country_id=(($HTTP_POST_VARS['affiliate_country_id'])?tep_db_prepare_input($HTTP_POST_VARS['affiliate_country_id']):0);
        $affiliate_telephone=tep_db_prepare_input($HTTP_POST_VARS['affiliate_telephone']);
        $affiliate_fax=tep_db_prepare_input($HTTP_POST_VARS['affiliate_fax']);
        $affiliate_homepage=tep_db_prepare_input($HTTP_POST_VARS['affiliate_homepage']);
       // $affiliate_state = tep_db_prepare_input($HTTP_POST_VARS['affiliate_state1']);        
   		$affiliate_state = (tep_db_prepare_input($HTTP_POST_VARS['affiliate_state1']))?tep_db_prepare_input($HTTP_POST_VARS['affiliate_state1']):tep_db_prepare_input($HTTP_POST_VARS['affiliate_zone_id']);
        $affiliate_zone_id = (int)(($HTTP_POST_VARS['affiliate_zone_id'])?tep_db_prepare_input($HTTP_POST_VARS['affiliate_zone_id']):0);                      
        $affiliate_commission_percent = (($HTTP_POST_VARS['affiliate_commission_percent'])?tep_db_prepare_input($HTTP_POST_VARS['affiliate_commission_percent']):0);
		$affiliate_username=tep_db_prepare_input($HTTP_POST_VARS['affiliate_username']);
		$affiliate_payment_type = tep_db_prepare_input($HTTP_POST_VARS['affiliate_payments']);
		$affiliate_commission_percent = str_replace (',' , '.' , $affiliate_commission_percent);
		//echo 'GENDER:'.$affiliate_gender;
	if (ACCOUNT_GENDER == 'true') {
      if (($affiliate_gender == 'm') || ($affiliate_gender == 'f')) {
        $entry_gender_error = false;
      } else {
        $error = true;
        $entry_gender_error = true;
		$update_string .='01^&nbsp;required#';
      }
    }
	
    if (strlen($affiliate_firstname) < ENTRY_FIRST_NAME_MIN_LENGTH) {
      $error = true;
      $entry_firstname_error = true;
	  $update_string .='02^&nbsp;min ' . ENTRY_FIRST_NAME_MIN_LENGTH . ' chars#';
    } else {
      $entry_firstname_error = false;
    }

    if (strlen($affiliate_lastname) < ENTRY_LAST_NAME_MIN_LENGTH) {
      $error = true;
      $entry_lastname_error = true;
	  $update_string .='03^&nbsp;min ' . ENTRY_LAST_NAME_MIN_LENGTH . ' chars#';
    } else {
      $entry_lastname_error = false;
    }

	$entry_date_of_birth_error = false;
	 if (ACCOUNT_DOB == 'true') {
      if (!tep_check_date_raw($affiliate_dob,EVENTS_DATE_FORMAT)) {
	  	$error = true;
       $entry_date_of_birth_error = true;
	   $update_string .= '04^&nbsp;(eg. ' . format_date('1970-05-21') . ')#';
      }
    }
	$entry_username_error = false;  
	if (ACCOUNT_USERNAME == 'true') {
		if (strlen($affiliate_username) < ENTRY_USERNAME_MIN_LENGTH) {
		  $error = true;
		  $entry_username_error = true;  
		  $update_string.='05^&nbsp;User Name already exists#';
		} else {
		  $check_name_query = tep_db_query("select count(*) as total from " . TABLE_AFFILIATE . " where LOWER(affiliate_username) = '" . strtolower(tep_db_input($affiliate_username)) . "' and affiliate_id != '" . $affiliates_id . "'");
		  $check_name = tep_db_fetch_array($check_name_query);
		  if ($check_name['total'] > 0) {
			$error = true;
			 $entry_username_error = true;  
			$update_string.='05^&nbsp;User Name already exists#';
		  }
		} 
	}
  
    if (strlen($affiliate_email_address) < ENTRY_EMAIL_ADDRESS_MIN_LENGTH) {
      $error = true;
      $entry_email_address_error = true;
	  $update_string .= '06^&nbsp;min ' . ENTRY_EMAIL_ADDRESS_MIN_LENGTH . ' chars#';
    } else {
      $entry_email_address_error = false;
    }
    if (!tep_validate_email($affiliate_email_address)) {
      $error = true;
	 
      $entry_email_address_check_error = true;
	  $update_string .= '06^&nbsp;The email address doesn\'t appear to be valid!#';
    } else {
      $entry_email_address_check_error = false;
    }
    if (strlen($affiliate_street_address) < ENTRY_STREET_ADDRESS_MIN_LENGTH) {
      $error = true;
      $entry_street_address_error = true;
	  $update_string .='07^&nbsp;min ' . ENTRY_STREET_ADDRESS_MIN_LENGTH . ' chars#';
    } else {
      $entry_street_address_error = false;
    }
  
    if (strlen($affiliate_postcode) < ENTRY_POSTCODE_MIN_LENGTH) {
      $error = true;
      $entry_post_code_error = true;
	  $update_string .='08^&nbsp;min ' . ENTRY_POSTCODE_MIN_LENGTH . ' chars#';
    } else {
      $entry_post_code_error = false;
    } 

    if (strlen($affiliate_city) < ENTRY_CITY_MIN_LENGTH) {
      $error = true;
      $entry_city_error = true;
	  $update_string .='09^&nbsp;min ' . ENTRY_CITY_MIN_LENGTH . ' chars#';
    } else {
      $entry_city_error = false;
    }

    if (!$affiliate_country_id) {
      $error = true;
      $entry_country_error = true;
    } else {
      $entry_country_error = false;
    }

    if (ACCOUNT_STATE == 'true') {
      if ($entry_country_error) {        
        $entry_state_error = true;
      } else {
        //$affiliate_zone_id = 0;
        $entry_state_error = false;
        $check_query = tep_db_query("select count(*) as total from " . TABLE_ZONES . " where zone_country_id = '" . tep_db_input($affiliate_country_id) . "'");
        $check_value = tep_db_fetch_array($check_query);
        $entry_state_has_zones = ($check_value['total'] > 0);        
        if ($entry_state_has_zones) {
          $zone_query = tep_db_query("select zone_id from " . TABLE_ZONES . " where zone_country_id = '" . tep_db_input($affiliate_country_id) . "' and zone_name = '" . tep_db_input($affiliate_state) . "'");                   
          if (tep_db_num_rows($zone_query) == 1) {
            $zone_values = tep_db_fetch_array($zone_query);
            $affiliate_zone_id = $zone_values['zone_id'];
          } else {          	                        
            $zone_query = tep_db_query("select zone_id from " . TABLE_ZONES . " where zone_country_id = '" . tep_db_input($affiliate_country_id) . "' and zone_id = '" . tep_db_input($affiliate_state) . "'");                                  
            if (tep_db_num_rows($zone_query) == 1) {
              $zone_values = tep_db_fetch_array($zone_query);
              $affiliate_zone_id = $zone_values['zone_id'];                          
            } else {
              $error = true;
              $entry_state_error = true;
			  $update_string .= '10^&nbsp;required#';
            }
          }
        } else {          
          if (!$affiliate_state) {
            $error = true;
            $entry_state_error = true;
			$update_string .= '10^&nbsp;required#';
          }
        }
      }
    }    
    
    if (strlen($affiliate_telephone) < ENTRY_TELEPHONE_MIN_LENGTH) {
      $error = true;
      $entry_telephone_error = true;
	  $update_string .='11^&nbsp;min ' . ENTRY_TELEPHONE_MIN_LENGTH . ' chars#';
    } else {
      $entry_telephone_error = false;
    }

   
//echo "select affiliate_email_address from " . TABLE_AFFILIATE . " where affiliate_email_address = '" . tep_db_input($affiliate_email_address) . "' and affiliate_id!='". $affiliates_id."'";
    $check_email = tep_db_query("select affiliate_email_address from " . TABLE_AFFILIATE . " where affiliate_email_address = '" . tep_db_input($affiliate_email_address) . "' and affiliate_id!='". (int)$affiliates_id."'");
    if (tep_db_num_rows($check_email)) { 
      $error = true;
      $entry_email_address_exists = true;
	  $update_string .= '06^&nbsp;This email address already exists!#';
    } else {
      $entry_email_address_exists = false;
    }

    // Check Suburb
    $entry_suburb_error = false;

    // Check Fax
    $entry_fax_error = false;
	
    if (!affiliate_check_url($affiliate_homepage)) {
      $error = true;      
      $entry_homepage_error = true;
	  $update_string .= '13^&nbsp;required#';
    } else {
      $entry_homepage_error = false;
    }    
    // Check Company 
    $entry_company_error = false;
    $entry_company_taxid_error = false;

    // Check Payment
    $entry_payment_check_error = false;
	if($affiliate_payment_type=='P'){
		if (!tep_validate_email($affiliate_payment_paypal)) {
		  $error = true;
		  $entry_payment_paypal_error = true;
		  $update_string .= '14^&nbsp;The email address doesn\'t appear to be valid!#';
		} else {
		  $entry_payment_paypal_error = false;
		}
	}
    //$entry_payment_paypal_error = false;
    $entry_payment_bank_name_error = false;
    $entry_payment_bank_branch_number_error = false;
    $entry_payment_bank_swift_code_error = false;
    $entry_payment_bank_account_name_error = false;
    $entry_payment_bank_account_number_error = false;
	if(!$error){
		$sql_data_array = array('affiliate_firstname' => $affiliate_firstname,
                                'affiliate_lastname' => $affiliate_lastname,
                                'affiliate_email_address' => $affiliate_email_address,
                                'affiliate_payment_check' => $affiliate_payment_check,
                                'affiliate_payment_paypal' => $affiliate_payment_paypal,
                                'affiliate_payment_bank_name' => $affiliate_payment_bank_name,
                                'affiliate_payment_bank_branch_number' => $affiliate_payment_bank_branch_number,
                                'affiliate_payment_bank_swift_code' => $affiliate_payment_bank_swift_code,
                                'affiliate_payment_bank_account_name' => $affiliate_payment_bank_account_name,
                                'affiliate_payment_bank_account_number' => $affiliate_payment_bank_account_number,
                                'affiliate_street_address' => $affiliate_street_address,
                                'affiliate_postcode' => $affiliate_postcode,
                                'affiliate_city' => $affiliate_city,
                                'affiliate_country_id' => $affiliate_country_id,
                                'affiliate_telephone' => $affiliate_telephone,
                                'affiliate_fax' => $affiliate_fax,
                                'affiliate_homepage' => $affiliate_homepage,
                                'affiliate_commission_percent' => $affiliate_commission_percent,
                                'affiliate_agb' => '1',
								'encryption_style' => $encription_style,
								'affiliate_payment_type' => $affiliate_payment_type);
						if (ACCOUNT_DOB == 'true') $sql_data_array['affiliate_dob'] = tep_convert_date_raw($affiliate_dob,EVENTS_DATE_FORMAT);
						if (ACCOUNT_GENDER == 'true') $sql_data_array['affiliate_gender'] = $affiliate_gender;
						if(ACCOUNT_USERNAME == 'true') $sql_data_array['affiliate_username'] = $affiliate_username;
						if (ACCOUNT_COMPANY == 'true') {
						  $sql_data_array['affiliate_company'] = $affiliate_company;
						  $sql_data_array['affiliate_company_taxid'] =  $affiliate_company_taxid;
						}
						if (ACCOUNT_SUBURB == 'true') $sql_data_array['affiliate_suburb'] = $affiliate_suburb;
						if (ACCOUNT_STATE == 'true') {
						  $sql_data_array['affiliate_state'] = $affiliate_state;
						  $sql_data_array['affiliate_zone_id'] = (int)$affiliate_zone_id;
						}
								
				if (!($affiliate_password == '*****' || $affiliate_password == '')) {
					 $sql_data_array['affiliate_password'] = tep_encrypt_password($affiliate_password);
				}	
		$sql_data_array['affiliate_date_account_last_modified'] = 'now()';
        tep_db_perform(TABLE_AFFILIATE, $sql_data_array, 'update', "affiliate_id = '" . (int)$affiliates_id . "'");
		echo get_default_details($affiliates_id);
		}else echo $update_string;
	}else if($command=='change'){
		$affiliate_fetch_string = $affiliates_id;
		$affiliate_select_query = tep_db_query("select * from "  . TABLE_AFFILIATE . " where affiliate_id=" . (int)$affiliates_id);
		$affiliate_fetch_string .= '<table border=1 cellspacing=0 cellspadding=0>';
		while($affiliate = tep_db_fetch_array($affiliate_select_query)){
			$affiliate_fetch_string .= '<tr><td class="main" >'. $affiliate['affiliate_id']  .'</td>';
			$affiliate_fetch_string .= '<td class="main">' . $affiliate['affiliate_firstname'] .'&nbsp;'. $affiliate['affiliate_lastname'] . '</td>';
			$affiliate_fetch_string .= '<td class="main">' . Images . '</td>';
		}
		echo  $affiliate_fetch_string ;
	}else if($command=='page_navigation'){
	     echo $command;
		 table_write(); 	
	}		
	exit;
}

function table_write(){
    global $page,$HTTP_GET_VARS;	
				$search="";
	 		    $keywords=tep_db_prepare_input($HTTP_GET_VARS['keywords']);
				if($keywords!="")
	   		    $search = " where affiliate_id like '" . tep_db_input($keywords) . "' or affiliate_firstname like '" . tep_db_input($keywords) . "' or affiliate_lastname like '" . tep_db_input($keywords) . "' or affiliate_email_address like '" . tep_db_input($keywords) . "'";
				$affiliate_query_raw = "select * from " . TABLE_AFFILIATE . $search . " order by affiliate_lastname";
				$affiliate_split = new splitPageResultsEvent($page, MAX_DISPLAY_SEARCH_RESULTS,$affiliate_query_raw, $affiliate_query_numrows);
				$affiliate_query = tep_db_query($affiliate_query_raw);
				$total_rows = tep_db_num_rows($affiliate_query);
	        ?>
			<table border="0" cellpadding="0" cellspacing="0" width="100%">
			<?php 
			if(tep_db_num_rows($affiliate_query)>0){ 
			 while ($affiliate = tep_db_fetch_array($affiliate_query)) {
			         echo '  <tr  class="dataTableRow" onmouseover="this.className=\'dataTableRowOver\';this.style.cursor=\'hand\'" onmouseout="this.className=\'dataTableRow\'" onclick="javascript:if(document.getElementById(\'head_'.$affiliate['affiliate_id'].'\').style.display==\'none\') expand_category(' . $affiliate['affiliate_id'] . ',3)">' . "\n";

 			if ((substr($affiliate['affiliate_homepage'],0,7) != "http://") && (substr($affiliate['affiliate_homepage'],0,8) != "https://"))
			 $affiliate['affiliate_homepage']="http://".$affiliate['affiliate_homepage'];
			?>    <td >
			<div id='<?php echo 'data_' . $affiliate['affiliate_id'];  ?>'>
			<table border="0" cellpadding="0" cellspacing="0" width="100%">
			   <tr>
                <td class="search" width="15%"><?php echo $affiliate['affiliate_id']; ?></td>        
                <td class="search" width="17%"><?php echo $affiliate['affiliate_lastname']; ?></td>
                <td class="search" width="18%"><?php echo $affiliate['affiliate_firstname']; ?></td>
                <td class="search" width="15%" align="left"><?php if($affiliate['affiliate_commission_percent'] > AFFILIATE_PERCENT) echo number_format($affiliate['affiliate_commission_percent'],2,'.',2); else echo  number_format(AFFILIATE_PERCENT,2,'.',2); ?> %</td>
                <td class="search" width="27%"><?php echo '<a href="' . $affiliate['affiliate_homepage'] . '" target="_blank">' . $affiliate['affiliate_homepage'] . '</a>'; ?></td>
                <td class="search" width="5%" align="right"><?php echo '<a href="' . tep_href_link(FILENAME_AFFILIATE_STATISTICS, tep_get_all_get_params(array('acID')) . 'acID=' . $affiliate['affiliate_id']) . '">' . tep_image(DIR_WS_ICONS . 'statistics.gif', ICON_STATISTICS) . '</a>&nbsp;'; //if ( (is_object($aInfo)) && ($affiliate['affiliate_id'] == $aInfo->affiliate_id) ) { echo tep_image(DIR_WS_IMAGES . 'icon_arrow_right.gif', ''); } else { echo '<a href="' . tep_href_link(FILENAME_AFFILIATE, tep_get_all_get_params(array('acID')) . 'acID=' . $affiliate['affiliate_id']) . '">' . tep_image(DIR_WS_IMAGES . 'icon_info.gif', IMAGE_ICON_INFO) . '</a>'; } ?>&nbsp;</td>
              </tr>
			 </table>
		   </div>	
		   <div id='<?php echo 'head_' . $affiliate['affiliate_id'];  ?>' style="display:none" class="openContent" ></div>
		 </td>
		 </tr> 
<?php } 
	}else if($HTTP_GET_VARS['keywords']==""){ ?>
		<table border="0" cellspacing="0" cellpadding="0" width="100%">
			<tr>
				<td class="main" align="center"><?php echo TEXT_EMPTY_GROUPS;?></td>
			</tr>
		</table>
<?php }	if($HTTP_GET_VARS['keywords']!=""){ ?>
		<table border="0" cellspacing="0" cellpadding="0" width="100%">
			<?php if(tep_db_num_rows($affiliate_query)<=0){  ?>
			<tr height="10">
				<td class="main" align="center"></td>
			</tr>
			<tr>
				<td class="main" align="center"><?php echo TEXT_N0_SEARCH_RESULT;?></td>
			</tr>
			<?php } ?>
			<tr>
				<td class="main" align="center"><?php echo tep_draw_separator('pixel_trans.gif');?></td>
			</tr>
			<tr>
				<td align="right"><a href="javascript:expand_category(1,'1','reset')"><?php echo tep_image_button('button_reset.gif', IMAGE_RESET);?></a></td>
			</tr>
		</table>		      	
<?php }?>
		</table>
<?php 	if(tep_db_num_rows($affiliate_query)>0){ ?>	
		<table border="0" cellspacing="0" cellpadding="0" width="100%">
			<tr height="10"></tr>
			<tr>				  
		         <td class="smallText" valign="top"><?php echo $affiliate_split->display_count($affiliate_query_numrows, MAX_DISPLAY_SEARCH_RESULTS, $page, TEXT_DISPLAY_NUMBER_OF_AFFILIATES); ?></td>
		    	 <td class="smallText" align="right"><?php echo $affiliate_split->display_script_links($affiliate_query_numrows, MAX_DISPLAY_SEARCH_RESULTS, MAX_DISPLAY_PAGE_LINKS, $page, 1,'expand_category(\'\'','\'\'');?></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">
<?php // require('includes/form_check.js.php');?>
<script language="javascript" src="includes/menu.js"></script>
<script language="javascript" src="includes/general.js"></script>
<script language="javascript" src="includes/http.js"></script>
<?php //require('includes/password_strength.js.php');?>
<script language="javascript">
		var img_src="<?php echo HTTP_SERVER.DIR_WS_ADMIN.'images/';?>";	
		
		function show_state(){
		var this_=document.affiliate.affiliate_country_id;
		id=this_.options[this_.selectedIndex].value;
		if(id){ 
			command="<?php echo tep_href_link(FILENAME_AFFILIATE,'command=show_state');?>&country_id="+id;
			do_get_command(command);
			if(document.getElementById("affiliate_zone_id"))document.getElementById("affiliate_zone_id").innerHTML="Loading...";
		}else{
			element=document.getElementById("affiliate_zone_id").innerHTML="";
		}
	}
	function do_action(){
		var payment=document.affiliate.elements["affiliate_payment"];
		if(payment){
			if(payment.length>0){
				for(i=0;i<payment.length;i++){
					if(payment[i].checked){
						disable(payment[i].value);
						return;
					}	
				}
			} else {
				if(payment.checked)	
					disable(payment.value);
			}
		}
	}
	function disable(val){ 
		switch (val){
			case 'C':
				if(document.getElementById('affiliate_cheque')) document.getElementById('affiliate_cheque').style.display="";
				if(document.getElementById('affiliate_paypal')) document.getElementById('affiliate_paypal').style.display="none";
				if(document.getElementById('affiliate_bank')) document.getElementById('affiliate_bank').style.display="none";
				if(document.getElementById('swift_code')) document.getElementById('swift_code').style.display="none";
				if(document.affiliate.elements['affiliate_payment_paypal']) document.affiliate.elements['affiliate_payment_paypal'].value="";
				if(document.affiliate.elements['affiliate_payment_bank_name']) document.affiliate.elements['affiliate_payment_bank_name'].value="";
				if(document.affiliate.elements['affiliate_payment_bank_branch_number']) document.affiliate.elements['affiliate_payment_bank_branch_number'].value="";
				if(document.affiliate.elements['affiliate_payment_bank_swift_code']) document.affiliate.elements['affiliate_payment_bank_swift_code'].value="";
				if(document.affiliate.elements['affiliate_payment_bank_account_name']) document.affiliate.elements['affiliate_payment_bank_account_name'].value="";
				if(document.affiliate.elements['affiliate_payment_bank_account_number']) document.affiliate.elements['affiliate_payment_bank_account_number'].value="";
				break;
			case 'P':
				if(document.getElementById('affiliate_cheque')) document.getElementById('affiliate_cheque').style.display="";
				if(document.getElementById('affiliate_paypal')) document.getElementById('affiliate_paypal').style.display="";
				if(document.getElementById('affiliate_bank')) document.getElementById('affiliate_bank').style.display="none";
				if(document.getElementById('swift_code')) document.getElementById('swift_code').style.display="none";
				if(document.affiliate.elements['affiliate_payment_bank_name']) document.affiliate.elements['affiliate_payment_bank_name'].value="";
				if(document.affiliate.elements['affiliate_payment_bank_branch_number']) document.affiliate.elements['affiliate_payment_bank_branch_number'].value="";
				if(document.affiliate.elements['affiliate_payment_bank_swift_code']) document.affiliate.elements['affiliate_payment_bank_swift_code'].value="";
				if(document.affiliate.elements['affiliate_payment_bank_account_name']) document.affiliate.elements['affiliate_payment_bank_account_name'].value="";
				if(document.affiliate.elements['affiliate_payment_bank_account_number']) document.affiliate.elements['affiliate_payment_bank_account_number'].value="";
			break;	
			case 'D':
				if(document.getElementById('affiliate_cheque')) document.getElementById('affiliate_cheque').style.display="";
				if(document.getElementById('affiliate_paypal')) document.getElementById('affiliate_paypal').style.display="none";
				if(document.getElementById('affiliate_bank')) document.getElementById('affiliate_bank').style.display="";
				if(document.getElementById('swift_code')) document.getElementById('swift_code').style.display="";
				if(document.affiliate.elements['affiliate_payment_paypal']) document.affiliate.elements['affiliate_payment_paypal'].value="";
			break;
		}
	}
	function resetStateText(theForm) {
  theForm.affiliate_state.value = '';
  if (theForm.affiliate_zone_id.options.length > 1) {
    theForm.affiliate_state.value = '<?php echo JS_STATE_SELECT; ?>';
  	}
}

function resetZoneSelected(theForm) {
  if (theForm.affiliate_state.value != '') {
    theForm.affiliate_zone_id.selectedIndex = '0';
    if (theForm.affiliate_zone_id.options.length > 1) {
      theForm.affiliate_state.value = '<?php echo JS_STATE_SELECT; ?>';
    }
  }
}

function update_zone(theForm) {
  var NumState = theForm.affiliate_zone_id.options.length;
  var SelectedCountry = '';

  while(NumState > 0) {
    NumState--;
    theForm.affiliate_zone_id.options[NumState] = null;
  }

  SelectedCountry = theForm.affiliate_country_id.options[theForm.affiliate_country_id.selectedIndex].value;

<?php echo tep_js_zone_list('SelectedCountry', 'theForm', 'affiliate_zone_id'); ?>

  resetStateText(theForm);
}
	function do_check(val){ 
	var err_msg="";
	switch (val){
		case 'C':
			  if (document.affiliate.affiliate_payment_check.value == "") {
				err_msg = err_msg + "<?php echo JS_PAYEE_NAME; ?>";
			  }
		break;
		case 'P':
			  if (document.affiliate.affiliate_payment_check.value == "") {
				err_msg = err_msg + "<?php echo JS_PAYEE_NAME; ?>";
			  }
			  if (document.affiliate.affiliate_payment_paypal.value == "") {
				err_msg = err_msg + "<?php echo JS_PAYPAL_EMAIL; ?>";
			  }
			 
		break;
		case 'D':
			  if (document.affiliate.affiliate_payment_check.value == "") {
				err_msg = err_msg + "<?php echo JS_PAYEE_NAME; ?>";
			  }
			  if (document.affiliate.affiliate_payment_bank_name.value == "") {
			  
				err_msg = err_msg + "<?php echo JS_BANK_NAME; ?>";
			  }
			  if (document.affiliate.affiliate_payment_bank_branch_number.value == "") {
				err_msg = err_msg + "<?php echo JS_BRANCH_NUMBER; ?>";
			  }
			  if (document.affiliate.affiliate_payment_bank_swift_code.value == "") {
				err_msg = err_msg + "<?php echo JS_SWIFT_CODE; ?>";
			  }
			  if (document.affiliate.affiliate_payment_bank_account_name.value == "") {
				err_msg = err_msg + "<?php echo JS_ACCOUNT_NAME; ?>";
			  }
			  if (document.affiliate.affiliate_payment_bank_account_number.value == "") {
				err_msg = err_msg + "<?php echo JS_ACCOUNT_NUMBER; ?>";
			  }
		break;
	}
	return err_msg;
}

	function check_edit_form() { 
			  var error = 0;
			  var pay_error;
			  var error_message = "<?php echo JS_ERROR; ?>";
			
		var affiliate_firstname = document.affiliate.affiliate_firstname.value;
		  var affiliate_lastname = document.affiliate.affiliate_lastname.value;
		<?php if (ACCOUNT_COMPANY == 'true') echo 'var affiliate_company = document.affiliate.affiliate_company.value;' . "\n"; ?>
		  var affiliate_email_address = document.affiliate.affiliate_email_address.value;  
		  var affiliate_street_address = document.affiliate.affiliate_street_address.value;
		  var affiliate_postcode = document.affiliate.affiliate_postcode.value;
		  var affiliate_city = document.affiliate.affiliate_city.value;
		  var affiliate_telephone = document.affiliate.affiliate_telephone.value;
		  var commission=document.affiliate.affiliate_commission_percent.value;
		  //var affiliate_password = document.affiliate.affiliate_password.value;
		  var affiliate_username=document.affiliate.affiliate_username.value;
		  
		  <?php if (ACCOUNT_DOB == 'true')  echo 'var affiliate_dob=document.affiliate.affiliate_dob.value;' . "\n";?>
		
		<?php if (ACCOUNT_GENDER == 'true') { ?>
		 if (document.affiliate.genderflag.value=="1"){
		  if (document.affiliate.affiliate_genders[0].checked || document.affiliate.affiliate_genders[1].checked) {
		  } else {
			error_message = error_message + "<?php echo JS_GENDER; ?>";
			error = 1;
		  }
		  }
		<?php } ?>
		
		  if (affiliate_firstname == "" || str_trim(affiliate_firstname) == "" || affiliate_firstname.length < <?php echo ENTRY_FIRST_NAME_MIN_LENGTH; ?>) {
			error_message = error_message + "<?php echo JS_FIRST_NAME; ?>";
			error = 1;
		  }
		
		  if (affiliate_lastname == "" || str_trim(affiliate_lastname) == "" || affiliate_lastname.length < <?php echo ENTRY_LAST_NAME_MIN_LENGTH; ?>) {
			error_message = error_message + "<?php echo JS_LAST_NAME; ?>";
			error = 1;
		  }
		  
		<?php if (ACCOUNT_DOB == 'true') { ?>
		  if (affiliate_dob == "" || affiliate_dob.length < <?php echo ENTRY_DOB_MIN_LENGTH; ?>) {
			error_message = error_message + "<?php echo JS_EVENT_DOB; ?>";
			error = 1;
		  }
		<?php } ?>
		<?php if (ACCOUNT_USERNAME == 'true') { ?>
		  if (affiliate_username == "" || str_trim(affiliate_username)=="" || affiliate_username.length < <?php echo ENTRY_USERNAME_MIN_LENGTH; ?>) {
			error_message = error_message + "<?php echo JS_USERNAME; ?>";
			error = 1;
		  }
		<?php } ?>
		  
		  if (affiliate_email_address == "" || affiliate_email_address.length < <?php echo ENTRY_EMAIL_ADDRESS_MIN_LENGTH; ?>) {
			error_message = error_message + "<?php echo JS_EMAIL_ADDRESS; ?>";
			error = 1;
		  }
			if(commission!='') {
				if(isNaN(parseInt(commission))==true ){
					error=true;
					error_message +="* <?php echo JS_COMMISSION_PERCENT;?>\n";
				}	
			}
		<?php if((AFFILIATE_USE_CHECK == 'true') || (AFFILIATE_USE_PAYPAL == 'true') || (AFFILIATE_USE_BANK == 'true')){ ?>
			var payment = document.affiliate.affiliate_payment;
			if(payment){
				if(payment.length>0){
					for(i=0;i<payment.length;i++){
						if(payment[i].checked){
							pay_error = do_check(payment[i].value);
							document.affiliate.affiliate_payments.value = payment[i].value;
							if(pay_error!=''){
								error_message +=pay_error;
								error = 1;
							}
						}
					}
				} else {
					pay_error =do_check(payment.value);
					if(pay_error!=''){
						error_message +=pay_error;
						error = 1;
					}
				}	
			}
		<?php } ?>
		
		  if (affiliate_street_address == "" || affiliate_street_address.length < <?php echo ENTRY_STREET_ADDRESS_MIN_LENGTH; ?>) {
			error_message = error_message + "<?php echo JS_ADDRESS; ?>";
			error = 1;
		  }
		
		  if (affiliate_postcode == "" || affiliate_postcode.length < <?php echo ENTRY_POSTCODE_MIN_LENGTH; ?>) {
			error_message = error_message + "<?php echo JS_POST_CODE; ?>";
			error = 1;
		  }
		
		  if (affiliate_city = "" || affiliate_city.length < <?php echo ENTRY_CITY_MIN_LENGTH; ?>) {
			error_message = error_message + "<?php echo JS_CITY; ?>";
			error = 1;
		  }
		
		<?php if (ACCOUNT_STATE == 'true') { ?>    
		  if (document.affiliate.affiliate_state1.type!='hidden' && document.affiliate.affiliate_state1.style.display!='none') {        
			if (document.affiliate.affiliate_state1.value =="" || document.affiliate.affiliate_state1.value.length < <?php echo ENTRY_STATE_MIN_LENGTH; ?>) {
			   error_message = error_message + "<?php echo JS_STATE; ?>";       
			   error = 1;
			}
		  } else if(document.affiliate.affiliate_zone_id.type!='hidden' && document.affiliate.affiliate_zone_id.style.display!='none' && document.affiliate.affiliate_zone_id){           
			if (document.affiliate.affiliate_zone_id.options[document.affiliate.affiliate_zone_id.selectedIndex].value=="") {
			   error_message = error_message + "<?php echo JS_ZONE; ?>";
			   error = 1;
			}
		  }
		<?php } ?>
		
		  if (document.affiliate.affiliate_country_id.value == 0) {
			error_message = error_message + "<?php echo JS_COUNTRY; ?>";
			error = 1;
		  }
		
		  if (affiliate_telephone == "" || affiliate_telephone.length < <?php echo ENTRY_TELEPHONE_MIN_LENGTH; ?>) {
			error_message = error_message + "<?php echo JS_TELEPHONE; ?>";
			error = 1;
		  }
		  var url = document.affiliate.affiliate_homepage.value.match(/^https?:\/\/[a-z0-9]([-_.]?[a-z0-9])+[.][a-z0-9][a-z0-9\/=?.&\~_-]+$/);
		 if(url == null) {
			error = true;
			error_message +="<?php echo JS_HOMEPAGE_ERROR;?>";
		 }
	
		  if (error == 1) { 
			alert(error_message);
			return false;
		  } else {
			return true;
		  }
}
	function check_form(){ 
	  var command="";
	  var frm = document.new_affiliate;
	  var id = frm.affiliate_id.value;
	  var span_details=document.getElementById("span_details");
	  var span_edit=document.getElementById("span_edit");				
	  var span_delete=document.getElementById("span_delete");
	  if(span_details && span_details.style.display=="") return false;
	  else if(span_details && span_details.style.display!="" && span_edit.style.display==''){ 
			  if(check_edit_form()==true){ 
				 if(document.affiliate.affiliate_genders[0].checked)
						document.affiliate.affiliate_gender.value=document.affiliate.affiliate_genders[0].value;
				if(document.affiliate.affiliate_genders[1].checked) 
						document.affiliate.affiliate_gender.value=document.affiliate.affiliate_genders[1].value;	
			  command = '<?php echo  tep_href_link(FILENAME_AFFILIATE,'command=update_affiliate'); ?>&id='+id;
			  do_post_command('affiliate',command);
			  }
			  return false;
	  }else if(span_delete.style.display==""){					
			span_details.innerHTML=span_edit.innerHTML="";
			command="<?php echo tep_href_link(FILENAME_AFFILIATE,'command=delete_confirm');?>&id="+id;			
			do_post_command('affiliate',command);
			if(span_delete) span_delete.style.display="none";
			return false;
		}
	}
	function do_result(result){  //alert(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,6)=='delete') print_details('delete',result.substr(6));
			 else  if(result.substr(0,14)=='success_delete')  print_details('delete_success',result.substr(0,14));
			 else  if(result.substr(0,4)=='mail') print_details('mail',result.substr(4));
			 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));
				
	 else if(result!='' && result.substr(result.indexOf('show_state'),10)=='show_state'){
			result=result.substr(result.indexOf('show_state')+10,result.length);
			var textArr=new Array();
			var valueArr=new Array();
			splt=result.split("^");
			valueArr=splt[0].split(",");		
			textArr=splt[1].split(",");
			sel_zone=splt[2];
		var sel=document.getElementById("affiliate_zone_id");
		var sta1=document.getElementById("affiliate_state1");
		if(valueArr.length==1) {
			if(sta1){
			 sta1.style.display="";
			 sta1.value="";}
			if(sel)sel.style.display="none";
		}else {
			if(sta1) {
				sta1.style.display="none";	
				sta1.value="";
			}
			if(sel) {
			  sel.style.display="";
			  sel.value="";	
			}
			optionElement=sel;

				// clear the previous details
				while(optionElement.options.length>0){
					optionElement.remove(optionElement.options.length - 1);
				}
				//create the new details
				for (icnt=0;icnt<textArr.length;icnt++){
				  var option = document.createElement('option');
				  option.text = textArr[icnt];
				  option.value = valueArr[icnt];
				  try {
					optionElement.add(option, null); // standards compliant; doesn't work in IE
				  }
				  catch(ex) {
					optionElement.add(option); // IE only
				  }
			}
			if(typeof(default_zone) != "undefined")
			for(i=0;i<optionElement.options.length;i++){
				if(optionElement.options[i].value==default_zone)
					optionElement.options[i].selected = true;
			}
			if(document.getElementById("state1") && typeof(default_country) != "undefined")
			if(default_country!=document.getElementById("country"))
				document.getElementById("state1").value="";
		}
	  }
	}
	
 function print_details(category,result){ 		 
 	 	 	 	 	 	 	
 	 	var no_result=""; 	 	
 	 	var include="";
 	 	//if(document.resource.action_type) document.resource.action_type.value='';
		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  resource_id="";
			var  resource_name="";
			var  resource_description="";			
			var  resource_date_added="";
			var  resource_last_modified="";
			var  affiliate_last_logon="";
			var  affiliate_number_of_logons="";
			var  affiliate_commission="";	
			var  affiliate_homepage=""; 	
			var sort_order="";																		
			
 	 		resource_id=splt_str[0]; 	 		
 	 		resource_name=splt_str[1] +'&nbsp;' + splt_str[2];
			resource_date_added=splt_str[3];
 	 		resource_last_modified=splt_str[4];
			affiliate_last_logon=splt_str[5];
			affiliate_number_of_logons=splt_str[6];
			affiliate_commission=splt_str[7];
			affiliate_homepage=splt_str[8];
 	 	}	  	 		 	 	 	 	  	 		 	  	 
 		if(document.new_affiliate && document.new_affiliate.affiliate_id) var id=document.new_affiliate.affiliate_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>'+
						         	'<td class="search" width="15%">&nbsp;'+resource_id+'</td>'+
									'<td class="search" width="17%">&nbsp;'+splt_str[1]+'</td>'+
									'<td class="search" width="18%">&nbsp;'+splt_str[2]+'</td>'+
									'<td class="search" width="15%">&nbsp;'+affiliate_commission+'</td>'+
									'<td class="search" width="27%">&nbsp;<a class="search" href="'+affiliate_homepage+'" target="_blank">'+affiliate_homepage+'</a></td>'+
					  			 	'<td class="search" width="5%" align="right"><a href="marketing_affiliate_statistics.php?acID='+resource_id+'"><img src="images/icons/statistics.gif" alt="Stati" title=" Info " border="0"></a></td>'+  
						         '</tr>'+
						      	'</tbody></table>';
	 	 		}				 	 			 	 		
	 	 		head.innerHTML ="<table width='100%' border='0' cellspacing='0' cellpadding='0' style='padding-top:4px;'>"+
				"<tr heigth='40'>"+
				  "<td width='10'></td>"+				  							  
				  "<td align='left' valign='middle' width='350' class='main'>"+resource_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("+resource_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("+resource_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%' onclick='javascript:change_class(this,1);expand_category("+resource_id+",6);' onmouseover='javascript:change_class(this,2);' onmouseout='javascript:change_class(this,3);'><img alt='Email' title='Email' src='images/template/img_sms.gif'></td>"+
					   	"<td width='10%' onclick='javascript:change_class(this,1);expand_category("+resource_id+",7);' onmouseover='javascript:change_class(this,2);' onmouseout='javascript:change_class(this,3);'><img alt='Payment' title='Payment' src='images/template/img_move.gif'></td>"+
					    "<td width='10%' onclick='javascript:change_class(this,1);expand_category("+resource_id+",8);' onmouseover='javascript:change_class(this,2);' onmouseout='javascript:change_class(this,3);'><img alt='Sales' title='Sales' src='images/template/img_copy.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("+resource_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='8' class='main'><span style='display:none' id='span_edit'></span><span style='display:none' id='span_delete'></span><span style='display:none' id='span_move'></span><span style='display:none' id='span_copy'></span><span id='span_details'>"+	"<table width='100%' border='0' cellspacing='0' cellpadding='0'>"+
				  		"<tr>"+
				  			"<td width='100'>&nbsp;</td>"+				  							  			
							"<td width='700'>"+				  							  			
				  				"<table width='100%' border='0' cellspacing='5' cellpadding='0' class='main'>"+
				  					"<tr>"+
				  						"<td align='left' width='100' valign='top'><?php echo TEXT_DATE_ADDED;?></td>"+
				  						"<td align='left' width='100' valign='top'>"+resource_date_added+"</td>"+
										"<td align='left' width='150'><?php echo TEXT_NUMBER_OF_LOGONS ;?></td>"+
										"<td align='left' width='250'>"+affiliate_number_of_logons+"</td>"+
				  					"</tr>"+			  					
				  					"<tr>"+
				  						"<td align='left' width='100'><?php echo TEXT_LAST_MODIFIED ;?></td>"+
				  						"<td align='left' width='100'>"+resource_last_modified+"</td>"+
										"<td align='left' width='100'><?php echo TEXT_COMMISSIONS ;?></td>"+
										"<td align='left' width='250'>"+affiliate_commission+"</td>"+
				  					"</tr>"+									
									"<tr>"+
										"<td align='left' width='100'><?php echo TEXT_LAST_LOGON ;?></td>"+
										"<td align='left' width='100'>"+affiliate_last_logon+"</td>"+
										"<td align='left' width='100'><?php echo TEXT_HOMEPAGE ;?></td>"+
										"<td align='left' width='250'>"+affiliate_homepage+"</td>"+
									"</tr>"+
									"<tr>"+
										'<td colspan="4"><?php echo tep_draw_separator('pixel_trans.gif',50,10); ?></td>'+
									"</tr>"+
				  			  "</table></td></tr>"+
					"</span>"+
				  "</td>"+
				"</tr>"+
			"</table>";
 	 		}		 	 		
 	 	break;
 	 	case 'edit': 	 		 	 		 	 		 	 		
			if(span_edit) span_edit.style.display="";			
 	 		if(span_edit && span_details){ 	 			 	 			
 	 			span_edit.innerHTML=result; 	 			
 	 			span_details.style.display='none';
 	 		}
			//toggle_panel('Customer_Details','','true','0');
			toggle_panel('Individual_Commission','false','','0');
			toggle_panel('Company','false','','0');
			toggle_panel('Affiliate_Payments','false','','0');
			toggle_panel('Address','false','','0');
			toggle_panel('Phone_Information','false','','0');
			do_action();
 	 	break;
 	 	case 'delete': 	 				 	 	
 	 		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 '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 TEXT_DELETE_SUCCESS;?>";
 	    	 	res_display.style.display=""; 	    	 	
 	    	 } 	    	 			 			 	
			 var obj=document.getElementById("page_''");
 	    	 	if(obj){  	    	 		
 	    	 		var len=obj.options[obj.selectedIndex].value;
 	    	 		command="<?php echo tep_href_link(FILENAME_AFFILIATE,'command=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 'mail':
			location.href='<?php echo tep_href_link(FILENAME_AFFILIATE_CONTACT,'selected_box=affiliate'); ?>&affiliate='+result; 	
		break;
		case 'update': 
				if(result.length>0){ 
					var span_obj="";
					var splt_len="";
					var splt_result="";
					splt_result = result.split('#');
					splt_len = splt_result.length;
					for(i=0;i<splt_len;i++){
						span_obj = splt_result[i].substr(0,2);
						if(span_obj){
						document.getElementById(span_obj).innerHTML=splt_result[i].substr(3);
						document.getElementById(span_obj).style.display='';
						document.getElementById(span_obj).className='errorText';
						}
					}
					
				}
			 	
		break;
 	 	}
		
 	 	if(res_display.style.display=="") setTimeout("res_display.style.display='none'",2000); 	 	 	 	
 	 	clearTimeout();
	  }
	
</script>
<?php
  if ($HTTP_GET_VARS['action'] == 'edit' || $HTTP_GET_VARS['action'] == 'update') {
?>
<script language="javascript"><!--





//--></script>
<?php
  }
?>
</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>
  <!--  <td width="<?php //echo BOX_WIDTH; ?>" valign="top"><table border="0" width="<?php //echo BOX_WIDTH; ?>" cellspacing="1" cellpadding="1" class="columnLeft">-->
<!-- left_navigation //-->
<?php //require(DIR_WS_INCLUDES . 'column_left.php'); ?>
<!-- left_navigation_eof //-->
  <!--  </table></td> -->
<!-- body_text //-->
    <td width="100%" valign="top"><table border="0" width="100%" cellspacing="0" cellpadding="2">
<?php
  if ($HTTP_GET_VARS['action'] == 'edit' || $HTTP_GET_VARS['action'] == 'update') { 
 /*"select affiliate_gender,affiliate_firstname,affiliate_lastname,affiliate_dob,affiliate_email_address,affiliate_telephone,affiliate_fax,affiliate_password, ".
	" affiliate_home_page,affiliate_street_address,affiliate_subrub,affiliate_post_code,affiliate_city,affiliate_state,affiliate_country_id,affiliate_zone_id,affiliate_agb,affiliate_company,affiliate_company_taxid,".
	" affiliate_commission_percent,affiliate_payment_check,affiliate_payment_paypal,affiliate_payment_bank_number,affiliate_bank_branch_number,affiliate_payment_swift_code,affiliate_payment_account_name,".
	"affiliate_payment_account_number,affiliate_date_of_lost_logon,affiliate_number_of_logons,affiliate_date_account_created,affiliate_date_account_last_modified,affiliate_lft,affiliate_rgt,affiliate_root,encryption_style ".*/
?>
     <!-- <tr>
        
      </tr>-->
	  <?php tep_content_title_bottom();?>
      <tr>
        <td><?php echo tep_draw_separator('pixel_trans.gif', '1', '10'); ?></td>
      </tr>
       <tr>
        <td align="right" class="main"><?php echo tep_image_submit('button_update.gif', IMAGE_UPDATE) . ' <a href="' . tep_href_link(FILENAME_AFFILIATE, tep_get_all_get_params(array('action'))) .'">' . tep_image_button('button_cancel.gif', IMAGE_CANCEL) . '</a>';?></td>
      </tr></form>
<?php
  } else {
?>
      <tr class="dataTableHeadingRow">
        <td><table border="0" width="100%" cellspacing="0" cellpadding="0">
          <tr><?php //echo tep_draw_form('search', FILENAME_AFFILIATE, '', 'get'); ?>
           <!--	 <td class="pageHeading"><?php echo HEADING_TITLE; ?></td> -->
            <td class="pageHeading" align="right"><?php echo tep_draw_separator('pixel_trans.gif', 1, 1); ?></td>
            <td class="dataTableHeadingContent" align="right"><?php echo HEADING_TITLE_SEARCH . ' ' . tep_draw_input_field('search','','onKeyup=check_key(event);') .'&nbsp;'; ?></td>
			<td align="left" valign="absmiddle" width="25"><a alt="Search" title="Search" href="javascript:expand_category(1,'1','search');"><?php echo tep_image('images/template/img_search.gif');?></a></td>	
          <!--</form>--></tr>
        </table></td>
      </tr>
      <tr>
        <td> <?php  echo tep_draw_form('affiliate',FILENAME_AFFILIATE,'','post','onSubmit="javascript:return check_form();"');?>
		<table border="0" width="100%" cellspacing="0" cellpadding="0">
          <tr id="result_id">
            <td valign="top"><table border="0" width="100%" cellspacing="0" cellpadding="2">
              <tr class="dataTableHeadingRow">
                <td class="dataTableHeadingContent" width="15%"><?php echo TABLE_HEADING_AFFILIATE_ID; ?></td>
                <td class="dataTableHeadingContent" width="17%"><?php echo TABLE_HEADING_LASTNAME; ?></td>
                <td class="dataTableHeadingContent" width="18%"><?php echo TABLE_HEADING_FIRSTNAME; ?></td>
                <td class="dataTableHeadingContent" width="15%" align="left"><?php echo TABLE_HEADING_COMMISSION; ?></td>
                <td class="dataTableHeadingContent" width="27%"><?php echo TABLE_HEADING_USERHOMEPAGE; ?></td>
                <td class="dataTableHeadingContent" width="5%" align="right"><?php echo TABLE_HEADING_ACTION; ?>&nbsp;</td>
              </tr>
			  <tr><td colspan="5" class="main" id="res_display" style="display:none"></td></tr>
                 <tr>
                  	<td colspan="6" id="ajax_details">
						<?php table_write(); ?>
					</td>
		 		 </tr>	

<?php echo '</form>';
	//echo tep_draw_form('new_affiliate',FILENAME_AFFILIATE);
?></table></td>
	 </tr>
              <tr>
                <td colspan="6" >
				<form name="new_affiliate" action="<?php echo FILENAME_AFFILIATE; ?>" method="post">
				<input type="hidden" id="affiliate_id">
				</form>
                </td>
              </tr>
            </table></td>
<?php
  $heading = array();
  $contents = array();
  switch ($HTTP_GET_VARS['action']) {
    case 'confirm':
      $heading[] = array('text' => '<b>' . TEXT_INFO_HEADING_DELETE_CUSTOMER . '</b>');

      $contents = array('form' => tep_draw_form('affiliate', FILENAME_AFFILIATE, tep_get_all_get_params(array('acID', 'action')) . 'acID=' . $aInfo->affiliate_id . '&action=deleteconfirm'));
      $contents[] = array('text' => TEXT_DELETE_INTRO . '<br><br><b>' . $aInfo->affiliate_firstname . ' ' . $aInfo->affiliate_lastname . '</b>');
      $contents[] = array('align' => 'center', 'text' => '<br>' . tep_image_submit('button_delete.gif', IMAGE_DELETE) . ' <a href="' . tep_href_link(FILENAME_AFFILIATE, tep_get_all_get_params(array('acID', 'action')) . 'acID=' . $aInfo->affiliate_id) . '">' . tep_image_button('button_cancel.gif', IMAGE_CANCEL) . '</a>');
      break;
   case 'default':
      if (is_object($aInfo)) {
        $heading[] = array('text' => '<b>' . $aInfo->affiliate_firstname . ' ' . $aInfo->affiliate_lastname . '</b>');

        $contents[] = array('align' => 'center', 'text' => '<a href="' . tep_href_link(FILENAME_AFFILIATE, tep_get_all_get_params(array('acID', 'action')) . 'acID=' . $aInfo->affiliate_id . '&action=edit') . '">' . tep_image_button('button_edit.gif', IMAGE_EDIT) . '</a> <a href="' . tep_href_link(FILENAME_AFFILIATE, tep_get_all_get_params(array('acID', 'action')) . 'acID=' . $aInfo->affiliate_id . '&action=confirm') . '">' . tep_image_button('button_delete.gif', IMAGE_DELETE) . '</a> <a href="' . tep_href_link(FILENAME_AFFILIATE_CONTACT, 'selected_box=affiliate&affiliate=' . $aInfo->affiliate_email_address) . '">' . tep_image_button('button_email.gif', IMAGE_EMAIL) . '</a>');
        $contents[] = array('align' => 'center', 'text' => '<a href="' . tep_href_link(FILENAME_AFFILIATE_PAYMENT, tep_get_all_get_params(array('acID')) . 'acID=' . $aInfo->affiliate_id ) . '">' . tep_image_button('button_payment.gif', IMAGE_PAYMENT) . '</a> <a href="' . tep_href_link(FILENAME_AFFILIATE_SALES, tep_get_all_get_params(array('acID')) . 'acID=' . $aInfo->affiliate_id ) . '">' . tep_image_button('button_sales.gif', IMAGE_SALES) . '</a>');
        $affiliate_sales_raw = "select count(*) as count, sum(affiliate_value) as total, sum(affiliate_payment) as payment from " . TABLE_AFFILIATE_SALES . " a left join " . TABLE_ORDERS . " o on (a.affiliate_orders_id=o.orders_id) where o.orders_status >= " . AFFILIATE_PAYMENT_ORDER_MIN_STATUS . " and  affiliate_id = '" . $aInfo->affiliate_id . "'";
        $affiliate_sales_values = tep_db_query($affiliate_sales_raw);
        $affiliate_sales = tep_db_fetch_array($affiliate_sales_values);

        $contents[] = array('text' => '<br>' . TEXT_DATE_ACCOUNT_CREATED . ' ' . format_date($aInfo->date_account_created));
        $contents[] = array('text' => '' . TEXT_DATE_ACCOUNT_LAST_MODIFIED . ' ' . format_date($aInfo->date_account_last_modified));
        $contents[] = array('text' => '' . TEXT_INFO_DATE_LAST_LOGON . ' '  . format_date($aInfo->date_last_logon));
        $contents[] = array('text' => '' . TEXT_INFO_NUMBER_OF_LOGONS . ' ' . $aInfo->number_of_logons);
        $contents[] = array('text' => '' . TEXT_INFO_COMMISSION . ' ' . $aInfo->affiliate_commission_percent . ' %');
        $contents[] = array('text' => '' . TEXT_INFO_COUNTRY . ' ' . $aInfo->countries_name);
        $contents[] = array('text' => '' . TEXT_INFO_NUMBER_OF_SALES . ' ' . $affiliate_sales['count'],'');
        $contents[] = array('text' => '' . TEXT_INFO_SALES_TOTAL . ' ' . $currencies->display_price($affiliate_sales['total'],''));
        $contents[] = array('text' => '' . TEXT_INFO_AFFILIATE_TOTAL . ' ' . $currencies->display_price($affiliate_sales['payment'],''));
      }
      break;
  }

  if ( (tep_not_null($heading)) && (tep_not_null($contents)) ) {
    echo '            <td width="25%" valign="top">' . "\n";

    $box = new box;
    echo $box->infoBox($heading, $contents);

    echo '            </td>' . "\n";
  }
?>
          </tr>
        </table></td>
      </tr>
<?php
  }
?>
    </table></td>
<!-- body_text_eof //-->
  </tr>
</table>
<!-- body_eof //-->

<!-- footer //-->
<?php require(DIR_WS_INCLUDES . 'footer.php'); ?>
<!-- footer_eof //-->
<br>
</body>
</html>
<?php require(DIR_WS_INCLUDES . 'application_bottom.php'); ?>
<script language="javascript">
function do_fetch(id){
command="<?php echo tep_href_link('marketing_affiliate_affiliates.php','command=get_details');?>&id="+id;
//alert(command);
do_get_command(command);
}
   function check_key(e){ 
     var kc=0;
   	  if (window.event)
	    kc=window.event.keyCode;
	  else if (e)
	 	kc=e.which;
	  else
		kc=0;
	  if(kc==13) expand_category(1,'1','search');
	}
function expand_category(id,category,s,sta){
//alert(s); alert(sta);	 
		
		var sta;
		var span_details=document.getElementById("span_details");
 	 	var span_edit=document.getElementById("span_edit");			
		var span_delete=document.getElementById("span_delete");
		if(!sta) sta="";
			
		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(document.new_affiliate && document.new_affiliate.affiliate_id && document.new_affiliate.affiliate_id.value>0)  { 
			var old_ids=document.new_affiliate.affiliate_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.new_affiliate.affiliate_id.value>0 && document.new_affiliate.affiliate_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.new_affiliate.affiliate_id.value=id;			   
			}							
		 
		if(category!=1 && document.new_affiliate && document.new_affiliate.affiliate_id && document.new_affiliate.affiliate_id.value=="") document.new_affiliate.affiliate_id.value=id; 	 	
			if(id>0 && document.new_affiliate.affiliate_id.value>0 && document.new_affiliate.affiliate_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.new_affiliate.affiliate_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 span_move=document.getElementById("span_move");	
 	 		var span_copy=document.getElementById("span_copy");	
			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 ser="";
 	 			       var page=""; 	 			       
 	 			       if(document.getElementById("search") && document.getElementById("search").value!="" && sta=="" && s=='search') {
					   	ser="&keywords="+document.getElementById("search").value;
						id="";
					    }else if(document.getElementById("search") && document.getElementById("search").value!="" && sta=="" && s=='reset'){
					  	 document.getElementById("search").value="";
						}else if(document.getElementById("search") && document.getElementById("search").value=="" && sta=="" && s=='search'){
						 return;
						}else if(document.getElementById("search") && document.getElementById("search").value=="" && sta=="" && s=='reset') id=1;
 	 			        if(id!="") page="&page="+id;
					    command="<?php echo tep_href_link(FILENAME_AFFILIATE,'command=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:
 	 				 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.resource.action_type) document.resource.action_type.value='new'; 	 					
 	 				 command="<?php echo tep_href_link(FILENAME_AFFILIATE,'command=edit');?>"; 	 					 	 					 	 					 	 				 	 		
 	 			break; 	 			
 	 			case 3:
 	 			   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';
 	 			   	  		else 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_AFFILIATE,'command=get_details');?>&id="+id; 	 			 	
 	 			 } 	 			  	 			  	 			
 	 			break;
 	 			case 4:
				
 	 					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...'>"; 	 					
 	 					command="<?php echo tep_href_link(FILENAME_AFFILIATE,'command=edit');?>&id="+id; 	 		 	 					 	 					 	 				 	 		
 	 			break; 	 			
 	 			case 5:	 	 				 	 				 	 		 	 				
 	 					span_delete.style.display="";
 	 					span_edit.style.display=span_details.style.display="none";
 	 					span_delete.innerHTML="<img src='images/24-1.gif' alt='Loading...' title='Loading...'>";
 	 					command="<?php echo tep_href_link(FILENAME_AFFILIATE,'command=delete');?>&id="+id; 	 	 	 					 	 					 	 			
 	 			break; 	
				case 6:
						command="<?php echo tep_href_link(FILENAME_AFFILIATE,'command=mail');?>&id="+id;
				break;			
				case 7:
 	 					if(span_move)span_move.style.display=""; 	 					
						location.href='<?php echo tep_href_link(FILENAME_AFFILIATE_PAYMENT,'acID='); ?>'+id;
				break;		
				case 8:
 	 					if(span_copy)span_copy.style.display=""; 	 					
						location.href='<?php echo tep_href_link(FILENAME_AFFILIATE_SALES,'acID='); ?>'+id;
				break;					
 	 		}
			if(command!="") do_get_command(command);
		}		
 	 }
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");
		 var span_move=document.getElementById("span_move");
		 var span_copy=document.getElementById("span_copy");
		 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_copy && span_copy.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_copy && span_copy.style.display=="none") img_get_src.src=img_src+'template/img_copy.gif';
			    if(img_get_src.src==img_src+'template/img_move.gif') {
					if(span_move && span_move.style.display=="" && eve==1 || eve==2){
					 	img_get_src.src=img_src+'template/img_move_hover.gif';
					}  		   		 	 			 	 			
			    }else if(eve==3 && img_get_src.src==img_src+'template/img_move_hover.gif' && span_move && span_move.style.display=="none") img_get_src.src=img_src+'template/img_move.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_sms.gif') {
					if(span_edit && span_edit.style.display=="" && eve==1 || eve==2){
					 	img_get_src.src=img_src+'template/img_sms_hover.gif';
					}  		   		 	 			 	 			
			    }else if(eve==3 && img_get_src.src==img_src+'template/img_sms_hover.gif' && span_edit )	 img_get_src.src=img_src+'template/img_sms.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';		    		    		     		   	
		  }
		 }		 
	  }	
	  
function do_navigation(cmd,params,affilliate,page,level){

command="<?php echo tep_href_link(FILENAME_AFFILIATE,'command=navigation');?>";
do_get_command(command);

}
</script>
<script>
<?php if($HTTP_GET_VARS['action']=='edit'){?>
do_action();
<?php } if(error==true){?>
	disable('<?php echo $affiliate_payment_type;?>');
<?php }?>	
</script>

<?php
function edit_function($affiliates_id){
$affiliate_query = tep_db_query("select * from " . TABLE_AFFILIATE . " where affiliate_id = '" . (int)$affiliates_id . "'");
			$affiliate = tep_db_fetch_array($affiliate_query);
			$aInfo = new objectInfo($affiliate);?>
	<table border="0" width="100%" cellpadding="0" cellspacing="0">
      <tr>
        <td><?php echo tep_draw_separator('pixel_trans.gif', '1', '10'); ?></td>
      </tr>
      
		<?php tep_content_title_top(CATEGORY_PERSONAL);?>
	  
      <tr>
        <td><?php //echo tep_draw_form('affiliate', FILENAME_AFFILIATE, tep_get_all_get_params(array('action')) . 'action=update', 'post', 'onSubmit="return check_form();"'); ?>
		<table width="100%" border="0" cellspacing="2" cellpadding="2">
<?php
   if (ACCOUNT_GENDER == 'true') {
?>
          <tr>
            <td class="main" width="110"><?php echo ENTRY_GENDER; ?></td>
            <td class="main" width="250">
			<?php 
				if ($error == true) {
				  if ($entry_gender_error == true) {
					echo tep_draw_radio_field('affiliate_gender', 'm', false, $aInfo->affiliate_gender) . '&nbsp;&nbsp;' . MALE . '&nbsp;&nbsp;' . tep_draw_radio_field('affiliate_gender', 'f', false, $aInfo->affiliate_gender) . '&nbsp;&nbsp;' . FEMALE . '&nbsp;' . ENTRY_GENDER_ERROR;
					echo tep_draw_hidden_field('genderflag',"1");
				  } else {
					echo ($aInfo->affiliate_gender == 'm') ? MALE : FEMALE;
					echo tep_draw_hidden_field('affiliate_gender',$aInfo->affiliate_gender);
					echo tep_draw_hidden_field('genderflag',"0");
				  }
				} else {
				  echo tep_draw_radio_field('affiliate_genders', 'm', false, $aInfo->affiliate_gender,'id=affiliate_genders') . '&nbsp;&nbsp;' . MALE . '&nbsp;&nbsp;' . tep_draw_radio_field('affiliate_genders', 'f', false, $aInfo->affiliate_gender,'id=affiliate_genders') . '&nbsp;&nbsp;' . FEMALE ;
				  echo tep_draw_hidden_field('genderflag',"1");
				  echo tep_draw_hidden_field('affiliate_gender');
				}
			?><span id="01"><?php echo ENTRY_GENDER_TEXT; ?></span></td>
			<td colspan="2"></td>
          </tr>
<?php
   }
?>
          <tr>
            <td class="main" width="110"><?php echo ENTRY_FIRST_NAME; ?></td>
            <td class="main" width="250"><?php 
			  if ($error == true) {
				if ($entry_firstname_error == true) {
				  echo tep_draw_input_field('affiliate_firstname', $aInfo->affiliate_firstname, 'maxlength="32"') . '&nbsp;' . ENTRY_FIRST_NAME_ERROR;
				} else {
				  echo $aInfo->affiliate_firstname . tep_draw_hidden_field('affiliate_firstname');
				}
			  } else {
				echo tep_draw_input_field('affiliate_firstname', $aInfo->affiliate_firstname, 'maxlength="32"');
			  }?>
			<span id="02"><?php echo ENTRY_FIRST_NAME_TEXT; ?></span>
			</td>
			<?php if(ACCOUNT_USERNAME =='true'){ ?>
			<td class="main" width="110"><?php echo ENTRY_USERNAME; ?></td>
			<td class="main" ><?php 
				if ($error == true) {
				  if ($entry_username_error == true) {
					echo tep_draw_input_field('affiliate_username', $aInfo->affiliate_username, 'maxlength="20"') . '&nbsp;' . ENTRY_USERNAME_ERROR_EXISTS;
				  } else {
					echo $aInfo->affiliate_username . tep_draw_hidden_field('affiliate_username');
				  }
				} else {
				  echo tep_draw_input_field('affiliate_username', $aInfo->affiliate_username, 'maxlength="20"') ;
				}?>	<span id="05"><?php echo ENTRY_USERNAME_TEXT  ?></span>
				</td>
				<?php }?>
          </tr>
          <tr>
            <td class="main" width="110"><?php echo ENTRY_LAST_NAME; ?></td>
            <td class="main" width="250"><?php 
			  if ($error == true) {
				if ($entry_lastname_error == true) {
				  echo tep_draw_input_field('affiliate_lastname', $aInfo->affiliate_lastname, 'maxlength="32"') . '&nbsp;' . ENTRY_LAST_NAME_ERROR;
				} else {
				  echo $aInfo->affiliate_lastname . tep_draw_hidden_field('affiliate_lastname');
				}
			  } else {
				echo tep_draw_input_field('affiliate_lastname', $aInfo->affiliate_lastname, 'maxlength="32"')  . '&nbsp;' . ENTRY_LAST_NAME_TEXT;
			  }?>
			  <span id="03" style="display:none"></span></td>
			  <td class="main" width="110"><?php echo ENTRY_EMAIL_ADDRESS; ?></td>
			  <td class="main" width="250"><?php 
					$con_email=false;
						   $er=ENTRY_EMAIL_ADDRESS_ERROR;
					  if ($error == true) {
						if ($entry_email_address_error == true) {
						  echo tep_draw_input_field('affiliate_email_address', $aInfo->affiliate_email_address, 'maxlength="96"') . '&nbsp;' . $er;
						} elseif ($entry_email_address_check_error == true) {
						  echo tep_draw_input_field('affiliate_email_address', $aInfo->affiliate_email_address, 'maxlength="96"') . '&nbsp;' . ENTRY_EMAIL_ADDRESS_CHECK_ERROR;
						} elseif ($entry_email_address_exists == true) {
						  echo tep_draw_input_field('affiliate_email_address', $aInfo->affiliate_email_address, 'maxlength="96"') . '&nbsp;' . ENTRY_EMAIL_ADDRESS_ERROR_EXISTS;
						} else {
						  echo $affiliate_email_address . tep_draw_hidden_field('affiliate_email_address');
						  $con_email=true;	
						}
					  } else {
						echo tep_draw_input_field('affiliate_email_address', $aInfo->affiliate_email_address, 'maxlength="96"') ;
					  }	 ?> <span id="06"><?php echo ENTRY_EMAIL_ADDRESS_TEXT;?></span></td>
          </tr>
          <tr>
              <td class="main" width="110" valign="top"><?php echo ENTRY_DOB; ?></td>
              <td class="main" width="250"><?php 
					if ($error == true) {
					  if ($entry_date_of_birth_error == true) {
						echo tep_draw_input_field('affiliate_dob', $aInfo->affiliate_dob, 'maxlength="10"') . '&nbsp;' . ENTRY_EVENT_DATE_OF_BIRTH_ERROR;
					  } else {
						echo $aInfo->affiliate_dob . tep_draw_hidden_field('affiliate_dob');
					  }
					} else {
					  echo tep_draw_input_field('affiliate_dob', format_date($aInfo->affiliate_dob), 'maxlength="10"')  . '<br>' . ENTRY_EVENT_DATE_OF_BIRTH_TEXT;
					}?><span id="04" style="display:none"></span>
				</td>
				
				<td class="main" width="110" valign="top"><?php echo ENTRY_PASSWORD; ?></td>
				<td class="main" valign="top"><?php
				  if ($error == true) {
					if ($entry_password_error == true) {
					  echo tep_draw_input_field('affiliate_password', '*****', 'maxlength="40"') . '&nbsp;' . ENTRY_FIRST_NAME_ERROR;
					} else {
					  echo PASSWORD_HIDDEN . tep_draw_hidden_field('affiliate_password');
					}
				  } else {
					echo tep_draw_input_field('affiliate_password', '*****', 'maxlength="40" onfocus="this.value=\'\'"; onblur="if (this.value==\'\') this.value=\'*****\';"', false);
				  }
			 ?></td>
          </tr>
        </table></td>
      </tr>
      <tr>
        <td colspan="4"><?php echo tep_draw_separator('pixel_trans.gif', '1', '10'); ?></td>
      </tr>
<!--	  <tr>
	 	<td colspan="4"><?php //tep_content_title_bottom();?></td>
	  </tr>
-->	  
<?php tep_content_title_bottom();

   if (AFFILATE_INDIVIDUAL_PERCENTAGE == 'true') {
?><?php tep_content_title_top(CATEGORY_COMMISSION); ?> 
<!--	  <tr>
	 	 <td colspan="4"><?php// tep_content_title_top(CATEGORY_COMMISSION);?></td>
	  </tr>	 
-->    <tr>
        <td><table border="0" cellspacing="2" cellpadding="2" width="100%">
          <tr>
            <td class="main" width="110"><?php echo ENTRY_AFFILIATE_COMMISSION; ?></td>
            <td class="main" width="250"><?php 
				  if ($error == true) {
					if ($entry_commission_error == true) {
					  echo tep_draw_input_field('affiliate_commission_percent', $aInfo->affiliate_commission_percent, 'maxlength="64"') . '&nbsp;' . ENTRY_COMMISSION_ERROR;
					} else {
					  echo $aInfo->affiliate_commission_percent . tep_draw_hidden_field('affiliate_commission_percent');
					}
				  } else {
					echo tep_draw_input_field('affiliate_commission_percent', $aInfo->affiliate_commission_percent, 'maxlength="64"')  . '&nbsp;' ;
				  }
			//echo tep_draw_input_field('affiliate_commission_percent', $aInfo->affiliate_commission_percent, 'maxlength="5"'); ?></td>
            <td class="main" width="250">&nbsp;</td>
			<td class="main" width="110">&nbsp;</td>
		  </tr>
        </table></td>
      </tr>
      <tr>
        <td colspan="4"><?php echo tep_draw_separator('pixel_trans.gif', '1', '10'); ?></td>
      </tr>
<!--  <tr>
	  	<td colspan="4"><?php //tep_content_title_bottom();?></td>
	  </tr>	
--><?php tep_content_title_bottom();
    }
  if (ACCOUNT_COMPANY == 'true') {
?><?php tep_content_title_top(CATEGORY_COMPANY);?>
<!--      <tr>
        <td colspan="4"><?php //echo tep_draw_separator('pixel_trans.gif', '1', '10'); ?></td>
      </tr>
	  <tr>
		<td colspan="4"><?php //tep_content_title_top(CATEGORY_COMPANY);?></td>
      </tr>
-->    <tr>
        <td><table width="100%" border="0" cellspacing="2" cellpadding="2">
          <tr>
            <td class="main" width="110"><?php echo ENTRY_COMPANY; ?></td>
            <td class="main" width="250"><?php 
				  if ($error == true) {
					if ($entry_company_error == true) {
					  echo tep_draw_input_field('affiliate_company', $aInfo->affiliate_company, 'maxlength="64"') . '&nbsp;' . ENTRY_COMPANY_ERROR;
					} else {
					  echo $aInfo->affiliate_company . tep_draw_hidden_field('affiliate_company');
					}
				  } else {
					echo tep_draw_input_field('affiliate_company', $aInfo->affiliate_company, 'maxlength="64"')  . '&nbsp;' ;
				  }
			?></td>
			<td class="main" width="120"><?php echo ENTRY_AFFILIATE_COMPANY_TAXID; ?></td>
			<td class="main" width="250"><?php 
				  if ($error == true) {
					if ($entry_company_taxid_error == true) {
					  echo tep_draw_input_field('affiliate_company_taxid', $aInfo->affiliate_company_taxid, 'maxlength="64"') . '&nbsp;' . ENTRY_TAX_ERROR;
					} else {
					  echo $aInfo->affiliate_company_taxid . tep_draw_hidden_field('affiliate_company_taxid');
					}
				  } else {
					echo tep_draw_input_field('affiliate_company_taxid', $aInfo->affiliate_company_taxid, 'maxlength="64"')  . '&nbsp;' ;
				  }
			 ?></td>
          </tr>
        </table></td>
      </tr>
      <tr>
        <td colspan="4"><?php echo tep_draw_separator('pixel_trans.gif', '1', '10'); ?></td>
      </tr>
<!--	  <tr>
	  	<td colspan="4"><?php //tep_content_title_bottom();?></td>
	  </tr>	
--><?php tep_content_title_bottom();
			
		} if((AFFILIATE_USE_CHECK == 'true') || (AFFILIATE_USE_PAYPAL == 'true') || (AFFILIATE_USE_BANK == 'true')){?>
      <tr>
        <td colspan="4"><?php echo tep_draw_separator('pixel_trans.gif', '1', '10'); ?></td>
      </tr>
      <tr>
	  	<td colspan="4"><?php tep_content_title_top(CATEGORY_PAYMENT_DETAILS);?></td>
	  </tr>	
      <tr>
        <td><table width="100%" border="0" cellspacing="2" cellpadding="2">
		<tr>
			<td class="main" width="160">&nbsp;<?php echo ENTRY_PAYMENT;?></td>
			<td width="350">
				<table cellpadding="2" cellspacing="0" border="0" >
					<tr>
						<?php 
								if ($error == true) {
								  	echo '<td class="main">' ;
									if($affiliate_payment_type=='C')
										echo 'Check';
									else if($affiliate_payment_type =='P'	)
										echo 'Paypal';
									else if($affiliate_payment_type == 'D'	)
										echo 'Direct Deposit';
									echo tep_draw_hidden_field('affiliate_payment') . '</td>';
								} else { 
									if (AFFILIATE_USE_CHECK == 'true') { 
										echo '<td class="main">' . tep_draw_radio_field('affiliate_payment','C',($aInfo->affiliate_payment_type=='C')?true:false,'','onClick="javascript:do_action();"') . ENTRY_AFFILIATE_CHECK . '</td>'; 
									}
									if (AFFILIATE_USE_PAYPAL == 'true') {
										echo '<td class="main">' . tep_draw_radio_field('affiliate_payment','P',($aInfo->affiliate_payment_type=='P')?true:false,'','onClick="javascript:do_action();"') .ENTRY_AFFILIATE_PAYPAL . '</td>'; 
									}	
									if (AFFILIATE_USE_BANK == 'true') {
										echo '<td class="main">' . tep_draw_radio_field('affiliate_payment','D',($aInfo->affiliate_payment_type=='D')?true:false,'','onClick="javascript:do_action();"') . ENTRY_AFFILIATE_BANK . '</td>'; 
									}
								}
								echo tep_draw_hidden_field('affiliate_payments');
						?>
						<td width="5"></td>
					</tr>	
				</table>
			</td><td colspan="4">&nbsp;</td>
		</tr>		
<?php // if (AFFILIATE_USE_CHECK == 'true') {
?>
          <tr id="affiliate_cheque" style="display:none">
            <td class="main" width="125"><?php echo ENTRY_AFFILIATE_PAYMENT_CHECK; ?></td>
            <td class="main" ><?php 
				  if ($error == true) {
					if ($entry_payment_check_error == true) {
					  echo tep_draw_input_field('affiliate_payment_check', $aInfo->affiliate_payment_check, 'maxlength="64"') . '&nbsp;' . ENTRY_PAYMENT_CHECK_ERROR;
					} else {
					  echo $aInfo->affiliate_payment_check . tep_draw_hidden_field('affiliate_payment_check');
					}
				  } else {
					echo tep_draw_input_field('affiliate_payment_check', $aInfo->affiliate_payment_check, 'maxlength="64"')  . '&nbsp;' .	ENTRY_PAYMENT_CHECK_TEXT ;
				  }
			 ?></td>
			<td class="main" id="swift_code"><?php echo ENTRY_AFFILIATE_PAYMENT_BANK_SWIFT_CODE . tep_draw_separator('pixel_trans.gif',45,10); 
				  if ($error == true) {
					if ($entry_payment_bank_swift_code_error == true) {
					  echo tep_draw_input_field('affiliate_payment_bank_swift_code', $aInfo->affiliate_payment_bank_swift_code, 'maxlength="64"') . '&nbsp;' . ENTRY_PAYMENT_BANK_SWIFT_CODE_ERROR;
					} else {
					  echo $aInfo->affiliate_payment_bank_swift_code . tep_draw_hidden_field('affiliate_payment_bank_swift_code');
					}
				  } else {
					echo tep_draw_input_field('affiliate_payment_bank_swift_code', $aInfo->affiliate_payment_bank_swift_code, 'maxlength="64"')  . '&nbsp;' .ENTRY_PAYMENT_BANK_SWIFT_CODE_TEXT ;
				  }
			 ?></td>
			 <td class="main"></td>
          </tr>
<?php 
 // }
  if (AFFILIATE_USE_PAYPAL == 'true') {
?>
          <tr id="affiliate_paypal" style="display:none">
            <td class="main" width="125"><?php echo ENTRY_AFFILIATE_PAYMENT_PAYPAL; ?></td>
            <td class="main"><?php 
				  if ($error == true) {
					if ($entry_payment_paypal_error == true) {
					  echo tep_draw_input_field('affiliate_payment_paypal', $aInfo->affiliate_payment_paypal, 'maxlength="64"') . '&nbsp;' . ENTRY_EMAIL_ADDRESS_CHECK_ERROR;
					} else {
					  echo $aInfo->affiliate_payment_paypal . tep_draw_hidden_field('affiliate_payment_paypal');
					}
				  } else {
					echo tep_draw_input_field('affiliate_payment_paypal', $aInfo->affiliate_payment_paypal, 'maxlength="64"');
				  }
			 ?>
			<span id="14"><?php echo ENTRY_PAYMENT_PAYPAL_TEXT;  ?></span></td>
			<td>&nbsp;</td>
			
          </tr>
<?php
  }
  if (AFFILIATE_USE_BANK == 'true') {
?>
	<tr  id="affiliate_bank" style="display:none">
		<td colspan="2"><table cellpadding="0" cellspacing="2" border="0" width="100%">
          <tr>
            <td class="main" width="160"><?php echo ENTRY_AFFILIATE_PAYMENT_BANK_NAME; ?></td>
            <td class="main"><?php 
				  if ($error == true) {
					if ($entry_payment_bank_name_error == true) {
					  echo tep_draw_input_field('affiliate_payment_bank_name', $aInfo->affiliate_payment_bank_name, 'maxlength="64"') . '&nbsp;' . ENTRY_PAYMENT_BANK_NAME_ERROR;
					} else {
					  echo $aInfo->affiliate_payment_bank_name . tep_draw_hidden_field('affiliate_payment_bank_name');
					}
				  } else {
					echo tep_draw_input_field('affiliate_payment_bank_name', $aInfo->affiliate_payment_bank_name, 'maxlength="64"')  . '&nbsp;' .ENTRY_PAYMENT_BANK_NAME_TEXT ;
				  }
				  
				
			//echo tep_draw_input_field('affiliate_payment_bank_name', $aInfo->affiliate_payment_bank_name, 'maxlength="64"'); ?></td>
          </tr>
          <tr>
            <td class="main" width="125"><?php echo ENTRY_AFFILIATE_PAYMENT_BANK_BRANCH_NUMBER; ?></td>
            <td class="main"><?php 
				  if ($error == true) {
					if ($entry_payment_bank_branch_number_error == true) {
					  echo tep_draw_input_field('affiliate_payment_bank_branch_number', $aInfo->affiliate_payment_bank_branch_number, 'maxlength="64"') . '&nbsp;' . ENTRY_PAYMENT_BANK_BRANCH_NUMBER_ERROR;
					} else {
					  echo $aInfo->affiliate_payment_bank_branch_number . tep_draw_hidden_field('affiliate_payment_bank_branch_number');
					}
				  } else {
					echo tep_draw_input_field('affiliate_payment_bank_branch_number', $aInfo->affiliate_payment_bank_branch_number, 'maxlength="64"')  . '&nbsp;' .ENTRY_PAYMENT_BANK_BRANCH_NUMBER_TEXT ;
				  }
			//echo tep_draw_input_field('affiliate_payment_bank_branch_number', $aInfo->affiliate_payment_bank_branch_number, 'maxlength="64"'); ?></td>
          </tr>
          
		   </table>
		 </td>
		 <td>
		 	<table border="0" cellpadding="0" cellspacing="2" width="100%">
			<tr>
		 		<td class="main" width="125"><?php echo ENTRY_AFFILIATE_PAYMENT_BANK_ACCOUNT_NAME; ?></td>
		 		<td class="main"><?php 
				  if ($error == true) {
					if ($entry_payment_bank_account_name_error == true) {
					  echo tep_draw_input_field('affiliate_payment_bank_account_name', $aInfo->affiliate_payment_bank_account_name, 'maxlength="64"') . '&nbsp;' . ENTRY_PAYMENT_BANK_ACCOUNT_NAME_ERROR;
					} else {
					  echo $aInfo->affiliate_payment_bank_account_name . tep_draw_hidden_field('affiliate_payment_bank_account_name');
					}
				  } else {
					echo tep_draw_input_field('affiliate_payment_bank_account_name', $aInfo->affiliate_payment_bank_account_name, 'maxlength="64"')  . '&nbsp;' .ENTRY_PAYMENT_BANK_ACCOUNT_NAME_TEXT ;
				  }
			?></td>
			</tr>
			<tr height="2"></tr>
			<tr>
				<td class="main" width="125"><?php echo ENTRY_AFFILIATE_PAYMENT_BANK_ACCOUNT_NUMBER; ?></td>
				<td class="main"><?php 
				  if ($error == true) {
					if ($entry_payment_bank_account_number_error == true) {
					  echo tep_draw_input_field('affiliate_payment_bank_account_number', $aInfo->affiliate_payment_bank_account_number, 'maxlength="64"') . '&nbsp;' . ENTRY_PAYMENT_BANK_ACCOUNT_NUMBER_ERROR;
					} else {
					  echo $aInfo->affiliate_payment_bank_account_number . tep_draw_hidden_field('affiliate_payment_bank_account_number');
					}
				  } else {
					echo tep_draw_input_field('affiliate_payment_bank_account_number', $aInfo->affiliate_payment_bank_account_number, 'maxlength="64"')  . '&nbsp;'. ENTRY_PAYMENT_BANK_ACCOUNT_NUMBER_TEXT;
				  }
			 ?></td>	
			</tr></table></td>	
		 </tr> 
<?php
  }
?>
        </table></td>
      </tr>
	   <?php }?>
      <tr>
        <td><?php echo tep_draw_separator('pixel_trans.gif', '1', '10'); ?></td>
      </tr>
	  <?php tep_content_title_bottom();?>
	  <?php tep_content_title_top(CATEGORY_ADDRESS);?>
      <tr>
        <td ><table width="100%" border="0" cellspacing="2" cellpadding="2">
          <tr>
            <td class="main" width="122"><?php echo ENTRY_STREET_ADDRESS; ?></td>
            <td class="main" width="250"><?php 
				  if ($error == true) {
					if ($entry_street_address_error == true) {
					  echo tep_draw_input_field('affiliate_street_address', $aInfo->affiliate_street_address, 'maxlength="64"') . '&nbsp;' . ENTRY_STREET_ADDRESS_ERROR;
					} else {
					  echo $aInfo->affiliate_street_address . tep_draw_hidden_field('affiliate_street_address');
					}
				  } else {
					echo tep_draw_input_field('affiliate_street_address', $aInfo->affiliate_street_address, 'maxlength="64"');
				  }
			 ?><span id="07"><?php echo ENTRY_STREET_ADDRESS_TEXT; ?></span></td>
			 <td class="main" width="122"><?php echo ENTRY_POST_CODE; ?></td>
			 <td class="main" width="250"><?php 
				  if ($error == true) {
					if ($entry_post_code_error == true) {
					  echo tep_draw_input_field('affiliate_postcode', $aInfo->affiliate_postcode, 'maxlength="8"') . '&nbsp;' . ENTRY_POST_CODE_ERROR;
					} else {
					  echo $aInfo->affiliate_postcode . tep_draw_hidden_field('affiliate_postcode');
					}
				  } else {
					echo tep_draw_input_field('affiliate_postcode', $aInfo->affiliate_postcode, 'maxlength="8"');
				  }
			 ?><span id="08"><?php echo ENTRY_POST_CODE_TEXT; ?></span></td>
          </tr>
<?php
  if (ACCOUNT_SUBURB == 'true') {
?>
          <tr>
            <td class="main" width="122"><?php echo ENTRY_SUBURB; ?></td>
            <td class="main" width="250"><?php 
				if ($error == true) {
				  if ($entry_suburb_error == true) {
					echo tep_draw_input_field('affiliate_suburb', $aInfo->affiliate_suburb, 'maxlength="32"') . '&nbsp;' . ENTRY_SUBURB_ERROR;
				  } else {
					echo $aInfo->affiliate_suburb . tep_draw_hidden_field('affiliate_suburb');
				  }
				} else {
				  echo tep_draw_input_field('affiliate_suburb', $aInfo->affiliate_suburb, 'maxlength="32"')  . '&nbsp;' . ENTRY_SUBURB_TEXT;
				}
			 ?></td>
			  <td class="main" width="122"><?php echo ENTRY_COUNTRY; ?></td>
            <td class="main" width="250"><?php 
				  if ($error == true) {
					if ($entry_country_error == true) {
					  echo tep_draw_pull_down_menu('affiliate_country_id', tep_get_countries(), $aInfo->affiliate_country_id,'onchange="javascript:show_state();"') . '&nbsp;' . ENTRY_COUNTRY_ERROR;
					} else {
					  echo tep_get_country_name($aInfo->affiliate_country_id) . tep_draw_hidden_field('affiliate_country_id');
					}
				  } else {
					echo tep_draw_pull_down_menu('affiliate_country_id', tep_get_countries(), $aInfo->affiliate_country_id,'onchange="javascript:show_state();"')  . '&nbsp;' . ENTRY_COUNTRY_TEXT;
				  }
			 ?></td>
          </tr>
<?php
  }
?>
          <tr>
            <td class="main" width="122"><?php echo ENTRY_CITY; ?></td>
            <td class="main" width="250"><?php 
				  if ($error == true) {
					if ($entry_city_error == true) {
					  echo tep_draw_input_field('affiliate_city', $aInfo->affiliate_city, 'maxlength="32"') . '&nbsp;' . ENTRY_CITY_ERROR;
					} else {
					  echo $aInfo->affiliate_city . tep_draw_hidden_field('affiliate_city');
					}
				  } else {
					echo tep_draw_input_field('affiliate_city', $aInfo->affiliate_city, 'maxlength="32"')  . '&nbsp;' . ENTRY_CITY_TEXT;
				  }
			 ?><span id="09" style="display:none"></span></td>
			 <?php
    if (ACCOUNT_STATE == 'true') {?>

            <td class="main" width="122"><?php echo ENTRY_STATE; ?></td>
            <td class="main" width="250"><?php              
              $zones_query = tep_db_query("select zone_id,zone_name from " . TABLE_ZONES . " where zone_country_id = '" . tep_db_input($aInfo->affiliate_country_id) . "' order by zone_name"); 	   		   	   			
 	  		  while ($zones_values = tep_db_fetch_array($zones_query)) { 
 		      	$zones_array[]=array('id'=>$zones_values['zone_id'],'text'=>$zones_values['zone_name']);
		   	  }			   	  
   			 $affiliate_state = ($aInfo->affiliate_state1)?$aInfo->affiliate_state1:$aInfo->affiliate_zone_id;
			  $state = tep_get_zone_name($aInfo->affiliate_country_id, $aInfo->affiliate_zone_id,$affiliate_state);
			if ($error == true) {
				  if ($entry_state_error == true) {
					if ($entry_state_has_zones == true) {                     
					  echo tep_draw_input_field('affiliate_state1','','id="affiliate_state1"') . '&nbsp;' . ENTRY_STATE_ERROR;
					  echo tep_draw_pull_down_menu('affiliate_zone_id', $zones_array,'','id="affiliate_zone_id" style="display:none"').(sizeof($zones_array))?ENTRY_STATE_ERROR:'';
					} else {
					  echo tep_draw_input_field('affiliate_zone_id') . '&nbsp;' . ENTRY_STATE_ERROR;
					}
				  } else {
					echo $state . tep_draw_hidden_field('affiliate_zone_id') . tep_draw_hidden_field('affiliate_state1');
				  }
				} else {                             
				  $state=$affiliate['affiliate_state'];
				  if(!$state) $state = tep_get_zone_name($affiliate['affiliate_country_id'], $affiliate['affiliate_zone_id'],'');      
				  echo tep_draw_input_field('affiliate_state1',$state,'id="affiliate_state1"'.((count($zones_array)>0)?' style="display:none"':''));
				  echo tep_draw_pull_down_menu('affiliate_zone_id', $zones_array,$state,'id="affiliate_zone_id"'.((count($zones_array)<=0)?' style="display:none"':'')); 
				}			
            ?><span id="10" style="display:none"></span></td>
<?php
    }
?>
          </tr>
        </table></td>
      </tr>
	  <?php tep_content_title_bottom();?>
      <tr>
        <td><?php echo tep_draw_separator('pixel_trans.gif', '1', '10'); ?></td>
      </tr>
	  <?php tep_content_title_top(CATEGORY_CONTACT);?>
      <tr>
        <td><table width="100%" border="0" cellspacing="2" cellpadding="2">
          <tr>
            <td class="main" width="110"><?php echo ENTRY_TELEPHONE_NUMBER; ?></td>
            <td class="main" width="250"><?php 
			  if ($error == true) {
				if ($entry_telephone_error == true) {
				  echo tep_draw_input_field('affiliate_telephone', $aInfo->affiliate_telephone, 'maxlength="32"') . '&nbsp;' . ENTRY_TELEPHONE_NUMBER_ERROR;
				} else {
				  echo $aInfo->affiliate_telephone . tep_draw_hidden_field('affiliate_telephone');
				}
			  } else {
				echo tep_draw_input_field('affiliate_telephone', $aInfo->affiliate_telephone, 'maxlength="32"')  . '&nbsp;' ;
			  }
			?><span id="11" style="display:none"></span></td>
			<td class="main" width="120"><?php echo ENTRY_FAX_NUMBER; ?></td>
            <td class="main" width="250"><?php 
			  if ($error == true) {
				if ($entry_mobile_error == true) {
				  echo tep_draw_input_field('affiliate_fax', $aInfo->affiliate_fax, 'maxlength="32"') . '&nbsp;' . ENTRY_FAX_ERROR;
				} else {
				  echo $aInfo->affiliate_fax . tep_draw_hidden_field('affiliate_fax');
				}
			  } else {
				echo tep_draw_input_field('affiliate_fax', $aInfo->affiliate_fax, 'maxlength="32"', false) . '&nbsp;' ;
			  }
			 ?></td>
          </tr>
            <td class="main" width="110"><?php echo ENTRY_AFFILIATE_HOMEPAGE; ?></td>
            <td class="main" colspan="3"><?php 
				if ($error == true) {
					if ($entry_homepage_error == true) {
					  echo tep_draw_input_field('affiliate_homepage') . '&nbsp;' . ENTRY_AFFILIATE_HOMEPAGE_ERROR;
					} else {
					  echo $aInfo->affiliate_homepage . tep_draw_hidden_field('affiliate_homepage');
					}
				  } else {
					echo tep_draw_input_field('affiliate_homepage', $aInfo->affiliate_homepage,'size=35');
 				 }	?><span id="13"><?php echo ENTRY_AFFILIATE_HOMEPAGE_TEXT; ?></span> </td>
          </tr>
        </table></td>
      </tr>
	  <?php tep_content_title_bottom();?>
      <tr>
        <td><?php echo tep_draw_separator('pixel_trans.gif', '1', '10'); ?></td>
      </tr>
	  <tr> 
	  <td><table cellpadding="0" cellspacing="0" border="0" width="100%">	  	
	   	<tr align="right"><td colspan="10" width='1200' align='right'><input type='image' src='images/template/img_savel.gif' alt='save' title='save' border='0'>&nbsp;&nbsp;<?php if($affiliates_id){ ;?><a href='javascript:expand_category(<?php echo $affiliates_id;?>,3)'><img src='images/template/img_closel.gif' alt='close' title='close' border='0'></a><?php } ?>&nbsp;&nbsp;</td></tr>	   
     </table>
    </td>
  </tr>
      
<?php
  
}
function get_default_details($affiliates_id){
$details_query = tep_db_query("select affiliate_id,affiliate_firstname,affiliate_lastname,affiliate_date_account_created,
		affiliate_date_account_last_modified,affiliate_date_of_last_logon,affiliate_number_of_logons,affiliate_commission_percent,affiliate_homepage from "  . TABLE_AFFILIATE . " where affiliate_id=" . (int)$affiliates_id);
		 if(tep_db_num_rows($details_query)>0){
		 	$affiliate = tep_db_fetch_array($details_query);
			while(list($key,$vals)=each($affiliate)){						
			 	if(($key=='affiliate_date_account_created') || ($key=='affiliate_date_account_last_modified') || ($key=='affiliate_date_of_last_logon') )
					$vals=format_date($vals);													
				if($key=='affiliate_commission_percent'){
					if($vals < AFFILIATE_PERCENT)   
					$vals =  AFFILIATE_PERCENT ;
					
					$vals = number_format($vals,2,'.',2).'&nbsp;%';
					}
				$str_vals.=$vals."^";	
			}
		 }else $str_vals = 'No Record Found';
		  echo 'get_details'.$str_vals;   
}
?>