function checkShare(oForm) {
	var incomplete=0;
	var alertMsg = "";
	var mailto = "";
	var mailtofound = 0;
	var emailerror = "";

	alertMsg = "The following fields are required:\n";

	if(allTrim(oForm.sendernamefirst.value) == "") {
			incomplete++;
			alertMsg = alertMsg +"First Name\n";
		}

	if(allTrim(oForm.sendernamelast.value) == "") {
			incomplete++;
			alertMsg = alertMsg +"Last Name\n";
		}

	if (allTrim(oForm.sendermail.value) == "") {
			incomplete++;
			alertMsg = alertMsg +"Your Email Address\n";
	} else {
			emailerror = checkEmail(allTrim(oForm.sendermail.value)); 
			if ( emailerror != "" ) {
				incomplete++;
				alertMsg = alertMsg +"Your Email address" + emailerror + "\n";
			}
	}
	

	for ( var i=0;i<oForm.mailto.length;i++ ) {
		if(allTrim(oForm.mailto[i].value) != "") {
			mailtofound = 1; // at least one email address was provided
			if ( allTrim(oForm.mailto[i].value) != "" ) {
				mailto = checkEmail(allTrim(oForm.mailto[i].value));
				if ( mailto != "" ) {
					incomplete++;
					alertMsg = alertMsg + "Your friends' Email addresses" + mailto + "\n";
				}
			}
		}
	}
	
	// if no email addresses were provided
	if ( mailtofound == 0 ) {
		incomplete++;
		alertMsg = alertMsg + "Your Friends' Email Addresses";
	}
	
	if (incomplete > 0){
		alert(alertMsg);
		return false;
	}
		
	return true;
	
}

function checkPoll(oForm) {
	var incomplete=0;
	var alertMsg = "";
	var atLeastOneSelected = 0;

	for (var i=0; i<oForm.elements.length; i++ ) {
		if ( oForm.elements[i].type == 'textarea' ){
			if ( oForm.elements[i].value != "" ) {
				atLeastOneSelected = 1;
			}
		}
		if ( oForm.elements[i].type == 'radio' ){
			if ( oForm.elements[i].checked == true ) {
				atLeastOneSelected = 1;
			}
		}
	}
	

	if ( atLeastOneSelected == 0 ) {
		incomplete++;
		alertMsg = "Please supply an answer for Poll & Forum and check the box near the bottom of the form indicating that you agree to the following conditions of posting to the Cascade.com website, or click the \"View Results Without Voting\" button to continue.";
	} else if ( oForm.useinfo.checked==false ) {
		incomplete++;
		alertMsg = "Please check the box near the bottom of the form indicating that you agree to the following conditions of posting to the Cascade.com website, or click the \"View Results Without Voting\" button at the top of the form to continue.";
	}

	if (incomplete > 0){
		alert(alertMsg);
		return false;
	}
		
	return true;
}


function checkEmail(addr) {
//  Will check for @, period after @ and text in between
	
	var error_msg = "";
	var in_space = addr.indexOf(" ");
	
	
	if (in_space != -1)	{ 
		error_msg= " should contain no spaces and be of the oForm.jdoe\@domain.com";
		return error_msg;  
	}

	var len = addr.length;
	var alpha = addr.indexOf("@");
	var last_alpha = addr.lastIndexOf("@");

	if (alpha != last_alpha) {  
		error_msg = " should contain only one @ and be of the oForm.jdoe\@domain.com";
		return error_msg; 
	}

	// No @, in first position, or name too short
	if (alpha == -1 || alpha == 0 || len<6 ) {  
		error_msg = " should contain an @ and be of the oForm.jdoe\@domain.com";
		return error_msg; 
	}

	var last_p = addr.lastIndexOf(".");
	// Be sure period at least two spaces after @, but not last char.
	if (last_p - alpha < 2 || last_p == (len - 1) )	{  
		error_msg = " should contain a period after the @ and be of the oForm.jdoe\@domain.com";
		return error_msg; }
				
	return error_msg;
	
}

function allTrim(cValue){
  var lDone=false;
  while (lDone==false){
    if (cValue.length==0) {return cValue;}
    if (cValue.indexOf(' ')==0){cValue=cValue.substring(1);lDone=false; continue;}
    else {lDone=true;}
    if (cValue.lastIndexOf(' ')==cValue.length-1){cValue=cValue.substring(0, cValue.length-1);lDone=false;continue;}
    else {lDone=true;}
  }
  return cValue;
}
function validRequired(formField)
{
	var result = true;
	if (formField.value == "")
	{
		//alert('Please enter a value for the "' + fieldLabel +'" field.');
		result = false;
	}

	return result;
}
function isZipUS(s) 
{
     /*
	  Check for correct zip code
     */
	 
	 var zipcode = trim(s);
	 var valid = "0123456789-";
	 var hyphencount = 0;
	 if (zipcode.length!=5 && zipcode.length!=10) {
		 //alert("Please enter your 5 digit or 5 digit+4 zip code.");
		 return false;
	 }
	 for (var i=0; i < zipcode.length; i++) {
		 temp = "" + zipcode.substring(i, i+1);
		 if (temp == "-") hyphencount++;
		 if (valid.indexOf(temp) == "-1") {
		 	//alert("Invalid characters in your zip code.  Please enter number values.");
		   	return false;
		 }
		 
		 if ((hyphencount > 1) || ((zipcode.length==10) && ""+zipcode.charAt(5)!="-")) {
			 	//alert("The hyphen character should be used with a properly formatted 5 digit+four zip code, like '12345-6789'.   Please try again.");
			    return false;
			}
	 }
	 return true;
} 

function trim(s) {
    while (s.substring(0,1) == ' ') {
      s = s.substring(1,s.length);
    }
    while (s.substring(s.length-1,s.length) == ' ') {
      s = s.substring(0,s.length-1);
    }
    return s;
}