function show_err(err_code)
{
    if(err_code==0){
        alert('The login Information you provided is incorrect');
    }
    if(err_code==2){
        alert('Your account is not active yet');
    }
}

// I removed www.backyardsports.com from the urls so that we can test it on the dev site - n : http://www.backyardsports.com

function popupSignin(from)
{
	if(from=='ast') {
    	MM_openBrWindow('/signin.php?from=ast','signin','width=500,height=325,resizable=yes,scrollbars=yes,toolbar=no,location=no,menubar=no');
    } else {
    	MM_openBrWindow('/signin.php','signin','width=500,height=325,resizable=yes,scrollbars=yes,toolbar=no,location=no,menubar=no');
    }
}
function popupRegister()
{
    MM_openBrWindow('/register.php','signin','width=500,height=330,resizable=yes,scrollbars=yes,toolbar=no,location=no,menubar=no');
}
function sel_month(valid_age)
{
	if($F('month')!='Month'){
		$('day').disabled=false;
	}else{
		$('day').disabled=true;
		$('day').options[0].selected=true;
		$('year').disabled=true;
		$('year').options[0].selected=true;
	}
        if (!valid_age) {
           sel_year();
        } else {
           sel_year(valid_age);
        }
	return false;
}
function sel_day(valid_age)
{
	if($F('day')!='Day'){
		$('year').disabled=false;
	}else{
		$('year').disabled=true;
		$('year').options[0].selected=true;
	}
        if (!valid_age) {
           sel_year();
        } else {
           sel_year(valid_age);
        }
	return false;
}
function sel_year(valid_age)
{
        if (!valid_age) {
            valid_age = 17;
        }
	if($F('year')!="Year"){
		var age = displayage($F('year'),$F('month'),$F('day'),"years",0,"rounddown");
		$('submit').disabled=false;
		if(age<=12){
			Element.show('pemail');
			Element.hide('parent_ok');
                        Element.hide('over');
			Element.hide('over2');
			$('email').disabled=false;
			$('pwd').disabled=false;
                        if($('privacy').checked == true)
                        {
                            $('submit').disabled=false;
                        }
                        else
                        {
                            $('submit').disabled=true;
                        }
		}else if(age>12){
			if(age<valid_age){
                                Element.show('over');
                                Element.show('pemail');
				Element.show('over2');
				Element.hide('parent_ok');
				$('email').disabled=false;
				$('pwd').disabled=false;
				if($('privacy').checked == true)
                                {
                                    $('submit').disabled=false;
                                }
                                else
                                {
                                    $('submit').disabled=true;
                                }
			}else if(age>=valid_age){
                                Element.hide('over');
                                Element.hide('pemail');
				Element.show('over2');
				Element.show('parent_ok');
				$('email').disabled=false;
				$('pwd').disabled=false;
                                if($('privacy').checked == true)
                                {
                                    $('submit').disabled=false;
                                }
                                else
                                {
                                    $('submit').disabled=true;
                                }
			}
		}
	}
	return false;
}
function privacy_check()
{
    if($F('year')!="Year" && $('privacy').checked)
    {
        $('submit').disabled=false;
    }
    else
    {
        $('submit').disabled=true;
    }
}

