
function setStatus(row, pos) {

	self.status = ptpPhotoTitles[currentOffset + row + pos];
	top.status = ptpPhotoTitles[currentOffset + row + pos];

}

imageStart = 0;
nullImage = null;
loaded = false;
function onLoadOps() {
	onLoadRange(0);
}


function onLoadRange(startRange) {
	//nothing to do when only a few images
	if (photoCount <= perRow * numRows) {
		loaded = true;
		return;
	}

	//first set imageStart 
	//be simplistic about figuring out which is starrting image
	//so it works in all browsers
	for (imageStart = 0; imageStart < document.images.length; 
			imageStart++) {
		if (document.images[imageStart].name == "Image1x1")
			break;
	}

	//then remember first set in imageCache
	//and null out rest
	offset = 0 - endOfLineOffset;
	for (i = 0; i < photoCount; i++) {
		if (i % perRow == 0)
			offset += endOfLineOffset;
		imageCache[i] = null;
		if (i < perRow * numRows) { 
			imageCache[i] = new Image();
			/*
			window.alert(document.images[imageStart + offset
					+ i * (1 + interImageGap)].name + " at is=" +
					imageStart + " of=" + offset + " i=" + i + " iig=" +
					interImageGap);
			*/
			imageCache[i].src = document.images[imageStart + offset
					+ i * (1 + interImageGap)].src;
		} 
	}

	//and load nullImage
	nullImage = new Image();
	nullImage.src = "/images/spacer.gif";

	loaded = true;
}

function placeImages() {

	offset = 0 - endOfLineOffset; //start here to handle initial case
	for (i = 0; i < perRow * numRows; i++) {
	
		//because there is an extra image at the end of each row
		if (i % perRow == 0)
			offset += endOfLineOffset;
		
		
		/*
		window.alert("eolo=" + endOfLineOffset + " co=" + currentOffset +
			"iC[]=" +imageCache[currentOffset + i] + '...' 
			+ i + ' o=' + offset);
		*/
	
		
		if (currentOffset + i >= photoCount) {
			document.images[imageStart + offset + i * (1 + interImageGap)].src =
					nullImage.src;
			continue;
		}
		
		if (imageCache[currentOffset + i] == null) {
			imageCache[currentOffset + i] = new Image();
			imageCache[currentOffset + i].src = image_progname
				+ '?size=' + size +'&amp;ptp_photo_id=' 
				+ ptpPhotoIds[currentOffset + i]
				+ '&amp;provider_id=' + providerID;
		}

		document.images[imageStart + offset + i * (1 + interImageGap)].src =
				imageCache[currentOffset + i].src;
		/*
		window.alert(document.images[imageStart + offset + i * (1 + interImageGap)].src);
		*/
	}
}

function setArrows() {

	for (i = 0; i < document.up_arrow.length; i++)
		if (currentOffset == 0)
				document.up_arrow[i].src = up_dis_arrow;
		else
			document.up_arrow[i].src = up_arrow;

	for (i = 0; i < document.down_arrow.length; i++)
		if (currentOffset + perRow * numRows >= photoCount)
			document.down_arrow[i].src = down_dis_arrow;
		else
			document.down_arrow[i].src = down_arrow;
}

function pageUp(galId) {

	if (currentOffset == 0)
		return;

	currentOffset -= perRow * numRows;
	if (currentOffset < 0)
		currentOffset = 0;

	//must be defined in each implementation
	goGalSeq(galId, currentOffset);
}

function moveUp() {

	if (!loaded)
		return;

	/*
	window.alert("moveUp called at " + currentOffset + 'pc=' +
			photoCount + 'pR=' + perRow + ' nR=' +numRows + " is=" + imageStart);
	*/
	
	if (currentOffset == 0)
		return;

	currentOffset -= perRow * numRows;
	if (currentOffset < 0)
		currentOffset = 0;

	setArrows();

	placeImages();

}

function pageDown(galId) {

	if (currentOffset + perRow * numRows >= photoCount)
		return;

	currentOffset += perRow * numRows;
	//must be defined in each implementation
	goGalSeq(galId, currentOffset);
}

function moveDown() {
	
	if (!loaded)
		return;

	/*
	window.alert("moveDown called at " + currentOffset + 'pc=' +
			photoCount + 'pR=' + perRow + ' nR=' +numRows + " is=" + imageStart);
		*/
	
	if (currentOffset + perRow * numRows >= photoCount)
		return;

	currentOffset += perRow * numRows;
	setArrows();
	placeImages();

}

DOM = (document.getElementById) ? true : false;
NS4 = (document.layers) ? true : false;
IE = (document.all) ? true : false;
IE4 = IE && !DOM;
function getHeight() {
	if(NS4) {
		winHeight = window.innerHeight;
		winWidth = window.innerWidth;
	} else {
		winHeight = document.body.clientHeight;
		winWidth = document.body.clientWidth;
	}
	return winHeight;
}

