function checkCalendarSubmit(calitem)  {
   if (calitem.msubmitter.value=="")  {
      alert("Please enter your name so we can contact you if necessary.");
      calitem.msubmitter.focus();
      return false;
   }
   if (calitem.msubphone.value=="")  {
      alert("Please enter your phone number so we can contact you if necessary.");
      calitem.msubphone.focus();
      return false;
   }
   if (calitem.msubemail.value=="")  {
      alert("Please enter your email so we can contact you if necessary.");
      calitem.msubemail.focus();
      return false;
   }
   if (calitem.msmonth.value=="none")  {
      alert("Please enter a valid start date.");
      calitem.msmonth.focus();
      return false;
   }
   if (calitem.msday.value=="none")  {
      alert("Please enter a valid start date.");
      calitem.msday.focus();
      return false;
   }
   if (calitem.msyear.value=="none")  {
      alert("Please enter a valid start date.");
      calitem.msyear.focus();
      return false;
   }
   if (calitem.memonth.value=="none")  {
      alert("Please enter a valid end date.");
      calitem.memonth.focus();
      return false;
   }
   if (calitem.meday.value=="none")  {
      alert("Please enter a valid end date.");
      calitem.meday.focus();
      return false;
   }
   if (calitem.meyear.value=="none")  {
      alert("Please enter a valid end date.");
      calitem.meyear.focus();
      return false;
   }
   if (calitem.msmonth.value=="02" && (calitem.msday.value=="30" || calitem.msday.value=="31"))  {
      alert("Please enter a valid start date.");
      calitem.msday.focus();
      return false;
   }
   if (calitem.msmonth.value=="02" && calitem.msyear.value!="2008" && calitem.msyear.value!="2012" && calitem.msyear.value!="2016" && calitem.msday.value=="29")  {
      alert("Please enter a valid start date.");
      calitem.msday.focus();
      return false;
   }
   if ((calitem.msmonth.value=="04" || calitem.msmonth.value=="06" || calitem.msmonth.value=="09" || calitem.msmonth.value=="11") && calitem.msday.value=="31")  {
      alert("Please enter a valid start date.");
      calitem.msday.focus();
      return false;
   }
   if (calitem.memonth.value=="02" && (calitem.meday.value=="30" || calitem.meday.value=="31"))  {
      alert("Please enter a valid end date.");
      calitem.meday.focus();
      return false;
   }
   if (calitem.memonth.value=="02" && calitem.meyear.value!="2008" && calitem.meyear.value!="2012" && calitem.meyear.value!="2016" && calitem.meday.value=="29")  {
      alert("Please enter a valid end date.");
      calitem.meday.focus();
      return false;
   }
   if ((calitem.memonth.value=="04" || calitem.memonth.value=="06" || calitem.memonth.value=="09" || calitem.memonth.value=="11") && calitem.meday.value=="31")  {
      alert("Please enter a valid end date.");
      calitem.meday.focus();
      return false;
   }
   if (calitem.meventtype.value=="none")  {
      alert("Please choose an Event Type.");
      calitem.meventtype.focus();
      return false;
   }
   if (calitem.meventtitle.value=="")  {
      alert("Please enter a title for the event.");
      calitem.meventtitle.focus();
      return false;
   }
//   if (calitem.mshortdesc.value=="")  {
//      alert("Please enter a short description for the event.");
//      calitem.mshortdesc.focus();
//      return false;
//   }
   if (!calitem.mspecneeds[0].checked && !calitem.mspecneeds[1].checked)  {
      alert("Please say if your venue accomodates children with special needs.");
      calitem.mspecneeds[0].focus();
      return false;
   }
   if (!calitem.mspecneedsdays[0].checked && !calitem.mspecneedsdays[1].checked)  {
      alert("Please say if your venue hosts specific days for children with special needs.");
      calitem.mspecneedsdays[0].focus();
      return false;
   }

   return true;
}

