<?php

// Check to ensure this file is included in Freeway!
defined('_FEXEC') or die(); 
  echo tep_draw_form('checkout_attendees', tep_href_link(FILENAME_CHECKOUT_ATTENDEES, tep_get_all_get_params(),'SSL'),'post','onSubmit="javascript: return check_form();"'); ?>
 <table border="0" width="100%" cellspacing="0" cellpadding="<?php echo CELLPADDING_SUB; ?>">
	<?php
	// BOF: Lango Added for template MOD
	if (SHOW_HEADING_TITLE_ORIGINAL == 'yes') {
	$header_text = '&nbsp;'
	//EOF: Lango Added for template MOD
	?>
      <tr>																													
        <td><table border="0" width="100%" cellspacing="0" cellpadding="0">
          <tr>
            <td class="pageHeading"><?php echo HEADING_TITLE; ?></td>
            <td class="pageHeading" align="right"><?php echo tep_image(DIR_WS_IMAGES . 'freeway.png', HEADING_TITLE, HEADING_IMAGE_WIDTH, HEADING_IMAGE_HEIGHT); ?></td>
          	<?php echo DIR_WS_IMAGES . 'freeway.png';?>
		  </tr>
        </table></td>
      </tr>
<?php
// BOF: Lango Added for template MOD
}else{
$header_text = HEADING_TITLE;
}
// EOF: Lango Added for template MOD
	if(!isset($hide_row_top)) {
?>
      <tr>
        <td><?php echo tep_draw_separator('pixel_trans.gif', '100%', '10'); ?></td>
      </tr>
<?php } ?>	  
<script language="JavaScript">

function do_expand(obj){
	if(document.getElementById("pop_common_sort_display")){
		document.getElementById("pop_common_sort_display").style.display="";
		if(obj) document.getElementById("pop_common_sort_display").style.display="none";
		document.getElementById('login_failed').style.display='none';
	}
}
function do_submit(){
	var uname=document.quick_find.user.value;
	var pword=document.quick_find.pass.value;
	if(uname!='' && pword!=''){
		command='<?php echo tep_href_link(FILENAME_LOGIN,'action=return','NONSSL',true,false); ?>';
		do_post_command('quick_find',command);
	}
	document.quick_find.user.value="";
	document.quick_find.pass.value="";
}


</script>
	  
<?php
// BOF: Lango Added for template MOD
if (MAIN_TABLE_BORDER == 'yes'){
table_image_border_top(false, false, $header_text);
}
// EOF: Lango Added for template MOD
$cust_array=array("name"=>"",
					"email"=>"",
					"streetaddress"=>"",
					"city"=>"",
					"postcode"=>"",
					"state"=>"",
					"city"=>"",
					"country"=>"",
					"attendee" =>""
					);

$cust_info=new objectInfo($cust_array);

