<?php

/*

osCommerce, Open Source E-Commerce Solutions 
http://www.oscommerce.com 

Copyright (c) 2003 osCommerce 

osCommRes, Services Online 
http://www.oscommres.com 
Copyright (c) 2005 osCommRes 

Freeway eCommerce 
http://www.zac-ware.com/freeway 
Copyright (c) 2007 ZacWare

Released under the GNU General Public License
*/ 
// Set flag that this is a parent file
	define( '_FEXEC', 1 );
	require('includes/application_top.php');
	require('includes/classes/split_page_results_event.php');	
		
	if(isset($HTTP_GET_VARS['customers_page'])){
		global $customers_page;
		$page_no=isset($HTTP_GET_VARS['customers_page'])?(int)$HTTP_GET_VARS['customers_page']:'';
		$customers_page=ceil($page_no/MAX_DISPLAY_SEARCH_RESULTS);		
		}
	require(DIR_WS_LANGUAGES . $language . '/' . FILENAME_CREATE_ACCOUNT); 
	require(DIR_WS_LANGUAGES . $language . '/' . FILENAME_MAIL);
	$command=isset($HTTP_GET_VARS['command'])?tep_db_prepare_input($HTTP_GET_VARS['command']):'';
	$country=isset($HTTP_GET_VARS['country_id'])?(int)$HTTP_GET_VARS['country_id']:0;
	$country=isset($HTTP_GET_VARS['country_id'])?(int)$HTTP_GET_VARS['country_id']:0; 
	$zone=isset($HTTP_GET_VARS['zone'])?(int)$HTTP_GET_VARS['zone']:0;
	$content=""; 
	//ajax start
	if($command=='edit_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)."^".substr($zone_name,0,-1)."^".$zone;    
	    echo $content; 
		exit;
	}  
 	//ajax end
	
	 //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 
	unset($HTTP_SESSION_VARS['ajax_flag']);
	if($command!=''){
	$customers_id=isset($HTTP_GET_VARS['customers_id'])?(int)$HTTP_GET_VARS['customers_id']:'';
		switch($command){
			case 'customers_page_navigation':
				global $customers_page;
				$customers_page=isset($HTTP_GET_VARS['customers_page'])?(int)$HTTP_GET_VARS['customers_page']:'';
				$customers_search=isset($HTTP_GET_VARS['customers_search'])?tep_db_prepare_input($HTTP_GET_VARS['customers_search']):'';
				//echo 'customers_page_navigation^^';
					//if($customers_search==''){
						echo 'customers_page_navigation^^';
						echo load_customer();
			//		}
				/*	else {
						echo 'search_customers^^';
						echo load_customer($customers_search);
						echo '<div align="right"><a href="javascript: reset_search();">'.tep_image_button('button_reset.gif', IMAGE_RESET).'</a></div>';
					}
				*/	
				break;
			case 'reload_customers'	:
				$customers_page=isset($HTTP_GET_VARS['customers_page'])?(int)$HTTP_GET_VARS['customers_page']:'';
				$customers_id=isset($HTTP_GET_VARS['customers_id'])?(int)$HTTP_GET_VARS['customers_id']:'';
				echo 'reload_customers^^';
				echo load_customer() . '^^' . $customers_id;
			break;
			case 'load_customers_details':
				echo 'load_customers_details^^'.$customers_id.'^^';
				echo load_customers_details($customers_id);
				if($HTTP_GET_VARS['return']){
					echo "^^" . tep_db_prepare_input($HTTP_GET_VARS['return']) . "^^" . tep_db_prepare_input($HTTP_GET_VARS['type']) . "^^" . tep_db_prepare_input($HTTP_GET_VARS['mPath']). "^^" . (int)$HTTP_GET_VARS['page'];
				}
				break;
			case 'edit_customer':
				echo 'edit_customer^^'.$customers_id.'^^';
				echo edit_customer($customers_id);
				break;
			case 'save_edit_customer':
				$status=update_customer($customers_id);
				if($status=='success'){
					echo 'load_customers_details^^'.$customers_id.'^^';
					echo load_customers_details($customers_id);
				}else {
					echo 'save_failure^^'.$customers_id.'^^'.substr($status,7);
					echo load_customers_details($customers_id);
				}
				break;
			case 'block_customer':
				$blocked_status=isset($HTTP_GET_VARS['blocked_status'])?tep_db_prepare_input($HTTP_GET_VARS['blocked_status']):'';
				tep_db_query('update '.TABLE_CUSTOMERS." set is_blocked='$blocked_status' where customers_id='$customers_id' ");
				echo 'load_customers_details^^'.$customers_id.'^^';
				echo load_customers_details($customers_id);
				break;
			case 'new_customer':
				echo 'new_customer^^';
				echo new_customer();
				break;
			case 'save_new_customer':
				$customers_id=save_new_customer();
					if (isset($HTTP_POST_VARS["create_order"])){
					echo 'create_order^^';
					echo tep_href_link(FILENAME_CREATE_ORDER_PROCESS, 'customer=' . $customers_id . '&param_1=' . tep_db_prepare_input($HTTP_GET_VARS["param_1"]) . '&param_2=' . tep_db_prepare_input($HTTP_GET_VARS["param_2"]) . '&check=1','SSL');
					} else {
					echo 'load_customers^^';
					echo load_customer();
					}
				break;
			case 'delete_customer':
				$reviews_query = tep_db_query("select count(*) as number_of_reviews from " . TABLE_REVIEWS . " where customers_id = '" . (int)$customers_id . "'");
				$reviews = tep_db_fetch_array($reviews_query);	
				$child_query=tep_db_query("SELECT count(*) as total_count from " . TABLE_ORDERS . " where customers_id='" . (int)$customers_id . "'");
      			$child_count=tep_db_fetch_array($child_query);
      			if (((int)$child_count['total_count'])<=0){
				echo 'delete_confirm^^'.$customers_id.'^^'.TEXT_DELETE_INTRO.'<br>'.tep_draw_checkbox_field('delete_reviews', 'on', true).sprintf(TEXT_DELETE_REVIEWS, $reviews['number_of_reviews']);
				}else{
				echo 'delete_denied^^'.TEXT_INFO_CHILD_COUNT;
				}
				break;
			case 'delete_confirm':
				if (isset($HTTP_GET_VARS['delete_reviews']) && ($HTTP_GET_VARS['delete_reviews'] == 'on')) {
          		$reviews_query = tep_db_query("select reviews_id from " . TABLE_REVIEWS . " where customers_id = '" . (int)$customers_id . "'");
          		while ($reviews = tep_db_fetch_array($reviews_query)) {
            	tep_db_query("delete from " . TABLE_REVIEWS_DESCRIPTION . " where reviews_id = '" . (int)$reviews['reviews_id'] . "'");
          		}

          		tep_db_query("delete from " . TABLE_REVIEWS . " where customers_id = '" . (int)$customers_id . "'");
        		} else {
          		tep_db_query("update " . TABLE_REVIEWS . " set customers_id = null where customers_id = '" . (int)$customers_id . "'");
        		}
			
				tep_db_query("delete from " . TABLE_ADDRESS_BOOK . " where customers_id = '" . (int)$customers_id . "'");
        		tep_db_query("delete from " . TABLE_CUSTOMERS . " where customers_id = '" . (int)$customers_id . "'");
        		tep_db_query("delete from " . TABLE_CUSTOMERS_INFO . " where customers_info_id = '" . (int)$customers_id . "'");
        		tep_db_query("delete from " . TABLE_CUSTOMERS_BASKET . " where customers_id = '" . (int)$customers_id . "'");
        		tep_db_query("delete from " . TABLE_CUSTOMERS_BASKET_ATTRIBUTES . " where customers_id = '" . (int)$customers_id . "'");
        		tep_db_query("delete from " . TABLE_WHOS_ONLINE . " where customer_id = '" . (int)$customers_id . "'");
				echo 'load_customers^^';
				echo load_customer();
				break;
			case 'search_customers':
				$cID=isset($HTTP_GET_VARS['cID'])?(int)$HTTP_GET_VARS['cID']:'';
				$customers_search=isset($HTTP_GET_VARS['customers_search'])?tep_db_prepare_input($HTTP_GET_VARS['customers_search']):'';
				echo 'search_customers^^';
				echo load_customer($customers_search,$cID);
				echo '<div align="right"><a href="javascript: reset_search();">'.tep_image_button('button_reset.gif', IMAGE_RESET).'</a></div>';
				echo '^^'.$cID;
				break;
			case 'reset_search':
				echo 'load_customers^^';
				echo load_customer('',$cID);
				break;
			case 'customer_mail';
				echo 'customer_mail^^';
				echo customer_mail();
				break;
			case 'mail_preview':
				echo 'mail_preview^^';
				echo mail_preview();
				break;
			case 'mail_send':
				mail_send();
				$customers_id_query=tep_db_query('select customers_id from '.TABLE_CUSTOMERS." where customers_email_address='". tep_db_input(tep_db_prepare_input($HTTP_POST_VARS['customers_email_address']))."'");
				$customers_id_array=tep_db_fetch_array($customers_id_query);
				echo 'load_customers_details^^'.$customers_id_array['customers_id'].'^^';
				echo load_customers_details($customers_id_array['customers_id']);
				break;
			case 'customers_payment_wallet':
				echo 'customers_payment_wallet^^';
				echo customers_payment_wallet();
				break;
			case 'customers_wallet_confirmation':
				$GLOBALS["EXECUTE_PAYMENT"]=1;
				echo 'customers_wallet_confirmation^^';
				echo customers_wallet_confirmation();
				break;
			case 'customers_wallet_process':
				echo 'customers_wallet_process^^';
				echo customers_wallet_process();
				break;
		}
	exit;
	}
	
	function customer_mail(){
	global $HTTP_GET_VARS;
	$customers_id=isset($HTTP_GET_VARS['customers_id'])?(int)$HTTP_GET_VARS['customers_id']:'';
	$email_address_query=tep_db_query('select customers_email_address from '.TABLE_CUSTOMERS." where customers_id='$customers_id'");
	$email_address_array=tep_db_fetch_array($email_address_query);
	$email_address=$email_address_array['customers_email_address'];
	?>
	<?php echo tep_draw_form('mail', FILENAME_MAIL, 'action=preview'); ?>
	<table border="0" cellpadding="0" cellspacing="2">
	<tr>
	<td colspan="2"><?php echo tep_draw_separator('pixel_trans.gif', '1', '10'); ?></td>
	</tr>
	<?php
    $customers = array();
    $customers[] = array('id' => '0', 'text' => TEXT_SELECT_CUSTOMER);
    $customers[] = array('id' => '***', 'text' => TEXT_ALL_CUSTOMERS);
    $customers[] = array('id' => '**D', 'text' => TEXT_NEWSLETTER_CUSTOMERS);
    $mail_query = tep_db_query("select customers_email_address, customers_firstname, customers_lastname from " . TABLE_CUSTOMERS . " order by customers_lastname");
    while($customers_values = tep_db_fetch_array($mail_query)) {
    $customers[] = array('id' => $customers_values['customers_email_address'],
                           'text' => $customers_values['customers_lastname'] . ', ' . $customers_values['customers_firstname'] . ' (' . $customers_values['customers_email_address'] . ')');
    }
    $fields_details=array(array('id'=>'TITLE_C','text'=>TEXT_TITLE_C),
                               array('id'=>'FN','text'=>'&nbsp;&nbsp;' . TEXT_FN),
                               array('id'=>'LN','text'=>'&nbsp;&nbsp;' . TEXT_LN),
			    			   array('id'=>'SN','text'=>'&nbsp;&nbsp;' . TEXT_SN),
    						   array('id'=>'SM','text'=>'&nbsp;&nbsp;' . TEXT_SM),
			   			       array('id'=>'SE','text'=>'&nbsp;&nbsp;' . TEXT_SE),
			      			   array('id'=>'LA','text'=>'&nbsp;&nbsp;' . TEXT_LA),
							   array('id'=>'EA','text'=>'&nbsp;&nbsp;' . TEXT_EA),
							   array('id'=>'PWD','text'=>'&nbsp;&nbsp;' . TEXT_PWD)
			       );
	// (isset($HTTP_GET_VARS['customer']) ? $HTTP_GET_VARS['customer'] : '')
	?>
              <tr>
                <td class="main"><?php echo TEXT_CUSTOMER; ?></td>
                <td><?php echo tep_draw_pull_down_menu('customers_email_address', $customers,$email_address);?></td>
              </tr>
              <tr>
                <td colspan="2"><?php echo tep_draw_separator('pixel_trans.gif', '1', '10'); ?></td>
              </tr>
              <tr>
                <td class="main"><?php echo TEXT_FROM; ?></td>
                <td><?php echo tep_draw_input_field('from', STORE_OWNER_EMAIL_ADDRESS,'size=40'); ?></td>
              </tr>
              <tr>
                <td colspan="2"><?php echo tep_draw_separator('pixel_trans.gif', '1', '10'); ?></td>
              </tr>
              <tr>
                <td class="main"><?php echo TEXT_SUBJECT; ?></td>
                <td><?php echo tep_draw_input_field('subject','','size=40'); ?></td>
              </tr>
              <tr>
                <td colspan="2"><?php echo tep_draw_separator('pixel_trans.gif', '1', '10'); ?></td>
              </tr>
              <tr>
                <td valign="top" class="main"><?php echo TEXT_MESSAGE; ?></td>
                <td><table border=0 cellspacing="0" cellpadding="0" style="background:ButtonFace;"><tr><td><?php echo tep_draw_textarea_field('message', 'soft', '80', '24','','id="message"'); ?></td>
				     <td  style="background:ButtonFace;" valign=bottom align=center>
          <?php 
		       echo "<div class='main'><b>" . TEXT_MERGE_FIELDS . '</b></div><br>';
		       echo tep_draw_pull_down_menu('fields',$fields_details,'','style="height:' .((strpos($_SERVER['HTTP_USER_AGENT'],"MSIE")>0)?'224':'241') .'" size=15 ondblClick="AddField()"');
		  ?></td></tr></table></td>
                
              </tr>
              <tr>
                <td colspan="2"><?php echo tep_draw_separator('pixel_trans.gif', '1', '10'); ?></td>
              </tr>
			  <tr>
			  <td class="main" align="center"><?php echo tep_draw_checkbox_field('chkpwd','','','','onClick="javascript:pwd(this.checked);"') . '&nbsp;' . TEXT_CREATE_PWD;?></td>
			  </tr>
              <tr>
              
              
                <td colspan="2" align="right">
                 <?php 
				 		//echo '<a href="' . tep_href_link(FILENAME_CUSTOMERS,'selected_box=customers') . '">' . tep_image_button('button_cancel.gif',IMAGE_CANCEL) . '</a>&nbsp;';
				 	   /*if (HTML_AREA_WYSIWYG_DISABLE_EMAIL == 'Enable'){ 
				 			echo tep_image_submit('button_send_email.gif', IMAGE_SEND_EMAIL, 'onClick="validate();return returnVal;"');
	                   } else {
    			            echo tep_image_submit('button_send_email.gif', IMAGE_SEND_EMAIL); 
					   }*/
				?>
                </td>
                
                
              </tr>
            </table>
          </form>
	<?php
	}

	function mail_preview(){
	global $HTTP_POST_VARS;
	switch ($HTTP_POST_VARS['customers_email_address']) {
      case '***':
        $mail_sent_to = TEXT_ALL_CUSTOMERS;
        break;
      case '**D':
        $mail_sent_to = TEXT_NEWSLETTER_CUSTOMERS;
        break;
      default:
        $mail_sent_to = tep_db_prepare_input($HTTP_POST_VARS['customers_email_address']);
        break;
    }
    $merge_details=array(TEXT_FN=>TEST_MAIL_FN,
                          TEXT_LN=>TEST_MAIL_LN,
			              TEXT_SN=>TEST_MAIL_SN,
    			          TEXT_SM=>TEST_MAIL_SM,
			              TEXT_SE=>TEST_MAIL_SE,
			              TEXT_LA=>TEST_MAIL_LA,
						  TEXT_EA=>TEST_MAIL_EA,
						  TEXT_PWD=>TEST_MAIL_PWD
			             );

   
    $message_text=tep_db_prepare_input($HTTP_POST_VARS['message']);
	while(list($key,$value)=each($merge_details))
       $message_text=str_replace("%%" . $key  . "%%",$value,$message_text);	
	?>
    <?php echo tep_draw_form('mail', FILENAME_MAIL, 'action=send_email_to_user'); ?>
            <table border="0" width="100%" cellpadding="0" cellspacing="2">
              <tr>
                <td><?php echo tep_draw_separator('pixel_trans.gif', '1', '10'); ?></td>
              </tr>
              <tr>
                <td class="smallText"><b><?php echo TEXT_CUSTOMER; ?></b><br><?php echo $mail_sent_to; ?></td>
              </tr>
              <tr>
                <td><?php echo tep_draw_separator('pixel_trans.gif', '1', '10'); ?></td>
              </tr>
              <tr>
                <td class="smallText"><b><?php echo TEXT_FROM; ?></b><br><?php echo htmlspecialchars(STORE_OWNER_EMAIL_ADDRESS); ?></td>
              </tr>
              <tr>
                <td><?php echo tep_draw_separator('pixel_trans.gif', '1', '10'); ?></td>
              </tr>
              <tr>
                <td class="smallText"><b><?php echo TEXT_SUBJECT; ?></b><br><?php echo htmlspecialchars(stripslashes($HTTP_POST_VARS['subject'])); ?></td>
              </tr>
              <tr>
                <td><?php echo tep_draw_separator('pixel_trans.gif', '1', '10'); ?></td>
              </tr>
              <tr>
                <td class="smallText"><b><?php echo TEXT_MESSAGE; ?></b><br><?php if (HTML_AREA_WYSIWYG_DISABLE_EMAIL == 'Enable') { echo (stripslashes($message_text)); } else { echo htmlspecialchars(stripslashes($message_text)); } ?></td>
              </tr>
              <tr>
                <td><?php echo tep_draw_separator('pixel_trans.gif', '1', '10'); ?></td>
              </tr>
              <tr>
                <td>
				<?php
				/* Re-Post all POST'ed variables */
					reset($HTTP_POST_VARS);
					while (list($key, $value) = each($HTTP_POST_VARS)) {
					  if (!is_array($HTTP_POST_VARS[$key])) {
						echo tep_draw_hidden_field($key, htmlspecialchars(stripslashes($value)));
					  }
					}
				?>
                    <tr>
	                    <td align="right">
						<?php 
							//echo tep_image_submit('button_back.gif', IMAGE_BACK, 'name="back"')  . '&nbsp;' . tep_image_submit('button_send_email.gif', IMAGE_SEND_EMAIL); 
						?>
						</td>
                    </tr>
                </table></td>
             </tr>
            </table>
          </form>
	<?php
	}

	function mail_send(){
	global $HTTP_POST_VARS;
		if ( isset($HTTP_POST_VARS['customers_email_address']) && !isset($HTTP_POST_VARS['back_x']) ) {
		switch ($HTTP_POST_VARS['customers_email_address']) {
			case '***':
				$mail_query = tep_db_query("select customers_firstname,customers_id, customers_lastname, customers_email_address, customers_password from " . TABLE_CUSTOMERS);
				$mail_sent_to = TEXT_ALL_CUSTOMERS;
				break;
			case '**D':
				$mail_query = tep_db_query("select customers_firstname,customers_id, customers_lastname, customers_email_address, customers_password from " . TABLE_CUSTOMERS . " where customers_newsletter = '1'");
				$mail_sent_to = TEXT_NEWSLETTER_CUSTOMERS;
				break;
			default:
				$customers_email_address = tep_db_prepare_input($HTTP_POST_VARS['customers_email_address']);
				$mail_query = tep_db_query("select customers_firstname, customers_id, customers_lastname, customers_email_address, customers_password from " . TABLE_CUSTOMERS . " where customers_email_address = '" . tep_db_input($customers_email_address) . "'");
				$mail_sent_to = $HTTP_POST_VARS['customers_email_address'];
				break;
		}
		$from = tep_db_prepare_input($HTTP_POST_VARS['from']);
		$subject = tep_db_prepare_input($HTTP_POST_VARS['subject']);
		$message = tep_db_prepare_input($HTTP_POST_VARS['message']);

		//Let's build a message object using the email class
		$mimemessage = new email(array('X-Mailer: osCommerce'));
		// add the message to the object
		while ($mail = tep_db_fetch_array($mail_query)) { 
			$message_detail=$message;
			$pos=strpos($message,"%%Password%%");
			if($chkpwd==true && $pos)
		{
		$pww=tep_rand(5);
		$password=tep_encrypt_password($pww);
		tep_db_query ("update " . TABLE_CUSTOMERS . " set customers_password = '". tep_db_input($password) ."' where customers_id = '" . (int)$mail['customers_id']. "'");
		}
		else
		{
		$pww="---- Hidden----";
		}
			$merge_details=array(	TEXT_FN=>$mail['customers_firstname'],
									TEXT_LN=>$mail['customers_lastname'],
									TEXT_SN=>STORE_NAME,
									TEXT_SM=>STORE_OWNER,
									TEXT_SE=>STORE_OWNER_EMAIL_ADDRESS,
									TEXT_LA=>tep_catalog_href_link(FILENAME_AUTOLOGIN,'email=' . $mail['customers_email_address'] . '&id=' . $mail['customers_password']),
									TEXT_EA=>$mail['customers_email_address'],
									TEXT_PWD=>$pww
								);
			
			while(list($key,$value)=each($merge_details))
				$message_detail=str_replace("%%" . $key  . "%%",$value,$message_detail);
			
			$message_text=strip_tags($message_detail,'<br>');
			$message_text=str_replace('<br>',chr(13) . chr(10),$message_text);
			$message_text=str_replace('<BR>',chr(13) . chr(10),$message_text);
			   
			if (HTML_AREA_WYSIWYG_DISABLE_EMAIL == 'Disable') {
				$mimemessage->add_text($message_text);
			} else {
				$mimemessage->add_html($message_detail,$message_text);
			}
			$mimemessage->build_message();
			//echo $mail['customers_firstname'] . ' ' . $mail['customers_lastname'], $mail['customers_email_address'], '', $from, $subject,$message_detail;
			$mimemessage->send($mail['customers_firstname'] . ' ' . $mail['customers_lastname'], $mail['customers_email_address'], '', $from, $subject);
		}
	}

	}

	function customers_payment_wallet(){
	global $HTTP_GET_VARS;
	global $upload_id;
	global $language;

	require(DIR_WS_CLASSES . 'currencies.php');
	require(DIR_WS_CLASSES . 'payment.php');
	require(DIR_WS_LANGUAGES.'/'.$language.'/'.FILENAME_WALLET_PAYMENT); 

	$payment_modules = new payment;
	$currencies = new currencies();
	include(DIR_WS_CLASSES . 'order.php'); 

	// check for the customer id in input or session
	$cID=(isset($HTTP_GET_VARS['cID'])?(int)$HTTP_GET_VARS['cID']:0);

	if ($cID==0) $cID=(isset($HTTP_SESSION_VARS['upload_id'])?(int)$HTTP_SESSION_VARS['upload_id']:0);

	$wallet_timestamp=time();
 	 if (!tep_session_is_registered('wallet_timestamp')) tep_session_register('wallet_timestamp');


	if (!tep_session_is_registered('upload_id')) tep_session_register('upload_id');
	
	// check for the payment page
	if (!tep_session_is_registered('payment_page')) tep_session_register('payment_page');
	
	$upload_id=$cID;
	$HTTP_SESSION_VARS['upload_id']=$cID;
	$payment_page="wallet";
	
	$customer_details_query = tep_db_query("select c.customers_id,c.customers_default_address_id, a.entry_firstname as firstname, a.entry_lastname as lastname, a.entry_company as company, a.entry_street_address as street_address, a.entry_suburb as suburb, a.entry_city as city, a.entry_postcode as postcode, a.entry_state as state, a.entry_zone_id as zone_id, a.entry_country_id as country_id from ". TABLE_ADDRESS_BOOK . " a, " . TABLE_CUSTOMERS . " c  where c.customers_id = " .(int)$cID . " and c.customers_id = a.customers_id and c.customers_default_address_id = a.address_book_id");
	$customer_details = tep_db_fetch_array($customer_details_query);
	$firstname=$lastname=$streets=$citypost=$state=$country="";
	
	$label='$firstname $lastname<br>$streets<br>$city $postcode<br>$statename$country';
	$firstname=$customer_details["firstname"];
	$lastname=$customer_details["lastname"];
	$street=$customer_details["street_address"];
	$suburb=$customer_details["suburb"];
	$postcode=$customer_details["postcode"];
	$city=$customer_details["city"];
	$state=$customer_details["state"];
	$country=tep_get_country_name($customer_details['country_id']);

	if (isset($customer_details['zone_id']) && tep_not_null($customer_details['zone_id'])) {
		$state = tep_get_zone_code($customer_details['country_id'], $customer_details['zone_id'], $state);
	}
	$streets=$street;
	if ($suburb!="") $streets=$street . "<br>" . $suburb;
	if ($state!="") $statename=$state . ',';
	
	// print the string
	eval("\$address = \"$label\";");
	
	?>
<?php echo tep_draw_form('checkout_payment', FILENAME_WALLET_CONFIRMATION,'','post') ; ?>
<!-- body -->
<table cellpadding="2" cellspacing="2" border="0" width="100%">
  <tr> 
<!-- body_text //-->

    <td style="padding-left:20px;" width="100%" valign="top">
		<table border="0" width="100%" cellspacing="0" cellpadding="0">
			  <?php  if (isset($HTTP_GET_VARS['error_message'])){ ?>
          	<tr>
		  		<td colspan="2" valign="top" >
					<table width="100%" cellpadding="2" cellspacing="0" border="0">
						<tr><td class="main" ><font color=red><?php echo tep_check_error($HTTP_GET_VARS['error_message']); ?></font>
					</table>	
				</td>
			</tr>
			<tr>
	<td><?php echo tep_draw_separator('pixel_trans.gif', '1', '5'); ?></td>
      </tr>
		  <?php  } ?>
		  
		<?php if (isset($HTTP_GET_VARS['payment_error']) && is_object(${$HTTP_GET_VARS['payment_error']}) && ($error = ${$HTTP_GET_VARS['payment_error']}->get_error())) {
		//print_r($HTTP_GET_VARS);
		?>
        <tr><td>
 	  <table border="0" width="100%" cellspacing="0" cellpadding="0">
	    <tr><td align=left class='pageHeading' colspan='2'><?php echo tep_output_string_protected($error['title']); ?></td></tr>
	  </table></td></tr>
      <tr>
        <td><table border="0" width="100%" cellspacing="1" cellpadding="2" bgcolor="#ff6c6c">
          <tr class="infoBoxNoticeContents">
            <td><table border="0" width="100%" cellspacing="0" cellpadding="2">
              <tr>
                <td><?php echo tep_draw_separator('pixel_trans.gif', '10', '1'); ?></td>
                <td class="main" width="100%" valign="top"><font color=black><?php echo $error['error']; ?></font></td>
                <td><?php echo tep_draw_separator('pixel_trans.gif', '10', '1'); ?></td>
              </tr>
            </table></td>
          </tr>
        </table></td>
      </tr>
     
<?php } ?>
		      <tr>
        		<td width="100%"><table border="0" width="100%" cellspacing="0" cellpadding="0">
	    	      <tr>
    	    	    <td class="pageHeading"><?php echo HEADING_TITLE; ?> <?php  ?></td>
            		<td class="pageHeading" align="right"><?php  echo tep_draw_separator('pixel_trans.gif', HEADING_IMAGE_WIDTH, HEADING_IMAGE_HEIGHT); ?></td>
		            <td class="pageHeading" align="right"><?php ?></td>
        		  </tr>
				
		        </table></td>
			  </tr>
			  
			   
			   <tr>
    		    <td>
					<table cellpadding="2" cellspacing="0" border="0"><tr><td class="formAreaTitle">
					</td></tr></table>	
				</td>
   			  </tr>
			  <tr>
			  	 <td><?php echo tep_draw_separator('pixel_trans.gif', '1', '5'); ?></td>	
			  </tr>
			  <?php tep_content_title_top(WALLET_FUNDS); ?>
		      <tr>
			  <td  valign="top" >
			  	<table  border="0" cellpadding="2" cellspacing="0" width="60%">
				
					<tr><td valign="top">
			  		<table border="0" width="100%" cellspacing="0" cellpadding="2"  >
	    		   	  <tr>
					  	 <td colspan="3"><?php echo tep_draw_separator('pixel_trans.gif', '1', '5'); ?></td>	
					  </tr>
					 <tr>
					 	<td ><?php echo tep_draw_separator('pixel_trans.gif', '7', '1'); ?></td>	
					 	 <td class="main" valign="top" width="150"><?php echo '<b>' . WALLET_UPLOAD_TO . '</b>' ; ?></td>
						 	<td class="main" align="left"><?php	 echo $address;?></td>	 
						</tr>
					 <tr>
					     <td colspan="3"><?php echo tep_draw_separator('pixel_trans.gif', '1', '3'); ?></td>
				     </tr>	  
          			  <tr>
					  	<td><?php echo tep_draw_separator('pixel_trans.gif', '7', '1'); ?></td>	
					   	<td class="main" align="left"><?php echo '<b>' . WALLET_AMOUNT . '</b>' ?></td>
						<td class="main" align="left"><?php echo  tep_draw_input_field('wallet_amount','','maxlength=12 size=13')?></td>
					  </tr>
					   <tr>
					  	 <td colspan="3"><?php echo tep_draw_separator('pixel_trans.gif', '1', '5'); ?></td>	
					  </tr>
					</table>
				</td></tr>
				
				
				</table>
				
				
				</td>
			   </tr>
			   <?php tep_content_title_bottom(); ?>
			   
				<?php tep_content_title_top(WALLET_PAYMENT_METHOD); ?>
	<tr>
		<td>
		<table border="0" width="100%" cellspacing="1" cellpadding="2" >
		<!--<tr><td id='payerr' style="display:none; " class="main" ><font color=red>payment err</font></td></tr>-->
		<tr id="show_payment_error" <?php if($error_text=="") echo 'style="display:none"';?>>
		<td>
		<table border="0" width="100%" cellspacing="1" cellpadding="2" class="infoBoxNotice">
			<tr class="infoBoxNoticeContents">
				<td>
				<table border="0" width="100%" cellspacing="0" cellpadding="2">
					<tr>
						<td><?php echo tep_draw_separator('pixel_trans.gif', '10', '1'); ?></td>
						<td class="main" width="100%" valign="top" id="payment_error_text"><?php echo $error_text; ?></td>
						<td><?php echo tep_draw_separator('pixel_trans.gif', '10', '1'); ?></td>
					</tr>
				</table>
				</td>
			</tr>
		</table>
		</td>
	</tr>
			<tr>
				<td>
				<table border="0" width="100%" cellspacing="0" cellpadding="2">
					<?php 
					  $selection = $payment_modules->selection();
					  if (sizeof($selection) > 1) {
					?>
								  <tr>
									<td><?php echo tep_draw_separator('pixel_trans.gif', '10', '1'); ?></td>
									<td class="main" width="50%" valign="top"><?php echo TEXT_SELECT_PAYMENT_METHOD; ?></td>
									<td class="main" width="50%" valign="top" align="right"><b><?php echo TITLE_PLEASE_SELECT; ?></b><br><?php echo tep_image(DIR_WS_IMAGES . 'arrow_east_south.gif'); ?></td>
									<td><?php echo tep_draw_separator('pixel_trans.gif', '10', '1'); ?></td>
								  </tr>
					<?php
					  } else {
					?>
								  <tr>
									<td><?php echo tep_draw_separator('pixel_trans.gif', '10', '1'); ?></td>
									<td class="main" width="100%" colspan="2">
									<?php  if(sizeof($selection)>0)
												echo TEXT_ENTER_PAYMENT_INFORMATION; 
										 else
												echo TEXT_NO_PAYMENT_SELECTION;
									?></td>
									<td><?php echo tep_draw_separator('pixel_trans.gif', '10', '1'); ?></td>
								  </tr>
					<?php
					  }
					  $flag='B';
					  $radio_buttons = 0;
					  $m = count($selection[0]['fields']);
					  $cnt = 0;
					  $barred=0;
					  for ($i=0, $n=sizeof($selection); $i<$n; $i++) {
					?>
					  <tr>
						<td><?php echo tep_draw_separator('pixel_trans.gif', '10', '1'); ?></td>
						<td colspan="2">
						<table border="0" width="100%" cellspacing="0" cellpadding="2">
							<?php
							
							//if ($selection[$i]['id']!='wallet'){
						
							 if ( ($selection[$i]['id'] == $payment) || ($n == 1) ) 
									echo '<tr id="defaultSelected" class="moduleRowSelected" onmouseover="rowOverEffect(this)" onmouseout="rowOutEffect(this)" onclick="selectRowEffect(this, ' . $radio_buttons . ',\'', $selection[$i]['id'] . '\')">' . "\n";
							 else 
								   echo '<tr id="defaultunSelected" class="moduleRow" onmouseover="rowOverEffect(this)" onmouseout="rowOutEffect(this)" onclick="selectRowEffect(this, ' . $radio_buttons . ',\'', $selection[$i]['id'] . '\')">' . "\n";
							?>
									<td width="10"><?php echo tep_draw_separator('pixel_trans.gif', '10', '1'); ?></td>
									<td class="main" colspan="3"><b><?php echo $selection[$i]['module']; ?></b>
									 <table border="0" cellpadding="0" cellspacing="0">
										<?php for($j=0;$j<$m;$j++){
										   while(list($k,$v) = each($selection[0]["fields"]["$j"])){
												  if($cnt%2==0)
													 //echo '<tr> ';
													//echo  '<td class="main">'.$v . '</td>';
													$cnt++;
												} 
											} ?>
									</table>
									</td>
				                    <td class="main" align="right">
									<?php $single_payment=false;
										if (sizeof($selection)>1) 
										  echo tep_draw_radio_field('payment', $selection[$i]['id'],(($i==0)?true:''));
										else {
										  $single_payment=true;
										  echo tep_draw_hidden_field('payment', $selection[$i]['id']);
										}
									?>
									</td>
									<td width="10"><?php echo tep_draw_separator('pixel_trans.gif', '10', '1'); ?></td>
								</tr>
								<?php
									if (isset($selection[$i]['error'])) {
								?>
												  <tr>
													<td width="10"><?php echo tep_draw_separator('pixel_trans.gif', '10', '1'); ?></td>
													<td class="main" colspan="4"><?php echo $selection[$i]['error']; ?></td>
													<td width="10"><?php echo tep_draw_separator('pixel_trans.gif', '10', '1'); ?></td>
												  </tr>
								<?php
									} elseif (isset($selection[$i]['fields']) && is_array($selection[$i]['fields'])) {
								?>	
												  <tr <?php if(!$single_payment){?>id="<?php echo $selection[$i]['id'];?>" <?php echo (($payment!=$selection[$i]['id'])?'style="display:none"':'');}?>>
													<td width="10"><?php echo tep_draw_separator('pixel_trans.gif', '10', '1'); ?></td>
													<td colspan="4">
													<table border="0" cellspacing="0" cellpadding="2">
														<?php
															  for ($j=0, $n2=sizeof($selection[$i]['fields']); $j<$n2; $j++) {
														?>
																			  <tr>
																				<td width="10"><?php echo tep_draw_separator('pixel_trans.gif', '10', '1'); ?></td>
																				<td class="main"><?php echo $selection[$i]['fields'][$j]['title']; ?></td>
																				<td><?php echo tep_draw_separator('pixel_trans.gif', '10', '1'); ?></td>
																				<td class="main"><?php echo $selection[$i]['fields'][$j]['field']; ?></td>
																				<td width="10"><?php echo tep_draw_separator('pixel_trans.gif', '10', '1'); ?></td>
																			  </tr>
														<?php
															  }
														?>
													</table>
													</td>
													<td width="10"><?php echo tep_draw_separator('pixel_trans.gif', '10', '1'); ?></td>
						  						</tr>
								<?php
									} // fields,error
								//	}
								?>
                		</table>
						</td>
                		<td><?php echo tep_draw_separator('pixel_trans.gif', '10', '1'); ?></td>
				  </tr>
			  
<?php
   $radio_buttons++;
    //$cnt++;
  }
?>
            </table></td>
          </tr>
		  <?php tep_content_title_bottom(); ?>
        </table></td>
      </tr>
	  <tr>
		<td><?php echo tep_draw_separator('pixel_trans.gif', '1', '5'); ?></td>
	 </tr>
	 <script language="javascript">
		//previousPaymentSelected="<?php echo $payment;?>";
		//if(!previousPaymentSelected && document.getElementById("defaultunSelected")) selectRowEffect(document.getElementById("defaultunSelected"),0,"<?php echo $selection[0]['id'];?>");
	</script>
      
			  <!-- ends payment blocks -->
	<!-- begins comments block -->
	 <?php tep_content_title_top(TEXT_ENTER_COMMENTS); ?>
	<tr>
        <td><table border="0" width="60%" cellspacing="2" cellpadding="2" > 
          <tr>
		     <td><table border="0" width="100%" cellspacing="2" cellpadding="2" >
              <tr>
                <td><?php echo tep_draw_textarea_field('comments', 'soft', '80', '5'); ?></td>
              </tr>
            </table></td>
          </tr>
        </table></td>
      </tr>
	
	<?php tep_content_title_bottom(); ?>
	<!-- end comments block -->
	
	  </form>
		   
		</table>
	</td>		   		
  </tr>
 </table>
			  
		
<!-- Begin Addresses Block -->
	<?php
	}
	
	function customers_wallet_confirmation(){
	global $HTTP_SESSION_VARS,$HTTP_POST_VARS;
	global $upload_id, $language;
	require(DIR_WS_CLASSES . 'payment.php');
	require(DIR_WS_CLASSES . 'currencies.php');
	require(DIR_WS_LANGUAGES.$language.'/'.FILENAME_WALLET_CONFIRMATION);
	// check for the customer id 

	$cID=(isset($HTTP_SESSION_VARS['upload_id'])?$HTTP_SESSION_VARS['upload_id']:0);

	// redirect to the customers page
	if ($cID==0) {
		//tep_redirect(tep_href_link(FILENAME_CUSTOMERS));

	tep_session_unregister('payment_page');
	tep_session_unregister('comments');
	tep_session_unregister('wallet_amount');
	tep_session_unregister('payment');
	tep_session_unregister('wallet_timestamp');
	}

	if (!tep_session_is_registered('wallet_amount')) tep_session_register('wallet_amount');
	if (!tep_session_is_registered('payment')) tep_session_register('payment');
	if (!tep_session_is_registered('comments')) tep_session_register('comments');


	// get the values from the payment page
	$wallet_amount=(isset($HTTP_POST_VARS['wallet_amount'])?$HTTP_POST_VARS['wallet_amount']:'');
	$payment = (isset($HTTP_POST_VARS['payment'])?$HTTP_POST_VARS['payment']:'');

	if (tep_not_null($HTTP_POST_VARS['comments'])) {
		$comments = tep_db_prepare_input($HTTP_POST_VARS['comments']);
	}

	// check for the wallet amount
	if( $wallet_amount=="" || ((float)$wallet_amount<=0))  {
		//tep_redirect(tep_href_link(FILENAME_WALLET_PAYMENT, 'error_message=' .urlencode(ERROR_NO_PAYMENT_MODULE_UPLOADS)));
	echo 'error^^'.'Wallet Amount Error'.'^^';
	}

	$payment_modules=new payment($payment);


	// check for the payment
	/*if ((is_array($payment_modules->modules)) && (sizeof($payment_modules->modules) > 1) && (!is_object($$payment))) {

		tep_redirect(tep_href_link(FILENAME_WALLET_PAYMENT, 'error_message=' . urlencode(ERROR_NO_PAYMENT_MODULE_SELECTED)));
	}*/
	  
	
	// perform a confirmation  
	if (is_array($payment_modules->modules)) {
	$payment_modules->pre_confirmation_check();
	$HTTP_SESSION_VARS['ajax_flag']="ajax_flag";
		
	}


	$currencies=new currencies();
	// get the customer address details	
	$customer_details_query = tep_db_query("select c.customers_id,c.customers_default_address_id, a.entry_firstname as firstname, a.entry_lastname as lastname, a.entry_company as company, a.entry_street_address as street_address, a.entry_suburb as suburb, a.entry_city as city, a.entry_postcode as postcode, a.entry_state as state, a.entry_zone_id as zone_id, a.entry_country_id as country_id from ". TABLE_ADDRESS_BOOK . " a, " . TABLE_CUSTOMERS . " c  where c.customers_id = " .(int)$cID . " and c.customers_id = a.customers_id and c.customers_default_address_id = a.address_book_id");
	$customer_details = tep_db_fetch_array($customer_details_query);
	$firstname=$lastname=$streets=$citypost=$state=$country="";
	
	$label='$firstname $lastname<br>$streets<br>$city $postcode<br>$statename$country';
	$firstname=$customer_details["firstname"];
	$lastname=$customer_details["lastname"];
	$street=$customer_details["street_address"];
	$suburb=$customer_details["suburb"];
	$postcode=$customer_details["postcode"];
	$city=$customer_details["city"];
	$state=$customer_details["state"];
	$country=tep_get_country_name($customer_details['country_id']);

	if (isset($customer_details['zone_id']) && tep_not_null($customer_details['zone_id'])) {
		$state = tep_get_zone_code($customer_details['country_id'], $customer_details['zone_id'], $state);
	}
	$streets=$street;
	if ($suburb!="") $streets=$street . "<br>" . $suburb;
	if ($state!="") $statename=$state . ',';
	
	// print the string
	eval("\$address = \"$label\";");

// BOF: Lango Added for template MOD

	if (isset($$payment->form_action_url)) {
		echo '<form name="checkout_confirmation" action="' . $$payment->form_action_url . '" method="post">';
		echo tep_draw_hidden_field('action',$$payment->form_action_url);
	} else {
		echo '<form name="checkout_confirmation" action="' . tep_href_link(FILENAME_WALLET_PROCESS,$payment_params) . '" method="post">';
		echo tep_draw_hidden_field('action',tep_href_link(FILENAME_WALLET_PROCESS,$payment_params));
	}
?>
	<!-- body //-->
<table border="0" width="100%" cellspacing="2" cellpadding="2">
<tr> 
	<!-- body_text //-->	  
    <td width=100% align=left valign="top"><table border="0" width="100%" cellspacing="0" cellpadding="0">
      <tr>
        <td><table border="0" width="100%" cellspacing="0" cellpadding="0">
          <tr>
            <td class="pageHeading"><?php echo HEADING_TITLE; ?></td>
          </tr>
        </table></td>
      </tr>
	<tr>
	<td><?php echo tep_draw_separator('pixel_trans.gif', '100%', '10'); ?></td>
	</tr>
	  <tr>
	  	<td>
		<table cellpadding="0" cellspacing="0" width="60%" border="0" >
			<tr>
    		    <td>
				<table border="0" width="100%" cellspacing="1" cellpadding="2">
					<tr>
						<td width="30%" valign="top">
						<table border="0" width="100%" cellspacing="1" cellpadding="2">
							<tr>
								<td class="main"><?php  echo '<b>' . HEADING_UPLOAD_TO . '</b> '; ?></td>
								<td class="main"><?php echo '<b>' . HEADING_UPLOAD_AMOUNT . '</b> ' ?><?php echo $currencies->format($wallet_amount); ?></td>
							</tr>
							<tr>
								<td class="main"><?php echo $address;?></td>
								<td></td>
							</tr>
						</table>
						</td>				
					</tr>
				</table>
				</td>
			</tr>
			<tr>
				<td><?php echo tep_draw_separator('pixel_trans.gif', '100%', '10'); ?></td>
			</tr>
			  <tr>
				<td>
				  <table border="0" width="100%" cellspacing="1" cellpadding="2">
				  <tr>
				   <td width="30%" valign="top">
					 <table border="0" width="100%" cellspacing="0" cellpadding="2">
					  <tr>
						<td class="main"><?php echo '<b>' . HEADING_PAYMENT_METHOD . '</b>'; ?></td>
					 	 <table cellpadding="0" cellspacing="0" border="0">
						 <tr><td width="10%">&nbsp;</td><td class="main">
						<tr>
             		    <td class="main"><?php echo $GLOBALS[$payment]->title; ?></td>
          			    </tr>
						<?php //echo $$payment->title; ?>
						</td></tr>
						</table>
						
					  </td>
					  </tr>
					
				</table></td>
			  </tr>
			<?php
			// draw the form
			
			// BOF: Lango modified for print order mod
			  if (is_array($payment_modules->modules)) {
				if ($confirmation = $payment_modules->confirmation()) {
				  $payment_info = $confirmation['title'];
				  if (!tep_session_is_registered('payment_info')) tep_session_register('payment_info');
			// EOF: Lango modified for print order mod
			?>
			  <tr>
				<td><?php echo tep_draw_separator('pixel_trans.gif', '100%', '10'); ?></td>
			  </tr>
			  <tr>
				<td><table border="0" width="100%" cellspacing="1" cellpadding="2">
				  <tr >
					<td><table border="0" cellspacing="0" cellpadding="2">
					<tr >
						<td class="main" colspan="4"><b><?php echo HEADING_PAYMENT_INFORMATION; ?></b></td>
					  </tr>
					  <tr>
						<td colspan="4"><?php echo tep_draw_separator('pixel_trans.gif', '100%', '5'); ?></td>
					  </tr>
					  <tr>
						<td class="main" colspan="4">
						<table cellpadding="0" cellspacing="0" border="0">
						<tr><td>&nbsp;</td><td class="main">
						<?php echo $confirmation['title']; ?></td></tr></table></td>
					  </tr>
					  <tr>
						<td colspan="4"><?php echo tep_draw_separator('pixel_trans.gif', '100%', '5'); ?></td>
					  </tr>
		<?php
			  for ($i=0, $n=sizeof($confirmation['fields']); $i<$n; $i++) {
		?>
					  <tr>
						<td width="10"><?php echo tep_draw_separator('pixel_trans.gif', '10', '1'); ?></td>
						<td class="main"><?php echo $confirmation['fields'][$i]['title']; ?></td>
						<td width="10"><?php echo tep_draw_separator('pixel_trans.gif', '10', '1'); ?></td>
						<td class="main"><?php echo $confirmation['fields'][$i]['field']; ?></td>
					  </tr>
					  
		<?php
			  }
		?>
					</table></td>
				  </tr>
				</table></td>
			  </tr>
		<?php
			}
		  }
		?>
			  <tr>
				<td><?php echo tep_draw_separator('pixel_trans.gif', '100%', '10'); ?></td>
			  </tr>       
<?php
  if (tep_not_null($comments)) {
?>
      <tr>
        <td><?php echo tep_draw_separator('pixel_trans.gif', '100%', '10'); ?></td>
      </tr>
      <tr>
        <td><table border="0" width="100%" cellspacing="1" cellpadding="2" class="infoBox">
		  <tr>
			<td class="main"><?php echo '<b>' . HEADING_WALLET_COMMENTS . '</b>'; ?></td>
		  </tr>
          <tr class="infoBoxContents">
            <td><table border="0" width="100%" cellspacing="0" cellpadding="4">
              <tr>
                <td class="main"><?php echo nl2br(tep_output_string_protected($comments)); ?></td>
              </tr>
            </table></td>
          </tr>
        </table></td>
      </tr>
      <tr>
        <td><?php echo tep_draw_separator('pixel_trans.gif', '100%', '10'); ?></td>
      </tr>
<?php  } ?>		  
	</table>

      <tr>
        <td><?php echo tep_draw_separator('pixel_trans.gif', '100%', '10'); ?></td>
      </tr>
      <tr>
        <td><table border="0" width="60%" cellspacing="0" cellpadding="0">
          <tr>
            <td align="right" class="main">
				<?php
				
					// draw the output form
					$temp_array=array('info'=>array('total'=>$wallet_amount));
					$order=new objectInfo($temp_array);
					
					// create a random value for internal checking
					$validID=tep_create_random_value(5,'digits');
					$payment_params='validID=' . $validID;
					if (!tep_session_is_registered('checkID')) tep_session_register('checkID');
					$checkID=$validID;
				
					
					if (is_array($payment_modules->modules)) {
						echo $payment_modules->process_button();
					}
					
				?>
            </td>
          </tr>
        </table></td>
      </tr>
      <tr>
        <td><?php echo tep_draw_separator('pixel_trans.gif', '100%', '10'); ?></td>
      </tr>
      <tr>
        <td><table border="0" width="100%" cellspacing="0" cellpadding="0">
          <tr>
            <td width="25%"><table border="0" width="100%" cellspacing="0" cellpadding="0">
              <tr>
                <td width="50%" align="right"><?php echo tep_draw_separator('pixel_silver.gif', '1', '5'); ?></td>
                <td width="50%"><?php echo tep_draw_separator('pixel_silver.gif', '100%', '1'); ?></td>
              </tr>
            </table></td>
          </tr>
    </table>
	</td></tr>
	</table>
	</table>
</form>
	<?php
	}
	
	function customers_wallet_process(){
	global $HTTP_SESSION_VARS,$HTTP_GET_VARS,$HTTP_POST_VARS;
	global $payment,$wallet_amount,$comments;
	global $language;
	
	require(DIR_WS_CLASSES . 'payment.php');
	require(DIR_WS_CLASSES . 'currencies.php');
	//require(DIR_WS_LANGUAGES.'english/'.FILENAME_WALLET_PROCESS);

	// check for the customer id 
	$cID=(isset($HTTP_SESSION_VARS['upload_id'])?(int)$HTTP_SESSION_VARS['upload_id']:0);
	
	$validID=isset($HTTP_GET_VARS["validID"])?(int)$HTTP_GET_VARS["validID"]:0;
	$checkID=isset($HTTP_SESSION_VARS["checkID"])?(int)$HTTP_SESSION_VARS["checkID"]:0;
	$wallet_timestamp=isset($HTTP_SESSION_VARS['wallet_timestamp'])?$HTTP_SESSION_VARS['wallet_timestamp']:0;
	$server_date = getServerDate(true);
	
	if ($cID==0) {
		echo 'error^^'.'Customer Id is null'.'^^';
	}

	// check for the payment
	if ( (tep_not_null(MODULE_PAYMENT_INSTALLED)) && (!tep_session_is_registered('payment')) ) {
	echo 'error^^'.'Payment Not Installed'.'^^';
	}

	//check for the valid internal id
	if ($validID!=$checkID) {
	echo 'error^^'.'Wallet Payment Error'.'^^';
	}

	$currencies=new currencies();
	$payment_modules = new payment($payment);
	  
	$payment_status = $GLOBALS['administrator_login'] ? $GLOBALS['administrator_login'] : DEFAULT_ORDERS_STATUS_ID;	
	if ( isset($GLOBALS[$payment]->order_status) && is_numeric($GLOBALS[$payment]->order_status) && ($GLOBALS[$payment]->order_status > 0) ) {
		$payment_status=$GLOBALS[$payment]->order_status;
	}

	$sql_data_array = array(
							'customers_id' => $cID,
							'payment_date'=>$server_date,
							'payment_method'=>$GLOBALS[$payment]->title,
							'payment_info' => $GLOBALS['payment_info'],
							'payment_status' => $payment_status,
							'comments' => $comments,
							'amount' => $wallet_amount
							);


	tep_db_perform(TABLE_WALLET_UPLOADS, $sql_data_array);
	$insert_id=tep_db_insert_id();
		
    $current_balance=tep_get_wallet_balance($cID);
	$customer_sql="SELECT c.customers_firstname,c.customers_lastname,c.customers_dob,c.customers_email_address,c.customers_telephone,
					c.customers_fax,a.entry_street_address,a.entry_city,a.entry_suburb,a.entry_postcode,a.entry_state,a.entry_country_id,a.entry_zone_id
					from " . TABLE_CUSTOMERS . " c," . TABLE_ADDRESS_BOOK . " a where a.address_book_id=c.customers_default_address_id and c.customers_id='" . (int)$cID . "'";

	$customer_query=tep_db_query($customer_sql);
	
	$customer_result=tep_db_fetch_array($customer_query);
	
		//for direct deposit module
	if($GLOBALS['payment']=='ausbank')
		$direct_deposit=sprintf(TEXT_DIRECT_DEPOSIT,substr(strtolower($customer_result['customers_firstname']),0,3) , substr(strtolower($customer_result['customers_lastname']),0,3) , $wallet_timestamp );
	else 
		$direct_deposit='';	
								
	$merge_details=array(	TEXT_FN=>$customer_result['customers_firstname'],
							TEXT_LN=>$customer_result['customers_lastname'],
							TEXT_DF=>format_date($customer_result['customers_dob']),
							TEXT_EM=>$customer_result['customers_email_address'],
							TEXT_TN=>$customer_result['entry_telephone_number'],
							TEXT_FX=>$customer_result['entry_fax'],
							TEXT_SA=>$customer_result['entry_street_address'],
							TEXT_SU=>$customer_result['entry_suburb'],
							TEXT_PC=>$customer_result['entry_postcode'],
							TEXT_CT=>$customer_result['entry_city'],
							TEXT_ST=>tep_get_zone_name($customer_result["entry_country_id"],$customer_result["entry_zone_id"],$customer_result['entry_state']),
							TEXT_CY=>tep_get_country_name($customer_result['entry_country_id']),
							TEXT_RE=>'',
							TEXT_IV=>'',
							TEXT_UN=>'',
							TEXT_PT=>$GLOBALS[$payment]->title,
							TEXT_DD=>$direct_deposit,
							TEXT_WAD=>$currencies->format($wallet_amount),
							TEXT_WCB=>$currencies->format($current_balance)
						);
	
   $send_details=array(
						array('to_name'=>$customer_result['customers_firstname'] . ' ' . $customer_result['customers_lastname'],
									 'to_email'=>$customer_result['customers_email_address'],
									 'from_name'=>STORE_OWNER,
									 'from_email'=>STORE_OWNER_EMAIL_ADDRESS
						)
					);
	$sql_array=array(	"send_date"=>$server_date,
						"customers_id"=>$cID,
						"message_mode"=>"E",
						"message_type"=>"WFU"
				);
	tep_db_perform(TABLE_WALLET_MESSAGES_HISTORY,$sql_array);
	
	tep_send_default_email("WFU",$merge_details,$send_details);
	
    //$messageStack->add_session(SUCCESS_UPLOAD_UPDATED, 'success');

	tep_session_unregister('payment_page');
	tep_session_unregister('comments');
	tep_session_unregister('wallet_amount');
	tep_session_unregister('payment');
	tep_session_unregister('wallet_timestamp');
	
	//require(DIR_WS_CLASSES . 'currencies.php');
 	require(DIR_WS_LANGUAGES. $language . '/'.FILENAME_WALLET_SUCCESS);

 	// check for the customer id 
	$cID=(isset($HTTP_SESSION_VARS['upload_id'])?(int)$HTTP_SESSION_VARS['upload_id']:0);

	//$currencies=new currencies();  
  	$upload_query=tep_db_query("SELECT payment_status,amount from " . TABLE_WALLET_UPLOADS . " where wallet_id='" . (int)$insert_id . "'");
	$upload_result=tep_db_fetch_array($upload_query);
	?>
	<!-- body //-->
<table border="0" width="100%" cellspacing="2" cellpadding="2">
<tr> 
	<!-- body_text //-->	  
    <td width=100% align=left valign="top">
	<table border="0" width="100%" cellspacing="0" cellpadding="0">
      <tr>
        <td>
		<table border="0" width="100%" cellspacing="0" cellpadding="0">
			<tr>
				<td class="pageHeading"><?php echo HEADING_TITLE; ?></td>
			</tr>
        </table>
		</td>
      </tr>
	<tr>
		<td><?php echo tep_draw_separator('pixel_trans.gif', '100%', '10'); ?></td>
	</tr>
	  <tr>
	  	<td>
		<table cellpadding="0" cellspacing="0" width="60%" border="0">
			<tr>
    		    <td>
				<table border="0" width="100%" cellspacing="1" cellpadding="2">
					<tr>
						<td width="30%" valign="top">
						<table border="0" width="100%" cellspacing="1" cellpadding="2">
							<tr>
								<td class="main">
									<?php echo TEXT_SUCCESS; ?><br><br>
								</td>
							</tr>
							<?php if ($upload_result['payment_status']<=1) { ?>
								<tr>
									<td class="smallText"><?php echo sprintf(TEXT_CREDIT,$currencies->format($upload_result["amount"])); ?><br><br>
									</td>
								</tr>
							<?php } ?>
							<tr>
								<td class="main">
									<?php 
										$balance=tep_get_wallet_balance($cID);
										echo sprintf(TEXT_WALLET_BALANCE,$currencies->format($balance));
									?>
								</td>
							</tr>
						</table>
						</td>				
					</tr>
				</table>
				</td>
			</tr>
			</table>
			</td>
			</tr>
			<tr>
				<td><?php echo tep_draw_separator('pixel_trans.gif', '100%', '10'); ?></td>
			</tr>
			<tr>
				<td class="main">
					<?php //echo '<a href="' . tep_href_link(FILENAME_CUSTOMERS) . '">' . tep_image_button('button_continue.gif',IMAGE_CONTINUE) . '</a>'; ?>
				</td>
			</tr>
	</table>
	</td>
	</tr>
	</table>
	<?php
	
	}

	function load_customer($search='',$cID=''){
	global $customers_page,$HTTP_GET_VARS;	
	$customers_search_criteria="";
		$search_criteria="";
		if($cID!='' && $HTTP_GET_VARS['action']=='edit')
			$customers_search_criteria.="where c.customers_id='$cID' ";
		if($search!='')
			$search_criteria.="where (customers_lastname like '%" . tep_db_input($search) . "%' or customers_firstname like '%" . tep_db_input($search) . "%' or customers_email_address like '%" . tep_db_input($search) . "%' ) ";
	//$customers_query_raw = "select c.customers_id, LTRIM(c.customers_lastname) as customers_lastname, LTRIM(c.customers_firstname) as customers_firstname, c.customers_email_address, c.is_blocked, a.entry_country_id from " . TABLE_CUSTOMERS . " c left join " . TABLE_ADDRESS_BOOK . " a on c.customers_id = a.customers_id and c.customers_default_address_id = a.address_book_id " . $search_criteria . $customers_search_criteria . " group by c.customers_id order by c.customers_id DESC, concat(customers_lastname,' ',customers_firstname)";
	$customers_query_raw = "select c.customers_id, LTRIM(c.customers_lastname) as customers_lastname, LTRIM(c.customers_firstname) as customers_firstname, c.customers_email_address, c.is_blocked, a.entry_country_id from " . TABLE_CUSTOMERS . " c left join " . TABLE_ADDRESS_BOOK . " a on c.customers_id = a.customers_id and c.customers_default_address_id = a.address_book_id " . $search_criteria . $customers_search_criteria . " group by c.customers_id order by  concat(c.customers_lastname,' ',c.customers_firstname),c.customers_username";
	//echo $customers_query_raw;
	$customers_split = new splitPageResultsEvent($customers_page, MAX_DISPLAY_SEARCH_RESULTS, $customers_query_raw, $customers_numrows);	    
    $customers_query = tep_db_query($customers_query_raw);	
	echo '<table width="100%" cellpadding="0" cellspacing="0" border="0">';
	$cnt=0;
		if(tep_db_num_rows($customers_query)<=0)
			echo '<tr><td style="color:#FF0000;" align="center">'.TEXT_NO_RECORDS_FOUND.'</td></tr>';
		while($customers_array=tep_db_fetch_array($customers_query)){
		$customers_id=$customers_array['customers_id'];
		$class_name=($cnt%2==0)?'dataTableRowEven':'dataTableRowOdd';
		$customers_info_query=tep_db_query('select customers_info_date_account_last_modified as last_modified from '.TABLE_CUSTOMERS_INFO." where customers_info_id='$customers_id'");
		$customers_info_array=tep_db_fetch_array($customers_info_query);
		?>
		<tr>
		<td style="padding-left:10px; padding-bottom:5px;" width="100%">
		<div onClick="load_customers_details(<?php echo $customers_id; ?>)" id="customers_<?php echo $customers_id; ?>" class="<?php echo $class_name; ?>" onMouseOver="rowOverEffect(this);" onMouseOut="rowOutEffect(this);">
		<table width="100%" cellpadding="0" cellspacing="0" border="0">
		<tr>
		<td class="main" width="35%" align="left"><?php echo '<span id="customer_status">'.( ($customers_array['is_blocked']=='N')? tep_image(DIR_WS_IMAGES.'template/icon_active.gif','Block') : tep_image(DIR_WS_IMAGES.'template/icon_inactive.gif','UnBlock') ).'</span>&nbsp;&nbsp;'.$customers_array['customers_lastname']; ?></td>
		<td class="main" width="35%" align="left"><?php echo $customers_array['customers_firstname']; ?></td>
		<td class="main" width="30%" align="left"><?php echo format_date($customers_info_array['last_modified']); ?></td>
		</tr>
		</table>	
		</div>
		<div id="ajax_customers_<?php echo $customers_id; ?>">
		</div>
		</td>
		</tr>
		<?php	
		}
		if($customers_numrows>1) {
		echo '<tr><td><table width="100%" cellpadding="0" cellspacing="0" border="0"><tr><td style="padding-left:10px;" class="smallText" width="50%">'.
		 $customers_split->display_count($customers_numrows, MAX_DISPLAY_SEARCH_RESULTS, $customers_page, TEXT_DISPLAY_NUMBER_OF_CUSTOMERS).
		 '</td><td width="50%" class="smallText" align="right">'.
		 $customers_split->display_script_links($customers_numrows, MAX_DISPLAY_SEARCH_RESULTS, MAX_DISPLAY_PAGE_LINKS, $customers_page,1,'customers_page_navigation(\'\'','1').
		 '<td></tr></table></td></tr>';
	 }
	echo '</table>';
	}
	
	
	function load_customers_details($customers_id){
		global $HTTP_GET_VARS,$smode;

	$customers_query = tep_db_query("select c.customers_id, c.customers_gender, LTRIM(c.customers_firstname) as customers_firstname, LTRIM(c.customers_lastname) as customers_lastname, c.customers_dob, c.customers_email_address, c.customers_second_email_address,c.customers_password,a.entry_company, a.entry_street_address, a.entry_suburb, a.entry_postcode, a.entry_city, a.entry_state, c.customers_type,c.is_blocked,
	                                 a.entry_zone_id, a.entry_country_id, c.customers_telephone, c.customers_second_telephone,c.customers_fax, c.customers_newsletter,c.customers_subscription_newsletter,c.customers_reserve_newsletter,c.customers_default_address_id,c.customers_groups_id,c.customers_discount,c.customers_username,c.customers_occupation,c.suspend_from,c.resume_from,c.customers_interest from " . TABLE_CUSTOMERS . " c left join " . TABLE_ADDRESS_BOOK . 
					 " a on c.customers_default_address_id = a.address_book_id where a.customers_id = c.customers_id and c.customers_id = '" . (int)$customers_id . "' order by concat(c.customers_lastname,' ',c.customers_firstname),c.customers_username");

        $customers = tep_db_fetch_array($customers_query); 
		if (!is_array($customers)) $customers=array();
        $cInfo = new objectInfo($customers);
		
	 $info_query = tep_db_query("select customers_info_date_account_created as date_account_created, customers_info_date_account_last_modified as date_account_last_modified, customers_info_date_of_last_logon as date_last_logon, customers_info_number_of_logons as number_of_logons from " . TABLE_CUSTOMERS_INFO . " where customers_info_id = '" .(int)$customers['customers_id'] . "'");
	$info = tep_db_fetch_array($info_query);

	$country_query = tep_db_query("select countries_name from " . TABLE_COUNTRIES . " where countries_id = '" . (int)$customers['entry_country_id'] . "'");
	$country = tep_db_fetch_array($country_query);
		
    $reviews_query = tep_db_query("select count(*) as number_of_reviews from " . TABLE_REVIEWS . " where customers_id = '" . (int)$customers['customers_id'] . "'");
	$reviews = tep_db_fetch_array($reviews_query);	

	$customer_info = array_merge((array)$country, (array)$info, (array)$reviews);
	
	$cInfo_array = array_merge($customers, (array)$customer_info);
	$cInfo = new objectInfo($cInfo_array);
	?>
	<table border="0" cellpadding="0" cellspacing="0" width="100%" class="openContent">
	<tr class="openContent_top">
	<td width="400" class="main"><?php echo ( ($cInfo->is_blocked=='N')?'<a href="javascript: block_customer('.$cInfo->customers_id.',\'Y\');">'.tep_image(DIR_WS_IMAGES.'template/icon_active.gif','Block'):'<a href="javascript: block_customer('.$cInfo->customers_id.',\'N\')">'.tep_image(DIR_WS_IMAGES.'template/icon_inactive.gif','UnBlock') ) .'</a>&nbsp;&nbsp;'.$cInfo->customers_lastname.'&nbsp;'.$cInfo->customers_firstname; ?></td>
	<td  width="100" align="center">
	<table style="background:#DEE4F5;" width="100%" border="0" cellpadding="0" id="header_operation_id" cellspacing="0">
	<tr id="img_ids">
	<td class="cell_bg_popm_left" width="10">&nbsp;</td>
	<?php echo '<td style="cursor:pointer;" width="10%" OnClick="javascript:do_hover_change(this,1); edit_customer('.$cInfo->customers_id.');" onMouseOver="javascript:do_hover_change(this,2);" onMouseOut="javascript:do_hover_change(this,3);"><img alt="Edit" title="Edit" src="images/template/img_edit.gif"></td>'; ?>
	<?php echo '<td style="cursor:pointer;" width="10%" OnClick="javascript:do_hover_change(this,1); delete_customer('.$cInfo->customers_id.');" onMouseOver="javascript:do_hover_change(this,2);" onMouseOut="javascript:do_hover_change(this,3);"><img alt="Delete" title="Delete" src="images/template/img_trash.gif"></td>'; ?>
	<?php if(tep_payment_installed('wallet.php')){
	echo '<td style="cursor:pointer;" width="10%" OnClick="javascript:do_hover_change(this,1); customers_payment_wallet('.$cInfo->customers_id.');" onMouseOver="javascript:do_hover_change(this,2);" onMouseOut="javascript:do_hover_change(this,3);"><img alt="Wallet" title="Wallet" src="images/template/img_copy.gif"></td>'; 
	//echo '<td width="10%"><a href="'.tep_href_link(FILENAME_WALLET_CONFIRMATION,'page=' . $HTTP_GET_VARS['page'] . '&cID=' . $cInfo->customers_id).'"  onMouseOver="do_hover_change(this,2);" onMouseOut="do_hover_change(this,3);">'.tep_image(DIR_WS_IMAGES.'template/img_copy.gif','Wallet').'</a></td>'; ?>
	<?php }
	echo '<td style="cursor:pointer;" width="10%" OnClick="customer_mail('.$cInfo->customers_id.');" onMouseOver="javascript:do_hover_change(this,2);" onMouseOut="javascript:do_hover_change(this,3);"><img alt="Mail" title="Mail" src="images/template/mail.gif"></td>'; 
	echo '<td width="10%"><a onMouseOver="javascript:do_hover_change2(this,2);" onMouseOut="javascript:do_hover_change2(this,1);" href="' . tep_href_link(FILENAME_CREATE_ORDER_NEW,'page=' . $HTTP_GET_VARS['page'] . '&cID=' . $cInfo->customers_id). '">' . tep_image(DIR_WS_IMAGES.'template/img_sms.gif',IMAGE_CREATE_ORDER) . '</a></td>'; 
	echo '<td width="10%"><a onMouseOver="javascript:do_hover_change2(this,2);" onMouseOut="javascript:do_hover_change2(this,1);" href="' . tep_href_link(FILENAME_EVENTS_ID_CARD,'cID=' . $cInfo->customers_id) . '" Target="blank">'.tep_image(DIR_WS_IMAGES.'template/img_move.gif','Id Card').'</a></td>';
	?>
	<td class="cell_bg_popm_right" width="10">&nbsp;</td>
	</tr>
	<tr style="display:none;"><td colspan="7"><span id="span_edit" style="display:none"  class="openContent"></span></td></tr>
     <tr style="display:none;"><td colspan="7"><span id="span_delete" style="display:none"  class="openContent"></span></td></tr>
     <tr style="display:none;"><td colspan="7"><span id="span_copy" style="display:none"  class="openContent"></span></td></tr>	
	</table>
	</td>
	<td width="550"  align="right"><?php echo '<a id="customers_operation" style="display:none;">'.tep_image(DIR_WS_IMAGES.'template/img_savel.gif','Save','','','').'</a>'.'&nbsp;&nbsp;';
		if(isset($HTTP_GET_VARS['return']) && $HTTP_GET_VARS['return']=='cm') echo '<a id="customers_close_button" style="display:none;" href="javascript: do_close(\'' . $customers_id .'\',\'' . $HTTP_GET_VARS['page'] . '\');">'.tep_image(DIR_WS_IMAGES.'template/img_closel.gif','Close','','','').'</a>';
		else echo '<a id="customers_close_button" style="display:none;" href="javascript: close_customer();">'.tep_image(DIR_WS_IMAGES.'template/img_closel.gif','Close','','','').'</a>';
	
	 ?>&nbsp;</td>
	</tr>
		<tr>
		<td id="preview_details" style="padding-top:10px;" colspan="3" width="100%"><table width="100%" class="main" cellpadding="2" cellspacing="2" border="0">
		<tr>
		<td width="18%" align="right"><?php echo TEXT_EMAIL_ADDRESS; ?></td>
		<td width="18%" align="left"><?php echo $cInfo->customers_email_address; ?></td>
		<td width="18%" align="right"><?php echo TEXT_DATE_ACCOUNT_CREATED; ?></td>
		<td width="18%" align="left"><?php echo format_date($cInfo->date_account_created); ?></td>
		<td width="18%" align="right"><?php echo TEXT_INFO_DATE_LAST_LOGON; ?></td>
		<td width="10%" align="left"><?php echo format_date($cInfo->date_last_logon); ?></td>
		</tr>
		<tr>
		<td width="18%" align="right"><?php echo TEXT_INFO_COUNTRY; ?></td>
		<td width="18%" align="left"><?php echo $cInfo->countries_name; ?></td>
		<td width="18%" align="right"><?php echo TEXT_DATE_ACCOUNT_LAST_MODIFIED; ?></td>
		<td width="18%" align="left"><?php echo format_date($cInfo->date_account_last_modified); ?></td>
		<td width="18%" align="right"><?php echo TEXT_INFO_NUMBER_OF_LOGONS; ?></td>
		<td width="18%" align="left"><?php echo $cInfo->number_of_logons; ?></td>
		</tr>
	
		<tr>
		<td colspan="6"><table width="100%" cellpadding="2" cellspacing="2" border="0">
		<tr>
		<td align="right" style="padding-right:30px;">
		<?php 
		echo '<a href="'.tep_href_link(FILENAME_ORDERS,'cID='.$cInfo->customers_id).'">'.tep_image_button('button_orders.gif','Orders').'</a>';
		?></td>
		</tr></table></td>
		</tr>
		</table></td>
		</tr> 
	<tr>
	<td style="padding-top:10px; padding-bottom:10px;" id="ajax_load" colspan="3" class="main"></td>
	</tr>
	<tr><td colspan="3"><br></td></tr>
	</table>^^
	<table width="100%" cellpadding="0" cellspacing="0" border="0">
	<tr>
	<td class="main" width="35%" align="left"><?php echo '<span id="customer_status">'.( ($cInfo->is_blocked=='N')? tep_image(DIR_WS_IMAGES.'template/icon_active.gif') : tep_image(DIR_WS_IMAGES.'template/icon_inactive.gif') ).'</span>&nbsp;&nbsp;'.$cInfo->customers_lastname; ?></td>
	<td class="main" width="35%" align="left"><?php echo $cInfo->customers_firstname; ?></td>
	<td class="main" width="30%" align="left"><?php echo format_date($cInfo->date_account_last_modified); ?></td>
	</tr>
	</table>
	<?php //echo '<span id="customer_status">'.( ($cInfo->is_blocked=='N')? tep_image(DIR_WS_IMAGES.'template/icon_active.gif') : tep_image(DIR_WS_IMAGES.'template/icon_inactive.gif') ).'</span>&nbsp;&nbsp;'.$cInfo->customers_lastname.'&nbsp;'.$cInfo->customers_firstname; 	?>
	<?php
	} // function load_customers_details ends


	function edit_customer($customers_id){
	$customers_query = tep_db_query("select c.customers_id, c.customers_gender, LTRIM(c.customers_firstname) as customers_firstname, LTRIM(c.customers_lastname) as customers_lastname, c.customers_dob, c.customers_email_address, c.customers_second_email_address,c.customers_password,a.entry_company, a.entry_street_address, a.entry_suburb, a.entry_postcode, a.entry_city, a.entry_state, c.customers_type,c.is_blocked,
	                                 a.entry_zone_id, a.entry_country_id, c.customers_telephone, c.customers_second_telephone,c.customers_fax, c.customers_newsletter,c.customers_subscription_newsletter,c.customers_reserve_newsletter,c.customers_default_address_id,c.customers_groups_id,c.customers_discount,c.customers_username,c.customers_occupation,c.suspend_from,c.resume_from,c.customers_interest from " . TABLE_CUSTOMERS . " c left join " . TABLE_ADDRESS_BOOK . 
					 " a on c.customers_default_address_id = a.address_book_id where a.customers_id = c.customers_id and c.customers_id = '" . (int)$customers_id . "' order by concat(c.customers_lastname,' ',c.customers_firstname),c.customers_username");

    $customers = tep_db_fetch_array($customers_query); 
	if (!is_array($customers)) $customers=array();
    $cInfo = new objectInfo($customers);
	
    $newsletter_array = array(array('id' => '1', 'text' => ENTRY_NEWSLETTER_YES),
                              array('id' => '0', 'text' => ENTRY_NEWSLETTER_NO));
	?>
	<?php echo tep_draw_form('customers', FILENAME_CUSTOMERS, tep_get_all_get_params(array('action')) . 'action=update', 'post', 'onSubmit="return check_form_customer();"') . tep_draw_hidden_field('default_address_id', $cInfo->customers_default_address_id); ?>
	<table border="0" width="100%" style="padding-left:80px;" 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 ><table border="0" cellspacing="2" cellpadding="2">
<?php
    if (ACCOUNT_GENDER == 'true') {
?>
          <tr>
            <td class="main" width=180><?php echo ENTRY_GENDER; ?></td>
            <td class="main">
<?php 
    if ($error == true) {
      if ($entry_gender_error == true) {
        echo tep_draw_radio_field('customers_gender', 'm', false, $cInfo->customers_gender) . '&nbsp;&nbsp;' . MALE . '&nbsp;&nbsp;' . tep_draw_radio_field('customers_gender', 'f', false, $cInfo->customers_gender) . '&nbsp;&nbsp;' . FEMALE . '&nbsp;' . ENTRY_GENDER_ERROR;
        echo tep_draw_hidden_field('genderflag',"1");		
      } else {
        echo ($cInfo->customers_gender == 'm') ? MALE : FEMALE;
        echo tep_draw_hidden_field('customers_gender',$cInfo->customers_gender);
        echo tep_draw_hidden_field('genderflag',"0");
      }
    } else {
      echo tep_draw_radio_field('customers_gender', 'm', false, $cInfo->customers_gender) . '&nbsp;&nbsp;' . MALE . '&nbsp;&nbsp;' . tep_draw_radio_field('customers_gender', 'f', false, $cInfo->customers_gender) . '&nbsp;&nbsp;' . FEMALE  . '&nbsp;' . ENTRY_GENDER_TEXT;
      echo tep_draw_hidden_field('genderflag',"1");
    }
?></td>
          </tr>
<?php
    }
?>
          <tr>
            <td class="main"><?php echo ENTRY_FIRST_NAME; ?></td>
            <td class="main">
<?php
  if ($error == true) {
    if ($entry_firstname_error == true) {
      echo tep_draw_input_field('customers_firstname', $cInfo->customers_firstname, 'maxlength="32"') . '&nbsp;' . ENTRY_FIRST_NAME_ERROR;

    } else {
      echo $cInfo->customers_firstname . tep_draw_hidden_field('customers_firstname');
    }
  } else {
    echo tep_draw_input_field('customers_firstname', $cInfo->customers_firstname, 'maxlength="32"')  . '&nbsp;' . ENTRY_FIRST_NAME_TEXT;
  }
?></td>
          </tr>
          <tr>
            <td class="main"><?php echo ENTRY_LAST_NAME; ?></td>
            <td class="main">
<?php
  if ($error == true) {
    if ($entry_lastname_error == true) {
      echo tep_draw_input_field('customers_lastname', $cInfo->customers_lastname, 'maxlength="32"') . '&nbsp;' . ENTRY_LAST_NAME_ERROR;
    } else {
      echo $cInfo->customers_lastname . tep_draw_hidden_field('customers_lastname');
    }
  } else {
    echo tep_draw_input_field('customers_lastname', $cInfo->customers_lastname, 'maxlength="32"')  . '&nbsp;' . ENTRY_LAST_NAME_TEXT;
  }
?></td>
          </tr>
<?php 
    if (ACCOUNT_DOB == 'true') {
?>
          <tr>
            <td class="main"><?php echo ENTRY_DATE_OF_BIRTH; ?></td>
            <td class="main">

<?php
    if ($error == true) {
      if ($entry_date_of_birth_error == true) {
        echo tep_draw_input_field('customers_dob', $cInfo->customers_dob, 'maxlength="10"') . '&nbsp;' . ENTRY_EVENT_DATE_OF_BIRTH_ERROR;
      } else {
        echo $cInfo->customers_dob . tep_draw_hidden_field('customers_dob');
      }
    } else {
      echo tep_draw_input_field('customers_dob', format_date($cInfo->customers_dob), 'maxlength="10"')  . '&nbsp;' . ENTRY_EVENT_DATE_OF_BIRTH_TEXT;
    }
?></td>
          </tr>
<?php
    }
?>
<?php
    if (ACCOUNT_USERNAME == 'true') {
?>
          <tr>
            <td class="main"><?php echo ENTRY_USERNAME; ?></td>
            <td class="main">
<?php
  if ($error == true) {
    if ($entry_username_error == true) {
      echo tep_draw_input_field('customers_username', $cInfo->customers_username, 'maxlength="20"') . '&nbsp;' . ENTRY_USERNAME_ERROR;
    } elseif ($entry_username_exists == true) {
      echo tep_draw_input_field('customers_username', $cInfo->customers_username, 'maxlength="20"') . '&nbsp;' . ENTRY_USERNAME_ERROR_EXISTS;	  
    } else {
      echo $customers_username . tep_draw_hidden_field('customers_username');
    }
  } else {
    echo tep_draw_input_field('customers_username', $cInfo->customers_username, 'maxlength="20"') . '&nbsp;' . ENTRY_USERNAME_TEXT;
  }
?></td>
          </tr>
<?php }?>
          <tr>
            <td class="main"><?php echo ENTRY_EMAIL_ADDRESS; ?></td>
            <td class="main">
<?php  
$con_email=false;
	   $er=ENTRY_EMAIL_ADDRESS_ERROR;
	   if($entry_email_address_check_match_error) $er=JS_EMAIL_CONFIRM_ADDRESS;
  if ($error == true) {
    if ($entry_email_address_error == true || $entry_email_address_check_match_error) {
      echo tep_draw_input_field('customers_email_address', $cInfo->customers_email_address, 'maxlength="96"') . '&nbsp;' . $er;
    } elseif ($entry_email_address_check_error == true) {
      echo tep_draw_input_field('customers_email_address', $cInfo->customers_email_address, 'maxlength="96"') . '&nbsp;' . ENTRY_EMAIL_ADDRESS_CHECK_ERROR;
	  
    } elseif ($entry_email_address_exists == true) {
      echo tep_draw_input_field('customers_email_address', $cInfo->customers_email_address, 'maxlength="96"') . '&nbsp;' . ENTRY_EMAIL_ADDRESS_ERROR_EXISTS;
	  
    } else {
      echo $customers_email_address . tep_draw_hidden_field('customers_email_address');
      $con_email=true;	
    } 
  } else {
    echo tep_draw_input_field('customers_email_address', $cInfo->customers_email_address, 'maxlength="96"') . '&nbsp;' . ENTRY_EMAIL_ADDRESS_TEXT;
  }
?></td>
          </tr>
<?php 
   if (ACCOUNT_SECOND_EMAIL=='true') {
?>
          <tr>
            <td class="main"><?php echo ENTRY_SECOND_EMAIL_ADDRESS; ?></td>
            <td class="main">
<?php $con_sec_email=false;
  if ($error == true) {
  	  $er=ENTRY_SECOND_EMAIL_ADDRESS_ERROR;
  	 if($entry_second_email_address_match_error) $er=ENTRY_SECOND_EMAIL_ADDRESS_MATCH_ERROR; 
    if ($entry_second_email_address_error == true || $entry_second_email_address_match_error==true) {
      echo tep_draw_input_field('customers_second_email_address', $cInfo->customers_second_email_address, 'maxlength="96"') . '&nbsp;' . $er;	 
    } elseif ($entry_second_email_address_check_error == true) {
      echo tep_draw_input_field('customers_second_email_address', $cInfo->customers_second_email_address, 'maxlength="96"') . '&nbsp;' . ENTRY_SECOND_EMAIL_ADDRESS_CHECK_ERROR;	  
    } elseif ($entry_second_email_address_exists == true) {
      echo tep_draw_input_field('customers_second_email_address', $cInfo->customers_second_email_address, 'maxlength="96"') . '&nbsp;' . ENTRY_SECOND_EMAIL_ADDRESS_ERROR_EXISTS;	  
    } else {
    	$con_sec_email=true;
      echo $customers_second_email_address . tep_draw_hidden_field('customers_second_email_address');
    }
  } else {
    echo tep_draw_input_field('customers_second_email_address', $cInfo->customers_second_email_address, 'maxlength="96"');
  }
?></td>
          </tr>		         
<?php } ?>
       <tr>
            <td class="main"><?php echo ENTRY_PASSWORD; ?></td>
            <td class="main"><Table><tr><td>
<?php
  if ($error == true) {
    if ($entry_password_error == true) {
      echo tep_draw_input_field('customers_password', '*****', 'maxlength="40" onKeyUp=javascript:do_pwd_check(this);') . '&nbsp;' . ENTRY_FIRST_NAME_ERROR;	  
    }
	elseif ($entry_password_strength_error == true) {
      echo tep_draw_input_field('customers_password', '*****', 'maxlength="40" onKeyUp=javascript:do_pwd_check(this);') . '&nbsp;' . ENTRY_PASSWORD_STRENGTH_ERROR;
	  
  } else {
      echo $cInfo->customers_password . tep_draw_hidden_field('customers_password');
    }
  } else {
    echo tep_draw_input_field('customers_password', '*****', 'maxlength="40" onKeyUp="javascript:do_pwd_check(this);" onfocus="this.value=\'\'"; onblur="if (this.value==\'\') this.value=\'*****\';"', false);
  }
?></td><td id='pwd_str' style="font-color:red;font-size:14"></td></tr></table>
</td>
          </tr>
        </table></td>
      </tr>
	   <?php tep_content_title_bottom(); ?>
<?php
    if (ACCOUNT_COMPANY == 'true') {
?>
	  <?php tep_content_title_top(CATEGORY_COMPANY); ?>
      <tr>
        <td><table border="0" cellspacing="2" cellpadding="2">
          <tr>
            <td class="main" width="180"><?php echo ENTRY_COMPANY; ?></td>
            <td class="main">
<?php
    if ($error == true) {
      if ($entry_company_error == true) {
        echo tep_draw_input_field('entry_company', $cInfo->entry_company, 'maxlength="32"') . '&nbsp;' . ENTRY_COMPANY_ERROR;		
      } else {
        echo $cInfo->entry_company . tep_draw_hidden_field('entry_company');
      }
    } else {
      echo tep_draw_input_field('entry_company', $cInfo->entry_company, 'maxlength="32"') . '&nbsp;' . ENTRY_COMPANY_TEXT;
    }
?></td>
          </tr>
        </table></td>
      </tr>
<?php tep_content_title_bottom();
    } 
?>
	  <?php tep_content_title_top(CATEGORY_ADDRESS); ?>
      <tr>
        <td ><table border="0" cellspacing="2" cellpadding="2">
          <tr>
            <td class="main" width=180><?php echo ENTRY_STREET_ADDRESS; ?></td>
            <td class="main">
<?php
  if ($error == true) {
    if ($entry_street_address_error == true) {
      echo tep_draw_input_field('entry_street_address', $cInfo->entry_street_address, 'maxlength="64"') . '&nbsp;' . ENTRY_STREET_ADDRESS_ERROR;	  
    } else {
      echo $cInfo->entry_street_address . tep_draw_hidden_field('entry_street_address');
    }
  } else {
    echo tep_draw_input_field('entry_street_address', $cInfo->entry_street_address, 'maxlength="64"')  . '&nbsp;' . ENTRY_STREET_ADDRESS_TEXT;
  }
?></td>
          </tr>
<?php
    if (ACCOUNT_SUBURB == 'true') {
?>
          <tr>
            <td class="main"><?php echo ENTRY_SUBURB; ?></td>
            <td class="main">
<?php
    if ($error == true) {
      if ($entry_suburb_error == true) {
        echo tep_draw_input_field('suburb', $cInfo->entry_suburb, 'maxlength="32"') . '&nbsp;' . ENTRY_SUBURB_ERROR;		
      } else {
        echo $cInfo->entry_suburb . tep_draw_hidden_field('entry_suburb');
      }
    } else {
      echo tep_draw_input_field('entry_suburb', $cInfo->entry_suburb, 'maxlength="32"')  . '&nbsp;' . ENTRY_SUBURB_TEXT;
    }
?></td>
          </tr>
<?php
    }
?>
          <tr>
            <td class="main"><?php echo ENTRY_POST_CODE; ?></td>
            <td class="main">
<?php
  if ($error == true) {
    if ($entry_post_code_error == true) {
      echo tep_draw_input_field('entry_postcode', $cInfo->entry_postcode, 'maxlength="8"') . '&nbsp;' . ENTRY_POST_CODE_ERROR;	  
    } else {
      echo $cInfo->entry_postcode . tep_draw_hidden_field('entry_postcode');
    }
  } else {
    echo tep_draw_input_field('entry_postcode', $cInfo->entry_postcode, 'maxlength="8"')  . '&nbsp;' . ENTRY_POST_CODE_TEXT;
  }
?></td>
          </tr>
          <tr>
            <td class="main"><?php echo ENTRY_CITY; ?></td>
            <td class="main">
<?php
  if ($error == true) {
    if ($entry_city_error == true) {
      echo tep_draw_input_field('entry_city', $cInfo->entry_city, 'maxlength="32"') . '&nbsp;' . ENTRY_CITY_ERROR;	  
    } else {
      echo $cInfo->entry_city . tep_draw_hidden_field('entry_city');
    }
  } else {
    echo tep_draw_input_field('entry_city', $cInfo->entry_city, 'maxlength="32"')  . '&nbsp;' . ENTRY_CITY_TEXT;
  }
?></td>
          </tr>
         
          <tr>
            <td class="main"><?php echo ENTRY_COUNTRY; ?></td>
            <td class="main">
<?php
  if ($error == true) {
    if ($entry_country_error == true) { // onchange="javascript:show_state();"
      echo tep_draw_pull_down_menu('entry_country_id', tep_get_countries(), $cInfo->entry_country_id,'onchange="javascript:show_state();"') . '&nbsp;' . ENTRY_COUNTRY_ERROR;
	  
    } else {
      echo tep_get_country_name($cInfo->entry_country_id) . tep_draw_hidden_field('entry_country_id');
    }
  } else { // onchange="javascript:show_state();"
    echo tep_draw_pull_down_menu('entry_country_id', tep_get_countries(), $cInfo->entry_country_id,'onchange="javascript:show_state();"')  . '&nbsp;' . ENTRY_COUNTRY_TEXT;
  }
?></td>
          </tr>
  	 <?php
    if (ACCOUNT_STATE == 'true') {  
	?>
 		<tr>
            <td class="main"><?php echo ENTRY_STATE; ?></td>
            <td class="main">
	<?php
 	   /*$zones_query = tep_db_query("select zone_id,zone_name from " . TABLE_ZONES . " where zone_country_id = '" . tep_db_input($cInfo->entry_country_id) . "' order by zone_name");
 	   if($cInfo->entry_zone_id)
 	   	$entry_state = base_sbs_get_zone_name($cInfo->entry_country_id, $cInfo->entry_zone_id);
 	   if($cInfo->entry_state) $entry_state=$cInfo->entry_state; 
 	  	while ($zones_values = tep_db_fetch_array($zones_query)) {
	      $zones_array[]=array('id'=>$zones_values['zone_name'],'text'=>$zones_values['zone_name']);
	   }
 	   if($action!='update'){  
 	  		 echo tep_draw_pull_down_menu('entry_state',array(),'','style="display:none"').' '.tep_draw_input_field('entry_state1',$entry_state);
 	   }else if($entry_state=='' && $action=='update' || $entry_state_error){
	 	   	echo tep_draw_pull_down_menu('entry_state',$zones_array).' ' .ENTRY_STATE_ERROR;
 	   } else {
 	 		echo $entry_state . 	tep_draw_hidden_field('entry_zone_id').tep_draw_hidden_field('entry_state');
 	   }*/	   
 	   $zones_query = tep_db_query("select zone_id,zone_name from " . TABLE_ZONES . " where zone_country_id = '" . tep_db_input($cInfo->entry_country_id) . "' order by zone_name");
 	   if($cInfo->entry_zone_id)
 	   	$entry_state = base_sbs_get_zone_name($cInfo->entry_country_id, $cInfo->entry_zone_id);
 	   if($cInfo->entry_state) $entry_state=$cInfo->entry_state; 
 	  	while ($zones_values = tep_db_fetch_array($zones_query)) {
	      $zones_array[]=array('id'=>$zones_values['zone_name'],'text'=>$zones_values['zone_name']);
	   }
	   $style_c='style="display:none"';
	   $style_t='';
       if(count($zones_array)>0) {
	   	$style_c='';
	    $style_t='style="display:none"';
	   }	   
	 	echo tep_draw_pull_down_menu('entry_state',$zones_array,$entry_state,$style_c). tep_draw_input_field('entry_state1',$entry_state,$style_t) .' ' . ENTRY_STATE_TEXT;
  ?></td>
  
  </tr>
	<?php
    }
	?>
     </table></td>
    </tr>
	<?php tep_content_title_bottom(); ?>
      <?php tep_content_title_top(CATEGORY_CONTACT); ?> 
      
      <tr>
        <td ><table border="0" cellspacing="2" cellpadding="2">
<?php if (ACCOUNT_TELEPHONE=="true") {?>
          <tr>
            <td class="main" width="180"><?php echo ENTRY_TELEPHONE_NUMBER; ?></td>
            <td class="main">
<?php
  if ($error == true) {
    if ($entry_telephone_error == true) {
      echo tep_draw_input_field('customers_telephone', $cInfo->customers_telephone, 'maxlength="32"') . '&nbsp;' . ENTRY_TELEPHONE_NUMBER_ERROR;
	  
    } else {
      echo $cInfo->customers_telephone . tep_draw_hidden_field('customers_telephone');
    }
  } else {
    echo tep_draw_input_field('customers_telephone', $cInfo->customers_telephone, 'maxlength="32"')  . '&nbsp;' . ENTRY_TELEPHONE_NUMBER_TEXT;
  }
?></td>
          </tr>
<?php 
   }
   if (ACCOUNT_SECOND_PHONE=='true') {
?>
          <tr>
            <td class="main"><?php echo ENTRY_SECOND_TELEPHONE_NUMBER; ?></td>
            <td class="main">
<?php
  if ($error == true) {
    if ($entry_second_telephone_error == true) {
      echo tep_draw_input_field('customers_second_telephone', $cInfo->customers_second_telephone, 'maxlength="32"') . '&nbsp;' . ENTRY_SECOND_TELEPHONE_NUMBER_ERROR;
	  
    } else {
      echo $cInfo->customers_second_telephone . tep_draw_hidden_field('customers_second_telephone');
    }
  } else {
    echo tep_draw_input_field('customers_second_telephone', $cInfo->customers_second_telephone, 'maxlength="32"', false);
  }
?></td>
          </tr>
<?php 
  } 
  ?>	  
          <tr>
            <td class="main"><?php echo ENTRY_MOBILE_NUMBER; ?></td>
            <td class="main">
<?php
  if ($error == true) {
    if ($entry_mobile_error == true) {
      echo tep_draw_input_field('customers_mobile', $cInfo->customers_mobile, 'maxlength="32"') . '&nbsp;' . ENTRY_MOBILE_NUMBER_ERROR;
    } else {
      echo $cInfo->customers_mobile . tep_draw_hidden_field('customers_mobile');
    }
  } else {
    echo tep_draw_input_field('customers_mobile', $cInfo->customers_fax, 'maxlength="32"', false) . '&nbsp;' . ENTRY_MOBILE_NUMBER_TEXT;
  }
?></td>
          </tr>
        </table></td>
      </tr>
	  <?php tep_content_title_bottom(); ?>
	  <?php tep_content_title_top(CATEGORY_OPTIONS); ?>
      <tr>
        <td ><table border="0" cellspacing="2" cellpadding="2">
		<?php 
		if (ACCOUNT_NEWSLETTER=='true'){?>
          <tr>
            <td class="main" width="220"><?php echo ENTRY_NEWSLETTER; ?></td>
            <td class="main">
<?php
  if ($processed == true) {
    if ($cInfo->customers_newsletter == '1') {
      echo ENTRY_NEWSLETTER_YES;
    } else {
      echo ENTRY_NEWSLETTER_NO;
    }
    echo tep_draw_hidden_field('customers_newsletter');
  } else {
    echo tep_draw_pull_down_menu('customers_newsletter', $newsletter_array, (($cInfo->customers_newsletter == '1') ? '1' : '0'));
  }
?></td>
      </tr>
	  <?php } 
	  if (ACCOUNT_RESERVATION_NEWSLETTER =='true'){ ?>
          <tr>
            <td class="main"><?php echo ENTRY_RESERVE_NEWSLETTER; ?></td>
            <td class="main">
<?php
  if ($processed == true) {
    if ($cInfo->customers_reserve_newsletter == '1') {
      echo ENTRY_NEWSLETTER_YES;
    } else {
      echo ENTRY_NEWSLETTER_NO;
    }
    echo tep_draw_hidden_field('customers_reserve_newsletter');
  } else {
    echo tep_draw_pull_down_menu('customers_reserve_newsletter', $newsletter_array, (($cInfo->customers_reserve_newsletter == '1') ? '1' : '0'));
  }
?></td>
      </tr>
	  <?php }
	 if (ACCOUNT_SUBSCRIPTION_NEWSLETTER=='true'){ ?>
	  <tr>
	  	<td class="main"><?php echo SUBSCRIPTION_NEWSLETTER;?></td>
		<td class="main">
		<?php
  if ($processed == true) {
    if ($cInfo->customers_subscription_newsletter == '1') {
      echo ENTRY_NEWSLETTER_YES;
    } else {
      echo ENTRY_NEWSLETTER_NO;
    }
    echo tep_draw_hidden_field('customers_subscription_newsletter');
  } else {
    echo tep_draw_pull_down_menu('customers_subscription_newsletter', $newsletter_array, (($cInfo->customers_subscription_newsletter == '1') ? '1' : '0'));
  }
?></td>

	  </tr>
<?php } ?>
<tr>
	<td><?php echo tep_draw_separator('pixel_trans.gif',1,10);?></td>
</tr>
<?php if (HIDE_CUSTOMER_OCCUPATION_BACK=='false'){ ?>
	<tr>
		<td class="main"><?php echo ENTRY_CUSTOMER_OCCUPATION; ?></td>
		<td class="main"><?php echo tep_draw_pull_down_menu('customers_occupation',tep_get_customer_options('O'),$cInfo->customers_occupation) . '&nbsp;' . ENTRY_CUSTOMER_OCCUPATION_TEXT; ?></td>
	</tr>
<?php } 
if (HIDE_CUSTOMER_INTEREST_BACK=='false'){
?>
	<tr>
		<td class="main"><?php echo ENTRY_CUSTOMER_INTEREST; ?></td>
		<td class="main"><?php echo tep_draw_pull_down_menu('customers_interest',tep_get_customer_options('I'),$cInfo->customers_interest) . '&nbsp;' . ENTRY_CUSTOMER_INTEREST_TEXT; ?></td>
	</tr>
<?php } ?>
     <!--CGDiscountSpecials start-->
	 <tr>
        <td class="main"><?php echo ENTRY_CUSTOMERS_DISCOUNT; ?></td>
        <td class="main">
              <select name="customers_discount_sign">
                 <option name="minus" value="-" <?php if (strstr($cInfo->customers_discount,"-")) echo "selected=\"selected\"" ?>>-</option>
                 <option name="plus" value="+" <?php if (strstr($cInfo->customers_discount,"+")) echo "selected=\"selected\"" ?>>+</option>
             </select>&nbsp;<?php echo tep_draw_input_field('customers_discount', substr($cInfo->customers_discount,1,strlen($cInfo->customers_discount)), 'maxlength="9"'); ?>&nbsp;%
       
<!--              </select>&nbsp;<?php //echo tep_draw_input_field('customers_discount', $cInfo->customers_discount, 'maxlength="9"'); ?>&nbsp;%
-->	    </td>
     </tr>
	 <tr>
       <td class="main"><?php echo ENTRY_CUSTOMERS_GROUPS_NAME; ?></td>
         <?php 
             $groups_query = tep_db_query("select customers_groups_id, customers_groups_name from " . TABLE_CUSTOMERS_GROUPS ." order by customers_groups_name");
             while($groups = tep_db_fetch_array($groups_query)) {
                $groups_array[] = array('text' => $groups['customers_groups_name'],
                                        'id' => $groups['customers_groups_id']);
             }
         ?>
        <td class="main"><?php echo tep_draw_pull_down_menu('customers_groups_id', $groups_array, $customers['customers_groups_id']); ?></td>
     </tr>
     <!--CGDiscountSpecials end-->
	 <?php 
	 	echo '<input type="hidden" name="currend_date" id="currend_date" value="' . tep_output_string(date(EVENTS_DATE_FORMAT)) . '">';
	 	$_array=array('d','m','Y');  $replace_array=array('DD','MM','YYYY'); 	$date_format=str_replace($_array,$replace_array,EVENTS_DATE_FORMAT);
	 ?>
	 <tr>
	  <td nowrap="nowrap"  class="main"><?php echo TEXT_SUSPEND_DATE ;?><small>(<?php echo $date_format;?>)</small></td>
	 <td class="main" ><?php echo tep_draw_input_field("txt_suspend_date",format_date($cInfo->suspend_from),"size=10",false,'text',false);
	 ?>
							<a href="javascript:show_calendar('customers.txt_suspend_date',null,null,'<?php echo $date_format; ?>');"
							onmouseover="window.status='Date Picker';return true;"
							onmouseout="window.status='';return true;"><img border="none" src="images/icon_calendar.gif"/>  
							</a>
		</td>
		</tr>
		<tr>
			<td nowrap="nowrap" class="main" ><?php echo TEXT_RESUME_DATE; ?><small>(<?php echo $date_format;?>)</small></td>
			<td class="main"><?php echo tep_draw_input_field("txt_resume_date",format_date($cInfo->resume_from),"size=10",false,'text',false);?>
							<a href="javascript:show_calendar('customers.txt_resume_date',null,null,'<?php echo $date_format; ?>');"
							onmouseover="window.status='Date Picker';return true;"
							onmouseout="window.status='';return true;"><img border="none" src="images/icon_calendar.gif"/>  
							</a>
						</td>
	 </tr>
     <tr>
      <td class="main">
<?php
  if ($processed==true){
     echo $cInfo->customers_type . tep_draw_hidden_field('customers_type') . '&nbsp;' . ENTRY_VIP_CUSTOMER;
  }else{
     echo tep_draw_checkbox_field('customers_type', 'V', ($cInfo->customers_type=='V'?true:false)) . '&nbsp;' . ENTRY_VIP_CUSTOMER;
  }  
?>
      </td>
	  <td class="main">
      <?php echo tep_draw_checkbox_field('is_blocked', 'Y', ($cInfo->is_blocked=='Y'?true:false)) . '&nbsp;' . ENTRY_BLOCKED_CUSTOMER;?>
	  </td>
      </tr>

        </table></td>
      </tr>
	  <?php tep_content_title_bottom(); ?>
      <tr>
        <td class="main" align="left">
		<?php 
			echo tep_draw_separator('pixel_trans.gif', '1', '10'); 
			?>
		</td>
      </tr>
      <tr>
	  	<td>
		<table border="0" cellpadding="0" cellspacing="0" width="100%">
			<tr>
				<td class="main" align="left">
				<?php
					$return=isset($HTTP_GET_VARS["return"])?$HTTP_GET_VARS["return"]:'';
					$type=isset($HTTP_GET_VARS['type'])?$HTTP_GET_VARS['type']:'';
					if ($return!=""){
						echo '<a href="' . (($type=='ser')?tep_get_service_report_name($return):tep_get_report_name($return)) . '">' . tep_image_button("button_back.gif",IMAGE_BACK) . '</a>&nbsp;';
					}
				?>
				</td>
				<td align="right" class="main">
				<?php 
				
					//echo tep_image_submit('button_update.gif', IMAGE_UPDATE) . ' <a href="' . tep_href_link(FILENAME_CUSTOMERS, tep_get_all_get_params(array('action'))) .'">' . tep_image_button('button_cancel.gif', IMAGE_CANCEL) . '</a>'; 
				?>
			</form></td>
			</tr>
		</table>
	</td></tr></table>
	<?php
	} // function edit customer ends
	function update_customer(){
	global $HTTP_GET_VARS,$HTTP_POST_VARS;	
	 $error_result="";
	 $customers_id = tep_db_prepare_input($HTTP_GET_VARS['customers_id']);
	$customers_firstname = tep_db_prepare_input($HTTP_POST_VARS['customers_firstname']);
	$customers_lastname = tep_db_prepare_input($HTTP_POST_VARS['customers_lastname']);
	  $customers_username = tep_db_prepare_input($HTTP_POST_VARS['customers_username']);
	  $customers_email_address = tep_db_prepare_input($HTTP_POST_VARS['customers_email_address']);
	 // $customers_confirm_email_address = tep_db_prepare_input($HTTP_POST_VARS['customers_confirm_email_address']);
	  $customers_password = tep_db_prepare_input($HTTP_POST_VARS['customers_password']);
	  $customers_second_email_address = tep_db_prepare_input($HTTP_POST_VARS['customers_second_email_address']);
	 // if($customers_second_email_address!='')$customers_second_confirm_email_address = tep_db_prepare_input($HTTP_POST_VARS['customers_second_confirm_email_address']);
	$customers_telephone = tep_db_prepare_input($HTTP_POST_VARS['customers_telephone']);
	$customers_second_telephone = tep_db_prepare_input($HTTP_POST_VARS['customers_second_telephone']);
	$customers_mobile = tep_db_prepare_input($HTTP_POST_VARS['customers_mobile']);
	  $customers_occupation=tep_db_prepare_input($HTTP_POST_VARS['customers_occupation']);
	  $customers_interest=tep_db_prepare_input($HTTP_POST_VARS['customers_interest']);
	  // check for newsletter is active or not
	//CGDiscountSpecials start
	  $customers_discount_sign = tep_db_prepare_input($HTTP_POST_VARS['customers_discount_sign']);
	  $customers_discount = tep_db_prepare_input($HTTP_POST_VARS['customers_discount']);
	  $customers_groups_id = tep_db_prepare_input($HTTP_POST_VARS['customers_groups_id']); 
	//CGDiscountSpecials end
	  $newsletter = tep_db_prepare_input($HTTP_POST_VARS['customers_newsletter']);
	  $reserve_newsletter = tep_db_prepare_input($HTTP_POST_VARS['customers_reserve_newsletter']);
	  $subscription_newsletter = tep_db_prepare_input($HTTP_POST_VARS['customers_subscription_newsletter']);
	 $suspend_from=isset($HTTP_POST_VARS['txt_suspend_date'])?tep_convert_date_raw(tep_db_prepare_input($HTTP_POST_VARS['txt_suspend_date'])):'0000-00-00';
	 $resume_from=isset($HTTP_POST_VARS['txt_resume_date'])?tep_convert_date_raw(tep_db_prepare_input($HTTP_POST_VARS['txt_resume_date'])):'0000-00-00';	
	$customers_gender = tep_db_prepare_input($HTTP_POST_VARS['customers_gender']);
	$customers_dob = tep_db_prepare_input($HTTP_POST_VARS['customers_dob']);
	$customers_type=($HTTP_POST_VARS['customers_type']=='V'?tep_db_prepare_input($HTTP_POST_VARS['customers_type']):'D');
	$default_address_id = tep_db_prepare_input($HTTP_POST_VARS['default_address_id']);
	$entry_street_address = tep_db_prepare_input($HTTP_POST_VARS['entry_street_address']);
	$entry_suburb = tep_db_prepare_input($HTTP_POST_VARS['entry_suburb']);
	$entry_postcode = tep_db_prepare_input($HTTP_POST_VARS['entry_postcode']);
	$entry_city = tep_db_prepare_input($HTTP_POST_VARS['entry_city']);
	$entry_country_id = tep_db_prepare_input($HTTP_POST_VARS['entry_country_id']);
	$entry_company = tep_db_prepare_input($HTTP_POST_VARS['entry_company']);
	$entry_state = tep_db_prepare_input($HTTP_POST_VARS['entry_state']);
	if($entry_state=='' || $HTTP_POST_VARS['entry_state1'])$entry_state=$HTTP_POST_VARS['entry_state1'];
	  $is_blocked=($HTTP_POST_VARS['is_blocked']=='Y'?tep_db_prepare_input($HTTP_POST_VARS['is_blocked']):'N');
	  if($customers_discount=='') $customers_discount='0';
	  
	
	if (isset($HTTP_POST_VARS['entry_zone_id'])) $entry_zone_id = tep_db_prepare_input($HTTP_POST_VARS['entry_zone_id']);
	
	if (strlen($customers_firstname) < ENTRY_FIRST_NAME_MIN_LENGTH) {
	  $error = true;
	  $entry_firstname_error = true;
	  $error_result.=ENTRY_FIRST_NAME_ERROR;
	} else {
	   $entry_firstname_error = false;
	}
	
	if (strlen($customers_lastname) < ENTRY_LAST_NAME_MIN_LENGTH) {
	  $error = true;
	  $entry_lastname_error = true;
	  $error_result.='<br>'.ENTRY_LAST_NAME_ERROR;
	} else {
	  $entry_lastname_error = false;
	}

	if (ACCOUNT_DOB == 'true') {
	  if (tep_check_date_raw($customers_dob,EVENTS_DATE_FORMAT)) {
		$entry_date_of_birth_error = false;
	  } else {
		$error = true;
		$entry_date_of_birth_error = true;
		$error_result.='<br>'.ENTRY_EVENT_DATE_OF_BIRTH_ERROR;
	  }
	}

	if (ACCOUNT_USERNAME == 'true') {
		if (strlen($customers_username) < ENTRY_USERNAME_MIN_LENGTH) {
		  $error = true;
		  $entry_username_error = true;
		  $error_result.='<br>'.ENTRY_USERNAME_ERROR;
		} else {
		  $entry_username_error = false;
		}
	}
	
	if (strlen($customers_email_address) < ENTRY_EMAIL_ADDRESS_MIN_LENGTH) {
	  $error = true;
	  $entry_email_address_error = true;
	  $error_result.='<br>'.ENTRY_EMAIL_ADDRESS_ERROR;
	} else {
	  $entry_email_address_error = false;
	}
	
	if (!tep_validate_email($customers_email_address)) {
	  $error = true;
	  $entry_email_address_check_error = true;
	  $error_result.='<br>'.ENTRY_EMAIL_ADDRESS_CHECK_ERROR;
	}/*else if($customers_email_address!=$customers_confirm_email_address){
		$error = true;
		$entry_email_address_check_match_error = true;
	}*/ else {
	  $entry_email_address_check_error = false;
	}
	
	if($customers_second_email_address!=''){ 	
	 if (!tep_validate_email($customers_second_email_address) || $customers_email_address==$customers_second_email_address) {
		   $error = true;
		   $entry_second_email_address_check_error = true;
		   $error_result.='<br>'.ENTRY_SECOND_EMAIL_ADDRESS_ERROR;
		}else {	
			 $entry_second_email_address_error = false;
		  $entry_second_email_address_check_error = false;
		}
	  }
	
		
	if (strlen($entry_street_address) < ENTRY_STREET_ADDRESS_MIN_LENGTH) {
	  $error = true;
	  $entry_street_address_error = true;
	   $error_result.='<br>'.ENTRY_STREET_ADDRESS_ERROR;
	} else {
	  $entry_street_address_error = false;
	}

	if (strlen($entry_postcode) < ENTRY_POSTCODE_MIN_LENGTH) {
	  $error = true;
	  $entry_post_code_error = true;
	  $error_result.='<br>'.ENTRY_POST_CODE_ERROR;
	} else {
	  $entry_post_code_error = false;
	}
	
	if (strlen($entry_city) < ENTRY_CITY_MIN_LENGTH) {
	  $error = true;
	  $entry_city_error = true;
	  $error_result.='<br>'.ENTRY_CITY_ERROR;
	} else {
	  $entry_city_error = false;
	}
	
	if ($entry_country_id == false) {
	  $error = true;
	  $entry_country_error = true;
	  $error_result.='<br>'.ENTRY_COUNTRY_ERROR;
	} else {
	  $entry_country_error = false;
	}

	if (ACCOUNT_STATE == 'true') {
	  if ($entry_country_error == true) {
		$entry_state_error = true; 
		$error_result.='<br>'.ENTRY_STATE_ERROR;
	  } else {
		$zone_id = 0;
		$entry_state_error = false;
		$check_query = tep_db_query("select count(*) as total from " . TABLE_ZONES . " where zone_country_id = '" . (int)$entry_country_id . "'");
		$check_value = tep_db_fetch_array($check_query);
		$entry_state_has_zones = ($check_value['total'] > 0);
		if ($entry_state_has_zones == true) {
		  $zone_query = tep_db_query("select zone_id from " . TABLE_ZONES . " where zone_country_id = '" . (int)$entry_country_id . "' and zone_name = '" . tep_db_input($entry_state) . "'");
		  if (tep_db_num_rows($zone_query) == 1) {
			$zone_values = tep_db_fetch_array($zone_query);
			$entry_zone_id = $zone_values['zone_id'];
		  } else {
			$error = true;
			$entry_state_error = true;
			$error_result.='<br>'.ENTRY_STATE_ERROR;
		  }
		} else {
		  if ($entry_state == false) {
			$error = true;
			$entry_state_error = true;
			$error_result.='<br>'.ENTRY_STATE_ERROR;
		  }
		}
	 }
	}

	if (ACCOUNT_TELEPHONE=="true"){
	if (strlen($customers_telephone) < ENTRY_TELEPHONE_MIN_LENGTH) {
	$error = true;
	$entry_telephone_error = true;
	$error_result.='<br>'.ENTRY_SECOND_TELEPHONE_NUMBER_ERROR;
	} else {
	$entry_telephone_error = false;
	}
	}
	
	if (strpos($customers_mobile,"+")!==FALSE) {
	$error = true;
	$entry_mobile_error = true;
	$error_result.='<br>'.ENTRY_MOBILE_NUMBER_ERROR;
	} else {
	$entry_mobile_error = false;
	}
	
	$check_email = tep_db_query("select customers_email_address from " . TABLE_CUSTOMERS . " where customers_email_address = '" . tep_db_input($customers_email_address) . "' and customers_id != '" . (int)$customers_id . "'");
	if (tep_db_num_rows($check_email)) {
	$error = true;
	$entry_email_address_exists = true;
	$error_result.='<br>'.ENTRY_EMAIL_ADDRESS_ERROR_EXISTS;
	} else {
	$entry_email_address_exists = false;
	}

	// check occupation and interest value
	if ((HIDE_CUSTOMER_OCCUPATION_BACK == 'false') && (is_numeric($customers_occupation) == false)) {
		$error = true;
	}
	$entry_occupation_error=false;
	if ((HIDE_CUSTOMER_INTEREST_BACK == 'false') && (is_numeric($customers_interest) == false)) {
		$error = true;
	}
	
	$entry_interest_error=false;
	if (ACCOUNT_USERNAME=="true"){
	  $check_name = tep_db_query("select customers_username from " . TABLE_CUSTOMERS . " where lower(customers_username) = '" . strtolower(tep_db_input($customers_username)) . "' and customers_id != '" . (int)$customers_id . "'"); 
	  if (tep_db_num_rows($check_name)) {
		$error = true;
		$entry_username_exists = true;
		$error_result.='<br>'.ENTRY_USERNAME_ERROR_EXISTS;
	  } else {
		$entry_username_exists = false;
	  }
	}

	if ($error == false) {
		if($suspend_from =='') $suspend_from = '0000-00-00';
		if($resume_from =='') $resume_from = '0000-00-00';
	$sql_data_array = array('customers_firstname' => $customers_firstname,
				'customers_lastname' => $customers_lastname,
				'customers_email_address' => $customers_email_address,
				'customers_fax' => $customers_mobile,
				'suspend_from' => $suspend_from,
				'resume_from' => $resume_from,
				'customers_type'=>$customers_type,
				'is_blocked'=>$is_blocked,
				//CGDiscountSpecials start
				'customers_discount' => $customers_discount_sign . $customers_discount,
				'customers_groups_id' => $customers_groups_id
				//CGDiscountSpecials end
			);
			
			if (!($customers_password == '*****' || $customers_password == '')) {
				 $sql_data_array['customers_password'] = tep_encrypt_password($customers_password);
				 $encription_style=(defined('ENCRYPTION_STYLE'))?ENCRYPTION_STYLE:'O';
				 $sql_data_array['encryption_style']=$encription_style;
			}	 

	if (ACCOUNT_USERNAME=='true') $sql_data_array['customers_username']=$customers_username;
	if (ACCOUNT_SECOND_PHONE=='true') $sql_data_array['customers_second_telephone']=$customers_second_telephone;
	if (ACCOUNT_SECOND_EMAIL=='true') $sql_data_array['customers_second_email_address']=$customers_second_email_address;
	
	if (ACCOUNT_GENDER == 'true') $sql_data_array['customers_gender'] = $customers_gender;
	if (ACCOUNT_DOB == 'true') $sql_data_array['customers_dob'] = tep_convert_date_raw($customers_dob,EVENTS_DATE_FORMAT);
	if (ACCOUNT_NEWSLETTER == 'true') $sql_data_array['customers_newsletter'] = $newsletter;
	if (ACCOUNT_RESERVATION_NEWSLETTER == 'true') $sql_data_array['customers_reserve_newsletter'] = $reserve_newsletter;
	if (ACCOUNT_SUBSCRIPTION_NEWSLETTER == 'true') $sql_data_array['customers_subscription_newsletter'] = $subscription_newsletter;
	if (ACCOUNT_TELEPHONE=='true') $sql_data_array["customers_telephone"]=$customers_telephone;
	if (HIDE_CUSTOMER_OCCUPATION_BACK=='false') $sql_data_array["customers_occupation"]=$customers_occupation;
	if (HIDE_CUSTOMER_INTEREST_BACK=='false') $sql_data_array["customers_interest"]=$customers_interest;
	
	
	tep_db_perform(TABLE_CUSTOMERS, $sql_data_array, 'update', "customers_id = '" . (int)$customers_id . "'");
	
	tep_db_query("update " . TABLE_CUSTOMERS_INFO . " set customers_info_date_account_last_modified ='" . getServerDate(true) . "' where customers_info_id = '" . (int)$customers_id . "'");
	
	if ($entry_zone_id > 0) $entry_state = '';
	
	$sql_data_array = array('entry_firstname' => $customers_firstname,
							'entry_lastname' => $customers_lastname,
							'entry_street_address' => $entry_street_address,
							'entry_postcode' => $entry_postcode,
							'entry_city' => $entry_city,
							'entry_country_id' => $entry_country_id);
	
	if (ACCOUNT_COMPANY == 'true') $sql_data_array['entry_company'] = $entry_company;
	if (ACCOUNT_SUBURB == 'true') $sql_data_array['entry_suburb'] = $entry_suburb;
	
	if (ACCOUNT_STATE == 'true') {
	  if ($entry_zone_id > 0) {
		$sql_data_array['entry_zone_id'] = $entry_zone_id;
		$sql_data_array['entry_state'] = '';
	  } else {
		$sql_data_array['entry_zone_id'] = '0';
		$sql_data_array['entry_state'] = $entry_state;
	  }
	}
	tep_db_perform(TABLE_ADDRESS_BOOK, $sql_data_array, 'update', "customers_id = '" . (int)$customers_id . "' and address_book_id = '" . (int)$default_address_id . "'");
	return 'success';	
	} else if ($error == true) {
	  //$cInfo = new objectInfo($HTTP_POST_VARS);
	  //$processed = true;
	return 'failure'.$error_result;
	}
	
	}
	
	function new_customer(){ 
	?>
	<form name="account_edit" method="post" <?php echo 'action="' . tep_href_link(FILENAME_CREATE_ACCOUNT_PROCESS, $add_option , 'SSL') . '"'; ?> onSubmit="return check_form();">
	<?php echo tep_draw_hidden_field('ajax_flag','1'); ?>	
	<input type="hidden" name="action" value="process">
	
	<table width="100%" cellpadding="0" cellspacing="0" border="0">
	<tr>
	<td width="200"><?php echo tep_image(DIR_WS_IMAGES.'template/icon_active.gif').'&nbsp;&nbsp;New Customer'; ?></td>
	<td align="right"><?php echo '<a href="javascript: check_form();">'.tep_image(DIR_WS_IMAGES.'template/img_savel.gif','Save','','','').'</a>&nbsp;&nbsp;<a href="javascript: close_new_customer();">'.tep_image(DIR_WS_IMAGES.'template/img_closel.gif','Close','','').'</a>'; ?></td>
	</tr>
	</table>
	<!-- body //-->
	<table border="0" width="100%" cellspacing="2" cellpadding="2">
	<tr> 
	
	<!-- body_text //-->
	<?php $add_option="";
	if (isset($HTTP_POST_VARS["param_event"]) && isset($HTTP_POST_VARS["param_session"])){
		$add_option.="&param_1=" . $HTTP_POST_VARS["param_event"];
		$add_option.="&param_2=" . $HTTP_POST_VARS["param_session"];
	}?>
	<td width="100%" valign="top">
	<?php if (isset($HTTP_POST_VARS["param_event"]) && isset($HTTP_POST_VARS["param_session"])){
			echo '<input type="hidden" name="param_event" value="' . tep_output_string($HTTP_POST_VARS["param_event"]) .'">';
			echo '<input type="hidden" name="param_session" value="' . tep_output_string($HTTP_POST_VARS["param_session"]) .'">';
		}?><table border="0" width="100%" cellspacing="0" cellpadding="0">
	<?php
	if (sizeof($navigation->snapshot) > 0) {
	?>
	<tr>
	<td class="smallText"><br><?php echo sprintf(TEXT_ORIGIN_LOGIN, tep_href_link(FILENAME_LOGIN, tep_get_all_get_params(), 'SSL')); ?></td>
	</tr>
	<?php
	}
	?>
	<tr>
	<td><?php echo tep_draw_separator('pixel_trans.gif', '100%', '10'); ?></td>
	</tr>
	<tr>
	<td>
	<?php
	//$email_address = tep_db_prepare_input($HTTP_GET_VARS['email_address']);
	$account['entry_country_id'] = STORE_COUNTRY;
	$account['entry_zone_id'] = STORE_ZONE;
	$account['entry_city']=STORE_CITY;
	require(DIR_WS_MODULES . 'account_details.php');
	?>
	</td>
	</tr>
	<tr>
	<td align="right" class="main" valign="middle"><br>
	<?php   echo tep_draw_checkbox_field("create_order",'Y') . '&nbsp;' . TEXT_CREATE_ORDER . '&nbsp;';
			
			//echo tep_image_submit('button_confirm.gif', IMAGE_CONTINUE,'align=absmiddle');
	?>
	</td>
	</tr>
	</table></form></td>
	<!-- body_text_eof //-->
	<td width="<?php echo BOX_WIDTH; ?>" valign="top"><table border="0" width="<?php echo BOX_WIDTH; ?>" cellspacing="0" cellpadding="2">
	</table></td>
	</tr>
	</table>
	<!-- body_eof //-->
	<?php
	}
	
	function save_new_customer(){
	$server_date = getServerDate(true);	
	global $HTTP_POST_VARS;
	define('EMAIL_PASS_1', 'Your password for this account is ');
	define('EMAIL_PASS_2', ', keep it in a safe place. (Please note: Your password is case sensitive.)');
	
	$gender = tep_db_prepare_input($HTTP_POST_VARS['gender']);
  $firstname = tep_db_prepare_input($HTTP_POST_VARS['firstname']);
  $lastname = tep_db_prepare_input($HTTP_POST_VARS['lastname']);
  $dob = tep_db_prepare_input($HTTP_POST_VARS['dob']);
  $username = tep_db_prepare_input($HTTP_POST_VARS['username']);
  $email_address = tep_db_prepare_input($HTTP_POST_VARS['email_address']);
  $confirm_email_address = tep_db_prepare_input($HTTP_POST_VARS['confirm_email_address']);
  $second_email_address = tep_db_prepare_input($HTTP_POST_VARS['second_email_address']);
  if($second_email_address!='')
  		$second_confirm_email_address = tep_db_prepare_input($HTTP_POST_VARS['second_confirm_email_address']);
    		
  $telephone = tep_db_prepare_input($HTTP_POST_VARS['telephone']);
  $second_telephone = tep_db_prepare_input($HTTP_POST_VARS['second_telephone']);
  $mobile = tep_db_prepare_input($HTTP_POST_VARS['mobile']);
  $newsletter = tep_db_prepare_input($HTTP_POST_VARS['newsletter']);
  $reserve_newsletter = tep_db_prepare_input($HTTP_POST_VARS['reserve_newsletter']);
  $subscription_newsletter = tep_db_prepare_input($HTTP_POST_VARS['subscription_newsletter']);
  $suspend_from=empty($HTTP_POST_VARS['txt_suspend_date'])? '0000-00-00' : tep_convert_date_raw(tep_db_prepare_input($HTTP_POST_VARS['txt_suspend_date']));
  $resume_from=empty($HTTP_POST_VARS['txt_resume_date'])? '0000-00-00' : tep_convert_date_raw(tep_db_prepare_input($HTTP_POST_VARS['txt_resume_date']));	
  $occupation=tep_db_prepare_input($HTTP_POST_VARS['occupation']);
  $interest=tep_db_prepare_input($HTTP_POST_VARS['interest']);
	//CGDiscountSpecials start
	$customers_discount_sign = tep_db_prepare_input($HTTP_POST_VARS['customers_discount_sign']);
	$customers_discount = tep_db_prepare_input($HTTP_POST_VARS['customers_discount']);
	$customers_groups_id = tep_db_prepare_input($HTTP_POST_VARS['customers_groups_id']); 
	if($customers_discount=='') $customers_discount='0';
	//CGDiscountSpecials end
		
  // check for newsletter is active
  $customers_type=(isset($HTTP_POST_VARS['customers_type'])?$HTTP_POST_VARS['customers_type']:'');
  $password = tep_db_prepare_input($HTTP_POST_VARS['password']);
  $confirmation = tep_db_prepare_input($HTTP_POST_VARS['confirmation']);
  $street_address = tep_db_prepare_input($HTTP_POST_VARS['street_address']);
  $company = tep_db_prepare_input($HTTP_POST_VARS['company']);
  $suburb = tep_db_prepare_input($HTTP_POST_VARS['suburb']);
  $postcode = tep_db_prepare_input($HTTP_POST_VARS['postcode']);
  $city = tep_db_prepare_input($HTTP_POST_VARS['city']);
  $zone_id = tep_db_prepare_input($HTTP_POST_VARS['zone_id']);
  $state = tep_db_prepare_input($HTTP_POST_VARS['state']);
  if($state=='' || $HTTP_POST_VARS['state1'])$state = tep_db_prepare_input($HTTP_POST_VARS['state1']);
  $country = tep_db_prepare_input($HTTP_POST_VARS['country']);
  $is_blocked=($HTTP_POST_VARS['is_blocked']=='Y'?tep_db_prepare_input($HTTP_POST_VARS['is_blocked']):'N');
  /////////////////      RAMDOMIZING SCRIPT BY PATRIC VEVERKA       \\\\\\\\\\\\\\\\\\

/*$t1 = date("mdy"); 
srand ((float) microtime() * 10000000); 
$input = array ("A", "a", "B", "b", "C", "c", "D", "d", "E", "e", "F", "f", "G", "g", "H", "h", "I", "i", "J", "j", "K", "k", "L", "l", "M", "m", "N", "n", "O", "o", "P", "p", "Q", "q", "R", "r", "S", "s", "T", "t", "U", "u", "V", "v", "W", "w", "X", "x", "Y", "y", "Z", "z"); 
$rand_keys = array_rand ($input, 3); 
$l1 = $input[$rand_keys[0]];
$r1 = rand(0,9); 
$l2 = $input[$rand_keys[1]];
$l3 = $input[$rand_keys[2]]; 
$r2 = rand(0,9); 

$password = $l1.$r1.$l2.$l3.$r2; */

/////////////////    End of Randomizing Script   \\\\\\\\\\\\\\\\\\\

  
  
  $error = false; // reset error flag

  if (ACCOUNT_GENDER == 'true') {
    if (($gender == 'm') || ($gender == 'f')) {
      $entry_gender_error = false;
    } else {
      $error = true;
      $entry_gender_error = true;
    }
  }

  if (strlen($firstname) < ENTRY_FIRST_NAME_MIN_LENGTH) {
    $error = true;
    $entry_firstname_error = true;
  } else {
    $entry_firstname_error = false;
  }

  if (strlen($lastname) < ENTRY_LAST_NAME_MIN_LENGTH) {
    $error = true;
    $entry_lastname_error = true;
  } else {
    $entry_lastname_error = false;
  }

  if (ACCOUNT_DOB == 'true') {
    if (tep_check_date_raw($dob,EVENTS_DATE_FORMAT)) {
      $entry_date_of_birth_error = false;
    } else {
      $error = true;
      $entry_date_of_birth_error = true;
    }
  }

  if (ACCOUNT_USERNAME == 'true') {
	  if (strlen($username) < ENTRY_USERNAME_MIN_LENGTH) {
		$error = true;
		$entry_username_error = true;
	  } else {
		$entry_username_error = false;
	  }
  }
  
  if (strlen($email_address) < ENTRY_EMAIL_ADDRESS_MIN_LENGTH) {
    $error = true;
    $entry_email_address_error = true;
  } else {
    $entry_email_address_error = false;
  }

 if (!tep_validate_email($email_address)) {
    $error = true;
    $entry_email_address_check_error = true;
  }else if($email_address!=$confirm_email_address){ 
  	 $error = true;
    $entry_email_address_check_match_error = true;
  } else {
    $entry_email_address_check_error = false;
  }
  
   if($second_email_address!=''){
	  	if (!tep_validate_email($second_email_address) || $email_address==$second_email_address) {
	     	$error = true;
	    	$entry_second_email_address_check_error = true;
	  	}else if($second_email_address!=$second_confirm_email_address){ 
	      $error = true;
	      $entry_second_email_address_match_error = true;
	   } else {
	      $entry_second_email_address_match_error = false;
	      $entry_second_email_address_check_error = false;
	   }
  } 
  //rmh referral start
	$source="";
	$source_other="";
	if (HIDE_REFERRAL_BACK=='false'){
		$source = tep_db_prepare_input($HTTP_POST_VARS['source']);
		if (isset($HTTP_POST_VARS['source_other'])) $source_other = tep_db_prepare_input($HTTP_POST_VARS['source_other']);
	}
//rmh referral end
	$error=false;

  if (strlen($street_address) < ENTRY_STREET_ADDRESS_MIN_LENGTH) {
    $error = true;
    $entry_street_address_error = true;
  } else {
    $entry_street_address_error = false;
  }

  if (strlen($postcode) < ENTRY_POSTCODE_MIN_LENGTH) {
    $error = true;
    $entry_post_code_error = true;
  } else {
    $entry_post_code_error = false;
  }

  if (strlen($city) < ENTRY_CITY_MIN_LENGTH) {
    $error = true;
    $entry_city_error = true;
  } else {
    $entry_city_error = false;
  }

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

  if (ACCOUNT_STATE == 'true') {
    if ($entry_country_error) {
      $entry_state_error = true;
    } else {
      $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($country) . "'");
      $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($country) . "' and zone_name = '" . tep_db_input($state) . "'");
        if (tep_db_num_rows($zone_query) == 1) {
          $zone_values = tep_db_fetch_array($zone_query);
          $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($country) . "' and zone_code = '" . tep_db_input($state) . "'");
          if (tep_db_num_rows($zone_query) == 1) {
            $zone_values = tep_db_fetch_array($zone_query);
            $zone_id = $zone_values['zone_id'];
          } else {
            $error = true;
            $entry_state_error = true;
          }
        }
      } else {
        if (!$state) {
          $error = true;
          $entry_state_error = true;
        }
      }
    }
  }