function checkSNDirSubmit(diritem)  {
   if (diritem.mprcontactname.value=="")  {
      alert("Please enter a contact name for this submission.  We will not publish this information.");
      diritem.mprcontactname.focus();
      return false;
   }
   if (diritem.mpremail.value=="")  {
      alert("Please enter a contact email for this submission.  We will not publish this information.");
      diritem.mpremail.focus();
      return false;
   }
   if (diritem.mprname.value=="")  {
      alert("Please enter the name of your organization.");
      diritem.mprname.focus();
      return false;
   }
   if (diritem.mprcity.value=="")  {
      alert("Please enter the city for your organization.");
      diritem.mprcity.focus();
      return false;
   }
   if (diritem.mprphone.value=="")  {
      alert("Please enter a phone number for your organization.");
      diritem.mprphone.focus();
      return false;
   }
   if (!Checkcatboxes(diritem))  {
      return false;
   }
   if (diritem.mcatother1.checked && diritem.mcatother2.value=="")  {
      alert("Please either enter a description for your Service Category, or uncheck the Other box.");
      diritem.mcatother2.focus();
      return false;
   }
   if (diritem.mconother1.checked && diritem.mconother2.value=="")  {
      alert("Please either enter a description for your Condition Served, or uncheck the Other box.");
      diritem.mconother2.focus();
      return false;
   }
   return true;
}

function checkforward(adv)  {
   if (adv.mremail.value=="")  {
      alert("Please enter an Email for your friend to receive this article.");
      adv.mremail.focus();
      return false;
   }
   if (adv.msender.value=="")  {
      alert("Please enter your name so your friend will know who is sending this article.");
      adv.msender.focus();
      return false;
   }
   if (adv.msemail.value=="")  {
      alert("Please enter your email so your friend will know who is sending this article.");
      adv.msemail.focus();
      return false;
   }
   return true;
}

function checkAcctInfo(mreg)  {
   if (mreg.mfname.value=="")  {
      alert("Please enter your first and last name.");
      mreg.mfname.focus();
      return false;
   }
   if (mreg.mlname.value=="")  {
      alert("Please enter your first and last name.");
      mreg.mlname.focus();
      return false;
   }
   if (mreg.mzipcode.value=="")  {
      alert("Please enter your ZIP code.");
      mreg.mzipcode.focus();
      return false;
   }
   if (mreg.memail.value=="")  {
      alert("Please enter your email address.");
      mreg.memail.focus();
      return false;
   }
   if (!(mreg.memail.value==mreg.cemail.value))  {
      alert("Please enter the same email for the Email box and the Confirm Email box to ensure that it is correct.");
      mreg.memail.focus();
      return false;
   }
   if (mreg.mcpassword.value=="")  {
      alert("Please enter your account password.");
      mreg.mcpassword.focus();
      return false;
   }
   if (!(mreg.mcpassword.value==mreg.mcpassword2.value))  {
      alert("Your passwords do not match.  We ask that you type the same password twice to ensure accuracy.");
      mreg.mcpassword.focus();
      return false;
   }
   return true;
}


function checkBarney(entry)  {
   if (entry.cafriends.value=="")  {
      alert("Please enter the name of one of Barney's friends.");
      entry.cafriends.focus();
      return false;
   }
   if (!entry.cacolor[0].checked && !entry.cacolor[1].checked && !entry.cacolor[2].checked)  {
      alert("Please choose an answer for Barney's favorite color.");
      entry.cacolor[0].focus();
      return false;
   }
   if (!entry.cafood[0].checked && !entry.cafood[1].checked && !entry.cafood[2].checked && !entry.cafood[3].checked)  {
      alert("Please choose an answer for Barney's favorite food.");
      entry.cafood[0].focus();
      return false;
   }
   return true;
}

function checkMakeover(entry)  {
   if (entry.contestant.value=="")  {
      alert("Please enter the name of the person deserving the makeover.");
      entry.contestant.focus();
      return false;
   }
   if (entry.mmfile.value=="")  {
      alert("Please upload a current picture of the contestant.");
      entry.mmfile.focus();
      return false;
   }
   if (entry.mmessay.value=="")  {
      alert("Please enter a 250 word or less description as to why you think the contestant deserves a makeover.");
      entry.mmessay.focus();
      return false;
   }
   return true;
}

function checkDiaries(entry)  {
   if (entry.contestant.value=="")  {
      alert("Please enter your name.");
      entry.contestant.focus();
      return false;
   }
   if (entry.mphone.value=="")  {
      alert("Please enter youre phone number.");
      entry.mphone.focus();
      return false;
   }
   if (entry.mmfile.value=="")  {
      alert("Please upload a current picture of yourself.");
      entry.mmfile.focus();
      return false;
   }
   var filext = entry.mmfile.value.substring(entry.mmfile.value.length-4,entry.mmfile.value.length);
   if (filext != ".jpg" && filext != ".JPG" && filext != ".gif" && filext != ".jpg") {
      alert("Your photo should be a JPG or GIF file and therefore end in either .jpg or .gif.");
      entry.mmfile.focus();
      return false;
   }
   if (entry.mwfile.value=="")  {
      alert("Please upload a Microsoft Word document containing your diary.");
      entry.mwfile.focus();
      return false;
   }
   return true;
}

