var validate = new Array();
// Usage:  validate["<form id>"] = <regex test>
validate["Email"] = /^([a-zA-Z0-9_\.\-\+])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
validate["Name"] = /^(.)+$/; // not blank
//validate["Sample1"] = /^(.)+$/;
//validate["Bio"] = /^(.)+$/;

function highlight_field(elem, onoff) {
	if (onoff == "on") {
		document.getElementById(elem).style.backgroundColor = '#FEFF6F';
		document.getElementById(elem).style.border = '1px solid #FF0000';
	} else {
		document.getElementById(elem).style.backgroundColor = '';
		document.getElementById(elem).style.border = '';
	}
}

function Apply() {
	var validation_error = false;
	for (var field_name in validate) {
		if (! validate[field_name].test(document.getElementById(field_name).value) ) {
			highlight_field(field_name,"on");
			validation_error = true;
		} else {
			highlight_field(field_name,"off");
		}	
	}

/*	//Work around for select box
	if (document.getElementById('BlogFor').selectedIndex == 0) {
		highlight_field('BlogFor','on');
		validation_error = true;
	} else {
		highlight_field('BlogFor','off');
	}
*/
	if (validation_error) {
		document.getElementById("resultsbox1error").innerHTML = '<div style="border: 2px solid #cccc00; background-color: #ffff99; color: #aa0000; font-weight: bold; padding: 6px;">Please correct the following problems and try sending your application again.</div>';
	} else {
		var postStr = '';
		postStr += 'Name=' + escape(document.getElementById('Name').value) + "&";
		postStr += 'Email=' + escape(document.getElementById('Email').value) + "&";
		postStr += 'Phone=' + escape(document.getElementById('Phone').value) + "&";
		postStr += 'State=' + escape(document.getElementById('State').value) + "&";
		postStr += 'Country=' + escape(document.getElementById('Country').value) + "&";
		postStr += 'Lang=' + escape(document.getElementById('Lang').value) + "&";
		postStr += 'BlogURL=' + escape(document.getElementById('Lang').value) + "&";
		var selObj = document.getElementById('BlogFor');
		postStr += 'BlogFor=' + escape(selObj.options[selObj.selectedIndex].value) + "&";
		postStr += 'Bio=' + escape(document.getElementById('Bio').value) + "&";
		postStr += 'Sample1=' + escape(document.getElementById('Sample1').value) + "&";
		postStr += 'Sample2=' + escape(document.getElementById('Sample2').value) + "&";
		postStr += 'Sample3=' + escape(document.getElementById('Sample3').value);
		document.getElementById('BloggerApply').value = 'Please wait...';
		document.getElementById('BloggerApply').disabled = true;

		postURL("submit.ajax.php", postStr);
	}

}
function submitFormOK(submit_result) {
	document.getElementById("resultsbox1").innerHTML = submit_result;
}