// check occupation and interest value
if ((HIDE_CUSTOMER_OCCUPATION_BACK == 'false') && (is_numeric($occupation) == false)) {
        $error = true;
    }
    $entry_occupation_error=false;
    if ((HIDE_CUSTOMER_INTEREST_BACK == 'false') && (is_numeric($interest) == false)) {
        $error = true;
    }
	$entry_interest_error=false;

// check occupation and interest

if (ACCOUNT_TELEPHONE == 'true') {
  if (strlen($telephone) < ENTRY_TELEPHONE_MIN_LENGTH) {
    $error = true;
    $entry_telephone_error = true;
  } else {
    $entry_telephone_error = false;
  }
}
//rmh referral start
    if ((REFERRAL_REQUIRED == 'true') && (is_numeric($source) == false)) {
        $error = true;
        //$messageStack->add('create_order', ENTRY_SOURCE_ERROR);
    }

    if ((REFERRAL_REQUIRED == 'true') && (DISPLAY_REFERRAL_OTHER == 'true') &&($source == '9999') && (!tep_not_null($source_other)) ) {
        $error = true;

        //$messageStack->add('create_order', ENTRY_SOURCE_OTHER_ERROR);
    }
//rmh referral end
  if (strpos($mobile,"+")!==FALSE) {
    $error = true;
    $entry_mobile_error = true;
  } else {
    $entry_mobile_error = false;
  }

  $check_email = tep_db_query("select customers_email_address from " . TABLE_CUSTOMERS . " where customers_email_address = '" . tep_db_input($email_address) . "'"); // and customers_id <> '" . tep_db_input($customer_id) . "'");
  if (tep_db_num_rows($check_email)) {
    $error = true;
    $entry_email_address_exists = true;
  } else {
    $entry_email_address_exists = false;
  }
  if (ACCOUNT_USERNAME=="true"){
	  $check_name = tep_db_query("select customers_username from " . TABLE_CUSTOMERS . " where lower(customers_username) = '" . strtolower(tep_db_input($username)) . "'"); // and customers_id <> '" . tep_db_input($customer_id) . "'");
	  if (tep_db_num_rows($check_name)) {
		$error = true;
		$entry_username_exists = true;
	  } else {
		$entry_username_exists = false;
	  }
  }
