// convert all characters to lowercase to simplify testing
var agt=navigator.userAgent.toLowerCase();

// *** BROWSER VERSION ***
// Note: On IE5, these return 4, so use is_ie5up to detect IE5.
var is_major = parseInt(navigator.appVersion);
var is_minor = parseFloat(navigator.appVersion);

// Note: Opera and WebTV spoof Navigator.  We do strict client detection.
// If you want to allow spoofing, take out the tests for opera and webtv.
var is_nav  = ((agt.indexOf('mozilla')!=-1) && (agt.indexOf('spoofer')==-1)
			&& (agt.indexOf('compatible') == -1) && (agt.indexOf('opera')==-1)
			&& (agt.indexOf('webtv')==-1) && (agt.indexOf('hotjava')==-1));
var is_nav2 = (is_nav && (is_major == 2));
var is_nav3 = (is_nav && (is_major == 3));
var is_nav4 = (is_nav && (is_major == 4));
var is_nav4up = (is_nav && (is_major >= 4));
var is_navonly      = (is_nav && ((agt.indexOf(";nav") != -1) ||
					  (agt.indexOf("; nav") != -1)) );
var is_nav6 = (is_nav && (is_major == 5));
var is_nav6up = (is_nav && (is_major >= 5));
var is_gecko = (agt.indexOf('gecko') != -1);


var is_ie     = ((agt.indexOf("msie") != -1) && (agt.indexOf("opera") == -1));
var is_ie3    = (is_ie && (is_major < 4));
var is_ie4    = (is_ie && (is_major == 4) && (agt.indexOf("msie 4")!=-1) );
var is_ie4up  = (is_ie && (is_major >= 4));
var is_ie5    = (is_ie && (is_major == 4) && (agt.indexOf("msie 5.0")!=-1) );
var is_ie5_5  = (is_ie && (is_major == 4) && (agt.indexOf("msie 5.5") !=-1));
var is_ie5up  = (is_ie && !is_ie3 && !is_ie4);
var is_ie5_5up =(is_ie && !is_ie3 && !is_ie4 && !is_ie5);
var is_ie6    = (is_ie && (is_major == 4) && (agt.indexOf("msie 6.")!=-1) );
var is_ie6up  = (is_ie && !is_ie3 && !is_ie4 && !is_ie5 && !is_ie5_5);

// KNOWN BUG: On AOL4, returns false if IE3 is embedded browser
// or if this is the first browser window opened.  Thus the
// variables is_aol, is_aol3, and is_aol4 aren't 100% reliable.
var is_aol   = (agt.indexOf("aol") != -1);
var is_aol3  = (is_aol && is_ie3);
var is_aol4  = (is_aol && is_ie4);
var is_aol5  = (agt.indexOf("aol 5") != -1);
var is_aol6  = (agt.indexOf("aol 6") != -1);

var is_opera = (agt.indexOf("opera") != -1);
var is_opera2 = (agt.indexOf("opera 2") != -1 || agt.indexOf("opera/2") != -1);
var is_opera3 = (agt.indexOf("opera 3") != -1 || agt.indexOf("opera/3") != -1);
var is_opera4 = (agt.indexOf("opera 4") != -1 || agt.indexOf("opera/4") != -1);
var is_opera5 = (agt.indexOf("opera 5") != -1 || agt.indexOf("opera/5") != -1);
var is_opera5up = (is_opera && !is_opera2 && !is_opera3 && !is_opera4);

var is_webtv = (agt.indexOf("webtv") != -1); 

var is_TVNavigator = ((agt.indexOf("navio") != -1) || (agt.indexOf("navio_aoltv") != -1)); 
var is_AOLTV = is_TVNavigator;

var is_hotjava = (agt.indexOf("hotjava") != -1);
var is_hotjava3 = (is_hotjava && (is_major == 3));
var is_hotjava3up = (is_hotjava && (is_major >= 3));

