
(function($){$.fn.cuiPostcodeCheck=function(options){try{$(this).submit(function(){return false;});}finally{}
var self=this;var settings=$.extend({vars:{idPc:'pcc-postcode',idHn:'pcc-huisnr',idDi:'pcc-dienst',idSim:'pcc-sim',idRc:'pcc-request_context',idUs:'pcc-url_success',idTp:'pcc-type',idLi:'pcc-locatie_id',idRcon:'pcc-result',idBut:'pcc-submit',usrPc:false,usrHn:false,sysRc:false,sysUs:false,sysTp:false,sysLi:false,sysDi:false,simRc:false}},options||{});var resultContainer=$('#'+settings.vars.idRcon);var buttonSubmit=$('#'+settings.vars.idBut);var jsonData=false;var aRc=new Array();aRc[-1]='ERROR_EXCEPTION';aRc[-2]='ERROR_NIET_BESTAAND_ADRES';aRc[-3]='ERROR_DUBBELE_ORDER';aRc[-4]='ERROR_INVALID_INPUT';aRc[100]='vroeg om fiber: kreeg fiber';aRc[101]='vroeg om fiber: kreeg vraagbundeling';aRc[102]='vroeg om fiber: geen fiber, wel adsl';aRc[103]='vroeg om fiber: geen matches';aRc[104]='mismatch in locatie_id en opgegeven postcode';aRc[200]='vroeg om adsl: kreeg adsl';aRc[201]='vroeg om adsl: kreeg adsl, ook fiber';aRc[202]='vroeg om adsl: kreeg adsl, ook vraagbundeling';aRc[203]='vroeg om adsl: geen adsl, wel fiber';aRc[204]='vroeg om adsl: geen adsl, wel vraagbundeling';aRc[205]='vroeg om adsl: geen matches';function _displayDialog(str,t){var style='';if(t==='error'){style=' style="color:#ff0000;"';}
var r='<p'+style+'>'+str+'</p>';try{resultContainer.html(r);}catch(err){parent.CICT.log({type:'error',msg:err.description});}};function _notEmpty(s,required){var r=false;var elm=$('#'+s);var v=elm.val();var p=elm.attr('placeholder');if(elm.exists()){if(v!==''&&v!==undefined&&v!==p){r=v;}}else if(required){parent.CICT.log({type:'error',msg:'Field: '+s+' is missing!'});}
return r;};function _validateForm(){if(!settings.vars.usrPc||settings.vars.usrPc.length<6){_displayDialog('U heeft nog geen postcode ingevuld!','error');$('#'+settings.vars.idPc).focus();return false;};if(!settings.vars.usrHn){_displayDialog('U heeft nog geen huisnummer ingevuld!','error');$('#'+settings.vars.idHn).focus();return false;};return true;};function _performCheck(){var url;var ds;if(!settings.vars.simRc){url='/ajax/PostcodeCheck/check';ds={'postcode':settings.vars.usrPc,'huisnr':settings.vars.usrHn,'type':settings.vars.sysTp}
if(location.host=='10.134.3.80:8100')
{url='/proxy.php';url+='?postcode='+settings.vars.usrPc+'&huisnr='+settings.vars.usrHn+'&type='+settings.vars.sysTp;ds=null;}}else{alert('WARNING THIS IS A SIMULATION');url='/ajax/PostcodeCheckSim/check';ds={'type':settings.vars.sysTp,'resultCode':settings.vars.simRc,'locationID':settings.vars.sysLi}}
$.ajax({url:url,dataType:'json',data:ds,success:function(data,textStatus){_handleData(data);},error:function(data,textStatus){_displayDialog('IO ERROR: '+textStatus,'error');}});};function _handleData(d){if(!settings.vars.simRc){if(typeof d.result_code==undefined){_displayDialog('SYSERROR: NO RESULT_CODE RECEIVED','error');return;}
var result_code=Number(d.result_code);if(aRc[result_code]!==undefined){_handleSuccess(result_code);}else{_displayDialog('SYSERROR: RESULT_CODE UNKNOWN ('+result_code+')','error');return;}}else{if(d.sim_result_code){if(d.sim_result_code.length!==null){alert(d.result_code[0]);}else{alert(d.sim_result_code);}
return;}
if(typeof d.result_code==undefined){_displayDialog('SYSERROR: NO RESULT_CODE RECEIVED','error');return;}
var result_code=Number(d.result_code);if(aRc[result_code]!==undefined){_handleSuccess(result_code);}else{_displayDialog('SYSERROR: RESULT_CODE UNKNOWN ('+result_code+')','error');return;}}}
function _handleSuccess(rc){if(rc<0&&rc!==-3&&rc!==-2){_displayDialog(aRc[rc],'error');return;}
var url;switch(rc){case-2:_displayDialog('Dit adres kon niet worden gevonden!','error');break;case-3:parent.CICT.callModal('/modalCheckerShow?pcrc='+rc+'',{});break;case 100:if(typeof settings.vars.sysTp==undefined)
{alert('Geen type');}
if(typeof settings.vars.sysDi==undefined)
{alert('Geen dienst ID');}
var url='/glasvezel/bestellen?dienst='+settings.vars.sysDi;parent.CICT.loadPage(url,'_self');break;case 101:var url='/glasvezel/bestellen?dienst='+settings.vars.sysDi;parent.CICT.loadPage(url,'_self');break;case 102:parent.CICT.callModal('/modalCheckerShow?pcrc='+rc+'',{});break;case 103:parent.CICT.callModal('/modalCheckerShow?pcrc='+rc+'',{});break;case 104:parent.CICT.callModal('/modalCheckerShow?pcrc='+rc+'',{});break;case 200:if(typeof settings.vars.sysTp==undefined)
{alert('Geen postcodecheck type aanwezig!');}
if(typeof settings.vars.sysDi==undefined)
{alert('Geen dienst id aanwezig!');}
var url='/adsl/bestellen?dienst='+settings.vars.sysDi;parent.CICT.loadPage(url,'_self');break;case 201:parent.CICT.callModal('/modalCheckerShow?pcrc='+rc+'&pcdienst='+settings.vars.sysDi,{});break;case 202:parent.CICT.callModal('/modalCheckerShow?pcrc='+rc+'&pcdienst='+settings.vars.sysDi,{});break;case 203:case 204:case 205:parent.CICT.callModal('/modalCheckerShow?pcrc='+rc+'',{});break;default:_displayDialog(aRc[rc]);}};buttonSubmit.bind('click',function(evt){$(evt.target).unbind('click').hide();resultContainer.html(CICT.getLoadIndicator());settings.vars.usrPc=_notEmpty(settings.vars.idPc,true);settings.vars.usrHn=_notEmpty(settings.vars.idHn,true);settings.vars.sysRc=_notEmpty(settings.vars.idRc,true);settings.vars.sysUs=_notEmpty(settings.vars.idUs,true);settings.vars.sysTp=_notEmpty(settings.vars.idTp,true);settings.vars.sysLi=_notEmpty(settings.vars.idLi,true);settings.vars.simRc=_notEmpty('pcc-sim',false);settings.vars.sysDi=_notEmpty('pcc-dienst',false);if(!_validateForm()){$('pcc-result').html();return;}else{_performCheck();}});};})(jQuery);
