function clearList(){
	if(queryString('go')==0){
		delete_cookie('specialsInterestList');
		document.getElementById("listContents").innerHTML = '<div style="margin-top:30px; text-align:center; font-size:12px; color:red; font-weight:900">Your inquiry has been received.  <br />Thank you.</div>'; //no specials picked - clear box.

	}
	else
	{
		paintList();	
	}
	
}

function changePage(thisPage){
	location.href="specials.asp?np=" + thisPage;
}

function addSpecialToList(recID, desc, price, itemNo){
	//alert(price);
	var qtybox='qty' + recID;
	qtybox = document.getElementById(qtybox).value;
	if(qtybox==''){
		qtybox = 1;
		}
	if(readCookie('specialsInterestList')){
		//==== check cookie to see if product has already been added:
		var str = readCookie('specialsInterestList');
		var dupeID = checkForDupe(recID, str);
		
		if(dupeID != 1){ //check to see if id is already in cookie.
			var collectedIDs = 	readCookie('specialsInterestList')
			//alert(collectedIDs);
			collectedIDs += '|' + recID + '~' + desc + '~' + price + '~' + qtybox  + '~' + itemNo;
			createCookie('specialsInterestList', collectedIDs)
		}
	}
	else
	{
		var xrecID = recID;
		createCookie('specialsInterestList', recID + '~' + desc + '~' + price + '~' + qtybox  + '~' + itemNo)
	}
	paintList();
}
function checkForDupe(recID, str){
	var hrs=0;
	var hgc='';
	var hOut = '';	
	var xinList = '';
	var dupeID = 0;
	
	var hStats = new Array();
	hStats = str.split( "|" ); 
	for (h2q=0; h2q<hStats.length; h2q++){
	if (hStats[h2q]!=''){		
		hStrq=hStats[h2q];
		hStrq=hStrq.replace(/^\s+|\s+$/g, '') ;
		hStatsRowq = hStrq.split( "~" );
		
		if(hStatsRowq[0] == recID){ //check for cookies existance.
			dupeID = 1;
		}
	  }	
	}
		return dupeID;
}

function paintList(){
	
	
	
	if(readCookie('specialsInterestList')){ //make sure stoopid cookie exists.
		var str = readCookie('specialsInterestList');
		var orgProduct='';
		var hrs=0;
		var hgc='';
		var hOut = '';	
		var xinList = '';
		var hStats = new Array();
		
		hStats = str.split( "|" ); 
		for (h2y=0; h2y<hStats.length; h2y++){ 
			if (hStats[h2y]!=''){		
				hStry=hStats[h2y];
				hStry=hStry.replace(/^\s+|\s+$/g, '') ;
				hStatsRowy = hStry.split( "~" );
				orgProduct='tr' + hStatsRowy[0];
				if(document.getElementById(orgProduct)){document.getElementById(orgProduct).style.backgroundImage = "url(../images/specialsAddedBG.gif)"}; //update product on page as added.
				if(document.getElementById('qty' + hStatsRowy[0])){document.getElementById('qty' + hStatsRowy[0]).disabled=true};
				if(document.getElementById('qty' + hStatsRowy[0])){document.getElementById('qty' + hStatsRowy[0]).style.backgroundColor='#cbcbcb'};
				if(h2y==0){hOut = hOut + '<tr><td><div class="fpbtmhr" style="width:220px"></div></td></tr>'}
				hOut += '<tr><td width="260" class="listContents"><div id="dataLinks"><div id="' + hStatsRowy[1]  + '" ' + xinList + '>' + Left(hStatsRowy[1], 60) + '</div></div></td><tr>'
				hOut += '<tr><td nowrap class="listContents"><div style="float:left; width:50px">QTY: ' +  hStatsRowy[3] + '</div>'
				hOut += '<div class="listBtns">[<a href="javascript:void(0)" onclick="removeFromList(' + hStatsRowy[0] +')">Remove</a>]'
				hOut += ' [<a href="javascript:void(0)" onclick="editListItem(' + hStatsRowy[0] +',\'' + hStatsRowy[1] + '\',' + hStatsRowy[3] + ',event)">Edit</a>]</div></td></tr>'
				if(h2y>=0 && h2y < hStats.length-2){hOut = hOut + '<tr><td><div class="fpbtmhr" style="width:260px; margin:0"></div><div class="fpbtmhr" style="width:260px"></div></td></tr>'}
				if(h2y == hStats.length-2){hOut = hOut + '<tr><td><div class="fpbtmhr" style="width:220px"></div></td></tr>'}
			}
		}
		hhOuty = '<table  cellpadding="0" cellspacing="0">' + hOut + '</table>';
		document.getElementById("listContents").innerHTML = hhOuty;
		document.getElementById("frmList").value = readCookie('specialsInterestList');
	}
	else
	{
		document.getElementById("listContents").innerHTML = '<div style="margin-top:30px; text-align:center; font-size:10px; color:#aaaaaa">Your list is empty ...</div>'; //no specials picked - clear box.
	}
}
function editListItem(id, desc, qty, e) {
	document.getElementById("specialsEdit").style.display = 'block';
	detectMouseCoordinates(e)
	var fposx = parseInt(posx) - parseInt(140);
	var fposy = parseInt(posy) + parseInt(-40);
	document.getElementById("specialsEdit").style.left = fposx + 'px';
	document.getElementById("specialsEdit").style.top = fposy + 'px';
	var str = '<table><tr><td><span style="font-weight:900">' + desc + '</span></td></tr>';
	str += '<tr><td><div style="width:55px; padding-top:5px; float:left; color:#255788; font-weight:900">Quantity: </div><div style="width:40px; float:left"><input class="inputQTY" id="qtyEdit"  type="text" maxlength="4" value="' + qty + '" /></div>';
	str += '<div style="margin-top:2px;  float:left" onclick="updateSpecial(' + id + ')" class="btnUpdate"><a href="javascript:void(0)"><img src="../images/trans.gif" width="65" height="30" border="0" /></a></td></tr>'
	str += '</table>';
	document.getElementById("specialsEdit").innerHTML = str;
}
function updateSpecial(id){
	var newqty = document.getElementById("qtyEdit").value;
	if (newqty=='' || newqty==0){
		alert('The quantity value must be at least 1.  If you wish to remove \rthis item from your list,  click the Update button and then click Remove.');
		document.getElementById("qtyEdit").value = 1;
		newqty=1;
		}
	//--- update qty value in array:
		var str = readCookie('specialsInterestList');
		var orgProduct='';
		var hrs=0;
		var newStr='';
		var hOut = '';	
		var xinList = '';
		var hStats = new Array();
		hStats = str.split( "|" ); 
		for (h2y=0; h2y<hStats.length; h2y++){
			if (hStats[h2y]!=''){		
				hStry=hStats[h2y];
				hStry=hStry.replace(/^\s+|\s+$/g, '') ;
				hStatsRowy = hStry.split( "~" );
				if(hStatsRowy[0]==id){
					//update qty value.
					newStr = newStr + hStatsRowy[0] + '~' + hStatsRowy[1] + '~' + hStatsRowy[2] + '~' + newqty + '~' + hStatsRowy[4] + '|';
				}
				else
				{
					newStr = newStr + hStats[h2y] + '|';
				}
			}
		}
		createCookie('specialsInterestList', newStr)
	paintList();
	document.getElementById("specialsEdit").innerHTML = '';
	document.getElementById("specialsEdit").style.display = 'none';
}