// *** JAVASCRIPT VERSION CHECK ***
var is_js;
if (is_nav2 || is_ie3) is_js = 1.0;
else if (is_nav3) is_js = 1.1;
else if (is_opera5up) is_js = 1.3;
else if (is_opera) is_js = 1.1;
else if ((is_nav4 && (is_minor <= 4.05)) || is_ie4) is_js = 1.2;
else if ((is_nav4 && (is_minor > 4.05)) || is_ie5) is_js = 1.3;
else if (is_hotjava3up) is_js = 1.4;
else if (is_nav6 || is_gecko) is_js = 1.5;
// NOTE: In the future, update this code when newer versions of JS
// are released. For now, we try to provide some upward compatibility
// so that future versions of Nav and IE will show they are at
// *least* JS 1.x capable. Always check for JS version compatibility
// with > or >=.
else if (is_nav6up) is_js = 1.5;
// NOTE: ie5up on mac is 1.4
else if (is_ie5up) is_js = 1.3

// HACK: no idea for other browsers; always check for JS version with > or >=
else is_js = 0.0;

// *** PLATFORM ***
var is_win   = ( (agt.indexOf("win")!=-1) || (agt.indexOf("16bit")!=-1) );
// NOTE: On Opera 3.0, the userAgent string includes "Windows 95/NT4" on all
//        Win32, so you can't distinguish between Win95 and WinNT.
var is_win95 = ((agt.indexOf("win95")!=-1) || (agt.indexOf("windows 95")!=-1));

// is this a 16 bit compiled version?
var is_win16 = ((agt.indexOf("win16")!=-1) || 
		   (agt.indexOf("16bit")!=-1) || (agt.indexOf("windows 3.1")!=-1) || 
		   (agt.indexOf("windows 16-bit")!=-1) );  

var is_win31 = ((agt.indexOf("windows 3.1")!=-1) || (agt.indexOf("win16")!=-1) ||
				(agt.indexOf("windows 16-bit")!=-1));

var is_winme = ((agt.indexOf("win 9x 4.90")!=-1));
var is_win2k = ((agt.indexOf("windows nt 5.0")!=-1));

// NOTE: Reliable detection of Win98 may not be possible. It appears that:
//       - On Nav 4.x and before you'll get plain "Windows" in userAgent.
//       - On Mercury client, the 32-bit version will return "Win98", but
//         the 16-bit version running on Win98 will still return "Win95".
var is_win98 = ((agt.indexOf("win98")!=-1) || (agt.indexOf("windows 98")!=-1));
var is_winnt = ((agt.indexOf("winnt")!=-1) || (agt.indexOf("windows nt")!=-1));
var is_win32 = (is_win95 || is_winnt || is_win98 || 
				((is_major >= 4) && (navigator.platform == "Win32")) ||
				(agt.indexOf("win32")!=-1) || (agt.indexOf("32bit")!=-1));

var is_os2   = ((agt.indexOf("os/2")!=-1) || 
				(navigator.appVersion.indexOf("OS/2")!=-1) ||   
				(agt.indexOf("ibm-webexplorer")!=-1));

var is_mac    = (agt.indexOf("mac")!=-1);
// hack ie5 js version for mac
if (is_mac && is_ie5up) is_js = 1.4;
var is_mac68k = (is_mac && ((agt.indexOf("68k")!=-1) || 
						   (agt.indexOf("68000")!=-1)));
var is_macppc = (is_mac && ((agt.indexOf("ppc")!=-1) || 
							(agt.indexOf("powerpc")!=-1)));