function goBuy(row, pos) {

	if (!loaded)
		return;

	if (currentOffset + row + pos >= photoCount)
		return;
	goBuyPhoto(ptpPhotoIds[currentOffset + row + pos]);
}

function goBuyPhoto(idnnnn) {
	f = document.buy_form;
	f.ptp_photo_id.value = idnnnn;
	goPtp(f);
}

function goBuyPhotoChoice(id, choiceId) {
	f = document.buy_choice_form;
	f.ptp_photo_id.value = id;
	f.choice_group_id.value = choiceId;
	goPtp(f);
}


ptpWindow = '';
function goPtp(f) {

	//if no daughter do it here directly
	if (typeof daughterWindow != "undefined" && daughterWindow == 'false') {
		//just submit directly
		f.submit();
		return;
	}

	tgt = 'ptp_' + providerID;
	//if (ptpWindow == '' || ptpWindow.closed) 
		ptpWindow = window.open('', tgt,
				'scrollbars=yes, resizable=yes, toolbar=no, '
				+ 'status=yes,width=760,height=600, menubar=no');
	f.target = tgt;
	f.date.value = new Date().getTime(); 
	f.submit();
	ptpWindow.focus();
}

function goDetailPhoto(f, id) {
	f.ptp_photo_id.value = id;
	f.submit();
}

function goDetails(f, x, y) {

	goDetailPhoto(f, ptpPhotoIds[x + y + currentOffset]);
}


// CHECK CLIENT BROWSER & PLATFORM
// Works: IE4+, NS4+, Opera

var its;
var browserName = '';
var browserNameLong = '';
var browserNew = '';
var Macintosh = navigator.userAgent.indexOf('Mac')>0;

function its() {
	var n = navigator;
	var ua = ' ' + n.userAgent.toLowerCase();
	var pl = n.platform.toLowerCase();
	var an = n.appName.toLowerCase();

	// browser version
	this.version = n.appVersion;
	this.nn = ua.indexOf('mozilla') > 0;

	// 'compatible' versions of mozilla aren't navigator
	if(ua.indexOf('compatible') > 0) {
		this.nn = false;
	}

	this.opera = ua.indexOf('opera') > 0;
	this.ie = ua.indexOf('msie') > 0;
	this.safari = ua.indexOf('safari') > 0;
	this.major = parseInt( this.version );
	this.minor = parseFloat( this.version );

	// platform
	this.mac = ua.indexOf('mac') > 0;
	this.win = ua.indexOf('win') > 0;

	// workaround for IE5 AND above which reports itself as version 4.0
	if(this.ie) {
		if(ua.match(/msie [0-9]/)) {
			var msieIndex = navigator.appVersion.indexOf("MSIE") + 5;
			this.major = parseFloat(navigator.appVersion.substr(msieIndex,3));
		}
	}

	return this;
}

function browserNaming() {
	its = new its();

	// is it a DOM-enabled browser?
	if (!document.getElementById) {
		browserNew = false;
	}
	else {
		browserNew = true;
	}

	// need the name, too
	if (its.opera) {
		browserName = "Opera";
	}else if (its.ie) {
		browserName = "IE";
	}else {
		browserName = "NS";
	}

	// and the number
	browserNameLong = browserName + its.major;
}

//call the browser detection at least once
browserNaming();


//some legacy things
isOldBrowser = !browserNew;
hasDocLayers = document.layers?1:document.all?1:0
hasGetElementById = browserNew;

//The Dreamweaver finding an object on a page function
function findObj(n, d) { 
  var p,i,x;  
  if(!d) d=document; 
  if((p=n.indexOf("?"))>0&&parent.frames.length) 
  {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);
  }
  if(!(x=d[n])&&d.all) 	x=d.all[n]; 
  
  for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=findObj(n,d.layers[i].document);
  
  if(!x && d.getElementById) 	x=d.getElementById(n); 
 
  return x;
}


//Sets the SOURCE of a layer
function load(target,src)
{
	var myobj=findObj(target);	
	window.top[target].location = src;		
	myobj.src = src;	
}
// DOM / GET PROPERTY
// Works: IE5+, NS6+, Opera
function getIdProperty(id,property) {
	var styleObject = typeof(id) == 'string' ? document.getElementById( id ) : id;
	if (styleObject != null) {
		styleObject = styleObject.style;
			if (styleObject[property]) {
				return styleObject[ property ];
			}
		}
	return (styleObject != null) ?
	styleObject[property] :
	null;
}