function checkKomen(entry)  {
   if(entry.mshirtsize.value=="none")  {
      alert("Please choose a shirt size");
      entry.mshirtsize.focus();
      return false;
   }
   return true;
}

function checkRockstar(entry)  {
   if(entry.maddress.value=="")  {
      alert("Please enter your address.");
      entry.maddress.focus();
      return false;
   }
   if(entry.mcity.value=="")  {
      alert("Please enter your city.");
      entry.mcity.focus();
      return false;
   }
   if(entry.mstate.value=="")  {
      alert("Please enter your state.");
      entry.mstate.focus();
      return false;
   }
   if(entry.mzipcode.value=="")  {
      alert("Please enter your ZIP code.");
      entry.mzipcode.focus();
      return false;
   }
   if(entry.mphone.value=="")  {
      alert("Please enter your phone.");
      entry.mphone.focus();
      return false;
   }
//   if(entry.mmagwhere.value=="")  {
//      alert("Please tell us where you like to pick up our magazine.");
//      entry.mmagwhere.focus();
//      return false;
//   }
//   if(entry.mparentingissues.value=="")  {
//      alert("Please tell us the parenting issues most important to you.");
//      entry.mparentingissues.focus();
//      return false;
//   }
//   if (!entry.missuecontact[0].checked && !entry.missuecontact[1].checked)  {
//     alert("Please tell us whether you're willing to be contacted for comment on issues important to you.");
//      entry.missuecontact[0].focus();
//      return false;
//   }
//   if(entry.mfavsections.value=="")  {
//      alert("Please tell us your favorite sections of the magazine.");
//      entry.mfavsections.focus();
//      return false;
//   }
//   if (!entry.mreaderspanel[0].checked && !entry.mreaderspanel[1].checked)  {
//      alert("Please tell us if you're interested in joining our Readers Panel.");
//      entry.missuecontact[0].focus();
//      return false;
//   }
   if(entry.mfname.value=="")  {
      alert("Please enter your child's first name.");
      entry.mfname.focus();
      return false;
   }
   if(entry.mlname.value=="")  {
      alert("Please enter your child's last name.");
      entry.mlname.focus();
      return false;
   }
   if (!entry.mgender[0].checked && !entry.mgender[1].checked)  {
      alert("Please tell us if your child is a boy or a girl.");
      entry.mgender[0].focus();
      return false;
   }
   if (entry.mbmonth.value=="none")  {
      alert("Please enter the month of your child's birth.");
      entry.mbmonth.focus();
      return false;
   }
   if (entry.mbday.value=="0")  {
      alert("Please enter the day of your child's birth.");
      entry.mbday.focus();
      return false;
   }
   if (entry.mbyear.value=="0")  {
      alert("Please enter the year of your child's birth.");
      entry.mbyear.focus();
      return false;
   }
   if (entry.mbmonth.value=="02" && (entry.mbday.value=="30" || entry.mbday.value=="31"))  {
      alert("Please enter a valid birth date.");
      entry.mbday.focus();
      return false;
   }
   if (entry.mbmonth.value=="02" && entry.mbyear.value!="2008" && entry.mbyear.value!="2004" && entry.mbyear.value!="2000" && entry.mbyear.value!="1996" && entry.mbyear.value!="1992" && entry.mbday.value=="29")  {
      alert("Please enter a valid birth date.");
      entry.mbday.focus();
      return false;
   }
   if ((entry.mbmonth.value=="04" || entry.mbmonth.value=="06" || entry.mbmonth.value=="09" || entry.mbmonth.value=="11") && entry.mbday.value=="31")  {
      alert("Please enter a valid birth date.");
      entry.mbday.focus();
      return false;
   }
   if (entry.mbyear.value=="2008")  {
      alert("We are only considering children between the ages of 1 and 12.  Please enter children only over one year of age.");
      mentry.mbyear.focus();
      return false;
   }
//   if(entry.mheight.value=="")  {
//      alert("Please enter your child's height.");
//     entry.mheight.focus();
//      return false;
//   }
//   if(entry.meyes.value=="")  {
//      alert("Please enter your child's eye color.");
//      entry.meyes.focus();
//      return false;
//   }
//   if(entry.mclothessize.value=="")  {
//      alert("Please enter your child's clothes size.");
//      entry.mclothessize.focus();
//      return false;
//   }
//   if (!entry.mapptpref[0].checked && !entry.mapptpref[1].checked)  {
//      alert("Please provide us your preferred appointment time of day.");
//     entry.mapptpref[0].focus();
//      return false;
//   }
   if (!entry.mpreviouslyattend[0].checked && !entry.mpreviouslyattend[1].checked)  {
      alert("Please tell us if you have ever attended one of our events before.");
      entry.mpreviouslyattend[0].focus();
      return false;
   }
   if (entry.mcontest.value=="none")  {
      alert("Please select a contest for your child to enter.");
      entry.mcontest.focus();
      return false;
   }
   if (entry.mcontest.value=="Child-Instrument")  {
     if (entry.minstrument.value=="none")  {
        alert("Please select an instrument or change your contest to Vocal.");
        entry.minstrument.focus();
        return false;
     }
   }
//   if (entry.mmfile.value=="")  {
//      alert("Please upload a current picture of your child.");
//      entry.mmfile.focus();
//      return false;
//   }
   return true;
}