var is_sun   = (agt.indexOf("sunos")!=-1);
var is_sun4  = (agt.indexOf("sunos 4")!=-1);
var is_sun5  = (agt.indexOf("sunos 5")!=-1);
var is_suni86= (is_sun && (agt.indexOf("i86")!=-1));
var is_irix  = (agt.indexOf("irix") !=-1);    // SGI
var is_irix5 = (agt.indexOf("irix 5") !=-1);
var is_irix6 = ((agt.indexOf("irix 6") !=-1) || (agt.indexOf("irix6") !=-1));
var is_hpux  = (agt.indexOf("hp-ux")!=-1);
var is_hpux9 = (is_hpux && (agt.indexOf("09.")!=-1));
var is_hpux10= (is_hpux && (agt.indexOf("10.")!=-1));
var is_aix   = (agt.indexOf("aix") !=-1);      // IBM
var is_aix1  = (agt.indexOf("aix 1") !=-1);    
var is_aix2  = (agt.indexOf("aix 2") !=-1);    
var is_aix3  = (agt.indexOf("aix 3") !=-1);    
var is_aix4  = (agt.indexOf("aix 4") !=-1);    
var is_linux = (agt.indexOf("inux")!=-1);
var is_sco   = (agt.indexOf("sco")!=-1) || (agt.indexOf("unix_sv")!=-1);
var is_unixware = (agt.indexOf("unix_system_v")!=-1); 
var is_mpras    = (agt.indexOf("ncr")!=-1); 
var is_reliant  = (agt.indexOf("reliantunix")!=-1);
var is_dec   = ((agt.indexOf("dec")!=-1) || (agt.indexOf("osf1")!=-1) || 
	   (agt.indexOf("dec_alpha")!=-1) || (agt.indexOf("alphaserver")!=-1) || 
	   (agt.indexOf("ultrix")!=-1) || (agt.indexOf("alphastation")!=-1)); 
var is_sinix = (agt.indexOf("sinix")!=-1);
var is_freebsd = (agt.indexOf("freebsd")!=-1);
var is_bsd = (agt.indexOf("bsd")!=-1);
var is_unix  = ((agt.indexOf("x11")!=-1) || is_sun || is_irix || is_hpux || 
			 is_sco ||is_unixware || is_mpras || is_reliant || 
			 is_dec || is_sinix || is_aix || is_linux || is_bsd || is_freebsd);

var is_vms   = ((agt.indexOf("vax")!=-1) || (agt.indexOf("openvms")!=-1));

var save = null;


function swapImage(imgName, src) {

	var obj = document.getElementById(imgName);

	if(obj) {
		if(src) {
			save = obj.src;
			obj.src = src;
		}
		else {
			if(save != null) {
				obj.src = save;
				save = null;
			}
		}
	}
}



// UTILITIES

var bName = navigator.appName;
var bVer  = parseInt(navigator.appVersion);
var browserSupportsCookies = false;

if(document.cookie.length > 0) {
	browserSupportsCookies = true;
}
else {
	document.cookie = "x=0";
	browserSupportsCookies = (document.cookie == "x=0");
}

//	if(!browserSupportsCookies) {
//		document.location.href = 'http://$ENV{'SERVER_NAME'}/unsupportedbrowser.html';
//	}

if ((bName == "Netscape" && bVer >= 3) || (bName == "Microsoft Internet Explorer" && bVer >= 4)) {
	br = "n3"; 
}
else {
	br = "n2";
}

if (br == "n3") {
		//preload
}


function openPopUp(url,width,height) {
	w = window.open(url, 'PopUp', 'scrollbars=yes,toolbar=no,location=no,directories=no,menubar=no,width=' + width + ',height=' + height);
}


function up_show_warn(elem_id) {
	document.getElementById(elem_id).style.display = "block";
	return false;
}

function up_hide_warn(elem_id) {
	document.getElementById(elem_id).style.display = "none";
	return false;
}

function up_show_added(elem_id) {
	document.getElementById(elem_id).className = "module_added_show";
	return false;
}

function up_hide_added(elem_id) {
	document.getElementById(elem_id).className = "module_added_hide";
	return false;
}

function clear_default (elem_id, def_value) {
	var this_elem = document.getElementById(elem_id);
	if (this_elem.value == def_value) {
		this_elem.value = "";
	}
}
	
function up_ff_set_bg(elem_id, check_id) {
	var this_elem = document.getElementById(elem_id);
	var this_check = document.getElementById(check_id);
	if (this_check.checked) {
		this_elem.className = "module_4_across_pics_white";
	} else {
		this_elem.className = "module_4_across_pics_gray";
	}
		
	return false;
}

function togglePaneSimple(pane_id) {
	var pane = document.getElementById(pane_id);
	
	if(pane.isShown) {
		Effect.BlindUp(pane_id,{duration:.3});
		pane.isShown = false;
	}
	else {
		Effect.BlindDown(pane_id,{duration:.3});
		pane.isShown = true;
	}
}


