
chkDate(1,2002,3,19,'sorry.html')

var byear,bmonth,bday;
var proceed = cookieChk();

function cookieChk(act) {

	var iaCookie = new Cookie(document,'IceAgeSweeps');
    isNow = new Date()
    tday = isNow.getDate()
    if (act == null) {
        if ( iaCookie.get() ) {
			/*if (!iaCookie.age) {
//				alert("Sorry you must 18 years of age or older to enter this sweepstakes.");
				document.location.href = "under18.html";
				return false;
			} else */if (iaCookie.day == tday) {
	            alert("Sorry, but you have already registered for this Sweepstakes. \nPlease come back tomorrow.");
   				document.location.href = "http://www.discovery.com/";
				return false;
        	} 
        }

		return true;
    }

    if (act == "set") {
        iaCookie.age = notMinor(byear,bmonth,bday)
        iaCookie.day = tday
        iaCookie.set();
		return iaCookie.age;
    }
}


function notMinor(yr,mo,dy) {
    var cday = new Date(1984,1,25); var dob = new Date(yr,(mo-1),dy);
//debug
//alert("entered notMinor: \nyr="+yr+"mo="+mo+"dy="+dy+"\ncday="+cday+"\ndob="+bday)
    if (cday.getTime() >= dob.getTime() ) {
		return true; //was born b4 feb 24, 1984
	} else {
		//alert("Sorry you must 18 years of age or older to enter this sweepstakes.")
		return false;
	}
}


var st="";
function chkFrm() {

    if (document.sweeps.first_name.value == "") {
        alert("Please fill in your first name.");
        document.sweeps.first_name.focus();
        return false;
    }

    if (document.sweeps.last_name.value == "") {
        alert("Please fill in your last name.");
        document.sweeps.last_name.focus();
        return false;
    }

    if (document.sweeps.address.value == "") {
        alert("Please enter your address.");
        document.sweeps.address.focus();
        return false;
    }

    if (document.sweeps.city.value == "") {
        alert("Please select your city.");
        document.sweeps.city.focus();
        return false;
    }

    if (st == "") {
        alert("Please select your state.");
        return false;
    }


	if (! checkZIPCode(document.sweeps.zipcode,0) ) {
        document.sweeps.zipcode.focus();
        return false;
	}
	

	if (! checkUSPhone(document.sweeps.phone,0) ) {
        document.sweeps.phone.focus();
		return false;
	}

	if (! checkEmail(document.sweeps.email,0) ) {
        document.sweeps.email.focus();
		return false;
	}


/*
    if (document.sweeps.zipcode.value == "") {
        alert("Please fill in zip/postal code.");
        document.sweeps.zipcode.focus();
        return false;
    }

    if (document.sweeps.phone.value == "") {
        alert("Please fill in you telephone number.");
        document.sweeps.phone.focus();
        return false;
    }

    if (document.sweeps.email.value == "") {
        alert("Please fill in your E-mail address.");
        document.sweeps.email.focus();
        return false;
    } 
*/

	if ( (document.sweeps.bmonth.value == "MM") || (document.sweeps.bmonth.value == "") ) {
		alert("Please fill in birth month.")
        document.sweeps.bmonth.focus();
        return false;
	} else {
		if ( checkMonth(document.sweeps.bmonth,false) ) bmonth = document.sweeps.bmonth.value;
	}

    if ( (document.sweeps.bday.value == "DD") || (document.sweeps.bday.value == "") ) {
		alert("Please fill in birth day.")
		document.sweeps.bday.focus();
        return false;
	} else {
		if ( checkDay(document.sweeps.bday,false) ) bday = document.sweeps.bday.value;
	}

	if ( (document.sweeps.byear.value == "YYYY") || (document.sweeps.byear.value == "") ) {
        alert("Please fill in birth year.");
        document.sweeps.byear.focus();
        return false;
	} else {
		if ( checkYear(document.sweeps.byear,false) ) byear = document.sweeps.byear.value;
	}

	if ( cookieChk('set') ) return true; 
	else {
		document.location.href = "under18.html"
		return false
	}
	

} //chkFrm

function getSt(obj) {
    var optSt = obj.selectedIndex;
    st = obj.options[optSt].value;
}


var isNN = (navigator.appName.indexOf("Netscape")!=-1);

function autoTab(input,len, e) {
    var keyCode = (isNN) ? e.which : e.keyCode;
    var filter = (isNN) ? [0,8,9] : [0,8,9,16,17,18,37,38,39,40,46];
    if(input.value.length >= len && !containsElement(filter,keyCode)) {
        input.value = input.value.slice(0, len);
        input.form[(getIndex(input)+1) % input.form.length].focus();
    }

    function containsElement(arr, ele) {
        var found = false, index = 0;
        while(!found && index < arr.length)
            if(arr[index] == ele) found = true;
            else
            index++;
            return found;
        }

        function getIndex(input) {
            var index = -1, i = 0, found = false;
            while (i < input.form.length && index == -1)
                if (input.form[i] == input)index = i;
                else i++;
            return index;
        }

        return true;
}

function clrFld(frmfld) { 
	var fld = frmfld.value
	if ( (fld.indexOf("D") == 0) || (fld.indexOf("M") == 0) || (fld.indexOf("Y") == 0) ) frmfld.value = "";
	frmfld.focus();
}

