<!-- 
// function to set a cookie
function setCookie (name, value, expires) {
	if (expires == '') document.cookie = name + "=" + escape (value) + "; path=/";
	else document.cookie = name + "=" + escape (value) + "; expires=" + expires.toGMTString() +  "; path=/";
	return null;
}

// function to retrieve a cookie
function getCookie (cookiename) {
	dcookie = document.cookie; 
	cname = cookiename + "=";
	clen = dcookie.length;
	cbegin = 0;
	while (cbegin < clen) {
		vbegin = cbegin + cname.length;
		if (dcookie.substring(cbegin, vbegin) == cname) { 
			vend = dcookie.indexOf (";", vbegin);
			if (vend == -1) vend = clen;
			return unescape(dcookie.substring(vbegin, vend));
		}
		cbegin = dcookie.indexOf(" ", cbegin) + 1;
		if (cbegin == 0) break;
	}
	return null;
}

// function to delete a cookie
function deleteCookie (cookiename, newlocation) {
	expireNow = new Date();
	document.cookie = cookiename + "=" + "; expires=Thu, 01-Jan-70 00:00:01 GMT" +  "; path=/";
	savedAdsCount("savedads");
	location.href=newlocation;
}


// function to check the checkbox status of the item just clicked
// and set or clear the adnumber from the cookie data
function boxclick(itemnumber, adnumber) {
	// see if we have an elements array
	if (document.mainform.ads.length>0) {
		// we do, so get the checked status of the proper item in the array
		checkstatus = document.mainform.ads[itemnumber].checked;
	}
	else {
		// we don't, so get the checked status of the single item
		checkstatus = document.mainform.ads.checked;
	}
	
	// get the cookie data
	savedads = getCookie("savedads");
	
	// if the box was just checked
	if (checkstatus) {
		// if we have cookie data
		if (savedads != null) {
			if (savedads.length > 0) {
				// see if the ad number we are saving is already in the cookie
				// if it isn't already there, add it to the cookie
				if (savedads.indexOf(adnumber) < 0) setCookie("savedads", savedads + ":" + adnumber, expdate);
			}
			else {
				setCookie("savedads", adnumber, expdate);
			}
		}
		// we don't have any cookie data
		else {
			// add the saved ad into the cookie
			setCookie("savedads", adnumber, expdate);
		}
	}
	// if the box was just UNchecked
	else {
		// if we have cookie data
		if (savedads != null) {
			// loop through the saved ads string in the cookie data
			for (i=0; i<savedads.length; i++) {
				// if we found the adnumber in the cookie data
				if (savedads.substring(i,i+adnumber.length) == adnumber) {
					// if it is in the first position
					if (i==0) {
						// if it isn't the only ad
						if (savedads.length > adnumber.length) {
							// remove the adnumber from the cookie data
							savedads = savedads.substring(adnumber.length+1,savedads.length);
						}
						// if it is the only ad
						else {
							// just make the cookie data empty
							savedads = "";
						}
					}
					// if it isn't in the first position
					else {
						// remove the adnumber from the cookie data
						savedads = savedads.substring(0,i-1)+savedads.substring(i+adnumber.length,savedads.length);
					}
				// set the cookie and break out of the loop
				setCookie("savedads", savedads, expdate);
				break;
				}
			}
		}
	}
	// update the saved ads counter
	savedAdsCount("savedads");
	
	return null;
}

// function to count saved ads, and update the text box with the adcount
function savedAdsCount (cookiename) {
	// get the cookie data
	savedads = getCookie(cookiename);
	
	// if we have cookie data
	if (savedads != null) {
		
		if (savedads.length > 0) {
			// see if there is a colon within the saved ads - indicates multiple ads
			if (savedads.indexOf(":") >= 0) {
				// split them into an array
				adsarray = savedads.split(":");
				// find the length of the array
				savedadscount = adsarray.length;
			}
			// there is only one ad
			else savedadscount = 1;
		}
		else savedadscount = 0;
	}
	// there are no ads
	else savedadscount = 0;
	// update the text box
	document.mainform.sdisplay.value = savedadscount;
	// return the adcount
	return savedadscount;
}



// init function when page loads
function init() {
	// update the saved ads counter
	savedAdsCount('savedads');
}
// -->