/*  if(MODULE_ADMIN_PASSWORD_STRENGTH==4)
  {
  	if(!tep_check_password_strength($password))
	{
		$error=true;
		$entry_password_strength_error=true;
	}
	else
		$entry_password_strength_error=false;
  }*/
  
   $encryption_style=(defined('ENCRYPTION_STYLE'))?ENCRYPTION_STYLE:'O';
    $sql_data_array = array('customers_firstname' => $firstname,
								'customers_lastname' => $lastname,
								'customers_email_address' => $email_address,
								'customers_fax' => $mobile,
								'customers_type' =>$customers_type,
								'customers_password' =>  tep_encrypt_password($password),
								//CGDiscountSpecials start
								'customers_discount' => $customers_discount_sign . $customers_discount,
								'customers_groups_id' => $customers_groups_id,
								'suspend_from' => $suspend_from,
								'resume_from' => $resume_from,
								'is_blocked'=>$is_blocked,
								//CGDiscountSpecials end
								//encription style
								'encryption_style'=>$encryption_style
								//encription style
							);

    if (ACCOUNT_USERNAME == 'true') $sql_data_array['customers_username'] = $username;
    if (ACCOUNT_SECOND_EMAIL == 'true') $sql_data_array['customers_second_email_address'] = $second_email_address;
    if (ACCOUNT_SECOND_PHONE == 'true') $sql_data_array['customers_second_telephone'] = $second_telephone;
    if (ACCOUNT_GENDER == 'true') $sql_data_array['customers_gender'] = $gender;
    if (ACCOUNT_DOB == 'true') $sql_data_array['customers_dob'] = tep_convert_date_raw($dob,EVENTS_DATE_FORMAT);
    if (ACCOUNT_NEWSLETTER == 'true') $sql_data_array['customers_newsletter'] = $newsletter;
    if (ACCOUNT_RESERVATION_NEWSLETTER == 'true') $sql_data_array['customers_reserve_newsletter'] = $reserve_newsletter;
    if (ACCOUNT_SUBSCRIPTION_NEWSLETTER == 'true') $sql_data_array['customers_subscription_newsletter'] = $subscription_newsletter;
	 if (ACCOUNT_TELEPHONE == 'true') $sql_data_array["customers_telephone"]=$telephone;
	 if (HIDE_CUSTOMER_OCCUPATION_BACK=='false') $sql_data_array["customers_occupation"]=$occupation;
 	 if (HIDE_CUSTOMER_INTEREST_BACK=='false') $sql_data_array["customers_interest"]=$interest;
	
    tep_db_perform(TABLE_CUSTOMERS, $sql_data_array);

    $customer_id = tep_db_insert_id();

    $sql_data_array = array('customers_id' => $customer_id,
                            //cchange line below to suit your version
							//'address_book_id' => 1,  //pre MS2
							//'address_book_id' => (int)$default_address_id, //for MS2
                            'entry_firstname' => $firstname,
                            'entry_lastname' => $lastname,
                            'entry_street_address' => $street_address,
                            'entry_postcode' => $postcode,
                            'entry_city' => $city,
                            'entry_country_id' => $country);

    if (ACCOUNT_GENDER == 'true') $sql_data_array['entry_gender'] = $gender;
    if (ACCOUNT_COMPANY == 'true') $sql_data_array['entry_company'] = $company;
    if (ACCOUNT_SUBURB == 'true') $sql_data_array['entry_suburb'] = $suburb;
    if (ACCOUNT_STATE == 'true') {
      if ($zone_id > 0) {
        $sql_data_array['entry_zone_id'] = $zone_id;
        $sql_data_array['entry_state'] = '';
      } else {
        $sql_data_array['entry_zone_id'] = '0';
        $sql_data_array['entry_state'] = $state;
      }
    }

    tep_db_perform(TABLE_ADDRESS_BOOK, $sql_data_array);

    $address_id = tep_db_insert_id();

    tep_db_query("update " . TABLE_CUSTOMERS . " set customers_default_address_id = '" . (int)$address_id . "' where customers_id = '" . (int)$customer_id . "'");

