<?php
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: 			*/
// +----------------------------------------------------------------------+
// | PHP version 4/5                                                      |
// +----------------------------------------------------------------------+
// | Copyright (c) 2004-2010 ARMIA INC                                    |
// +----------------------------------------------------------------------+
// | This source file is a part of iScripts VistaCart                     |
// +----------------------------------------------------------------------+
// | Authors: Jipson<jipson.thomas@armiasystems.com>             		  |
// +----------------------------------------------------------------------+
?>
<?php echo $javascript->link('jquery.js'); ?>
<?php echo $javascript->link('alphanumeric.js'); ?>
<script>
$(document).ready(function() 
{
  var dflt_cntry='';
  dflt_cntry='<?php echo $ship["country"];?>';
  if(dflt_cntry != '')
  setStates(dflt_cntry);
  else
  setStates('US');
});
</script>
<script language="javascript" type="text/javascript">
function chk(){
	var errorstr = '';
	var msgstr = "Sorry, we cannot complete your request.\nKindly provide us the missing or incorrect information enclosed below.\n\n";
	with(document.bill_ship)
	{ 	
		
		if (fname.value == "") { errorstr += "- Please enter First name.\n"; fname.focus();}
		if(chkname(fname.value)==false) { errorstr += "- First name should contain only characters. \n"; fname.focus();}
		if(lname.value != "")  
		{
		  if(chkname(lname.value)==false) { errorstr += "- Last name should contain only characters. \n"; lname.focus();}
		}				
		if (address.value == "") { errorstr += "- Please enter Address.\n"; address.focus();}
		if (country.value == "") { errorstr += "- Please select Country.\n"; country.focus();}
		if (zip.value == "") { errorstr += "- Please enter the Zip Code.\n"; zip.focus();}
		var zipval=zip.value;
		if(country.value == 'US')
		{
		    if(isNaN(zipval))
		    {   errorstr += "- Zip code should contain only numbers.\n"; zip.focus(); }	
		    if(zipval.length < 5 || zipval.length > 5)
		    {   errorstr += "- Zip code should contain 5 numeric digits.\n"; zip.focus(); }	
		}
		if($.trim($('#country').val()) != 'US')
		 {
		   if($.trim($('#state').val()) == "") { errorstr += "- Please enter State name. \n"; state.focus();} 
		 } 
		if($.trim($('#phone').val()) != "")  
		{ 
		      if(verify(phone.value)==false)
              { errorstr += "- Phone number should contain only numbers, spaces, (, ), - and + \n"; phone.focus();}
		}	
		if($.trim($('#mobile').val()) != "")  
		{   
			  if(verify(mobile.value)==false)
              { errorstr += "- Mobile number should contain only numbers, spaces, (, ), - and + \n"; mobile.focus();}
		}	
		if($.trim($('#fax').val()) != "")  
		{   
			  if(verify(fax.value)==false)
              { errorstr += "- Fax number should contain only numbers, spaces, (, ), - and + \n"; fax.focus();}
		}	  
	}	
	
	if (errorstr != '')
	{
		msgstr = msgstr + errorstr;
		alert(msgstr);
		return false;
	}
	else
	{
		return true;
	}
} 

function chkname(str) 
{
    return /^[A-Za-z\s]{1,}$/.test(str);
}
function verify(str) 
{
    return /^[0-9\-\s\)\(\+]{1,}$/.test(str);
}

</script>

