/*
Ultimate Age calculator script- By JavaScript Kit (http://www.javascriptkit.com)
Over 200+ free scripts here!
Credit must stay intact for use
*/

var one_day=1000*60*60*24
var one_month=1000*60*60*24*30
var one_year=1000*60*60*24*30*12

function isAge13(yr, mon, day)
{
	//alert(yr+mon+day);
	var age = 0;
	age = calculateage(yr, mon, day, "years", 0, "rounddown");
	//alert(age);
	if(age >= 13)
	{   return true; }
	else 
	{
		alert('You must be at least 13 to register to use this site.');
		return false; 
	}
}

function calculateage(yr, mon, day, unit, decimal, round)
{
   today=new Date()
   var pastdate=new Date(yr, mon-1, day)

   var countunit=unit
   var decimals=decimal
   var rounding=round

   finalunit=(countunit=="days")? one_day : (countunit=="months")? one_month : one_year
   decimals=(decimals<=0)? 1 : decimals*10

   if (unit!="years")
   {
      if (rounding=="rounddown")
         document.write(Math.floor((today.getTime()-pastdate.getTime())/(finalunit)*decimals)/decimals+" "+countunit)
      else 
         document.write(Math.ceil((today.getTime()-pastdate.getTime())/(finalunit)*decimals)/decimals+" "+countunit)
   }
   else
   { // years
      yearspast=today.getFullYear()-yr-1
      tail=(today.getMonth()>mon-1 || today.getMonth()==mon-1 && today.getDate()>=day)? 1 : 0
      pastdate.setFullYear(today.getFullYear())
      pastdate2=new Date(today.getFullYear()-1, mon-1, day)
      tail=(tail==1)? tail+Math.floor((today.getTime()-pastdate.getTime())/(finalunit)*decimals)/decimals : Math.floor((today.getTime()-pastdate2.getTime())/(finalunit)*decimals)/decimals
      //document.write(yearspast+tail+" "+countunit)
	  return (yearspast+tail);
   }
}

//Sample usage
//displayage (year, month, day, unit, decimals, rounding)
//Unit can be "years", "months", or "days"
//Decimals specifies demical places to round to (ie: 2)
//Rounding can be "roundup" or "rounddown"

//displayage(1997, 11, 24, "years", 0, "rounddown")


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 MM_validateForm() 
{ //v4.0
   //alert('In MM_validateForm');
   var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
   var msg = 'The following error(s) occurred:\n';
   for (i=0; i<(args.length-2); i+=3) 
   { 
      test=args[i+2]; 
	  val=MM_findObj(args[i]);
      if (val) 
      { 
	     nm=val.name; 
	     if ((val=val.value)!="") 
	     {
            if (test.indexOf('isEmail')!=-1) 
		    { 
		       p=val.indexOf('@');
               if (p<1 || p==(val.length-1)) errors+='- '+nm+' must contain an e-mail address.\n';
            } else if (test!='R') 
		    { 
		       num = parseFloat(val);
               if (isNaN(val)) errors+='- '+nm+' must contain a number.\n';
               if (test.indexOf('inRange') != -1) 
		       { 
		          p=test.indexOf(':');
                  min=test.substring(8,p); max=test.substring(p+1);
                  if (num<min || max<num) errors+='- '+nm+' must contain a number between '+min+' and '+max+'.\n';
               } 
            } // END else if (test!='R')
         } else if (test.charAt(0) == 'R') errors += '- '+nm+' is required.\n'; 
      } // END if (val)
   } // END for  (i=0; i<(args.length-2); i+=3)

   if (document.form1.country.value == 47 || document.form1.country.value == 6)
   {
      //if(document.form1.zip.value == "") { msg += '- Postal Code required for U.S. or Canada.\n'; }
	  if(document.form1.zip.value == "") { errors += '- Postal Code required for U.S. or Canada.\n'; }
   }
   //if (errors) alert(msg+errors);
   if (errors) alert(errors);
   document.MM_returnValue = (errors == '');
} // END function MM_validateForm() 