//rmh referral start
      tep_db_query("insert into " . TABLE_CUSTOMERS_INFO . " (customers_info_id, customers_info_number_of_logons, customers_info_date_account_created, customers_info_source_id) values ('" . (int)$customer_id . "', '0','" . $server_date . "', '". (int)$source .  "')");
	  if ($source=="9999") {
        	tep_db_query("insert into " . TABLE_SOURCES_OTHER . " (customers_id, sources_other_name) values ('" . (int)$customer_id . "', '". tep_db_input($source_other) . "')");
      }
//rmh referral end



    $customer_first_name = $firstname;
    $customer_default_address_id = 1;
    $customer_country_id = $country;
    $customer_zone_id = $zone_id;
    tep_session_register('customer_id');
    tep_session_register('customer_first_name');
    tep_session_register('customer_default_address_id');
    tep_session_register('customer_country_id');
    tep_session_register('customer_zone_id');

// build the message content using built in template
      $send_details=array();
      
      //build merge details
      $merge_details=array();
      $merge_details[TEXT_FN]=$firstname;
      $merge_details[TEXT_LN]=$lastname;
      
      if (ACCOUNT_GENDER == 'true') {
         if ($HTTP_POST_VARS['gender'] == 'm') {
           $merge_details[TEXT_GR] = EMAIL_GREET_MR;
         } else {
           $merge_details[TEXT_GR] = EMAIL_GREET_MS;
         }
      } else {
        $merge_details[TEXT_GR] = EMAIL_GREET_NONE;
      }
      $merge_details[TEXT_SM]=STORE_NAME;
      $merge_details[TEXT_SN]=STORE_OWNER;
      $merge_details[TEXT_SE]=STORE_OWNER_EMAIL_ADDRESS;
      if (ACCOUNT_USERNAME == 'true') {
	      $merge_details[TEXT_LE]=$email_address;
	  } else  {
		  $merge_details[TEXT_LE]=$username;
	  }
      $merge_details[TEXT_LP]=$password;

      $send_details[0]['to_name'] = $firstname . ' ' . $lastname;
      $send_details[0]['to_email'] = $email_address;
      $send_details[0]['from_name']=STORE_OWNER;
      $send_details[0]['from_email']=STORE_OWNER_EMAIL_ADDRESS;

      tep_send_default_email("CUS",$merge_details,$send_details);
		/*if (isset($HTTP_POST_VARS["create_order"])){
				tep_redirect(tep_href_link(FILENAME_CREATE_ORDER_PROCESS, 'customer=' . $customer_id . '&param_1=' . $HTTP_GET_VARS["param_1"] . '&param_2=' . $HTTP_GET_VARS["param_2"] . '&check=1','SSL'));
		} else {
				tep_redirect(tep_href_link(FILENAME_CREATE_ACCOUNT_SUCCESS, 'cID=' . $customer_id, 'SSL'));
		}*/
	
	return $customer_id;
	}
	
	
	tep_get_last_access_file();
	require(DIR_WS_CLASSES . 'currencies.php');
	$currencies=new currencies();
	$action = (isset($HTTP_GET_VARS['action']) ? $HTTP_GET_VARS['action'] : '');
	$error = false;
	$processed = false;

 	 
	if (tep_session_is_registered("cID")) tep_session_unregister("cID");
	if (tep_session_is_registered("payment_page")) tep_session_unregister("payment_page");
	if (tep_session_is_registered("wallet_amount")) tep_session_unregister("wallet_amount");
	
