function eidiPhoto() {}

function deleteThought(id) {
	dynamItSendOnConfirm('index.php?dynamItAction=thought.delete&id=' + id, 'Are you sure you wish permanently delete this thought?');
}

function editThought(id) {
	dynamItLoad('index.php?dynamItAction=thought.edit&id=' + id, null, 403, 320, '');
}

function editOpinion(iid) {
	dynamItLoad('index.php?dynamItAction=opinion.edit&issue=' + iid, null, 430, 320, '');
}

function deleteOpinion(iid) {
	dynamItSendOnConfirm('index.php?dynamItAction=opinion.delete&issue=' + iid, 'Are you sure you wish to remove your opinion on this issue?');
}

function deleteComment(type, cid) {
	dynamItSendOnConfirm('index.php?dynamItAction=comment.delete&type='  + type + '&id=' + cid, 'Are you sure you wish permanently delete this comment?');
}

function createIssue() {
	dynamItLoad('index.php?dynamItAction=issue.new', null, 403, 420, '');
}

function createRelatedIssue(id) {
	dynamItLoad('index.php?dynamItAction=issue.new&related=' + id, null, 403, 420, '');
}

function relateIssue(id) {
	dynamItLoad('index.php?dynamItAction=issue.relate&issue=' + id, null, 403, 420, '');
}

function editIssue(id) {
	dynamItLoad('index.php?dynamItAction=issue.edit&id=' + id, null, 403, 420, '');
}

function deleteIssue(id) {
	dynamItSendOnConfirm('index.php?dynamItAction=admin.deleteissue&id=' + id, 'WARNING: You are a about to permanently delete ALL data associated with this issue. Do you wish to continue?');
}

function createEpac() {
	dynamItLoad('index.php?dynamItAction=epac.new', null, 403, 420, '');
}

function editEpac(id) {
	dynamItLoad('index.php?dynamItAction=epac.edit&id=' + id, null, 403, 420, '');
}

function deleteEpac(id) {
	dynamItSendOnConfirm('index.php?dynamItAction=admin.deleteepac&id=' + id, 'WARNING: You are a about to permanently delete ALL data associated with this ePAC. Do you wish to continue?');
}


function createEvent() {
	dynamItLoad('index.php?dynamItAction=event.new', null, 480, 465, '');
}

function createEventEpac(epac) {
	dynamItLoad('index.php?dynamItAction=event.new&epac=' + epac, null, 480, 465, '');
}

function editEvent(id) {
	dynamItLoad('index.php?dynamItAction=event.edit&id=' + id, null, 485, 465, '');
}

function deleteEvent(id) {
	dynamItSendOnConfirm('index.php?dynamItAction=admin.deleteepac&id=' + id, 'WARNING: You are a about to permanently delete ALL data associated with this ePAC. Do you wish to continue?');
}


function createDebate(issue) {
	if(!issue) issue = 0;
	dynamItLoad('index.php?dynamItAction=debate.new&issue=' + issue, null, 480, 465, '');
}

function editDebate(id) {
	dynamItLoad('index.php?dynamItAction=debate.edit&id=' + id, null, 485, 465, '');
}

function deleteDebate(id) {
//	dynamItSendOnConfirm('index.php?dynamItAction=admin.deleteepac&id=' + id, 'WARNING: You are a about to permanently delete ALL data associated with this ePAC. Do you wish to continue?');
}


function sendMessage(mid, subj) {
	if(!subj) subj = '';
	if(!mid) mid = '';
	dynamItLoad('index.php?dynamItAction=message.new&user='+mid+'&subj=' + urlencode(subj), null, 480, 465, '');
}

function readMessage(mid, inbox) {

	var mb = dynamItElem('message_unread_' + mid);
	if(mb && inbox) {
		if(mb.style.backgroundColor != 'white') {
			mb.style.backgroundColor = 'white';
			mb.style.border = 'none';
			var num = dynamItElem('number');
			var number = parseInt(num.innerHTML, 10);
			num.innerHTML = '' + (number - 1);
		}
	}

	dynamItLoad('index.php?dynamItAction=message.read&id=' + mid, null, 480, 465, '');
}

