var server_name = 'http://www.grandparents.com';

function googleClickTrack(id) {
	var trackpath = '/clicktrack-PAGE' + document.location.pathname + '/ID-' + escape(id);
	pageTracker._trackPageview(trackpath);
}

function setSectionV3(id) {
	changeClass(id, id + '_on');
	
	var obj = document.getElementById(id);
	if(obj) {
		obj.onmouseover = "";
    	obj.onmouseout = "";
    }
}

function surveyMonkey() {
	var is_first = getCookie('promoPopInVisitCount');

	document.write('current page: ' + document.location.href + ' is_first:' + is_first) ;

	if(1 || is_first != 1) {

		if(document.location.href != 'someurl') {

			// document.write('<scr' + 'ipt src="http://www.surveymonkey.com/jsPop.aspx?sm=4zZ74T0UgeaFdHRybln72Q_3d_3d"></scr' + 'ipt>');
			// window.open('http://www.surveymonkey.com/jsPopInvite.aspx?sm=4zZ74T0UgeaFdHRybln72Q%3d%3d', 'win', 'height=300,width=300,scrollbars=yes,resizable=yes,status=yes')
		}
	}
}

function launchArticleEmbeddedSlideShow(photo) {

	var backgroundId = 'popinBackgroundDark';
	var bg = document.createElement('div'); 
	bg.setAttribute('id',backgroundId);
	bg.setAttribute('class','popinBackgroundDark');
	bg.setAttribute('className', 'popinBackgroundDark');
	document.body.appendChild(bg);

	var id = 'embedded_slideshow';
	var popin = document.createElement('div'); 
	popin.setAttribute('id',id);
	popin.style.zIndex = 20000;
	document.body.appendChild(popin);
	popin.innerHTML = '<IFRAME src="/gp/embedded-slideshow.html?id=' + id + '&record=' + photo + '" allowtransparency="true" width=726 height=700 frameborder=0>';
	promoPopInOpen(id,backgroundId,'','',726,740,'','');
}

function bookmarksite(title,url) {

	title = unescape(title);
	url = unescape(url);
	
	if (window.sidebar) { // firefox
		window.sidebar.addPanel(title, "http://www.grandparents.com" + url, "");
	}
	else if(window.opera && window.print){ // opera
		var elem = document.createElement('a');
		elem.setAttribute('href',"http://www.grandparents.com" + url);
		elem.setAttribute('title',title);
		elem.setAttribute('rel','sidebar');
		elem.click();
	} 
	else if(document.all) {// ie
		window.external.AddFavorite("http://www.grandparents.com" + url, title);
	}
}

function registerOrGo(url,source) {

	var destination = escape(server_name + url);

	if(getCookie('account')) {
		document.location.href = unescape(destination);
	}
	else {
		promoPopInShowWindow("account_popin","","",420,800,'',"/gp/popins/register.html?destination=" + destination, false, source);
	}
}

// GROUPS

function joinGroup(group, destination) {
	var destination = escape(server_name + destination);

	if(getCookie('account')) {
		promoPopInShowWindow("account_popin","","",420,800,'',"/gp/popins/joingroup.html?group=" + group + "&destination=" + destination, false, 'groups');
	}
	else {
		promoPopInShowWindow("account_popin","","",420,800,'',"/gp/popins/register.html?group=" + group + "&destination=" + destination, false, 'groups');
	}
}

function applyGroup(group, destination) {
	var destination = escape(server_name + destination);

	if(getCookie('account')) {
		promoPopInShowWindow("account_popin","","",420,800,'',"/gp/popins/joingroup.html?group=" + group + "&destination=" + destination, false, 'groups');
	}
	else {
		promoPopInShowWindow("account_popin","","",420,800,'',"/gp/popins/register.html?group=" + group + "&destination=" + destination, false, 'groups');
	}
}

function inviteGroup(group, destination) {
	promoPopInShowWindow("invite_popin","","",420,800,'',"/gp/popins/groupinvite.html?group=" + group, false, '');
}

function openWhatIsSticky(id) {
	document.getElementById(id).style.display = '';
}
function closeWhatIsSticky(id) {
	document.getElementById(id).style.display = 'none';
}

var postDeleteDestination = '';