?>
<!doctype html public "-//W3C//DTD HTML 4.01 Transitional//EN">
<html <?php echo HTML_PARAMS; ?>>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=<?php echo CHARSET; ?>">
<title><?php echo TITLE; ?></title>
<link rel="stylesheet" type="text/css" href="includes/stylesheet.css">
<script language="javascript" src="includes/menu.js"></script>
<script language="javascript" src="includes/general.js"></script>
<script language="JavaScript" src="includes/date-picker.js"></script>
<script language="javascript" src="includes/http.js"></script>

<script type="text/javascript" src="htmlarea/htmlarea.js"></script>
<script type="text/javascript" src="htmlarea/editor.js"></script>
<script language="JavaScript" src="htmlarea/validation.js"></script>

<?php require('includes/password_strength.js.php');?>
<script>
 function do_pwd_check(obj)
 {
  <?php //if(MODULE_ADMIN_PASSWORD_STRENGTH==4){?>	
 	pwd=obj.value;
	if(pwd.length==0)
	  document.all.pwd_str.innerHTML='';
	else if(pwd.length<<?php echo ENTRY_PASSWORD_MIN_LENGTH;?>)
		document.all.pwd_str.innerHTML='<?php echo ENTRY_PASSWORD_STRENGTH_ERROR;?>';
	else if(!check_password_strength(pwd))
		document.all.pwd_str.innerHTML='<?php echo ENTRY_PASSWORD_STRENGTH_ERROR;?>';
	else
		document.all.pwd_str.innerHTML='';
  <?php // }?>
 }