function togglePaneDefaultClosed(pane_id, toggle_id) {
	var pane = document.getElementById(pane_id);
	var toggle = document.getElementById(toggle_id);
	
	if(pane.isShown) {
		Effect.BlindUp(pane_id,{duration:.3});
		pane.isShown = false;
		toggle.src = '/images/static/icons/icon_view_more.gif';
	}
	else {
		Effect.BlindDown(pane_id,{duration:.3});
		pane.isShown = true;
		toggle.src = '/images/static/icons/icon_down_dot.gif';
	}
}

function togglePane(pane_id,toggle_id) {
	var pane = document.getElementById(pane_id);
	var toggle = document.getElementById(toggle_id);
	
	if(!pane.isHidden) {
		Effect.BlindUp(pane_id,{duration:.3});
		pane.isHidden = true;
		toggle.src = '/images/static/arrows/arrow_closed.gif';
	}
	else {
		Effect.BlindDown(pane_id,{duration:.3});
		pane.isHidden = false;
		toggle.src = '/images/static/arrows/arrow_expanded.gif';
	}
}

function toggleBlindPane(pane_id) {
	var pane = document.getElementById(pane_id);

	if(!pane.isShown) {
		Effect.BlindDown(pane_id,{duration:.3});
		pane.isShown = true;
	}
	else {
		Effect.BlindUp(pane_id,{duration:.3});
		pane.isShown = false;
	}
}

function showBlindPane(pane_id) {
	var pane = document.getElementById(pane_id);

	Effect.BlindDown(pane_id,{duration:.3});
}

function hideBlindPane(pane_id) {
	var pane = document.getElementById(pane_id);

	Effect.BlindUp(pane_id,{duration:.3});
}

function selectCheckboxes(prefix){
	
	var checkboxes = document.getElementsByName(prefix);

	for(i=0;i < checkboxes.length;i++){
		checkboxes[i].checked = true;
	}
}

function getInputValue(id) {
	var input = document.getElementById(id);
	
	return escape(input.value);
}

function transmitInvitations() {

	var request_body = "proc=transmit_invitations";
	
	request_body += "&add_ff01=" + getInputValue('add_ff01');
	request_body += "&add_ff02=" + getInputValue('add_ff02');
	request_body += "&add_ff03=" + getInputValue('add_ff03');
	request_body += "&add_ff04=" + getInputValue('add_ff04');
	request_body += "&add_ff05=" + getInputValue('add_ff05');
	request_body += "&add_ff06=" + getInputValue('add_ff06');
	request_body += "&add_ff07=" + getInputValue('add_ff07');
	request_body += "&add_ff08=" + getInputValue('add_ff08');
	request_body += "&add_ff09=" + getInputValue('add_ff09');
	request_body += "&add_ff10=" + getInputValue('add_ff10');
	
	request_body += "&message=" + getInputValue('message');

	var http_request = setupAjax()
	
	http_request.onreadystatechange = function() { invitationsSent(http_request); };
	http_request.open('POST', "/gp/ajaxupdate.xml", true);
	http_request.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	http_request.send(request_body);

}


function invitationsSent(http_request) {
	if (http_request.readyState == 4) {
		if (http_request.status == 200) {
			var xmldoc = http_request.responseXML;
			var status = getXmlFirstChildData('status', xmldoc);

			if(status == 'ok') {
				up_show_added('added2');
			}
			else {
				alert('Could not transmit invitations error:' + status);
			}
		}
	}
}


function acceptFF(row, paneID) {

	document.getElementById('ff_accept_' + row).src= '/images/static/buttons/btn_accept_check.gif';
	document.getElementById('ff_decline_' + row).src= '/images/static/buttons/btn_decline.gif';

	var request_body = "proc=accept_ff";
	request_body += "&record=" + row;
	
	var http_request = setupAjax()
	http_request.onreadystatechange = function() { acceptDeclineDone(http_request); };
	http_request.open('POST', "/gp/ajaxupdate.xml", true);
	http_request.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	http_request.send(request_body);
	
}

