function writeLine(x, y, prg, size, provId, buyLink) {
	

	if (currentOffset + x + y - 2 >= photoCount) {
		document.write('<tr><td>');
		document.write('<img name="Image' + x + 'x'+ y 
				+ '" border="0" src="/images/spacer.gif" />');
		document.write('</td></tr>');
		return;
	}
	
	pfx = size <= 128 ? '' : '_175';
	bord = size <= 128 ? 10 : 14;
	
	document.write('<tr>'
			+ '<td align="center" valign="bottom">');


	if (IE) 
		document.write('<a onclick="' + buyLink + '" onmouseover="setStatus('
				+ (x - 1) + ',' + (y - 1) + ');">');
	else
		document.write('<a href="' + buyLink + '" onmouseover="setStatus('
				+ (x - 1) + ',' + (y - 1) + ');">');

	url = prg + '?size=' + size + '_art&ptp_photo_id=' 
			+ ptpPhotoIds[x - 1 + y - 1 + currentOffset]
			+ '&provider_id=' + provId;

	document.write('<table border="0" cellspacing="0" cellpadding="0">'
			+ '<tr>'
			+ '<td valign="bottom" align="right"><img src="' + url 
			+ '" border="0" /></td>'
			+ '<td valign="bottom" align="left" style="background-image: url(/ptp/gal/img/sh_r' + pfx + '.gif);"><img src="/images/spacer.gif" alt="" width="' + bord
			+ '"  border="0" /></td>'
			+ '</tr><tr>'
			+ '<td valign="top" style="background-image: url(/ptp/gal/img/sh_b' + pfx + '.gif);"><img src="/images/spacer.gif" alt="" width="1" height="' + bord
			+ '" border="0" /></td>'
			+ '<td valign="top" align="left" style="background-image: url(/ptp/gal/img/sh_br' + pfx + '.gif);"><img src="/images/spacer.gif" alt="" width="' + bord
			+ '" height="' + bord + '" border="0" /></td>'
			+ '</tr></table>');

	document.write('</a></td></tr>');
	
	//31 is a magic number to equal area of title and link
	document.write('<tr>'
			+ '<td>' 
			+ '<img src="/images/spacer.gif" width="1" height="31" />'
			+ '</td>'
			+ '<td class="content" align="center" '
			+ 'valign="top"><font size="-1">'
			+ '<img src="/images/spacer.gif" align="left" width="1" height="31"/>'
			+ ptpPhotoTitles[x - 1 + y - 1 + currentOffset]
			+ '<br clear="all"/>');
	document.write('<a href="javascript:'
			+ buyLink + '">View details</a></font></td></tr>');

	document.write('<tr><td colspan="2"><hr width="90%" size="1" /></td></tr>');
}

function unshadowedWriteLine(x, y, prg, size, provId, buyLink) {

	if (currentOffset + x + y - 2 >= photoCount) {
		document.write('<tr><td rowspan="3">');
		document.write('<img name="Image' + x + 'x'+ y 
				+ '" border="0" src="/images/spacer.gif" />');
		document.write('</td></tr>');
		return;
	}

	document.write('<tr><td>');

	if (IE) 
		document.write('<a onclick="' + buyLink + '" onmouseover="setStatus('
				+ (x - 1) + ',' + (y - 1) + ');">');
	else
		document.write('<a href="' + buyLink + '" onmouseover="setStatus('
				+ (x - 1) + ',' + (y - 1) + ');">');

	document.write('<img name="Image' + x + 'x'+ y + '" border="0" src="'
			+ prg + '?size=' + size + '&ptp_photo_id=' 
			+ ptpPhotoIds[x - 1 + y - 1 + currentOffset]
			+ '&provider_id=' + provId + '" width="' + size +
			'" height="' + size + '" />');

	document.write('</a></td></tr>');
	document.write('<tr><td class="content" align="center" '
			+ 'valign="top" width="175"><font size="-1">'
			+ ptpPhotoTitles[x - 1 + y - 1 + currentOffset]
			+ '<br clear="all"/>');
	document.write('<a class="galname_link" href="javascript:'
			+ buyLink + '">View details</a></font></td></tr>');

	document.write('<tr><td><hr size="1" /></td></tr>');
}

function photoTurner(formName, pId) {
	itemTurner(formName, pId, 'pho', 'img');
}

function itemTurner(formName, pId, gifP, type) {

	//normalize id
	while(pId.indexOf(":") > 0) {
		pId=pId.substr(pId.indexOf(":")+1, pId.length);
	}
	
	//figure out where on the list
	for (i = 0; i < ptpPhotoIds.length; i++) {
		var str = ptpPhotoIds[i];
		while(str.indexOf(":") > 0) {
			str=str.substr(str.indexOf(":")+1, str.length);
		}
		if (str == pId)
			break;
	}

	document.write('<table><tr><td align="left">');

	if (type == 'img') {
	
		if (i == 0 || i == ptpPhotoIds.length) 
			document.write('<img src="/ptp/gal/img/pv' + gifP + '-dead.gif">');
		else
			itemGo(formName, ptpPhotoIds[i - 1], 'pv' + gifP);
		
		document.write('</td>'
				+ '<td><img src="/images/spacer.gif" width="15" height="1"/></td>'
				+ '<td align="right">');

		if (i + 1 >= ptpPhotoIds.length) 
			document.write('<img src="/ptp/gal/img/nx' + gifP + '-dead.gif">');
		else
			itemGo(formName, ptpPhotoIds[i + 1], 'nx' + gifP);
	} else { //text
			itemGoText(formName, ptpPhotoIds[i - 1], gifP[0]);
			document.write(gifP[1]);
			itemGoText(formName, ptpPhotoIds[i - 1], gifP[2]);
	}
	
	document.write('</td></tr></table>');

}