function deleteMessage(mid) {
	dynamItSendOnConfirm('index.php?dynamItAction=message.delete&id=' + mid, 'Are you sure you wish to delete this message?');
}

function editProfile(mid) {
	dynamItLoad('index.php?dynamItAction=member.edit&id=' + mid, null, 403, 540, '');
}

function searchByState(st) {


	var localeBox = dynamItElem('localeBox');

	if(st.length) {
		localeBox.style.display = 'block';
		dynamItSend('index.php?dynamItAction=member.loadstate&state=' + st + '&region=1&district=1');
	} else {
		localeBox.style.display = 'none';
	}

}

function searchByStateTwo(st) {

	var localeBox = dynamItElem('regionField');
	var localeBox2 = dynamItElem('districtField');
	if(st.length) {
		localeBox.style.display = 'block';
		localeBox2.style.display = 'block';
		dynamItSend('index.php?dynamItAction=member.loadstate&state='+st+'&region=1&district=1');
	} else {
		localeBox.style.display = 'none';
		localeBox2.style.display = 'none';
	}

}


function selectState(st) {

	var localeBox = dynamItElem('regionField');

	if(st.length) {
		localeBox.style.display = 'block';
		dynamItSend('index.php?dynamItAction=member.loadstate&state='+st+'&region=1&district=0');
	} else {
		localeBox.style.display = 'none';
	}

}

function addToNetwork(mid, mname, func) {
	if(!func) func = '';
	dynamItSendOnConfirm('index.php?dynamItAction=network.addfriend&member=' + mid + '&membername=' + urlencode(mname) + '&function='  + func, 'Are you sure you wish to add ' + mname + ' to your network?');
}
function removeFromNetwork(mid, mname, func) {
	if(!func) func = '';
	dynamItSendOnConfirm('index.php?dynamItAction=network.removefriend&member=' + mid + '&membername=' + urlencode(mname) + '&function='  + func, 'Are you sure you wish to remove ' + mname + ' from your network?');
}

function addToMyX(type, mid, mname, func) {
	if(!func) func = '';
	dynamItSendOnConfirm('index.php?dynamItAction=' + type + '.add&id=' + mid + '&name=' + urlencode(mname) + '&function='  + func, 'Are you sure you wish to add ' + mname + ' to my ' + type + 's?');
}
function removeFromMyX(type, mid, mname, func) {
	if(!func) func = '';
	dynamItSendOnConfirm('index.php?dynamItAction=' + type + '.drop&id=' + mid + '&name=' + urlencode(mname) + '&function='  + func, 'Are you sure you wish to remove ' + mname + ' from my ' + type + 's?');
}

function joinDebate(did, dname, func) {
	if(!func) func = '';
	dynamItSend('index.php?dynamItAction=debate.join&debate=' + did + '&name=' + urlencode(dname) + '&function=' + func );
}
function leaveDebate(did, dname, func) {
	dynamItSend('index.php?dynamItAction=debate.drop&id=' + did + '&name=' + urlencode(dname) + '&function=' + func );
}
function banDebater(did, pid, pname) {
	dynamItSendOnConfirm('index.php?dynamItAction=debate.ban&debate=' + did + '&person=' + pid + '&pname=' + pname, 'Are you sure you wish to ban ' + pname + ' from this debate?');
}

function addPolitician(mid, mname) {
	dynamItSendOnConfirm('index.php?dynamItAction=network.addpolitician&politician=' + mid + '&politname=' + urlencode(mname), 'Are you sure you wish to add ' + mname + ' to your politicians?');
}
function removePolitician(mid, mname) {
	dynamItSendOnConfirm('index.php?dynamItAction=network.removepolitician&politician=' + mid + '&politname=' + urlencode(mname), 'Are you sure you wish to remove ' + mname + ' from your politicians?');
}


