function record (type,id,val,web) {
	var myConn = new XHConn();
	if (!myConn) alert("XMLHTTP not available. Try a newer/better browser.");
	var fnWhenDone = function (oXML) { eval(oXML.responseText); };
	myConn.connect("/log.php", "POST", "type="+type+"&id="+id+"&val="+val+"&web="+web, fnWhenDone);
	
}
function submit_form(fobj,form_name) {
	cnt = 0;
	get_string = gettheFormValues(fobj)
	the_string = get_string.toString();
	var a=the_string.indexOf('Form Error');
	if (a == 0) { // Form has errors
		alert(get_string + "\n\n");
	}
	else { // Submit the call
		//alert(the_string);
		document.forms[form_name].submit();
	}
}
function gettheFormValues(theForm)
{
	var textData = "";
	var required = "";
   for(i=0; i<theForm.elements.length; i++){
   	  var mySplit = theForm.elements[i].name.split("_r_");
   	  if (mySplit[1]) {required = required + check_field(theForm.elements[i].value,mySplit[1],theForm.elements[i].name,theForm.elements[i].checked);}
      if(theForm.elements[i].type == "text" || theForm.elements[i].type == "textarea" || theForm.elements[i].type == "password" || theForm.elements[i].type == "hidden"){
      textData += theForm.elements[i].name + "=" + theForm.elements[i].value + "&"
      }
      else if(theForm.elements[i].type == "checkbox" || theForm.elements[i].type == "radio"){
      textData += theForm.elements[i].name + "=" + theForm.elements[i].value + "&"
      }
      else if(theForm.elements[i].type == "select-one"){
      textData += theForm.elements[i].name + "=" + theForm.elements[i].options[theForm.elements[i].selectedIndex].text + "&"
      }  
	  else if(theForm.elements[i].type == "select-multiple") {
			for(var x=0; x < theForm.elements[i].length; x++) {
				if(theForm.elements[i][x].selected == true) {
					textData += theForm.elements[i].name + "=" + theForm.elements[i][x].value + "&";
				}
			}
	  }
   }
   if (required) {
   	return "Form Error(s):\n\n" + required;
   }
   else {
   	return textData
   }
}

function check_field(val,what,named,check) {
	cnt = cnt + 1;
	if (what == "text") { // Just see if they have filled something in
		if (val == "" || val == null) {
			var named = named.replace(/_r_text/i,'');
			var named = named.replace(/_/g,' ');
			return cnt + ") " + named + " must be filled in\n";
		}
		cnt = cnt - 1;
	}
	else if (what == "checked") { // Just see if they have filled something in
		if (check == false || check == "" || check == null || check == "undefined") {
			var named = named.replace(/_r_checked/i,'');
			var named = named.replace(/_/g,' ');
			return cnt + ") " + named + " must be filled in\n";
		}
		cnt = cnt - 1;
	}
	else if (what == "email") { // Check the value is a valid email address
		var em = val.toString();
		if (em.indexOf("@") == -1 || em.indexOf(".") == -1 || val == "" || val == null) {
			var named = named.replace(/_r_email/i,'');
			var named = named.replace(/_/g,' ');
			return cnt + ") " + named + " must be a valid email address\n";
		}
		cnt = cnt - 1;
	}
	return ""; // Passed the checks
}
function showtown(file,county,sel,req) {
	var myConn = new XHConn();
	if (!myConn) alert("XMLHTTP not available. Try a newer/better browser.");
	var fnWhenDone = function (oXML) { document.getElementById('town_select_span').innerHTML = oXML.responseText; };
	myConn.connect("/" + file, "POST", "county="+county+"&sel="+sel+"&req="+req, fnWhenDone);
}
function showtown_2(file,county,sel,req) {
	var myConn = new XHConn();
	if (!myConn) alert("XMLHTTP not available. Try a newer/better browser.");
	var fnWhenDone = function (oXML) { document.getElementById('town_select_span_2').innerHTML = oXML.responseText; };
	myConn.connect("/" + file, "POST", "county="+county+"&sel="+sel+"&req="+req, fnWhenDone);
}
function show_town(file,county,sel,req) {
  	if (county == "") {
		document.getElementById('town_select_span').innerHTML = 'Please select county / area';
	}
	else {
		new Ajax.Updater('town_select_span', file, {
			method: 'post' ,
			parameters: {county:county,sel:sel,req:req},
			asynchronous:true,
			evalScripts:true
			}
		);
	}
  }