// DOM / SET PROPERTY
// Works: IE5+, NS6+, Opera
function setIdProperty(id,property,value) {
	var styleObject = typeof(id) == 'string' ? document.getElementById( id ) : id;
	if (styleObject != null) {
		styleObject = styleObject.style;
		styleObject[ property ] = value;
	}
}

// HIDE AND SHOW LAYERS

// Works: IE4+, NS4+, Opera
function hide(id) {
	if (browserNew) {
		setIdProperty(id,"visibility","hidden");
		setIdProperty(id,"display","none");
	}
	else {
		if (browserName == "NS") { document.layers[id].visibility = "hide"; }
		else { document.all[id].style.visibility = "hidden"; }
	}
}

function show(id) {
	if (browserNew) {
		setIdProperty(id,"visibility","visible");
		setIdProperty(id,"display","block");
	}
	else {
		if (browserName == "NS") { 
			document.layers[id].visibility = "show"; 
			document.layers[id].display = "block"; 
		} else {
			 document.all[id].style.visibility = "visible"; 
			 document.all[id].style.display = "block"; 
		}
	}
}

//sends out browser alert - 1 time; then sets cookie
function oldBrowserAlert() {
	var bad = !browserNew;
	if (!bad && Macintosh)  {
		bad = (navigator.userAgent.toLowerCase().indexOf('msie') != -1);
	}
	//alert('bad=' + bad + ' mac=' + Macintosh + ' ua=' + navigator.userAgent.toLowerCase() + ' u=' + navigator.userAgent.toLowerCase().indexOf('msie'));
	if (bad && ReadCookie("bt") == '') {
		//remember bad
		writeCookie("bt", "1");
		if (Macintosh) {
			alert(
				"We do not support the browser you are using; "
				+ "we suggest that you upgrade to another browser "
				+ "such as Firefox (http://www.firefox.com)."
				);
		} else {
			alert(
				"We do not support the browser you are using; "
				+ "we suggest that you upgrade to another browser "
				+ "such as Firefox (http://www.firefox.com) "
				+ "or Internet Explorer (http://www.microsoft.com/windows/ie/downloads/default.mspx)."
				);
		}
	}
}


// MOVE TO - SHORTHAND
function move(id,x,y,additive) {
  //values may have units attached (ALWAYS assume pixels!)
	var left = parseValue(getIdProperty(id, "left"));
	var top = parseValue(getIdProperty(id, "top"));

	if (additive) {
		setIdProperty(id,"left", (left.num + x) + left.units);
		setIdProperty(id,"top", (top.num + y) + top.units);
	} else {
		setIdProperty(id,"left",x + left.units);
		setIdProperty(id,"top",y + left.units);
	}
}

//breaks element into its numeric value and any units
function parseValue(v) {
  var ret = new Array();
	ret['num'] = parseFloat(v);
	if (isNaN(ret['num']))
		return;

	ret['units'] = v.replace(/^-?[\d\.]+/,'');
	return ret;
}

mailtoX = 100;
mailtoY  =100;
function setMailtoFriendEvent(e) {
	if(!e) e = window.event;
	
	if (e.clientX || e.clientY) {
		mailtoX = e.clientX+50;
		mailtoY = e.clientY-50;
	} else if (e.pageX || e.pageY) {
		mailtoX = e.pageX+50;
		mailtoY = e.pageY-50;
	}
}

function goMailToFriend() {
	show('mailtofriend');
	move('mailtofriend', mailtoX, mailtoY, 0);
	show('mailtofriend_f');
	//move('mailtofriend_f', mailtoX, mailtoY, 0);
	var f = document.mtofform;
	f.submit();
}

function hideMailToFriend() {
	hide('mailtofriend');
	hide('mailtofriend_f');
}

function goPopDeliver(tgt, p, w, h) {
	goPop(tgt, '/perl/gal?process=deliver&provider_id=' + providerID + '&page=' + p, w, h);
}

function goPop(tgt, url, w, h) {

	var params = 'scrollbars=yes,resizable=yes,toolbar=no,status=yes,menubar=no,width=' + w + ',height=' + h;
	var win = window.open(url, tgt, params);
	win.focus();
}

//prodArray element 0 = choice group
//	element 1 = 1 IF help text 0 otherwise
function getProdHelp(tgt, provider_id, product_id, prodArray, choice_group_id) {
	if ((product_id == 0 || product_id == '') 
			&& choice_group_id == '') {
		alert("For product information, please first select a product.");
		return;
	}
	var m_base = "/perl/product_des";
	var m_link ="?";

	if (prodArray != null) {
		if (prodArray[product_id] == null || !prodArray[product_id][1]) {
			alert("No description is available for selected product.");
			return;
		}
		choice_group_id = prodArray[product_id][0];
	}

	if(product_id && (product_id != '') && (product_id != 0))
		m_link += "product_id="+ product_id + '&';

	if(provider_id) 
		m_link += "provider_id="+ provider_id + '&';

	if(choice_group_id && choice_group_id != '') 
			m_link += "choice_group_id="+ choice_group_id + '&';
	goPop(tgt, m_base + m_link, 250, 300);

}


