chkDate(1,2002,5,12,'sorry.html')

var zyear=0,zmonth=0,zday=0;
var sendimg = false;
var proceed = cookieChk();

var sweepsOver = new Date(2002,4,13);

function cookieChk(act) {
	// 604800000   = 1 week (7 * 24 * 60 * 60 * 1000)
	var momCookie = new Cookie(document,'Outback',sweepsOver)
    isNow = new Date()
    tday = isNow.getDate()
    if (act == null) {
        if ( momCookie.get() ) {
			if (!momCookie.age) {
				document.location.href = "under18.html";
				return false;
			} else if (momCookie.entered == tday) {
	            alert("Sorry, but you have already entered this sweepstakes today, please come back tomorrow.");
   				document.location.href = "http://tlc.discovery.com/";
				return false;
        	} 
        }

		return true;
    }

    if (act == "set") {
        momCookie.age = notMinor(zyear,zmonth,zday)
        momCookie.entered = tday
        momCookie.set()
		if (momCookie.age) {
			return true;
		} else {
			document.location.href = "under18.html";
			return false;
		}
    }
}


function notMinor(yr,mo,dy) {
    var cday = new Date(1984,3,1); var dob = new Date(yr,(mo-1),dy);
    if (cday.getTime() >= dob.getTime() ) {
		return true; //was born b4 Apr 1, 1984
	} else {
		return false;
	}
}


function chkFrm(frm) {

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

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

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

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

	var objSt = frm.state;
    var idx = objSt.selectedIndex;
	var st = objSt.options[idx].value;
	if ( st == "" ) {
        alert("Please select your state.");
        frm.state.focus();
        return false;
    }


	if (!checkZIPCode(frm.zipcode) ) {
        frm.zipcode.focus();
        return false;
	}
	

	if (!checkUSPhone(frm.phone_am) ) {
        frm.phone_am.focus();
		return false;
	}

	if (!checkUSPhone(frm.phone_pm) ) {
        frm.phone_pm.focus();
		return false;
	}

	if (!checkEmail(frm.email) ) {
        frm.email.focus();
		return false;
	}

	if (!checkDay(frm.bday)) return false;
	if (!checkMonth(frm.bmonth)) return false;
	if (!checkYear(frm.byear)) return false;

    if (frm.cable.value == "") {
        alert("Please select your Cable/Satellite provider.");
        frm.cable.focus();
        return false;
    }

	if ( txtTooLong(frm.mom) ) return false;

	return cookieChk('set')

} //chkFrm

function txtTooLong(fld) {
    if (fld.value.length > 1050 ) {
        alert("Please limit your entry to 200 words or less.");
        fld.focus();
		return true;
    } else { return false; }

}


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("D") == 0) || (fld.indexOf("m") == 0) || (fld.indexOf("M") == 0) || (fld.indexOf("Y") == 0) || (fld.indexOf("y") == 0) ) frmfld.value = "";
	frmfld.focus();
}

