

/* window scripts */

function closeIt() {
	window.close(self);
}

/* Form Validation */

function isEmpty(strng) {
var error = "";
  if (strng.length == 0) {
	 error = "A mandatory field has not been filled in.\n"
  }
return error;	  
}

function checkEmail (strng) {
	var error="";
	if (strng == "") {
	   error = "You didn't enter an email address.\n";
	}

	var emailFilter=/^.+@.+\..{2,3}$/;
	
	if (!(emailFilter.test(strng))) { 
	   error = "Please enter a valid email address.\n";
	} else {
		//test email for illegal characters
		var illegalChars= /[\(\)\<\>\,\;\:\\\"\[\]]/
		if (strng.match(illegalChars)) {
			error = "The email address contains illegal characters.\n";
		}
	}
	return error;    
}

function checkForm(theForm) {
	var why = "";
	why += checkEmail(theForm.email.value);
	why += isEmpty(theForm.name.value);
	why += isEmpty(theForm.city.value);
	if (why != "") {
	   alert(why);
	   return false;
	}
return true;
}


/* Ajax Scripts (requires ajax_scripts.js) */

function get(btn,action,from) {
  //var poststr = "mytextarea1=" + encodeURI( document.getElementById("mytextarea1").value ) +
	//			"&mytextarea2=" + encodeURI( document.getElementById("mytextarea2").value );
  // var poststr = encodeURI(message) + encodeURI(from);
  if(checkForm(from)) {
	  poststr = "name=" + encodeURI(from.name.value);
	  poststr += "&city=" + encodeURI(from.city.value);
	  poststr += "&email=" + encodeURI(from.email.value);
	  	  
	  if(from.show_public.checked) {
			poststr += "&show_public=" + encodeURI(from.show_public.value);
	  } else {
			poststr += "&show_public=0";
	  }
	  
	  makePOSTRequest(btn, action, poststr);
	}
}