</script>
<script language="javascript">
	/*function show_state(zone){
		document.getElementById("entry_state1").style.display="none";
		document.getElementById("entry_state").style.display="";
		var this_=document.getElementById("entry_country_id");
		id=this_.options[this_.selectedIndex].value;
		if(id){
			command="<?php echo tep_href_link(FILENAME_CUSTOMERS,'command=show_state');?>&country_id="+id+"&zone="+zone;
			do_get_command(command);	
		}
	}*/
	
	function show_state(){		
		var this_=document.getElementById("entry_country_id");
		if(document.getElementById("country")) this_=document.getElementById("country");
		id=this_.options[this_.selectedIndex].value;
		var state=document.getElementById("entry_state");
		if(document.getElementById("state")) state=document.getElementById("state");
		if(id){
			command="<?php echo tep_href_link(FILENAME_CUSTOMERS,'command=show_state');?>&country_id="+id;
			do_get_command(command);
			if(state) state.innerHTML="Loading...";
		}else
			element=state.innerHTML="";		
	}
	
	/*function do_result(result){ 
	  alert(result);
	  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[1].split(",");		
		textArr=splt[1].split(",");
		sel_zone=splt[2];
		var sel=document.getElementById("entry_state");
		if(valueArr.length==1) {
			document.getElementById("entry_state1").style.display="";
			sel.style.display="none";
		}else {
			document.getElementById("entry_state1").value="";
			document.getElementById("entry_state1").style.display="none";
			sel.style.display="";
			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
			  }
			}
		}
	  }
	}*/