function removeFromList(id){
	if(document.getElementById("tr" + id)){document.getElementById("tr" + id).style.backgroundImage = ''};
	if(readCookie('specialsInterestList')){	
	var str = readCookie('specialsInterestList');
		var orgProduct='';
		var hrs=0;
		var newStr='';
		var hOut = '';	
		var xinList = '';
		var hStats = new Array();
		hStats = str.split( "|" ); 
		for (h2y=0; h2y<hStats.length; h2y++){
			if (hStats[h2y]!=''){		
				hStry=hStats[h2y];
				hStry=hStry.replace(/^\s+|\s+$/g, '') ;
				hStatsRowy = hStry.split( "~" );
				if(hStatsRowy[0]==id){
					//this is the rec to remove - do nothing.
				}
				else
				{
					newStr = newStr + hStats[h2y] + '|';
				}
			}
		}

	}
	newStr = Left(newStr, newStr.length-1);
	if(newStr==''){
		delete_cookie('specialsInterestList');
	}
	else
	{
		createCookie('specialsInterestList', newStr)
	}
	//alert(newStr);
	if(document.getElementById('qty' + id)){document.getElementById('qty' + id).disabled=false};
	if(document.getElementById('qty' + id)){document.getElementById('qty' + id).style.backgroundColor='#fff'};
	if(document.getElementById('btnAdd' + id)){document.getElementById('btnAdd' + id).style.background = 'url(../images/btnAdd.gif)'};
	paintList();
}

function PageQuery(q) {
if(q.length > 1) this.q = q.substring(1, q.length);
else this.q = null;
	this.keyValuePairs = new Array();
	if(q) {
	for(var i=0; i < this.q.split("&").length; i++) {
	this.keyValuePairs[i] = this.q.split("&")[i];
}
}
this.getKeyValuePairs = function() { return this.keyValuePairs; }
this.getValue = function(s) {
for(var j=0; j < this.keyValuePairs.length; j++) {
if(this.keyValuePairs[j].split("=")[0] == s)
return this.keyValuePairs[j].split("=")[1];
}
return false;
}
this.getParameters = function() {
var a = new Array(this.getLength());
for(var j=0; j < this.keyValuePairs.length; j++) {
a[j] = this.keyValuePairs[j].split("=")[0];
}
return a;
}
this.getLength = function() { return this.keyValuePairs.length; } 
}

function queryString(key){
var page = new PageQuery(window.location.search); 
return unescape(page.getValue(key)); 
}
function displayItem(key){
if(queryString(key)=='false') 
{
document.write("you didn't enter a ?name=value querystring item.");
}else{
document.write(queryString(key));
}
}