
function init()
{
	$$('.SEO').each(Element.hide);
}

function doPopupNamed(name, url, width, height)
{
	var popup = window.open(url, name, "resizable=1, scrollbars=1, status=0, toolbar=0, location=0, menubar=0, directories=0, width=" + width + ", height=" + height);
	popup.focus();
}


var imageIsOpen = false;
function doImagePopup(img_name_base, id, doSOTW)
{
        if (imageIsOpen) {
                return;
        } else {
                imageIsOpen = true;
        }

        var imageDiv = document.createElement('div');
        var main = document.getElementById(containerNameMain);
        main.appendChild(imageDiv);

	var altText = '';
	if (doSOTW) {

		Event.observe(imageDiv, 'click', function(event) {

			showVote(event, id);
		});

		imageDiv.style.cursor = 'hand';
		altText = 'Vote for me!';

	} else {

		altText = '';
	}

        imageDiv.style.display = 'block';
        imageDiv.style.zIndex = 100;
        imageDiv.style.backgroundColor = '#ffffff';
        imageDiv.style.borderWidth = '2px';
        imageDiv.style.borderStyle = 'solid';
        imageDiv.style.borderColor = '000000';
        imageDiv.style.padding= '10px';

        imageDiv.innerHTML = '<center><img id="popupImage" src="" alt="' + altText + '"/></center>';
        imageDiv.innerHTML += '<div style="text-align:right;"><a id="closeImage" href="javascript:void(0)" style="color:#000000; font-weight:bold;">Close X</a></div>';

	$('popupImage').src = eval('featureImage_' + img_name_base + '.src');

        $('closeImage').observe('click', function(e) {

                if (imageDiv) {
                        $(imageDiv).remove();
                }
		Event.stop(e);
                imageIsOpen = false;

        });

        if ($('popupImage').getWidth() > 774) {

                $('popupImage').style.width = '774px';
	} 


        imageDiv.style.width = ($('popupImage').getWidth() + 20) + 'px';

        var offsetsMain = $(containerNameMain).cumulativeOffset();
	if (parseInt(navigator.appVersion) > 3) {

		if (navigator.appName=="Netscape") {

			imageDiv.style.position  = 'fixed';
			imageDiv.style.top = 10;

		}
		if (navigator.appName.indexOf("Microsoft") != -1) {

			imageDiv.style.position  = 'absolute';

			var offsetsOrigin = $('imageContainer_' + id).cumulativeOffset();
			imageDiv.style.top = offsetsOrigin['top'] - ($('popupImage').getHeight()/2);

		}
	}

        var center = offsetsMain['left'] + 388;
	var popupImageWidth = $('popupImage').getWidth();
	//alert('popup image width =' + popupImageWidth);
        left = center - popupImageWidth / 2;
	//alert('left=' + left);
        imageDiv.style.left = left + 'px';

}

var isOpenBuyMe = false;
var popupDivBuyMe;