function createAd(page, data) {
	var more = '';
	if(page) more += '&page=' + urlencode(page);
	if(data) more += '&data=' + urlencode(data);
	dynamItLoad('index.php?dynamItAction=advertise.add' + more, null, 480, 470, '');
}
function editAd(ad) {
	dynamItLoad('index.php?dynamItAction=advertise.edit&ad=' + ad, null, 480, 470, '');
}
function activateAd(ad) {
	dynamItSendOnConfirm('index.php?dynamItAction=advertise.active&active=1&ad=' + ad, 'Are you sure you wish to activate this advertisement?');
}
function deactivateAd(ad) {
	dynamItSendOnConfirm('index.php?dynamItAction=advertise.active&active=0&ad=' + ad, 'Are you sure you wish to deactivate this advertisement?');
}
function removeAd(ad) {
	dynamItSendOnConfirm('index.php?dynamItAction=advertise.remove&ad=' + ad, 'Are you sure you wish to permanently delete this advertisement?');
}


function createUser() {
	dynamItLoad('index.php?dynamItAction=admin.adduser', null, 480, 470, '');
}

function editSomething(action, title, id, field, value) {

	var html = '';
	html += '<div><b>' + title + '</b></div><br />';
	html += '<form method="post" action="index.php" onsubmit="return dynamItPublish(this);">';
	html += '<input type="hidden" name="dynamItAction" value="' + action + '" />';
	html += '<input type="hidden" name="id" value="' + id + '" />';
	html += '<div align="center">';
	html += '<input type="text" name="' + field + '" value="' + value + '" /><br /><br />';
	html += '<input type="submit" value="Save" /> &nbsp; ';
	html += '<input type="button" value="Cancel" onclick="closeDialog();" /> &nbsp; '
	html += '</div>';
	html += '</form>';

	openDialog(html);

}
function deleteSomething(action, object, id) {
	dynamItSendOnConfirm('index.php?dynamItAction=' + action + '&id=' + id, 'Are you sure you wish to permanently delete this ' + object + '?');
}

function loadRegionsByState(st) {
	dynamItLoad('index.php?dynamItAction=admin.loadstate&state='+st+'&region=1&district=0', 'regionHolderDiv', null, null, '');
}

function loadDistrictsByState(st) {
	dynamItLoad('index.php?dynamItAction=admin.loadstate&state='+st+'&region=0&district=1', 'districtHolderDiv', null, null, '');
}

function banUser(id) {
	dynamItSendOnConfirm('index.php?dynamItAction=admin.banuser&id=' + id, 'Are you sure you wish to ban this member?');
}
function unBanUser(id) {
	dynamItSendOnConfirm('index.php?dynamItAction=admin.unbanuser&id=' + id, 'Are you sure you wish to unblock this member?');
}

function addToFeatured(id) {
	dynamItSendOnConfirm('index.php?dynamItAction=admin.featureuser&id=' + id, 'Are you sure you wish to feature this politician?');
}

function removeFeatured(id) {
	dynamItSendOnConfirm('index.php?dynamItAction=admin.unfeatureuser&id=' + id, 'Are you sure you wish to remove this member from featured politicians?');
}

function addToFeaturedIssues(id) {
	dynamItSendOnConfirm('index.php?dynamItAction=admin.featureissue&id=' + id, 'Are you sure you wish to feature this issue?');
}

function removeFeaturedIssues(id) {
	dynamItSendOnConfirm('index.php?dynamItAction=admin.unfeatureissue&id=' + id, 'Are you sure you wish to remove this issue from top issues?');
}

function sendReport() {
	dynamItLoad('index.php?dynamItAction=report.new&uri=' + urlencode(REQUEST_URI), null, 403, 260, '');
}
var openContainer = null;
var hideMenuTimer = null;

function allowClose() {
        hideTimeout = 1000;
        hideMenuTimer = setTimeout("hideMenus()", hideTimeout);
}

function hideMenus() {
        stayOpen();
        if(openContainer) {
                var c = document.getElementById(openContainer);
                c.style.visibility = "hidden";
                openContainer = null;
        }
}

