
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 getCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i = 0; i < ca.length; i++)
	{
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		//alert(c); 
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

// detect whether cookie is set. If so, display download links; if not, display form
 //window.onload = function() {
 // calcRegForm = MM_findObj("calcRegForm");
 // calcRegLinks = MM_findObj("calcRegLinks");
 // 
 // cookieValue = getCookie('cacpCalcID');
 // alert("cookieValue = " + cookieValue);
 // if (cookieValue == null) {
 //   calcRegLinks.style.display = "hidden";
 // } else {
 //   calcRegForm.style.display = "hidden";
 // }
//}

function check_calc_reg_form() {
	error_message = "";

	contact_first_name = document.calc_reg_form.contact_first_name.value;
	contact_last_name  = document.calc_reg_form.contact_last_name.value ;
	organization       = document.calc_reg_form.organization.value ;
	title		       = document.calc_reg_form.title.value ;
	contact_address    = document.calc_reg_form.contact_address.value;
	contact_city       = document.calc_reg_form.contact_city.value   ;
	contact_state      = document.calc_reg_form.contact_state.value  ;
	contact_zip        = document.calc_reg_form.contact_zip.value    ;
	contact_e_mail     = document.calc_reg_form.cacpSToCCID.value ;
	contact_phone      = document.calc_reg_form.contact_phone.value  ;
	terms			   = document.calc_reg_form.terms ;
	
	if (contact_first_name == "") { error_message = error_message + " - the First Name field was empty\n"; }
	if (contact_last_name  == "") { error_message = error_message + " - the Last Name field was empty\n";  }
	if (organization    == "") { error_message = error_message + " - the Organization field was empty\n";         }
	if (title		    == "") { error_message = error_message + " - the Title field was empty\n";         }
	if (contact_address == "") { error_message = error_message + " - the Contact Address field was empty\n";         }
	if (contact_city    == "") { error_message = error_message + " - the Contact City field was empty\n";            }
	if (contact_state   == "") { error_message = error_message + " - the Contact State/Province field was empty\n";  }
	if (contact_zip     == "") { error_message = error_message + " - the Contact Zip/Postal Code field was empty\n"; }
	if (contact_e_mail  == "") { error_message = error_message + " - the Contact Email field was empty\n";          }
	if (contact_phone   == "") { error_message = error_message + " - the Contact Phone field was empty\n";           }
	if (terms[0].checked == false) {
		error_message = error_message + " - You must agree to the Terms and Conditions to continue\n";
	}

	if (error_message != "") {
		error_display = "There was an error in your registration form:\n\n" + error_message;
		alert (error_display);
		return false;

	}	else {
		return true;
	}
}
