function f_formValidate(f) { // build destination base var urlString = f.action + "?"; // validate entries with(f) { if (Empty(fname,"First Name is required","text",2,15)) return false; if (Empty(lname,"Last Name is required","text",2,20)) return false; if (Empty(email,"Email Address is required","text, numbers, and other characters",6,256)) return false; if (!ValidEmail(email)) return false; if (!ValidDropDown(banner_id)) return false; if (Empty(vuser,"Mileage Plus number is required","numbers",11,11)) return false; if (!f_checkDigit(vuser)) return false; } // disable submit button if(navigator.appName.indexOf("Netscape") == -1)f_submitOnce(f); // build dynamic destination for (i=0; i< f.length-1; i++) { var g = f.elements[i]; if (g.name.charAt(0) != "x" && g.value != null && g.value != "") { if(g.name == "fname" || g.name == "lname" || g.name == "targetURL" || g.name == "failureURL" || g.name == "email" || g.name == "vuser") { urlString += g.name+ "=" + escape(g.value) + "&"; } else if (g.type == "submit") { // do nothing here } else if (g.name == "banner_id") { // extract the banner id from the drop-down urlString += g.name + "=" + document.coreg.banner_id.options[document.coreg.banner_id.selectedIndex].value + "&"; } else { // add to the string all the hidden values urlString += g.name + "=" + g.value + "&"; } } } // clean up URL string, remove last "&" urlString = urlString.substring(0,urlString.length-1); // submit window to destination //if (confirm("Go to: " + urlString)){ //strike this line top.location=urlString; //alert(urlString); //} return false; } function SelectMe(fld) { fld.focus(); if (fld.type != "select-one") fld.select(); } function Empty(fld,alertMsg,aType,minLen,maxLen) { // determine the Valid Characters var strValidChars = " "; if (aType.indexOf("text") != -1) { strValidChars += "abcdefghijklmnopqrstuvwxyz"; } if (aType.indexOf("numbers") != -1) { strValidChars += "1234567890"; } if (aType.indexOf("other") != -1) { strValidChars += "@_().-/ "; } with(fld) { // test if we're just off really simply if (value.length != 0 && value != " ") { // here, there's some characters and it's not a single space //let's test further...assuming all things start off good: var valid = true; // let's test for length first - there's special cases // ...for exact length (i.e. the ARC Number), if (minLen == maxLen && value.length != minLen) { valid = false; alertMsg +=". It should be a " + minLen + " digit number"; } // ...for too short, if (value.length < minLen && valid == true) { valid = false; alertMsg +=". It should be at least " + minLen + " characters long"; } // ...and too long. if (value.length > maxLen && valid == true) { valid = false; alertMsg +=". It should be at no more than " + maxLen + " characters long"; } // Now, set up a flag for looping var spaces = 0; // now loop thru the string given and see what's there for(i=0; i < value.length && valid == true; i++) { aChar = value.charAt(i).toLowerCase(); if (strValidChars.indexOf(aChar) == -1) { valid=false; alertMsg += ", and should contain only " + aType; } if (aChar == " ") { spaces++; if(spaces == value.length) { valid=false; alertMsg += ", and cannot consist of all spaces" } else { // Special case, text only fields can not have more than 2 spaces if (type == "text") { if(spaces > 5) { valid=false; alertMsg += ", and cannot contain extra spaces" } } } } } // we're done looping - are things good or not? if(!valid) { alert(alertMsg + "."); setTimeout("SelectMe(document.forms['" + fld.form.name + "'].elements['" + fld.name + "'])", 0); return true; } else { return false; } } else { // we made a simple stupid error - give me basic messaging alert(alertMsg + "."); setTimeout("SelectMe(document.forms['" + fld.form.name + "'].elements['" + fld.name + "'])", 0); return true; } } } function ValidEmail(address) { with (address) { apos=value.indexOf("@"); dotpos=value.lastIndexOf("."); lastpos=value.length-1; if (apos<1 || dotpos-apos<2 || lastpos-dotpos>3 || lastpos-dotpos<2) { alert('Email address requires the @ symbol, a . (dot), and at least two letters after the dot.'); setTimeout("SelectMe(document.forms['" + address.form.name + "'].elements['" + address.name + "'])", 0); return false; } else return true; } } function ValidDropDown(dropdown) { with (dropdown) { if (selectedIndex < 1) { alert('Please tell us how you heard about this promotion.'); //setTimeout("SelectMe(document.forms['" + //dropdown.form.name + "'].elements['" + dropdown.name + "'])", 0); return false; } else return true; } } function ValidTerms(fld,alertMsg) { with(fld) { if (checked == false) { alert(alertMsg); setTimeout("SelectMe(document.forms['" + fld.form.name + "'].elements['" + fld.name + "'])", 0); return false; } else return true; } } function f_checkDigit(fld) { var mpNum = fld.value; if (mpNum.search(/^\d{11}$/) == -1) return false; var factor = [5,4,3,2,7,6,5,4,3,2]; var check = 0; for (var digit = 0; digit < 10; digit++) check += mpNum.charAt(digit) * factor[digit]; check = (((11 - (check % 11)) % 11) % 10); // return (check == mpNum.charAt(10)); if(check == mpNum.charAt(10)) { return true; } else { alert("The Mileage Plus number you entered is invalid, please try again."); setTimeout("SelectMe(document.forms['" + fld.form.name + "'].elements['" + fld.name + "'])", 0); return false; } } function f_submitOnce(aForm){ // Controls Button Change // if (document.all||document.getElementById){ for (i=0; i < aForm.length; i++){ var t_obj=aForm.elements[i]; if(t_obj.type.toLowerCase()=="submit"){ t_obj.value="Sending..."; t_obj.disabled=true; } } } }