function stayOpen() {
        if (hideMenuTimer) clearTimeout(hideMenuTimer);
        hideMenuTimer = null;
}

function openDrop(containName) {
        hideMenus();
        stayOpen();
        var c = document.getElementById(containName);
        c.style.visibility = "visible";
        openContainer = "" + containName
}


function acIssue(value) {

	if(value.length) {
		dynamItLoad('index.php?dynamItAction=debate.searchissue&search=' + value, 'issue_select', null, null, '');
		openDrop('issue_select');
	} else {
		hideMenus();
	}
}


function markReport(id, actioned) {
	dynamItSend('index.php?dynamItAction=report.action&actioned=' + actioned + '&id=' + id);
}

function deleteReport(id) {
	dynamItSendOnConfirm('index.php?dynamItAction=report.delete&id=' + id, 'Are you sure you wish to permanently delete this report?');
}

function loadMonth(mid, m, y, type) {
	dynamItLoad('index.php?dynamItAction=member.calendar&mid=' + mid + '&month=' + m + '&year=' + y + '&type=' + type, 'myCalendar', null, null, '');
}

function loadDate(mid, m, d, y, type) {
	dynamItLoad('index.php?dynamItAction=member.' + type + 'events&mid=' + mid + '&month=' + m + '&day=' + d + '&year=' + y, 'myEventPane', null, null, '');
	if(type == 'home') {
		selectedCalendarTab = 'my';
	}
}


function loadMonthEpac(mid, m, y) {
	dynamItLoad('index.php?dynamItAction=epac.calendar&eid=' + mid + '&month=' + m + '&year=' + y, 'myCalendar', null, null, '');
}

function loadDateEpac(mid, m, d, y) {
	dynamItLoad('index.php?dynamItAction=epac.events&eid=' + mid + '&month=' + m + '&day=' + d + '&year=' + y, 'myEventPane', null, null, '');
}

function loadInvite(type, id) {
	dynamItLoad('index.php?dynamItAction=invite.form&id=' + id + '&type=' + type, null, 480, 465, '');
}


function addIssueToDebate(mid, mname) {

	var elems = dynamItElem('selectedIssues').getElementsByTagName('div');

	if(elems.length == 4) {
		alert('You may only have four(4) issue on a single debate.');
	} else {

		var html = '<span class="controls"><small><a href="javascript:removeIssueFromDebate(' + mid + ', \'' + str_replace('\'', '\\\'', mname) + '\');">remove</a></small></span>';
		html += '<span>' + mname + '</span>';

		addDiv('selectedIssues', 'issue_' + mid, 'friend-invite', html);
	}
}

function removeIssueFromDebate(mid, mname) {
	remDiv('issue_' + mid);
}

function sendAddDebate(f) {
	f.submitter.disabled = true;
	var elems = dynamItElem('selectedIssues').getElementsByTagName('div');

	var to = '';
	var memid, mid;
	for(var j = 0; j < elems.length; j++) {
		memid = elems[j].getAttribute('id').split('_');
		mid = memid[1];
		to += mid + ':';
	}

	f.debateIssues.value = to;

	return true;
}

function invite(mid, mname) {
	var html = '<span class="controls"><small><a href="javascript:unInvite(' + mid + ', \'' + str_replace('\'', '\\\'', mname) + '\');">remove</a></small></span>';
	html += '<span>' + mname + '</span>';

	addDiv('invited', 'invited_' + mid, 'friend-invite', html);
	remDiv('invite_friend_' + mid);
}

function unInvite(mid, mname) {
	var html = '<span class="controls"><small><a href="javascript:invite(' + mid + ', \'' + str_replace('\'', '\\\'', mname) + '\');">invite</a></small></span>';
	html += '<span>' + mname + '</span>';

	addDiv('friendScroll', 'invite_friend_' + mid, 'mytrait', html);
	remDiv('invited_' + mid);
}