//check the country coide and nullify the state field if we should
function countryValue(form){
		if(form.country){
			var c = form.country;
			return c.options[c.selectedIndex].value;
		}
		return '';
	}
function stateValue(form){
	if(form.state){
		var c = form.state;
		return c.options[c.selectedIndex].value;
	}
	return '';
}
function treatState(form){
	var cc = countryValue(form)
	var st = form.state;
	if (!st)
		return;
	if (cc == 'US') {
		st.selectedIndex =1;
		st.disabled=false;
		return;
	} 
	if (cc == 'MX') {
		for (var i = 0; i < st.options.length; i++) {
			if (st.options[i].value != '' 
					&& st.options[i].text.search(/mexico:/i) != -1) {
				st.selectedIndex = i;
				break;
			}
		}
		st.disabled=false;
		return;
	} 
	if (cc == 'CA') {
		for (var i = 0; i < st.options.length; i++) {
			if (st.options[i].value != '' 
					&& st.options[i].text.search(/canada:/i) != -1) {
				st.selectedIndex = i;
				break;
			}
		}
		st.disabled=false;
		return;
	} 

	//if(cc != 'US' && cc != 'MX' && cc !='CA')
	st.selectedIndex = 0;
	st.disabled = true;
}

function changeState(form){
	var st = form.state;
	var ctyValue = null;
	if (st.options[st.selectedIndex].text.search(/canada/i) != -1) {
		if (st.options[st.selectedIndex].value == '') {
			alert("Please choose a specific province or territory in Canada.");
			st.focus();
			return;
		}
		ctyValue = 'CA';
	} else if (st.options[st.selectedIndex].text.search(/mexico/i) != -1 && st.options[st.selectedIndex].text.search(/new mexico/i) == -1) {
		if (st.options[st.selectedIndex].value == '') {
			alert("Please choose a specific state in Mexico.");
			st.focus();
			return;
		}
		ctyValue = 'MX';
	} else if (st.options[st.selectedIndex].value != '') {
		ctyValue = 'US';
	}
	if (ctyValue == null || !form.country)
		return;

	var cty = form.country;
	for (var i = 0; i < cty.options.length; i++) {
		if (cty.options[i].value == ctyValue) {
			cty.selectedIndex = i;
			break;
		}
	}
	return;
}


//show the little product descript popo up
function showProdHelp(product_id, provider_id, choice_group_id)
{
	var m_base = 'http://' + window.location.hostname + "/perl/product_des";
	var m_link ="?none=1";
	if(product_id) m_link += "&product_id="+ product_id;
	if(provider_id) m_link += "&provider_id="+ provider_id;
	if(choice_group_id) m_link += "&choice_group_id="+ choice_group_id;
	
	show('help_text');
	show('help_text_frame');
	move('help_text', 50, 50);
	load('help_text_frame', m_base+m_link);
}

function goFocus(wint)
{
	if (!wint || wint.closed ||wint == self) {
		window.blur();
		return;
	}
	try{
		wint.focus();	
	}catch(e){	
		window.blur();
	}
}

function goGalleries() {
	openerGo( (typeof(server) != 'undefined' ? server : '') 
		+ (typeof(galProgName) != 'undefined' ? galProgName : gal_progname)
		+ '?provider_id=' + providerID);
}

function openerGo(url) {
	//if no opener use self
	if (window.opener == null) {
		window.top.location = url;
		return;
	}

	window.opener.top.location = url;
	try{ window.opener.top.focus();}catch(e){ window.blur();	}
}


function subm(proc, isSecure) {
	f = document.logform;
	f.process.value = proc;
	re = new RegExp('[^/]*//[^/]*', '');
	if (isSecure) 
		f.action = f.action.replace(re, secureServer); 
	else
		f.action = f.action.replace(re, server);
	f.submit();
}

function goRefPage(page) {
	f = document.gorefpage;
	f.page.value = page;
	f.submit();
}


function goChoose(id) {
	f = document.go_choose;
	for (i = 0; i < f.elements.length; i++) {
		if (f.elements[i].name.search(/^choice/) != -1) {
			f.elements[i].name = 'choice_group_id';
			f.elements[i].value = id;
			break;
		}
	}
	f.submit();
}

function goChooseType(type) {
	f = document.go_choose;
	for (i = 0; i < f.elements.length; i++) {
		if (f.elements[i].name.search(/^choice/) != -1) {
			f.elements[i].name = 'choice_type';
			f.elements[i].value = type;
			break;
		}
	}
	f.submit();
}