function declineFF(row, paneID) {

	document.getElementById('ff_accept_' + row).src= '/images/static/buttons/btn_accept.gif';
	document.getElementById('ff_decline_' + row).src= '/images/static/buttons/btn_decline_check.gif';

	var request_body = "proc=decline_ff";
	request_body += "&record=" + row;
	
	var http_request = setupAjax()
	http_request.onreadystatechange = function() { acceptDeclineDone(http_request); };
	http_request.open('POST', "/gp/ajaxupdate.xml", true);
	http_request.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	http_request.send(request_body);
	
}

function acceptDeclineDone(http_request) {
	if (http_request.readyState == 4) {
		if (http_request.status == 200) {
		
			var xmldoc = http_request.responseXML;
			var status = getXmlFirstChildData('status', xmldoc);

			if(status == 'ok') {
			}
			else {
				alert('Could not transmit invitation decline error:' + status);
			}
		}
	}
}

function toggleDeletePostingDone(http_request) {
	if (http_request.readyState == 4) {
		if (http_request.status == 200) {
		
			var xmldoc = http_request.responseXML;
			var status = getXmlFirstChildData('status', xmldoc);

			if(status == 'ok') {
				var deleted = getXmlFirstChildData('isdeleted', xmldoc);
				var row = getXmlFirstChildData('record', xmldoc);
				if(deleted) {
					document.getElementById('post_decline_' + row).src= '/images/static/buttons/btn_decline_check.gif';
				}
			}
			else {
				alert('Could not transmit invitation decline error:' + status);
			}
		}
	}
}

function toggleDeleteGuestbookDone(http_request) {
	if (http_request.readyState == 4) {
		if (http_request.status == 200) {
		
			var xmldoc = http_request.responseXML;
			var status = getXmlFirstChildData('status', xmldoc);

			if(status == 'ok') {
				var deleted = getXmlFirstChildData('isdeleted', xmldoc);
				var row = getXmlFirstChildData('record', xmldoc);
				if(deleted) {
					document.getElementById('guest_decline_' + row).src= '/images/static/buttons/btn_decline_check.gif';
				}
			}
			else {
				alert('Could not transmit invitation decline error:' + status);
			}
		}
	}
}

function toggleGuestbook(row, paneID) {

	document.getElementById('guest_decline_' + row).src= '/images/static/buttons/btn_decline.gif';

	var request_body = "proc=accept_guest";
	request_body += "&record=" + row;
	
	var http_request = setupAjax()
	http_request.onreadystatechange = function() { toggleDeleteGuestbookDone(http_request); };
	http_request.open('POST', "/gp/ajaxupdate.xml", true);
	http_request.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	http_request.send(request_body);
}

function togglePosting(row, paneID) {

	document.getElementById('post_decline_' + row).src= '/images/static/buttons/btn_decline.gif';

	var request_body = "proc=accept_post";
	request_body += "&record=" + row;
	
	var http_request = setupAjax()
	http_request.onreadystatechange = function() { toggleDeletePostingDone(http_request); };
	http_request.open('POST', "/gp/ajaxupdate.xml", true);
	http_request.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	http_request.send(request_body);
}



function acceptGuestbook(row, paneID) {

	document.getElementById('guest_accept_' + row).src= '/images/static/buttons/btn_accept_check.gif';
	document.getElementById('guest_decline_' + row).src= '/images/static/buttons/btn_decline.gif';

	var request_body = "proc=accept_guest";
	request_body += "&record=" + row;
	
	var http_request = setupAjax()
	http_request.onreadystatechange = function() { acceptDeclineDone(http_request); };
	http_request.open('POST', "/gp/ajaxupdate.xml", true);
	http_request.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	http_request.send(request_body);
}


function declineGuestbook(row, paneID) {

	document.getElementById('guest_accept_' + row).src= '/images/static/buttons/btn_accept.gif';
	document.getElementById('guest_decline_' + row).src= '/images/static/buttons/btn_decline_check.gif';

	var request_body = "proc=decline_guest";
	request_body += "&record=" + row;
	
	var http_request = setupAjax()
	http_request.onreadystatechange = function() { acceptDeclineDone(http_request); };
	http_request.open('POST', "/gp/ajaxupdate.xml", true);
	http_request.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	http_request.send(request_body);
}