function sendInvite(f) {
	var elems = dynamItElem('invited').getElementsByTagName('div');

	var to = '';
	var memid, mid;
	for(var j = 0; j < elems.length; j++) {
		memid = elems[j].getAttribute('id').split('_');
		mid = memid[1];
		to += mid + ':';
	}

	f.to.value = to;
	return dynamItPublish(f);
}

var usernameOK = false;
function testUsername(un) {

	usernameOK = false;
         var wd = dynamItElem('warnDiv');
	if(un.length == 0) {
		wd.style.color = '#cc0000';
		wd.innerHTML = 'Please enter a username';
		return;
	}

	var url = 'index.php?dynamItAction=member.name&username=' + urlencode(un);
	sendRequest(url, function() {
		if(isAjaxComplete(xmlHttp)) {
			if(xmlHttp.responseText == "good") {
				usernameOK = true;
				wd.style.color = '#00cc00';
				wd.innerHTML = 'Username OK';
			} else {
				wd.style.color = '#cc0000';
				wd.innerHTML = 'Username taken. Please try again.';
			}
		}
	});

}

function removeSpecials(unbox){

	var un = unbox.value;
	var un_regexp = /[^A-Za-z0-9]+/
	if(un_regexp.test(un)) {
		var cleaned = un.replace(/[^A-Za-z0-9]/, '');
		//alert(cleaned);
		unbox.value = cleaned;
		un = cleaned;

		alert('You may use only letters and numbers in your username.');
		return false;
	}

	return true;
}

var uniqueEmail = false;
function testEmail(em) {

	uniqueEmail = false;
         var wde = dynamItElem('warnDivEm');
	if(em.length == 0) {
		wde.style.color = '#cc0000';
		wde.innerHTML = 'Please enter your e-mail address';
		return;
	}

	var url = 'index.php?dynamItAction=member.email&email=' + urlencode(em);
	sendRequest(url, function() {
		if(isAjaxComplete(xmlHttp)) {
			if(xmlHttp.responseText == "good") {
				uniqueEmail = true;
				wde.style.color = '#00cc00';
				wde.innerHTML = 'E-mail Address OK';
			} else {
				wde.style.color = '#cc0000';
				wde.innerHTML = 'An account with this e-mail exists. Please try again.';
			}
		}
	});

}

function placeVote(val) {

	val = parseInt(val);
	var left = [0, 48, 63, 81, 99, 117, 135, 153, 170, 185, 200];
	var l = left[val];

	var ball = dynamItElem('myStance');
	ball.style.left = l + 'px';

	var stf = dynamItElem('stance_field');
	stf.value = val;
}

function createYardsign() {
	dynamItLoad('index.php?dynamItAction=member.createsign', null, 480, 465, '');
}

function generateYardsign(f) {

	var sel;
	var style = f.signstyle.value;

	var type = '';
	if(dynamItElem('signtype_me').checked) {
		type = 'me';
		sel = f.myusername.value;
	} else if(dynamItElem('signtype_eu').checked) {
		type = 'me';
		sel = 'ElectionU';
	} else {
		type = 'polit';
		sel = f.politician.value;
	}

	var html = '<div style="text-align:center"><object type="application/x-shockwave-flash" data="yardsign' + style + '.swf?sign_type=' + type + '&sign_id=' + sel + '" width="195" height="180"><param name="allowScriptAccess" value="sameDomain" /><param name="movie" value="yardsign' + style + '.swf?sign_type=' + type + '&sign_id=' + sel + '" /><param name="quality" value="high" /><param name="wmode" value="transparent" /><p> You must have Flash installed to see this content.</p></object></div>';

//	var code = '<script type="text/javascript" src="' + HTTP_ROOT + 'eyardsign.php?sign_type=' + type + '&sign_style=' + style + '&sign_id=' + sel + '"></script>';

	var code = '<object width="195" height="180">';
	code += '<param name="movie" value="http://www.electionu.com/yardsign' + style + '.swf?sign_type=' + type + '&sign_id=' + sel + '"></param>';
	code += '<param name="wmode" value="transparent"></param>';
	code += '<embed src="http://www.electionu.com/yardsign' + style + '.swf?sign_type=' + type + '&sign_id=' + sel + '" type="application/x-shockwave-flash" wmode="transparent" width="195" height="180"></embed>';
	code += '</object>';
	code += '<br /><a href="http://www.electionu.com/user/' + sel + '">Visit ElectionU.com</a>';


	var pp = dynamItElem('signPreview');
	pp.innerHTML = code;

	var ta = dynamItElem('signCode');
	ta.value = code;

	return false;
}


