<?php
//This code is copyright (c) ViciSoft SL, all rights reserved.
//The contents of this file are protected under law as the intellectual property 
//of ViciSoft SL. Any use, reproduction, disclosure or copying of any kind 
//without the express and written permission of ViciSoft SL is forbidden.
//Author: Vince Reid, vincereid@gmail.com
if(!@$GLOBALS['incfunctionsdefined']){print 'No incfunctions.php file';exit;}
global $forceloginonhttps;
include './vsadmin/inc/incemail.php';
$cartisincluded=TRUE;
include './vsadmin/inc/inccart.php';
if(@$_SERVER['CONTENT_LENGTH']!='' && $_SERVER['CONTENT_LENGTH'] > 10000) exit;
$success=TRUE;
if(@$dateformatstr=='') $dateformatstr='m/d/Y';
$ordGrandTotal=$ordTotal=$ordStateTax=$ordHSTTax=$ordCountryTax=$ordShipping=$ordHandling=$ordDiscount=0;
$ordID=$affilID=$ordCity=$ordState=$ordCountry=$ordDiscountText=$ordEmail='';
$nonhomecountries=FALSE;
$digidownloads=FALSE;
$allcountries=[];
$warncheckspamfolder=FALSE;
if(!@$GLOBALS['enableclientlogin']){
	$success=FALSE;
	$errmsg="Client login not enabled";
}
$GLOBALS['noreceiptbuttons']=TRUE;
$GLOBALS['xxThkYou']='';
$pagename='clientlogin'.$GLOBALS['extension'];
if(@$forceloginonhttps) $thisaction=$GLOBALS['storeurlssl'] . $pagename; else $thisaction='';
$GLOBALS['alreadygotadmin']=getadminsettings();
if(@$GLOBALS['enableclientlogin']) displaysoftlogin();
?>
<div id="vieworderdiv" class="ectopaque" style="display:none" onclick="if(event.target==this)hideviewimage()" tabindex="0"></div>
<script>
/* <![CDATA[ */
function doprintcontent(){
	var stylesheetlist='';
	if(document.styleSheets){
		for(var dpci=0;dpci<document.styleSheets.length;dpci++){
			if(document.styleSheets[dpci].href){
				stylesheetlist+='<link rel="stylesheet" type="text/css" href="'+document.styleSheets[dpci].href+'" />\n';
			}
		}
	}
	var prnttext='<html><head>'+stylesheetlist+'</head' + '><' + 'body onload="window.print()"><div class="printbody">\n';
	prnttext+=document.getElementById('printcontent').innerHTML+"\n";
	prnttext+='</div><' + '/body></'+'html>\n';
	var newwin=window.open("","printit",'menubar=no, scrollbars=yes, width=600, height=450, directories=no,location=no,resizable=yes,status=no,toolbar=no');
	newwin.document.open();
	newwin.document.write(prnttext);
	newwin.document.close();
}
var ajaxobj;
function hideviewimage(){
	document.getElementById('vieworderdiv').style.display='none';
}
function ppajaxcallback(){
	if(ajaxobj.readyState==4){
		var restxt=ajaxobj.responseText;
		document.getElementById('vieworderdiv').innerHTML='<div class="opaqueinner"><div class="scart scclose" role="img" onclick="hideviewimage()" title="' + "<?php print jscheck($GLOBALS['xxClsWin'])?>" + '"></div>'+restxt+'</div>';
		document.getElementById('vieworderdiv').style.display='';
	}
}
function vieworder(theid){
	var postdata="theid=" + theid;
	ajaxobj=window.XMLHttpRequest?new XMLHttpRequest():new ActiveXObject("MSXML2.XMLHTTP");
	ajaxobj.onreadystatechange=ppajaxcallback;
	ajaxobj.open("POST",'vsadmin/ajaxservice.php?action=vieworder', true);
	ajaxobj.setRequestHeader('Content-type','application/x-www-form-urlencoded');
	ajaxobj.send(postdata);
}
function editaddress(theid){
	document.forms.mainform.action.value="editaddress";
	document.forms.mainform.theid.value=theid;
	document.forms.mainform.submit();
}
function newaddress(){
	document.forms.mainform.action.value="newaddress";
	document.forms.mainform.submit();
}
function editaccount(){
	document.forms.mainform.action.value="editaccount";
	document.forms.mainform.submit();
}
function deleteaddress(theid){
	if(confirm("<?php print jscheck($GLOBALS['xxDelAdd'])?>")){
		document.forms.mainform.action.value="deleteaddress";
		document.forms.mainform.theid.value=theid;
		document.forms.mainform.submit();
	}
}
function createlist(){
	if(document.forms.mainform.listname.value.indexOf('<')!=-1){
		alert("<?php print jscheck('Illegal Character "<"')?>.");
		document.forms.mainform.listname.focus();
		return(false);
	}else if(document.forms.mainform.listname.value==''){
		alert("<?php print jscheck($GLOBALS['xxPlsEntr'] . ' "' . $GLOBALS['xxLisNam'])?>\".");
		document.forms.mainform.listname.focus();
		return(false);
	}else{
		document.forms.mainform.action.value="createlist";
		document.forms.mainform.submit();
	}
}
function deletelist(theid){
	if(confirm("<?php print jscheck($GLOBALS['xxDelLis'])?>")){
		document.forms.mainform.action.value="deletelist";
		document.forms.mainform.theid.value=theid;
		document.forms.mainform.submit();
	}
}
/* ]]> */
</script>
<?php
	if(getpost('doresetpw')=="1"){
		$sSQL="SELECT clID FROM customerlogin WHERE clEmail='".escape_string(getpost('rst'))."' AND clPw='".escape_string(getpost('rsk'))."'";
		$result=ect_query($sSQL) or ect_error();
		if($rs=ect_fetch_assoc($result)) $clid=$rs['clID']; else $clid='';
		if(getpost('newpw')=='') $clid='';
		ect_free_result($result);
		if($clid!='') ect_query("UPDATE customerlogin SET clPw='".escape_string(dohashpw(getpost('newpw')))."' WHERE clID=" . $clid) or ect_error();
?>	  <div class="ectdiv ectclientlogin">
		<div class="ectdivhead"><?php print $GLOBALS['xxCusAcc']?></div>
		  <div class="ectdivcontainer">
			<div class="ectdivleft"><?php print $GLOBALS['xxForPas']?></div>
			<div class="ectdivright"><?php print ($clid==''?$GLOBALS['xxEmNtFn']:$GLOBALS['xxPasRsS']) ?></div>
		  </div>
		  <div class="ectdiv2column"><?php
		if($clid!='')
			print imageorbutton(@$imglogin,$GLOBALS['xxLogin'],'login','return displayloginaccount()',TRUE);
		else
			print imageorbutton(@$imggoback,$GLOBALS['xxGoBack'],'goback','history.go(-1)',TRUE); ?></div>
	  </div>
<?php
	}elseif(getget('rst')!='' && getget('rsk')!=''){
		$sSQL="SELECT clID FROM customerlogin WHERE clEmail='".escape_string(getget('rst'))."' AND clPw='".escape_string(getget('rsk'))."'";
		$result=ect_query($sSQL) or ect_error();
		if(ect_num_rows($result)>0) $success=TRUE; else $success=FALSE;
		ect_free_result($result);
		if(! $success){ ?>
	  <div class="ectdiv ectclientlogin">
		<div class="ectdivhead"><?php print $GLOBALS['xxCusAcc']?></div>
		  <div class="ectdivcontainer">
			<div class="ectdivleft"><?php print $GLOBALS['xxForPas']?></div>
			<div class="ectdivright"><?php print $GLOBALS['xxSorRes']?></div>
		  </div>
		  <div class="ectdiv2column"><?php print imageorbutton(@$imgcancel,$GLOBALS['xxCancel'],'cancel',$storeurl,FALSE) ?></div>
	  </div>
<?php	}else{ ?>
<script>
/* <![CDATA[ */
function checknewpw(frm){
if(frm.newpw.value==""){
	alert("<?php print jscheck($GLOBALS['xxPlsEntr'] . ' "' . $GLOBALS['xxNewPwd'])?>\".");
	frm.newpw.focus();
	return(false);
}
var newpw=frm.newpw.value;
var newpw2=frm.newpw2.value;
if(newpw!=newpw2){
	alert("<?php print jscheck($GLOBALS['xxPwdMat'])?>");
	frm.newpw.focus();
	return(false);
}
return true;
}
/* ]]> */
</script>
	<form method="post" name="mainform" action="<?php print $thisaction?>" onsubmit="return checknewpw(this)">
	<input type="hidden" name="doresetpw" value="1" />
	<input type="hidden" name="rst" value="<?php print str_replace('"','',getget('rst'))?>" />
	<input type="hidden" name="rsk" value="<?php print str_replace('"','',getget('rsk'))?>" />
	  <div class="ectdiv ectclientlogin">
		<div class="ectdivhead"><?php print $GLOBALS['xxCusAcc'] . ' ' . $GLOBALS['xxForPas']?></div>
		  <div class="ectdivcontainer">
			<div class="ectdivleft"><?php print $GLOBALS['xxNewPwd']?></div>
			<div class="ectdivright"><input type="password" size="20" name="newpw" value="" autocomplete="off" /></div>
		  </div>
		  <div class="ectdivcontainer">
			<div class="ectdivleft"><?php print $GLOBALS['xxRptPwd']?></div>
			<div class="ectdivright"><input type="password" size="20" name="newpw2" value="" autocomplete="off" /></div>
		  </div>
		  <div class="ectdiv2column"><?php print imageorsubmit(@$imgsubmit,$GLOBALS['xxSubmt'],'submit').' '.imageorbutton(@$imgcancel,$GLOBALS['xxCancel'],'cancel',$storeurl,FALSE)?></div>
	  </div>
	</form>
<?php	}
	}elseif(getget('action')=='logout'){
		$_SESSION['clientID']=NULL; unset($_SESSION['clientID']);
		$_SESSION['clientUser']=NULL; unset($_SESSION['clientUser']);
		$_SESSION['clientActions']=NULL; unset($_SESSION['clientActions']);
		$_SESSION['clientLoginLevel']=NULL; unset($_SESSION['clientLoginLevel']);
		$_SESSION['clientPercentDiscount']=NULL; unset($_SESSION['clientPercentDiscount']);
		setacookie('WRITECLL', '', -7);
		setacookie('WRITECLP', '', -7);
		if(@$storeurlssl!=$storeurl) print '<script src="'.$storeurlssl.'vsadmin/savecookie.php?DELCLL=Y"></script>';
		if(@$clientlogoutref!='')
			$refURL=$clientlogoutref;
		else
			$refURL=$GLOBALS['storehomeurl'];
		print '<script>setTimeout(function(){document.location=\'' . jsescape($refURL) . "'},3000)</script>";
?>
		<div class="ectdiv ectclientlogin">
		  <div class="ectmessagescreen">
			<div><?php print $GLOBALS['xxLOSuc']?></div>
			<div><?php print $GLOBALS['xxAutFo']?></div>
			<div><?php print $GLOBALS['xxForAut']?><?php print imageorbuttontag('',$GLOBALS['xxClkHere'],'ectclientlogin',$refURL,FALSE)?></div>
		  </div>
		</div>
<?php	
	}elseif(getpost('action')=='dolostpassword'){
		$errormsg='';
		$dofloodcontrol=FALSE;
		if(recaptchaenabled(8)) $success=checkrecaptcha($errormsg);
		if($success){
			$theemail=cleanupemail(getpost('email'));
			$sSQL="SELECT clPW FROM customerlogin WHERE clEmail<>'' AND clEmail='" . escape_string($theemail) . "'";
			$result=ect_query($sSQL) or ect_error();
			if(ect_num_rows($result) > 0){
				ect_query("DELETE FROM ajaxfloodcontrol WHERE afcAction=6 AND afcDate<'" . date('Y-m-d H:i:s',time()-300) . "'") or ect_error();
				$sSQL="SELECT afcID FROM ajaxfloodcontrol WHERE afcAction=6 AND (afcIP='" . escape_string($REMOTE_ADDR) . "' OR afcSession='" . escape_string(session_id()) . "')";
				$result2=ect_query($sSQL) or ect_error();
				$dofloodcontrol=ect_num_rows($result2)>0;
				ect_free_result($result2);
				
				if(!$dofloodcontrol){
					$rs=ect_fetch_assoc($result);
					if(@$htmlemails==TRUE) $emlNl='<br />'; else $emlNl="\n";
					$tlink=$storeurl . $pagename . "?rst=" . $theemail . "&rsk=" . $rs['clPW'];
					if(@$htmlemails==TRUE) $tlink='<a href="' . $tlink . '">' . $tlink . '</a>';
					dosendemail($theemail, $emailAddr, '', $GLOBALS['xxForPas'], $GLOBALS['xxLosPw1'] . $emlNl . $storeurl . $emlNl . $emlNl . $GLOBALS['xxResPas'] . $emlNl . $tlink . $emlNl . $emlNl . $GLOBALS['xxLosPw3'] . $emlNl);
					
					$sSQL="INSERT INTO ajaxfloodcontrol (afcAction,afcIP,afcSession,afcDate) VALUES (6,'" . escape_string($REMOTE_ADDR) . "','" . escape_string(session_id()) . "','" . date('Y-m-d H:i:s') . "')";
					ect_query($sSQL) or ect_error();
				
					$success=TRUE;
				}else
					$success=FALSE;
			}else{
				$success=FALSE;
			}
			ect_free_result($result);
		}else
			$GLOBALS['xxSorPw']=$errormsg; ?>
		<form method="post" name="mainform" action="<?php print $thisaction?>">
			<div class="ectdiv ectclientlogin">
				<div class="ectdivhead"><?php print $GLOBALS['xxCusAcc']?></div>
				<div class="ectdivcontainer">
					<div class="ectdivleft"><h4><?php print $GLOBALS['xxForPas']?></h4></div>
					<div class="ectdivright"><h4><?php
					if($dofloodcontrol){
						print $GLOBALS['xxFldCnt'];
					}else{
						if($success) print $GLOBALS['xxSenPw']; else print $GLOBALS['xxSorPw'];
					} ?></h4></div>
				</div>
				<div class="ectdivcontainer">
					<div class="ectdivleft"></div>
					<div class="ectdivright"><?php
					if($success)
						print imageorbutton(@$imglogin,$GLOBALS['xxLogin'],'login','return displayloginaccount()',TRUE);
					else
						print imageorbutton(@$imggoback,$GLOBALS['xxGoBack'],'goback','history.go(-1)',TRUE);
					?></div>
				</div>
			</div>
		</form>
<?php
	}elseif(getget('mode')=='lostpassword'){ ?>
<script>
/* <![CDATA[ */
function checklostpw(){
frm=document.forms.mainform;
if(frm.email.value==""){
	alert("<?php print jscheck($GLOBALS['xxPlsEntr'] . ' "' . $GLOBALS['xxEmail'])?>\".");
	frm.email.focus();
	return(false);
}
var regex=/[^@]+@[^@]+\.[a-z]{2,}$/i;
if(!regex.test(frm.email.value)){
	alert("<?php print jscheck($GLOBALS['xxValEm'])?>");
	frm.email.focus();
	return(false);
}
<?php	if(recaptchaenabled(8)) print 'if(!lostpwcaptchaok){ alert("' . jscheck($GLOBALS['xxRecapt']) . '");return(false); }' ?>
return true;
}
/* ]]> */
</script>
	  <form method="post" name="mainform" action="<?php print $thisaction?>" onsubmit="return checklostpw()">
	  <input type="hidden" name="action" value="dolostpassword" />
	  <div class="ectdiv ectclientlogin ectlostpassword">
		<div class="ectdivhead"><?php print $GLOBALS['xxCusAcc']?></div>
		<div class="ectdivcontainer">
			<div class="ectdivleft"><h4><?php print $GLOBALS['xxForPas']?></h4></div>
			<div class="ectdivright"><h4><?php print $GLOBALS['xxEntEm']?></h4></div>
		</div>
		<div class="ectdivcontainer">
			<div class="ectdivleft"><?php print labeltxt($GLOBALS['xxEmail'],'email')?></div>
			<div class="ectdivright"><input type="text" name="email" id="email" class="ecttextinput" size="31" placeholder="<?php print $GLOBALS['xxEmail']?>" /></div>
		</div>
<?php	if(recaptchaenabled(8)){ ?>
		<div class="ectdivcontainer">
			<div class="ectdivleft">&nbsp;</div>
			<?php displayrecaptchajs('lostpwcaptcha',TRUE,FALSE) ?>
			<div id="lostpwcaptcha" class="g-recaptcha ectdivright"></div>
		</div>
<?php	} ?>
		<div class="ectdivcontainer">
			<div class="ectdivleft"></div>
			<div class="ectdivright"><?php print imageorsubmit(@$imgsubmit,$GLOBALS['xxSubmt'],'submit')?></div>
		</div>
	  </div>
	  </form>
<?php
	}elseif(@$_SESSION['clientID']==''){
			print '<div class="ectdivhead"><div class="clientloginbuttons">';
				if(@$GLOBALS['enableclientlogin']){
					print imageorbutton(@$imgloginaccount,$GLOBALS['xxLogAcc'],'logintoaccount',"displayloginaccount()",TRUE);
					if(@$allowclientregistration) print imageorbutton(@$imgcreateaccount,$GLOBALS['xxCreAcc'],'createaccount',"displaynewaccount()",TRUE);
				}else
					print 'Customer Login Disabled';
			print '</div></div>'; ?>
	  <div class="ectdiv ectclientlogin">
		<div class="ectdivhead"><?php print $GLOBALS['xxCusAcc']?></div>
		<div>
			<div class="clientloginmessage"><?php print $GLOBALS['xxMusLog']?></div>
		</div>
	  </div>
<script>
displayloginaccount();
</script>
<?php
	}else{ // is logged in ?>
		<div class="ectdivhead"><div class="clientloginbuttons"><?php print imageorbuttontag(@$GLOBALS['imgcartlogout'],$GLOBALS['xxLogout'] . ' ' . htmlspecials($_SESSION['clientUser']),'ectlink','return dologoutaccount()',TRUE)?></div></div>
<?php
		if(getpost('action')=='doeditaccount'){
			$oldpw=dohashpw(getpost('oldpw'));
			$newpw=getpost('newpw');
			$newpw2=getpost('newpw2');
			$clientuser=getpost('xname');
			$clientemail=cleanupemail(getpost('email'));
			$allowemail=getpost('allowemail');
			$sSQL="SELECT clPW,clEmail FROM customerlogin WHERE clID=" . $_SESSION['clientID'];
			$result=ect_query($sSQL) or ect_error();
			$rs=ect_fetch_assoc($result);
			ect_free_result($result);
			$oldpassword=$rs['clPW'];
			$oldemail=$rs['clEmail'];
			$success=TRUE;
			$checkhash=hash('sha256',$oldemail . 'only know the hash' . $GLOBALS['adminSecret']);
			if($checkhash!=getpost('emhash')){
				$success=FALSE;
				$errmsg='Hash check error';
			}else{
				if($newpw!='' || $newpw2!=''){
					if($oldpw!=$oldpassword){
						$success=FALSE;
						$errmsg=$GLOBALS['xxExNoMa'];
					}
				}
				if($oldemail != $clientemail){
					$sSQL="SELECT clID FROM customerlogin WHERE clEmail='" . escape_string($clientemail) . "'";
					$result=ect_query($sSQL) or ect_error();
					if(ect_num_rows($result) > 0){
						$success=FALSE;
						$errmsg=$GLOBALS['xxEmExi'];
					}
					ect_free_result($result);
				}
			}
			if($success){
				$sSQL='UPDATE customerlogin SET ';
				$sSQL.="clUserName='" . escape_string($clientuser) . "',";
				$sSQL.="clEmail='" . escape_string($clientemail) . "'";
				if(trim_(@$GLOBALS['extraclientfield1'])!='') $sSQL.=",clientCustom1='" . escape_string(getpost('clientCustom1')) . "'";
				if(trim_(@$GLOBALS['extraclientfield2'])!='') $sSQL.=",clientCustom2='" . escape_string(getpost('clientCustom2')) . "'";
				if($newpw!='') $sSQL.=",clPW='" . escape_string(dohashpw($newpw)) . "'";
				$sSQL.=" WHERE clID=" . $_SESSION['clientID'];
				ect_query($sSQL) or ect_error();
				$_SESSION['clientPW']=dohashpw($newpw);
				if($allowemail=='ON'){
					addtomailinglist($clientemail,$clientuser);
					if($oldemail != $clientemail) ect_query("DELETE FROM mailinglist WHERE email='" . escape_string($oldemail) . "'");
				}else{
					ect_query("DELETE FROM mailinglist WHERE email='" . escape_string($clientemail) . "'");
					ect_query("DELETE FROM mailinglist WHERE email='" . escape_string($oldemail) . "'");
				}
				$_SESSION['clientUser']=$clientuser;
				print '<script>var url=[location.protocol,"//",location.host,location.pathname].join("");setTimeout(function(){document.location=url},2000)</script>';
			}
?>
	<form method="post" name="mainform" action="<?php print $thisaction?>">
	  <div class="ectdiv ectclientlogin">
		<div class="ectdivhead"><?php print $GLOBALS['xxCusAcc']?></div>
		<div style="padding:50px 0;text-align:center" class="ectdiv2column<?php print ($success?'':' ectwarning')?>"><?php if($success) print $GLOBALS['xxUpdSuc']; else print $errmsg ?></div>
		<div style="text-align:center" class="ectdiv2column"><?php
		if($success)
			print imageorsubmit(@$imgcustomeracct,$GLOBALS['xxCusAcc'],'customeracct');
		else
			print imageorbutton(@$imggoback,$GLOBALS['xxGoBack'],'goback','history.go(-1)',TRUE);
		?></div>
	  </div>
	</form>
<?php	}elseif(getpost('action')=='editaccount'){
			if(@$forceloginonhttps && (@$_SERVER['HTTPS']!='on' && @$_SERVER['SERVER_PORT']!='443') && strpos(@$GLOBALS['storeurlssl'],'https')!==FALSE){ header('Location: '.$GLOBALS['storeurlssl'].$pagename.(@$_SERVER['QUERY_STRING']!='' ? '?'.$_SERVER['QUERY_STRING'] : '')); exit; }
?>
<script>
/* <![CDATA[ */
var checkedfullname=false;
function checknewaccount(){
frm=document.forms.mainform;
if(frm.xname.value==""||frm.xname.value=="<?php print $GLOBALS['xxFirNam']?>"){
	alert("<?php print jscheck($GLOBALS['xxPlsEntr'] . ' "' . (@$GLOBALS['usefirstlastname'] ? $GLOBALS['xxFirNam'] : $GLOBALS['xxName']))?>\".");
	frm.xname.focus();
	return (false);
}
gotspace=false;
var checkStr=frm.xname.value;
for (i=0; i < checkStr.length; i++){
	if(checkStr.charAt(i)==" ")
		gotspace=true;
}
if(!checkedfullname && !gotspace){
	alert("<?php print jscheck($GLOBALS['xxFulNam'] . ' "' . $GLOBALS['xxName'])?>\".");
	frm.xname.focus();
	checkedfullname=true;
	return (false);
}
if(frm.email.value==""){
	alert("<?php print jscheck($GLOBALS['xxPlsEntr'] . ' "' . $GLOBALS['xxEmail'])?>\".");
	frm.email.focus();
	return (false);
}
<?php	if(@$GLOBALS['extraclientfield1required']){ ?>
if(frm.clientCustom1.value==""){
	alert("<?php print jscheck($GLOBALS['xxPlsEntr'] . ' "' . @$GLOBALS['extraclientfield1'])?>\".");
	frm.clientCustom1.focus();
	return(false);
}
<?php	}
		if(@$GLOBALS['extraclientfield2required']){ ?>
if(frm.clientCustom2.value==""){
	alert("<?php print jscheck($GLOBALS['xxPlsEntr'] . ' "' . @$GLOBALS['extraclientfield2'])?>\".");
	frm.clientCustom2.focus();
	return(false);
}
<?php	} ?>
var regex=/[^@]+@[^@]+\.[a-z]{2,}$/i;
if(!regex.test(frm.email.value)){
	alert("<?php print jscheck($GLOBALS['xxValEm'])?>");
	frm.email.focus();
	return (false);
}
var newpw=frm.newpw.value;
var newpw2=frm.newpw2.value;
if(newpw!='' && newpw!=newpw2){
	alert("<?php print jscheck($GLOBALS['xxPwdMat'])?>");
	frm.newpw.focus();
	return(false);
}
return true;
}
/* ]]> */
</script>
		<form method="post" name="mainform" action="<?php print $thisaction?>" onsubmit="return checknewaccount()">
		<input type="hidden" name="action" value="doeditaccount" />
		<div class="ectdiv ectclientlogin">
		  <div class="ectdivhead"><?php print $GLOBALS['xxAccDet']?></div>
		  <div class="clientlogineditaccount">
<?php		$sSQL="SELECT clID,clUserName,clActions,clLoginLevel,clPercentDiscount,clEmail,loyaltyPoints,clientCustom1,clientCustom2 FROM customerlogin WHERE clID=" . $_SESSION['clientID'];
			$result=ect_query($sSQL) or ect_error();
			if($rs=ect_fetch_assoc($result)){
				$theemail=$rs['clEmail'];
				$clientCustom1=$rs['clientCustom1'];
				$clientCustom2=$rs['clientCustom2'];
			}else
				$_SESSION['clientID']='';
			ect_free_result($result);
			$sSQL="SELECT email FROM mailinglist WHERE email='" . escape_string(@$theemail) . "'";
			$result=ect_query($sSQL) or ect_error();
			if(ect_num_rows($result)>0) $allowemail=1; else $allowemail=0;
			ect_free_result($result);
			print whv('emhash', hash('sha256',$theemail . 'only know the hash' . $GLOBALS['adminSecret']));
?>
			<div class="ectdivcontainer">
				<div class="ectdivleft"><?php print $redstar . $GLOBALS['xxName']?></div>
				<div class="ectdivright"><input type="text" size="30" name="xname" value="<?php print htmlspecials($_SESSION['clientUser'])?>" placeholder="<?php print placeholder($GLOBALS['xxName'])?>" /></div>
			</div>
<?php		if(@$nounsubscribe!=TRUE){ ?>
			<div class="ectdivcontainer">
				<div class="ectdivleft"><input type="checkbox" class="ectcheckbox" name="allowemail" value="ON"<?php if($allowemail!=0) print ' checked="checked"'?> /></div>
				<div class="ectdivright"><div><?php print $GLOBALS['xxAlPrEm']?></div><div style="font-size:10px"><?php print $GLOBALS['xxNevDiv']?></div></div>
			</div>
<?php		} ?>
			<div class="ectdivcontainer">
				<div class="ectdivleft"><?php print $redstar . $GLOBALS['xxEmail']?></div>
				<div class="ectdivright"><input type="text" size="30" name="email" value="<?php print $theemail?>" placeholder="<?php print placeholder($GLOBALS['xxEmail'])?>" /></div>
			</div>
<?php		if(trim_(@$GLOBALS['extraclientfield1'])!=''){ ?>
			<div class="ectdivcontainer">
				<div class="ectdivleft"><?php print (@$GLOBALS['extraclientfield1required']?$redstar:'') . $GLOBALS['extraclientfield1']?></div>
				<div class="ectdivright"><input type="text" name="clientCustom1" size="30" value="<?php print $clientCustom1?>" placeholder="<?php print placeholder($GLOBALS['extraclientfield1'])?>" /></div>
			</div>
<?php		}
			if(trim_(@$GLOBALS['extraclientfield2'])!=''){ ?>
			<div class="ectdivcontainer">
				<div class="ectdivleft"><?php print (@$GLOBALS['extraclientfield2required']?$redstar:'') . $GLOBALS['extraclientfield2']?></div>
				<div class="ectdivright"><input type="text" name="clientCustom2" size="30" value="<?php print $clientCustom2?>" placeholder="<?php print placeholder($GLOBALS['extraclientfield2'])?>" /></div>
			</div>
<?php		} ?>
			<div class="ectdivhead"><?php print $GLOBALS['xxPwdChg']?></div>
			<div class="ectdivcontainer">
				<div class="ectdivleft"><?php print $GLOBALS['xxOldPwd']?></div>
				<div class="ectdivright"><input type="password" size="20" name="oldpw" value="" placeholder="<?php print placeholder($GLOBALS['xxOldPwd'])?>" autocomplete="off" /></div>
			</div>
			<div class="ectdivcontainer">
				<div class="ectdivleft"><?php print $GLOBALS['xxNewPwd']?></div>
				<div class="ectdivright"><input type="password" size="20" name="newpw" value="" placeholder="<?php print placeholder($GLOBALS['xxNewPwd'])?>" autocomplete="off" /></div>
			</div>
			<div class="ectdivcontainer">
				<div class="ectdivleft"><?php print $GLOBALS['xxRptPwd']?></div>
				<div class="ectdivright"><input type="password" size="20" name="newpw2" value="" placeholder="<?php print placeholder($GLOBALS['xxRptPwd'])?>" autocomplete="off" /></div>
			</div>
			<div class="ectdiv2column"><?php print imageorsubmit(@$imgsubmit,$GLOBALS['xxSubmt'],'submit').' '.imageorbutton(@$imgcancel,$GLOBALS['xxCancel'],'cancel','history.go(-1)',TRUE)?></div>
		  </div>
		</div>
		</form>
<?php	}elseif(getpost('action')=='editaddress' || getpost('action')=='newaddress'){
			$addID=str_replace("'",'',getpost('theid'));
			if(!is_numeric($addID))$addID=0;
			$addIsDefault='';
			$addName='';
			$addLastName='';
			$addAddress='';
			$addAddress2='';
			$addState='';
			$addCity='';
			$addZip='';
			$addPhone='';
			$addCountry='';
			$addExtra1='';
			$addExtra2='';
			$sSQL='SELECT stateID FROM states INNER JOIN countries ON states.stateCountryID=countries.countryID WHERE countryEnabled<>0 AND stateEnabled<>0 AND (loadStates=2 OR countryID=' . $origCountryID . ') ORDER BY stateCountryID,stateName';
			$result=ect_query($sSQL) or ect_error();
			$hasstates=(ect_num_rows($result)>0);
			ect_free_result($result);
			$sSQL="SELECT countryName,countryOrder,".getlangid("countryName",8).",countryID,loadStates FROM countries WHERE countryEnabled=1 ORDER BY countryOrder DESC," . getlangid("countryName",8);
			$result=ect_query($sSQL) or ect_error();
			while($rs=ect_fetch_assoc($result)){
				$allcountries[$numallcountries++]=$rs;
			}
			ect_free_result($result);
			for($index=0;$index<$numallcountries;$index++){
				if($allcountries[$index]['loadStates']==0){ $nonhomecountries=TRUE; break; }
			}
			if(! $nonhomecountries){
				for($index=0;$index<$numallcountries;$index++){
					if($allcountries[$index]['loadStates']>0){
						$sSQL="SELECT stateID FROM states WHERE stateEnabled<>0 AND stateCountryID=" . $allcountries[$index]['countryID'];
						$result=ect_query($sSQL) or ect_error();
						if(ect_num_rows($result)==0) $nonhomecountries=TRUE;
						ect_free_result($result);
						if($nonhomecountries) break;
					}
				}
			}
			if(getpost('action')=='editaddress'){
				$sSQL="SELECT addID,addIsDefault,addName,addLastName,addAddress,addAddress2,addState,addCity,addZip,addPhone,addCountry,addExtra1,addExtra2 FROM address WHERE addID=" . $addID . " AND addCustID='" . $_SESSION['clientID'] . "' ORDER BY addIsDefault";
				$result=ect_query($sSQL) or ect_error();
				if($rs=ect_fetch_assoc($result)){
					$addIsDefault=$rs['addIsDefault'];
					$addName=$rs['addName'];
					$addLastName=$rs['addLastName'];
					$addAddress=$rs['addAddress'];
					$addAddress2=$rs['addAddress2'];
					$addState=$rs['addState'];
					$ordState=$addState;
					$addCity=$rs['addCity'];
					$addZip=$rs['addZip'];
					$addPhone=$rs['addPhone'];
					$addCountry=$rs['addCountry'];
					$addExtra1=$rs['addExtra1'];
					$addExtra2=$rs['addExtra2'];
				}
				ect_free_result($result);
			} ?>
	<form method="post" name="mainform" action="<?php print $thisaction?>" onsubmit="return checkform(this)">
	<input type="hidden" name="action" value="<?php if(getpost('action')=='editaddress') print "doeditaddress"; else print "donewaddress" ?>" />
	<input type="hidden" name="theid" value="<?php print $addID?>" />
	  <div class="ectdiv ectclientlogin">
		<div class="ectdivhead"><?php print $GLOBALS['xxEdAdd']?></div>
		<?php	if(trim_(@$GLOBALS['extraorderfield1'])!=''){ ?>
		<div class="ectdivcontainer">
			<div class="ectdivleft"><?php print (@$GLOBALS['extraorderfield1required']==TRUE ? $redstar : '') . $GLOBALS['extraorderfield1'] ?></div>
			<div class="ectdivright"><?php if(@$GLOBALS['extraorderfield1html']!='') print $GLOBALS['extraorderfield1html']; else print '<input type="text" name="ordextra1" id="ordextra1" size="20" value="' . htmlspecials($addExtra1) . '" autocomplete="false" />'?></div>
		</div>
		<?php	} ?>
		<div class="ectdivcontainer">
			<div class="ectdivleft"><?php print $redstar . $GLOBALS['xxName']?></div>
			<div class="ectdivright"><?php
		if(@$GLOBALS['usefirstlastname']){
			print '<input type="text" name="xname" class="ectinputhalf" size="25" value="'.htmlspecials($addName).'" placeholder="'.placeholder($GLOBALS['xxFirNam']).'" autocomplete="given-name" /> <input type="text" name="lastname" class="ectinputhalf" size="25" value="'.htmlspecials($addLastName).'" placeholder="'.placeholder($GLOBALS['xxLasNam']).'" autocomplete="family-name" />';
		}else
			print '<input type="text" name="xname" size="25" id="name" placeholder="' . placeholder($GLOBALS['xxName']) . '" value="'.htmlspecials(trim($addName.' '.$addLastName)).'" />';
		?></div>
		</div>
		<div class="ectdivcontainer">
			<div class="ectdivleft"><?php print $redstar . $GLOBALS['xxAddress']?></div>
			<div class="ectdivright"><input type="text" name="address" id="address" size="25" value="<?php print htmlspecials($addAddress)?>" placeholder="<?php print placeholder($GLOBALS['xxAddress'])?>" /></div>
		</div>
		<?php	if(@$useaddressline2==TRUE){ ?>
		<div class="ectdivcontainer">
			<div class="ectdivleft"><?php print $GLOBALS['xxAddress2']?></div>
			<div class="ectdivright"><input type="text" name="address2" id="address2" size="25" value="<?php print htmlspecials($addAddress2)?>" placeholder="<?php print placeholder($GLOBALS['xxAddress2'])?>" /></div>
		</div>
		<?php	} ?>
		<div class="ectdivcontainer">
			<div class="ectdivleft"><?php print $redstar . $GLOBALS['xxCity']?></div>
			<div class="ectdivright"><input type="text" name="city" id="city" size="25" value="<?php print htmlspecials($addCity)?>" placeholder="<?php print placeholder($GLOBALS['xxCity'])?>" /></div>
		</div>
		<?php	if($hasstates || $nonhomecountries){ ?>
		<div class="ectdivcontainer">
			<div class="ectdivleft"><?php print replace($redstar,'<span','<span id="statestar"')?><span id="statetxt"><?php print $GLOBALS['xxState']?></span></div>
			<div class="ectdivright"><select name="state" id="state" size="1" onchange="dosavestate('')"><?php $havestate=show_states($addState) ?></select><input type="text" name="state2" id="state2" size="25" value="<?php if(! $havestate) print htmlspecials($addState)?>" placeholder="<?php print placeholder($GLOBALS['xxState'])?>" /></div>
		</div>
		<?php	} ?>
		<div class="ectdivcontainer">
			<div class="ectdivleft"><?php print $redstar . $GLOBALS['xxCountry']?></div>
			<div class="ectdivright"><select name="country" id="country" size="1" onchange="checkoutspan('')" ><?php show_countries($addCountry,FALSE) ?></select></div>
		</div>
		<div class="ectdivcontainer">
			<div class="ectdivleft"><?php print replace($redstar,'<span','<span id="zipstar"') . '<span id="ziptxt">' . $GLOBALS['xxZip'] . '</span>'?></div>
			<div class="ectdivright"><input type="text" name="zip" id="zip" size="25" value="<?php print htmlspecials($addZip)?>" placeholder="<?php print placeholder($GLOBALS['xxCountry'])?>" /></div>
		</div>
		<div class="ectdivcontainer">
			<div class="ectdivleft"><?php print $redstar . $GLOBALS['xxPhone']?></div>
			<div class="ectdivright"><input type="text" name="phone" id="phone" size="25" value="<?php print htmlspecials($addPhone)?>" placeholder="<?php print placeholder($GLOBALS['xxPhone'])?>" /></div>
		</div>
		<?php	if(trim_(@$GLOBALS['extraorderfield2'])!=''){ ?>
		<div class="ectdivcontainer">
			<div class="ectdivleft"><?php print (@$GLOBALS['extraorderfield2required'] ? $redstar : '') . $GLOBALS['extraorderfield2'] ?></div>
			<div class="ectdivright"><?php if(@$GLOBALS['extraorderfield2html']!='') print $GLOBALS['extraorderfield2html']; else print '<input type="text" name="ordextra2" id="ordextra2" size="25" value="' . htmlspecials($addExtra2) . '" placeholder="'.placeholder($GLOBALS['extraorderfield2']).'" autocomplete="false" />'?></div>
		</div>
		<?php	} ?>
		<div class="ectdiv2column"><?php print imageorsubmit(@$imgsubmit,$GLOBALS['xxSubmt'],'submit').' '.imageorbutton(@$imgcancel,$GLOBALS['xxCancel'],'cancel','history.go(-1)',TRUE)?></div>
	  </div>
	</form>
<script>
/* <![CDATA[ */
var checkedfullname=false;
function zipoptional(cntobj){
var cntid=cntobj[cntobj.selectedIndex].value;
if(cntid==85 || cntid==91 || cntid==154 || cntid==200)return true; else return false;
}
function stateoptional(cntobj){
var cntid=cntobj[cntobj.selectedIndex].value;
if(false<?php
$result=ect_query('SELECT countryID FROM countries WHERE countryEnabled<>0 AND loadStates<0') or ect_error();
while($rs=ect_fetch_assoc($result)) print '||cntid==' . $rs['countryID'];
ect_free_result($result);
?>)return true; else return false;
}
function checkform(frm)
{
<?php if(trim_(@$GLOBALS['extraorderfield1'])!='' && @$GLOBALS['extraorderfield1required']){ ?>
if(frm.ordextra1.value==""){
	alert("<?php print jscheck($GLOBALS['xxPlsEntr'] . ' "' . $GLOBALS['extraorderfield1'])?>\".");
	frm.ordextra1.focus();
	return (false);
}
<?php } ?>
if(frm.xname.value==""||frm.xname.value=="<?php print $GLOBALS['xxFirNam']?>"){
	alert("<?php print jscheck($GLOBALS['xxPlsEntr'] . ' "' . (@$GLOBALS['usefirstlastname'] ? $GLOBALS['xxFirNam'] : $GLOBALS['xxName']))?>\".");
	frm.xname.focus();
	return (false);
}
<?php	if(@$GLOBALS['usefirstlastname']){ ?>
if(frm.lastname.value==""||frm.lastname.value=="<?php print $GLOBALS['xxLasNam']?>"){
	alert("<?php print jscheck($GLOBALS['xxPlsEntr'] . ' "' . $GLOBALS['xxLasNam'])?>\".");
	frm.lastname.focus();
	return (false);
}
<?php	}else{ ?>
gotspace=false;
var checkStr=frm.xname.value;
for (i=0; i < checkStr.length; i++){
	if(checkStr.charAt(i)==" ")
		gotspace=true;
}
if(!checkedfullname && !gotspace){
	alert("<?php print jscheck($GLOBALS['xxFulNam'] . ' "' . $GLOBALS['xxName'])?>\".");
	frm.xname.focus();
	checkedfullname=true;
	return (false);
}
<?php	} ?>
if(frm.address.value==""){
	alert("<?php print jscheck($GLOBALS['xxPlsEntr'] . ' "' . $GLOBALS['xxAddress'])?>\".");
	frm.address.focus();
	return (false);
}
if(frm.city.value==""){
	alert("<?php print jscheck($GLOBALS['xxPlsEntr'] . ' "' . $GLOBALS['xxCity'])?>\".");
	frm.city.focus();
	return (false);
}
if(stateoptional(document.getElementById('country'))){
	}else if(stateselectordisabled[0]==false){
<?php
	if($hasstates){ ?>
	if(frm.state.selectedIndex==0){
		alert("<?php print jscheck($GLOBALS['xxPlsSlct']) . ' '?>" + document.getElementById('statetxt').innerHTML);
		frm.state.focus();
		return(false);
	}
<?php	} ?>
	}else{
<?php	if($nonhomecountries){ ?>
	if(frm.state2.value==""){
		alert("<?php print jscheck($GLOBALS['xxPlsEntr'])?> \"" + document.getElementById('statetxt').innerHTML + "\".");
		frm.state2.focus();
		return(false);
	}
<?php	} ?>}
if(frm.zip.value=="" && ! zipoptional(document.getElementById('country'))){
	alert("<?php print jscheck($GLOBALS['xxPlsEntr'] . ' "' . $GLOBALS['xxZip'])?>\".");
	frm.zip.focus();
	return(false);
}
if(frm.phone.value==""){
	alert("<?php print jscheck($GLOBALS['xxPlsEntr'] . ' "' . $GLOBALS['xxPhone'])?>\".");
	frm.phone.focus();
	return (false);
}
<?php if(trim_(@$GLOBALS['extraorderfield2'])!='' && @$GLOBALS['extraorderfield2required']){ ?>
if(frm.ordextra2.value==""){
	alert("<?php print jscheck($GLOBALS['xxPlsEntr'] . ' "' . $GLOBALS['extraorderfield2'])?>\".");
	frm.ordextra2.focus();
	return (false);
}
<?php } ?>
return (true);
}
<?php if(@$termsandconditions==TRUE){ ?>
function showtermsandconds(){
newwin=window.open("termsandconditions<?php print $GLOBALS['extension']?>","Terms","menubar=no, scrollbars=yes, width=420, height=380, directories=no,location=no,resizable=yes,status=no,toolbar=no");
}
<?php } ?>
var savestate=0;
var ssavestate=0;
function dosavestate(shp){
	thestate=eval('document.forms.mainform.'+shp+'state');
	eval(shp+'savestate=thestate.selectedIndex');
}
function checkoutspan(shp){
	document.getElementById(shp+'zipstar').style.display=(zipoptional(document.getElementById(shp+'country'))?'none':'');
	document.getElementById(shp+'statestar').style.display=(stateoptional(document.getElementById(shp+'country'))?'none':'');<?php
	if($hasstates){
		print "thestate=document.getElementById(shp+'state');\r\n";
		print "dynamiccountries(document.getElementById(shp+'country'),shp);\r\n";
	}
	print "if(stateselectordisabled[shp=='s'?1:0]==false&&!stateoptional(document.getElementById(shp+'country'))){\r\n";
	print "if(document.getElementById(shp+'state2'))document.getElementById(shp+'state2').style.display='none';\r\n";
	if($hasstates){
		print "thestate.disabled=false;\r\n";
		print "eval('thestate.selectedIndex='+shp+'savestate');\r\n";
		print "document.getElementById(shp+'state').style.display='';\r\n";
	} ?>
}else{<?php
	print "if(document.getElementById(shp+'state2'))document.getElementById(shp+'state2').style.display='';\r\n";
	if($hasstates){ ?>
		document.getElementById(shp+'state').style.display='none';
		if(thestate.disabled==false){
		thestate.disabled=true;
		eval(shp+'savestate=thestate.selectedIndex');
		thestate.selectedIndex=0;}
<?php
	} ?>
}}
<?php
	createdynamicstates('SELECT stateID,stateAbbrev,stateName,stateName2,stateName3,stateCountryID,countryName FROM states INNER JOIN countries ON states.stateCountryID=countries.countryID WHERE countryEnabled<>0 AND stateEnabled<>0 AND (loadStates=2 OR countryID=' . $origCountryID . ') ORDER BY stateCountryID,' . getlangid('stateName',1048576));
	print "checkoutspan('');setinitialstate('');\r\n";
?>/* ]]> */
</script>
<?php	}elseif((getpost('action')=='createlist' && trim(str_replace('<','',getpost("listname")))!='') || getpost('action')=='deletelist' || getpost('action')=='deleteaddress' || getpost('action')=='doeditaddress' || getpost('action')=='donewaddress'){
			$viewing='';
			$addID=str_replace("'",'',getpost('theid'));
			if(!is_numeric($addID))$addID=0;
			$ordName=strip_tags(getpost('xname'));
			$ordLastName=strip_tags(getpost('lastname'));
			$ordAddress=strip_tags(getpost('address'));
			$ordAddress2=strip_tags(getpost('address2'));
			$ordState=strip_tags(getpost('state2'));
			if(getpost('state')!='')
				$ordState=strip_tags(getpost('state'));
			$ordState=strip_tags(getstatefromid($ordState));
			$ordCity=strip_tags(getpost('city'));
			$ordZip=strip_tags(getpost('zip'));
			$ordPhone=strip_tags(getpost('phone'));
			$ordCountry=strip_tags(getcountryfromid(getpost('country')));
			$ordExtra1=strip_tags(getpost('ordextra1'));
			$ordExtra2=strip_tags(getpost('ordextra2'));
			$headertext='';
			$listname=trim(str_replace('<','',getpost("listname")));
			if(getpost('action')=='createlist' && @$GLOBALS['enablewishlists']){
				$headertext=$GLOBALS['xxLisMan'];
				$listaccess=md5(time() . $listname . $adminSecret);
				$sSQL="INSERT INTO customerlists (listName,listOwner,listAccess) VALUES ('" . escape_string($listname) . "'," . $_SESSION['clientID'] . ",'" . escape_string($listaccess) . "')";
				ect_query($sSQL) or ect_error();
			}elseif(getpost('action')=='deletelist' && @$GLOBALS['enablewishlists']){
				$headertext=$GLOBALS['xxLisMan'];
				$sSQL="DELETE FROM customerlists WHERE listID=" . $addID . " AND listOwner=" . $_SESSION['clientID'];
				ect_query($sSQL) or ect_error();
				$sSQL="DELETE FROM cart WHERE cartListID=" . $addID . " AND cartClientID=" . $_SESSION['clientID'];
				ect_query($sSQL) or ect_error();
			}elseif(getpost('action')=='deleteaddress'){
				$viewing='add';
				$headertext=$GLOBALS['xxAddMan'];
				$sSQL="DELETE FROM address WHERE addID=" . $addID . " AND addCustID=" . $_SESSION['clientID'];
				ect_query($sSQL) or ect_error();
			}elseif(getpost('action')=='donewaddress'){
				$viewing='add';
				$headertext=$GLOBALS['xxAddMan'];
				$sSQL="INSERT INTO address (addCustID,addIsDefault,addName,addLastName,addAddress,addAddress2,addCity,addState,addZip,addCountry,addPhone,addExtra1,addExtra2) VALUES (" . $_SESSION['clientID'] . ",0,'" . escape_string($ordName) . "','" . escape_string($ordLastName) . "','" . escape_string($ordAddress) . "','" . escape_string($ordAddress2) . "','" . escape_string($ordCity) . "','" . escape_string($ordState) . "','" . escape_string($ordZip) . "','" . escape_string($ordCountry) . "','" . escape_string($ordPhone) . "','" . escape_string($ordExtra1) . "','" . escape_string($ordExtra2) . "')";
				ect_query($sSQL) or ect_error();
			}elseif(getpost('action')=='doeditaddress'){
				$viewing='add';
				$headertext=$GLOBALS['xxAddMan'];
				$sSQL="UPDATE address SET addName='" . escape_string($ordName) . "',addLastName='" . escape_string($ordLastName) . "',addAddress='" . escape_string($ordAddress) . "',addAddress2='" . escape_string($ordAddress2) . "',addCity='" . escape_string($ordCity) . "',addState='" . escape_string($ordState) . "',addZip='" . escape_string($ordZip) . "',addCountry='" . escape_string($ordCountry) . "',addPhone='" . escape_string($ordPhone) . "',addExtra1='" . escape_string($ordExtra1) . "',addExtra2='" . escape_string($ordExtra2) . "' WHERE addCustID=" . $_SESSION['clientID'] . " AND addID=" . $addID;
				ect_query($sSQL) or ect_error();
			}
			print '<script>setTimeout(function(){document.location=\'' . jsescape($pagename) . ($viewing!=''?'?vw='.$viewing:'') . "'},2000)</script>";
?>	  <div class="ectdiv ectclientlogin">
		<div class="ectmessagescreen">
			<div class="ectdivhead"><?php print $headertext?></div>
			<div style="padding:50px 0;text-align:center"><?php print $GLOBALS['xxUpdSuc']?></div>
		</div>
	  </div>
<?php	}else{ ?>
<script>
/* <![CDATA[ */
var currstate=[];
currstate['ad']='none';
currstate['am']='none';
currstate['gr']='none';
currstate['om']='none';
function closeformsection(sect){
	currstate[sect]='none';
	document.getElementById('sectimage'+sect).src='images/arrow-down.png';
	document.getElementById(sect+'formrow').style.display='none';
}
function showhidesection(sect){
	var elem=document.getElementById(sect+'formrow');
	currstate[sect]=currstate[sect]=='none'?'':'none';
	elem.style.display=currstate[sect];
	if(document.getElementById('sectimage'+sect))document.getElementById('sectimage'+sect).src=currstate[sect]=='none'?'images/arrow-down.png':'images/arrow-up.png';
	for(var fri in currstate){
		if(fri!=sect&&document.getElementById('sectimage'+fri)){
			currstate[fri]='none';
			document.getElementById('sectimage'+fri).src='images/arrow-down.png';
			document.getElementById(fri+'formrow').style.display='none';
		}
	}
	return false;
}
/* ]]> */</script>
		  <form method="post" name="mainform" action="<?php print $thisaction?>">
			<input type="hidden" name="posted" value="1" />
			<input type="hidden" name="action" value="none" />
			<input type="hidden" name="theid" value="" />
			<div id="clientlogindiv" class="ectdiv ectclientlogin">
				<div class="ectdivhead clientloginmainheader" style="cursor:pointer" onclick="showhidesection('ad')"><?php print $GLOBALS['xxAccDet']?><img id="sectimagead" src="images/arrow-down.png" style="float:right;margin-right:15px" /></div>
				<div id="adformrow" class="adformrow" style="display:none">
				  <div class="ectclientloginaccount">
<?php		$sSQL="SELECT clID,clUserName,clActions,clLoginLevel,clPercentDiscount,clEmail,loyaltyPoints,clientCustom1,clientCustom2 FROM customerlogin WHERE clID=" . $_SESSION['clientID'];
			$result=ect_query($sSQL) or ect_error();
			if($rs=ect_fetch_assoc($result)){
				$theemail=$rs['clEmail'];
				$loyaltypointtotal=$rs['loyaltyPoints'];
				$clientCustom1=$rs['clientCustom1'];
				$clientCustom2=$rs['clientCustom2'];
			}else
				$theemail='ACCOUNT DELETED';
			ect_free_result($result);
			$sSQL="SELECT email,isconfirmed FROM mailinglist WHERE email='" . escape_string($theemail) . "'";
			$result=ect_query($sSQL) or ect_error();
			if($rs=ect_fetch_assoc($result)){ $allowemail=1; $isconfirmed=$rs['isconfirmed']; }else{ $allowemail=0; $isconfirmed=FALSE; }
			ect_free_result($result); ?>
					<div class="ectdivcontainer">
						<div class="ectdivleft"><?php print $GLOBALS['xxName']?></div>
						<div class="ectdivright"><?php print htmlspecials($_SESSION['clientUser'])?></div>
					</div>
<?php		if(@$nounsubscribe!=TRUE){ ?>
					<div class="ectdivcontainer">
						<div class="ectdivleft"><?php print $GLOBALS['xxAlPrEm']?><div style="font-size:10px"><?php print $GLOBALS['xxNevDiv']?></div></div>
						<div class="ectdivright"><?php if(@$noconfirmationemail!=TRUE && $allowemail!=0 && $isconfirmed==0) print $GLOBALS['xxWaiCon']; else print '<input type="checkbox" class="ectcheckbox" name="allowemail" value="ON"' . ($allowemail!=0 ? ' checked="checked"' : '') . ' disabled="disabled" />'; ?></div>
					</div>
<?php		} ?>
					<div class="ectdivcontainer">
						<div class="ectdivleft"><?php print $GLOBALS['xxEmail']?></div>
						<div class="ectdivright"><?php print $theemail?></div>
					</div>
<?php		if(trim_(@$GLOBALS['extraclientfield1'])!=''){ ?>
					<div class="ectdivcontainer">
						<div class="ectdivleft"><?php print $GLOBALS['extraclientfield1']?></div>
						<div class="ectdivright"><?php print $clientCustom1?></div>
					</div>
<?php		}
			if(trim_(@$GLOBALS['extraclientfield2'])!=''){ ?>
					<div class="ectdivcontainer">
						<div class="ectdivleft"><?php print $GLOBALS['extraclientfield2']?></div>
						<div class="ectdivright"><?php print $clientCustom2?></div>
					</div>
<?php		}
			if(@$loyaltypoints!=''){ ?>
					<div class="ectdivcontainer">
						<div class="ectdivleft"><?php print $GLOBALS['xxLoyPoi']?></div>
						<div class="ectdivright"><?php print $loyaltypointtotal?></div>
					</div>
<?php		} ?>
					<div class="ectdiv2column"><?php print $GLOBALS['xxChaAcc']?> <?php print imageorbuttontag('',$GLOBALS['xxClkHere'],'ectclientlogin','editaccount()',TRUE)?></div>
				  </div>
				</div>
<?php		// Address Management
?>  		  <div class="ectdivhead clientloginmainheader" style="cursor:pointer" onclick="showhidesection('am')"><?php print $GLOBALS['xxAddMan']?><img id="sectimageam" src="images/arrow-<?php print (getget('vw')=='add') ? 'up' : 'down'?>.png" style="float:right;margin-right:15px" /></div>
			  <div id="amformrow" class="amformrow"<?php if(getget('vw')!='add') print ' style="display:none"'?>>
				  <div class="ectclientloginaddress">
<?php		$sSQL="SELECT addID,addIsDefault,addName,addLastName,addAddress,addAddress2,addState,addCity,addZip,addPhone,addCountry,addExtra1,addExtra2 FROM address WHERE addCustID=" . $_SESSION['clientID'] . " ORDER BY addIsDefault";
			$result=ect_query($sSQL) or ect_error();
			if(ect_num_rows($result)>0){
				while($rs=ect_fetch_assoc($result)){
					print '<div class="ectdivcontainer">';
						print '<div class="ectdivleft">' .
						(strip_tags(trim_($rs['addExtra1']))!='' && @$GLOBALS['extraorderfield1']!='' ? $rs['addExtra1'] . '<br>' : '') .
						strip_tags(trim_($rs['addName'].' '.$rs['addLastName'])) . '<br>' .
						strip_tags($rs['addAddress']) . (trim_($rs['addAddress2'])!='' ? '<br>' .
						strip_tags($rs['addAddress2']) : '') . '<br>' .
						strip_tags($rs['addCity']) . ', ' .
						strip_tags($rs['addState']) . ($rs['addZip']!='' ? '<br>' . strip_tags($rs['addZip']) : '') . '<br>' .
						strip_tags($rs['addCountry']) .
						(strip_tags(trim_($rs['addExtra2']))!='' && @$GLOBALS['extraorderfield2']!='' ? '<br>' . $rs['addExtra2'] : '') .
						'</div>';
						print '<div class="ectdivright"><div class="ectcladdressbutton">' . imageorbuttontag('',$GLOBALS['xxEdAdd'],'ectclientlogin editaddress','editaddress(' . $rs['addID'] . ')',TRUE) . '</div><div class="ectcladdressbutton">' . imageorbuttontag('',$GLOBALS['xxDeAdd'],'ectclientlogin deleteaddress','deleteaddress(' . $rs['addID'] . ')',TRUE) . '</div></div>';
					print '</div>';
				}
			}else{
				print '<div class="nosearchresults">' . $GLOBALS['xxNoAdd'] . '</div>';
			}
			ect_free_result($result);
?>
					<div class="ectdiv2column"><?php print $GLOBALS['xxPCAdd']?> <?php print imageorbuttontag('',$GLOBALS['xxClkHere'],'ectclientlogin','newaddress()',TRUE)?></div>
				  </div>
			  </div>
<?php		// Gift Registry Management
			if(@$GLOBALS['enablewishlists']){
?>			  <div class="ectdivhead clientloginmainheader" style="cursor:pointer" onclick="showhidesection('gr')"><?php print $GLOBALS['xxLisMan']?><img id="sectimagegr" src="images/arrow-down.png" style="float:right;margin-right:15px" /></div>
			  <div id="grformrow" class="grformrow" style="display:none">
				  <div class="ectclientlogingiftreg">
<?php			$sSQL="SELECT listID,listName,listAccess FROM customerlists WHERE listOwner=" . $_SESSION['clientID'] . " ORDER BY listName";
				$result=ect_query($sSQL) or ect_error();
				if(ect_num_rows($result)>0){
					while($rs=ect_fetch_assoc($result)){
						$numitems=0;
						$sSQL="SELECT COUNT(*) AS numitems FROM cart WHERE cartListID=" . $rs['listID'];
						$result2=ect_query($sSQL) or ect_error();
						if($rs2=ect_fetch_assoc($result2))
							if(! is_null($rs2['numitems'])) $numitems=$rs2['numitems'];
						ect_free_result($result2);
						print '<div class="ectgiftregname">' . htmlspecials(trim($rs['listName'])) . ' (' . $numitems . ')</div>';
						print '<div class="ectdiv2column"><div class="ectpublicaccesstext">' . $GLOBALS['xxPubAcc'] . ':</div><div class="ectpublicaccessinput"><input class="ecttextinput giftregistrycopy" id="publicop' . $rs['listID'] . '" value="'.$storeurl.'cart'.$GLOBALS['extension'].'?pli=' . $rs['listID'] . '&pla=' . $rs['listAccess'] . '" size="60" /></div></div>';
						print '<div class="ectgiftregistrybuttons">';
							print '<div class="ectgiftregcopy"><input type="button" class="ectbutton" onclick="document.getElementById(\'publicop' . $rs['listID'] . '\').select();try{document.execCommand(\'copy\')}catch(err){alert(\'Copy command not supported\')}" value="Copy To Clipboard" /></div>';
							if($numitems>0) print '<div class="ectgiftregview">' . imageorbutton(@$GLOBALS['imgectgiftregview'],$GLOBALS['xxVieGRe'],"ectgiftregview",'cart'.$GLOBALS['extension'].'?pli=' . $rs['listID'],FALSE) . '</div>';
							print '<div class="ectgiftregdel">' . imageorbutton(@$GLOBALS['imgectgiftregdel'],$GLOBALS['xxDelGRe'],'ectgiftregdel','deletelist(' . $rs['listID'] . ')',TRUE) . '</div>';
						print '</div>';
					}
				}else
					print '<div class="nosearchresults">' . $GLOBALS['xxNoGRe'] . '</div>';
				ect_free_result($result);
?>					<div>
						<?php print imageorbutton(@$imgcreatelist,'Create New List','createlist','createlist()',TRUE)?>
						<input type="text" class="ecttextinput createlistinput" name="listname" size="40" maxlength="50" placeholder="<?php print $GLOBALS['xxLisNam']?>" />
					</div>
				  </div>
			  </div>
<?php		}
			// Order Management
			$ordersperpage=10;
			$ordersearch=getpost('ordersearch');
			if(is_numeric(getget('perpage'))&&(int)getget('perpage')<=50) $ordersperpage=getget('perpage');
			if(! is_numeric(getget('pg')) || strlen(getget('pg'))>8) $CurPage=1; else $CurPage=max(1, (int)getget('pg'));
			$success=TRUE;
			$whereclause=' WHERE ordStatus>=3 AND ordClientID=' . $_SESSION['clientID'];
			if($ordersearch!=''){
				$whereclause=' INNER JOIN cart ON orders.ordID=cart.cartOrderID ' . $whereclause . " AND (cartProdID LIKE '%" . escape_string($ordersearch) . "%' OR cartProdName LIKE '%" . escape_string($ordersearch) . "%'";
				if(is_numeric($ordersearch)) $whereclause.=" OR ordID='" . escape_string($ordersearch) . "'";
				$whereclause.=') ';
			}
			$sSQL='SELECT COUNT(DISTINCT ordID) AS bar FROM orders LEFT JOIN orderstatus ON orders.ordStatus=orderstatus.statID' . $whereclause;
			$foundrows=ect_query($sSQL) or ect_error();
			$rs=ect_fetch_assoc($foundrows);
			$inumoforders=$rs['bar'];
			$iNumOfPages=ceil($rs['bar']/$ordersperpage);
			ect_free_result($foundrows);
?>			  <div class="ectdivhead clientloginmainheader" style="cursor:pointer" onclick="showhidesection('om')"><?php print $GLOBALS['xxOrdMan']?><img id="sectimageom" src="images/arrow-down.png" style="float:right;margin-right:15px" /></div>
			  <div id="omformrow" class="omformrow" style="display:none">
				  <div class="ordhistorycontrols">
					<form method="post" action="<?php if(is_numeric(getget('perpage'))) print '?perpage=' . getget('perpage')?>">
						<div class="ectclordcount"><?php print $inumoforders?> <?php print $GLOBALS['xxOHNumO']?> </div> - <select class="ectselectinput" size="1" name="perpage" onchange="document.location='<?php print @$_SERVER['PHP_SELF'].'?perpage='?>'+this[this.selectedIndex].value">
							<option value="10">10 <?php print $GLOBALS['xxPerPag']?></option>
							<option value="20"<?php if(getget('perpage')=='20') print ' selected'?>>20 <?php print $GLOBALS['xxPerPag']?></option>
							<option value="30"<?php if(getget('perpage')=='30') print ' selected'?>>30 <?php print $GLOBALS['xxPerPag']?></option>
							<option value="40"<?php if(getget('perpage')=='40') print ' selected'?>>40 <?php print $GLOBALS['xxPerPag']?></option>
							<option value="50"<?php if(getget('perpage')=='50') print ' selected'?>>50 <?php print $GLOBALS['xxPerPag']?></option>
						</select>
						<input class="ecttextinput ectclordsearchtxt" type="text" name="ordersearch" placeholder="<?php print $GLOBALS['xxOHOPID']?>" value="<?php print htmlspecials($ordersearch)?>">
						<button type="submit" class="ectbutton"><?php print $GLOBALS['xxOHSeOr']?></button>
					</form>
				  </div>
				  <div class="ectorderhistorytable">
<?php		if($iNumOfPages>1){
				$pblink='<a class="ectlink" href="' . $pagename . '?pg=';
				print '<div class="pagenumbers">' . "\n";
				print writepagebar($CurPage,$iNumOfPages,$GLOBALS['xxPrev'],$GLOBALS['xxNext'],$pblink,TRUE);
				print "</div>\n";
			}
			$sSQL="SELECT DISTINCT ordID,ordDate,ordTrackNum,ordTotal,ordStateTax,ordCountryTax,ordShipping,ordHSTTax,ordHandling,ordDiscount," . getlangid('statPublic',64) . " FROM orders LEFT JOIN orderstatus ON orders.ordStatus=orderstatus.statID " . $whereclause . ' ORDER BY ordDate DESC LIMIT ' . ($ordersperpage*($CurPage-1)) . ', '.$ordersperpage;
			$result=ect_query($sSQL) or ect_error();
			if(ect_num_rows($result)>0){
				while($rs=ect_fetch_assoc($result)){
					$trackingnum=trim_($rs['ordTrackNum']);
					$cartquant=0;
					$sSQL="SELECT SUM(cartQuantity) AS cartquant FROM cart WHERE cartOrderID=".$rs['ordID'];
					$result2=ect_query($sSQL) or ect_error();
					while($rs2=ect_fetch_assoc($result2)){
						$cartquant=$rs2['cartquant'];
					}
					ect_free_result($result2);
					print '<div class="ectclientlogorder">';
					print '<div class="ectclordrow1">';
						print '<div><span class="ectclordlabel">Date:</span> ' . date($dateformatstr, strtotime($rs['ordDate'])) . '</div>';
						print '<div>';
							print '<div class="ectclordarticle">' . $cartquant . ' ' . $GLOBALS['xxOHArtc'] . ' - <span class="ectclordlabel">' . FormatEuroCurrency(($rs['ordTotal']+$rs['ordStateTax']+$rs['ordCountryTax']+$rs['ordShipping']+$rs['ordHSTTax']+$rs['ordHandling'])-$rs['ordDiscount']) . '</span></div>';
							if($trackingnum!=''){
								$tracknumarr=explode(',',$rs['ordTrackNum']);
								foreach($tracknumarr as $key => $trkno){
									if(trim($trkno)!=''){
										$thecarrier=getcarrierfromtrack($trkno,$thelink);
										print '<div>';
										if($thelink!='') print imageorbuttontag('',$GLOBALS['xxOHTrPa'],'',$thelink . $trkno,FALSE,TRUE); else print '<button type="button" class="ectbutton" disabled>' . $GLOBALS['xxOHTrPa'] . '</button>';
										print '</div>';
									}
								}
							}
						print '</div>';
					print '</div>';
					print '<div class="ectclordrow2">';
						print '<div><span class="ectclordlabel">Status:</span> ' . $rs[getlangid("statPublic",64)] . '</div>';
						print '<div class="orderhistorydetails">' . imageorbuttontag('',$GLOBALS['xxOHDeta'] . ' ' . $rs['ordID'],'ectclientlogin','vieworder(' . $rs['ordID'] . ')',TRUE) . '</div>';
					print '</div>';
					$sSQL="SELECT cartProdID,cartProdName,cartOrigProdID,cartTrackNum,pName,pStaticPage,pStaticURL FROM cart LEFT JOIN products ON cart.cartOrigProdID=products.pID WHERE cartOrderID=".$rs['ordID'];
					if($ordersearch!=''){
						$sSQL.=" AND (cartProdID LIKE '%" . escape_string($ordersearch) . "%' OR cartProdName LIKE '%" . escape_string($ordersearch) . "%'";
						if(is_numeric($ordersearch)) $sSQL.=" OR cartOrderID='" . escape_string($ordersearch) . "'";
						$sSQL.=')';
					}
					$sSQL.=' ORDER BY cartID';
					$result2=ect_query($sSQL) or ect_error();
					while($rs2=ect_fetch_assoc($result2)){
						$trackingnum=$rs2['cartTrackNum'];
						$cartOrigProdName=$rs2['cartProdName'];
						if($rs2['cartOrigProdID']!=''){
							$opts=ect_query("SELECT pName,".getaltlang('pStaticURL',8388608).",pStaticPage FROM products WHERE pID='" . escape_string($rs2['cartOrigProdID']) . "'") or ect_error();
							if($rs3=ect_fetch_assoc($opts)){
								$rs2['pStaticURL']=$rs3['pStaticURL'];
								$rs2['pStaticPage']=$rs3['pStaticPage'];
								$cartOrigProdName=$rs3['pName'];
							}
							ect_free_result($opts);
						}
						$thedetailslink=getdetailsurl($rs2['cartOrigProdID']?$rs2['cartOrigProdID']:$rs2['cartProdID'],$rs2['pStaticPage'],$cartOrigProdName,$rs2['pStaticURL'],'',@$GLOBALS['pathtohere']);
						print '<div class="ectclordrow3">';
						$thankspageimage='';
						$sSQL="SELECT imageSrc FROM productimages WHERE imageProduct='" . escape_string($rs2['cartProdID']) . "' AND (imageType=0 OR imageType=1) ORDER BY imageType,imageNumber";
						$imgresult=ect_query($sSQL) or ect_error();
						$thankspageimage=@$GLOBALS['defaultthankspageimage'];
						if($rs3=ect_fetch_assoc($imgresult)) $thankspageimage=$rs3['imageSrc'];
						ect_free_result($imgresult);
						if($thankspageimage!='') print '<div class="ectclprodimg"><img src="' . $thankspageimage . '" alt=""></div>';
						print '<div>';
							print '<div class="ectclordprodid">' . $GLOBALS['xxPrId'] . ': ' . $rs2['cartProdID'] . '</div>';
							print '<div class="ectclordprodname">' . $rs2['cartProdName'] . '</div>';
						print '</div>';
						print '<div>';
							print '<div class="ectclordviewprod">' . imageorbuttontag('',$GLOBALS['xxOHViPr'],'',$thedetailslink,FALSE) . '</div>';
							if($trackingnum!=''){
								print '<div class="ectclordtrack">';
								$tracknumarr=explode(',',$trackingnum);
								foreach($tracknumarr as $key => $trkno){
									if(trim($trkno)!=''){
										$thecarrier=getcarrierfromtrack($trkno,$thelink);
										if($thelink!='') print imageorbuttontag('',$GLOBALS['xxOHTrPa'],'',$thelink . $trkno,FALSE,TRUE); else print '<button type="button" class="ectbutton" disabled>' . $GLOBALS['xxOHTrPa'] . '</button>';
									}
								}
								print '</div>';
							}
							if(@$GLOBALS['enablecustomerratings']) print '<div class="ectclordreview">' . imageorbuttontag('',$GLOBALS['xxOHRePr'],'',$thedetailslink.(strpos($thedetailslink,'?')!==FALSE?'&':'?').'review=true', FALSE) . '</div>';
							print '</div>';
						print '</div>';
					}
					ect_free_result($result2);
					print "</div>\n";
				}
			}else
				$success=FALSE;
			ect_free_result($result);

			if($iNumOfPages>1){
				$pblink='<a class="ectlink" href="' . $pagename . '?pg=';
				print '<div class="pagenumbers">' . "\n";
				print writepagebar($CurPage,$iNumOfPages,$GLOBALS['xxPrev'],$GLOBALS['xxNext'],$pblink,TRUE);
				print "</div>\n";
			}
			
			if(! $success) print '<div class="nosearchresults">' . $GLOBALS['xxNoOrd'] . '</div>' ?>
				</div>
			  </div>
			</div>
		  </form>
<script>
/* <![CDATA[ */
if(document.location.hash=='#list')showhidesection('gr');
else if(document.location.hash=='#add')showhidesection('am');
else if(document.location.hash=='#acct')showhidesection('ad');
else showhidesection('om');
/* ]]> */</script>
<?php	}
	} ?>
