<!--#include virtual="/appDB/db_connection.asp" -->
<!--#include virtual="/appDB/functions.asp" -->
<!--#include virtual="/admin/scripts/admin_functions.asp" -->
<!--#include virtual="/admin/scripts/enc_function.asp" -->
<!--#include virtual="/admin/scripts/adm_inst.asp" -->
<%
IF (checkPermission("customers")="FAILED") THEN
	response.write("You do not have permission to view this page")
	response.end
END IF
customerID=sanitizeRequest("cID","querystring")
IF customerID <> "" AND IsNumeric(customerID) THEN
	SET rsC = dbCBK.Execute("SELECT `acc_type`, `business_accountID` from cbk_customers WHERE `customerID`='"&customerID&"' AND `companyID`='"&str_company_id&"' limit 1")
	IF rsC.EOF THEN response.write("customer account could not be found..") END IF
	DO WHILE NOT rsC.EOF
		str_acc_type=rsC("acc_type")
		str_biz_id=rsC("business_accountID")
	rsC.MoveNext
	loop
	rsC.Close
	SET rsC = Nothing

%>
<div style="width:100%;box-sizing:border-box;padding:10px;">
<table cellpadding="2" cellspacing="0" style="width:100%;" class="drvDataTable">
		<tr style="background-color:#f8f8f8;">
			<td class="formfields">
				<select name="acc_type" id="acc_type">
					<option value="std" <%IF str_acc_type="std" THEN response.write("selected='selected'") END IF%>>Standard Account</option>
					<option value="acc" <%IF str_acc_type="acc" THEN response.write("selected='selected'") END IF%>>Business Account</option>
				</select>
				<div id="reg_wr" style="margin-top:5px;<%IF str_acc_type="std" THEN response.write("display:none;") END IF%>">
				<select name="reg_bus" id="reg_bus">
				<%
				strBAWarn="0"
				SET rsBA = dbCBK.Execute("SELECT `accountID`,`businessNAME` FROM cbk_business_accounts WHERE `companyID`='"&str_company_id&"' order by `businessNAME` asc")%>
				<%IF rsBA.EOF THEN
				 strBAWarn="1"
				%>
					<option value="--">None Found</option>
				<%ELSE%>
					<option value="0">Please Choose</option>
				<%END IF%>
				<%
				DO WHILE NOT rsBA.EOF%>
					<option value="<%=rsBA("accountID")%>"><%=rsBA("businessNAME")%></option>
				<%
					rsBA.MoveNext
					loop
					rsBA.Close
					SET rsBA = Nothing
				%>
				</select>
				<%IF strBAWarn="1" THEN%>
				<p>You need to create a Company profile!</p>
				<%END IF%>
				</div>
			</td>
		</tr>
		<tr style="background-color:#f8f8f8;">
			<td><div class="adminbutton"><a href="#" id="chacc" style="width:99%;color:#fff;">Change account</a></div></td>
		</tr>	
</table>
</div>
<script type="text/javascript">
 $('#acc_type').change(function(){
	if(this.value == 'acc'){
		$('#reg_wr').fadeIn('slow');
	}else if(this.value == 'std'){
		$('#reg_wr').fadeOut('slow');
	}
 });
 $('#chacc').click(function(e){
	e.preventDefault();
	var acc = $('#acc_type').val();
	var c = <%=customerID%>;
	$('#chacc').html('<img src="/admin/img/blue_load.gif" alt="" />');
	if(acc  == 'acc'){
		var bizID = $('#reg_bus').val();
		if(bizID == '--'){
			miniNotify('You need to create a Company profile','error');
			setTimeout(function(){$('#chacc').html('Change account');},1500);
		}else if(bizID == '0'){
			miniNotify('Please select the Company','error');
			setTimeout(function(){$('#chacc').html('Change account');},1500);
		}else{
			setTimeout(function(){window.location = '/admin/control-panel/?go=customers=&customers=view&view='+c+'&action=change_acc&new_acc_type=acc&assoc_biz='+bizID;},1500);
		}
	}else if(acc == 'std'){
		setTimeout(function(){window.location = '/admin/control-panel/?go=customers=&customers=view&view='+c+'&action=change_acc&new_acc_type=std';},1500);
	}
 });
</script>
<%
ELSE
	response.write("invalid data detected..")
END IF
%>