<?php 
/*
##################################################################
#                       PHP 4&5 MySQL 4&5                        #
##################################################################
#           Copyright (c) 2004-2008 Armia Systems Inc            #
##################################################################
#               This file is part of Cybermatch site             #
##################################################################
#    Developed By: simi (simi@armia.com)                         #

##################################################################
#               Developed On:   03-04-2008                       #
##################################################################
#               Modified By:                                     #
##################################################################
#               Modified On:                                     #
##################################################################
# This script may not be distributed, sold, given away for free  #
# to third party, or used as a part of any internet services 	 #
# such as webdesign etc.                                         #
##################################################################
*/

require_once ("config.inc.php");
require_once ("includes/userlogincheck.inc.php");
require_once ("includes/mysql.inc.php");
require_once ("includes/arrays.inc.php");
require_once ("classes/settings.class.php");
require_once ("classes/userside.class.php");
require_once ("classes/misc.class.php");

$message	= "";
$scripts	= "";

if (!$objDB) {
	$message	= "Unable to Locate Database Server.";
} else {
	$objU			= new userside($objDB);
	$objS			= new settings($objDB);
	$objM			= new misc($objDB);
	$objS->set_variables();
        $arrCountry	= $objU->get_country_list();
	
	if (isset($_POST['PYN'])) {
		$objU->set_values($_POST);
		$message	= $objU->edit_creditcard($_SESSION['user_id']);
                $arrState	= $objU->get_state_list($objU->vCountry);
		$arrCounty	= $objU->get_county_list($objU->vState);
		if ($message == "") {
			$message	= "<font color='green'>Your credit card information successfully saved.</font><br>";
		}
	} else {
		$objU->set_creditcard($_SESSION['user_id']);
                $arrState	= $objU->get_state_list($objU->vCountry);
		$arrCounty	= $objU->get_county_list($objU->vState);
	}
	
	$scripts	= $objM->get_script($message);
	$message	= $objM->remove_script($message);
}
include_once ("title.inc.php");
include_once ("tophtml.inc.php");
?>
<script type="text/javascript"  src="js/googlefix.js"></script>
<script type="text/javascript"  src="js/ajax.js"></script>
<script language="javascript" type="text/javascript">
function changeCSS(obj, type)
{
	if (type == 'text') {
		obj.className = 'textbox';
	} else if (type == 'textarea') {
		obj.className = 'textbox_textarea';
	} else if (type == 'select') {
		obj.className = 'textbox';
	} else {
		obj.className = 'textbox';
	}
}
function clickConfirm(){
	var frm = document.frmPayment;
	var flag = false;
	if (frm.vFirstName.value == "") {
		alert("Please enter your firstname.");
		frm.vFirstName.focus();
		frm.vFirstName.className ='errorinput';
		return false;
	}
	if (frm.vLastName.value == "") {
		alert("Please enter your lastname.");
		frm.vLastName.focus();
		frm.vLastName.className ='errorinput';
		return false;
	}
	if (frm.nNumber.value == "") {
		alert("Please enter your cardnumber.");
		frm.nNumber.focus();
		frm.nNumber.className ='errorinput';
		return false;
	}
	if (frm.nCvv2.value == "") {
		alert("Please enter validation code of your card.");
		frm.nCvv2.focus();
		frm.nCvv2.className ='errorinput';
		return false;
	}
	if (frm.vMM.value == "") {
		alert("Please enter month of expiry date of your card.");
		frm.vMM.focus();
		frm.vMM.className ='errorinput';
		return false;
	}
	if (frm.vYYYY.value == "") {
		alert("Please enter year of expiry date of your card.");
		frm.vYYYY.focus();
		frm.vYYYY.className ='errorinput';
		return false;
	}
	if (frm.vAddress.value == "") {
		alert("Please enter your billing address.");
		frm.vAddress.focus();
		frm.vAddress.className ='errorinput';
		return false;
	}
	
	if (frm.vCity.value == "") {
		alert("Please enter your city address.");
		frm.vCity.focus();
		frm.vCity.className ='errorinput';
		return false;
	}
	if (frm.vState.value == "") {
		alert("Please enter your state address.");
		frm.vState.focus();
		frm.vState.className ='errorinput';
		return false;
	}
	if (frm.vCountry.value == "") {
		alert("Please enter your country.");
		frm.vCountry.focus();
		frm.vCountry.className ='errorinput';
		return false;
	}
	if (frm.vPostCode.value == "") {
		alert("Please enter your postalcode.");
		frm.vPostCode.focus();
		frm.vPostCode.className ='errorinput';
		return false;
	}
	if (frm.vPhone.value == "") {
		alert("Please enter your phone number.");
		frm.vPhone.focus();
		frm.vPhone.className ='errorinput';
		return false;
	}
	if (frm.vEmail.value == "") {
		alert("Please enter your email address.");
		frm.vEmail.focus();
		frm.vEmail.className ='errorinput';
		return false;
	}
	
	return true;
}
function checkValue(t) {
  if(isNaN(t.value) || t.value.substring(0,1) == " " || t.value.length == 0 || parseFloat(t.value) < 0 ) {
	 if(t.name == "nNumber") {
		 t.value = "";
	 } else{
		t.value = "000";
	 }
  }
}
var ajax = new Array();
var sajax = new Array();
function getStateList(sel)
{
    
	$('#girish_state_cont').html('<select name="vState" class="textbox3 txt-bx01" id="girish_state"></select>');
	var stateCode = sel;
        
	document.getElementById('girish_state').options.length = 0;	// Empty city select box
	if(stateCode.length>0){
		var index = ajax.length;
		ajax[index] = new sack();
		
		ajax[index].requestFile = 'get_state_list.php?id='+stateCode;	// Specifying which file to get
		ajax[index].onCompletion = function(){ createStateList(index) };	// Specify function that will be executed after file has been found
		ajax[index].runAJAX();		// Execute AJAX function
	}
}
function createStateList(index)
{
	var obj = document.getElementById('girish_state');
	eval(ajax[index].response);	// Executing the response from Ajax as Javascript code	
}