function acceptPosting(row, paneID) {

	document.getElementById('post_accept_' + row).src= '/images/static/buttons/btn_accept_check.gif';
	document.getElementById('post_decline_' + row).src= '/images/static/buttons/btn_decline.gif';

	var request_body = "proc=accept_post";
	request_body += "&record=" + row;
	
	var http_request = setupAjax()
	http_request.onreadystatechange = function() { acceptDeclineDone(http_request); };
	http_request.open('POST', "/gp/ajaxupdate.xml", true);
	http_request.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	http_request.send(request_body);
}


function declinePosting(row, paneID) {

	document.getElementById('post_accept_' + row).src= '/images/static/buttons/btn_accept.gif';
	document.getElementById('post_decline_' + row).src= '/images/static/buttons/btn_decline_check.gif';

	var request_body = "proc=decline_post";
	request_body += "&record=" + row;
	
	var http_request = setupAjax()
	http_request.onreadystatechange = function() { acceptDeclineDone(http_request); };
	http_request.open('POST', "/gp/ajaxupdate.xml", true);
	http_request.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	http_request.send(request_body);
}

function saveFavorites(url,title,type) {

	var request_body = "proc=save_favorite";
	request_body += "&description=" + title;
	request_body += "&type=" + type;
	request_body += "&url=" + url;

	var http_request = setupAjax()
	http_request.onreadystatechange = function() { saveFavoritesDone(http_request); };
	http_request.open('POST', "/gp/ajaxupdate.xml", true);
	http_request.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	http_request.send(request_body);
}

function saveFavoritesDone(http_request) {
	if (http_request.readyState == 4) {
		if (http_request.status == 200) {
		
			var xmldoc = http_request.responseXML;
			var status = getXmlFirstChildData('status', xmldoc);

			if(status == 'ok') {
				alertZone('This page has been saved in your favorites list.');
			}
			else {
				alertZone(status);
			}
		}
	}
}

function flag(url,table,row) {

	var request_body = "proc=flag";
	request_body += "&table=" + table;
	request_body += "&row=" + row;
	request_body += "&url=" + url;

	var http_request = setupAjax()
	http_request.onreadystatechange = function() { flagDone(http_request); };
	http_request.open('POST', "/gp/ajaxupdate.xml", true);
	http_request.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	http_request.send(request_body);
}

function flagDone(http_request) {
	if (http_request.readyState == 4) {
		if (http_request.status == 200) {
		
			var xmldoc = http_request.responseXML;
			var status = getXmlFirstChildData('status', xmldoc);
			var record = getXmlFirstChildData('record', xmldoc);

			if(status == 'ok') {
				alertZone('The editor has been notified. Reference:' + record);
			}
			else {
				alertZone('error:' + status);
			}
		}
	}
}



function submitBodyPoll(table,row,poll) {
	var request_body = "&table=" + table;
	request_body += "&row=" + row;
	request_body += "&poll=" + poll;

	var http_request = setupAjax()
	http_request.onreadystatechange = function() { bodyPollDone(http_request); };
	http_request.open('POST', "/gp/bodypoll.incl", true);
	http_request.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	http_request.send(request_body);
}

function bodyPollDone(http_request) {
	if (http_request.readyState == 4) {
		if (http_request.status == 200) {
			var html = http_request.responseText;
			var obj = document.getElementById('body_poll_container');
			obj.innerHTML = html;
		}
	}
}

function alertZone(message) {
	var pane = document.getElementById('alertzonetext');
	pane.innerHTML = message;
	Effect.BlindDown('alertzone', {duration:.3, queue:'end'});
}
	
function closeAlert() {
	Effect.BlindUp('alertzone', {duration:.3, queue:'end'})
}

function blockUser(user) {

	var request_body = "proc=block";
	request_body += "&user=" + user;

	var http_request = setupAjax()
	http_request.onreadystatechange = function() { blockDone(http_request); };
	http_request.open('POST', "/gp/ajaxupdate.xml", true);
	http_request.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	http_request.send(request_body);
}

function blockDone(http_request) {
	if (http_request.readyState == 4) {
		if (http_request.status == 200) {
		
			var xmldoc = http_request.responseXML;
			var status = getXmlFirstChildData('status', xmldoc);

			if(status == 'ok') {
				alertZone('user blocked');
			}
			else {
				alertZone('Could not transmit error:' + status);
			}
		}
	}
}