//used in cart processing

cart_tainted = false;

function checkoutConfirm() {
	if (cart_tainted) {
		if (!confirm("To save your changes to the cart you must first Update Cart."
			+ "To discard your changes and checkout now, click OK."))
				return;
	}
	document.checkout.submit();
}

function altCheckoutConfirm() {
	if (!cart_tainted) {
		document.checkout.submit();
		return;
	}
	if (!confirm("You've changed the quantities in your cart!\n To update the cart click ok, to discard the changes click cancel.")) {
		document.cart_values.reset();
	} else {
		document.cart_values.submit();
	}
}

//used for credit_card
function set_cc_address() {
	f = document.ccInfo;
	lastName = "";
	firstName = "";
	state = ""; 
	country = "";
	for (i = 0; i < values.length; i++) {
		//remember name values
		if (values[i][0] == "last_name") {
			lastName = values[i][1];
			continue;
		}
		if (values[i][0] == "first_name") {
			firstName = values[i][1];
			continue;
		}
		if (values[i][0] == "state") state = values[i][1];
		if (values[i][0] == "country") country  = values[i][1];
		ref = eval("f." + values[i][0]);
		//indirect reference to an element
		if ((typeof ref) != "undefined") {
			if (ref.type.toLowerCase().indexOf("select") != -1) {
				//match select NOW we need to find it
				for (j = 0; j < ref.length; j++)
					ref.options[j].selected = (ref.options[j].value == values[i][1]);
			} else
				ref.value = values[i][1];
		}
	}
	//finish special case on name
	if ((typeof f.name) != "undefined")
		f.last_name.value = firstName + (firstName != "" ? " " : "") + lastName;
	//specail case on the state and US or mexico
	if(country == 'US'){
		ref  = f.state;
		for (j = 0; j < ref.length; j++){
		      if(ref.options[j].value == state){
                      	ref.options[j].selected = true;
			break;
		      }
		}
	}
}


couponX = 100;
couponY  =100;
function setCouponEvent(e) {
	if(!e) e = window.event;
	
	if (e.clientX || e.clientY) {
		couponX = e.clientX;
		couponY = e.clientY;
	} else if (e.pageX || e.pageY) {
		couponX = e.pageX;
		couponY = e.pageY;
	}
}

function goCoupon() {
	show('coupon_lay');
	move('coupon_lay', couponX, couponY, 0);
	document.gocoupon.parameter.focus();

}

function hideCoupon() {
	hide('coupon_lay');
}

function submitCoupon(){
	var f = document.gocoupon;
	f.submit();
	hideCoupon();
	
}

codename = "code";
function goActOnCoupon(c, p) {
	f = document.valid_coupon;
	f.criteria.value = c;
	f.parameter.value = p;
	f.submit();
	return false;
}

//for choice_group selection
//set a value

function modElText(val, c) {	

	modText('el1', val, c, elX['el1'], elY['el1']);
}

function modText( el, val, c, x, y) {

	if (browserNew) {
		document.getElementById(el).innerHTML = '';
		document.getElementById(el).innerHTML = val;
	} else if (browser == "IE") {
		document.all[el].innerHTML = val;
	} else if (browser == "NS") {
		document.layers[el].innerHTML = val;
		//this is NS4 ignore this case
		/*
		window.alert('modText on ' + el + ' v=' + val + ' c=' + c 
				+ ' x=' + x + ' y=' + y + ' s=' + (x+y));
		//setPos(el, x, y);
		layer = document.layers[el];
		layer.document.open();
		layer.document.write('<p class="' + c + '">' + val + '</p>');
		layer.document.close();
		*/
	}
}

var elX = new Array();
var elY = new Array();

function initElPos() {

	if (!hasDocLayers) 
		return;

	//ignore this case
	return;

	for (var i=0; i < document.anchors.length; i++) {
		inx = document.anchors[i].name.indexOf('_anchor');
		if (inx != -1) {
			nm = document.anchors[i].name.substring(0, inx);
		
			marker = document.anchors[nm + '_anchor'];
			elX[nm] = marker.x;
			elY[nm] = marker.y;

			setPos(nm, elX[nm], elY[nm]);
		}
	}

}

function setPos(el, x, y) {

	if (!hasDocLayers) 
		return;

	//ignore this case
	return;

	layer = document.layers[el];
	layer.pageX = x;
	layer.pageY = y;
}

function writeAnchor(anc) {
	document.write('<a name="' + anc + '"><img src="/images/spacer.gif"/></a>');
}



//HB hit bits
function hb_getCookieVal (offset) {  
	var endstr = document.cookie.indexOf (";", offset);  
	if (endstr == -1)    
	endstr = document.cookie.length;  
	return unescape(document.cookie.substring(offset, endstr));
}

