function submitForm(){
	// check required fields
	pass = true;
	for (i=0; i<req.length; i++){
		obj = document.getElementById(req[i]+'_Id');
		switch (obj.type){
			case 'checkbox':
				stat = pass = obj.checked;
				break;
			default:
				val = trim(obj.value);
				stat = true;
				if (!val || val==null || val == '') stat = pass = false;
				break;
		}
		st = (stat) ? '#F3F3EC' : '#FF7CB6';
		document.getElementById(req[i]+'_row1').style.background = st;
		document.getElementById(req[i]+'_row2').style.background = st;
	}	
	
	
	if (pass) document.apply_form.submit();
	else {
		alert ('Fields marked in red are required!');
		return false;
	}
}

function trim(str) {
	return str.replace(/^\s+|\s+$/g,"");
}

function imposeMaxLength(obj, charsLeftSpanId) {
	var objectMaxLength = obj.getAttribute('maxlength');
	var charsLeftEl = document.getElementById(charsLeftSpanId);
	
	if (obj.value.length > objectMaxLength) {
		obj.value = obj.value.substring(0, objectMaxLength);
	} 
	else {
		if (objectMaxLength - obj.value.length == 0) {
			charsLeftEl.innerHTML = '<font color="red">(0)</font>';
		} else {
			charsLeftEl.innerHTML = "(" + (objectMaxLength - obj.value.length) + ")";
		}
	}
}

function adjustChannel(preselectChannel){
	net = document.getElementById('NETWORK_Id').value;
	rStyle = (navigator.appName.indexOf("Microsoft") > -1) ? "block" : "table-cell";
	switch (net){
		case 'Tinker':
			aud = 'Tinker';
			break;
	} 
	
	// hide/show audience question
	document.getElementById('AUDIENCE_row1').style.display = rStyle;
	document.getElementById('AUDIENCE_row2').style.display = rStyle;
	
	// manipulate the name
	document.getElementById('AUDIENCE_row1').innerHTML = aud;

    // clean-up channe;
    obj = document.getElementById('CHANNEL_Id');
    optCont = obj.options;
    for (i = optCont.length; i >= 0; --i) optCont[i] = null;
	
	// populate channel
	for (i=0; i<channels[net].length; i++){
		text = channels[net][i]['text'];
		value = channels[net][i]['value'];
		selected = (preselectChannel == value) ? true : false;
		obj.options[i] = new Option(text, value, selected, selected);
	}
}