var pic_album;
var pic_mode;
var pic_ref_table;
var pic_ref_field;
var pic_ref_row;
var pic_thumb_div;
var pic_input_id;
var pic_thumb_width;
var pic_thumb_class;
var pic_row;
var pic_sort;
var pic_popin_pane;

var gTargetPaneID;
var gShowPopin;
var gDoInAlbum;


function populatePaneRequest(paneID, url, show_popin) {
	
	var http_request = setupAjax();
	http_request.onreadystatechange = function() { populatePane(http_request); };
	http_request.open('GET', url, true);
	http_request.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	gTargetPaneID = paneID;
	gShowPopin = show_popin;
	http_request.send(null);

	// google bug on media pane 
	_uacct = "UA-1136660-1";
	urchinTracker();
}


function populatePane(http_request) {
	if (http_request.readyState == 4) {
		if (http_request.status == 200) {
			var text = http_request.responseText;
			var pane = document.getElementById(gTargetPaneID);
			
			if(gDoInAlbum) {
				pane = document.getElementById('albums_main');
				gDoInAlbum = false;
			}
			
			
			if(!pane) {
				alert('div ' + gTargetPaneID + ' does not exist');
			}
			else {
				pane.innerHTML = text;
				
				var input = document.getElementById('photo_title');
				if(input) { input.focus(); }

				var mask = document.createElement('iframe');
				mask.style.display 	= 'block';
				mask.style.position	= 'absolute';
				mask.style.top		= 0;
				mask.style.left		= 0;
				mask.style.zIndex 	= -1;
				mask.style.filter 	= 'mask();';
				mask.style.width  	= 648;
				mask.style.height 	= 408;

				// mask.allowTransparency="true";
				mask.frameBorder="0";
				pane.appendChild(mask);

				
			}

			if(gShowPopin) {
				popin(pic_popin_pane, 'popinBackground'); 
			}
		}
	}
}



function emailFriendSend(table,row,inurl,inAlbum) {
	var url = '/gp/emailfriend.incl';
	
	var request_body = '';
	
	if(table) {
		request_body += '&table=' + table;
	}
	if(row) {
		request_body += '&row=' + row;
	}
	if(inurl) {
		request_body += '&url=' + escape(inurl);
	}
	
	
	for(i=1;i<6;i++){
		value = document.getElementById('recipient0' + i).value;
	
		if(value) {
			request_body += '&recipient0' + i + '=' + escape(value);
		}
	}
	
	value = document.getElementById('sender_name').value;
	
	if(value){
		request_body += '&sender_name=' + escape(value);
	}
	
	value = document.getElementById('sender_email').value;
	
	if(value){
		request_body += '&sender_email=' + escape(value);
	}	

	value = document.getElementById('sender_message').value;
	
	if(value){
		request_body += '&sender_message=' + escape(value);
	}	


	request_body += '&submit=1';

	status_div = document.getElementById('please_wait');
	if(status_div) {
		status_div.innerHTML = "Sending. Please Wait.";
	}
	
	var http_request = setupAjax();
	http_request.onreadystatechange = function() { populatePane(http_request); };
	http_request.open('POST', url, true);
	http_request.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	if(inAlbum) {
		gDoInAlbum = true;
	}
	else {
		gTargetPaneID = 'mary_popin';
	}
	http_request.send(request_body);
}

function emailFriend(table,row,inurl) {
	if (typeof(pmi_displayPanel) != 'undefined') {
		pmi_displayPanel(); 
	}
}



//function emailFriend(table,row,inurl) {
//	var url = '/gp/popins/emailfriend.html?';
//	if(table) {
//		url += '&table=' + table;
//	}
//	if(row) {
//		url += '&row=' + row;
//	}
//	if(url) {
//		url += '&url=' + escape('http://www.grandparents.com' + inurl);
//	}
//	javascript:promoPopInShowWindow("send_link_popin","","",648,600,"",url,false,"send-link");
//}
//