function moreComments(type, obj, first) {
	dynamItLoad('index.php?dynamItAction=comment.list&comment_type=' + type + '&obj='  + obj + '&first=' + first, type + 'CommentPane', null, null, '');
}

var selectedCalendarTab = null;
function selTab(tab) {
	if(selectedCalendarTab == null) selectedCalendarTab = 'my';

	var curTab = dynamItElem(selectedCalendarTab + 'tab');
	var curPane = dynamItElem(selectedCalendarTab + 'Events');

	curTab.className = 'offtab';
	curPane.style.display = 'none';

	var newTab = dynamItElem(tab + 'tab');
	var newPane = dynamItElem(tab + 'Events');

	newTab.className = 'ontab';
	newPane.style.display = 'block';

	selectedCalendarTab = tab;
}

function checkMessageForm(f) {

	var rv = true;
	var m = '';

	if(!f.to.value.length) {
		m += 'Please select a recipient.' + "\n";
		rv = false;
	}

	if(!f.subject.value.length) {
		m += 'Please enter a subject for this message.' + "\n";
		rv = false;
	}
	if(!f.message.value.length) {
		m += 'Your message is blank. Please enter text in the message.' + "\n";
		rv = false;
	}

	if(!rv) {
		alert(m);
		return false;
	}

	return true;

}

function checkFormSimple(f, field, message) {
	if(f.submitter) f.submitter.disabled = true;

	var val = eval('f.' + field + '.value');

	if(!val.length) {
		alert(message);
		if(f.submitter) f.submitter.disabled = false;
		return false;
	}

	return true;

}

function checkEventForm(f) {

	if(f.submitter) f.submitter.disabled = true;

	var rv = true;
	var m = '';

	var start = f.start_year.value + f.start_month.value + f.start_day.value + str_replace(':', '', f.start_time.value);
	var end = f.end_year.value + f.end_month.value + f.end_day.value + str_replace(':', '', f.end_time.value);

	if(!f.title.value.length) {
		m += 'Please enter a title for this event.' + "\n";
		rv = false;
	}

	if(end < start) {
		m += 'Error: end time occurs before start time.' + "\n";
		rv = false;
	}

	if(!rv) {
		alert(m);
		if(f.submitter) f.submitter.disabled = false;
		return false;
	}

	return true;

}

	function checkRegisterForm(f) {

		var rv = true;
		var m = '';
		if(!f.name.value.length) {
			m += 'Please enter your name.' + "\n";
			rv = false;
		}

		if(f.region.value <= 0 || !f.region.value.length) {

			m += 'Please select a region.' + "\n";
			rv = false;
		}

		if(!f.pass1.value.length) {

			m += 'Please enter a password.' + "\n";
		}

		if(f.pass1.value != f.pass2.value) {

			m += 'Passwords do not match.' + "\n";
			rv = false;
		}

		if(!usernameOK) {
			m += 'The username you have selected is already in use. Please try another.' + "\n";
			rv = false;
		}

		if(!uniqueEmail) {
			m += 'This e-mail address is already in use. Please try another.' + "\n";
			rv = false;
		}


		if(!rv) { alert(m); }
		return rv;

	}

function deleteMyAccount(id) {
	dynamItSendOnConfirm('index.php?dynamItAction=member.deleteaccount&user_id=' + id + '&confirm=yes', 'Are you sure you wish to completely delete your ElectionU account? ALL OF YOUR DATA WILL BE LOST AND YOU CANNOT UNDO THIS ACTION.');
}