if($('.block-bid-opportnities-table')[0]){console.log("block-bid-opportnities-table");$(document).on("click",".js-rfb",function(e){e.preventDefault();var url=ShowPdfUrl;var id=e.target.getAttribute("data-bid");var v=currentVendorID;if(id!=""){$.ajax({url:url,type:"GET",data:{bidNumber:id,vendor:v},context:this,success:function(response){var url=GetFileUrl;window.open(url,"_blank");}});}
else{}});$(document).on("click",".js-bid-detail",function(e){e.preventDefault();var id=e.target.getAttribute('data-bid-number');window.open("/vendor/bid/view"+"?bidNumber="+id,"_self");});}
if($('.block-terms-and-conditions')[0]){console.log("block-terms-and-conditions");function disableSubmit(){document.getElementById("submit").disabled=true;}
function activateButton(element){if(element.checked){document.getElementById("submit").disabled=false;}
else{document.getElementById("submit").disabled=true;}}
function loadDataByAjax(){var url="/vendor/bid/tc";$.ajax({url:url,type:"POST",data:{agree:true},context:this,dataType:"json",success:function(data){if(data.redirectUrl){window.location.href=data.redirectUrl;}},});}}
if($('.block-bid-history')[0]){console.log("block-bid-history");var dropDown=document.getElementById("ddlSearchBy");var dateRangeMenu=document.getElementById("date-range-search");var RFBMenu=document.getElementById("rfb-number-search");var stockNumberMenu=document.getElementById("stock-number-search");var searchBtn=document.getElementById("btnSave");var startDate=document.getElementById("startDate");var endDate=document.getElementById("endDate");var stockNumber=document.getElementById("stockNumber");var RFBNumber=document.getElementById("rfbSearch");var errorMessages=document.getElementById("errorMessages");var originalHTML=document.getElementById("submitBid-table");var currentTable=document.getElementById("tableReplacement");dropDown.addEventListener("change",filterSearch);searchBtn.addEventListener("click",viewBidHistory);loadInitialBids();function filterSearch(){errorMessages.innerText="";if(dropDown.value=="1"){dateRangeMenu.classList.remove("hidden");stockNumberMenu.classList.add("hidden");RFBMenu.classList.add("hidden");}
else if(dropDown.value=="2"){dateRangeMenu.classList.add("hidden");stockNumberMenu.classList.remove("hidden");RFBMenu.classList.add("hidden");}
else if(dropDown.value=="3"){dateRangeMenu.classList.add("hidden");stockNumberMenu.classList.add("hidden");RFBMenu.classList.remove("hidden");}};function loadInitialBids(){var date=new Date();var endDateMonth=parseInt(date.getMonth())+1;if(endDateMonth<10){endDateMonth="0"+endDateMonth;}
var dateEnd=date.getDate();if(dateEnd<10){dateEnd="0"+dateEnd;}
var endDateInitial=date.getFullYear()+'-'+endDateMonth+'-'+dateEnd;date.setDate(date.getDate()-60);var startDateMonth=parseInt(date.getMonth())+1;if(startDateMonth<10){startDateMonth="0"+startDateMonth;}
var dateStart=date.getDate();if(dateStart<10){dateStart="0"+dateStart;}
var startDateInitial=date.getFullYear()+'-'+startDateMonth+'-'+dateStart;startDate.value=startDateInitial;endDate.value=endDateInitial;viewBidHistory();}
function viewBidHistory(){searchBtn.innerHTML="Loading";errorMessages.innerText="";var searchByMethod=dropDown.value;if(searchByMethod=="1"){var startDay=new Date(startDate.value);var endDay=new Date(endDate.value);var dateNow=new Date();if(startDay.getTime()>endDay.getTime()){errorMessages.innerText="The start date shouldn't be after the end date.";return;}
else if(endDay.getFullYear()>dateNow.getFullYear()||(endDay.getFullYear()==dateNow.getFullYear()&&endDay.getMonth()>dateNow.getMonth())||(endDay.getFullYear()==dateNow.getFullYear()&&endDay.getMonth()==dateNow.getMonth()&&endDay.getDate()>dateNow.getDate())){errorMessages.innerText="The end date shouldn't be in the future.";return;}
else if(startDate.value==""){errorMessages.innerText="Please input a correct date range.";return;}
else if(endDate.value==""){errorMessages.innerText="Please input a correct date range.";return;}}
else if(searchByMethod=="2"){if(stockNumber.value==""){errorMessages.innerText="Please input a stock number.";return;}}
else if(searchByMethod=="3"){if(RFBNumber.value==""){errorMessages.innerText="Please input a RFB number.";return;}
else{var worksheetUrl=document.getElementById("worksheetUrl").value;var redirectLink=worksheetUrl+"?rfb="+RFBNumber.value;window.location.href=redirectLink;}}
$.ajax({url:'/vendor/bid/getbidhistory',contentType:'application/html; charset=utf-8',type:'GET',data:{searchByMethod:searchByMethod,startDate:startDate.value,endDate:endDate.value,stockNumber:stockNumber.value,vendorId:"",RFBNumber:RFBNumber.value},dataType:'html'}).success(function(result){if(result.includes("No bids found")){searchBtn.innerHTML="Search";$('#tableHead').addClass("hidden");$('#tableReplacement').addClass("hidden");$('#bidErrors').removeClass("hidden");$('#bidErrors').html(result);}
else{searchBtn.innerHTML="Search";$('#submitBid-table').innerHTML=originalHTML.innerHTML;$('#bidErrors').addClass("hidden");$('#tableHead').removeClass("hidden");$('#tableReplacement').removeClass("hidden");var doc=new DOMParser().parseFromString(result,"text/html");var table=doc.getElementById("tableReplacement");currentTable.innerHTML=table.innerHTML;}}).error(function(xhr,status){searchBtn.innerHTML="Search";$('#submitBid-table').addClass("hidden");})};}
if($('.block-submit-bid')[0]){console.log("block-submit-bid");function view_bids(){var rfb=$("#vendor_summary").find("#hdnRFBId").val();$.ajax({url:'/vendor/bid/openbids',contentType:'application/html; charset=utf-8',type:'GET',data:{rfb:rfb},dataType:'html'}).success(function(result){$xa(document).accountModal({title:"Open bids",message:result,cancel:false});$('.nes-modal__wrapper').css({"max-width":"50%"});}).error(function(xhr,status){alert(status);})};var template=`<p><b>[ColumnLabel]</b></p>
                    <p id="addComment-dialog-description">[ItemDescription]</p>
                    <label for="addComment">
                        <h4 id="addComment-dialog-title">Add a comment</h4>
                    </label>
                    <textarea name="addComment" id="addComment" class="nes-modal__text-area" style="width: 100%" >[Comment]</textarea>`;$(function(){$('#btnSaveNew').on('click',function(e){e.preventDefault();e.stopPropagation();$xa(document).accountModal({title:"Submit Bid",message:"Are you sure you want to submit this bid?",callback:ConfirmSaveCallback});});});$("#btn-show-comment222").each(function(){$(this).on('click',function(element){element.preventDefault();element.stopPropagation();console.log("click btn");itemdes=$(this).next().next().val();comment=$(this).next().val();$xa(document).accountModal({title:"Add or edit comment",message:template.replace("[ItemDescription]",itemdes).replace("[Comment]",comment).replace("[ColumnLabel]",label),data:{txtFileDescription:""}});$(".nes-modal__ok").bind('click',{param:this},function(event){var data=event.data;var comments=$('#addComment');if(comments.length>540){alert('Please limit Comment length to 540 characters or less. Comment not accepted. Please try again.');return false;}
var closestHiddenfield=$(data.param).closest("TD").find('#hdnComments').val(comments.val());});});});function GetCalculatedPrice(el){var price=$(el).val();var quantity=$(el).parent().parent().find("#txtQty").val();$(el).parent().parent().find("#CalculatedPrice").val((price*quantity).toFixed(4));}
var format=/[!@@#$%^&*()+\=\[\]{};':"\\|,.<>\/?]+/;function ConfirmSaveCallback(){var bidSubmissionModel={};var rfb=$("#vendor_summary").find("#hdnRFBId").val();var vendorId=$("#vendor_summary").find("#hdnVendorId").val();var formData=new FormData($("#bid-table")[0]);var fileCount=0;var totalSize=0;var shouldProcess=true;$("input[type=file]").each(function(index,field){for(var i=0;i<field.files.length;i++){const file=field.files[i];fileCount++;var fileSize=file.size;if(fileSize>4194304){shouldProcess=false;ShowMessage("The file is too large to upload. </br>The maximum supported file sizes are : 4 MB for one document, 10 MB for all documents. The bid will not be submitted. ");return false;}
var tempFilename=file.name.replace(".pdf","");if(format.test(tempFilename)){shouldProcess=false;ShowMessage("The file name contains special characters. </br>The bid will not be submitted. ");return false;}
totalSize+=fileSize;formData.append('files',file);}});if(totalSize>10485760){shouldProcess=false;ShowMessage("The file is too large to upload. </br>The maximum supported file sizes are : 4 MB for one document, 10 MB for all documents. The bid will not be submitted. ");return false;}
if(!shouldProcess)return false;bidSubmissionModel.BidNumber=rfb;bidSubmissionModel.VendorNumber=vendorId;var bidDetails=new Array();$("#submitBid-table TBODY TR").each(function(){var row=$(this);var bidRow={};bidRow.ItemNbr=row.find("#hdnItemNr").val();bidRow.BrandPart=row.find('#BrandPart').find(":selected").text();if(bidRow.BrandPart=="Choose..."){shouldProcess=false;ShowMessage("Please fill all required fields before submitting the form");return false;}
bidRow.Delivery=row.find("#txtLeadTime").val();bidRow.Price=row.find("#txtPrice").val();if(bidRow.Price=="0"||bidRow.Price==""||bidRow.Price=="0.00"){shouldProcess=false;ShowMessage("Please fill all required fields before submitting the form");return false;}
bidRow.Comments=row.find("#hdnComments").val();bidDetails.push(bidRow);});if(!shouldProcess)return false;bidSubmissionModel.BidOfferList=bidDetails;bidSubmissionModel.FileCount=fileCount;var form=$('#bid-table');bidSubmissionModel.__RequestVerificationToken=$('input[name="__RequestVerificationToken"]',form).val();btnEl=$('#btnSaveNew');ButtonShowPending(btnEl);$.ajax({type:"POST",url:"/vendor/bid/Save",data:bidSubmissionModel,success:function(response){if(!response.HasError){formData.append("OfferNr",response.DataToPass);if(fileCount>0){$.ajax({type:"POST",url:"/vendor/bid/upload",data:formData,cache:false,contentType:false,processData:false,success:function(response){if(response.HasError){ShowMessage(response.ErrorMessage);ButtonShowOriginal(btnEl);}else{ShowMessage(response.SuccessMessage);if(!!response.RedirectUrl){$xa(document).accountModal({title:"Submit Bid",message:response.SuccessMessage,cancel:false});$(".nes-modal__ok").bind('click',{param:this},function(event){window.open(response.RedirectUrl,"_self");});}}}});}else{if(!!response.RedirectUrl){$xa(document).accountModal({title:"Submit Bid",message:response.SuccessMessage,cancel:false});$(".nes-modal__ok").bind('click',{param:this},function(event){window.open(response.RedirectUrl,"_self");});}}}else{ShowMessage(response.ErrorMessage);ButtonShowOriginal(btnEl);}}});}
function showCommentdialog(element){console.log("comment click");console.log("comment click");console.log("click btn");itemdes=$(element).next().next().val();comment=$(element).next().val();$xa(document).accountModal({title:"Add or edit comment",message:template.replace("[ItemDescription]",itemdes).replace("[Comment]",comment).replace("[ColumnLabel]",label),data:{txtFileDescription:""}});$(".nes-modal__ok").bind('click',{param:element},function(event){var data=event.data;var comments=$('#addComment');if(comments.val().length>540){alert('Please limit Comment length to 540 characters or less. Comment not accepted. Please try again.');return false;}
var closestHiddenfield=$(data.param).closest("TD").find('#hdnComments').val(comments.val());});}
function showMoredialog(element){console.log("more click");itemdes=$(element).next().val();$xa(document).accountModal({title:"Item description",message:itemdes,cancel:false});}
function SaveComment(event){var comments=$('#addComment');var closestHiddenfield=$(el).closest("TD").find('#hdnComments').val(comments.val());}
function ShowMessage(message){$xa(document).accountModal({title:"Submit Bid",message:message,cancel:false});}
function ButtonShowPending(btnEl){if(btnEl){btnEl.attr('data-orig-text',btnEl.html());btnEl.prop("disabled",true);btnEl.html('Processing...');}}
function ButtonShowOriginal(btnEl){if(btnEl){var txt=btnEl.attr('data-orig-text');if(!txt){txt="Error";}
btnEl.prop("disabled",false);btnEl.html(txt);}}
function GetFileSizeNameAndTypeSubmitBid(){var fi=document.getElementById('attachFile');var totalFileSize=0;document.getElementById('fp').innerHTML="";if(fi.files.length>0){for(var i=0;i<=fi.files.length-1;i++){document.getElementById('fp').innerHTML=document.getElementById('fp').innerHTML+"<p>"+fi.files.item(i).name+"</p>";}}}
$('#btnAddUpload').click(function(){i=i+1;var templateNew=` <div id="fileInput${i}">
            <div id=" " class="file-section nes-form active" style="padding: 8px;">
                <div class="file-section__header" style="border-bottom: 0px;padding: 0px;">

                    <label  id="label-file-upload${i}" class="custom-file-upload" for="file-upload${i}">
                        <svg class="icon">
                            <use xlink:href="#icon-pdf"></use>
                        </svg>
                        Upload
                        <input type="file" id="file-upload${i}" accept=".pdf" onchange="getPfdSubmitInfo(this,${i})" />
                    </label>
					 <div class="file-section__header-info">
                        <div>
							<p id = "txtFileName${i}" name = "txtFileName${i}" style="margin-bottom: -5px; margin-left: 20px;">No file choosen</p>
                        </div>
                    </div>
                    <button type="button" style="margin-left: auto;" value="Remove" class="custom-file-remove" onclick="removeSection(fileInput${i})">
                        <svg class="icon">
                            <use xlink:href="#icon-bin"></use>
                        </svg>
                        Remove
                    </button>
                </div>
            </div >
			</div >`
$('#fileUploadarea').append(templateNew);});function removeSection(id){id.parentNode.removeChild(id);}
function getPfdSubmitInfo(input,i){var url=input.value;if(input.files&&input.files[0]){fileName=input.files[0].name;var tempFilename=fileName.replace(".pdf","");if(format.test(tempFilename)){shouldProcess=false;ShowMessage("The file name contains special characters. </br>The bid will not be submitted. ");return false;}
$(input).closest(".file-section").find("#txtFileName"+i).text(fileName);$(input).closest(".file-section").find(".custom-file-remove").show();}}}
if($('.block-list-questions-vendor')[0]){console.log("block-list-questions-vendor");var searchBtn=document.getElementById("btnSearch");searchBtn.addEventListener("click",Search);var sizeDropdown=document.getElementById("size");sizeDropdown.addEventListener("change",Search);function Search(){var url=window.location.href.substring(0,window.location.href.lastIndexOf("/"));var redirectUrl="";var sortOption=document.getElementById("sort").value;var filterOption=document.getElementById("filter").value;var searchText=document.getElementById("questions_search_input").value;var size=document.getElementById("size").value;if(window.location.href.charAt(window.location.href.length-1)=="/"){redirectUrl=`${url}?sort=${sortOption}&type=${filterOption}&size=${size}`;}
else{redirectUrl=`${url}/questions?sort=${sortOption}&type=${filterOption}&size=${size}`;}
if(searchText!=""){redirectUrl=redirectUrl.concat("&q=",searchText);}
location.href=redirectUrl;}}
if($('.block-view-response')[0]){console.log("block-view-response");var decodedAnswer=decodeURIComponent(document.getElementById("hiddenAnswer").value);document.getElementById("readAnswer").innerHTML=decodedAnswer;}
if($('.block-vendor-support-documents')[0]){console.log("vendor-support-documents");function getParameterByName(name){var regexS="[\\?&]"+name+"=([^&#]*)",regex=new RegExp(regexS),results=regex.exec(window.location.search);if(results==null){return "";}else{return decodeURIComponent(results[1].replace(/\+/g," "));}}
var format=/[!@@#$%^&*()+\=\[\]{};':"\\|,.<>\/?]+/;var submitVendorBtn=document.getElementById("submit-vendor");var submitW9Btn=document.getElementById("submit-w9");var submitDiversityBtn=document.getElementById("submit-diversity");var filesToDownload=document.querySelectorAll(".filesToDownload");var vendorDocumentsComponent=document.getElementsByClassName('vendor-content')[0];var vendorDocumentsLi=vendorDocumentsComponent.getElementsByTagName('li')[0];var vendorDocumentsLi_SdAffidavit=vendorDocumentsComponent.getElementsByTagName('li')[2];if(vendorDocumentsLi){vendorDocumentsLi.addEventListener('click',getPrefilledDoc,false);}
if(vendorDocumentsLi_SdAffidavit){vendorDocumentsLi_SdAffidavit.addEventListener('click',getPrefilledDoc_SdAffidavit,false);}
if(filesToDownload!=null){filesToDownload.forEach(function(files){files.addEventListener("click",function(){DownloadFile(files.id);},false);})}
submitVendorBtn.addEventListener("click",UploadFiles);submitW9Btn.addEventListener("click",UploadFiles);submitDiversityBtn.addEventListener("click",UploadFiles);function UploadFiles(evt){evt.preventDefault();evt.stopPropagation();var id=evt.currentTarget.id;var fileId="";var divId="";var ctaId="";var divToRemove="";var formData=new FormData();if(id=="submit-diversity"){fileId="file-upload-diversity";formData.append("method","Diversity");divId="uploadedDiversityDiv";ctaId="upload-cta-diversity";divToRemove="uploadedDiversity";}
else if(id=="submit-w9"){fileId="file-upload-w9";formData.append("method","W9");divId="uploadedw9Div";ctaId="upload-cta-w9";divToRemove="uploadedw9";}
else if(id=="submit-vendor"){fileId="file-upload-vendor";formData.append("method","Affidavit");divId="uploadedVendorDiv";ctaId="upload-cta-vendor";divToRemove="uploadedVendor";}
var fi=document.getElementById(fileId)
var uploadDiv=document.getElementById(divId);var ctaDiv=document.getElementById(ctaId);const file=fi.files[0];formData.append('file',file);var vendor=getParameterByName('vendorId');formData.append("vendorId",vendor);formData.append('fileName',file.name.replace(".pdf",''));$.ajax({type:"POST",url:"/vendor/uploaddocuments",data:formData,cache:false,contentType:false,processData:false,success:function(result){if(!result.HasError){ShowMessage(result.SuccessMessage);var removeDiv=document.getElementById(divToRemove);if(removeDiv){removeDiv.innerHTML="";}
var iDiv=document.createElement('div');var iDivId=result.DataToPass.replace(".pdf",'');iDiv.id=iDivId;iDiv.className='file-upload-done';iDiv.innerHTML=('<a class="filesToDownload" id="'+result.DataToPass+'" > '+result.DataToPass+'</a > ');uploadDiv.appendChild(iDiv);var newFileToDownload=document.getElementById(result.DataToPass);newFileToDownload.addEventListener("click",function(){DownloadFile(newFileToDownload.id);},false);}
else{ShowMessage(result.ErrorMessage);}}});}
function GetFileSizeNameAndType(buttonId){var fi=document.getElementById(buttonId);var element="";var elementDiv="";var method=""
if(buttonId.includes("diversity")){element="uploadedDiversity";elementDiv="uploadedDiversityDiv";method="Diversity";}
else if(buttonId.includes("w9")){element="uploadedw9";elementDiv="uploadedw9Div";method="W9";}
else if(buttonId.includes("vendor")){element="uploadedVendor";elementDiv="uploadedVendorDiv";method="Affidavit";}
if(fi.files.length>0){var fileSize=fi.files[0].size;if(fileSize>4194304){ShowMessage("The file is too large to upload. </br>The maximum supported file sizes are : 4 MB for one document, 10 MB for all documents. The bid will not be submitted. ");return false;}
var tempFilename=fi.files[0].name.replace(".pdf","");if(format.test(tempFilename)){ShowMessage("The file name contains special characters. </br>The bid will not be submitted. ");return false;}
document.getElementById(element).innerHTML="";document.getElementById(elementDiv).classList.remove("hidden");document.getElementById(element).innerHTML=document.getElementById(element).innerHTML+"<p>"+fi.files[0].name.replace(".pdf",'')+"_"+method+".pdf"+"</p>";}}
function DownloadFile(fileName){var vendorId=document.getElementById("vendorId").value;var url="/vendor/downloaddocuments";$.ajax({url:url,contentType:'application/html; charset=utf-8',type:'GET',data:{fileName:fileName,vendorId:vendorId},dataType:'html'}).success(function(result){window.location=url+"?fileName="+fileName+"&vendorId="+vendorId;})}
function ShowMessage(message){$xa(document).accountModal({title:"Vendor Support Documents",message:message,cancel:false});}
function getPrefilledDoc(event){var url="/vendor/vendor-documents/getvendordocument";$.ajax({url:url,contentType:'application/html; charset=utf-8',type:'GET',dataType:'html'}).success(function(result){window.location=url;})
event.preventDefault();}
function getPrefilledDoc_SdAffidavit(event){var url="/vendor/vendor-documents/getsdaffidavitdocument";$.ajax({url:url,contentType:'application/html; charset=utf-8',type:'GET',dataType:'html'}).success(function(result){window.location=url;})
event.preventDefault();}}
if($('.block-ask-question')[0]){console.log("block-ask-question");var submitBtn=document.getElementById("submitBtn");submitBtn.addEventListener("click",Encode);function Encode(){if(document.getElementById("Title").value!==""&&document.getElementById("VendorEmail").value!==""){var text=document.getElementById("askQuestionArea");text.value=escape(text.value);}}}
if($('.block-search-rfb')[0]){console.log("block-search-rfb");var rfbSearch=document.getElementById("rfbNumber");var searchBtn=document.getElementById("btnSearch");var worksheetBtn=document.getElementById("btnWorksheet");var result=document.getElementById("result");var currentSummary=document.getElementById("summaryReplacement");var currentDetail=document.getElementById("detailReplacement");searchBtn.addEventListener("click",getWorksheet);worksheetBtn.addEventListener("click",showDetailSummary);function showDetailSummary(){if(worksheetBtn.innerHTML=="View Summary"){worksheetBtn.innerHTML="View Detail";$('div.submitBid-table').addClass("hidden");$('div.submitBid-table.summary').removeClass("hidden");}
else{worksheetBtn.innerHTML="View Summary";$('div.submitBid-table').removeClass("hidden");$('div.submitBid-table.summary').addClass("hidden");}}
function getWorksheet(){searchBtn.innerHTML="Loading";var rfbNumber=rfbSearch.value;if(rfbNumber.value==""){result.innerText="Please input a RFB number.";return;}
$.ajax({url:'/vendor/vendor-account/getworksheet',contentType:'application/html; charset=utf-8',type:'GET',data:{rfb:rfbNumber},dataType:'html'}).success(function(result){if(result.includes("Sorry, we are unable to locate the requested")){searchBtn.innerHTML="Search";worksheetBtn.innerHTML="View Summary";$('#worksheetButton').addClass("hidden");$('#errorMessage').removeClass("hidden");$('.submitBid-table').addClass("hidden");$('.submitBid-table.summary').addClass("hidden");$('#detailTable').addClass("hidden");$('#errorMessage').html(result);}
else{searchBtn.innerHTML="Search";worksheetBtn.innerHTML="View Summary";$('#worksheetButton').removeClass("hidden");var doc=new DOMParser().parseFromString(result,"text/html");var summary=doc.getElementById("summaryReplacement");var detail=doc.getElementById("detailReplacement");$('#result').html(result);}}).error(function(xhr,status){searchBtn.innerHTML="Search";})};}
if($('.block-bid-search')[0]){console.log("block-bid-search");var searchBtn=document.getElementById("btnSearch");searchBtn.addEventListener("click",viewWorksheet);function viewWorksheet(){$.ajax({url:'/vendor/bid/searchbyrfb',contentType:'application/html; charset=utf-8',type:'GET',data:{rfb:$('#RFB').val()},dataType:'html'}).success(function(result){$('#bidWorksheet').html(result);}).error(function(xhr,status){})};}
if($('.block-bid-details')[0]){console.log("block-bid-details");$(document).on("click",".js-file",function(e){e.preventDefault();var url=ShowFileUrl;var fileName=e.target.getAttribute("data-file");var id=e.target.getAttribute("id-bid");if(id!=""){$.ajax({url:url,type:"GET",data:{bidNumber:id,fileName:fileName},context:this,success:function(response){var url=GetBidFileUrl;window.open(url);}});}
else{}});}
if($('.block-diversity-affidavit')[0]){console.log("block-diversity-affidavit");var btnSave=document.getElementById("btnSave");var btnPrint=document.getElementById("btnPrint");var allInputs=document.querySelectorAll(".diversityForm");var errorMessages=document.getElementById("errorMessages");var isChanged=false;var originalMoiGender=document.getElementById("gender").value;var originalMoiEthnicity=document.getElementById("ethnicity").value;var originalMoiVeteran=document.getElementById("veteran").value;btnSave.addEventListener("click",Save);btnPrint.addEventListener("click",Print);for(let i=0;i<allInputs.length;i++){allInputs[i].addEventListener("change",Changed);}
function Changed(){isChanged=true;}
function Save(){var textInputs=document.querySelectorAll(".number-input")
var africanAmericanPerc=document.getElementById("african-american").value;var americanIndianPerc=document.getElementById("american-indian").value;var caucasianPerc=document.getElementById("caucasian").value;var asianAmericanPerc=document.getElementById("asian-american").value;var hispanicAmericanPerc=document.getElementById("hispanic-american").value;var moiGender=document.getElementById("gender").value;var moiEthnicity=document.getElementById("ethnicity").value
var moiVeteran=document.getElementById("veteran").value;var totalWorkers=document.getElementById("totalEmployees").value;var allInputTrue=true;var message="";for(let i=0;i<allInputs.length;i++){if(allInputs[i].value==""&&!allInputs[i].id.endsWith('2')){allInputs[i].classList.add("field-error");allInputTrue=false;}
else{allInputs[i].classList.remove("field-error");}}
if(!allInputTrue)message+="All the fields are required.Please fill the form correctly. ";var percentageValid=true;for(let i=0;i<textInputs.length;i++){if(textInputs[i].value>100||textInputs[i].value<0||textInputs[i].value==""){if(!textInputs[i].id.endsWith('2')){textInputs[i].classList.add("field-error");allInputTrue=false;percentageValid=false;}}
else{textInputs[i].classList.remove("field-error");}}
if(!percentageValid)message+="The percentage of the fields should be between 0 and 100. ";var totalDivercityPercValid=true;if(allInputTrue){var totalDiversityPerc=parseInt(americanIndianPerc)+parseInt(africanAmericanPerc)+parseInt(caucasianPerc)+parseInt(asianAmericanPerc)+parseInt(hispanicAmericanPerc);if(totalDiversityPerc>100){allInputTrue=false;totalDivercityPercValid=false;}
else{errorMessages.innerText="";}}
if(!totalDivercityPercValid)message+="The total percentage of the fields in Racial Composition of Workforce section shouldn't exceed 100%.";if(!allInputTrue){$xa(document).accountModal({title:"Diversity Affidavit",message:message,cancel:false});return;}
if(totalWorkers<0){allInputTrue=false;$xa(document).accountModal({title:"Diversity Affidavit",message:"Total employees can't be negative.",cancel:false});}
if(moiGender.value=="Select Gender"){allInputTrue=false;$xa(document).accountModal({title:"Diversity Affidavit",message:"Select a gender.",cancel:false});}
if(moiEthnicity.value=="Select Ethnicity"){allInputTrue=false;$xa(document).accountModal({title:"Diversity Affidavit",message:"Select ethnicity.",cancel:false});}
if(moiVeteran.value=="Select Disability Status"){allInputTrue=false;$xa(document).accountModal({title:"Diversity Affidavit",message:"Select disabillity status.",cancel:false});}
if(!allInputTrue){return;}
var owner1=document.getElementById("owner1").value;var telephone1=document.getElementById("telephone1").value;var address1=document.getElementById("address1").value;var city1=document.getElementById("city1").value;var state1=document.getElementById("state1").value;var zip1=document.getElementById("zip1").value;var ownership1=document.getElementById("ownership1").value;var owner2=document.getElementById("owner2").value;var telephone2=document.getElementById("telephone2").value;var address2=document.getElementById("address2").value;var city2=document.getElementById("city2").value;var state2=document.getElementById("state2").value;var zip2=document.getElementById("zip2").value;var ownership2=document.getElementById("ownership2").value;var moiGenderOwnership=document.getElementById("gender-ownership").value;var moiEthnicityOwnership=document.getElementById("ethnicity-ownership").value;var moiTotalEmployees=document.getElementById("totalEmployees").value;var moiPercDisabillity=document.getElementById("disabillityPerc").value;var businessSize="";var businessPrint=document.getElementById("businessPrint");var moiMore=document.getElementById("more");if(moiMore.checked){businessSize="11";businessPrint.value="$6,000,000 or more";}
var moiLess=document.getElementById("less");if(moiLess.checked){businessSize="12";businessPrint.value="Less Than $6,000,000";}
var url="/vendor/reg/updateaffidavit";if(originalMoiGender=="Select Gender"&&originalMoiEthnicity=="Select Ethnicity"&&originalMoiVeteran=="Select Disability Status"){url="/vendor/reg/updateaffidavit";}
$.ajax({url:url,context:this,type:'POST',data:{owner1:owner1,telephone1:telephone1,address1:address1,city1:city1,state1:state1,zip1:zip1,ownership1:ownership1,owner2:owner2,telephone2:telephone2,address2:address2,city2:city2,state2:state2,zip2:zip2,ownership2:ownership2,moiGender:moiGender,moiGenderOwnership:moiGenderOwnership,moiEthnicity:moiEthnicity,moiEthnicityOwnership:moiEthnicityOwnership,moiVeteran:moiVeteran,moiTotalEmployees:moiTotalEmployees,moiPercDisabillity:moiPercDisabillity,businessSize:businessSize,africanAmericanPerc:africanAmericanPerc,americanIndianPerc:americanIndianPerc,caucasianPerc:caucasianPerc,asianAmericanPerc:asianAmericanPerc,hispanicAmericanPerc:hispanicAmericanPerc},dataType:'json'}).success(function(data){if(data.HasError){$xa(document).accountModal({title:"Diversity Affidavit",message:data.ErrorMessage,cancel:false});}
else{$xa(document).accountModal({title:"Diversity Affidavit",message:data.SuccessMessage,cancel:false});isChanged=false;}}).error(function(xhr,status){})}
function Print(){if(isChanged){$xa(document).accountModal({title:"Diversity Affidavit",message:"Please save your changes before printing.",cancel:false});return;}
errorMessages.innerText="";document.getElementById("divToPrint-top").classList.remove("hidden");document.getElementById("divToPrint-bottom").classList.remove("hidden");btnSave.classList.add("hidden");btnPrint.classList.add("hidden");document.getElementById("sizeNormal").classList.add("hidden");document.getElementById("sizePrint").classList.remove("hidden");document.getElementById("address1").value=`${document.getElementById("city1").value}, ${document.getElementById("address1").value}, ${document.getElementById("state1").value}, ${document.getElementById("zip1").value}`
document.getElementById("address2").value=`${document.getElementById("city2").value}, ${document.getElementById("address2").value}, ${document.getElementById("state2").value}, ${document.getElementById("zip2").value}`
document.getElementById("cityPrint1").classList.add("hidden");document.getElementById("zipPrint1").classList.add("hidden");document.getElementById("cityPrint2").classList.add("hidden");document.getElementById("zipPrint2").classList.add("hidden");var moiMore=document.getElementById("more");if(moiMore.checked){businessPrint.value="$6,000,000 or more";}
var moiLess=document.getElementById("less");if(moiLess.checked){businessPrint.value="Less Than $6,000,000";}
window.print();location.reload();}}
document.addEventListener("DOMContentLoaded",function(){var partic=document.getElementById('participation-selection');partic.addEventListener("change",function(){var addr=document.getElementById('section-affidavit-address');if(this.value=="No"){addr.style.display="none";var affidavitAddress=document.getElementById('affidavit-address');var affidavitCity=document.getElementById('affidavit-city');var affidavitState=document.getElementById('affidavit-state');var affidavitZip=document.getElementById('affidavit-zip');affidavitAddress.value="N/A";affidavitCity.value="N/A";affidavitState.value="AL";affidavitZip.value="N/A";}else{addr.style.display="";var newAddress=document.getElementById('order-address');var newCity=document.getElementById('order-city');var newState=document.getElementById('order-state');var newZip=document.getElementById('order-zip');var affidavitAddress=document.getElementById('affidavit-address');var affidavitCity=document.getElementById('affidavit-city');var affidavitState=document.getElementById('affidavit-state');var affidavitZip=document.getElementById('affidavit-zip');affidavitAddress.value=newAddress.value;affidavitCity.value=newCity.value;affidavitState.value=newState.value;affidavitZip.value=newZip.value;var aff=document.getElementById('affidavit-address-selection');aff.Value="OrderAddress";}});var aff=document.getElementById('affidavit-address-selection');if(aff!=null){aff.addEventListener("change",function(){if(this.value=="OrderAddress"){var newAddress=document.getElementById('order-address');var newCity=document.getElementById('order-city');var newState=document.getElementById('order-state');var newZip=document.getElementById('order-zip');}
else if(this.value=="PaymentAddress"){var newAddress=document.getElementById('payment-address');var newCity=document.getElementById('payment-city');var newState=document.getElementById('payment-state');var newZip=document.getElementById('payment-zip');}
else if(this.value=="SalesAddress"){var newAddress=document.getElementById('sales-address');var newCity=document.getElementById('sales-city');var newState=document.getElementById('sales-state');var newZip=document.getElementById('sales-zip');}
var affidavitAddress=document.getElementById('affidavit-address');var affidavitCity=document.getElementById('affidavit-city');var affidavitState=document.getElementById('affidavit-state');var affidavitZip=document.getElementById('affidavit-zip');affidavitAddress.value=newAddress.value;affidavitCity.value=newCity.value;affidavitState.value=newState.value;affidavitZip.value=newZip.value;});}});if($('.block-retrieve-username')[0]){$('#phoneNumber').on('keypress',function(event){var regex=new RegExp("^[0-9]{1,11}$");var key=String.fromCharCode(!event.charCode?event.which:event.charCode);if(!regex.test(key)){event.preventDefault();return false;}});function submitRetrieveUserName(event,recaptchaSiteKey){event.preventDefault();grecaptcha.ready(function(){grecaptcha.execute(recaptchaSiteKey,{action:'submit'}).then(function(token){document.getElementById('recaptchaValue').value=token;var url="/vendor/username/submit";$(":disabled").prop("disabled",false);var formData=new FormData($("#vendor-form")[0]);var allentriesfilled=true;for(var pair of formData.entries()){console.log(pair[0]+' - '+pair[1]);if(pair[1]==null||pair[1]==undefined||pair[1]=="")
allentriesfilled=false;}
if(!allentriesfilled){$xa(document).accountModal({title:"Retrieve Username",message:"All fields are mandatory!",cancel:false});return;}
$.ajax({url:url,type:"POST",data:formData,context:this,processData:false,contentType:false,success:function(response){if(response.HasError){$xa(document).accountModal({title:"Retrieve Username",message:response.ErrorMessage,subtext:"The information provided does not match the information in our system. Please contact NES Support at 615-747-3821, or send an email to: ProcurementAssistance@nespower.com.",cancel:false});}else{$xa(document).accountModal({title:"Retrieve Username",message:response.SuccessMessage,subtext:"If the username, or email address, associated with the account needs to be changed, then please contact NES Support at 615-747-3821, or send an email to: ProcurementAssistance@nespower.com.",cancel:false});$(".nes-modal__ok").bind('click',{param:this},function(event){location.href="/";});}}});});});}}
if($('.block-vendor-registration')[0]){console.log("block-vendor-registration");if(!isNew){$(".step-wrapper").removeClass("mode-edit").removeClass("closed").addClass("mode-done");}
function myPayAddr(){$("#stepPayment .same-address input").trigger("click");}
function mySalesAddr(){$("#stepSales .same-address input").trigger("click");}
function preSelectedServices(){if(!isNew){var myString=myStringServicesList;var textStringWithServices="";var selectedServicesArray=myString.split(",");$('input:checkbox').prop("disabled",true);selectedServicesArray.forEach(function(element){$('input[value="'+element+'"]').prop('checked',true);if(textStringWithServices.length>0){textStringWithServices=textStringWithServices+",<br>"+$('input[value="'+element+'"]').parent().contents()[1].wholeText;}
else{textStringWithServices=$('input[value="'+element+'"]').parent().contents()[1].wholeText;}});$('p[name="pListOfProducts"]').html(textStringWithServices);}}
function validateEIN(){var ein=document.getElementById('ein');if($("#newRegistration").val()=="false"){$(ein).parents(".step-wrapper").removeClass("mode-edit").addClass("mode-done");$(ein).parents(".step-wrapper").find("input").attr("disabled",true);$(ein).parents(".step-wrapper").find("select").attr("disabled",true);$(ein).parents(".step-wrapper").next(".step-wrapper").removeClass("closed");$(ein).parents(".step-wrapper").find('input').each(function(){if($(this).val()==' '){console.log('no value');$(this).parents(".form__field").addClass("no-value");}});}
else{event.preventDefault();event.stopPropagation();var url="/vendor/reg/validateein";var nextStep=document.getElementById('secondStep');var einErrorMessage=document.getElementById('EINError');$.ajax({url:url,type:"POST",data:{ein:ein.value},context:this,dataType:"json",success:function(data){if(data.HasError){event.preventDefault();event.stopPropagation();einErrorMessage.removeAttribute("hidden");}
else{einErrorMessage.setAttribute("hidden","hidden");$(ein).parents(".step-wrapper").removeClass("mode-edit").addClass("mode-done");$(ein).parents(".step-wrapper").find("input").attr("disabled",true);$(ein).parents(".step-wrapper").find("select").attr("disabled",true);$(ein).parents(".step-wrapper").next(".step-wrapper").removeClass("closed");$(ein).parents(".step-wrapper").find('input').each(function(){if($(this).val()==' '){console.log('no value');$(this).parents(".form__field").addClass("no-value");}});}},error:function(xhr,status){einErrorMessage.removeAttribute("hidden");}});}}
function submitVendor(){var url="/vendor/reg/submit";event.preventDefault();$(":disabled").prop("disabled",false);var formData=new FormData($("#vendor-form")[0]);for(var pair of formData.entries()){console.log(pair[0]+' - '+pair[1]);}
btnEl=$('#btnSave');ButtonShowPending(btnEl);$.ajax({url:url,type:"POST",data:formData,context:this,processData:false,contentType:false,success:function(response){if(response.HasError){$xa(document).accountModal({title:"Vendor Registration",message:response.ErrorMessage,cancel:false});ButtonShowOriginal(btnEl);}else{ButtonShowOriginal(btnEl);$xa(document).accountModal({title:"Vendor Registration",message:response.SuccessMessage,cancel:false});$(".nes-modal__ok").bind('click',{param:this},function(event){});}}});}
$(document).ready(function(){setTimeout(preSelectedServices,600);$('#DivCode04,#DivCode03,#DivCode05').on('change',function(){CheckForSDPForm();});$('input[name="service-list"]').on('change',function(){GenerateNameList();});});function GenerateNameList(){var currentText=$(event.target).parent().contents()[1].wholeText;var pToUpdateText=$('p[name="pListOfProducts"]').html();var newText="";if(event.target.checked){if(pToUpdateText.length>0){newText=pToUpdateText+",<br>"+currentText;}
else{newText=currentText;}}
else{if(pToUpdateText.includes(",<br>"+currentText)){newText=pToUpdateText.replace(",<br>"+currentText,"");}
else if(pToUpdateText.includes(currentText+",<br>")){newText=pToUpdateText.replace(currentText+",<br>","")}
else{newText=pToUpdateText.replace(currentText,"");}}
if(newText.startsWith(", ")){newText=newText.substring(2,newText.length);}
$('p[name="pListOfProducts"]').html(newText);}
function CheckForSDPForm(){if($('#DivCode04').val()=="41"||$('#DivCode05').val()=="51"||($('#DivCode03').val()!="34"&&$('#DivCode03').val()!="0")){$("#SupplierDiversityProgramFormMessage").show();}
else{$("div#SupplierDiversityProgramFormMessage").hide();}}
function ButtonShowPending(btnEl){if(btnEl){btnEl.attr('data-orig-text',btnEl.html());btnEl.prop("disabled",true);btnEl.html('Saving...');}}
function ButtonShowOriginal(btnEl){if(btnEl){var txt=btnEl.attr('data-orig-text');if(!txt){txt="Error";}
btnEl.prop("disabled",false);btnEl.html(txt);}}
function search(){var input,filter,ul,li,a,i,txtValue;input=document.getElementById("myInput");if(input.value.length>2){filter=input.value.toUpperCase();ul=$(".toggle-content");ul.parent(".item").hide();li=ul.find("li");for(i=0;i<li.length;i++){txtValue=$(li[i]).find("input").parent().html();if(txtValue.toUpperCase().indexOf(filter)>-1||li[i].className.indexOf("alwaysshow")>-1){li[i].style.display="";if($(li[i]).parent("ul").length){$(li[i]).parent("ul").parent(".item").addClass("active");$(li[i]).parent("ul").parent(".item").show();$(li[i]).parent("ul").parent(".item").parent("ul").parent(".item").addClass("active");$(li[i]).parent("ul").parent(".item").parent("ul").parent(".item").show();}
else{$(li[i]).parent(".item").addClass("active");$(li[i]).parent(".item").show();$(li[i]).parent(".item").parent("ul").parent(".item").addClass("active");$(li[i]).parent(".item").parent("ul").parent(".item").show();}}else{li[i].style.display="none";}}}
if(input.value.length==0){ul=$(".toggle-content");ul.parent(".item").show();ul.parent(".item").removeClass("active");ul.find("li").show();}}}