function checkNameAvailability() {
	var nickname = document.forms["registrationform"].elements["REGISTERED_USER_nickname"].value
	var http_request = setupAjax();

	http_request.onreadystatechange = function() { nameAvailability(http_request); };
	http_request.open('POST', "/gp/ajaxupdate.xml", true);
	http_request.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	http_request.send("proc=checknickname&nickname=" + nickname);
}

function nameAvailability(http_request) {
	if (http_request.readyState == 4) {
		if (http_request.status == 200) {
		
			var xmldoc = http_request.responseXML;
			
			var status = getXmlFirstChildData('status', xmldoc);
			
			if(status == 'ok') {
				var results = getXmlFirstChildData('results', xmldoc);
				var div = document.getElementById('name_availability_results');
				div.innerHTML = results;
			}
			else {
				alert('Could not check name: ' + status);
			}
		}
	}
}


// from G2

// pop-in.js
// also uses pop-in.css
	function popin(popinId, backgroundId) {
		// first, set the backgroundId div to cover the window with opacity set in pop-in.css

		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;
		}
//		window.alert( 'Width = ' + myWidth );
//		window.alert( 'Height = ' + myHeight );

		var windowHeight = myHeight;
		var windowWidth = myWidth;
		var docHeight = document.body.offsetHeight;
		var docWidth = document.body.offsetWidth;

		var windowLeft = 0;
		var fullHeight = docHeight;
		var fullWidth  = docWidth;
		if (windowWidth > docWidth) {
			fullWidth = windowWidth;
			//need to start at window left, not document left
			windowLeft = Math.round( (docWidth - windowWidth)/2 );
		}
		if (windowHeight > docHeight) {
			fullHeight = windowHeight;
		}
		var backgroundNode = document.getElementById(backgroundId);
		backgroundNode.style.height = ""+fullHeight+"px";
		backgroundNode.style.width = ""+fullWidth+"px";
		backgroundNode.style.left = ""+windowLeft+"px";
		backgroundNode.style.visibility = "visible";
		// next, center and make the popin div visible
		var popinNode = document.getElementById(popinId);
		popinNode.style.display = "block";

		var popinHeight = popinNode.offsetHeight;
		var popinWidth = popinNode.offsetWidth;
		if (windowHeight-popinHeight < 0) {
			popinNode.style.top = "0px";
		} else {
			popinNode.style.top = ""+(windowHeight-popinHeight)/2+"px";
		}
		popinNode.style.left = ""+( (windowWidth-popinWidth)/2 + windowLeft)+"px";
		popinNode.style.position = "absolute";
		popinNode.style.visibility = "visible";
	}

	function popinExit(popinId, backgroundId) {
//		var popinNode = document.getElementById(popinId);
		var popinNode = document.getElementById(pic_popin_pane);
		popinNode.style.visibility = "hidden";
		var backgroundNode = document.getElementById(backgroundId);
		backgroundNode.style.visibility = "hidden";
		popinNode.style.display = "none";
	}

	function popinSwitch(popinIdCurrent, popinIdNext, backgroundId) {
		var windowHeight = document.body.parentNode.clientHeight;
		var windowWidth = document.body.parentNode.clientWidth;
		var docWidth = document.body.offsetWidth;
		var windowLeft = 0;
		if (windowWidth > docWidth) {
			//need to start at window left, not document left
			windowLeft = Math.round( (docWidth - windowWidth)/2 );
		}
		// hide the current popin div
		var popinNode = document.getElementById(popinIdCurrent);
		popinNode.style.visibility = "hidden";
		// center and make the next popin div visible
		var popinNode = document.getElementById(popinIdNext);
		var popinHeight = popinNode.offsetHeight;
		var popinWidth = popinNode.offsetWidth;
		if (windowHeight-popinHeight < 0) {
			popinNode.style.top = "0px";
		} else {
			popinNode.style.top = ""+(windowHeight-popinHeight)/2+"px";
		}
		popinNode.style.top = ""+(windowHeight-popinHeight)/2+"px";
		popinNode.style.left = ""+( (windowWidth-popinWidth)/2 + windowLeft)+"px";
		popinNode.style.position = "absolute";
		popinNode.style.visibility = "visible";
	}