function checkCreditCard(order) {

    var data = order;
    var userInfo = "";
    var now = new Date();
    var month = now.getMonth()+1;
    var year = now.getYear();    // gives 2005
    card_type = data.credit_card.value;
    exp_month_index = data.month.selectedIndex;
    exp_year_index = data.year.selectedIndex;

    if (data.credit_card.value=="none") {
        alert("You have not selected a credit card type");
        data.credit_card.focus();
        return false;
    }

    if (data.card_number.value == "") {
        alert("You have not filled in the Credit Card Number");
        data.card_number.focus();
        return false;
    }

    if (data.card_name.value == "") {
        alert("Please provide your name exactly as it appears on your credit card");
        data.card_name.focus();
        return false;
    }

    if (data.month.value=="none") {
        alert("You have not selected an expiration date");
        data.month.focus();
        return false;
    }

    if (data.year.value=="none") {
        alert("You have not selected an expiration date");
        data.year.focus();
        return false;
    }

/*
		cvv = data.card_vnumber.value
    if (cvv == "") {
        alert("You have not filled in the Credit Card Verification Number");
        data.card_vnumber.focus();
        return false;
    }
		
		if (cvv.length != 3) {
        alert("The Credit Card Verification Number is the last three digits on the back of the Credit Card");
        data.card_vnumber.focus();
        return false;
    }
*/		
    var credit_filter1=/[0-9\s]{16,19}/;
    var credit_filter2=/[0-9]{13,16}/;
    
		
	  charset = "0123456789";
		card_num_hold = data.card_number.value;
		var card_num = "";
	  for (var i=0;i<card_num_hold.length;i++) {
		   c = card_num_hold.substr(i,1);
		   if (charset.indexOf(c)!= -1) {
         card_num += c;
		   }
    }


//    if (!validateCCNum(card_type,card_num) || !LuhnCheck(card_num)) {
    if (!validateCCNum(card_type,card_num)) {
      alert("Credit card number is not valid or you have selected incorrect type of credit card");
	    return false;    
	  }

    if (data.month.value < month && data.year.value <= year) {
      alert("Your Card has Expired");
      data.month.focus();
      return false;
    }            
    if(data.year.value < year) {
      alert("Your Card has Expired");
      data.year.focus();
      return false;
    }
    alert("We are processing your order.  After clicking OK in this box, simply wait for the Thank You page to display.  Do not click the Continue button again or refresh your browser as this may cancel your order.");
    return true;


}


function validateCCNum(cardType,cardNum)
{
	var result = false;
	cardType = cardType.toUpperCase();

	
	var cardLen = cardNum.length;
	var firstdig = cardNum.substring(0,1);
	var seconddig = cardNum.substring(1,2);
	var first4digs = cardNum.substring(0,4);
	switch (cardType)
	{
		case "VISA":
			result = ((cardLen == 16) || (cardLen == 13)) && (firstdig == "4");
			break;
		case "AMEX":
			var validNums = "47";
			result = (cardLen == 15) && (firstdig == "3") && (validNums.indexOf(seconddig)>=0);
			break;
		case "MASTERCARD":
			var validNums = "12345";
			result = (cardLen == 16) && (firstdig == "5") && (validNums.indexOf(seconddig)>=0);
			break;
		case "DISCOVER":
			result = (cardLen == 16) && (first4digs == "6011");
			break;
		case "DINERS":
			var validNums = "068";
			result = (cardLen == 14) && (firstdig == "3") && (validNums.indexOf(seconddig)>=0);
			break;
	}
	return result;
}