for($icnt=0;$icnt<$no_attendees;$icnt++){ 
	if ($error==true && isset($customers_list[$icnt])){
		$customer=new objectInfo($customers_list[$icnt]);
	} else if ($mode=="edit"){
		$customer=new objectInfo($cart->attendees[$icnt]);
	} else { 
		$customer=$cust_info;
	}
	$customer->name=sprintf(TEXT_ATTENDEE,$icnt+1); 
	$focus_option=' onFocus="javascript:clear_error(' . $icnt . ');"';
?> 
		<tr>
			<td class="messageStackWarning" id="error_box_<?php echo $icnt;?>" style="display:<?php echo ($error && isset($errors[$icnt])?"":"none");?>">
				<?php
					if ($error) {
						for ($jcnt=0;$jcnt<=count($errors[$icnt]);$jcnt++){
							echo $errors[$icnt][$jcnt] . '<br>';
						}
					}
				?>
			</td>
		</tr>
      <tr>
        <td><table border="0" width="100%" cellspacing="1" cellpadding="2" class="infoBox">
          <tr>
            <td class="infoBoxContents">
			    <table border="0" width="100%" cellspacing="0" cellpadding="2">
              <tr>
			    <td colspan="2" valign="top" align="left"><B><?php echo $customer->name;?></B></td>
			  </tr>
			  <?php if(tep_db_num_rows($customer_query)>0 || $customer_id==''){  
			  			if($icnt==0 || $customer_id=='') $style = 'display:none';
			 				else $style = "display:''";  ?>
			  	<tr>
			  	<td class="main" colspan="2" >
			  	<table border="0"  cellspacing="0" cellpadding="0" width="100%">
			  		<tr>
			  		<td align="left" class="main" width="176" >
						<div id="chk_ids[<?php echo $icnt; ?>]" style='<?php echo $style;?>'> 
			  			<?php echo tep_draw_checkbox_field('attendee['.$icnt.']',1,($customer->attendee==1)?true:false,'id="attendee[]" onclick="javascript:hide_customerlistbox('.$icnt.');"' ).' '. TEXT_ADD_EXISTING_CUSTOMER;?>
			  		</div></td>
					<td class="main" id="select_cus[<?php echo $icnt; ?>]">
						<?php  echo tep_draw_pull_down_menu('customer_text',$customer_list,check_customer_exists($customer->email_address,($customer->attendee==1)?true:false),"onchange=javascript:fill_details($icnt); onkeydown=javascript:fill_details($icnt); onkeyup=javascript:fill_details($icnt); style='display:none'"); ?>
					</td>
					
			  		</tr>
			    </table>
				</td>
			  </tr>
			  <?php } if($customer_id=='' && $icnt==0){ ?>
			   <tr height="30" id="return_login">
                <td class="infoBoxHeadingPage" width="70" align="left"><?php echo TEXT_RETURNING_CUSTOMERS;?></td>
                <td class="infoBoxHeadingPage" width="50" align="left" nowrap><?php echo tep_draw_separator('pixel_trans.gif',60,1).'<a href="javascript:do_expand();">'.tep_template_image_button('button_login.gif',IMAGE_BUTTON_LOGIN,'align=absmiddle').'</a>';?></td>
			  </tr>
			  <tr height="30">
                <td class="infoBoxHeadingPage" width="70" align="left"><?php echo TEXT_NEW_CUSTOMERS;?></td>
                <td class="infoBoxHeadingPage" width="50" align="left" nowrap><?php  echo TEXT_FILL_INFO;?></td>
			  </tr>
			  <?php } ?>
			  <tr>
                <td class="main" width="70" align="left"><?php echo ENTRY_FIRST_NAME;?></td>
                <td class="main" width="50" align="left" nowrap><?php  echo tep_draw_input_field('first_name[]',$customer->first_name,$focus_option) . '&nbsp;<span class="inputRequirement">' . ENTRY_REQUIRED . '</span>';?></td>
			  </tr>
			  <tr>
                <td class="main" width="70" align="left"><?php echo ENTRY_LAST_NAME; ?></td>
                <td class="main" width="50" align="left" nowrap><?php  echo tep_draw_input_field('last_name[]',$customer->last_name,$focus_option) . '&nbsp;<span class="inputRequirement">' . ENTRY_REQUIRED . '</span>';?></td>
			  </tr>
              <tr>
                <td nowrap class="main" width="90" align="left"><?php echo ENTRY_EMAIL_ADDRESS; ?></td>
                <td class="main" width="100" align="left" nowrap="nowrap"><?php echo tep_draw_input_field('email_address[]',$customer->email_address,$focus_option) . '&nbsp;<span class="inputRequirement">' . ENTRY_REQUIRED . '</span>';?> 
					<?php echo '&nbsp;' . (($icnt==0 && $no_attendees>1)?'<a href="javascript:dofill();">' . tep_template_image_button('button_apply_to_all.gif','','align=absmiddle') .'</a>':'');?>
				</td>
			  </tr>
			  <tr>
                <td nowrap class="main" width="90" align="left"><?php echo ENTRY_STREET_ADDRESS; ?></td>
                <td class="main" width="50" align="left"><?php echo tep_draw_input_field('street_address[]',$customer->street_address,$focus_option) . '&nbsp;<span class="inputRequirement">' . ENTRY_REQUIRED . '</span>'; ?></td>
			  </tr>
			  <tr>
                <td nowrap class="main" width="90" align="left"><?php echo ENTRY_CITY; ?></td>
                <td class="main" width="70%">
				  <table width="100%" align="center" border="0" cellpadding="0" cellspacing="0">
				     <tr><td  class="main" align="left"><?php echo tep_draw_input_field('city[]',$customer->city,$focus_option) . '&nbsp;<span class="inputRequirement">' . ENTRY_REQUIRED . '</span>'; ?></td>
				  </table>
				</td>
			  </tr>
			  <tr>
                <td nowrap class="main" width="90" align="left"><?php echo ENTRY_POSTCODE ; ?></td>
                <td class="main" width="50" align="left"><?php echo tep_draw_input_field('postcode[]',$customer->postcode,$focus_option) . '&nbsp;<span class="inputRequirement">' . ENTRY_REQUIRED . '</span>'; ?></td>
			  </tr>
			  <tr>
                <td nowrap class="main" width="90" align="left"><?php echo ENTRY_COUNTRY; ?></td>
                <td class="main" width="70%" align="left">
					<?php echo tep_get_country_list('country[]',$customer->country,'id="country[]" onchange="javascript:show_state('.$icnt.');"',$focus_option) .'&nbsp;<span class="inputRequirement">' . ENTRY_REQUIRED . '</span>';
				 			//echo '&nbsp;' . (($icnt==0 && $no_attendees>2)?'<a href="javascript:dofill();">' . TEXT_APPLY_ALL .'</a>':'');
				?></td>
			  </tr>
			  <tr>
                <td nowrap class="main" width="90" align="left"><?php echo ENTRY_STATE; ?></td>
                <td class="main" width="70%" align="left">
				<?php 
					$customer_state=tep_get_zone_name($customer->country, $customer->zone_id, $customer->state);
					if ($error==true && sizeof($state_errors[$icnt])>0){
						//if ($entry_state_has_zones == true ) {
							$zones_array = array();
							$zones_query = tep_db_query("select zone_name from " . TABLE_ZONES . " where zone_country_id = '" . (int)$customer->country. "' order by zone_name");
							while ($zones_values = tep_db_fetch_array($zones_query)) {
								$zones_array[] = array('id' => $zones_values['zone_name'], 'text' => $zones_values['zone_name']);
							}	
						//} 
						echo tep_draw_pull_down_menu('state[]', $zones_array,$customer->state,'id="state[]"','');
						echo tep_draw_input_field('state1[]',$customer_state,'id="state1[]" style="display:none"'); 
					} else {
						   echo tep_draw_pull_down_menu('state[]', $zones_array,$customer->state,'id="state[]" style="display:none"','');
							echo tep_draw_input_field('state1[]',$customer_state,'id="state1[]"'); 
					}
					echo tep_draw_hidden_field('customer_state[]');
				//	echo tep_draw_input_field('state1[]',$customer->state,'id="state1[]"');
				/*	if($no_attendees==2)
						echo '<div id="div_state">'.tep_draw_pull_down_menu('state[]', array(),'','id="state[]" style="display:none"').'</div>';
					else
					   echo tep_draw_pull_down_menu('state[]', array(),'','id="state[]" style="display:none"'); */
				?>
				</td>
			  </tr>
			  <tr>
			    <td colspan="2"><hr></td>
			  </tr>
            </table></td>
          </tr>
        </table></td>
      </tr>
       <script language='javascript'>
      		var cnt=<?php echo $icnt;?>;
      		var check="<?php echo ($customer->attendee==1)?true:false;?>";
      		if(check) hide_customerlistbox(cnt);  	
		</script> 
		<?php  
  }
