
  
  
// VVVVVVVVVVVVVVVVVVV ExactTarget Code VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV
//set onBlur event on zipcode
addEvent(window, 'load', initZipCheck, false);

// validates email
function validEmail(addemailvalue) {
    invalidChars = " /:,;"
    if (addemailvalue == "") {
        return false
    }
    for (i=0; i<invalidChars.length; i++) {
        badChar = invalidChars.charAt(i)
        if (addemailvalue.indexOf(badChar,0) != -1) {
            return false
        }
    }
    atPos = addemailvalue.indexOf("@",1)
    if (atPos == -1) {
        return false
    }
    if (addemailvalue.indexOf("@",atPos+1) != -1) {
        return false
    }
    periodPos = addemailvalue.indexOf(".",atPos)
    if (periodPos == -1) {
        return false
    }
    if (periodPos+3 > addemailvalue.length) {
        return false
    }
    return true
}
//check if year is in range.
function inRange(inputStr, lo, hi) {
    //var num = parseInt(inputStr, 10)
    if (inputStr < lo || inputStr > hi) {
        return false
    }
    return true
}

//check if year is valid
//function validateYear(field) {
//  today = new Date();
//    if (!inRange(field,1900,today.getFullYear()-13)) {
//      return false
//     }
//alert('this is true');
// return true
//}

function validateMonth(field, Month) {
    Mydate = new Date();
    theMonth = Mydate.getMonth();
	  //alert (Month + ':' + field + ':' +theMonth + ':' + (Mydate.getFullYear()-12)+ ':' + (Mydate.getFullYear()-13));
    //if (!inRange(field,1900,Mydate.getFullYear()-12)) {
    if ( field >= (Mydate.getFullYear()-12)) {
        return false;
    }
    else{//alert("I'm here")
        if (field == (Mydate.getFullYear()-13) && theMonth < Month){
            return false;
        }
    }
    return true
}
//<% For i = 0 to numBirthYears
//Response.Write("<option value='"&Year(Date())-i&"'>"&Year(Date())-i&"</option>")
//next %>
function checkForm() {
    var ok =true;
    setCheckboxValues();
    addr = document.getElementById('addressLong');
    cty = document.getElementById('cityLong');
    if (document.subscribeForm['Email Address'].value.toLowerCase() != document.subscribeForm['Email Address Confirm'].value.toLowerCase()) {
        alert("Your email addresses don't match, please reenter you email address.");
        document.subscribeForm['Email Address'].focus();
        ok = false;
    }
    else if (!validEmail(document.subscribeForm['Email Address'].value)) {
        alert('Please enter a valid Email Address.');
        document.subscribeForm['Email Address'].focus();
        ok = false;
    }
    else if (document.subscribeForm['First Name'].value.length <= 0) {
        alert('Please enter a valid First Name.');
        document.subscribeForm['First Name'].focus();
        ok = false;
    }
    else if (document.subscribeForm['lastName'].value.length <= 0) {
        alert('Please enter a valid Last Name.');
        document.subscribeForm['lastName'].focus();
        ok = false;
    }
    else if (document.subscribeForm['State Or Province'].value.length <= 0) {
        alert('Please enter a valid State/Province.');
        document.subscribeForm['State Or Province'].focus();
        ok = false;

    }else if (document.subscribeForm['Zip Code'].value.length <= 0) {
        alert('Please enter a valid Zip Code.');
        document.subscribeForm['Zip Code'].focus();
        ok = false;
    }  else if (addr != null){
        if (document.subscribeForm['addressLong'].value.length <= 0) {
            alert('Please enter a valid Address.');
            document.subscribeForm['addressLong'].focus();
            ok = false;
        }
    }

    if (cty != null){
        if (document.subscribeForm['cityLong'].value.length <= 0) {
            alert('Please enter a valid City.');
            document.subscribeForm['cityLong'].focus();
            ok = false;
        }
    }

    //if (!validateYear(document.subscribeForm.Birthday__Year.value)) {
    //alert('! Sorry, you must be at least 13 years old to use this service. Please ask a parent to sign-up to receive information from our site. \n' + 'The reason for this is because the U.S. Children’s Online Privacy Protection Act requires prior Verifiable Parental Consent before collection of personal information from children. ');
    //document.subscribeForm.Birthday__Year.focus();
    //return false;
    //}
    //alert(document.subscribeForm.Birthday__Year[document.subscribeForm.Birthday__Year.selectedIndex].value + ":" + document.subscribeForm.Birthday__Month[document.subscribeForm.Birthday__Month.selectedIndex].value);
    if(document.subscribeForm['Best of the Buzz'].checked || document.subscribeForm['Entertainment Buzz'].checked || document.subscribeForm['Food Wine Buzz'].checked || document.subscribeForm['TC Tix On Sale Today'].checked || document.subscribeForm['The Outburst'].checked || document.subscribeForm['American Express Cardmember'].checked) {
        if (!validateMonth(document.subscribeForm['Birthday Year'][document.subscribeForm['Birthday Year'].selectedIndex].value, document.subscribeForm['Birthday Month'][document.subscribeForm['Birthday Month'].selectedIndex].value ) || document.subscribeForm['Birthday Month'].value.length <= 0 || document.subscribeForm['Birthday Year'].value.length <= 0 ) {
            alert('! Sorry, you must be at least 13 years old to use this service. Please ask a parent to sign-up to receive information from our site. \n\n' + ' The U.S. Children\'s Online Privacy Protection Act requires prior Verifiable Parental Consent before collection of personal information from children. ');
            document.subscribeForm['Birthday Year'].focus();
            ok = false;
        }
    }

    return ok;
}