function hb_GetCookie (name) {  
	var arg = name + "=";  
	var alen = arg.length;  
	var clen = document.cookie.length;  
	var i = 0;  
	while (i < clen) {    
		var j = i + alen;    
		if (document.cookie.substring(i, j) == arg)      
		return hb_getCookieVal (j);    
		i = document.cookie.indexOf(" ", i) + 1;    
		if (i == 0) break;   
	}  
	return null;
}
function hb_SetCookie (name, value) {  
	var argv = hb_SetCookie.arguments;  
	var argc = hb_SetCookie.arguments.length;  
	var expires = (argc > 2) ? argv[2] : null;  
	var path = (argc > 3) ? argv[3] : null;  
	var domain = (argc > 4) ? argv[4] : null;  
	var secure = (argc > 5) ? argv[5] : false;  
	document.cookie = name + "=" + escape (value) + 
	((expires == null) ? "" : ("; expires=" + expires.toGMTString())) + 
	"; path=" + (path == null ? "/" : path) + 
	((domain == null) ? "" : ("; domain=" + domain)) +    
	((secure == true) ? "; secure" : "");
}

function hb_genid(){
      var expdate = new Date();
      expdate.setTime (expdate.getTime() + (20*60*1000));  
      var hbid = "a" + (expdate.getTime());
      hbid = "a" + (Math.floor(hbid.substring(1,11) * Math.random()*200));
      return hbid.substring(1,11);
}

function hb_write(bits)
{
	if(!bits) return;
	var today = new Date();
	var expire = new Date();
	expire.setTime(today.getTime() + 3600000000*24);
	var hbid= hb_GetCookie('hbid');
	if(!hbid) hbid = hb_genid();
	hb_SetCookie('hbid', hbid, expire);
	var ref = "";
	if(document.referrer && document.referrer!=""){
		//see if ref is current domain and ignore if it is
		var loc = window.location.hostname.replace(/www\./,'');
		var reg = new RegExp('/'+loc+'/');
		if(!document.referrer.match(reg)){
			ref = escape(document.referrer);
		}
	}
	if(ref && ref != ""){
		bits['ref'] = ref;
	}
	var ptpRef = unescape(ref);
	if (location.href.match(/[\?\&]ref=/)) {
		ptpRef = location.href.replace(/.*[\?\&]ref=/, '');
		ptpRef = ptpRef.replace(/\&.*/,'');
		if(ptpRef) bits['ptp_ref'] = escape(ptpRef);
	}
	if(ptpRef && ptpRef != ""){
		//set if not there
		var cookedRef = hb_GetCookie ('ptp_ref_' + bits['provider_id']);
		if (cookedRef == null || cookedRef == '') {
			hb_SetCookie ('ptp_ref_' + bits['provider_id'], ptpRef);
		}
	}

	bits['hbid']=hbid;
	bits['r'] = today.getTime();
	var url = "/ptp/hb.gif?";
	for(k in bits) url += '&'+k+'='+bits[k];
	document.write('<div style="display:none"><img src="' + url +'" width="1" height="1" alt=" " /></div>');
}

//stick a few generic functions here
//(that were going to be used for centering e-mail a friend

//from http://www.howtocreate.co.uk/tutorials/index.php?tut=0&part=16
function getScrollXY() {
  var scrOfX = 0, scrOfY = 0;
	if( typeof( window.pageYOffset ) == 'number' ) {
		//Netscape compliant
		scrOfY = window.pageYOffset;
		scrOfX = window.pageXOffset;
	} else if( document.body 
			&& ( document.body.scrollLeft || document.body.scrollTop ) ) {
		//DOM compliant
		scrOfY = document.body.scrollTop;
		scrOfX = document.body.scrollLeft;
	} else if( document.documentElement &&
			( document.documentElement.scrollLeft 
		|| document.documentElement.scrollTop ) ) {
		//IE6 standards compliant mode
		scrOfY = document.documentElement.scrollTop;
		scrOfX = document.documentElement.scrollLeft;
	}
	var s = new Array();
	s['x'] = scrOfX;
	s['y'] = scrOfY;
	return s;
}

function winSize() {
  var myWidth = 0, myHeight = 0;
	if( typeof( window.innerWidth ) == 'number' ) {
		//Non-IE
		myWidth = window.innerWidth;
		myHeight = window.innerHeight;
	} else if( document.documentElement &&
			( document.documentElement.clientWidth 
			|| document.documentElement.clientHeight ) ) {
		//IE 6+ in 'standards compliant mode'
		myWidth = document.documentElement.clientWidth;
		myHeight = document.documentElement.clientHeight;
	} else if( document.body 
			&& ( document.body.clientWidth || document.body.clientHeight ) ) {
		//IE 4 compatible
		myWidth = document.body.clientWidth;
		myHeight = document.body.clientHeight;
	}
	var w = new Array();
	w['width'] = myWidth;
	w['height'] = myHeight;
	return w;
}