function showBuyMe(e, id)
{
	if (isOpenBuyMe) { return; }

	var posY = Event.pointerY(e);
	var posX = Event.pointerX(e);

        popupDivBuyMe = document.createElement('div');

        $('buy_me' + id).appendChild(popupDivBuyMe);

	popupDivBuyMe.style.position = 'absolute';
	popupDivBuyMe.style.top = posY + 'px';
	popupDivBuyMe.style.left = posX + 'px';
        popupDivBuyMe.style.display = 'block';
        popupDivBuyMe.style.zIndex = 1000;
	popupDivBuyMe.style.color = '#000000';
        popupDivBuyMe.style.backgroundColor = '#ffffff';
        popupDivBuyMe.style.borderWidth = '2px';
        popupDivBuyMe.style.borderStyle = 'solid';
        popupDivBuyMe.style.borderColor = '000000';
        popupDivBuyMe.style.padding = '10px';
        popupDivBuyMe.style.width = '500px';
        //popupDivBuyMe.style.height = '60px';
	popupDivBuyMe.style.cursor = 'default';

	var sale_notes  = '';
	new Ajax.Request('./?c=specimens&a=ajax_sale_notes&id=' + id, {
		onSuccess: function(transport) {

			if (transport.responseText) {

				var ret = transport.responseText;

				if (ret !=  '0') {

					sale_notes = ret;

					var html = '<div style="text-align:left; margin-left:30px;">';
					html += '<p style="font-weight:bold; margin-bottom:5px;">Inquire to Buy</p>';
					html += '<p>' + sale_notes + '</p>';
					html += '<span style="font-size:0.8em;">(* required)</span><br /><br />';
					html += '<table cellpadding="5" border="0" style="background-color:#ffffff;">';
					html += '<tr>';
					html += '<td align="right" class="ContainerPopupInput">*Email:&nbsp;</td>';
					html += '<td class="ContainerPopupInput"><input id="buyMeEmail' + id  + '" type="text" name="buyMeEmail' + id  + '" value="" style="width:200px;" /></td>';
					html += '</tr>';

					html += '<tr>';
					html += '<td align="right" class="ContainerPopupInput">Name:&nbsp;</td>';
					html += '<td class="ContainerPopupInput"><input id="buyMeName' + id  + '" type="text" name="buyMeName' + id  + '" value="" style="width:200px;" /></td>';
					html += '</tr>';

					html += '<tr>';
					html += '<td align="right" class="ContainerPopupInput">Phone:&nbsp;</td>';
					html += '<td class="ContainerPopupInput"><input id="buyMePhone' + id  + '" type="text" name="buyMePhone' + id  + '" value="" style="width:200px;" /></td>';
					html += '</tr>';

					html += '<tr>';
					html += '<td align="right" class="ContainerPopupInput">Message:&nbsp;</td>';
					html += '<td class="ContainerPopupInput"><textarea id="buyMeMessage' + id  + '" name="buyMeMessage' + id  + '" value="" rows="3" style="width:350px; background-color:#ffffff;"></textarea></td>';
					html += '</tr>';

					html += '</table>';

					html += '<p style="font-size:0.8em;">';
					html += 'Submission of this form implies willingness by the submittor to be contacted by the seller via whatever information is submitted. SerpenTrack provides this service only as a means to contact the seller. SerpenTrack does not vouch for the sellers intentions, conduct or representations and takes no responsibility for any communications, interacttions and/or transactions between buyer and seller pursuant to this contact.<br /><br />';
					html += '<input type="checkbox" id="acceptContactTerms" name="accept" value="1" />&nbsp;I am 18 years of age or older and have read and accept the terms above.';
					html += '</p>';

					html += '<p>';
					html += '<input type="button" id="submitBuyMe" name="submitBuyMe" value="Send" style="padding:2px; background-color:#000000; color:#ffffff; text-align:center; width:50px; cursor:hand;" onClick="procBuyMe(event, ' + id + ')" />&nbsp;&nbsp;';
					html += '<input type="button" id="cancelBuyMe" name="cancelBuyMe" value="Cancel" style="padding:2px; background-color:#000000; color:#ffffff; text-align:center; width:50px; cursor:hand;" onClick="closeBuyMe(event)" />';
					html += '</p>';
					html += '</div>';

					popupDivBuyMe.innerHTML = html;

					isOpenBuyMe = true;

				} else {

					alert('Error: Missing Specimen ID!');
				}

			}

		},

		onFaliure: function() {

			alert('Error: vote not processed!');
		}
	});


}

