/* JavaScript functions for venue submission forms -- added by joshuae (08/18/2007) */

function MM_displayStatusMsg(msgStr) { //v1.0
  status=msgStr;
  document.MM_returnValue = true;
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function control(x) {
	// reset validation errors -- added by joshuae (08/21/2007)
	validateReset();

	// validate each form field -- modified by joshuae (08/21/2007)
	if (document.getElementById('place').value == "") validatePrompt ("Please enter the name of this business");
	if (document.getElementById('region').value == 0) validatePrompt ("Please select the continent");
	if (document.getElementById('country').value == "") validatePrompt ("Please enter the Country Name");
	if (document.getElementById('state').value == "") validatePrompt ("Please enter the State or Province Name");
	if (document.getElementById('city').value == "") validatePrompt ("Please enter the City Name");
	if (document.getElementById('street_address1').value == "") validatePrompt ("Please enter the street address");
	if (document.getElementById('phone').value == "") validatePrompt ("Please enter the phone number");
	if (document.getElementById('price').value == 0) validatePrompt ("Please select the Price Range");
	if (document.getElementById('comments').value == "") validatePrompt ("Please enter some description of this business");
	if (document.getElementById('sender').value == "") validatePrompt ("Please enter your name");
	if (document.getElementById('sender_email').value == "") validatePrompt ("Please enter your email address");

	var validity_value = document.getElementById('validity').value;
	if (validity_value == "" || validity_value.length > 5 || validity_value.length < 5) validatePrompt ("Please enter the validation code");

	// get validation result and display error message, if needed -- added by joshuae (08/21/2007)
	return(validateResult());
}

var validate_error_string = "";

function validateReset() {
	// reset validation error string -- added by joshuae (08/21/2007)
	validate_error_string = "";
}

function validatePrompt(PromptStr) {
	// add string to validation error message -- modified by joshuae (08/21/2007)
	validate_error_string = validate_error_string + " - " + PromptStr + "\n";
}

function validateResult() {
	// check for error string and show alert box if needed -- added by joshuae (08/21/2007)
	if (validate_error_string != "") {
		alert("Please correct the following errors:\n\n"+validate_error_string);
		return(false);
	}
	return(true);
}