var ignoredRightClickObjects = new Array();
function rightClickWarning(e) {

	//get ie global event
	if (!e) 
		e = window.event;

	//check for netscape and right button 
	if (navigator.appName == "Netscape") {
		//only act on an image
		//if (HTMLImageElement.prototype.isPrototypeOf(e.target)) {
		if (e.target.tagName == 'IMG') {
			if (isOnList(ignoredRightClickObjects, e.target)) {
				return true;
			}
			if (e.type == 'contextmenu') {
				return false;
			} 
			//else button case
			if (e.type == 'mousedown' && e.button == 2) {
				alert(rightClickMessage);
				return false;
			}
		}
		return true;
	} 
	
	//in IE only get here on mouse
	if (navigator.appName == "Microsoft Internet Explorer"
				&& e.button == 2 && e.srcElement.tagName == 'IMG') {
		if (isOnList(ignoredRightClickObjects, e.target)) {
			return true;
		}
		//is there a better way than tagName???
		alert(unescape(rightClickMessage));
		e.cancelBubble = true;
		return false;
	}
}

//used for magnifier warning message
function popImgWarning(evt) {
	if (evt) {
		if (evt.type == 'contextmenu') {
			return stopEventPropagation(evt);
		}
		//else button case
		if (evt.type == 'mousedown' && evt.button == 2) {
			alert(unescape(popRightClickMessage));
			return stopEventPropagation(evt);
		}
		return true;
	}

	//in IE only get here on mouse
	if (window.event.button == 2) {
		alert(unescape(popRightClickMessage));
		return stopEventPropagation(evt);
	}
	return true;
}

function addIgnoredRightClickObject(obj) {
	if (!isOnList(ignoredRightClickObjects, obj)) 
		ignoredRightClickObjects.push(obj);
}

function isOnList(list, obj) {
	for (var i = 0 ; i < list.length; i++) {
		if (list[i] == obj)
			return true;
	}
	return false;
}



// Time & Date Script

// Instructions below

// currentdate(); Standard | currentdate('UK'); International
// currentdate('y'); | Year with copyright symbol
// currentdate('day'); | Current date w/o short day
// currentdate('date'); | Current date w short day
// currentdate('year'); | Year without copyright symbol
// currentdate('clock'); | Clock with current time
// currentdate('month_year'); | Month and Year

function currentdate(options) {
	var date = new Date();
	var hour = date.getHours();
	var min = date.getMinutes();
	var d = date.getDate();
	var day = date.getDay();
	var month = date.getMonth();
	var year = date.getFullYear();
	
	var months = new Array(12);
		months[0] = 'January';
		months[1] = 'February';
		months[2] = 'March';
		months[3] = 'April';
		months[4] = 'May';
		months[5] = 'June';
		months[6] = 'July';
		months[7] = 'August';
		months[8] = 'September';
		months[9] = 'October';
		months[10] = 'November';
		months[11] = 'December';
	
	var days = new Array(7);
		days[0] = 'Sunday';
		days[1] = 'Monday';
		days[2] = 'Tuesday';
		days[3] = 'Wednesday';
		days[4] = 'Thursday';
		days[5] = 'Friday';
		days[6] = 'Saturday';
	
	var shortdays = new Array(7);
		shortdays[0] = 'Sun';
		shortdays[1] = 'Mon';
		shortdays[2] = 'Tues';
		shortdays[3] = 'Wed';
		shortdays[4] = 'Thurs';
		shortdays[5] = 'Fri';
		shortdays[6] = 'Sat';
	
	var shortday = shortdays[day];
	var day = days[day];
	var m = months[month];
	
	if(options == "UK") {
		var currentdate = day + ', ' + d + ' ' + m + ' ' + year;
	} else if (options == "y") {
		var currentdate = '&copy ' + year;
	} else if (options == "year") {
		var currentdate = year;
	} else if (options == "clock") {
		if(hour > 12)	{
			hour = hour - 12;
			ampm = 'PM';
		} else {
		ampm = 'AM';
		}
		var currentdate = hour + ':' + min + ampm;
	} else if (options == "date") {
		var currentdate = shortday + ', ' + m + ' ' + d;
	} else if (options =="month_year") {
		var currentdate = m + ' ' + year;
    } else if (options =="day") {
		var currentdate = m + ' ' + d + ' ' + year;
	} else {
		var currentdate = day + ', ' + m + ' ' + d + ', ' + year;
	}
	document.write(currentdate);
}