function LuhnCheck(str) 
{
  var result = true;

  var sum = 0; 
  var mul = 1; 
  var strLen = str.length;
  
  for (i = 0; i < strLen; i++) 
  {
    var digit = str.substring(strLen-i-1,strLen-i);
    var tproduct = parseInt(digit ,10)*mul;
    if (tproduct >= 10)
      sum += (tproduct % 10) + 1;
    else
      sum += tproduct;
    if (mul == 1)
      mul++;
    else
      mul--;
  }
  if ((sum % 10) != 0)
    result = false;
    
  return result;
}

function clearcard(form) 
{   
    form.reset();
    form.credit_card.focus();
}


function IsNumeric(sText)  {
   var ValidChars = "0123456789.";
   var IsNumber=true;
   var Char;
 
   for (i = 0; i < sText.length && IsNumber == true; i++) 
      { 
      Char = sText.charAt(i); 
      if (ValidChars.indexOf(Char) == -1) 
         {
         IsNumber = false;
         }
      }
   return IsNumber;
}

/**
 * DHTML date validation script. Courtesy of SmartWebby.com (http://www.smartwebby.com/dhtml/)
 */
// Declaring valid date character, minimum year and maximum year
var dtCh= "/";
var minYear=1900;
var maxYear=2100;

function isInteger(s){
	var i;
    for (i = 0; i < s.length; i++){   
        // Check that current character is number.
        var c = s.charAt(i);
        if (((c < "0") || (c > "9"))) return false;
    }
    // All characters are numbers.
    return true;
}

function stripCharsInBag(s, bag){
	var i;
    var returnString = "";
    // Search through string's characters one by one.
    // If character is not in bag, append to returnString.
    for (i = 0; i < s.length; i++){   
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }
    return returnString;
}

function daysInFebruary (year){
	// February has 29 days in any year evenly divisible by four,
    // EXCEPT for centurial years which are not also divisible by 400.
    return (((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0))) ? 29 : 28 );
}
function DaysArray(n) {
	for (var i = 1; i <= n; i++) {
		this[i] = 31
		if (i==4 || i==6 || i==9 || i==11) {this[i] = 30}
		if (i==2) {this[i] = 29}
   } 
   return this
}

function IsDate(dtStr){
	var daysInMonth = DaysArray(12)
	var pos1=dtStr.indexOf(dtCh)
	var pos2=dtStr.indexOf(dtCh,pos1+1)
	var strMonth=dtStr.substring(0,pos1)
	var strDay=dtStr.substring(pos1+1,pos2)
	var strYear=dtStr.substring(pos2+1)
	strYr=strYear
	if (strDay.charAt(0)=="0" && strDay.length>1) strDay=strDay.substring(1)
	if (strMonth.charAt(0)=="0" && strMonth.length>1) strMonth=strMonth.substring(1)
	for (var i = 1; i <= 3; i++) {
		if (strYr.charAt(0)=="0" && strYr.length>1) strYr=strYr.substring(1)
	}
	month=parseInt(strMonth)
	day=parseInt(strDay)
	year=parseInt(strYr)
	if (pos1==-1 || pos2==-1){
		// alert("The date format should be : mm/dd/yyyy")
		return false
	}
	if (strMonth.length<1 || month<1 || month>12){
		// alert("Please enter a valid month")
		return false
	}
	if (strDay.length<1 || day<1 || day>31 || (month==2 && day>daysInFebruary(year)) || day > daysInMonth[month]){
		// alert("Please enter a valid day")
		return false
	}
	if (strYear.length != 4 || year==0 || year<minYear || year>maxYear){
		// alert("Please enter a valid 4 digit year between "+minYear+" and "+maxYear)
		return false
	}
	if (dtStr.indexOf(dtCh,pos2+1)!=-1 || isInteger(stripCharsInBag(dtStr, dtCh))==false){
		// alert("Please enter a valid date")
		return false
	}
return true
}

function setAdminAddr(form) {
   if (form.admincontact.checked == true) 
   {
      form.b_name.value = form.c_name.value;
      form.b_address.value = form.c_address.value;
      form.b_city.value = form.c_city.value;
      form.b_state.selectedIndex = form.c_state.selectedIndex;
      form.b_zip.value = form.c_zip.value;
      form.b_phone.value = form.c_phone.value;
      form.b_email.value = form.c_email.value;
   }
//   else
//   {
//      form.b_name.value = "";
//      form.b_address.value = "";
//      form.b_city.value = "";
//      form.b_state.selectedIndex = 0;
//      form.b_zip.value = "";
//      form.b_phone.value = "";
//      form.b_email.value = "";
//   }
}  