</script>
<?php include('includes/date_format_js.php'); ?>
<script language="javascript">
 
function check_form_customer(customers_id) {
  var error = 0;
  var error_message = "<?php echo JS_ERROR; ?>";

  var customers_firstname = document.getElementById('customers_firstname').value;
  var customers_lastname = document.getElementById('customers_lastname').value;
<?php if (ACCOUNT_COMPANY == 'true') echo 'var entry_company = document.getElementById("entry_company").value;' . "\n"; ?>
<?php if (ACCOUNT_DOB == 'true') echo 'var customers_dob = document.getElementById("customers_dob").value;' . "\n"; ?>
<?php if (ACCOUNT_USERNAME == 'true') echo 'var customers_username = document.getElementById("customers_username").value;' . "\n"; ?>
  var customers_email_address = document.getElementById('customers_email_address').value;
  //var customers_confirm_email_address = document.customers.customers_confirm_email_address.value;
  var customers_password = document.getElementById('customers_password').value;

<?php if (ACCOUNT_SECOND_PHONE == 'true') echo 'var customers_second_telephone = document.getElementById("customers_second_telephone").value;' . "\n"; ?>
<?php if (ACCOUNT_SECOND_EMAIL == 'true') echo 'var customers_second_email_address = document.getElementById("customers_second_email_address");' . "\n"; ?>
  //if(customers_second_email_address!='')
	//var customers_second_confirm_email_address = document.customers.customers_second_confirm_email_address.value;
  var entry_street_address = document.getElementById('entry_street_address').value;
  var entry_postcode = document.getElementById('entry_postcode').value;
  var entry_city = document.getElementById('entry_city').value;
  var password = document.getElementById('customers_password').value;
  
<?php if (ACCOUNT_TELEPHONE == 'true') echo 'var customers_telephone = document.getElementById("customers_telephone").value;' . "\n"; ?>

<?php if (ACCOUNT_GENDER == 'true') { ?>
 if (document.getElementById('genderflag').value=="1"){

  if (document.customers.customers_gender[0].checked || document.customers.customers_gender[1].checked) {
  } else {
    error_message = error_message + "<?php echo JS_GENDER; ?>";
    error = 1;
  }
}
<?php } ?>

  if (str_trim(customers_firstname) == "" || customers_firstname.length < <?php echo ENTRY_FIRST_NAME_MIN_LENGTH; ?>) {
    error_message = error_message + "<?php echo JS_FIRST_NAME; ?>";
    error = 1;
  }

  if (str_trim(customers_lastname) == "" || customers_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 (str_trim(customers_dob) == "" || customers_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 (str_trim(customers_username) == "" || customers_username.length < <?php echo ENTRY_USERNAME_MIN_LENGTH; ?>) {
    error_message = error_message + "<?php echo JS_USERNAME; ?>";
    error = 1;
  }
<?php } ?>

  if (str_trim(customers_email_address) == "" || customers_email_address.length < <?php echo ENTRY_EMAIL_ADDRESS_MIN_LENGTH; ?>) {
    error_message = error_message + "<?php echo JS_EMAIL_ADDRESS; ?>";
    error = 1;
  }
 /*  if(customers_email_address!=customers_confirm_email_address){
 		error_message = error_message + "<?php echo JS_EMAIL_CONFIRM_ADDRESS; ?>";
    	error = 1;
  } */
  <?php if (ACCOUNT_SECOND_EMAIL == 'true') { ?>
  if(customers_second_email_address && customers_second_email_address.value!=''){
	 /* if(customers_second_email_address!=customers_second_confirm_email_address){
	  		error_message = error_message + "<?php //echo JS_SECONDEMAIL_CONFIRM_ADDRESS; ?>";
	    	error = 1;	
	  }else*/
	  if(customers_email_address==customers_second_email_address.value){	
	  		error_message = error_message + "<?php echo JS_SECOND_EMAIL_ADDRESS_UNIQUE; ?>";
	    	error = 1;
	  }
  }
 <?php  } ?> 
  if(password!='*****' && pwdValidation('<?php echo MODULE_CUSTOMERS_PASSWORD_STRENGTH;?>',password)==false){
	  switch ('<?php echo MODULE_CUSTOMERS_PASSWORD_STRENGTH;?>'){	
		case '1':
			error_message = error_message + '<?php echo ERR_PWD_EMPTY;?>';
			error=1;
			break;
		case '2':
			error_message = error_message + '<?php echo ERR_PWD_ALPHANUMERIC;?>';
			error=1;
			break;
		case '3':
			error_message = error_message + '<?php echo ERR_PWD_ALPHA_SYMBOLS;?>';
			error=1;
			break;
		case '4':
			error_message = error_message + '<?php echo ERR_PWD_DICTIONARY_WORDS;?>';
			error=1;
			break;
	  }
 } 
  
  if (str_trim(entry_street_address) == "" || entry_street_address.length < <?php echo ENTRY_STREET_ADDRESS_MIN_LENGTH; ?>) {
    error_message = error_message + "<?php echo JS_ADDRESS; ?>";
    error = 1;
  }

  if (str_trim(entry_postcode) == "" || entry_postcode.length < <?php echo ENTRY_POSTCODE_MIN_LENGTH; ?>) {
    error_message = error_message + "<?php echo JS_POST_CODE; ?>";
    error = 1;
  }

  if (str_trim(entry_city) == "" || entry_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.getElementById('entry_state').style.display != "none") {
    if (document.getElementById('entry_state').value == '' || document.getElementById('entry_state').value.length < <?php echo ENTRY_STATE_MIN_LENGTH; ?> ) {
       error_message = error_message + "<?php echo JS_STATE; ?>";
       error = 1;
    }
  }else if (document.getElementById('entry_state1').style.display != "none") {
    if (document.getElementById('entry_state1').value == '' || document.getElementById('entry_state1').value.length < <?php echo ENTRY_STATE_MIN_LENGTH; ?> ) {
       error_message = error_message + "<?php echo JS_STATE; ?>";
       error = 1;
    }
  }
  
<?php
  }
?>

  if (document.getElementById('entry_country_id').type != "hidden") {
    if (document.getElementById('entry_country_id').value == 0) {
      error_message = error_message + "<?php echo JS_COUNTRY; ?>";
      error = 1;
    }
  }

<?php if (ACCOUNT_TELEPHONE == 'true') { ?>
  if (customers_telephone == "" || customers_telephone.length < <?php echo ENTRY_TELEPHONE_MIN_LENGTH; ?>) {
    error_message = error_message + "<?php echo JS_TELEPHONE; ?>";
    error = 1;
  }
 <?php } ?>
  if (document.getElementById('customers_mobile').type != "hidden") {
    if (check_phone(document.getElementById('customers_mobile').value)==false) {
      error_message = error_message + "<?php echo JS_MOBILE; ?>";
      error = 1;
    }
  }
<?php if (HIDE_CUSTOMER_OCCUPATION_BACK=='false'){ ?>
    if (document.getElementById('customers_occupation').type != "hidden") {
    if (document.getElementById('customers_occupation').value == 0) {
      error_message = error_message + "* <?php echo ENTRY_CUSTOMER_OCCUPATION_ERROR; ?>\n";
      error = 1;
    }
  }
<?php } ?> 
<?php if (HIDE_CUSTOMER_INTEREST_BACK=='false'){ ?>
    if (document.getElementById('customers_interest').type != "hidden") {
    if (document.getElementById('customers_interest').value == 0) {
      error_message = error_message + "* <?php echo ENTRY_CUSTOMER_INTEREST_ERROR; ?>\n";
      error = 1;
    }
  }
<?php } ?>
	var suspend_date_time = 0;
	var resume_date_time = 0;
if(document.getElementById('txt_suspend_date').value!=""){
	var date_error = true;
	if((document.getElementById('txt_suspend_date').value).indexOf("-")!=-1){
		date_error = isValidDate(date_format(document.getElementById('txt_suspend_date').value,'','Y-m-d'));
	} else {
		date_error = false;
	}
	if(!(date_error)){
		error = 1;
		error_message+="* <?php echo ENTRY_SUSPEND_DATE_ERROR;?>\n";
		document.getElementById('txt_suspend_date').value = "";
	} else {
		 suspend_date_time = date_format(document.getElementById('txt_suspend_date').value,'','',true).getTime();
	}
}
if(document.getElementById('txt_resume_date').value!=""){
	var date_error = true;
	if((document.getElementById('txt_resume_date').value).indexOf("-")!=-1){
		date_error = isValidDate(date_format(document.getElementById('txt_resume_date').value,'','Y-m-d'));
	} else {
		date_error = false;
	}
	if(!(date_error)){
		error = 1;
		error_message+="* <?php echo ENTRY_RESUME_DATE_ERROR;?>\n";
		document.getElementById('txt_resume_date').value = "";
	} else {
		 resume_date_time = date_format(document.getElementById('txt_resume_date').value,'','',true).getTime();
	}
}
if(suspend_date_time != 0 && resume_date_time != 0 ){
	if(suspend_date_time>resume_date_time){
		error = 1;
		error_message+="* <?php echo SUSPEND_DATE_EXCEED_RESUME_DATE_ERROR;?>\n";
		document.getElementById('txt_resume_date').value="";
	}
}
  if (error == 1) {
    alert(error_message);
  } else {
  do_post_command('customers','<?php echo tep_href_link(FILENAME_CUSTOMERS,'command=save_edit_customer&customers_id='); ?>'+customers_id);
  document.getElementById('ajax_load').innerHTML=ajax_image_load;
  }
}
function check_phone(value){
var rc = new RegExp("[~`!@#$%^&*_=|\/><,?;:+-]","i")
var rn = new RegExp("[A-Z]","i");
var res;
	if (value=="") return true;
    res= rn.exec(value);
	if (isNaN(res))
		return false;
	else
	{
		res=rc.exec(value);
		if (res!=null) 
			return false;
	}
	return true;
}

//--></script>
<?php require('includes/password_strength.js.php'); ?>