// BOF: Lango Added for template MOD
if (MAIN_TABLE_BORDER == 'yes'){
table_image_border_bottom();
}
// EOF: Lango Added for template 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" class="infoBox">
          <tr class="infoBoxContents">
            <td><table border="0" width="100%" cellspacing="0" cellpadding="2">
			  <tr>
                <td width="10"><?php echo tep_draw_separator('pixel_trans.gif', '10', '1'); ?></td>
                <td align="right"><?php echo tep_template_image_submit('button_continue.gif', IMAGE_BUTTON_CONTINUE); ?></td>
                <td width="10"><?php echo tep_draw_separator('pixel_trans.gif', '10', '1'); ?></td>
              </tr>
            </table></td>
          </tr>
        </table></td>
      </tr>
    </table>
<?php
		// draw the hidden field
		if ($mode=="add"){
			echo tep_draw_hidden("old_orders_id",$HTTP_POST_VARS["old_orders_id"]);
			echo tep_draw_hidden("events_id",$HTTP_POST_VARS["events_id"]);
			echo tep_draw_hidden("event_question_type",$HTTP_POST_VARS["event_question_type"]);
			echo tep_draw_hidden("event_question_value_data",$HTTP_POST_VARS["event_question_value_data"]);
			echo tep_draw_hidden("no_attendees",$no_attendees);
		
			$session_id=tep_db_prepare_input($HTTP_POST_VARS["session_id"]);
			$session_type=tep_db_prepare_input($HTTP_POST_VARS["session_type"]);
			$session_group=tep_db_prepare_input($HTTP_POST_VARS["session_group"]);
			$session_date=tep_db_prepare_input($HTTP_POST_VARS["session_date"]);
			for ($icnt=0;$icnt<count($session_id);$icnt++){
				echo tep_draw_hidden("session_select_" . $session_id[$icnt],$HTTP_POST_VARS["session_select_" . $session_id[$icnt]]);
				echo tep_draw_hidden("session_id[]",$session_id[$icnt]);
				echo tep_draw_hidden("session_type[]",$session_type[$icnt]);
				echo tep_draw_hidden("session_group[]",$session_group[$icnt]);
				echo tep_draw_hidden("session_date[]",$session_date[$icnt]);
			}
		}
/*function check_customer_exists($email,$id=false){
	global $check_array,$icnt,$mode;
	
	if(!$check_array[$icnt] && $mode!='edit') return;
	$retutn=false;
	if($email=='') return;
	$check_customer=tep_db_query("select customers_id from ".TABLE_CUSTOMERS." where customers_email_address='".$email."'");
	if(tep_db_num_rows($check_customer)>0)
		$return=true;
	if($id){
		$customer_id=tep_db_fetch_array($check_customer);
		$return=$customer_id['customers_id'];
	}	
	return $return;
}*/
?>
<input type="hidden" name="post_action" value="save">
</form>

<script language="javascript">
function start_up(){
	cnt=0;
	id='<?php echo $customer_id; ?>';
	command="<?php echo tep_href_link(FILENAME_CHECKOUT_ATTENDEES,'command=fetch_customers_details','NONSSL',true,false);?>&cust_id="+id+"&cnt="+cnt; 
	do_get_command(command);
}
<?php if($customer_id!=''){?>
start_up();
<?php } ?>
</script>
