/*
* Standard field JS
* Date: 2010.07.20
* Updated: 2010.11.16 -- intl
* 2011.05.05 -- indcode
*/
$(document).ready(function(){
occInit();
checkValOcp(1);
checkValInd();
$('select#ocpcode1_dt').change(function(){
setHasJS('D');
checkValOcp(2);
});
$('select#indcode1_dt').change(function(){
checkValInd();
});
$('input[name=ocpcode_other]').blur(function(){ checkValOcp(3); });
$('input[name=indcode_other]').blur(function(){ checkValInd(); });
SetErrorMessages();
setCustomErrorMessages();
});
//onload checks. Set has_js
function occInit() {
var p = $("input[name='p']").val();
//$('div#ocpcode_wrap, div#indcode_wrap').show();
//$('div#container_ocpcode, div#container_ocpcode2, div#container_ocpcode3, div#container_indcode1, div#container_indcode2').show();
$('div#container_ocpcode, div#container_indcode1').show();
var hasjs = $('#has_js').val();
var val_jone = $('input[name=ocpcode1]').val();
if (val_jone != '') { setHasJS('C'); }
else if (hasjs == 'N') { setHasJS('Y'); }
//if (hasjs == 'N') { $('#has_js').val("Y"); }
}
//testing has_js onchange instead of onload 3/15
function setHasJS(v) {
var hasjs = $('#has_js').val();
$('#has_js').val(v);
}
//ajax call to return OCPCODE or html, pass in val_one,
//iterate through array to populate ocpcode2_dt and ocpcode3_dt
function checkValOcp(s) {
//Get level1 values and load html
var val_one = $('select#ocpcode1_dt').val();
//See if already set from prefill
var val_jone = $('input[name=ocpcode1]').val();
var val_jtwo = $('input[name=ocpcode2]').val();
var val_jthr = $('input[name=ocpcode3]').val();
var lang = $('input[name=ocpcode_lang]').val();
if (lang == undefined) { lang = "eng"; }
//Load level1
if (!val_one && !val_jone) {
//Set select to what is in prefill and clear out
//prefill so user can switch options
if (val_jone != '') {
$('select#ocpcode1_dt').val(val_jone);
$('input[name=ocpcode1]').val('');
}
var val = $('select#ocpcode1_dt').val();
$('div#ocpcode_level2').html('');
$('#ocpcode_level1').load('/c/getjob2017_intl.mpl', {level: '1', val: val, lang: lang}, function(h){
$('select#ocpcode1_dt').change(function(){
setHasJS('A');
checkValOcp(4);
});
//Hide level2 div [secondary]
$('div#ocpcode_secondary').hide();
//prafulla-highlight
var noFillFields = new Array ('ocpcode1_dt');
SetHighlight(noFillFields,"call2");
SetErrorMessages("ocpcode1_dt");
splitForm();
});
}
//Load level2 and level3
else {
//for prefill
if (val_one == '') { val_one = val_jone; }
$('#ocpcode_level1').load('/c/getjob2017_intl.mpl', {level: '1', val: val_one, lang: lang}, function(h){
if (val_jone != '') {
$('select#ocpcode1_dt').val(val_jone);
$('input[name=ocpcode1]').val('');
}
if (!h.match(/matched ocpcode1_dt/)) { $('select#ocpcode1_dt').val('');}
setJobVal();
$('select#ocpcode1_dt').change(function(){
setHasJS('B');
setJobVal();
checkValOcp(5);
});
splitForm();
});
$('#ocpcode_level2').load('/c/getjob2017_intl.mpl', {level: '2', val: val_one, val2: val_jtwo, val3: val_jthr, lang: lang}, function(h){
if (val_jtwo != '') {
$('select#ocpcode2_dt').val(val_jtwo);
$('input[name=ocpcode2]').val('');
}
if (val_jthr != '') {
$('select#ocpcode3_dt').val(val_jthr);
$('input[name=ocpcode3]').val('');
}
//prafulla-highlight
// This code gets executed when ocpcode1 is selected for the first time
// set highlight class to ocpcode 2 & 3 if they are blank
var noFillFields = new Array ('ocpcode1_dt','ocpcode2_dt','ocpcode3_dt');
SetHighlight(noFillFields,"call4");
SetErrorMessages("ocpcode2_dt");
SetErrorMessages("ocpcode3_dt");
SetHighlightOther('ocpcode_other_text',"callo1");
FormLoaded();
//Clear out hidden input if not matched
if (!h.match(/matched ocpcode2_dt/)) { $('select#ocpcode2_dt').val('');}
if (!h.match(/matched ocpcode3_dt/)) { $('select#ocpcode3_dt').val('');}
setJobVal();
//Bind actions
$('#ocpcode2_dt, #ocpcode3_dt').change(function(){
setJobVal();
//prafulla-highlight
var noFillFields = new Array ('ocpcode2_dt','ocpcode3_dt');
SetHighlight(noFillFields,"call5");
SetHighlightOther('ocpcode_other_text',"callo2");
});
if($('input[name=lclick]').val() != 1) { showHidePostPredict();}
splitForm();
});
//Show secondary div
$('#ocpcode_secondary').show('fast');
}
//Set values for hidden div
setJobVal();
}
//Set hidden vars
function setJobVal(){
var myVal1 = $('select#ocpcode1_dt').val();
var myVal2 = $('select#ocpcode2_dt').val();
var myVal3 = $('select#ocpcode3_dt').val();
//if (myVal1 == 'Other' || myVal2 == 'Other' || myVal3 == 'Other') { $('div#ocpcode_other').show('fast'); }
//else { $('div#ocpcode_other').hide('fast'); } //$('input[name=ocpcode_other]').val('');
var otc1 = $.trim($("select#ocpcode1_dt option:selected").text());
var otc2 = $.trim($("select#ocpcode2_dt option:selected").text());
var otc3 = $.trim($("select#ocpcode3_dt option:selected").text());
// ocpcode2 check hash
// 109,122,133,147,175,19,195,210,222,231,247,259,279,295,30,315,344,356,372,383,39,397,415,48,68,80
var ocp2hash = {109:'109', 122:'122', 133:'133', 147:'147', 175:'175', 19:'19', 195:'195', 210:'210', 222:'222', 231:'231', 247:'247', 259:'259', 279:'279', 295:'295', 30:'30', 315:'315', 344:'344', 356:'356', 372:'372', 383:'383', 39:'39', 397:'397', 415:'415', 48:'48', 68:'68', 80:'80'};
if (otc1 == 'Other' || otc2 == 'Other' || otc3 == 'Other'){ $('div#ocpcode_other').show('fast'); }
else if (myVal1 == 416 || myVal3 == 17){ $('div#ocpcode_other').show('fast'); }
else if (ocp2hash[myVal2] !== undefined) { $('div#ocpcode_other').show('fast'); }
else { $('div#ocpcode_other').hide('fast'); } //$('input[name=ocpcode_other]').val('');
var myValOther = $('input[name=ocpcode_other]').val();
$('#ocpcode_hidden').html('');
$('#ocpcode_hidden').append('');
$('#ocpcode_hidden').append('');
$('#ocpcode_hidden').append('');
}
//ajax call to return INDCODE html, pass in val_one,
//iterate through array to populate indcode2_dt
function checkValInd() {
//Get level1 values and load html
var val_one = $('select#indcode1_dt').val();
//See if already set from prefill
var val_ione = $('input[name=indcode1]').val();
var val_itwo = $('input[name=indcode2]').val();
var lang = $('input[name=ocpcode_lang]').val();
if (lang == undefined) { lang = "eng"; }
//Load level1
if (!val_one && !val_ione) {
//Set select to what is in prefill and clear out
//prefill so user can switch options
if (val_ione != '') {
$('select#indcode1_dt').val(val_ione);
$('input[name=indcode1]').val('');
}
var val = $('select#indcode1_dt').val();
$('div#indcode_level2').html('');
$('#indcode_level1').load('/c/getind2017_intl.mpl', {level: '1', val: val, lang: lang}, function(h){
$('select#indcode1_dt').change(function(){
checkValInd();
//prafulla-highlight - debug here
var noFillFields = new Array ('indcode1_dt');
SetHighlight(noFillFields,"indcall1");
});
//Hide level2 div [secondary]
//$('div#indcode_secondary').hide();
$('div#container_indcode2').hide();
//prafulla-highlight
var noFillFields = new Array ('indcode1_dt');
SetHighlight(noFillFields,"indcall2");
SetErrorMessages('indcode1_dt');
splitForm();
});
}
//Load level2
else {
//for prefill
if (val_one == '') { val_one = val_ione; }
$('#indcode_level1').load('/c/getind2017_intl.mpl', {level: '1', val: val_one, lang: lang}, function(h){
if (val_ione != '') {
$('select#indcode1_dt').val(val_ione);
$('input[name=indcode1]').val('');
}
if (!h.match(/matched indcode1_dt/)) { $('select#indcode1_dt').val('');}
setIndVal();
$('select#indcode1_dt').change(function(){
setIndVal();
checkValInd();
//prafulla-highlight
var noFillFields = new Array ('indcode1_dt');
SetHighlight(noFillFields,"indcall3");
});
splitForm();
});
$('#indcode_level2').load('/c/getind2017_intl.mpl', {level: '2', val: val_one, val2: val_itwo, lang: lang}, function(h){
if (val_itwo != '') {
$('select#indcode2_dt').val(val_itwo);
$('input[name=indcode2]').val('');
}
//prafulla-highlight
var noFillFields = new Array ('indcode2_dt');
SetHighlight(noFillFields,"indcall4");
SetErrorMessages("indcode2_dt");
SetHighlightOther('indcode_other_text',"calli1");
FormLoaded();
//Clear out hidden input if not matched
if (!h.match(/matched indcode2_dt/)) { $('select#indcode2_dt').val('');}
setIndVal();
//Bind actions
$('#indcode2_dt').change(function(){
setIndVal();
//prafulla-highlight
var noFillFields = new Array ('indcode2_dt');
SetHighlight(noFillFields,"indcall5");
SetHighlightOther('indcode_other_text',"calli2");
});
//code to handle if load happens after showhidepsotpredict is called
if( ($("input[name=indcode1]").val().length == 0 || $("input[name=indcode1]").val() == 'undefined' || $("input[name=indcode1]").val() == 'null' || $("input[name=indcode2]").val().length == 0 || $("input[name=indcode2]").val() == 'undefined' || $("input[name=indcode2]").val() == 'null' || $('input[name=lclick]').val() == 1) && $("input[name=company]").val().length > 0) {
$('#container_indcode1,#container_indcode2 ').show();
} else {
$('#container_indcode1,#container_indcode2 ').hide();
}
//if($('input[name=lclick]').val() != 1) { showHidePostPredict();}
splitForm();
});
if($("input[name=indcode2]").val().length == 0 || $("input[name=indcode2]").val() == 'undefined' || $("input[name=indcode2]").val() == 'null' || $('input[name=lclick]').val() == 1) {
//Show secondary div
$('#indcode_secondary').show('fast');
$('#container_indcode2').show('fast');
}
}
//Set values for hidden div
setIndVal();
}
//Set hidden vars
function setIndVal(){
var myVal1 = $('select#indcode1_dt').val();
var myVal2 = $('select#indcode2_dt').val();
var itc1 = $.trim($("select#indcode1_dt option:selected").text());
var itc2 = $.trim($("select#indcode2_dt option:selected").text());
// indcode2 check hash
// these values = "Other"
var ind2hash = {100:'100',106:'106',130:'130',15:'15',152:'152',162:'162',177:'177',202:'202',212:'212',223:'223',224:'224',31:'31',49:'49',55:'55',6:'6',65:'65',84:'84'};
if (itc1 == 'Other' || itc2 == 'Other'){ $('div#indcode_other').show('fast'); }
else if (myVal1 == 224){ $('div#indcode_other').show('fast'); }
else if (ind2hash[myVal2] !== undefined) { $('div#indcode_other').show('fast'); }
else { $('div#indcode_other').hide('fast'); } //$('input[name=indcode_other]').val('');
var myValOther = $('input[name=indcode_other]').val();
$('#indcode_hidden').html('');
$('#indcode_hidden').append('');
$('#indcode_hidden').append('');
}
//Set a random variable and assign a value of A or B to the invisible field
//If the random variable is < 0.5, then assign a value of B (hide)
//If the random variable is >= 0.5 and <= 1, assign a value of A (show)
function genRandom(elemId){
var rndm = Math.random();
if (rndm < 0.5) {
$('#'+elemId).val('B');
}
if(rndm >= 0.5 && rndm <= 1) {
$('#'+elemId).val('A');
}
}
// Highlight Blank Fields
function SetHighlight (highlightFields, debugcall) {
for (var i in highlightFields) {
//alert ("id = " + highlightFields[i]);
var hval = $('select#'+highlightFields[i]).val();
if (hval == '' || hval == undefined) {
$('select#'+highlightFields[i]).addClass('highlight');
} else {
$('select#'+highlightFields[i]).removeClass('highlight');
}
}
}
// Highlight Blank Other field
function SetHighlightOther (highlightField, debugcall) {
//alert ("calling from = " + debugcall + "fieldID = " + highlightField );
var hval = $('input#'+highlightField).val();
//alert("other-value = " + hval);
if (hval == '' || hval == undefined) {
$('input#'+highlightField).addClass('highlight');
} else {
$('input#'+highlightField).removeClass('highlight');
}
}
// Set error messages
// When "errorField" is passed in, only "errorField" will be updated
function SetErrorMessages (errorField) {
if ($("#form_errors").val()) {
//Build a hash for form errors
var errors_hash = {};
var form_errors = $("#form_errors").val().split("|");
//Display global form error box
if($("#custom_form_errors").val().length == 0) {
$("#erroralert").show();
}
//log error event optimizely
dispFormErr();
for(i=0; i" + value + "";
$("#" + index).after(html);
//if(index != 'notice') {
$("#" + index).addClass("error");
//} else {
// $("#container_notice").addClass("error");
//}
//console.log(index);
});
//On change and nonblank field, assume issue is fixed.
$(".error", "#usercontainer").change(function() {
if ($("#" + this.id).val() == '') {
$("#" + this.id).addClass("error");
$("#" + this.id).bind("mouseenter focus");
} else {
if(this.id== 'phone') {
// $('#container_street,#container_dept_div, #container_zip,#container_city, #container_state,#container_country').hide();
}
unsetError($("#" + this.id));
}
});
/* $("input[name='notice']", "#usercontainer").change(function() {
$("#" + this.name).removeClass("error");
});
*/
//Hide/Show errorbox
$(".error", "#tp_qual").focus(function() {
$("#errorbox_" + this.id).show();
});
$(".error", "#tp_qual").blur(function() {
$("#errorbox_" + this.id).hide();
});
$(".error", "#tp_qual").hover(function() {
$("#errorbox_" + this.id).show();
}, function() {
$("#errorbox_" + this.id).hide();
});
}
}
function unsetError(ele) {
$(ele).removeClass("error");
$(ele).unbind("mouseenter focus");
}
function setCustomErrorMessages () {
if ($("#custom_form_errors").val()) {
var num_err = 0;
$("#erroralert").hide();
var html = 'Please correct the error(s) below:
';
var errors_hash = {};
var form_errors = $("#custom_form_errors").val().split("|");
for(i=0; i" + e_msg + "";
num_err++;
}
html += "
";
$(".errortab").html(html);
$(".errortab").show();
dispFormErr();
}
if($('#demoscontainer').children(':visible').length == 0) { $('#demoscontainer').hide();}
}
// Unset all error messages
// When "errorField" is passed in, only "errorField" will be updated
function UnsetErrorMessages (errorField) {
if ($("#form_errors").val()) {
//Build a hash for form errors
var errors_hash = {};
var form_errors = $("#form_errors").val().split("|");
for(i=0; i