function itemGo(formName, pId, pic) {
	itemGoText(
			formName,
			pId, 
			'<img src="/ptp/gal/img/' + pic + '-link.gif" border="0"'
			+ 'onmouseover="this.src='
			+ "'/ptp/gal/img/" + pic + "-hover.gif';\" "
			+ ' onclick="this.src=' + "'/ptp/gal/img/" + pic + "-act.gif';\" "
			+ ' onmouseout="this.src=' 
			+ "'/ptp/gal/img/" + pic + "-link.gif';\" />"
			);
}

function itemGoText(formName, pId, txt) {
	document.write(
			'<a href="javascript:goDetailPhoto(' + formName
			+ ",'" +  pId  + "');" + '">'
			+ txt
			+ '</a>');
}

function borderedThumbnail(thisId, selectedId, imgSrc) {

	sty = 'border: solid 5px '  
			+ (thisId != selectedId ? 'rgb(255,255,255)' : 'rgb(255,204,102)')
			+ ';';
		
	if (thisId != selectedId) 
		document.write('<a href="javascript:goDetailPhoto(document.detail_form,'
				+ thisId + ');" >');

	document.write('<img src="' + imgSrc + '" ' 
			+ 'style="' + sty + '" />');

	if (thisId != selectedId) 
		document.write('</a>');
}

//for movement in horizlinks
function goGalElem(pos) {

	//window.alert(pos + " gllp=" + galListLeftPos);
	//may get here with nothing to do
	if (pos + galListLeftPos> galElem.length) 
		return;

	galleryId = galElem[galListLeftPos + pos - 1][1];
	goGallery(galleryId);
}

function goGalListNext() {
	//nothing to do if no more
	if (galListLeftPos + maxListPerRow > galElem.length)
		return;

	//else move over
	setGalListStart(galListLeftPos + maxListPerRow);
}

function goGalListPrev() {
	//nothing to do if at start
	if (galListLeftPos == 0)
		return;

	//else move over
	newStart = galListLeftPos - maxListPerRow < 0 ? 
			0 : galListLeftPos - maxListPerRow;
	setGalListStart(newStart);
}

function setGalListStart(start) {

	galListLeftPos = start;

		//window.alert("s=" + start + " gel=" + galElem.length + " mlpr=" + maxListPerRow);
	//set leftlink
	document.images["horizlinks_left"].src = start != 0 ?
			"/ptp/gal/img/prevgal.gif" : "/images/spacer.gif";

	//set middle values
	for (i = 0; i < maxListPerRow; i++) {
		txt = start + i < galElem.length ?
				galElem[start + i][0] : "";
		//should test for new browser here!
		/*
		document.getElementById("horiz_" + (i + 1)).class = 
				start + i == thisGalleryPos ? "hnavbg1s" : "hnavbg";
		document.getElementById("horizlink_" + (i + 1)).class = 
				start + i == thisGalleryPos ? "hnav1s" : "hnav1";
		*/
		document.getElementById("horizlink_" + (i + 1)).innerHTML = txt;
	}

	//set rightlink
	document.images["horizlinks_right"].src = 
			start + maxListPerRow < galElem.length ?
			"/ptp/gal/img/nextgal.gif" : "/images/spacer.gif";
}
				
		
		
function goSelectedGallery(selectEl) {
	var galleryId = selectEl.options[selectEl.selectedIndex].value;
	if (galleryId != '' && galleryId != 0)
		goGallery(galleryId);
}
	
function hotlinkSeq(ptpPhotoId, seq) {
	var f = document.detail_form;
	f.ptp_photo_id.value= ptpPhotoId;
	f.sequencenum.value= seq;
	f.page.value = '';
	f.submit();
}

function hotlinkPageSeq(ptpPhotoId, seq, page) {
	var f = document.detail_form;
	f.ptp_photo_id.value= ptpPhotoId;
	f.sequencenum.value= seq;
	f.page.value = page;
	f.submit();
}

function hotlink(ptpPhotoId) {
	hotlinkWithPage(ptpPhotoId, '');
}

function hotlinkWithPage(ptpPhotoId, page) {
	var f = document.detail_form;
	f.ptp_photo_id.value= ptpPhotoId;
	if (typeof(f.page) != 'undefined')
		f.page.value = page;
	f.submit();
}

function goBuyChoice(id, type) {
	var f = document.choice_form;
	f.ptp_photo_id.value = id;
	f.choice_type.value = type;
	f.submit();
}

function addProdToCart(prodField, qty) {

	val = prodField.options[prodField.selectedIndex].value;
	if (val == 0) {
		window.alert("Please select a product");
		return;
	}
	addProd(val, qty);
}

function addProd(val, qty) {
	var f = document.add_form;
	var i = 0;
	for (i = 0; i < f.elements.length; i++) {
		if (f.elements[i].name.search(/qty_/) == 0) { 
			break;
		}
	}
	//just set in first in odd case of not finding it
	if (i == f.elements.length) 
		i = 0;

	//correct qty name (use temp variable cause of netscape 6)
	var el = f.elements[i];
	el.name = "qty_" + val;
	el.value = qty;
	f.submit();
}

function addToCartInhouse(qty) {
	var f = document.add_form;
	for (var i = 0; i < f.elements.length; i++) {
		if (f.elements[i].name.search(/qty_/) == 0) {
			break;
		}
	}
	//just set in first in odd case of not finding it
	if (i == f.elements.length) 
		i = 0;

	var el = f.elements[i];
	el.value = qty;

	f.submit();
}

