/*********************************************************** Arguments: obj = Input element on which to return focus lbl = Field Label to prepend on to the message msg = Array value for message to give the user ************************************************************/ function OnFailure( obj, lbl, msg ) { var msgs = new Array(); msgs["text"] = " is a required field. \n\nPlease enter a value."; msgs["textarea"] = " is a required field. \n\nPlease enter a value."; msgs["select-one"] = " is a required field. \n\nPlease select an entry."; msgs["select-multiple"] = " is a required field. \n\nPlease select an entry."; msgs["checkbox"] = " is a required field. \n\nPlease select an entry."; msgs["file"] = " is a required upload. \n\nPlease select a file."; msgs["fileType"] = " requires certain file types. \n\nPlease select a valid file type."; msgs["fileLimit"] = " is a limited file upload. \n\nPlease reduce number of attachment(s) first."; msgs["radio"] = " is a required field. \n\nPlease select an entry."; msgs["number"] = " is a numeric field. \n\nPlease enter a valid number."; msgs["date"] = " is a date field. \n\nPlease enter a valid date."; msgs["email"] = " is an address field. \n\nPlease enter a valid e-mail address."; if(msg[1] || msg[2]) { //upper/lower bound ranges have been specified if(msg[1] && msg[2]) {//range term = ( msg[0] == "date" )? " ("+msg[3]+")" : ""; alert(lbl + msgs[msg[0]] + term + " between " + msg[1] + " and " + msg[2]); } else if (msg[1]) {//lower bound term = ( msg[0] == "number" ) ? " greater than " : " (" + msg[3] + ") after "; alert(lbl + msgs[msg[0]] + term + msg[1]); } else {//upper bound term = ( msg[0] == "number" )? " less than " : " (" + msg[3] + ") before "; alert(lbl + msgs[msg[0]] + term + msg[2]); } } else {//no range given alert(lbl + msgs[msg[0]]); } // this block is to highlight error fields col = document.getElementsByName(obj.name); for (x=0; x< col.length; x++) { col[x].style.backgroundColor = "#ffff99"; } if ((!obj.disabled) && (!obj.readOnly)) { if (col.length == 1) { obj.focus(); } } return false; } function isSomethingSelected( obj ) { for (var r=0; r < obj.length; r++) { if ( obj[r].checked ) return true; } } function validateRequiredFields( f, a ) { for (var i=0; i < a.length; i++) { e = a[i][0]; if (e == null) // object can be null for spreadsheet type fields { continue; } // this if block is added to clear highlight on radio and checkbox fields if ( e[0]) { col = document.getElementsByName(e[0].name); for (x=0; x< col.length; x++) { col[x].style.backgroundColor = "#ffffff"; } } //checks input types: "text","select-one","select-multiple","textarea","checkbox","radio","file" switch (e.type) { case "text": e.style.backgroundColor = "#ffffff"; if ( trim(e.value) == "" ) return OnFailure(e, a[i][1], ["text"]); break; case "textarea": e.style.backgroundColor = "#ffffff"; if ( trim(e.value) == "" ) return OnFailure(e, a[i][1], ["textarea"]); break; case "select-one": e.style.backgroundColor = "#ffffff"; if ( e.selectedIndex == 0 ) return OnFailure(e, a[i][1], ["select-one"]); break case "select-multiple": e.style.backgroundColor = "#ffffff"; if (e.selectedIndex == -1) return OnFailure(e, a[i][1], ["select-multiple"]); break default: //must be a checkbox or a radio group if none of above if ( !e[0]) {//handle single item group first switch (e.type) { case "checkbox": if ( !e.checked ) return OnFailure(e, a[i][1], ["checkbox"]); break case "radio": if ( !e.checked ) return OnFailure(e, a[i][1], ["radio"]); break default: break } } else { //handle multi-item groups switch (e[0].type) { case "checkbox": if ( !isSomethingSelected( e ) ) return OnFailure(e[0], a[i][1], ["checkbox"]); break case "radio": if ( !isSomethingSelected( e ) ) return OnFailure(e[0], a[i][1], ["radio"]); break default: break } } break } } return true; } function isEmpty(e) { //checks input types: "text","select-one","select-multiple","textarea","checkbox","radio","file" switch (e.type) { case "text": if ( trim(e.value) == "" ) return true; break; case "textarea": if ( trim(e.value) == "" ) return true; break; case "select-one": if ( e.selectedIndex == 0 ) return true; break; case "select-multiple": if (e.selectedIndex == -1) return true; break; default: //must be a checkbox or a radio group if none of above if ( !e[0]) {//handle single item group first switch (e.type) { case "checkbox": if ( !e.checked ) return true; break; case "radio": if ( !e.checked ) return true; break; default: break; } } else { //handle multi-item groups switch (e[0].type) { case "checkbox": if ( !isSomethingSelected( e ) ) return true; break; case "radio": if ( !isSomethingSelected( e ) ) return true; break; default: break; } } break; } return false; } function trim(aStr) { return aStr.replace(/^\s{1,}/, "").replace(/\s{1,}$/, "") } function submitDoc() { var a = new Array; f = document.forms[0]; a[a.length] = [f.name, "Your Name"]; a[a.length] = [f.email, "Your Email Address"]; a[a.length] = [f.phone, "Your Phone"]; a[a.length] = [f.region, "Your Region"]; a[a.length] = [f.question, "Your Question"]; if (validateRequiredFields(f, a)) { f.currentURL.value = window.location; f.submit(); } } function checkQuestion1(obj) { if (obj.value == "Yes") { document.getElementById("networkQuestion").style.display = "block"; document.getElementById("externalForm").style.display = "none"; } else { document.getElementById("networkQuestion").style.display = "none"; document.getElementById("externalForm").style.display = "block"; } } function checkQuestion2(obj) { if (obj.value == "Yes") { document.getElementById("externalForm").style.display = "none"; document.getElementById("messageRow").style.display = "block"; window.setTimeout("window.location = 'http://ikonnect.lendlease.com/ikonnect/sst/'", 1500) } else { document.getElementById("externalForm").style.display = "block"; } }