<script type="text/javascript">
$('#zip').numeric({allow:"."});
function setStates(val)
{
  if(val=='US')
  {
    $('#us_states').show();
	$('#other_states').hide(); 
  }	
  else
  {
    $('#other_states').show(); 
	$('#us_states').hide();
  }	
}
</script>
            
			<div align="center">
				<h2 class="title text-center mainhd">My Account</h2>
            </div>
			
			
            <br />
            <div align="left" id="item_details_admin">
              <!--items display area start -->
              <div align="center" id="items_display_area_admin">
                <div align="left" class="inner_content_area_admin">
				<?php $session->flash(); ?>
                <form name="bill_ship" action="" method="post">
				 <input type="hidden" name="addr_type" value="Shipping">
    			<input type="hidden" name="user_id" value="<?php echo $user_id; ?>">
                  
				   <div id="admin_heading">Shipping Address</div>
				  <div id="grid_admin" class="grid-adm" style="background:none ">
                    <div align="left" id="inner_leftcontent" class="lft-cell">
                      <p class="maintext_inner">First Name &nbsp;<span class="required_field">*</span></p>
                    </div>
                    <div align="right" id="inner_rightcontent" class="ryt-cell">
                     <span class="toplinks">
						<input type="text" value="<?php  if(!empty($ship["fname"])) echo $ship["fname"]; ?>" name="fname" id="fname"  class="box2_admin" size="27">
                      
                        </span>
                    </div>
                    <div align="left" class="float_clear1"><?php echo $html->image('/img/clear.gif');?></div>
                  </div>
                  <div align="left" class="float_clear1"><?php echo $html->image('/img/clear.gif');?></div>
                  <div id="grid_admin" class="grid-adm" style="background:none ">
                    <div align="left" id="inner_leftcontent" class="lft-cell">
                      <p class="maintext_inner">Last Name</p>
                    </div>
                    <div align="right" id="inner_rightcontent" class="ryt-cell">
                      <span class="toplinks">
						<input type="text" value="<?php  if(!empty($ship["lname"])) echo $ship["lname"]; ?>" name="lname" id="lname" class="box2_admin" size="27">
                        </span>
                    </div>
                    <div align="left" class="float_clear1"><?php echo $html->image('/img/clear.gif');?></div>
                  </div>
                  <div align="left" class="float_clear1"><?php echo $html->image('/img/clear.gif');?></div>
                  <div id="grid_admin" class="grid-adm" style="background:none ">
                    <div align="left" id="inner_leftcontent" class="lft-cell">
                      <p class="maintext_inner">Address &nbsp;<span class="required_field">*</span></p>
                    </div>
                    <div align="right" id="inner_rightcontent" class="ryt-cell">
                     <span class="toplinks">
						<input type="text" value="<?php  if(!empty($ship["address"])) echo $ship["address"]; ?>" name="address" class="box2_admin" size="27">
                      
                        </span>
                    </div>
                    <div align="left" class="float_clear1"><?php echo $html->image('/img/clear.gif');?></div>
                  </div>
                  <div align="left" class="float_clear1"><?php echo $html->image('/img/clear.gif');?></div>
				  
				  
				
				  
				  
                  <div id="grid_admin" class="grid-adm" style="background:none ">
                    <div align="left" id="inner_leftcontent" class="lft-cell">
                      <p class="maintext_inner">Country &nbsp;<span class="required_field">*</span></p>
                    </div>
                    <div align="right" id="inner_rightcontent" class="ryt-cell">
                     <span class="toplinks">
						<?php  if(!empty($ship["country"])) { ?>
							<?php echo $form->input('country', array('options' => $countrylist,'label' => '', 'selected' => $ship["country"],'class' => 'box2_admin','onchange' => 'javascript:setStates(this.value)'));?>
						<?php }else{ ?>
							<?php echo $form->input('country', array('options' => $countrylist,'label' => '', 'selected' => 'US','class' => 'box2_admin','onchange' => 'javascript:setStates(this.value)'));?>
						<?php } ?>     
                        </span>
                    </div>
                    <div align="left" class="float_clear1"><?php echo $html->image('/img/clear.gif');?></div>
                  </div>
                  <div align="left" class="float_clear1"><?php echo $html->image('/img/clear.gif');?></div>
				  
				  <div  id="us_states">
				    <div id="grid_admin" class="grid-adm" style="background:none ">
                    <div align="left" id="inner_leftcontent" class="lft-cell">
                      <p class="maintext_inner">State &nbsp;<span class="required_field">*</span></p>
                    </div>
                    <div align="right" id="inner_rightcontent" class="ryt-cell">
                    <span class="toplinks">
													 <select class="box2_admin" name="us_state" id="us_state">
						<?php
						foreach($us_states as $stval) { ?>
						<option value="<?php echo $stval["Statecode"]["code"];?>" <?php if($stval["Statecode"]["code"] == $ship["state"]) echo "selected=selected";?>><?php echo $stval["Statecode"]["name"];?></option>
						<?php } ?>
						</select>    
                        </span>
                    </div>
                    <div align="left" class="float_clear1"><?php echo $html->image('/img/clear.gif');?></div>
                  </div>
                  <div align="left" class="float_clear1"><?php echo $html->image('/img/clear.gif');?></div>
				  </div>
				  
				  
				    <div id="other_states" style="display:none;">
				   <div id="grid_admin" class="grid-adm" style="background:none ">
                    <div align="left" id="inner_leftcontent" class="lft-cell">
                      <p class="maintext_inner">State &nbsp;<span class="required_field">*</span></p>

                    </div>
                    <div align="right" id="inner_rightcontent" class="ryt-cell">
                    <span class="toplinks">
						<input type="text" value="<?php  if($ship["country"] <> 'US') { if(!empty($ship["state"])) echo $ship["state"];}  ?>" name="state" id="state" class="box2_admin" size="27">
                      
                        </span>
                    </div>
                    <div align="left" class="float_clear1"><?php echo $html->image('/img/clear.gif');?></div>
                  </div>
                  <div align="left" class="float_clear1"><?php echo $html->image('/img/clear.gif');?></div>
				  </div>
				  
				  
				    
                  <div id="grid_admin" class="grid-adm" style="background:none ">
                    <div align="left" id="inner_leftcontent" class="lft-cell">
                      <p class="maintext_inner">City</p>
                    </div>
                    <div align="right" id="inner_rightcontent" class="ryt-cell">
                      <span class="toplinks">
						<input type="text" value="<?php  if(!empty($ship["city"])) echo $ship["city"]; ?>" name="city" class="box2_admin" size="27">
                      
                        </span>
                    </div>
                    <div align="left" class="float_clear1"><?php echo $html->image('/img/clear.gif');?></div>
                  </div>
                  <div align="left" class="float_clear1"><?php echo $html->image('/img/clear.gif');?></div>  
				  
                
				  
				  
				  
				  
				  
                  <div id="grid_admin" class="grid-adm" style="background:none ">
                    <div align="left" id="inner_leftcontent" class="lft-cell">
                      <p class="maintext_inner">Zip Code &nbsp;<span class="required_field">*</span></p>
                    </div>
                    <div align="right" id="inner_rightcontent" class="ryt-cell">
                      <span class="toplinks">
						<input type="text" value="<?php  if(!empty($ship["zip"])) echo $ship["zip"]; ?>" name="zip" id="zip" class="box2_admin" size="27">
                      
                        </span>
                    </div>
                    <div align="left" class="float_clear1"><?php echo $html->image('/img/clear.gif');?></div>
                  </div>
                  <div align="left" class="float_clear1"><?php echo $html->image('/img/clear.gif');?></div>
				  <div id="grid_admin" class="grid-adm" style="background:none ">
                    <div align="left" id="inner_leftcontent" class="lft-cell">
                      <p class="maintext_inner">Phone </p>
                    </div>
                    <div align="right" id="inner_rightcontent" class="ryt-cell">
                      <span class="toplinks">
						<input type="text" value="<?php  if(!empty($ship["phone"])) echo $ship["phone"]; ?>" name="phone" id="phone" class="box2_admin" size="27">
                      
                        </span>
                    </div>
                    <div align="left" class="float_clear1"><?php echo $html->image('/img/clear.gif');?></div>
                  </div>
                  <div align="left" class="float_clear1"><?php echo $html->image('/img/clear.gif');?></div>
				  <div id="grid_admin" class="grid-adm" style="background:none ">
                    <div align="left" id="inner_leftcontent" class="lft-cell">
                      <p class="maintext_inner">Mobile </p>
                    </div>
                    <div align="right" id="inner_rightcontent" class="ryt-cell">
                      <span class="toplinks">
						<input type="text" value="<?php  if(!empty($ship["mobile"])) echo $ship["mobile"]; ?>" name="mobile"  id="mobile" class="box2_admin" size="27">
                      
                        </span>
                    </div>
                    <div align="left" class="float_clear1"><?php echo $html->image('/img/clear.gif');?></div>
                  </div>
                  <div align="left" class="float_clear1"><?php echo $html->image('/img/clear.gif');?></div>
				  <div id="grid_admin" class="grid-adm" style="background:none ">
                    <div align="left" id="inner_leftcontent" class="lft-cell">
                      <p class="maintext_inner">Fax</p>
                    </div>
                    <div align="right" id="inner_rightcontent" class="ryt-cell">
                      <span class="toplinks">
						<input type="text" value="<?php  if(!empty($ship["fax"])) echo $ship["fax"]; ?>" name="fax" id="fax" class="box2_admin" size="27">
                        </span>
                    </div>
                    <div align="left" class="float_clear1"><?php echo $html->image('/img/clear.gif');?></div>
                  </div>
                  <div align="left" class="float_clear1"><?php echo $html->image('/img/clear.gif');?></div>
                 <div id="admin_bottom" style="margin-bottom:20px ">
				<div align="left" id="inner_leftcontent" class="lft-cell">
				  <p class="maintext_inner">&nbsp;</p>
				</div>
				<div align="right" id="inner_rightcontent" class="ryt-cell">
					<span class="toplinks">		
					<input type="submit" value="Save" onClick="return chk();" class="btn-usr01" >
					<input type="button" value="Cancel" onClick="window.location.href='<?php echo $sitebase.$sitefolder;?>/users/myaccount/'"  class="btn-gry01" >
					
					</span>
					<div class="clear"></div>
				</div>
				<div align="left" class="float_clear1"><?php echo $html->image('/img/clear.gif', array('width' => 1, 'height' => 1));?></div>
			</div>
                
                <!--form area end -->
				</form>
               </div> </div>
              <div align="left" class="float_clear1"></div>
            </div>
            <div align="left" class="float_clear1"><?php echo $html->image('/img/clear.gif');?></div>
<script type="text/javascript">
$('#fname').alpha();
$('#lname').alpha();
$('#phone').numeric({allow:"(,),-,+"});
$('#mobile').numeric({allow:"(,),-,+"});
$('#fax').numeric({allow:"(,),-,+"});
</script>