<?php 
	include('includes/date_format_js.php');
	require('includes/form_check.js.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 //-->
<?php $cID=isset($HTTP_GET_VARS['cID'])?(int)$HTTP_GET_VARS['cID']:''; 
?>
<script language="javascript"> 
	var cID='<?php echo $cID; ?>';
</script>
<!-- Ajax Work Starts -->
<div style="padding:5px;color:#FF0000;display:none;" id="error_tag">Some Error will occur. Data not saved.</div>
<div style="padding:5px;color:#FF0000;display:none;" id="upload_error_tag"></div>

<table width="100%" cellpadding="0" cellspacing="0" border="0">
<tr>
	<td style="padding:5px;" class="pageHeading"><?php echo HEADING_TITLE; ?></td>
</tr>
<tr class="dataTableHeadingRow" style="height:24px;">
	<td><table width="100%" cellpadding="0" cellspacing="0" border="0">
	<tr>
	<td width="300" style="padding-left:10px;"><?php echo '<a id="new_customer_button" onMouseOver="do_hover_change1(this,2);" onMouseOut="do_hover_change1(this,1);" href="javascript: new_customer();">'.tep_image(DIR_WS_IMAGES.'template/img_new.gif',IMAGE_NEW).'</a>'; ?></td>
	<td class="dataTableHeadingContent" align="right"><?php echo HEADING_TITLE_SEARCH.tep_draw_form('customer_search_form',FILENAME_CUSTOMERS,'','post','onSubmit="javascript: return search_customers();"').tep_draw_input_field('customers_search').'</form>&nbsp;&nbsp;<a href="javascript: search_customerss();">'.tep_image(DIR_WS_IMAGES.'template/img_search.gif',HEADING_TITLE_SEARCH,'','','title="Search" align="absbottom"').'</a>&nbsp;&nbsp;'; ?></td>
	</tr></table></td>
</tr>
<tr>
	<td width="100%"><table id="tbl" border="0" width="100%" cellspacing="0" cellpadding="2" class="info_content">
    <tr class="dataTableHeadingRow">
    <td class="dataTableHeadingContent" width="35%" align="left"><?php echo TABLE_HEADING_LASTNAME; ?></td>
    <td class="dataTableHeadingContent" width="35%" align="left"><?php echo TABLE_HEADING_FIRSTNAME; ?></td>
    <td class="dataTableHeadingContent" width="30%" align="left"><?php echo TABLE_HEADING_LAST_MODIFIED; ?></td>				                
    </tr></table></td>
</tr>
<?php $smode='';if($HTTP_GET_VARS['return']=='csl') $smode='csl';?>
<input id="spage" type="hidden" value="<?php echo tep_output_string($HTTP_GET_VARS['page']);?>">
<input id="search_word" type="hidden" value="<?php echo tep_output_string($HTTP_GET_VARS['search_link']);?>">
<tr style="border: solid 1px red;">
	<td style="padding-top:10px;" id="load_customers"><?php echo load_customer('',$cID); ?></td>
</tr>
<tr valign="top" style="border:solid 1px blue;">
	<td id="new_customer_content"></td>
</tr>
<tr>
		<td align="left"><?php if($smode=='csl') echo '<a href="javascript:get_search_links(' . $cID . ');">'.tep_image_button('button_back.gif','Back').'</a>';?></td>
</tr>	
</table>

<!-- Ajax Work Ends -->



<!-- footer //-->
<?php require(DIR_WS_INCLUDES . 'footer.php'); ?>
<!-- footer_eof //-->
</body>
</html> 
<?php require(DIR_WS_INCLUDES . 'application_bottom.php'); 
function base_sbs_get_zone_name($country_id, $zone_id) {
    $zone_query = tep_db_query("select zone_name from " . TABLE_ZONES . " where zone_country_id = '" .(int)$country_id . "' and zone_id = '" .(int)$zone_id . "'");
    if (tep_db_num_rows($zone_query)) {
      $zone = tep_db_fetch_array($zone_query);
      return $zone['zone_name'];
    } else {
      return $default_zone;
    }
  }

?>

<script language="javascript">
var img_src="<?php echo HTTP_SERVER.DIR_WS_ADMIN.'images/';?>";
var ajax_image_load='<?php echo tep_image(DIR_WS_IMAGES.'24-1.gif'); ?>';
var previous_customers_id='';
	function customers_page_navigation(arg1,agr2,agr3,agr4){
		var page_no=1;
		if(agr2==1) var obj=document.getElementById("page_1");
		else if(agr2==2) var obj=document.getElementById("page_2");
		if(agr2 && agr4){
			if(obj){
 	 			page_no=parseInt(obj.options[obj.selectedIndex].value);
 	 			if(agr4=='next') {
 	 				if(obj.length==obj.selectedIndex+1) return;
 	 				page_no+=1;
 	 			}else if(agr4=='prev') {
	 	 			if(obj.selectedIndex==0) return;
 		 			page_no-=1;
 	 			}
 	 			if(page_no<=1) page_no=1;
 	 		} 	 		
		}		
	page=page_no;
	var customers_search=document.getElementById('customers_search').value;		
		if(agr2==1) command="<?php echo tep_href_link(FILENAME_CUSTOMERS,'command=customers_page_navigation&customers_page='); ?>"+page_no;
		else if(agr2==2) command="<?php echo tep_href_link(FILENAME_CUSTOMERS,'command=customers_page_navigation&customers_page='); ?>"+page_no;

		if(command!="") do_get_command(command);
	document.getElementById('load_customers').innerHTML=ajax_image_load;
	}
	
	function load_customers_details(customers_id){
	close_new_customer();
		if(previous_customers_id!='')
				clear_previous_customer_details(previous_customers_id);
	if(document.getElementById('ajax_customers_'+customers_id)){			
	document.getElementById('ajax_customers_'+customers_id).style.display='';
	document.getElementById('ajax_customers_'+customers_id).innerHTML=ajax_image_load;
	do_get_command('<?php echo tep_href_link(FILENAME_CUSTOMERS,'command=load_customers_details&customers_id='); ?>'+customers_id);
	previous_customers_id=customers_id;
	}
	}
	
	function clear_previous_customer_details(customers_id){
		if(document.getElementById('ajax_customers_'+customers_id) && document.getElementById('customers_'+customers_id)){
		document.getElementById('ajax_customers_'+customers_id).innerHTML='';
		document.getElementById('ajax_customers_'+customers_id).style.display='none';
		document.getElementById('customers_'+customers_id).style.display='';
		}
	}
	function edit_customer(customers_id){
	customer_close_panel();
	document.getElementById('span_edit').style.display='';
	document.getElementById('ajax_load').style.display='';
	document.getElementById('ajax_load').innerHTML=ajax_image_load;
	do_get_command('<?php echo tep_href_link(FILENAME_CUSTOMERS,'command=edit_customer&customers_id='); ?>'+customers_id);
	}
	function customer_close_panel(){
	document.getElementById('preview_details').style.display='none';
	//document.getElementById('pay_error_tag').style.display='none';
	document.getElementById('ajax_load').innerHTML='';
	document.getElementById('ajax_load').style.display='none';
	document.getElementById('customers_operation').style.display='none';
	document.getElementById('customers_close_button').style.display='none';
	document.getElementById('span_delete').style.display='none';
	document.getElementById('span_copy').style.display='none';
	document.getElementById('span_edit').style.display='none';
	}
	function close_customer(){
	customer_close_panel();
	document.getElementById('preview_details').style.display='';
	var tr1=document.getElementById("img_ids");
	var imgsrc;
	var node;
	if(tr1)
	for(var j=0;j<tr1.cells.length;j++){
		td=tr1.cells[j];
		imgsrc='';
		for(var i=0;i<td.childNodes.length;i++){
			node=td.childNodes[i];
			if(node.tagName=='IMG'){
				imgsrc=node.src;
				if(imgsrc==img_src+'template/img_edit_hover.gif')
				   td.childNodes[i].src = img_src+'template/img_edit.gif';
				else if(imgsrc==img_src+'template/img_trash_hover.gif')
				   td.childNodes[i].src = img_src+'template/img_trash.gif';
				else if(imgsrc==img_src+'template/img_copy_hover.gif')
				   td.childNodes[i].src = img_src+'template/img_copy.gif';
				break;
			}
		}
	}
	}
	
	function do_close(id,page) {	
		location.href=	'<?php echo tep_href_link(FILENAME_CUSTOMERS,'return=cm&action=reload_customers');?>' + '&customers_id=' +id + '&customers_page=' +page;
		//document.customers.action='<?php echo tep_href_link(FILENAME_CUSTOMERS,'return=ct&action=reload_customers');?>' + '&customers_id=' +id + '&customers_page=' +page;
		//document.customers.submit();
	}
	function block_customer(customers_id,blocked_status){
	do_get_command('<?php echo tep_href_link(FILENAME_CUSTOMERS,'command=block_customer&customers_id='); ?>'+customers_id+'&blocked_status='+blocked_status);
	}
	function delete_customer(customers_id){
		customer_close_panel();
	document.getElementById('span_delete').style.display='';
	document.getElementById('span_edit').style.display='none';
	document.getElementById('ajax_load').style.display='';
	document.getElementById('ajax_load').innerHTML=ajax_image_load;
	do_get_command('<?php echo tep_href_link(FILENAME_CUSTOMERS,'command=delete_customer&customers_id='); ?>'+customers_id);
	}
	function delete_confirm(customers_id){
	document.getElementById('span_delete').style.display='';
	var delete_reviews=document.getElementById('delete_reviews').value;
	do_get_command('<?php echo tep_href_link(FILENAME_CUSTOMERS,'command=delete_confirm&customers_id='); ?>'+customers_id+'&delete_reviews='+delete_reviews);
	document.getElementById('ajax_load').innerHTML=ajax_image_load;
	}
	function new_customer(){
	display_flag=0;

	if(previous_customers_id!='')
				clear_previous_customer_details(previous_customers_id);
		document.getElementById('new_customer_content').innerHTML=ajax_image_load;
		do_get_command('<?php echo tep_href_link(FILENAME_CUSTOMERS,'command=new_customer'); ?>');
	}
	function close_new_customer(){
	display_flag=1;
	document.getElementById('new_customer_button').firstChild.src=document.getElementById('new_customer_button').firstChild.src.replace('_hover.gif','.gif');
	document.getElementById('new_customer_content').innerHTML='';
	}
	function customer_mail(customers_id){
		customer_close_panel();
	document.getElementById('ajax_load').style.display='';
	document.getElementById('ajax_load').innerHTML=ajax_image_load;
	do_get_command('<?php echo tep_href_link(FILENAME_CUSTOMERS,'command=customer_mail&customers_id='); ?>'+customers_id);
	}
	function mail_preview(){
	var error=false; var error_message='';
		if(document.getElementById('customers_email_address').value==0){
		error=true;error_message='<?php echo JS_EMAIL_ADDRESS_ERROR; ?>';
		}
		if(document.getElementById('subject').value==''){
		error=true;error_message+='\n<?php echo JS_SUBJECT_ERROR; ?>';
		}
		if(error==true)
			alert(error_message);
		else{
		document.getElementById('message').value=document.getElementById('if_message').contentWindow.document.body.innerHTML;
		do_post_command('mail','<?php echo tep_href_link(FILENAME_CUSTOMERS,'command=mail_preview'); ?>');
		document.getElementById('ajax_load').innerHTML=ajax_image_load;
		}
	}
	function mail_send(){
	do_post_command('mail','<?php echo tep_href_link(FILENAME_CUSTOMERS,'command=mail_send'); ?>');
	document.getElementById('ajax_load').innerHTML=ajax_image_load;
	}
	
	function search_customers(){
	var customers_search=document.getElementById('customers_search').value;
		if(customers_search!=''){
		do_get_command('<?php echo tep_href_link(FILENAME_CUSTOMERS,'command=search_customers&customers_search='); ?>'+customers_search);
		document.getElementById('load_customers').innerHTML=ajax_image_load;
		}
	return false;
	}
	function search_customerss(){
	var customers_search=document.getElementById('customers_search').value;
		if(customers_search!=''){
		do_get_command('<?php echo tep_href_link(FILENAME_CUSTOMERS,'command=search_customers&customers_search='); ?>'+customers_search);
		document.getElementById('load_customers').innerHTML=ajax_image_load;
		}
	}
	function reset_search(){
	document.getElementById('customers_search').value='';
	do_get_command('<?php echo tep_href_link(FILENAME_CUSTOMERS,'command=reset_search'); ?>');
	document.getElementById('load_customers').innerHTML=ajax_image_load;
	}
	function customers_payment_wallet(customers_id){
	customer_close_panel();
	document.getElementById('span_copy').style.display='';
	
	//document.getElementById('pay_error_tag').style.display='';
	document.getElementById('span_edit').style.display='none';
	document.getElementById('span_delete').style.display='none';
	document.getElementById('ajax_load').style.display='';
	document.getElementById('ajax_load').innerHTML=ajax_image_load;
	do_get_command('<?php echo tep_href_link(FILENAME_CUSTOMERS,'command=customers_payment_wallet&cID='); ?>'+customers_id);
	}
	function payment_validation(){
	var error=false,error_message="",flag=0;
		if(document.getElementById('wallet_amount').value==''){
		error=true;
		error_message='<?php echo JS_WALLET_AMOUNT; ?>';
		}
		for(i=0,len=document.checkout_payment.payment.length;i<len;i++){
			if(document.checkout_payment.payment[i].checked==true)
				flag=1;
		}
		
		if(flag==0){
		error=true;
		error_message+='<?php echo JS_PAYMENT_ERROR; ?>';
		}
	if(error==true)
		alert(error_message);
	else{
		do_post_command('checkout_payment','<?php echo tep_href_link(FILENAME_CUSTOMERS,'command=customers_wallet_confirmation'); ?>');
		//document.getElementById('ajax_load').innerHTML=ajax_image_load;
		document.getElementById('span_copy').style.display='none';
		var tr1=document.getElementById("img_ids");
		var imgsrc;
		var node;
		if(tr1)
		for(var j=0;j<tr1.cells.length;j++){
			td=tr1.cells[j];
			imgsrc='';
			for(var i=0;i<td.childNodes.length;i++){
				node=td.childNodes[i];
				if(node.tagName=='IMG'){
					imgsrc=node.src;
					if(imgsrc==img_src+'template/img_edit_hover.gif')
					   td.childNodes[i].src = img_src+'template/img_edit.gif';
					else if(imgsrc==img_src+'template/img_trash_hover.gif')
					   td.childNodes[i].src = img_src+'template/img_trash.gif';
					else if(imgsrc==img_src+'template/img_copy_hover.gif')
					   td.childNodes[i].src = img_src+'template/img_copy.gif';
					break;
					}
				}
			}
		 }
  }
	
	function customers_wallet_process(){
	document.getElementById('span_copy').style.display='';
	document.getElementById('span_edit').style.display='none';
	document.getElementById('span_delete').style.display='none';
	var action=document.getElementById('action').value;
	do_post_command('checkout_confirmation','<?php echo tep_href_link(FILENAME_CUSTOMERS,'command=customers_wallet_process&action='); ?>'+action);
	document.getElementById('ajax_load').innerHTML=ajax_image_load;
	}
	
	function do_result(result){ 

	
	//alert (err_split[0]);
	
	if(result!='' && result.substr(0,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[1].split(",");		
		textArr=splt[1].split(",");
		sel_zone=splt[2];
		var sel=document.getElementById("entry_state");
		if(document.getElementById("state")) sel=document.getElementById("state");
		var state1=document.getElementById("entry_state1");
		if(document.getElementById("state1")) state1=document.getElementById("state1");
		if(valueArr.length==1) {
			state1.style.display="";
			sel.style.display="none";
		}else {
			state1.value="";
			state1.style.display="none";
			sel.style.display="";
			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
			  }
			}
		}
	  }
	var token=result.split('^^');
		switch(token[0]){
			case 'customers_page_navigation':
				 document.getElementById('load_customers').innerHTML=token[1];
				 break;
			case 'reload_customers'	 :
				 document.getElementById('load_customers').innerHTML=token[1];
					do_get_command('<?php echo tep_href_link(FILENAME_CUSTOMERS,'command=load_customers_details&customers_id='); ?>'+token[2]);
				 break;
			case 'load_customers':
				display_flag=1;
				close_new_customer();
				document.getElementById('load_customers').innerHTML=token[1];
				break;
			case 'search_customers':
				close_new_customer();
				document.getElementById('load_customers').innerHTML=token[1];
				break;
			case 'load_customers_details': 
				document.getElementById('customers_'+token[1]).style.display='none';
				document.getElementById('customers_'+token[1]).innerHTML=token[3];
				document.getElementById('ajax_customers_'+token[1]).innerHTML=token[2];
				previous_customers_id=token[1];
				if(expand_customers==true)
					edit_customers_details(token[1]);
				expand_customers=false;
				if(typeof(token[4])!='undefined'){
					if(document.getElementById('preview_details'))document.getElementById('preview_details').style.display='none';
					do_get_command('<?php echo tep_href_link(FILENAME_CUSTOMERS,'command=edit_customer&customers_id='); ?>'+token[1]+'<?php echo '&return=';?>'+token[4] + '&page=' + token[7]);
				}
				break;
			case 'save_failure':
				document.getElementById('customers_'+token[1]).style.display='none';
				document.getElementById('customers_'+token[1]).innerHTML=token[3];
				document.getElementById('ajax_customers_'+token[1]).innerHTML=token[2];
				document.getElementById('error_tag').style.display='';
				setInterval('save_failure()',3000);
				break;
			case 'edit_customer':
				var customers_id=token[1];
				document.getElementById('ajax_load').innerHTML=token[2];
				document.getElementById('span_edit').style.display='';
				document.getElementById('span_delete').style.display='none';
				document.getElementById('span_copy').style.display='none';
				document.getElementById('customers_operation').style.display='';
				document.getElementById('customers_operation').href="javascript: check_form_customer("+customers_id+")";
				document.getElementById('customers_close_button').style.display='';
				expand_customers=false;
				break;
			case 'new_customer':
				document.getElementById('new_customer_content').innerHTML=token[1];
				break;
			case 'delete_confirm':
				var customers_id=token[1];
				document.getElementById('span_delete').style.display='';
				document.getElementById('ajax_load').innerHTML='<center>'+token[2]+'<center>';
				document.getElementById('customers_operation').style.display='';
				document.getElementById('customers_operation').href="javascript: delete_confirm("+customers_id+")";
				document.getElementById('customers_close_button').style.display='';
				break;
			case 'delete_denied':
				document.getElementById('customers_close_button').style.display='';
				document.getElementById('ajax_load').innerHTML='<center>'+token[1]+'</center>';
				break;
			case 'create_order':
				display_flag=1;
				location.href=token[1];
				break;
			case 'customer_mail':
				document.getElementById('ajax_load').innerHTML=token[1];
				document.getElementById('customers_close_button').style.display='';
				document.getElementById('customers_operation').style.display='';
				document.getElementById('customers_operation').href="javascript: mail_preview();";
				<?php if (HTML_AREA_WYSIWYG_DISABLE_EMAIL == 'Enable') { ?>
           		initEditor('message');
				<?php }  ?>
				break;
			case 'mail_preview':
				document.getElementById('ajax_load').innerHTML=token[1];
				document.getElementById('customers_operation').href="javascript: mail_send();";
				break;
			case 'mail_send':
				document.getElementById('ajax_load').innerHTML=token[1];
				break;
			case 'customers_payment_wallet':
				document.getElementById('span_copy').style.display='';
				document.getElementById('ajax_load').innerHTML=token[1];
				document.getElementById('customers_close_button').style.display='';
				document.getElementById('customers_operation').style.display='';
				document.getElementById('customers_operation').href="javascript: payment_validation();";
						if(document.checkout_payment.elements["payment"]){
							var pay_selection=document.checkout_payment.elements["payment"];
							var sel_payment=false;
							for(i=0;i<pay_selection.length;i++){
								if(!sel_payment && pay_selection[i].checked) {									
									if(document.getElementById("defaultSelected")) selectRowEffect(document.getElementById("defaultSelected"),i,pay_selection[i].value);
									else if(document.getElementById("defaultunSelected")) selectRowEffect(document.getElementById("defaultunSelected"),i,pay_selection[i].value);									
									sel_payment=true;									
								}
							}
						}

				break;
			case 'customers_wallet_confirmation':
					if(token[1]=='error'){
					customer_close_panel();
					document.getElementById('preview_details').style.display='';
					document.getElementById('upload_error_tag').style.display='';
					document.getElementById('upload_error_tag').innerHTML=token[2];
					setInterval('upload_save_failure()',4000);
					}else{
					
					var cap=result.split('^^');
					var err_split=cap[1].split('||');
					if(err_split[0]=='payment_error'){
						document.getElementById('show_payment_error').style.display="";
						document.getElementById('payment_error_text').innerHTML=err_split[1];
						document.getElementById('payment_error_text').style.display='';
						return;
					}
					
					document.getElementById('ajax_load').innerHTML=token[1];
					document.getElementById('customers_operation').href="javascript: customers_wallet_process();";
					
			
					
					}
				break;
			case 'customers_wallet_process':
					if(token[1]=='error'){
					customer_close_panel();
					document.getElementById('preview_details').style.display='';
					document.getElementById('upload_error_tag').style.display='';
					document.getElementById('upload_error_tag').innerHTML=token[2];
					setInterval('upload_save_failure()',4000);
					}else{
					
					document.getElementById('ajax_load').innerHTML=token[1];
					document.getElementById('customers_operation').style.display='none';
					}
				break;
		}
	}
	function save_failure(){
	document.getElementById('error_tag').style.display='none';
	}
	function upload_save_failure(){
	document.getElementById('upload_error_tag').style.display='none';
	}
var display_flag=1;	
	
 function do_hover_change(element,eve){ 
		 var span_copy=document.getElementById("span_copy"); 
		 var span_edit=document.getElementById("span_edit");
		 var span_delete=document.getElementById("span_delete");

	  	 if(element){		   		    		    
		    var img_get_src=element.childNodes[0];
			if(img_get_src){
			    if(img_get_src.src==img_src+'template/img_edit.gif') {
					if(span_edit && span_edit.style.display=="" && eve==1 || eve==2){
					 	img_get_src.src=img_src+'template/img_edit_hover.gif';
					}  		   		 	 			 	 			
			    }else if(eve==3 && img_get_src.src==img_src+'template/img_edit_hover.gif' && span_edit && span_edit.style.display=="none") img_get_src.src=img_src+'template/img_edit.gif';
			    if(img_get_src.src==img_src+'template/img_trash.gif') {
					if(span_delete && span_delete.style.display=="" && eve==1 || eve==2){
					 	img_get_src.src=img_src+'template/img_trash_hover.gif';
					}  		   		 	 			 	 			
			    }else if(eve==3 && img_get_src.src==img_src+'template/img_trash_hover.gif' && span_delete && span_delete.style.display=="none") img_get_src.src=img_src+'template/img_trash.gif';
			    if(img_get_src.src==img_src+'template/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';
		  }
		 }		 
	 }  	


	function do_hover_change1(element,mode){ 
	if(display_flag==1){
		if (element.mode && mode==element.mode) return;
		if (mode==2)
			element.firstChild.src=element.firstChild.src.replace(".gif","_hover.gif");
		else
			element.firstChild.src=element.firstChild.src.replace("_hover.gif",".gif");
	}
	element.mode=mode;
	} 
	function do_hover_change2(element,mode){ 

		if (element.mode && mode==element.mode) return;
		if (mode==2)
			element.firstChild.src=element.firstChild.src.replace(".gif","_hover.gif");
		else
			element.firstChild.src=element.firstChild.src.replace("_hover.gif",".gif");

	element.mode=mode;
	} 

//var pwd ="<?php //echo TEXT_PWD?>";
	function AddField(){
	 var select_field;
	 var select_id;
	
	 if (document.mail.fields.selectedIndex<=-1) return;
	 select_id=document.mail.fields.options[document.mail.fields.selectedIndex].value;
	
	 
	 if (select_id.length>3) return;
	
	 select_field="%%" + document.mail.fields.options[document.mail.fields.selectedIndex].innerHTML + "%%";
	 select_field=select_field.replace("&nbsp;&nbsp;","");
	
	
	 if(document.mail.chkpwd.checked==false && select_id=='PWD' ){
	 select_field="--"+"Hidden"+"--";
	
	
	 }
     editor.insertHTML(select_field);
	}
	
	function get_search_links(id) { 
		location.href='<?php echo tep_href_link(FILENAME_SEARCH_LINKS,'mPath=1');?>&id='+id+'&action=get_details&return=csl&page=' + document.getElementById('spage').value + '&search_link='  + document.getElementById('search_word').value ;
	}
<?php
	
	//$cID=isset($HTTP_GET_VARS['cID'])?$HTTP_GET_VARS['cID']:'';
	//if(isset($HTTP_GET_VARS['cID']))
	//	echo "load_customers_details($cID)";
?>	
	
</script>

<script language="javascript">
function changing_status(){ 
	//document.getElementById('shipping').style.display='';
} 
var expand_customers=false;
var page=1;
<?php 
	if(isset($HTTP_GET_VARS['expand']) && $HTTP_GET_VARS['expand']=='expand_customers'){
		if(isset($HTTP_GET_VARS['customers_page'])) {
?>page='<?php echo $HTTP_GET_VARS['customers_page']?>';
<?php }?>
expand_customers=true;
	load_customers_details('<?php echo $HTTP_GET_VARS['customers_id'];?>');
	//edit_order_details('<?php echo $HTTP_GET_VARS['customers_id'];?>');
<?php } ?>
<?php if($HTTP_GET_VARS['return'] && $HTTP_GET_VARS['cID']){?>
do_get_command('<?php echo tep_href_link(FILENAME_CUSTOMERS,'command=load_customers_details&customers_id=' . $HTTP_GET_VARS['cID'] . '&return=' . $HTTP_GET_VARS['return'] . '&page=' . $HTTP_GET_VARS['page']); ?>');
<?php }?>

<?php if($HTTP_GET_VARS['action']=='reload_customers'){ ?>
	do_get_command('<?php echo tep_href_link(FILENAME_CUSTOMERS,'command=reload_customers&&customers_id=' . $HTTP_GET_VARS['customers_id'] . '&customers_page=' . $HTTP_GET_VARS['customers_page']); ?>');
<?php } ?>
</script>