function removeGroupMember(row,destination) {
	if(confirm("You are about to remove this member from the group. If you are sure you want to do this, click OK. To cancel and stay on this page, click Cancel.")) {
		postDeleteDestination = destination;

		var request_body = "proc=group_delete_member";
		request_body 	+= "&row=" + escape(row);
		var http_request = setupAjax();
		http_request.onreadystatechange = function() { groupMemberDone(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 reportGroupMember(row,destination) {
	if(confirm("You are about to report this member to Grandparents.com. If you are sure you want to do this, click OK. To cancel, click Cancel.")) {
		postDeleteDestination = destination;

		var request_body = "proc=group_report_member";
		request_body 	+= "&row=" + escape(row);
		var http_request = setupAjax();
		http_request.onreadystatechange = function() { groupMemberReportDone(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 makeGroupMemberModerator(row,destination) {
	if(confirm("You are about to make this member a Moderator of this group. This will give them the same privileges that you have. If you are sure you want to do this, click OK. To cancel, click Cancel.")) {
		postDeleteDestination = destination;

		var request_body = "proc=group_make_member_moderator";
		request_body 	+= "&row=" + escape(row);
		var http_request = setupAjax();
		http_request.onreadystatechange = function() { groupMemberDone(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 groupMemberDone(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') {
				document.location.href = postDeleteDestination;
			}
			else {
				alert('Could not save member changes ' + status);
			}
		}
	}
}

function groupMemberReportDone(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') {
				alert("Your notification has been sent.");
			}
			else {
				alert('Could not save member changes ' + status);
			}
		}
	}
}

function deleteDiscussion(row,destination) {
	if(confirm("Are you sure you want to delete this discussion? Once deleted, all postings associated with this discussion will be removed and can not be retrieved. To continue, click OK. To cancel and return to the page, click Cancel.")) {

		postDeleteDestination = destination;
		
		var request_body = "proc=group_delete_discussion";
		request_body 	+= "&row=" + escape(row);
		var http_request = setupAjax();
		http_request.onreadystatechange = function() { deleteDiscussionDone(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 deleteReply(row,destination) {
	if(confirm("Are you sure you want to delete this reply? To continue, click OK. To cancel and return to the page, click Cancel.")) {

		postDeleteDestination = destination;
		
		var request_body = "proc=group_delete_discussion";
		request_body 	+= "&row=" + escape(row);
		var http_request = setupAjax();
		http_request.onreadystatechange = function() { deleteDiscussionDone(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 deleteDiscussionDone(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') {
				document.location.href = postDeleteDestination;
			}
			else {
				alert('Could not delete discussion ' + status);
			}
		}
	}
}


function deletePhoto(row,destination) {
	if(confirm("Are you sure you want to delete this photo? Once deleted, any comments associated with this photo will be removed and can not be retrieved. To continue, click OK. To cancel and return to the page, click Cancel.")) {

		postDeleteDestination = destination;
		
		var request_body = "proc=group_delete_photo";
		request_body 	+= "&row=" + escape(row);
		var http_request = setupAjax();
		http_request.onreadystatechange = function() { deletePhotoDone(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 deletePhotoDone(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') {
				document.location.href = postDeleteDestination;
			}
			else {
				alert('Could not delete photo ' + status);
			}
		}
	}
}

function makeSticky(row,destination) {
	if(confirm('Are you sure you want to make this post sticky? If so, click OK. If not, click Cancel.')){
		postDeleteDestination = destination;
		var request_body = "proc=group_make_sticky";
		request_body 	+= "&row=" + escape(row);
		var http_request = setupAjax();
		http_request.onreadystatechange = function() { makeStickyDone(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 makeUnSticky(row,destination) {
	if(confirm('Are you sure that you do NOT want this post to be sticky? If so, click OK. If not, click Cancel.')){
		postDeleteDestination = destination;
		var request_body = "proc=group_make_unsticky";
		request_body 	+= "&row=" + escape(row);
		var http_request = setupAjax();
		http_request.onreadystatechange = function() { makeStickyDone(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 makeStickyDone(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') {
				document.location.href = postDeleteDestination;
			}
			else {
				alert('Could not delete photo ' + status);
			}
		}
	}
}

function flagPost(row) {
	if(confirm("Are you sure you want to report this as inappropriate? If so, click OK. To cancel, click Cancel.")) {
		div = document.getElementById('flagdiv_' + row);
		if(div) {
			div.innerHTML = '<img src="/images/static-v3/groups/flag_over.gif">';
		}
		var request_body = "proc=group_flag_post";
		request_body 	+= "&row=" + escape(row);
		
		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 flagPhoto(row) {
	if(confirm("Are you sure you want to report this as inappropriate? If so, click OK. To cancel, click Cancel.")) {
		div = document.getElementById('flagdiv_' + row);
		if(div) {
			div.innerHTML = '<img src="/images/static-v3/groups/flag_over.gif">';
		}
		var request_body = "proc=group_flag_photo";
		request_body 	+= "&row=" + escape(row);
		
		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 flagPhotoComment(row) {
	if(confirm("Are you sure you want to report this as inappropriate? If so, click OK. To cancel, click Cancel.")) {
		div = document.getElementById('flagdiv_' + row);
		if(div) {
			div.innerHTML = '<img src="/images/static-v3/groups/flag_over.gif">';
		}
		var request_body = "proc=group_flag_photo_comment";
		request_body 	+= "&row=" + escape(row);
		
		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);
			if(status == 'ok') {
			}
			else {
				alert('Could not save flag ' + status);
			}
		}
	}
}

function ajaxSaveComment(parent,destination,member) {
	postDeleteDestination = destination;

	var comment_body = document.getElementById('comment_body');
	if(comment_body && comment_body.value) {
		var http_request 	= setupAjax()
		var url 			= '/gp/ajaxupdate.xml';
		var request_body 	= 'proc=group_save_photo_comment';

		request_body += '&table=GROUP_PHOTO_COMMENT';
		request_body += '&parent=' + parent;
		request_body += '&member=' + member;
		request_body += '&comment=' + escape(comment_body.value);

		http_request.onreadystatechange = function() { ajaxSaveCommentDone(http_request); };
		http_request.open('POST', url, true);
		http_request.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
		http_request.send(request_body);

		var div = document.getElementById('comment_logged_in');
		if(div) {
			div.innerHTML = 'Saving comment...';
		}
	}
	else {
		var div = document.getElementById('comment_error');
		if(div) {
			div.innerHTML = 'Please enter a comment.';
		}
	}
	return false;
}

function ajaxSaveCommentDone(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 div = document.getElementById('comment_logged_in');
				if(div) {
					div.innerHTML = 'Your comment has been saved.';
					document.location.href = postDeleteDestination;
				}
			}
			else {
				alert('Could not save comment error:' + status);
			}
		}
		else {
			alert('Could not save comment error:' + http_request.status);
		}
	}
}

function clearDefault(obj) {
	obj.value='';
}

function showHeaderJoinButton() {
	document.getElementById('header_join_button').style.display = '';
}

function checkSimilar() {
	
	var keywords = '';
	
	if(document.forms.newgroup.GP_GROUP_title.value) {
		keywords = document.forms.newgroup.GP_GROUP_title.value;
	}
	
	if(document.forms.newgroup.GP_GROUP_keywords.value) {
		keywords += ' ';
		keywords += document.forms.newgroup.GP_GROUP_keywords.value;
	}

	promoPopInShowWindow("similar_popin","","",420,800,'',"/gp/popins/similargroups.html?keywords=" + escape(keywords), false, "");
	
}

// promo

var promos = new Array();

function promo(id,first_visit, skip_if_did_newsletter, skip_if_did_account, skip_if_did_pictures, skip_if_did_groups) {
	this.id 					= id;
	this.first_visit 			= first_visit;
	this.skip_if_did_newsletter = skip_if_did_newsletter;
	this.skip_if_did_account 	= skip_if_did_account;
	this.skip_if_did_pictures 	= skip_if_did_pictures;
	this.skip_if_did_groups 	= skip_if_did_groups;
}

function registerPromoDiv(id,first_visit,skip_if_did_newsletter,skip_if_did_account,skip_if_did_pictures,skip_if_did_groups) {
	var p = new promo(id,first_visit,skip_if_did_newsletter,skip_if_did_account,skip_if_did_pictures,skip_if_did_groups);
	promos.push(p);
}

function findFirstVistPromos() {
	var found = new Array();
	for(var i = 0; i < promos.length; i++) {
		if(promos[i].first_visit) {
			found.push(promos[i]);
		}
	}
	return found;
}

function log(message) {
	var div = document.getElementById('debug');
	if(div) {
		div.innerHTML = message + '<br>' + div.innerHTML;
	}
}

function pickPromo() {
	hideAllPromos();

	var visit_count 	= getCookie('PromoVisited');
	var have_account    = getCookie('account');
	var did_account 	= getCookie('did_account');
	var did_newsletter  = getCookie('did_newsletter');
	var did_photos  	= getCookie('have_photos');
	var did_groups 		= getCookie('have_groups');
		
	// log('visit_count:' + visit_count + ' have_account:' + have_account + ' did_account:' + did_account + ' did_newsletter:' + did_newsletter + ' have_photos:' + have_photos);

	var found = null;
	if(!visit_count) {
		found = findFirstVistPromos();
		setCookie('PromoVisited','1',365);
	}
	else {
		found = new Array();
		
		for(var i = 0; i < promos.length; i++) {
		
			var ok = true;
		
			if(promos[i].skip_if_did_newsletter && did_newsletter) {
				ok = false;
			}

			if(promos[i].skip_if_did_account && (have_account || did_account)) {
				ok = false;
			}

			if(promos[i].skip_if_did_pictures && did_photos) {
				ok = false;
			}

			if(promos[i].skip_if_did_groups && did_groups) {
				ok = false;
			}
			
			if(ok) {
				found.push(promos[i]);
			}
		}
	}
	
	if(found.length) {

		// log('found ' + found.length + ' matching promos');
		
		var p = found[Math.floor(Math.random() * found.length)];

		// log('picked ' + p.id);

		
		var div = document.getElementById(p.id);
		if(div) {
			div.style.display = '';
		}
		else {
			alert('could not find promo div ' + p.id);
		}
	}
	else {
		// log('no promos found');
	}

}

function hideAllPromos() {
	for(var i = 0; i < promos.length; i++) {
		var div = document.getElementById(promos[i].id);
		if(div) {
			div.style.display = 'none';
		}
	}
}

// photo contest

	var currentPhoto  = -1;
	var photos		  = null;
	var photoPane     = null;
	var lastPhotoPane = null;
	var votePane	  = null;
	var skipPane	  = null;

	var gAdvertCounter = 0;

	var contestNickname = '';
	var contestpath     = '';

	function initPhotoContest() {
		photoPane     = document.getElementById('photo');
		lastPhotoPane = document.getElementById('lastphoto');
		votePane	  = document.getElementById('vote');
		skipPane	  = document.getElementById('skip');
	}
	
	function newAdvert(id,page, position) {
		var advertDiv = document.getElementById(id);
		if(advertDiv) {
			advertDiv.style.display = '';
			++gAdvertCounter;
			if(id == 'advert1') {
				advertDiv.innerHTML = '<iframe id=advertIframe scrolling="no" style="border:0;padding:0;margin:0;width:450;height:300;" src="/gp/ajax-advert.html?page=' + page + '&position=' + position + '&bust=' + gAdvertCounter + '"></iframe>';
			}
			else {
				advertDiv.innerHTML = '<iframe id=advertIframe scrolling="no" style="border:0;padding:0;margin:0;width:750;height:100;" src="/gp/ajax-advert.html?page=' + page + '&position=' + position + '&bust=' + gAdvertCounter + '"></iframe>';
			}
		}
	}
	
	function refreshAds() {
		newAdvert('advert1',contestpath,'Right1');
		newAdvert('ajaxadverttop',contestpath,'Top3');
		newAdvert('ajaxadvertbottom',contestpath,'Bottom');
	}	

	function vote(vote,contest,name_of_contest) {
		pageTracker._trackEvent('Photo Contests', 'Open Contest Views', name_of_contest);

		var radios = document.getElementsByName('vote');
		for(var i = 0; i < radios.length; i++) {
			radios[i].checked = false;
		}

		var photo = getXmlFirstChildData('row',photos[currentPhoto]);
		var contest = contest;
		
		var request_body = "proc=vote";
		request_body += "&contest=" + contest;
		request_body += "&photo=" + photo;
		request_body += "&vote=" + vote;
		var http_request = setupAjax();
		http_request.onreadystatechange = function() { voteDone(http_request); };
		http_request.open('POST', "/gp/photocontest.xml", true);
		http_request.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
		http_request.send(request_body);
	}
	
	function skip() {
		showNext(true);
	}
	
	function showNext(doAds) {
		var lastPhoto = '';
		
		if(currentPhoto >= 0) {
			lastPhoto  = getXmlFirstChildData('row',photos[currentPhoto]);
		}
		
		++currentPhoto;
		if(currentPhoto < photos.length) {
			var user = getXmlFirstChildData('owner',photos[currentPhoto]);
			var row  = getXmlFirstChildData('row',photos[currentPhoto]);
			
			var buffer;
			buffer = "<table cellpadding=0 cellspacing=0 style=\"margin-top:3px;width:450px;\">";
			buffer += "<tr><td align=center style=\"border-style:solid;border-width:1;border-color:#ccc;\">";
			buffer += "<img src=\"" +getXmlFirstChildData('file',photos[currentPhoto])+ "\" width=\" " + getXmlFirstChildData('width',photos[currentPhoto]) + "\" height=\"" + getXmlFirstChildData('height',photos[currentPhoto]) + "\" border=0>";
			buffer += "</td></tr>";
			buffer += "<tr>";
			buffer += "<td class=content style=\"font-size:12px;\">";
			buffer += "Posted by: <a href=\"javascript:promoPopInUserProfile(\'" + user + "\');\">" + user + "</a>";
			buffer += "</td>";
			buffer += "<td align=right>";
			buffer += "<div id=\"flagdiv\"><a href=\"javascript:flagPhotoContest();\" onmouseover=\"swapImage('flag', '/images/static-v3/groups/flag_over.gif');\" onmouseout=\"swapImage('flag', '/images/static-v3/groups/flag_off.gif');\"><img src=\"/images/static-v3/groups/flag_off.gif\" width=15 height=17 border=0 name=flag id=flag></a></div>";
			buffer += "</td>";
			buffer += "</tr>";
			buffer += "</table>";
			buffer += '<div style="margin-top:15px\" class=content><a href="javascript:emailFriend(\'\',\'\',\'/gp/photo-contests/contest/' + contestNickname + '.html?first=' + row + '\')" style="font-weight:bold;">Share</a> this photo with friends and family.</div>';
			
			// alert(buffer);
			
			photoPane.innerHTML = buffer;
			
			if(doAds) {
				refreshAds();
			}
		}
		else {
			document.location.href = '/gp/photo-contests/contest/winning/' + contestNickname + '.html?lastvote=' + lastPhoto;
		}
	}

	function getBatch(row,winners,first,path) {
		initPhotoContest();
		contestpath = path;
		var request_body = "proc=batch";
		request_body += "&contest=" + row;
		request_body += "&first=" + first;
		request_body += "&winners=" + winners;
		var http_request = setupAjax();
		http_request.onreadystatechange = function() { getBatchDone(http_request); };
		http_request.open('POST', "/gp/photocontest.xml", true);
		http_request.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
		http_request.send(request_body);
	}
	
	function getBatchDone(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') {						
					photos = xmldoc.getElementsByTagName('photo')
					showNext(false);
				}
				else {
					alert('Could get contest photos ' + status);
				}
			}
		}
	}

	function voteDone(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 score = getXmlFirstChildData('score', xmldoc);
					
					var src = getXmlFirstChildData('file',photos[currentPhoto]);
					
					lastPhotoPane.innerHTML = "<div style=\"width:120px;height:62px;background-color:#e2e2e2;overflow:hidden;\"><table><tr><td><img src=\"" + src + "\" width=53></td><td valign=top style=\"font-family:arial;font-size:12px;padding-left:5px;\">Previous Photo<br><span style=\"font-size:25px;font-weight:bold;color:#888;\">" + score + "</span></td></tr></table></div>";
					showNext(true);

				}
				else {
					alert('Could save vote ' + status);
				}
			}
		}
	}


	function flagPhotoContest(row) {
		if(confirm("Are you sure you want to report this as inappropriate? If so, click OK. To cancel, click Cancel.")) {
			div = document.getElementById('flagdiv');
			if(div) {
				div.innerHTML = '<img src="/images/static-v3/groups/flag_over.gif">';
			}
	
			var row = getXmlFirstChildData('row',photos[currentPhoto]);
	
			var request_body = "proc=flag";
			request_body 	+= "&row=" + row;
			
			var http_request = setupAjax();
			http_request.onreadystatechange = function() { flagPhotoContestDone(http_request); };
			http_request.open('POST', "/gp/photocontest.xml", true);
			http_request.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
			http_request.send(request_body);
		}
	}
	
	function flagPhotoContestDone(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 save flag ' + status);
				}
			}
		}
	}

function doTodaysDate() {
	var div = document.getElementById('currentdatedisplay');
	if(div) {
		var dayNames = new Array("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday");
		var monthNames = new Array("January","February","March","April","May","June","July","August","September","October","November","December");
		var now = new Date();
		// var buffer = dayNames[now.getDay()] + ", " + monthNames[now.getMonth()] + " " + now.getDate();
		var buffer = monthNames[now.getMonth()] + " " + now.getDate();
		div.innerHTML = buffer;
	}
}

