<?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(@$storesessionvalue=='') $storesessionvalue='virtualstore'.time();
if(@$_SESSION['loggedon']!=$storesessionvalue||@$GLOBALS['disallowlogin']||!@$GLOBALS['incfunctionsdefined']) exit;
$success=TRUE;
if(@$maxbreaksperpage=='')$maxbreaksperpage=200;
$maxpricebreaks = 25;
$sSQL='';
$dropdown=(getpost('ddown')=='1');
$alldata='';
$dorefresh=FALSE;
if(getpost('posted')=='1'){
	if(getpost('act')=='delete'){
		$sSQL = "DELETE FROM pricebreaks WHERE pbProdID='" . escape_string(getpost('id')) . "'";
		ect_query($sSQL) or ect_error();
		$dorefresh=TRUE;
	}elseif(getpost('act')=="domodify"){
		$theprod=getpost('pid');
		$sSQL = "SELECT pID FROM products WHERE pID='" . escape_string($theprod) . "'";
		$result=ect_query($sSQL) or ect_error();
		if(ect_num_rows($result)<=0){
			$success=FALSE;
			$errmsg = "The specified product id (" . $theprod . ") does not exist.";
		}
		ect_free_result($result);
		if($success){
			ect_query("DELETE FROM pricebreaks WHERE pbProdID='" . escape_string($theprod) . "'") or ect_error();
			for($index=1; $index <= $maxpricebreaks; $index++){
				$thequant=getpost('quant' . $index);
				if(! is_numeric($thequant)) $thequant=0;
				$price=getpost('price' . $index);
				if(! is_numeric($price)) $price=0;
				$wprice=getpost('wprice' . $index);
				if(! is_numeric($wprice)) $wprice=0;
				$wpercent=(getpost("wpercent".$index)=='1'?'1':'0');
				$wholesalepercent=(getpost("wholesalepercent".$index)=='1'?'1':'0');
				if($thequant != 0 && ($price != 0 || $wprice != 0)){
					$sSQL = "INSERT INTO pricebreaks (pbProdID,pbQuantity,pPrice,pWholesalePrice,pbPercent,pbWholesalePercent) VALUES ('" . escape_string($theprod) . "',";
					$sSQL.=$thequant . ",";
					$sSQL.=$price . ",";
					$sSQL.=$wprice . ',' . $wpercent . ',' . $wholesalepercent . ")";
					ect_query($sSQL);
				}
			}
			$dorefresh=TRUE;
		}
	}elseif(getpost('act')=="doaddnew"){
		$theprod=getpost('pid');
		$sSQL = "SELECT pbProdID FROM pricebreaks WHERE pbProdID='" . escape_string($theprod) . "'";
		$result=ect_query($sSQL) or ect_error();
		if(ect_num_rows($result)>0){
			$success=FALSE;
			$errmsg = 'Price breaks already exist for this product id. You should use the "Modify" option on the price breaks admin page';
		}
		ect_free_result($result);
		$sSQL = "SELECT pID FROM products WHERE pID='" . escape_string($theprod) . "'";
		$result=ect_query($sSQL) or ect_error();
		if(ect_num_rows($result)<=0){
			$success=FALSE;
			$errmsg = "The specified product id (" . $theprod . ") does not exist.";
		}
		ect_free_result($result);
		if($success){
			for($index=1; $index <= $maxpricebreaks; $index++){
				$thequant=getpost('quant' . $index);
				if(! is_numeric($thequant)) $thequant=0;
				$price=getpost('price' . $index);
				if(! is_numeric($price)) $price=0;
				$wprice=getpost('wprice' . $index);
				if(! is_numeric($wprice)) $wprice=0;
				$wpercent=(getpost("wpercent".$index)=='1'?'1':'0');
				$wholesalepercent=(getpost("wholesalepercent".$index)=='1'?'1':'0');
				if($thequant != 0 && ($price != 0 || $wprice != 0)){
					$sSQL = "INSERT INTO pricebreaks (pbProdID,pbQuantity,pPrice,pWholesalePrice,pbPercent,pbWholesalePercent) VALUES ('" . escape_string($theprod) . "',";
					$sSQL.=$thequant . ",";
					$sSQL.=$price . ",";
					$sSQL.=$wprice . ',' . $wpercent . ',' . $wholesalepercent . ")";
					ect_query($sSQL);
				}
			}
			$dorefresh=TRUE;
		}
	}
	if($dorefresh)
		print '<meta http-equiv="refresh" content="1; url=adminpricebreak.php?stext=' . urlencode(@$_REQUEST['stext']) . '&sort=' . @$_REQUEST['sort'] . '&stype=' . @$_REQUEST['stype'] . '&ddown=' . @$_REQUEST['ddown'] . '&pg=' . @$_REQUEST['pg'] . '" />';
}
?>
<script>
<!--
function setCookie(c_name,value,expiredays){
	var exdate=new Date();
	exdate.setDate(exdate.getDate()+expiredays);
	document.cookie=c_name+ "=" +escape(value)+((expiredays==null) ? "" : ";expires="+exdate.toGMTString());
}
var opensels=[];
var tmrid;
var gtxt;
document.getElementById('main').onclick=function(){
	for(var ii=0; ii<opensels.length; ii++)
		document.getElementById(opensels[ii]).style.display='none';
};
function getvalsfromserver(oSelect){
	oText=document.getElementById('pid');
	if(oSelect.selectedIndex != -1){
		oText.value=oSelect.options[oSelect.selectedIndex].value;
		oSelect.style.display='none';
		oText.focus();
	}
	return false;
}
function comboselect_onclick(oSelect){
	return(getvalsfromserver(oSelect));
}
function comboselect_onchange(oSelect){
	oText=document.getElementById('pid');
	if(oSelect.selectedIndex != -1){
		oText.value=oSelect.options[oSelect.selectedIndex].value;
	}
}
function comboselect_onkeyup(keyCode,oSelect){
	if(keyCode==13){
		getvalsfromserver(oSelect);
	}
	return(false);
}
function plajaxcallback(){
	if(ajaxobj.readyState==4){
		var resarr=ajaxobj.responseText.replace(/^\s+|\s+$/g,"").split('==LISTOBJ==');
		var index,isname=false;
		oSelect=document.getElementById(resarr[0]);
		var act=resarr[0].replace(/\d/g,'');
		for(index=0; index<resarr.length-2; index++){
			var splitelem=resarr[index+1].split('==LISTELM==');
			var val1=splitelem[0];
			var val2=splitelem[1];
			if(index<oSelect.length)
				var y=oSelect.options[index];
			else
				var y=document.createElement('option');
			y.text=val1+(val2!='----------------'?' / '+val2:'');
			y.value=val1;
			if(y.text=='----------------') y.disabled=true; else y.disabled=false;
			if(index>=oSelect.length){
				try{oSelect.add(y, null);} // FF etc
				catch(ex){oSelect.add(y);} // IE
			}
		}
		if(oSelect){
			for(var ii=oSelect.length;ii>=index;ii--){
				oSelect.remove(ii);
			}
		}
	}
}
function populatelist(){
	var stext=gtxt;
	ajaxobj=window.XMLHttpRequest?new XMLHttpRequest():new ActiveXObject("MSXML2.XMLHTTP");
	ajaxobj.onreadystatechange=plajaxcallback;
	ajaxobj.open("POST", "ajaxservice.php?action=getlist&objid=comboselect&listtype=prodid", true);
	ajaxobj.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	ajaxobj.send('listtext='+stext);
}
function addopensel(id){
	for(var ii=0; ii<opensels.length; ii++)
		if(id==opensels[ii]) return;
	opensels.push(id);
}
function combochange(oText,e){
	if(document.getElementById("autocomplete").checked==false)
		return;
	keyCode=e.keyCode;
	if(keyCode<32&&keyCode!=8)return true;
	oSelect=document.getElementById('comboselect');
	addopensel(oSelect.id);
	oSelect.style.display='';
	toFind=oText.value.toLowerCase();
	gtxt=toFind;
	clearTimeout(tmrid);
	tmrid=setTimeout("populatelist()",800);
}
function combokey(oText,e){
	if(document.getElementById("autocomplete").checked==false)
		return
	oSelect=document.getElementById('comboselect');
	keyCode=e.keyCode;
	if(keyCode==40 || keyCode==38){ // Up / down arrows
		addopensel(oSelect.id);
		oSelect.style.display='';
		oSelect.focus();
		comboselect_onchange(oSelect);
	}
	else if(keyCode==13){
		oSelect.style.display='none';
		oText.focus();
		return getvalsfromserver(oSelect);
	}
	return true;
}
function focusfield(tfield,tmsg){
tfield.focus();
alert(tmsg);
return(false);
}
function formvalidator(theForm){
var patternprice=/[^0-9\.]/
var patternquant=/[^0-9]/
<?php if($dropdown){ ?>
  if (theForm.pid.selectedIndex==0){
    alert("<?php print jscheck($yyPlsSel . ' "' . $yyPrId)?>\".");
<?php }else{ ?>
  if (theForm.pid.value==""){
    alert("<?php print jscheck($yyPlsEntr . ' "' . $yyPrId)?>\".");
<?php } ?>
    theForm.pid.focus();
    return (false);
  }
  for(var index=0;index<<?php print $maxpricebreaks?>;index++){
	if(document.getElementById('quant'+index)){
		if(patternquant.test(document.getElementById('quant'+index).value)) return(focusfield(document.getElementById('quant'+index),"<?php print jscheck($yyOnDig)?>"));
		if(patternprice.test(document.getElementById('price'+index).value)) return(focusfield(document.getElementById('price'+index),"<?php print jscheck($yyDecFld)?>"));
		if(patternprice.test(document.getElementById('wprice'+index).value)) return(focusfield(document.getElementById('wprice'+index),"<?php print jscheck($yyDecFld)?>"));
		if(document.getElementById('wpercent'+index).checked){
			if(parseFloat(document.getElementById('price'+index).value)>100) return(focusfield(document.getElementById('price'+index),"<?php print jscheck("Percentage breaks should be between 0 and 100")?>"));
		}
		if(document.getElementById('wholesalepercent'+index).checked){
			if(parseFloat(document.getElementById('wprice'+index).value)>100) return(focusfield(document.getElementById('wprice'+index),"<?php print jscheck("Percentage breaks should be between 0 and 100")?>"));
		}
	}
  }
  return (true);
}
//-->
</script>
<?php
if(getpost('posted')=='1' && (getpost('act')=='modify' || getpost('act')=='clone' || getpost('act')=='addnew')){ ?>
	  <table border="0" cellspacing="0" cellpadding="0" width="100%" align="center">
        <tr>
		  <td align="center">
		  <form name="mainform" method="post" action="adminpricebreak.php" onsubmit="return formvalidator(this)">
			<input type="hidden" name="posted" value="1" />
			<?php if(getpost('act')=='clone' || getpost('act')=='addnew'){ ?>
			<input type="hidden" name="act" value="doaddnew" />
			<?php }else{ ?>
			<input type="hidden" name="act" value="domodify" />
			<input type="hidden" name="pid" value="<?php print getpost('id')?>" />
			<?php }
			writehiddenvar('ddown', getpost('ddown'));
			writehiddenvar('stext', getpost('stext'));
			writehiddenvar('sort', getpost('sort'));
			writehiddenvar('stype', getpost('stype'));
			writehiddenvar('pg', getpost('pg')); ?>
			<table width="320" border="0" cellspacing="0" cellpadding="1">
			  <tr> 
                <td colspan="5" align="center"><strong><?php print $yyPBKAdm?></strong><br />&nbsp;</td>
			  </tr>
			  <tr>
				<td style="text-align:right"><?php print $yyPrId?>:</td>
				<td colspan="4"><?php
				if($dropdown && (getpost('act')=='clone' || getpost('act')=='addnew')){
					print '<select size="1" name="pid"><option value="">' . $yySelect . "</option>";
					$sSQL = "SELECT pID FROM products LEFT JOIN pricebreaks ON products.pID=pricebreaks.pbProdID WHERE pbProdID IS NULL ORDER BY pID";
					$result=ect_query($sSQL) or ect_error();
					while($rs=ect_fetch_assoc($result))
						print '<option value="' . $rs["pID"] . '">' . $rs["pID"] . "</option>\r\n";
					ect_free_result($result);
					print '</select>';
				}elseif(getpost('act')=='clone' || getpost('act')=='addnew'){
					print '<input type="text" name="pid" id="pid" size="30" autocomplete="off" onkeydown="return combokey(this,event)" onkeyup="combochange(this,event)" />';
					print '<div style="position:absolute"><select id="comboselect" size="15" ' .
		'style="display:none;position:absolute;min-width:280px;top:0px;left:0px;" ' .
		'onblur="this.style.display=\'none\'" ' .
		'onchange="comboselect_onchange(this)" ' .
		'onclick="comboselect_onclick(this)" ' .
		'onkeyup="comboselect_onkeyup(event.keyCode,this)">' .
		'<option value="">Populating...</option>' .
		'</select></div>';
				}else{
					print getpost('id');
				} ?></td>
			  </tr>
<?php			if(!$dropdown && (getpost('act')=='clone' || getpost('act')=='addnew')){ ?>
			  <tr>
				<td style="text-align:right"><?php print '<input type="checkbox" value="ON" name="autocomplete" id="autocomplete" onclick="setCookie(\'ectautocomp\',this.checked?1:0,600)" '.(@$_COOKIE['ectautocomp']=="1"?'checked="checked" ':'').'/>'?></td>
				<td colspan="4"><?php print $yyUsAuCo?></td>
			  </tr>
<?php			} ?>
			  <tr>
				<td align="center"><span style="font-size:10px;font-weight:bold"><?php print $yyQuaFro?></span></td>
				<td align="center"><span style="font-size:10px;font-weight:bold"><?php print $yyPrPri?></span></td>
				<td align="left" style="padding-left:10px"><span style="font-size:10px;font-weight:bold" title="Treat as percentage price reduction. Eg &quot;10&quot; would mean 10% off the regular price.">%</span></td>
				<td align="center"><span style="font-size:10px;font-weight:bold"><?php print $yyWhoPri?></span></td>
				<td align="left" style="padding-left:10px"><span style="font-size:10px;font-weight:bold" title="Treat as percentage price reduction. Eg &quot;10&quot; would mean 10% off the regular price.">%</span></td>
			  </tr>
<?php		$sSQL = "SELECT pbQuantity,pPrice,pWholesalePrice,pbPercent,pbWholesalePercent FROM pricebreaks WHERE pbProdID='" . escape_string(getpost('id')) . "' ORDER BY pbQuantity";
			$index=1;
			$result=ect_query($sSQL) or ect_error();
			while($rs=ect_fetch_assoc($result)){ ?>
			  <tr>
				<td align="center" style="padding-right:15px"><input type="text" name="quant<?php print $index?>" id="quant<?php print $index?>" size="12" value="<?php print $rs["pbQuantity"]?>" /></td>
				<td align="center"><input type="text" name="price<?php print $index?>" id="price<?php print $index?>" size="12" value="<?php print $rs["pPrice"]?>" /></td>
				<td align="left" style="padding-right:5px"><input type="checkbox" name="wpercent<?php print $index?>" id="wpercent<?php print $index?>" value="1" <?php if($rs["pbPercent"]!=0) print 'checked="checked" '?>/></td>
				<td align="center"><input type="text" name="wprice<?php print $index?>" id="wprice<?php print $index?>" size="12" value="<?php print $rs["pWholesalePrice"]?>" /></td>
				<td align="left"><input type="checkbox" name="wholesalepercent<?php print $index?>" id="wholesalepercent<?php print $index?>" value="1" <?php if($rs["pbWholesalePercent"]!=0) print 'checked="checked" '?>/></td>
			  </tr>
<?php			$index++;
			}
			ect_free_result($result);
			for($index2=$index; $index2 < $maxpricebreaks; $index2++){ ?>
			  <tr>
				<td align="center" style="padding-right:15px"><input type="text" name="quant<?php print $index2?>" id="quant<?php print $index2?>" size="12" value="" /></td>
				<td align="center"><input type="text" name="price<?php print $index2?>" id="price<?php print $index2?>" size="12" value="" /></td>
				<td align="left" style="padding-right:5px"><input type="checkbox" name="wpercent<?php print $index2?>" id="wpercent<?php print $index2?>" value="1" /></td>
				<td align="center"><input type="text" name="wprice<?php print $index2?>" id="wprice<?php print $index2?>" size="12" value="" /></td>
				<td align="left"><input type="checkbox" name="wholesalepercent<?php print $index2?>" id="wholesalepercent<?php print $index2?>" value="1" /></td>
			  </tr>
<?php		} ?>
			  <tr>
                <td width="100%" colspan="5" align="center"><br /><input type="submit" value="<?php print $yySubmit?>" /></td>
			  </tr>
			  <tr> 
                <td width="100%" colspan="5" align="center"><br /><a href="admin.php"><strong><?php print $yyAdmHom?></strong></a><br />&nbsp;</td>
			  </tr>
            </table>
		  </form>
		  </td>
        </tr>
	  </table>
<?php
}elseif(getpost('posted')=="1" && $success){ ?>
		<table width="100%" border="0" cellspacing="0" cellpadding="3">
		  <tr> 
			<td width="100%" colspan="2" align="center"><br /><strong><?php print $yyUpdSuc?></strong><br /><br /><?php print $yyNowFrd?><br /><br />
					<?php print $yyNoAuto?> <a href="adminpricebreak.php"><strong><?php print $yyClkHer?></strong></a>.<br />
					<br />&nbsp;</td>
		  </tr>
		</table>
<?php
}elseif(getpost('posted')=="1"){ ?>
		<table width="100%" border="0" cellspacing="0" cellpadding="2">
		  <tr> 
			<td width="100%" colspan="2" align="center"><br /><span style="color:#FF0000;font-weight:bold"><?php print $yyOpFai?></span><br /><br /><?php print $errmsg?><br /><br />
			<a href="javascript:history.go(-1)"><strong><?php print $yyClkBac?></strong></a></td>
		  </tr>
		</table>
<?php
}else{
	$jscript='';
	$sortorder=@$_REQUEST['sort'];
	$modclone = @$_COOKIE['modclone']; ?>
<script>
<!--
function setCookie(c_name,value,expiredays){
	var exdate=new Date();
	exdate.setDate(exdate.getDate()+expiredays);
	document.cookie=c_name+ "=" +escape(value)+((expiredays==null) ? "" : ";expires="+exdate.toGMTString());
}
function mr(id){
	document.mainform.id.value=id;
	document.mainform.act.value="modify";
	document.mainform.submit();
}
function newrec(){
	document.mainform.act.value="addnew";
	document.mainform.submit();
}
function cr(id){
	document.mainform.id.value=id;
	document.mainform.act.value="clone";
	document.mainform.submit();
}
function dr(id){
if(confirm("<?php print jscheck($yyConDel)?>\n")){
	document.mainform.id.value=id;
	document.mainform.act.value="delete";
	document.mainform.submit();
}
}
function startsearch(){
	document.mainform.action="adminpricebreak.php";
	document.mainform.act.value="search";
	document.mainform.posted.value="";
	document.mainform.submit();
}
function changemodclone(modclone){
	setCookie('modclone',modclone[modclone.selectedIndex].value,600);
	startsearch();
}
// -->
</script>
<h2><?php print $yyAdmQua?></h2>
		  <form name="mainform" method="post" action="adminpricebreak.php">
			<input type="hidden" name="posted" value="1" />
			<input type="hidden" name="act" value="xxxxx" />
			<input type="hidden" name="id" value="xxxxx" />
			<input type="hidden" name="pg" value="<?php print (getpost('act')=='search' ? '1' : getget('pg'))?>" />
			<input type="hidden" name="selectedq" value="1" />
			<input type="hidden" name="newval" value="1" />
	<table class="cobtbl" width="100%" border="0" cellspacing="1" cellpadding="3">
	  <tr height="30"> 
		<td class="cobhl" width="25%" align="right"><?php print $yySrchFr?>:</td>
		<td class="cobll" width="25%"><input type="text" name="stext" size="20" value="<?php print @$_REQUEST['stext']?>" /></td>
		<td class="cobhl" width="25%" align="right"><?php print $yySrchTp?>:</td>
		<td class="cobll" width="25%"><select name="stype" size="1">
			<option value=""><?php print $yySrchAl?></option>
			<option value="any"<?php if(@$_REQUEST['stype']=="any") print ' selected="selected"'?>><?php print $yySrchAn?></option>
			<option value="exact"<?php if(@$_REQUEST['stype']=="exact") print ' selected="selected"'?>><?php print $yySrchEx?></option>
			</select>
		</td>
	  </tr>
	  <tr height="30">
		<td class="cobhl">&nbsp;</td>
		<td class="cobll" colspan="3" align="center">
				<select name="sort" size="1" style="vertical-align:middle">
				<option value="bid">Sort - Product ID</option>
				<option value="bna"<?php if($sortorder=='bna') print ' selected="selected"'?>>Sort - Product Name</option>
				</select>
				<input type="submit" value="List Quantity Discounts" onclick="startsearch();" />
				<input type="button" value="<?php print $yyNewPBK?>" onclick="newrec()" />
				<select name="ddown" size="1" style="vertical-align:middle"><option value="">Text Entry</option><option value="1"<?php if(@$_REQUEST['ddown']=="1") print ' selected="selected"'?>>Dropdown Menu</option></select>
	  </tr>
	</table>
<br />
            <table width="100%" class="stackable admin-table-a sta-white">
<?php
	if(getpost('act')=='search' || getget('pg')!=''){
		$hassearch=FALSE;
		$sSQL = '';
		$whereand=" WHERE ";
		if(getrequest('stext')!=''){
			$Xstext = escape_string(@$_REQUEST['stext']);
			$aText = explode(' ',$Xstext);
			$maxsearchindex=1;
			$aFields[0]='pbProdID';
			$aFields[1]='pName';
			if(@$_REQUEST['stype']=='exact'){
				$sSQL.=$whereand . "(pbProdID LIKE '%".$Xstext."%' OR pName LIKE '%".$Xstext."%') ";
				$whereand=" AND ";
			}else{
				$sJoin='AND ';
				if(@$_REQUEST['stype']=='any') $sJoin='OR ';
				$sSQL.=$whereand . '(';
				$whereand=' AND ';
				for($index=0;$index<=$maxsearchindex;$index++){
					$sSQL.='(';
					$rowcounter=0;
					$arrelms=count($aText);
					foreach($aText as $theopt){
						if(is_array($theopt))$theopt=$theopt[0];
						$sSQL.=$aFields[$index] . " LIKE '%" . $theopt . "%' ";
						if(++$rowcounter < $arrelms) $sSQL.=$sJoin;
					}
					$sSQL.=') ';
					if($index < $maxsearchindex) $sSQL.='OR ';
				}
				$sSQL.=') ';
			}
		}
		if($sortorder=='bna')
			$sSQL.=' ORDER BY pName';
		else
			$sSQL.=' ORDER BY pbProdID';
		if(! is_numeric(getget('pg')))
			$CurPage = 1;
		else
			$CurPage = (int)getget('pg');
		
		$tmpSQL = 'SELECT COUNT(DISTINCT pbProdID) AS bar FROM pricebreaks INNER JOIN products ON pricebreaks.pbProdID=products.pID' . $sSQL;
		$sSQL = "SELECT DISTINCT pbProdID,pName FROM pricebreaks INNER JOIN products ON pricebreaks.pbProdID=products.pID" . $sSQL;
		$sSQL.=" LIMIT " . ($maxbreaksperpage*($CurPage-1)) . ", $maxbreaksperpage";
		
		$result=ect_query($tmpSQL) or ect_error();
		$rs=ect_fetch_assoc($result);
		$numids = $rs['bar'];
		$iNumOfPages = ceil($numids/$maxbreaksperpage);
		ect_free_result($result);
		
		$result=ect_query($sSQL) or ect_error();
		if($numids > 0){
			$islooping=FALSE;
			$noproducts=FALSE;
			$hascatinprodsection=FALSE;
			$rowcounter=0;
			$bgcolor="";
			$pblink = '<a href="adminpricebreak.php?stext='.urlencode(@$_REQUEST['stext']).'&stype='.@$_REQUEST['stype'].'&ddown='.@$_REQUEST['ddown'].'&pg=';
			if($iNumOfPages > 1) print '<tr><td align="center" colspan="3">' . writepagebar($CurPage,$iNumOfPages,$yyPrev,$yyNext,$pblink,FALSE) . '<br /><br /></td></tr>';
?>			  <tr>
				<th class="maincell"><strong><?php print $yyPrId?></strong></th>
				<th class="maincell"><strong><?php print $yyPrName?></strong></th>
				<th class="minicell"><?php print $yyModify?></th>
			  </tr>
<?php		while($rs=ect_fetch_assoc($result)){
				$jscript.='pa['.$rowcounter.']=['; ?>
<tr id="tr<?php print $rowcounter?>">
<td class="maincell"><?php print $rs['pbProdID']?></td>
<td class="maincell"><?php print $rs['pName']?></td>
<td>-</td>
</tr><?php		$jscript.="'".$rs['pbProdID']."'];\r\n";
				$rowcounter++;
			}
			if($iNumOfPages > 1) print '<tr><td align="center" colspan="3"><br />' . writepagebar($CurPage,$iNumOfPages,$yyPrev,$yyNext,$pblink,FALSE) . '</td></tr>';
		}else{ ?>
			  <tr><td width="100%" colspan="3" align="center"><br /><?php print $yyItNone?><br />&nbsp;</td></tr>
<?php	}
		ect_free_result($result);
	}else{
		$numitems=0;
		$sSQL='SELECT COUNT(DISTINCT pbProdID) as totcount FROM pricebreaks';
		$result=ect_query($sSQL) or ect_error();
		if($rs=ect_fetch_assoc($result))
		$numitems=$rs['totcount'];
		print '<tr><td colspan="3"><div class="itemsdefine">You have ' . $numitems . ' quantity discounts defined.</div></td></tr>';
	} ?>
			  <tr> 
                <td colspan="3" align="center"><br /><a href="admin.php"><strong><?php print $yyAdmHom?></strong></a><br />&nbsp;</td>
			  </tr>
            </table>
		  </form>
<script>
/* <![CDATA[ */
var pa=[];
<?php print $jscript?>
for(var pidind in pa){
	var ttr=document.getElementById('tr'+pidind);
	ttr.cells[2].style.textAlign='center';
	ttr.cells[2].style.whiteSpace='nowrap';
	ttr.cells[2].innerHTML='<input type="button" value="M" style="width:30px;margin-right:4px" onclick="mr(\''+pa[pidind][0]+'\')" title="<?php print jsescape(htmlspecials($yyModify))?>" />' +
		'<input type="button" value="C" style="width:30px;margin-right:4px" onclick="cr(\''+pa[pidind][0]+'\')" title="<?php print jsescape(htmlspecials($yyClone))?>" />' +
		'<input type="button" value="X" style="width:30px" onclick="dr(\''+pa[pidind][0]+'\')" title="<?php print jsescape(htmlspecials($yyDelete))?>" />';
}
/* ]]> */
</script>
<?php
}
?>