errArr[99] = 'Please select at least one subscription list';
errArr[98] = 'Auxilliary details are required to subscribe to a bids list';
errArr[97] = 'The email you provided is already in the system';

function checkAll(x) {
	var id = x.id.replace(/group/,'');
	var b = $('list'+id);
	var a = b.getElementsByTagName('input');
	var i, c;
	c = false;
	
	for (i = 0; i < a.length; i++) {
		if (a[i].checked) {
			c = true;
			break;
		}
	}
	
	c = c == true ? false : true;
	x.checked = c;
	
	for (i = 0; i < a.length; i++) {
		a[i].checked = c;
	}
}

function confChk(x,p) {
	if (x.checked == false && $('group'+p).checked == true) $('group'+p).checked = false;
}

function subs() {
	var b = $('form');
	var a = b.getElementsByTagName('input');
	var i;
	for (i = 0; i < a.length; i++) {
		if (a[i].type == 'checkbox') {
			if (a[i].checked) return;
		}
	}
	apnd();
	errStr += 99;
}

function ckBids() {
	// Check For Bids List
	var b = $('list6');
	var a = b.getElementsByTagName('input');
	var i;
	for (i = 0; i < a.length; i++) {
		if (a[i].checked) return true;
	}
	return false;
}
	
function signUp(button) {
	var q = 'email=' + $('email').value+'&req='+Math.random();
	q = encodeURI(q);
	var objAjax = new getAjaxObj();
	objAjax.onreadystatechange = function() {
		if (objAjax.readyState == 4) {
			if (objAjax.responseText != '101 - OK') {
				$('emailCK').innerHTML = objAjax.responseText;
				$('emailCK').className = 'alert';
				apnd()
				idStr += 'email';
				errStr += 97;
			} else {
				$('emailCK').className = 'hide';
			}
			completeSignUp(button);
		}
	}
	objAjax.open('POST','AJAX.ckEmail.asp',true);
	objAjax.setRequestHeader('Content-type','application/x-www-form-urlencoded');
	objAjax.setRequestHeader('Content-length',q.length);
	objAjax.setRequestHeader('Connection','close');
	objAjax.send(q);
}

function completeSignUp(button) {
	if (ckBids()) {
		var ih = $('bids').innerHTML;
		if (ih.indexOf('<table') == -1 && ih.indexOf('<TABLE') == -1) {
			useForm('','edit/CTR.aux.asp','bids');
			apnd();
			errStr += 98;
		}
	} else {
		$('bids').innerHTML = '';
	}
	
	subs();
	
		
	alert("In order to prevent spam filters from intercepting emails from the City of Iowa City, please add " +
		  "webmaster@iowa-city.org to your address book. If you have subscribed to any bid lists, you will " +
		  "also want to add ServicesUpForBid@iowa-city.org.\n\n" +
		  "You may do so now. The confimation mail won't be sent until you press 'OK'.");
	
	getForm('form','edit/AJAX.saveUpdate.asp');
	if (!errTripped) {
		button.disabled = true;
		button.value = 'saving details...';
		toTop();
	}
}

function sendLink(x) {
	getForm('form','edit/AJAX.default.asp');
	if (!errTripped) {
		x.disabled = true;
		x.value = 'Sending link...';
	}
}
