// advertise.js

// global variables
var msg ="Please make sure all the proper fields are filled.";

function submit_ad() {
	// first check fields
	var m = verify();
	
	if (m == true) {
		document.getElementById('advertiseform').submit();
	}
}

function verify() {
	with(document.advertiseform) {
		var missing = false;
		var exclude=/[^@\-\.\w]|^[_@\.\-]|[\._\-]{2}|[@\.]{2}|(@)[^@]*\1/;
		var check=/@[\w\-]+\./;
		var checkend=/\.[a-zA-Z]{2,3}$/;
		
		if(uword.value == "") {missing=true; msg="Please enter the code.";}
		if(company.value == "") {missing=true; msg="Please enter your company name.";}
		if(email.value == "") {missing=true; msg="Please enter your email address.";}
		if(name.value == "") {missing=true; msg="Please enter your name.";}
		if(getCheckedValue(term) == "" ) {missing=true; msg="Please choose a term.";}
		if(getCheckedValue(placement) == "") {missing=true; msg="Please choose an advertising slot.";}
		
		if (missing) {
			alert(msg);
			return false;
		}
		
	 	document.advertiseform.action = "advertise.cfm";
		return true;

	}
}


// return the value of the radio button that is checked
// return an empty string if none are checked, or
// there are no radio buttons
function getCheckedValue(radioObj) {
	if(!radioObj)
		return "";
	var radioLength = radioObj.length;
	if(radioLength == undefined)
		if(radioObj.checked)
			return radioObj.value;
		else
			return "";
	for(var i = 0; i < radioLength; i++) {
		if(radioObj[i].checked) {
			return radioObj[i].value;
		}
	}
	return "";
}