function getCountyList(sel)
{
	var countryCode = sel.options[sel.selectedIndex].value;
	document.getElementById('girish_county').options.length = 0;	// Empty city select box
	if(countryCode.length>0){
		var index = ajax.length;
		ajax[index] = new sack();
		
		ajax[index].requestFile = 'get_county_list.php?id='+countryCode;	// Specifying which file to get
		ajax[index].onCompletion = function(){ createCountyList(index) };	// Specify function that will be executed after file has been found
		ajax[index].runAJAX();		// Execute AJAX function
	}
}

function createCountyList(index)
{
	var obj = document.getElementById('girish_county');
	eval(ajax[index].response);	// Executing the response from Ajax as Javascript code	
}


function showstatetext() 
{
    
    
            
            $('#girish_state_cont').html("<input type='text' name='vState' class='textbox' value='<?php echo $objU->vState;?>' size='40' maxlength='100'>")
        
}


$(window).load(function(){
   
   <?php if(!$arrState){ ?>
           
       //var obj = document.getElementById('girish_county');  
   getStateList('<?php echo $objU->vState;?>');
    <?php } ?>
});
</script>


<div class="row">
	<div class="eight columns">
		<div class="search-rslts">
			<div class="row"><div class="inenr-hd"><h2>Credit Card Information</h2></div></div>
			
			<div class="row">
				<form name="frmPayment" method="post" action="<?php echo $_SERVER['PHP_SELF']?>" onSubmit="return clickConfirm();">
					<div class="newdesignforinput maintext1">
						<div class="full_row">
							<div class="maintext1 warning" align="right"><em>Note: * indicates mandatory fields.</em></div>
						</div>
						
						<?php if(isset($message) && trim($message)!='')
					      {
						?>
						<div class="full_row">
							<div class="maintext1 success"><?php echo $message;?></div>
						</div>
						<?php }//end if?>
						
						<div class="row">
							<h2 class="maintext1 brdrbtm_new"><b>Card Details</b></h2>
						</div>
			
						<div class="full_row">
							<div class="three columns">First Name <span class="warning">*</span></div>
							<div class="five columns margin_R_200">
								<input name="vFirstName" type="text" value="<?php echo htmlspecialchars($objU->vFirstName)?>" size="30" class="textbox" maxlength="200" onKeyDown="changeCSS(this, 'text');">
							</div>
						</div>
						
						<div class="full_row">
							<div class="three columns">Last Name <span class="warning">*</span></div>
							<div class="five columns margin_R_200">
								<input name="vLastName" type="text" value="<?php echo htmlspecialchars($objU->vLastName)?>" size="30" maxlength="200" class="textbox"   onKeyDown="changeCSS(this, 'text');">
							</div>
						</div>
						
						<div class="full_row">
							<div class="three columns">Authorize.net</div>
							<div class="five columns margin_R_200">
								&nbsp;
							</div>
						</div>
						
						<div class="full_row">
							<div class="three columns">Card Number <span class="warning">*</span></div>
							<div class="five columns margin_R_200">
								<input name="nNumber" type="text" class="textbox credit_card_small" size="30" maxlength="16" value="<?php echo $objU->nNumber?>" onBlur="javascript:checkValue(this);"  onKeyDown="changeCSS(this, 'text');">
								<img src="images/visa_amex.gif" width="80" height="16" border="0">
							</div>
						</div>
						
						<div class="full_row">
							<div class="three columns">Card Validation Code <span class="warning">*</span></div>
							<div class="five columns margin_R_200">
								<input name="nCvv2" type="text" class="textbox" size="30" maxlength="3" value="<?php echo $objU->nCvv2?>"  onBlur="javascript:checkValue(this);"  onKeyDown="changeCSS(this, 'text');">
							</div>
						</div>
						
						<div class="full_row">
							<div class="three columns">Expiration Date (MM/YYYY) <span class="warning">*</span></div>
							<div class="five columns margin_R_200">
								<div class="five columns"><input name="vMM" type="text" class="textbox" size="2" maxlength="2" value="<?php echo addslashes($objU->vMM)?>" onKeyDown="changeCSS(this, 'text');"></div>
								<div class="two columns" align="center">/</div>
								<div class="five columns"><input name="vYYYY" type="text" class="textbox" size="4" maxlength="4" value="<?php echo addslashes($objU->vYYYY)?>" onKeyDown="changeCSS(this, 'text');"></div>
							</div>
						</div>
						<div class="clear"></div>
						
						<div class="row">
							<h2 class="maintext1 brdrbtm_new"><b>eCheck</b></h2>
						</div>
						<div class="full_row">
							<div class="three columns">Routing Number of a Bank: <?php if($_SESSION['sess_register_stype']=='ECHECK'){?><span class="warning">*</span><?php }?></div>
							<div class="five columns margin_R_200">
								<input name="rBank" type="text" class="textbox" onBlur="javascript:checkValue(this);"  onKeyDown="changeCSS(this, 'text');" value="<?php echo $objU->rBank?>" size="30" maxlength="16">
							</div>
						</div>
						
						<div class="full_row">
							<div class="three columns">Bank Account Number <?php if($_SESSION['sess_register_stype']=='ECHECK'){?><span class="warning">*</span><?php }?></div>
							<div class="five columns margin_R_200">
								<input name="nAccountNumber" type="text" class="textbox"  onBlur="javascript:checkValue(this);"  onKeyDown="changeCSS(this, 'text');" value="<?php echo $objU->nAccountNumber?>" size="30" maxlength="50">
							</div>
						</div>
						
						<div class="full_row">
							<div class="three columns">Account Type <?php if($_SESSION['sess_register_stype']=='ECHECK'){?><span class="warning">*</span><?php }?></div>
							<div class="five columns margin_R_200">
								<input name="txtAccountType" type="text" class="textbox" onKeyDown="changeCSS(this, 'text');" value="<?php echo addslashes($objU->txtAccountType)?>" size="25" maxlength="50">
							</div>
						</div>
						
						<div class="full_row">
							<div class="three columns">Bank Name <?php if($_SESSION['sess_register_stype']=='ECHECK'){?><span class="warning">*</span><?php }?></div>
							<div class="five columns margin_R_200">
								<input name="txtBankName" type="text" class="textbox" onKeyDown="changeCSS(this, 'text');" value="<?php echo $objU->txtBankName?>" size="30" maxlength="50">
							</div>
						</div>
						
						<div class="full_row">
							<div class="three columns">Bank Holder Name <?php if($_SESSION['sess_register_stype']=='ECHECK'){?><span class="warning">*</span><?php }?></div>
							<div class="five columns margin_R_200">
								<input name="txtBankHolderName" type="text" class="textbox"  onKeyDown="changeCSS(this, 'text');" value="<?php echo $objU->txtBankHolderName?>" size="30" maxlength="50">
							</div>
						</div>
						<div class="clear"></div>
						
						<div class="row">
							<h2 class="maintext1 brdrbtm_new"><b>Billing Address Details</b></h2>
						</div>
						
						<div class="full_row">
							<div class="three columns">Address <span class="warning">*</span></div>
							<div class="five columns margin_R_200">
								<input name="vAddress" type="text" class="textbox" size="30" maxlength="100" value="<?php echo $objU->vAddress?>" onKeyDown="changeCSS(this, 'text');">
							</div>
						</div>
						
						<div class="full_row">
							<div class="three columns">City <span class="warning">*</span></div>
							<div class="five columns margin_R_200">
								<input name="vCity" type="text" class="textbox" value="<?php echo htmlspecialchars($objU->vCity)?>" size="30" maxlength="100" onKeyDown="changeCSS(this, 'text');">
							</div>
						</div>
						
						<div class="full_row">
							<div class="three columns">Country</div>
							<div class="five columns margin_R_200">
								<select name="vCountry" class="textbox3 txt-bx01" id="girish_country" onchange="getStateList(this.value)";>
									<?php foreach ($arrCountry as $key => $value) { ?>
									<option value="<?php echo stripslashes($value)?>" <?php echo stripslashes($objU->vCountry) == stripslashes($value) ? "selected" : ""?>>
									<?php echo stripslashes($value)?>
									</option>
									<?php } ?>
								</select>
							</div>
						</div>
						
						<div class="full_row">
							<div class="three columns">State</div>
							<div class="five columns margin_R_200" id="girish_state_cont">
								<select name="vState" class="textbox3 txt-bx01" id="girish_state">
									<?php foreach ($arrState as $key => $value) { ?>
									<option value="<?php echo stripslashes($value)?>" <?php echo $objU->vState == stripslashes($value) ? "selected" : ""?>>
									<?php echo stripslashes($value)?>
									</option>
									<?php } ?>
								</select>
							</div>
						</div>
						
						<!--<tr>
						<td class="maintext1">State/Province <span class="warning">*</span></td>
						<td colspan="2" class="maintext1"><input name="vState" type="text" class="textbox" size="30" maxlength="100" value="<?php echo $objU->vState?>" onKeyDown="changeCSS(this, 'text');"></td>
						</tr>
						<tr>
						<td class="maintext1">Country <span class="warning">*</span></td>
						<td colspan="2" class="maintext1"><select name="vCountry" class="textbox">
						<?php foreach ($arrCountry as $key => $value) { ?>
						<option value="<?php echo $value?>" <?php echo $objU->vCountry == $value ? "selected" : ""?>>
						<?php echo $value?>
						</option>
						<?php } ?>
						</select></td>
						</tr>-->
						
						<div class="full_row">
							<div class="three columns">Postal Code <span class="warning">*</span></div>
							<div class="five columns margin_R_200">
								<input name="vPostCode" type="text" class="textbox" size="30" maxlength="100" value="<?php echo $objU->vPostCode?>" onKeyDown="changeCSS(this, 'text');">
							</div>
						</div>
						
						<div class="full_row">
							<div class="three columns">Phone <span class="warning">*</span></div>
							<div class="five columns margin_R_200">
								<input name="vPhone" type="text" class="textbox" size="30" maxlength="100" value="<?php echo $objU->vPhone?>" onKeyDown="changeCSS(this, 'text');">
							</div>
						</div>
						
						<div class="full_row">
							<div class="three columns">Email <span class="warning">*</span></div>
							<div class="five columns margin_R_200">
								<input name="vEmail" type="text" class="textbox" value="<?php echo $objU->vEmail?>" size="30" maxlength="200" onKeyDown="changeCSS(this, 'text');">
							</div>
						</div>
						<div class="row">
							<div class="clear"></div>
							<h2 class="maintext1 brdrbtm_new">&nbsp;</h2>
						</div>
						
						<div class="full_row">
							<div class="three columns">&nbsp;</div>
							<div class="five columns margin_R_200">
								<input name="PYN" type="submit" class="loginbutton" value="Save Now">
							</div>
						</div>
						
					</div>
				</form>
			</div>
		</div>
	</div>
	
	<div class="four columns right search_result_R">
		<?php include_once ("left.inc.php");?>
	</div>
	
</div>

<table width="100%"  border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td valign="top" ><table width="100%"  border="0" cellspacing="0" cellpadding="0">
      <tr>
        <td width="72%" valign="top"><div class="search-rslts"><table width="100%"  border="0" cellspacing="0" cellpadding="0">
          <tr>
            <td>              
				<table width="100%"  border="0" cellspacing="0" cellpadding="10" >
                <tr>
                  <td>
                    
					<form name="frmPayment" method="post" action="<?php echo $_SERVER['PHP_SELF']?>" onSubmit="return clickConfirm();">
                    <table width="100%"  border="0" cellspacing="0" cellpadding="5" class="newdesignforinput">
					
                    
                  </table>
					</form>
                    </td>
                </tr>
              </table>
              <div id="hide"><?php echo $script?></div>
			</td>
          </tr>
        </table></div></td>
		<td width="1%">&nbsp;</td>
        <td width="27%" valign="top"></td>
      </tr>
    </table>      
    </td>
  </tr>
</table>
<?php include_once('bottomhtml.inc.php');?>