function setCheckboxValues(){
    var doc = document.subscribeForm;
    doc['Best of the Buzz'].value = (doc['Best of the Buzz'].checked ? "yes" : "no");
    doc['Entertainment Buzz'].value = (doc['Entertainment Buzz'].checked ? "yes" : "no");
    doc['Food Wine Buzz'].value = (doc['Food Wine Buzz'].checked ? "yes" : "no");
    doc['Shopping Buzz'].value = (doc['Shopping Buzz'].checked ? "yes" : "no");
    doc['TC Tix On Sale Today'].value = (doc['TC Tix On Sale Today'].checked ? "yes" : "no");
    doc['The Outburst'].value = (doc['The Outburst'].checked ? "yes" : "no");
    doc['American Express Cardmember'].value = (doc['American Express Cardmember'].checked ? "yes" : "no");
    doc['Visitor Guide'].value = (doc['Visitor Guide'].checked ? "yes" : "no");
}


//Functions for adding the Local flag
function initZipCheck() {
  if (!document.createElement) return; // Check for DOM support

  var zip = document.getElementById('zip-postal-code');
  if(zip != null) {
    addEvent(zip, 'blur', zipCheckProc, false);
  }
}

function zipCheckProc() {
  var zipList = '55001,55002,55003,55005,55006,55009,55010,55011,55012,55013,55014,55016,55018,55020,55024,55025,55031,55032,55033,55037,55038,55042,55043,55044,55045,55047,55054,55055,55056,55057,55065,55068,55069,55070,55071,55073,55074,55075,55076,55077,55078,55079,55080,55082,55083,55084,55085,55088,55089,55090,55092,55101,55102,55103,55104,55105,55106,55107,55108,55109,55110,55111,55112,55113,55114,55115,55116,55117,55118,55119,55120,55121,55122,55123,55124,55125,55126,55127,55128,55129,55130,55133,55144,55145,55146,55150,55155,55161,55164,55165,55166,55168,55169,55170,55171,55172,55175,55177,55187,55188,55191,55301,55302,55303,55304,55305,55306,55311,55313,55315,55316,55317,55318,55320,55321,55322,55323,55327,55328,55330,55331,55337,55338,55339,55340,55341,55343,55344,55345,55346,55347,55348,55349,55352,55356,55357,55358,55359,55360,55361,55362,55363,55363,55364,55365,55367,55368,55369,55372,55373,55374,55375,55376,55378,55379,55380,55382,55383,55384,55386,55387,55388,55390,55391,55392,55393,55394,55395,55397,55399,55401,55402,55403,55404,55405,55406,55407,55408,55409,55410,55411,55412,55413,55414,55415,55416,55417,55418,55419,55420,55421,55422,55423,55424,55425,55426,55427,55428,55429,55430,55431,55432,55433,55434,55435,55436,55437,55438,55439,55440,55441,55442,55443,55444,55445,55446,55447,55448,55449,55450,55454,55455,55458,55459,55460,55467,55468,55470,55472,55473,55474,55478,55479,55480,55483,55484,55485,55486,55487,55488,55550,55551,55552,55553,55554,55555,55556,55557,55558,55559,55560,55561,55562,55563,55564,55565,55566,55567,55568,55569,55570,55571,55572,55573,55574,55575,55576,55577,55578,55579,55580,55581,55582,55583,55584,55585,55586,55587,55588,55589,55590,55591,55592,55593,55594,55595,55596,55597,55598,55599,56011,56044,56071';

  if (!document.createElement) return; // Check for DOM support
    var zip = document.getElementById('zip-postal-code');
  if(zip != null) {
    var zipInput = zip.value;

    if(zipList.indexOf(zipInput) > -1 && !document.getElementById('localFlag')) {
      var field = document.createElement("input");
      field.setAttribute('type','hidden');
      field.setAttribute('value','Yes');
      field.setAttribute('name','Local');
      field.setAttribute('id','localFlag');

      //add new element to the existing form
     document.subscribeForm.appendChild(field);
    } else if(zipList.indexOf(zipInput) > -1 && document.getElementById('localFlag')) {
      document.getElementById('localFlag').value = 'Yes';
    } else if(zipList.indexOf(zipInput) == -1 && !document.getElementById('localFlag')) {
      var field = document.createElement("input");
      field.setAttribute('type','hidden');
      field.setAttribute('value','No');
      field.setAttribute('name','Local');
      field.setAttribute('id','localFlag');

      //add new element to the existing form
      document.subscribeForm.appendChild(field);
    } else if(zipList.indexOf(zipInput) == -1 && document.getElementById('localFlag')) {
      document.getElementById('localFlag').value = 'No';
    }
  }
}

// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