function getEventTarget(e) {
	if(!e) e = window.event;
	var targ;
	if (e.target) 
		targ = e.target;
	else if (e.srcElement) 
		targ = e.srcElement;

	if (targ.nodeType == 3) // defeat Safari bug
		targ = targ.parentNode;
	return targ;
}

function stopEventPropagation(evt) {

	if (typeof(window.event) != 'undefined') {
		//IE global event case
		window.event.returnValue = false;
		window.event.cancelBubble = false;

	} else {
		evt.preventDefault();
		evt.stopPropagation();
	}
	return false;
}

//perform shallow clone 
function clone(obj) {
  var clonedObj = [];
	for (var key in obj) 
		clonedObj[key] = obj[key];
	return clonedObj;
}

function objToString(obj) {
	return objToStringDo(obj, []);
}

function objToStringDo(obj, list) {
	if (typeof(obj) == 'undefined') 	
		return 'undefined';

	if (typeof(obj) != 'object') 
		return obj;

	if (obj == null)
		return 'null';

	var m = '{';
	try {
		OUTER:
		for (var key in obj) {
			if (typeof(obj[key]) == 'function') 
				continue;
			//skip those we've seen before of the same key name
			if (typeof(obj[key]) == 'object') {
				for (var i = 0; i < list.length; i++) {
					if (list[i] == obj[key])
						continue OUTER;
				}
				list.push(obj[key]);
			}
			m += key + '=' + objToStringDo(obj[key], list) + '; ';
		}
	} catch (e) {
		m += 'UNREADABLE';
	}

	m += '}';
	return  m;
}

function gooby() {
	var d = document.getElementById('debugDiv');
	//nothing to do if nowhere to output
	if (typeof(d) == 'undefined' || d == null)
		return;
	
	for (var i = 0; i < arguments.length; i++)
		d.innerHTML += objToString(arguments[i]) 
				+ (typeof(arguments[i]) == 'object' ? '<br/>' : ' ');
}

function galert() {
	var s = '';	
	for (var i = 0; i < arguments.length; i++)
		s += objToString(arguments[i]) + "\n";
	alert(s);
}

//clean up pngs
//id points to div if ie and img otherwise
function needsPngDiv() {
	return its.ie;
	//return (navigator.userAgent.match(/msie/i));
}

function placePng(id, src, width, height) {

	if (needsPngDiv()) {
		if (height != null)
			setIdProperty(id, 'height', height);
		if (width != null)
			setIdProperty(id, 'width', width);
		setIdProperty(id, 'filter', 
			'progid:DXImageTransform.Microsoft.AlphaImageLoader(src=\''
			+ src
			+ '\', sizingMethod=\'scale\')');
		return;
	}

	var obj = typeof(id) == 'string' ? document.getElementById(id) : id;
	if (height != null)
		obj.height = height;
	if (height != null)
		obj.width = width;
	obj.src = src;
}

function delOption(sel, value) {
  //get rid of all options with matching value...as more work cause of FireFox
	var origLength = sel.options.length;
	var origSelectedIndex = sel.selectedIndex;
	var newSelectedIndex = sel.selectedIndex;
	var offset = 0;
	for (var i = 0; i < origLength; i++) {
		if (sel.options[i].value == value) {
			offset++;
		}
		if (offset == 0)
			continue;
		
		if (i == origLength - 1) {
			//end condition
			sel.options[i] == null;
			sel.options.length = origLength - 1;
			continue;
		}

		if (origSelectedIndex == i + offset)
			newSelectedIndex = i;
		
		sel.options[i] = new Option(
				sel.options[i + offset].text,
				sel.options[i + offset].value,
				false,
				(origSelectedIndex == i + offset));
	}
	//reset for whatever reason
	sel.selectedIndex = newSelectedIndex;
}

function selectOption(sel, value) {
	var found = false;
	for (var i = 0; i < sel.options.length; i++) {
		sel.options[i].selected = (sel.options[i].value == value);
		if (sel.options[i].value == value) {
			found = true;
			sel.options[i].selected = true;
		} else 
			sel.options[i].selected = false;
	}
	return found;
}

function setOptions(validValues, selected, noneOk, data, valueField, nameField, sel) {

	//reset all selections
	var opts = new Array();
	if (noneOk) {
		opts.push(new Option(
		'none',
		0,
		false, 
		(selected == null || selected == 0)));
	}

	for (var key in data) {
		var item = data[key];

		if (typeof(validValues[item[valueField]]) == 'undefined')
			continue;
		
		opts.push(new Option(
			item[nameField],
			item[valueField], 
			false, 
			(item[valueField] == selected)));
	}
	//replace options as necessary (keeping order!)
	sel.options.length = 0;
	for (var i = 0; i < opts.length; i++) {
		sel.options[i] = opts[i];
	}
}




