function equalHeight(colList) {
   $(colList).each(function() {$(this).height("auto");}); 
   var topHeight = 0;
   var staticTop = -1;

   $(colList).each(function() {
      if ($(this).height() >= topHeight) {
         topHeight = $(this).height();
      }

      if ($(this).css("position") == "static") {
         staticTop = findPos(document.getElementById($(this).attr("id"))).y;
      }	
   });

   topHeight = topHeight + "px";
   staticTop = staticTop + "px"
   $(colList).each(function() {
      $(this).height(topHeight);
      if (staticTop != -1) $(this).css("top",staticTop);
   });
};

function isRequired( el ){
    return ( req_fld[ el.name ] );
}

function validate( frm ) {
     var orig_reg_omn = reg_omn;

     with (frm) {
        if (typeof user_name !="undefined") {
                if (!user_name.value) {alert("Please provide a user name"); user_name.focus();  if( reg_omn ){ s.sendFormEvent( 'e', document.title, frm.name, 'Error: user name is missing' ); } return false }
                if (user_name.value.match(/[^\w\d_]/)) {alert("Only letters, numbers & underscores allowed in user name"); user_name.focus(); if( reg_omn ){ s.sendFormEvent( 'e', document.title, frm.name, 'Error: invalid character in user name' ); } return false }
                if (user_name.value.match(/^\d.*$/)) {alert("Your user name cannot begin with a number"); user_name.focus(); if( reg_omn ){ s.sendFormEvent( 'e', document.title, frm.name, 'Error: user name begins with number' ); } return false }
                if (user_name.value.length>user_name_maxlen) {alert("Your user name must be less than " + user_name_maxlen + " characters"); user_name.focus(); if( reg_omn ){ s.sendFormEvent( 'e', document.title, frm.name, 'Error: user name too long' ); } return false }
        }
        if (typeof password !="undefined") {
                if (!password.value) {alert("Please provide your password"); password.focus(); if( reg_omn ){ s.sendFormEvent( 'e', document.title, frm.name, 'Error: password is missing' ); } return false }
                if (password.value.match(/[^\w\d]/)) {alert("Only letters & numbers allowed in password"); password.focus(); if( reg_omn ){ s.sendFormEvent( 'e', document.title, frm.name, 'Error: invalid character in password' ); } return false }
                if (password.value.length<pw_minlen || password.value.length>pw_maxlen) {alert("Your password must be between " + pw_minlen + " and " + pw_maxlen + " characters"); password.focus(); if( reg_omn ){ s.sendFormEvent( 'e', document.title, frm.name, 'Error: password wrong size' ); } return false }
        }
        if ((typeof password  !="undefined") && (typeof pwconfirm  !="undefined")) {
                if (!(password.value==pwconfirm.value)) {alert("Passwords do not match. Please reconfirm password."); pwconfirm.focus(); if( reg_omn ){ s.sendFormEvent( 'e', document.title, frm.name, 'Error: passwords do not match' ); } return false }
        }
        if (typeof email != "undefined" && isRequired( email )) {
                if (!email.value) {alert("Please provide your email address"); email.focus(); if( reg_omn ){ s.sendFormEvent( 'e', document.title, frm.name, 'Error: email is missing' ); } return false }
                if (!email.value.match(/^\w+((-\w+)|(\.\w+)|(\+\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/)) {
                        alert("Your email address apears to be invalid. Please provide a valid email address.");
                        email.focus();
                        if( reg_omn ){ s.sendFormEvent( 'e', document.title, frm.name, 'Error: email is invalid' ); }
                        return false
                }
                if (!email.value.match(/.+@.+\..+/)) {alert("Your email address apears to be invalid.  Please provide a valid email address."); email.focus(); if( reg_omn ){ s.sendFormEvent( 'e', document.title, frm.name, 'Error: email is invalid' ); } return false }
        }
        if (typeof first_name != "undefined" && isRequired( first_name ) ){
                if (!first_name.value) {
                        alert("Please provide your first name");
                        first_name.focus();
                        if( reg_omn ){ s.sendFormEvent( 'e', document.title, frm.name, 'Error: first name is missing' ); }
                        return false
                }
        }
        if (typeof last_name != "undefined" && isRequired( last_name )) {
                if (!last_name.value) {
                        alert("Please provide your last name");
                        last_name.focus();
                        if( reg_omn ){ s.sendFormEvent( 'e', document.title, frm.name, 'Error: last name is missing' ); }
                        return false
                }
        }
        if (typeof address1 != "undefined" && isRequired( address1 )) {
                if (!address1.value) {
                    alert("Please provide your street address");
                    address1.focus();
                    if( reg_omn ){ s.sendFormEvent( 'e', document.title, frm.name, 'Error: address1 is missing' ); }
                    return false
                }
        }
        if (typeof address2 != "undefined" && isRequired( address2 )) {
                if (!address2.value) {
                    alert("Please provide address2");
                    address2.focus();
                    if( reg_omn ){ s.sendFormEvent( 'e', document.title, frm.name, 'Error: address2 is missing' ); }
                    return false
                }
        }
        if (typeof city != "undefined" && isRequired( city )) {
                if (!city.value) {
                    alert("Please provide your city");
                    city.focus();
                    if( reg_omn ){ s.sendFormEvent( 'e', document.title, frm.name, 'Error: city is missing' ); }
                    return false
                }
        }
        if (typeof state != "undefined" && isRequired( state )) {
                if (!state.options[state.selectedIndex].value) {
                    alert("Please select your state");
                    state.focus();
                    if( reg_omn ){ s.sendFormEvent( 'e', document.title, frm.name, 'Error: state is missing' ); }
                    return false
                }
        }
        if (typeof country != "undefined" && isRequired( country )) {
                if (!country.options[country.selectedIndex].value) {
                    alert("Please select your country");
                    country.focus();
                    if( reg_omn ){ s.sendFormEvent( 'e', document.title, frm.name, 'Error: country is missing' );}
                    return false
                }
        }
        if (typeof zipcode != "undefined") {
            if( isRequired( zipcode )){
                if (!zipcode.value) {
                    alert("Please provide your zipcode");
                    zipcode.focus();
                    if( reg_omn ){ s.sendFormEvent( 'e', document.title, frm.name, 'Error: zipcode is missing' ); }
                    return false
                }
            }
        }
        //State and Country values both required for zip_test() function
        if (typeof country != "undefined" && typeof state != "undefined" && isRequired( zipcode) && isRequired( state) ) {
            if(zip_test( frm ) != true) { return false; }
        }
        if (typeof area_code != "undefined" && isRequired( area_code )) {
                if (!area_code.value) {
                    alert("Please provide your area code");
                    area_code.focus();
                    if( reg_omn ){ s.sendFormEvent( 'e', document.title, frm.name, 'Error: area code is missing' ); }
                    return false
                }
        }
        if (typeof income != "undefined" && isRequired( income )) {
                if (!income.options[income.selectedIndex].value) {
                    alert("Please select your income");
                    income.focus();
                    if( reg_omn ){ s.sendFormEvent( 'e', document.title, frm.name, 'Error: income is missing' ); }
                    return false
                }
        }

        if (typeof gender != "undefined" && isRequired( gender[0] )) {
                myOption = -1;
                for (i=gender.length-1; i>-1; i--) {
                        if (gender[i].checked) {
                                myOption = i;
                        }
                }
                if (myOption == -1) {
                        alert("Please specify your gender");
                        if( reg_omn ){ s.sendFormEvent( 'e', document.title, frm.name, 'Error: gender is missing' ); }
                        return false;
                }
        }
        if (typeof birth_year != "undefined" && isRequired( birth_year )) {
                if (!birth_year.value) {
                    alert("Please provide your birth year");
                    birth_year.focus();
                    if( reg_omn ){ s.sendFormEvent( 'e', document.title, frm.name, 'Error: birth year is missing' ); }
                    return false
                }
        }
        if (typeof birth_month != "undefined" && isRequired( birth_month )) {
                if (!birth_month.value) {
                    alert("Please provide your birth month");
                    birth_month.focus();
                    if( reg_omn ){ s.sendFormEvent( 'e', document.title, frm.name, 'Error: birth month is missing' ); }
                    return false
                }
        }
        if (typeof birth_day != "undefined" && isRequired( birth_day )) {
                if (!birth_day.value) {
                    alert("Please provide your birth day");
                    birth_day.focus();
                    if( reg_omn ){ s.sendFormEvent( 'e', document.title, frm.name, 'Error: birth day is missing' ); }
                    return false
                }
        }
        if (typeof birth_year != "undefined" && typeof birth_month != "undefined" && typeof birth_day != "undefined") {
                var now = new Date();
                var this_year = now.getYear();
                var this_month = now.getMonth();
                var this_day = now.getDate();
                var needed_year=this_year-13;
                var needed_date=new Date(needed_year,this_month,this_day);
                var needed_seconds = needed_date.getTime();
                var year = birth_year.options[birth_year.selectedIndex].value;
                var month = birth_month.options[birth_month.selectedIndex].value;
                var day = birth_day.options[birth_day.selectedIndex].value;
                var born_on = new Date(year,(month-1),day);
                var born_seconds = born_on.getTime();
                if(born_seconds > needed_seconds) {
                        alert('You must be at least 13 to register. Please view our Child Protection Policy for more information');
                        showHide('child_privacy_policy');
                        document.location="#child_privacy_policy";
                        if( reg_omn ){ s.sendFormEvent( 'e', document.title, frm.name, 'Error: user is too young' ); }
                        return false;
                }
        }

        if (typeof education != "undefined" && isRequired( education )) {
                if (!education.options[education.selectedIndex].value) {
                    alert("Please select your education level");
                    education.focus();
                    if( reg_omn ){ s.sendFormEvent( 'e', document.title, frm.name, 'Error: education is missing' ); }
                    return false
                }
        }
        if (typeof cf_access != "undefined" && isRequired( cf_access )) {
                myOption = -1;
                for (i=cf_access.length-1; i>-1; i--) {
                        if (cf_access[i].checked) {
                                myOption = i;
                        }
                }
                if (myOption == -1) {
                        alert("Please choose your access type");
                        cf_access.focus();
                        if( reg_omn ){ s.sendFormEvent( 'e', document.title, frm.name, 'Error: access type is missing' ); }
                        return false;
                }
        }

        if (typeof cf_ack_privacy != "undefined" && isRequired( cf_ack_privacy )) {
                if (!cf_ack_privacy.checked) {
                    alert("Please check the box indicating your agreement with the terms of the Privacy Policy");
                    cf_ack_privacy.focus();
                    if( reg_omn ){ s.sendFormEvent( 'e', document.title, frm.name, 'Error: privacy policy agreement is missing' ); }
                    return false
               }
        }
        if( reg_omn ){ s.sendFormEvent( 's', document.title, frm.name ); }
    }

    return true;
}

function zip_test( frm ) {
  with (frm) {
        //Canadian postal code and province validation...
        if (country.options[country.selectedIndex].value == "CA") {
               canzip=new Array();                   canzip["AB"] = "T";                             canzip["BC"] = "V";
               canzip["MB"] = "R";                   canzip["NB"] = "E";                             canzip["NL"] = "A";
               canzip["NT"] = "X";                   canzip["NS"] = "B";                             canzip["NU"] = "X";
               canzip["ON"] = "[KLMNP]";              canzip["PE"] = "C";                             canzip["QC"] = "[GHJ]";
               canzip["SK"] = "S";                   canzip["YT"] = "Y";
               var canprovinces = "AB BC MB NB NL NT NS NU ON PE QC SK YT";
               if ( !canprovinces.match(state.options[state.selectedIndex].value) ) {
                       alert("Please specify a Canadian Province");
                       state.focus();
                       if( reg_omn ){ s.sendFormEvent( 'e', document.title,name, 'Error: canadian province is missing' );
                       return false
               }
               zipcode.value=zipcode.value.toUpperCase();
               if (!zipcode.value.match(/^\D\d\D[ -]\d\D\d$/)) {
                       alert("Valid Canadian postal code required");
                       zipcode.focus();
                       if( reg_omn ){ s.sendFormEvent( 'e', document.title, name, 'Error: canadian postal code is invalid' ); }
                       return false
               }
               var pattern = new RegExp("^"+canzip[state.options[state.selectedIndex].value]);
               if (!zipcode.value.match(pattern)) {
                   alert("The postal code and province do not match");
                   zipcode.focus();
                   if( reg_omn ){ s.sendFormEvent( 'e', document.title, name, 'Error: canadian province does not match postal code' ); }
                   return false
               }
            }
        }

        // US resident state & zip code validation...
        if (country.options[country.selectedIndex].value == "US" ) {
               //3-digit valid zipcodelist, updated 2/6/2004 from http://www.ribbs.usps.gov/files/Advance/ZIP3.TXT
               var ziplist= "005006007008009010011012013014015016017018019020021022023024025026027028029030031032033034035036037038039040041042043044045046047048049050051052053054055056057058059060061062063064065066067068069070071072073074075076077078079080081082083084085086087088089090091092093094095096097098100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342344346347349350351352354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516520521522523524525526527528530531532534535537538539540541542543544545546547548549550551553554555556557558559560561562563564565566567570571572573574575576577580581582583584585586587588590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620622623624625626627628629630631633634635636637638639640641644645646647648649650651652653654655656657658660661662664665666667668669670671672673674675676677678679680681683684685686687688689690691692693700701703704705706707708710711712713714716717718719720721722723724725726727728729730731733734735736737738739740741743744745746747748749750751752753754755756757758759760761762763764765766767768769770772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816820821822823824825826827828829830831832833834835836837838840841842843844845846847850852853855856857859860863864865870871872873874875877878879880881882883884885889890891893894895897898900901902903904905906907908910911912913914915916917918919920921922923924925926927928930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986988989990991992993994995996997998999";
               ziplist = ziplist.replace(/(\d\d\d)/g,"$1 "); //Put spaces in the data
               statezip=new Array();
               statezip["AL"] = "3[56]";             statezip["AK"] = "99[5-9]";            statezip["AS"] = "967";
               statezip["AZ"] = "8[56]";             statezip["AR"] = "7[12]|755";          statezip["CA"] = "9[0-6]";
               statezip["CO"] = "8[01]";             statezip["CT"] = "06";                 statezip["DE"] = "19[789]";
               statezip["DC"] = "20[0-5]";           statezip["FL"] = "3[234]";             statezip["GA"] = "3[01]";
               statezip["GU"] = "969";               statezip["HI"] = "96[78]";             statezip["ID"] = "83[2-8]";
               statezip["IL"] = "6[012]";            statezip["IN"] = "4[67]";              statezip["IA"] = "5[012]";
               statezip["KS"] = "6[67]";             statezip["KY"] = "4[012]";             statezip["LA"] = "7[01]";
               statezip["ME"] = "0[34]";             statezip["MD"] = "2[01]";              statezip["MA"] = "0[12]|055";
               statezip["MI"] = "4[89]";             statezip["MN"] = "5[56]";              statezip["MS"] = "3[89]";
               statezip["MO"] = "6[345]";            statezip["MT"] = "59";                 statezip["NE"] = "6[89]";
               statezip["NV"] = "8[89]";             statezip["NH"] = "03[0-8]";            statezip["NJ"] = "0[78]";
               statezip["NM"] = "8[78]";             statezip["NY"] = "[01]|004|063";       statezip["NC"] = "2[678]";
               statezip["ND"] = "58[0-8]";           statezip["OH"] = "4[345]";             statezip["OK"] = "7[34]";
               statezip["OR"] = "97";                statezip["PA"] = "1[5-9]";             statezip["PR"] = "00[6-9]";
               statezip["RI"] = "02[89]";            statezip["SC"] = "29";                 statezip["SD"] = "57[0-7]";
               statezip["TN"] = "3[78]";             statezip["TX"] = "7[5-9]|885";         statezip["UT"] = "84[0-7]";
               statezip["VT"] = "05";                statezip["VA"] = "2[234]|201";         statezip["VI"] = "008";
               statezip["WA"] = "9[89]";             statezip["WI"] = "5[34]";              statezip["WV"] = "2[456]";
               statezip["WY"] = "8[23]";
               if (!statezip[state.options[state.selectedIndex].value]) {
                       alert("US residents must specify a state");
                       state.focus();
                       if( reg_omn ){ s.sendFormEvent( 'e', document.title, name, 'Error: state is missing' ); }
                       return false;
               }
               //Normalize data entry for +4 offerings, eliminating spaces and ensuring "#####-####"
               zipcode.value = zipcode.value.replace(/ /g,"").replace(/(^\d\d\d\d\d)(\d\d\d\d)/,"$1-$2");
               if ( !zipcode.value.match(/^\d\d\d\d\d$/) &&
                        !zipcode.value.match(/^\d\d\d\d\d-\d\d\d\d$/) ||
                        !ziplist.match(zipcode.value.substr(0,3)) ) {
                       alert("Please enter a valid US zip code2");
                       zipcode.focus();
                       if( reg_omn ){ s.sendFormEvent( 'e', document.title, name, 'Error: zipcode is invalid'); }
                       return false;
               }
               // Test that zip code is in range of the selected state
               var foundmatch = false;
               var ranges = statezip[state.options[state.selectedIndex].value].split("|");
               for (pattern in ranges) {
                       pattern = new RegExp("^"+ranges[pattern]);
                       if (zipcode.value.match(pattern)) { foundmatch=true }
               }
               if (!foundmatch) {
                   alert("The zip code and state you selected do not match");
                   zipcode.focus();
                   if( reg_omn ){ s.sendFormEvent( 'e', document.title, name, 'Error: zipcode does not match state' ); }
                   return false;
               }
        }
        if (country.selectedIndex > 2) { zipcode.value="00000"; state.selectedIndex=1 }

        return true;
      }
}

function showHide(id) {
    //Arrays are zero-based, so start from zero instead of one
    //To hide all divs, just send a parameter higher than the number of divs
    var divArray = ["edit","opt_in","privacy_policy","child_privacy_policy","user_agreement","faq", "newsletters", "feedback"];
    for(i=0;i<divArray.length;i++) {
        x = document.getElementById( divArray[i] );
        if(x){
            if(id==divArray[i]) {
                x.style.display='block';
            } else {
                x.style.display='none';
            }
        }
    }
    if('top'==id){
        document.location='#top';
    }
    equalHeight('#col1, #col2, #col3'); // force the page to resize to fit
}

var user_run_mode = '[% runmode %]';