function privacy_check_parent()
{
    if($('privacy').checked)
    {
        $('submit').disabled=false;
    }
    else
    {
        $('submit').disabled=true;
    }
}
/*
age calculator
*/
var one_day=1000*60*60*24;
var one_month=1000*60*60*24*30;
var one_year=1000*60*60*24*365;
function displayage(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{
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
$('age').value = yearspast+tail;
return yearspast+tail;
//document.write(yearspast+tail+" "+countunit);
}
}
//displayage (year, month, day, unit, decimals, rounding)
//Unit can be "years", "months", or "days"
//displayage(1997, 11, 24, "years", 0, "rounddown")
// Registration Validation!
function configureValidation(f){
	//alert("configuring validation");
	var vage = displayage($F('year'),$F('month'),$F('day'),"years",0,"rounddown");
	//alert("calculated age:"+ vage);
	 	if(vage<=12){
			f.Email_Address.isEmail = true;
			f.Password.isLengthBetween = [4,12];
			f.First_Name.optional = true;
			f.Last_Name.optional = true;
			/*f.Address_1.optional = true;
			f.Address_2.optional = true;
			f.City.optional = true;
			f.State.optional = true;
			f.Zip.optional = true;
			f.Phone.optional = true;*/
			//alert("validate: under 12");
			
		}else if(vage>12){
			if(vage<17){
				f.Email_Address.isEmail = true;
				f.Password.isLengthBetween = [4,12];
				f.First_Name.isAlphaNumeric = true;
				f.Last_Name.isAlphaNumeric = true;
				/*f.Address_1.optional = true;
				f.Address_2.optional = true;
				f.City.isAlpha = true;
				f.State.isAlpha = true;
				f.Zip.isNumeric = true;
				f.Phone.isPhoneNumber = true;*/
				//alert("validate: over 12 under 17");
			}else if(vage>=17){
				f.Email_Address.optional = true;
				f.Password.optional = true;
				f.p_email.optional = true;
				f.First_Name.optional = true;
				f.Last_Name.optional = true;
				/*f.Address_1.optional = true;
				f.Address_2.optional = true;
				f.City.optional = true;
				f.State.optional = true;
				f.Zip.optional = true;
				f.Phone.optional = true;*/
				//alert("validate: over 12 under 17");
			}
			
		}
		f.Referal_Code.optional=true;
	
	if(validateForm(f)==false){
        //new Ajax.Updater("form",'common/common.php?action=doRegister&'+Form.serialize('register'),{method:'POST',evalScripts:true});
        //alert('false');
		return false;
	}else{    
        //new Ajax.Updater("form",'common/common.php?action=doRegister&'+Form.serialize('register'),{method:'POST',evalScripts:true});
        //alert('true');
        return false;
	}
}
//displayage (year, month, day, unit, decimals, rounding)
//Unit can be "years", "months", or "days"
//displayage(1997, 11, 24, "years", 0, "rounddown")
// Registration Validation!
function configureValidationPopWarner(f){
	//alert("configuring validation");
	var vage = displayage($F('year'),$F('month'),$F('day'),"years",0,"rounddown");
	//alert("calculated age:"+ vage);
	 	if(vage<=12){
			f.Email_Address.isEmail = true;
			f.Password.isLengthBetween = [4,12];
			f.Parent_Email.isEmail = true;
			/*f.First_Name.optional = true;
			f.Last_Name.optional = true;
			f.Address_1.optional = true;
			f.Address_2.optional = true;
			f.City.optional = true;
			f.State.optional = true;
			f.Zip.optional = true;
			f.Phone.optional = true;*/
			//alert("validate: under 12");
			
		}else if(vage>12){
			if(vage<21){
				f.Email_Address.isEmail = true;
				f.Password.isLengthBetween = [4,12];
				f.Parent_Email.isEmail = true;
				/*f.First_Name.isAlphaNumeric = true;
				f.Last_Name.isAlphaNumeric = true;
				f.Address_1.optional = true;
				f.Address_2.optional = true;
				f.City.isAlpha = true;
				f.State.isAlpha = true;
				f.Zip.isNumeric = true;
				f.Phone.isPhoneNumber = true;*/
				//alert("validate: over 12 under 21");
			}else if(vage>=21){
				f.Email_Address.isEmail = true;
				f.Password.isLengthBetween = [4,12];
				f.Parent_Email.optional = true;
				/*f.First_Name.optional = true;
				f.Last_Name.optional = true;
				f.Address_1.optional = true;
				f.Address_2.optional = true;
				f.City.optional = true;
				f.State.optional = true;
				f.Zip.optional = true;
				f.Phone.optional = true;*/
				//alert("validate: over 12 under 21");
			}
			
		}
		f.Referal_Code.optional=true;
	
	if(validateForm(f)==false){
        //new Ajax.Updater("form",'common/common.php?action=doRegister&'+Form.serialize('register'),{method:'POST',evalScripts:true});
        //alert('false');
		return false;
	}else{    
        //new Ajax.Updater("form",'common/common.php?action=doRegister&'+Form.serialize('register'),{method:'POST',evalScripts:true});
        //alert('true');
        return false;
	}
}
function submitform()
{
  document.vote.submit();
}
var curStep = 1;
function switchVote()
{
	if(curStep==1){     
    
        if($('vstep10').checked){
            alert('Please vote for your favorite before continuing');
        }else{
		curStep = 2;
		Element.hide('step1');
		Element.show('step2');
		Element.hide('step3');
		Element.hide('step4');
		Element.hide('step5');
		Element.hide('step6');
		Element.hide('step7');
        }
	} else if(curStep==2){
    if($('vstep20').checked){
            alert('Please vote for your favorite before continuing');
        }else{
		curStep = 3;
		Element.hide('step1');
		Element.hide('step2');
		Element.show('step3');
		Element.hide('step4');
		Element.hide('step5');
		Element.hide('step6');
		Element.hide('step7');
        }
	} else if(curStep==3){
    if($('vstep30').checked){
            alert('Please vote for your favorite before continuing');
        }else{
		curStep = 4;
		Element.hide('step1');
		Element.hide('step2');
		Element.hide('step3');
		Element.show('step4');
		Element.hide('step5');
		Element.hide('step6');	
		Element.hide('step7');	
        }
	} else if(curStep==4){
    if($('vstep40').checked){
            alert('Please vote for your favorite before continuing');
        }else{
		curStep = 5;
		Element.hide('step1');
		Element.hide('step2');
		Element.hide('step3');
		Element.hide('step4');
		Element.show('step5');
		Element.hide('step6');
		Element.hide('step7');
        }
	} else if(curStep==5){
    if($('vstep50').checked){
            alert('Please vote for your favorite before continuing');
        }else{
		curStep = 6;
		Element.hide('step1');
		Element.hide('step2');
		Element.hide('step3');
		Element.hide('step4');
		Element.hide('step5');
		Element.show('step6');
		Element.hide('step7');
        }
	} else if(curStep==6){
    if($('vstep60').checked){
            alert('Please vote for your favorite before continuing');
        }else{
		curStep = 7;
		Element.hide('step1');
		Element.hide('step2');
		Element.hide('step3');
		Element.hide('step4');
		Element.hide('step5');
		Element.hide('step6');
		Element.show('step7');
        }
	} else if(curStep==7){
		//doVote();
		submitform();
		//alert(Form.serialize('vote'));
		//alert("Vote Will Submit Here");
	}
}
function confirm_remove()
{
	return confirm('Are you SURE you want to remove your child\'s account?');
}
function forgot_pass(){
        opener.location = "/allstarteam/forgotpassword.php";
        self.close();
}