function procBuyMe(e, id)
{
	var accept = $("acceptContactTerms").getValue();
	if (accept) {

		var qStr = '&form[id]='+id;
		qStr += '&form[name]=' + $("buyMeName" + id).getValue();
		qStr += '&form[email]=' + $("buyMeEmail" + id).getValue();
		qStr += '&form[phone]=' + $("buyMePhone" + id).getValue();
		qStr += '&form[message]=' + $("buyMeMessage" + id).getValue();
		new Ajax.Request('./?c=specimens&a=ajax_buy_me' + encodeURI(qStr), {
			onSuccess: function(transport) {

				if (transport.responseText) {

					var ret = transport.responseText;
					var msg = '';

					if (ret == '1') {

						msg = 'Message Submitted';

					} else {

						msg = 'Message not sent:<br />' + ret;
					}

					var html = '<div style="text-align:center;">';
					html += '<div style="background-color:#ffffff; font-weight:bold; margin-bottom:5px;">' + msg;
					html += '<br /><br /><input type="button" id="close" name="close" value="Close" style="padding:2px; background-color:#000000; color:#ffffff; text-align:center; width:50px; cursor:hand;" onClick="closeBuyMe(event)" />';
					html += '</div>';
					
					html += '</div>';

					popupDivBuyMe.innerHTML = html;

				}

			},
			onFaliure: function() {

				alert('Error: vote not processed!');
			}
		});

	} else {

		alert('Terms must be accepted to submit inquiry.');
	}
}

function closeBuyMe(e)
{
	$(popupDivBuyMe).remove();
	Event.stop(e);
	isOpenBuyMe = false;
}

var isOpenVote = false;
var popupDivVote;

function showVote(e, id)
{
	if (isOpenVote) { return; }

	var posY = Event.pointerY(e);
	var posX = Event.pointerX(e);

        popupDivVote = document.createElement('div');

        $('vote_sotw_' + id).appendChild(popupDivVote);

	popupDivVote.style.position = 'absolute';
	popupDivVote.style.top = posY + 'px';
	popupDivVote.style.left = posX + 'px';
        popupDivVote.style.display = 'block';
        popupDivVote.style.zIndex = 1000;
	popupDivVote.style.color = '#000000';
        popupDivVote.style.backgroundColor = '#ffffff';
        popupDivVote.style.borderWidth = '2px';
        popupDivVote.style.borderStyle = 'solid';
        popupDivVote.style.borderColor = '000000';
        popupDivVote.style.padding = '10px';
        popupDivVote.style.width = '180px';
        //popupDivVote.style.height = '60px';
	popupDivVote.style.cursor = 'default';

	var html = '<div style="text-align:center;">';
	html += '<p style="font-weight:bold; margin-bottom:5px;">Specimen of the Week?</p>';
	html += '<input type="button" id="vote_sotwYes" name="vote_sotwYes" value="Yes" style="padding:2px; background-color:#000000; color:#ffffff; text-align:center; width:50px; cursor:hand;" onClick="procVote(event, ' + id + ')" />&nbsp;&nbsp;';
	html += '<input type="button" id="vote_sotwNo" name="vote_sotwNo" value="No" style="padding:2px; background-color:#000000; color:#ffffff; text-align:center; width:50px; cursor:hand;" onClick="closeVote(event)" />';
	html += '</div>';

	popupDivVote.innerHTML = html;

	isOpenVote = true;

}

function procVote(e, id)
{

	new Ajax.Request('./?c=specimens&a=ajax_sotw_vote&id=' + id, {
		onSuccess: function(transport) {

			if (transport.responseText) {

				var ret = transport.responseText;
				var msg = '';

				if (ret == '1') {

					msg = 'Current vote changed';

				} else if (ret == '2') {

					msg = 'Vote is redundant for this specimen/period. No change.';

				} else if (ret == '3') {

					msg = 'Vote registered';
				} else {

					msg = 'WTF?';
				}

				var html = '<div style="text-align:center;">';
				html += '<div style="background-color:#ffffff; font-weight:bold; margin-bottom:5px;">' + msg;
				html += '<br /><br /><input type="button" id="close" name="close" value="Close" style="padding:2px; background-color:#000000; color:#ffffff; text-align:center; width:50px; cursor:hand;" onClick="closeVote(event)" />';
				html += '</div>';
				
				html += '</div>';

				popupDivVote.innerHTML = html;

			}

		},
		onFaliure: function() {

			alert('Error: vote not processed!');
		}
	});
}

function closeVote(e)
{
	$(popupDivVote).remove();
	Event.stop(e);
	isOpenVote = false;
}

function doPartnerClick(partner_id, url)
{
	new Ajax.Request('./?c=partners&a=ajax_proc_click&id=' + partner_id); 
	window.open(url);
}

