
var mcw={};mcw.fillVariables=function(text,variables){$.each(variables,function(name,value){var variablePattern=new RegExp('\\{'+name+'\\}','g');text=text.replace(variablePattern,value);});return text;};mcw.fillElementVariables=function(element,variables){var html=element.html();html=mcw.fillVariables(html,variables);element.html(html);};mcw.getPageUrl=function(){return location.protocol+'//'+location.host+location.pathname;};mcw.removeDuplicates=function(array){var result=[];for(var i=0;i<array.length;i++){for(var j=i+1;j<array.length;j++){if(array[i]===array[j]){j=++i;}}
result.push(array[i]);}
return result;};mcw.openFileLink=function(action,parameters,windowId){var parametersString='';$.each(parameters,function(name,value){parametersString+='&'+name+'='+value;});var url=mcw.configuration.fileLinkUrl
+'?action='
+action
+parametersString;window.open(url,'mcw'+action+windowId);};mcw.adjustValidator=function(){$.validator.addMethod('regularExpression',function(value,element,pattern){if(this.optional(element)){return true;}
var regularExpression=new RegExp(pattern);return regularExpression.test(value);},mcw.i18n.localizeCode('form.field.invalidFormat'));$.validator.addMethod('minInteger',function(value,element,minValue){if(this.optional(element)){return true;}
var number=parseInt(value);if(isNaN(number)){return false;}
$(element).val(number);return number>=minValue;},mcw.i18n.localizeCode('form.field.minInteger'));$.validator.addMethod('maxInteger',function(value,element,minValue){if(this.optional(element)){return true;}
var number=parseInt(value);if(isNaN(number)){return false;}
$(element).val(number);return number<=minValue;},mcw.i18n.localizeCode('form.field.maxInteger'));$.validator.addMethod('rangeInteger',function(value,element,range){if(this.optional(element)){return true;}
var number=parseInt(value);if(isNaN(number)){return false;}
$(element).val(number);return number>=range.minValue&&number<=range.maxValue;},mcw.i18n.localizeCode('form.field.integerOutOfRange'));};mcw.logout=function(){if(mcw.dataCache.loginType==='logout'){return;}
mcw.server.callFunction('logout',{},function(response){location.href=mcw.getPageUrl();});};mcw.reload=function(){location.reload(true);};$(function(){mcw.logger=new mcw.Logger();mcw.server=new mcw.Server();mcw.dataCache=new mcw.DataCache();mcw.request=new mcw.Request();mcw.autoLogout=new mcw.AutoLogout();mcw.i18n=new mcw.I18n();mcw.progressDialog=new mcw.ProgressDialog();mcw.iconSet=new mcw.IconSet(mcw.configuration.iconSet);mcw.countryManager=new mcw.CountryManager();mcw.calendar=new mcw.Calendar();mcw.adjustValidator();mcw.messageForm=new mcw.MessageForm();mcw.menuForm=new mcw.MenuForm();mcw.bootstrap=new mcw.Bootstrap();mcw.bootstrap.boot();});
mcw.Logger=function(level){switch(level){case'ERROR':this.level=1;break;case'WARNING':this.level=2;break;case'INFO':this.level=3;break;default:this.level=0;break;}};mcw.Logger.prototype.logInfo=function(message){if(this.level<3){return;}
this.logMessage(message,'INFO');};mcw.Logger.prototype.logWarning=function(message){if(this.level<2){return;}
this.logMessage(message,'WARNING');};mcw.Logger.prototype.logError=function(message){if(this.level<1){return;}
this.logMessage(message,'ERROR');};mcw.Logger.prototype.logMessage=function(message,type){$('#mcWidget_logArea').prepend('<p class="'+type.toLowerCase()+'">'+this.buildDate()+' ['+type+'] '+message+'</p>');};mcw.Logger.prototype.buildDate=function(){var now=new Date();return now.getFullYear()
+'-'
+this.fillZero(now.getMonth())
+'-'
+this.fillZero(now.getDate())
+' '
+this.fillZero(now.getHours())
+':'
+this.fillZero(now.getMinutes())
+':'
+this.fillZero(now.getSeconds());};mcw.Logger.prototype.fillZero=function(number){return number<10?'0'+number:number;};
mcw.ProgressDialog=function(){var progressSpinner=mcw.configuration.mcwUrl+'/images/progressSpinner.gif';$('#mcWidget_progressBarArea').html('<img src="'+progressSpinner+'" alt="..." />');$('#mcWidget_progressBarArea').dialog({title:mcw.i18n.localizeCode('progressBar.title'),modal:true,autoOpen:false,closeOnEscape:false,draggable:false,resizable:false,stack:false,width:200,height:50,dialogClass:'mcWidget_progressDialog'});};mcw.ProgressDialog.prototype.show=function(){$('#mcWidget_progressBarArea').bind('dialogbeforeclose',function(event,ui){return false;});$('#mcWidget_progressBarArea').dialog('open');};mcw.ProgressDialog.prototype.hide=function(){$('#mcWidget_progressBarArea').unbind('dialogbeforeclose');$('#mcWidget_progressBarArea').dialog('close');};
mcw.Bootstrap=function(){this.requestProcessors={dando:new mcw.DandoProcessor(),emailVerificationConfirmation:new mcw.EmailVerificationConfirmationProcessor(),faq:new mcw.FaqProcessor(),passwordResetConfirmation:new mcw.PasswordResetConfirmationProcessor(),registration:new mcw.RegistrationProcessor(),webPaymentResponse:new mcw.WebPaymentResponseProcessor()};};mcw.Bootstrap.prototype.boot=function(){var self=this;this.registerEvents();self.updateData(function(){mcw.menuForm.display();self.displayLoginAreaForm();self.processRequest();});};mcw.Bootstrap.prototype.registerEvents=function(){var widgetAreas=['mcWidget_logArea','mcWidget_loginArea','mcWidget_menuArea','mcWidget_messageArea','mcWidget_mainArea','mcWidget_progressBarArea'];$.each(widgetAreas,function(index,area){$('#'+area+' a:not(.normal), #'+area+' :button').live('click',function(){$(this).blur();return false;});});};mcw.Bootstrap.prototype.updateData=function(callback){mcw.dataCache.updateAllLogoutData(function(){var loginType=mcw.dataCache.loginType;if(loginType=='user'){mcw.dataCache.updateAllUserData(callback);}else if(loginType=='mpos'){mcw.dataCache.updateAllMposData(callback);}else if(loginType=='msisdn'){mcw.dataCache.updateAllMsisdnData(callback);}else{callback();}});};mcw.Bootstrap.prototype.displayLoginAreaForm=function(){var loginType=mcw.dataCache.loginType;var form;if(loginType=='user'||loginType=='mpos'){form=new mcw.LogoutForm();}else if(loginType=='msisdn'){form=new mcw.MsisdnLogoutForm();}else{form=new mcw.LoginForm();}
form.display();};mcw.Bootstrap.prototype.processRequest=function(){var requestProcessed=false;$.each(this.requestProcessors,function(name,processor){if(processor.isApplicable()){mcw.logger.logInfo('Processing request by the "'+name+'" request processor');requestProcessed=true;processor.processRequest();}});if(requestProcessed){return;}
mcw.logger.logInfo('The request has not been processed');this.processLoginType();};mcw.Bootstrap.prototype.processLoginType=function(){var loginType=mcw.dataCache.loginType;var form;switch(loginType){case'user':form=new mcw.ServicesForm();break;case'mpos':form=new mcw.MposUserListForm();break;case'msisdn':form=new mcw.DandoElementListForm();break;default:form=new mcw.IntroductionForm();break;}
form.display();};
mcw.Request=function(){this.parameters={};this.initializeParameters();};mcw.Request.prototype.initializeParameters=function(){if(!location.search){return;};var self=this;var query=location.search.substr(1);var nameValuePairs=query.split('&');$.each(nameValuePairs,function(index,pair){var nameAndValue=pair.split('=',2);if(nameAndValue.length==2){self.parameters[nameAndValue[0]]=nameAndValue[1];}else{mcw.logger.logInfo('The request parameter "'+nameAndValue[0]+'" has no value');}});};
mcw.Server=function(){this.calls=0;};mcw.Server.prototype.callFunction=function(name,parameters,successCallback,errorCallback){var self=this;this.calls++;mcw.logger.logInfo('Calling server function "'+name+'"');mcw.logger.logInfo('Running server function calls: '+this.calls);if($('#mcWidget_mainArea .progressBar').length==0){mcw.progressDialog.show();}
$.ajax({url:mcw.configuration.callServerFunctionUrl,data:{functionName:name,functionArguments:JSON.stringify(parameters)},dataType:'json',cache:false,timeout:20000,success:function(response,status){mcw.logger.logInfo('Server function "'+name+'" response status: '+status);if(response.errors){mcw.logger.logWarning('Server function "'+name+'" response contains errors');if(errorCallback){errorCallback(response);}else{self.displayErrors(response.errors);}}else{successCallback(response);}
self.endCall();},error:function(request,status,exception){mcw.logger.logError('Server function "'+name+'" response status: '+status);if(status==='timeout'){self.calls--;self.callFunction(name,parameters,successCallback,errorCallback);}else{mcw.reload();}}});mcw.autoLogout.reset();};mcw.Server.prototype.endCall=function(){this.calls--;if(this.calls===0){mcw.progressDialog.hide();}};mcw.Server.prototype.displayErrors=function(errors){mcw.messageForm.reset();$.each(errors,function(index,error){mcw.messageForm.addErrorCode(error);});mcw.messageForm.display();};
mcw.DataCache=function(){this.loginType='logout';this.registrationConstraints=null;this.currencies=null;this.user=null;this.msisdn=null;this.mpos=null;};mcw.DataCache.prototype.updateAllLogoutData=function(callback){var self=this;mcw.server.callFunction('getAllLogoutData',{},function(response){self.loginType=response.loginType;self.registrationConstraints=response.registrationConstraints.constraints;self.currencies=response.currencies;callback();});};mcw.DataCache.prototype.updateAllUserData=function(callback){var self=this;mcw.server.callFunction('getAllUserData',{},function(response){self.loginType='user';self.user=response;callback();});};mcw.DataCache.prototype.updateAllMsisdnData=function(callback){var self=this;mcw.server.callFunction('getAllMsisdnData',{},function(response){self.loginType='msisdn';self.msisdn=response;callback();});};mcw.DataCache.prototype.updateAllMposData=function(callback){var self=this;mcw.server.callFunction('getAllMposData',{},function(response){self.loginType='mpos';self.mpos=response;self.mpos.selectedUserLoginNumber=null;self.mpos.selectedUser=null;callback();});};mcw.DataCache.prototype.updateAllMposSelectedUserData=function(callback){var self=this;mcw.server.callFunction('getAllMposSelectedUserData',{loginNumber:this.mpos.selectedUserLoginNumber},function(response){self.mpos.selectedUser=response;callback();});};
mcw.I18n=function(){this.initializeDatePicker();};mcw.I18n.prototype.initializeDatePicker=function(){var datePickerDefaults=$.datepicker.regional[mcw.configuration.locale];datePickerDefaults.changeMonth=true;$.datepicker.setDefaults(datePickerDefaults);};mcw.I18n.prototype.localizeCode=function(code,variables){var text=code;if(code in this.texts){text=this.texts[code];}else{var codePart=code;for(var lastDot=codePart.lastIndexOf('.');lastDot!=-1;lastDot=codePart.lastIndexOf('.')){codePart=codePart.substr(0,lastDot);if(codePart in this.texts){text=this.texts[codePart];break;}}}
if(variables){text=mcw.fillVariables(text,variables);}
return text;};mcw.I18n.prototype.localizeText=function(text){var self=this;return text.replace(/\{(.*?)\}/g,function(fullMatch,firstGroupMatch){var localizedText=self.localizeCode(firstGroupMatch);if(localizedText==firstGroupMatch){return fullMatch;}else{return localizedText;}});};mcw.I18n.prototype.formatCurrency=function(amount,currencyCode){if(!mcw.dataCache.currencies[currencyCode]){mcw.logger.logWarning('Unknown currency code "'+currencyCode+'"');return amount+' '+currencyCode;}
var currency=mcw.dataCache.currencies[currencyCode];var amountFloat=parseFloat(amount);if(isNaN(amountFloat)){mcw.logger.logError('Invalid currency amount "'+amount+'"');return amount+' '+currencyCode;}
var amountFloat=amountFloat.toFixed(currency.decimalPrecision);var amountString=new String(amountFloat);var parts=amountString.split('.',2);var integralPart=parts[0];var decimalPartWithSeparator;if(parts.length>1){decimalPartWithSeparator=currency.decimalSymbol+parts[1];}else{decimalPartWithSeparator='';}
var thousandsPattern=/(\d+)(\d{3})/;while(thousandsPattern.test(integralPart)){integralPart=integralPart.replace(thousandsPattern,'$1'+currency.thousandsSeparator+'$2');}
var formattedCurrency=mcw.fillVariables(currency.format,{amount:integralPart+decimalPartWithSeparator});return formattedCurrency;};mcw.I18n.prototype.formatDate=function(date,format){var day=date.getDate();var month=date.getMonth()+1;var year=date.getFullYear();var hours=date.getHours();var minutes=date.getMinutes();var seconds=date.getSeconds();var leadingZeroDay=day<10?'0'+day:day;var leadingZeroMonth=month<10?'0'+month:month;var leadingZeroHours=hours<10?'0'+hours:hours;var leadingZeroMinutes=minutes<10?'0'+minutes:minutes;var leadingZeroSeconds=seconds<10?'0'+seconds:seconds;var shortYear=new String(year).substr(2);return mcw.fillVariables(format,{day:day,month:month,year:year,hours:hours,minutes:minutes,seconds:seconds,leadingZeroDay:leadingZeroDay,leadingZeroMonth:leadingZeroMonth,leadingZeroHours:leadingZeroHours,leadingZeroMinutes:leadingZeroMinutes,leadingZeroSeconds:leadingZeroSeconds,shortYear:shortYear});};
mcw.CountryManager=function(){};mcw.CountryManager.prototype.getLocalizedCountries=function(){var localizedCountries=[];$.each(this.countries,function(index,country){var countryName=mcw.i18n.localizeCode('country.'+country.code);localizedCountries.push({code:country.code,name:countryName,callingCodes:country.callingCodes});});localizedCountries.sort(function(country1,country2){if(country1.code<country2.code){return-1;}
if(country1.code>country2.code){return 1;}
return 0;});return localizedCountries;};mcw.CountryManager.prototype.getCallingCodes=function(sortFunction){var callingCodes=[];$.each(this.countries,function(index,country){callingCodes=callingCodes.concat(country.callingCodes);});callingCodes=mcw.removeDuplicates(callingCodes);callingCodes.sort(sortFunction);return callingCodes;};mcw.CountryManager.prototype.splitPhone=function(phone){var callingCodes=this.getCallingCodes(function(code1,code2){return code2.length-code1.length;});var callingCode=null;for(var i=0;i<callingCodes.length;i++){callingCode=callingCodes[i];if(phone.indexOf(callingCode)==0){break;}}
if(callingCode==null){mcw.logger.logWarning('Unknown calling code for the msisdn: "'+phone+'"');return{callingCode:'',localNumber:phone};}
return{callingCode:callingCode,localNumber:phone.substr(callingCode.length)};};mcw.CountryManager.prototype.fillCountries=function(select){var localizedCountries=this.getLocalizedCountries();var options=[];$.each(localizedCountries,function(index,country){options.push('<option value="'+country.code+'">'+country.name+'</option>');});select.html(options.join());};mcw.CountryManager.prototype.fillCallingCodes=function(select){var localizedCountries=this.getLocalizedCountries();var options=[];$.each(localizedCountries,function(index,country){$.each(country.callingCodes,function(index2,callingCode){options.push('<option value="'+callingCode+'">'+country.name+' ['+callingCode+']</option>');});});select.html(options.join());};
mcw.Timer=function(parameters){this.id=parameters.id;this.interval=parameters.interval;this.time=parameters.time;this.remainingTime=this.time;};mcw.Timer.prototype.start=function(){this.stop();var self=this;var callback=function(){self.callbackWrapper();};$('body').everyTime(this.interval*1000,this.id,callback,this.time/this.interval);mcw.logger.logInfo('Timer "'+this.id+'" started');};mcw.Timer.prototype.stop=function(){$('body').stopTime(this.id);mcw.logger.logInfo('Timer "'+this.id+'" stopped');};mcw.Timer.prototype.callbackWrapper=function(){if(this.checkStop()){this.stop();return;}
this.remainingTime-=this.interval;this.callback();};mcw.Timer.prototype.checkStop=function(){mcw.logger.logWarning('The method "mcw.Timer.prototype.checkStop" is not overriden');return false;};mcw.Timer.prototype.callback=function(){mcw.logger.logWarning('The method "mcw.Timer.prototype.callback" is not overriden');};
mcw.AutoLogout=function(){this.timerId='AutoLogout';};mcw.AutoLogout.prototype.reset=function(){mcw.logger.logInfo('AutoLogout: reset');$('body').stopTime(this.timerId);$('body').oneTime(mcw.configuration.inactivityTimeout*60*1000,this.timerId,function(){mcw.logger.logInfo('AutoLogout: log out');mcw.logout();});};
mcw.Calendar=function(){};mcw.Calendar.prototype.getMonthFirstDay=function(){var monthFirstDay=new Date();monthFirstDay.setDate(1);return monthFirstDay;};mcw.Calendar.prototype.getMonthLastDay=function(){var lastDay=31;var today=new Date();var monthLastDay;do{monthLastDay=new Date();monthLastDay.setDate(lastDay--);}while(monthLastDay.getMonth()!==today.getMonth());return monthLastDay;};
mcw.IconSet=function(icons){this.icons=icons;};mcw.IconSet.prototype.hasIcon=function(iconName){return iconName in this.icons;};mcw.IconSet.prototype.getIconPath=function(iconName){return this.icons[iconName];};
mcw.IconSetIcon=function(buttonPrototypes,iconName,buttonClass){this.buttonPrototypes=buttonPrototypes;this.iconName=iconName;this.buttonClass=buttonClass;};mcw.IconSetIcon.prototype.display=function(){var image=this.buttonPrototypes.filter('.iconSet');var text=this.buttonPrototypes.filter('.noIconSet');if(mcw.iconSet.hasIcon(this.iconName)){text.remove();image.find('img').attr('src',mcw.iconSet.getIconPath(this.iconName));}else{image.remove();text.addClass(this.buttonClass);}};
mcw.IconSetButton=function(buttonPrototypes,iconName,enabled){this.buttonPrototypes=buttonPrototypes;this.iconName=iconName;this.enabled=enabled;};mcw.IconSetButton.prototype.display=function(){var image=this.buttonPrototypes.filter('.iconSet');var text=this.buttonPrototypes.filter('.noIconSet');if(mcw.iconSet.hasIcon(this.iconName)){text.remove();var imageInput=image.find(':image');imageInput.attr('src',mcw.iconSet.getIconPath(this.iconName));if(!this.enabled){imageInput.attr('disabled','disabled');imageInput.addClass('disabled');}}else if(!this.enabled){text.remove();image.empty();}else{image.remove();if(!this.enabled){text.find(':button').attr('disabled','disabled');}}};
mcw.FormConstraintBuilder=function(fieldConstraints,fieldMapping){this.fieldConstraints=fieldConstraints;this.fieldMapping=fieldMapping;for(var index in this.fieldMapping){var fieldMapping=this.fieldMapping[index];if(fieldMapping.constructor!=Array){this.fieldMapping[index]=[fieldMapping];}}};mcw.FormConstraintBuilder.prototype.build=function(){var self=this;for(var index in this.fieldConstraints){var fieldConstraints=this.fieldConstraints[index];if(!(fieldConstraints.name in this.fieldMapping)){continue;}
var fields=this.fieldMapping[fieldConstraints.name];$.each(fields,function(index2,field){self.buildFieldConstraints(field,fieldConstraints.constraints);});}};mcw.FormConstraintBuilder.prototype.buildFieldConstraints=function(field,constraints){var hasPhoneConstraint=false;var maxlength=null;for(var index in constraints){var constraint=constraints[index];if(/^maxlength=\d+$/.test(constraint)){var parts=constraint.split('=');maxlength=parts[1];}else if(constraint=='phone'){hasPhoneConstraint=true;}}
for(var index in constraints){var constraint=constraints[index];if(constraint=='required'){this.buildRequiredConstraint(field);}else if(/^maxlength=\d+$/.test(constraint)){if(!hasPhoneConstraint){this.buildMaxlengthConstraint(field,maxlength);}}else if(constraint=='email'){this.buildEmailConstraint(field);}else if(constraint=='phone'){this.buildPhoneConstraint(field,maxlength);}else if(/^intrange=/.test(constraint)){var result=constraint.match(/^intrange=(-?\d+)?,(-?\d+)?$/);var min=result[1];var max=result[2];this.buildIntRangeConstraint(field,min,max);}else if(/^mask=/.test(constraint)){var regularExpression=new RegExp(constraint.substr('mask='.length));this.buildRegularExpressionConstraint(field,regularExpression);}}};mcw.FormConstraintBuilder.prototype.buildRequiredConstraint=function(field){field.rules('add',{required:true,messages:{required:mcw.i18n.localizeCode('form.field.required')}});field.addClass('required');field.parents().find('label[for="'+field.attr('id')+'"]').addClass('required');};mcw.FormConstraintBuilder.prototype.buildMaxlengthConstraint=function(field,maxlength){field.rules('add',{maxlength:maxlength,messages:{maxlength:mcw.i18n.localizeCode('form.field.maxlength',{maxlength:maxlength})}});};mcw.FormConstraintBuilder.prototype.buildEmailConstraint=function(field){field.rules('add',{email:true,messages:{email:mcw.i18n.localizeCode('form.field.invalidFormat.email')}});};mcw.FormConstraintBuilder.prototype.buildPhoneConstraint=function(field,maxlength){field.rules('add',{digits:true,messages:{digits:mcw.i18n.localizeCode('form.field.invalidFormat.phone')}});if(maxlength!=null){var maxPrefixLength=0;$('#'+field.attr('id')+'Prefix option').each(function(){var prefixLength=$(this).val().length;if(prefixLength>maxPrefixLength){maxPrefixLength=prefixLength;}});var maxlengthWithoutPrefix=maxlength-maxPrefixLength;field.rules('add',{maxlength:maxlengthWithoutPrefix,messages:{maxlength:mcw.i18n.localizeCode('form.field.maxlength',{maxlength:maxlengthWithoutPrefix})}});}};mcw.FormConstraintBuilder.prototype.buildIntRangeConstraint=function(field,min,max){if(min==undefined&&max==undefined){mcw.debug('Int range has both min and max undefined');return;}
if(min==undefined){field.rules('add',{maxInteger:max,messages:{maxInteger:mcw.i18n.localizeCode('form.field.maxInteger',{max:max})}});}else if(max==undefined){field.rules('add',{minInteger:min,messages:{minInteger:mcw.i18n.localizeCode('form.field.minInteger',{min:min})}});}else{field.rules('add',{rangeInteger:{minValue:min,maxValue:max},messages:{rangeInteger:mcw.i18n.localizeCode('form.field.integerRange',{min:min,max:max})}});}};mcw.FormConstraintBuilder.prototype.buildRegularExpressionConstraint=function(field,regularExpression){field.rules('add',{regularExpression:regularExpression,messages:{regularExpression:mcw.i18n.localizeCode('form.field.invalidFormat')}});};
mcw.ServiceParameters=function(parameters,element,formId){this.parameters=parameters;this.element=element;this.formId=formId;};mcw.ServiceParameters.prototype.display=function(){var self=this;var textFieldPrototype=this.element.find('div.textField');var checkBoxPrototype=this.element.find('div.checkBox');var msisdnPrototype=this.element.find('div.msisdnField');$.each(this.parameters,function(index,parameter){switch(parameter.type){case'string':case'integer':if(self.hasConstraint(parameter,/^phone$/)){var msisdnParameter=msisdnPrototype.clone();mcw.fillElementVariables(msisdnParameter,{parameterCode:parameter.name,parameterName:mcw.i18n.localizeCode('serviceParameter.'+parameter.name)});mcw.countryManager.fillCallingCodes(msisdnParameter.find('select'));msisdnParameter.find('input').val(parameter.value?parameter.value:'');self.element.append(msisdnParameter);}else{var textFieldParameter=textFieldPrototype.clone();mcw.fillElementVariables(textFieldParameter,{parameterCode:parameter.name,parameterName:mcw.i18n.localizeCode('serviceParameter.'+parameter.name)});textFieldParameter.find('input').val(parameter.value?parameter.value:'');self.element.append(textFieldParameter);}
break;case'boolean':var checkBoxParameter=checkBoxPrototype.clone();mcw.fillElementVariables(checkBoxParameter,{parameterCode:parameter.name,parameterName:mcw.i18n.localizeCode('serviceParameter.'+parameter.name),checked:parameter.value?'checked="checked"':''});self.element.append(checkBoxParameter);break;default:mcw.logger.logWarning('Undefined service parameter data type "'+parameter.type+'"');break;}});textFieldPrototype.remove();checkBoxPrototype.remove();msisdnPrototype.remove();};mcw.ServiceParameters.prototype.applyConstraints=function(){var self=this;var fieldsMapping={};$.each(this.parameters,function(index,parameter){fieldsMapping[parameter.name]=self.element.find('#mcWidget_'+self.formId+'_parameter_'+parameter.name);});var formConstraintBuilder=new mcw.FormConstraintBuilder(this.parameters,fieldsMapping);formConstraintBuilder.build();};mcw.ServiceParameters.prototype.getValues=function(){var self=this;var parameters=[];$.each(this.parameters,function(index,parameter){var field=self.element.find('#mcWidget_'+self.formId+'_parameter_'+parameter.name);if(field.is(':checkbox')){parameters.push({name:parameter.name,value:field.is(':checked')});}else if(self.hasConstraint(parameter,/^phone$/)){var msisdnPrefix=self.element.find('#mcWidget_'+self.formId+'_parameter_'+parameter.name+'Prefix');parameters.push({name:parameter.name,value:msisdnPrefix.val()+field.val()});}else{parameters.push({name:parameter.name,value:field.val()});}});return parameters;};mcw.ServiceParameters.prototype.hasConstraint=function(parameter,pattern){var result=false;$.each(parameter.constraints,function(index,constraint){if(pattern.test(constraint)){result=true;}});return result;};
mcw.FormPaging=function(){this.pageNumber=0;this.pageCount=1;this.pageSize=10;};mcw.FormPaging.prototype.setElementCount=function(count){this.pageCount=Math.ceil(count/this.pageSize);if(this.pageCount==0){this.pageCount++;}};mcw.FormPaging.prototype.adjustHtml=function(html){var self=this;this.html=html;this.html.find('.paging .pageSize').val(this.pageSize);this.html.find('.paging .pageSize').change(function(){self.pageSize=$(this).val();self.pageNumber=0;});this.html.find('.paging .currentPage').html(mcw.i18n.localizeCode('paging.currentPage',{pageNumber:this.pageNumber+1,numberOfPages:this.pageCount}));if(this.pageNumber==0){this.html.find('.paging .firstPage').remove();this.html.find('.paging .previousPage').remove();}else{this.html.find('.paging .firstPage').click(function(){self.moveToFirstPage();});this.html.find('.paging .previousPage').click(function(){self.moveToPreviousPage();});}
if(this.pageNumber==this.pageCount-1){this.html.find('.paging .lastPage').remove();this.html.find('.paging .nextPage').remove();}else{this.html.find('.paging .lastPage').click(function(){self.moveToLastPage();});this.html.find('.paging .nextPage').click(function(){self.moveToNextPage();});}
this.html.find('.selection .selectAll').click(function(){self.selectAll();});this.html.find('.selection .deselectAll').click(function(){self.deselectAll();});};mcw.FormPaging.prototype.moveToFirstPage=function(){this.pageNumber=0;this.changePage();};mcw.FormPaging.prototype.moveToLastPage=function(){this.pageNumber=this.pageCount-1;this.changePage();};mcw.FormPaging.prototype.moveToPreviousPage=function(){this.pageNumber--;this.changePage();};mcw.FormPaging.prototype.moveToNextPage=function(){this.pageNumber++;this.changePage();};mcw.FormPaging.prototype.changePage=function(){mcw.logger.logWarning('The method "mcw.FormPaging.prototype.changePage" is not overriden');};mcw.FormPaging.prototype.selectAll=function(){$('.selection :checkbox').attr('checked','checked');};mcw.FormPaging.prototype.deselectAll=function(){$('.selection :checkbox').removeAttr('checked');};
mcw.FormDateRange=function(parameters){this.from=parameters.from;this.to=parameters.to;this.fromElement=null;this.toElement=null;};mcw.FormDateRange.prototype.getServerFrom=function(){return this.getServerDate(this.from);};mcw.FormDateRange.prototype.getServerTo=function(){return this.getServerDate(this.to);};mcw.FormDateRange.prototype.getServerDate=function(date){var month=date.getMonth()+1;if(month<10){month='0'+month;}
var day=date.getDate();if(day<10){day='0'+day;}
return date.getFullYear()+'-'+month+'-'+day;};mcw.FormDateRange.prototype.adjustHtml=function(fromElement,toElement){var self=this;this.fromElement=fromElement;this.toElement=toElement;this.fromElement.val(mcw.i18n.formatDate(this.from,mcw.i18n.dateFormats.date));this.toElement.val(mcw.i18n.formatDate(this.to,mcw.i18n.dateFormats.date));this.fromElement.datepicker();this.toElement.datepicker();this.fromElement.change(function(){self.from=$(this).datepicker('getDate');});this.toElement.change(function(){self.to=$(this).datepicker('getDate');});};
mcw.DandoProcessor=function(){};mcw.DandoProcessor.prototype.isApplicable=function(){return mcw.request.parameters.action&&mcw.request.parameters.action=='dando';};mcw.DandoProcessor.prototype.processRequest=function(){var form;if(mcw.dataCache.loginType=='logout'){form=new mcw.DandoPsmsLoginForm();}else{form=new mcw.DandoElementListForm();}
form.display();};
mcw.EmailVerificationConfirmationProcessor=function(){};mcw.EmailVerificationConfirmationProcessor.prototype.isApplicable=function(){return mcw.request.parameters.action&&mcw.request.parameters.action=='emailVerification'&&mcw.request.parameters.key&&mcw.request.parameters.email&&mcw.request.parameters.loginNumber;};mcw.EmailVerificationConfirmationProcessor.prototype.processRequest=function(){var self=this;mcw.server.callFunction('validateVerification',{action:'emailVerification',code:mcw.request.parameters.key},function(response){self.displayResult(true);},function(response){self.displayResult(false);});};mcw.EmailVerificationConfirmationProcessor.prototype.displayResult=function(confirmed){var loginType=mcw.dataCache.loginType;var loginNumber=mcw.request.parameters.loginNumber;var email=mcw.request.parameters.email;mcw.messageForm.reset();if(confirmed){if(loginType=='user'){mcw.messageForm.addSuccessCode('emailVerificationConfirmation.success.login.par1',{email:email,loginNumber:loginNumber});mcw.dataCache.updateAllUserData(function(){mcw.messageForm.display();});}else{mcw.messageForm.addSuccessCode('emailVerificationConfirmation.success.logout.par1',{email:email,loginNumber:loginNumber});mcw.messageForm.display();}}else{mcw.messageForm.addErrorCode('emailVerificationConfirmation.failure.par1',{email:email,loginNumber:loginNumber});mcw.messageForm.display();}};
mcw.FaqProcessor=function(){};mcw.FaqProcessor.prototype.isApplicable=function(){return mcw.request.parameters.action&&mcw.request.parameters.action=='faq';};mcw.FaqProcessor.prototype.processRequest=function(){new mcw.FaqForm().display();};
mcw.PasswordResetConfirmationProcessor=function(){};mcw.PasswordResetConfirmationProcessor.prototype.isApplicable=function(){return mcw.request.parameters.action&&mcw.request.parameters.action=='resetPassword'&&mcw.request.parameters.key;};mcw.PasswordResetConfirmationProcessor.prototype.processRequest=function(){var form=new mcw.PasswordResetConfirmationForm({key:mcw.request.parameters.key});form.display();};
mcw.RegistrationProcessor=function(){};mcw.RegistrationProcessor.prototype.isApplicable=function(){return mcw.request.parameters.action&&mcw.request.parameters.action=='registration';};mcw.RegistrationProcessor.prototype.processRequest=function(){new mcw.UserRegistrationForm().display();};
mcw.WebPaymentResponseProcessor=function(){};mcw.WebPaymentResponseProcessor.prototype.isApplicable=function(){return mcw.request.parameters.orderNumber&&mcw.request.parameters.result&&mcw.request.parameters.digest&&mcw.request.parameters.loginNumber;};mcw.WebPaymentResponseProcessor.prototype.processRequest=function(){var self=this;mcw.dataCache.mpos.selectedUserLoginNumber=mcw.request.parameters.loginNumber;mcw.server.callFunction('mposVerifyWebpayment',{loginNumber:mcw.dataCache.mpos.selectedUserLoginNumber,orderNumber:mcw.request.parameters.orderNumber,result:mcw.request.parameters.result,digest:mcw.request.parameters.digest},function(response){self.displayResult(response.orderResult);},function(response){self.displayResult(response.orderResult);});};mcw.WebPaymentResponseProcessor.prototype.displayResult=function(result){mcw.dataCache.updateAllMposSelectedUserData(function(){mcw.messageForm.reset();if(result){mcw.messageForm.addSuccessCode('mposTopup.topup.success');}else{if(mcw.request.parameters.result=='NO_CREDIT'){mcw.messageForm.addErrorCode('mposTopup.topup.error.no_credit');}else{mcw.messageForm.addErrorCode('mposTopup.topup.error');}}
mcw.messageForm.display();new mcw.MposUserDetailForm().display();});};
mcw.Form=function(parameters){if(!parameters){parameters={};}
this.data={};this.htmlTemplateId=parameters.htmlTemplateId;this.localizedHtmlTemplate=parameters.localizedHtmlTemplate;this.menuItem=parameters.menuItem;};mcw.Form.prototype.display=function(){var self=this;this.highlightMenuItem();this.loadData(function(){self.displayData();});};mcw.Form.prototype.loadData=function(callback){callback();};mcw.Form.prototype.displayData=function(){if(this.checkErrorData()){this.displayErrorData();}else{this.displaySuccessData();}};mcw.Form.prototype.checkErrorData=function(){return this.data.errors;};mcw.Form.prototype.displayErrorData=function(){mcw.messageForm.reset();$.each(this.data.errors,function(index,error){mcw.messageForm.addErrorCode(error);});mcw.messageForm.display();};mcw.Form.prototype.displaySuccessData=function(){var self=this;this.loadHtmlTemplate(function(){self.adjustHtmlTemplate();self.displayHtml();self.adjustDom();});};mcw.Form.prototype.loadHtmlTemplate=function(callback){if(this.htmlTemplate){callback();return;}
var self=this;var htmlTemplateUrl;if(this.localizedHtmlTemplate){htmlTemplateUrl=mcw.configuration.mcwUrl+'/i18n/'+mcw.configuration.locale+'/html/'+this.htmlTemplateId+'.html';}else{htmlTemplateUrl=mcw.configuration.mcwUrl+'/html/'+this.htmlTemplateId+'.html';}
$.ajax({dataType:'html',cache:true,timeout:10000,url:htmlTemplateUrl,success:function(htmlTemplate,status){mcw.logger.logInfo('HTML template "'+self.htmlTemplateId+'": is loaded');if(self.localizedHtmlTemplate){self.constructor.prototype.htmlTemplate=htmlTemplate;}else{self.constructor.prototype.htmlTemplate=mcw.i18n.localizeText(htmlTemplate);}
callback();},error:function(request,status,exception){mcw.logger.logError('HTML template "'+self.htmlTemplateId+'" cannot be loaded, response status: '+status);if(status==='timeout'){self.loadHtmlTemplate(callback);}else{mcw.reload();}}});};mcw.Form.prototype.adjustHtmlTemplate=function(){};mcw.Form.prototype.displayHtml=function(){this.html=$(this.htmlTemplate);this.adjustHtmlByRole();this.adjustHtml();this.getDisplayElement().html(this.html);};mcw.Form.prototype.highlightMenuItem=function(){if(!this.menuItem){return;}
mcw.menuForm.highlightItem(this.menuItem);};mcw.Form.prototype.adjustHtmlByRole=function(){var self=this;var roles=['logout','user','msisdn','mpos'];var currentRolePosition=$.inArray(mcw.dataCache.loginType,roles);delete roles[currentRolePosition];$.each(roles,function(index,role){self.html.find('.'+role).not('.'+mcw.dataCache.loginType).remove();});};mcw.Form.prototype.adjustHtml=function(){};mcw.Form.prototype.getDisplayElement=function(){return $('#mcWidget_mainArea');};mcw.Form.prototype.adjustDom=function(){};
mcw.MessageForm=function(){this.reset();};mcw.MessageForm.prototype=new mcw.Form({htmlTemplateId:'message'});mcw.MessageForm.prototype.constructor=mcw.MessageForm;mcw.MessageForm.prototype.getDisplayElement=function(){return $('#mcWidget_messageArea');};mcw.MessageForm.prototype.adjustHtml=function(){if(this.successes.length==0&&this.notifications.length==0&&this.errors.length==0){this.html.empty();return;}
this.adjustMessages(this.successes,'success');this.adjustMessages(this.notifications,'notification');this.adjustMessages(this.errors,'error');};mcw.MessageForm.prototype.adjustMessages=function(messages,liClass){var liPrototype=this.html.find('li.'+liClass);$.each(messages,function(index,message){var li=liPrototype.clone();li.html(message);li.insertBefore(liPrototype);});liPrototype.remove();};mcw.MessageForm.prototype.addSuccess=function(message){this.successes.push(message);};mcw.MessageForm.prototype.addNotification=function(message){this.notifications.push(message);};mcw.MessageForm.prototype.addError=function(message){this.errors.push(message);};mcw.MessageForm.prototype.addSuccessCode=function(code,variables){var message=mcw.i18n.localizeCode(code,variables);this.successes.push(message);};mcw.MessageForm.prototype.addNotificationCode=function(code,variables){var message=mcw.i18n.localizeCode(code,variables);this.notifications.push(message);};mcw.MessageForm.prototype.addErrorCode=function(code,variables){var message=mcw.i18n.localizeCode(code,variables);this.errors.push(message);};mcw.MessageForm.prototype.reset=function(){this.errors=[];this.notifications=[];this.successes=[];};mcw.MessageForm.prototype.clear=function(){this.reset();this.display();};
mcw.MenuForm=function(){this.highlightedItem=null;};mcw.MenuForm.prototype=new mcw.Form({htmlTemplateId:'menu'});mcw.MenuForm.prototype.constructor=mcw.MenuForm;mcw.MenuForm.prototype.getDisplayElement=function(){return $('#mcWidget_menuArea');};mcw.MenuForm.prototype.adjustHtml=function(){this.removeMenuItemsByLoginType();this.registerEvents();};mcw.MenuForm.prototype.removeMenuItemsByLoginType=function(){this.html.find('li').not('.'+mcw.dataCache.loginType).remove();if(!this.isAwegActive()){this.html.find('#mcWidget_menu_aweg').parent().remove();}};mcw.MenuForm.prototype.isAwegActive=function(){try{return mcw.dataCache.user.services.AWEG.active;}catch(error){return false;}};mcw.MenuForm.prototype.registerEvents=function(){var self=this;this.html.find('#mcWidget_menu_myAccount').click(function(){self.displayForm(new mcw.UserEditForm());});this.html.find('#mcWidget_menu_topup').click(function(){self.displayForm(new mcw.TopupForm());});this.html.find('#mcWidget_menu_services').click(function(){self.displayForm(new mcw.ServicesForm());});this.html.find('#mcWidget_menu_dando').click(function(){self.displayForm(new mcw.DandoElementListForm());});this.html.find('#mcWidget_menu_dandoPsms').click(function(){if(mcw.dataCache.loginType=='msisdn'){self.displayForm(new mcw.DandoElementListForm());}else{self.displayForm(new mcw.DandoPsmsLoginForm());}});this.html.find('#mcWidget_menu_aweg').click(function(){self.displayForm(new mcw.AwegSendSmsForm());});this.html.find('#mcWidget_menu_eventLog').click(function(){self.displayForm(new mcw.EventLogForm());});this.html.find('#mcWidget_menu_faq').click(function(){self.displayForm(new mcw.FaqForm());});this.html.find('#mcWidget_menu_mposUserRegistration').click(function(){self.displayForm(new mcw.MposUserRegistrationForm());});this.html.find('#mcWidget_menu_mposUserList').click(function(){self.displayForm(new mcw.MposUserListForm());});this.html.find('#mcWidget_menu_mposFindUser').click(function(){self.displayForm(new mcw.MposFindUserForm());});this.html.find('#mcWidget_menu_logout').click(function(){mcw.logout();});};mcw.MenuForm.prototype.displayForm=function(form){mcw.messageForm.clear();form.display();};mcw.MenuForm.prototype.highlightItem=function(item){if(item){this.highlightedItem=item;}
if(!this.highlightedItem){return;}
$('#mcWidget_menuArea a').removeClass('current');$('#mcWidget_menu .'+this.highlightedItem).addClass('current');};mcw.MenuForm.prototype.adjustDom=function(){this.highlightItem();};
mcw.LoginForm=function(){};mcw.LoginForm.prototype=new mcw.Form({htmlTemplateId:'login'});mcw.LoginForm.prototype.constructor=mcw.LoginForm;mcw.LoginForm.prototype.getDisplayElement=function(){return $('#mcWidget_loginArea');};mcw.LoginForm.prototype.adjustHtml=function(){var self=this;this.html.find('form').validate({submitHandler:function(){self.login();},messages:{accountNumber:{required:mcw.i18n.localizeCode('login.accountNumber.required')},password:{required:mcw.i18n.localizeCode('login.password.required')}}});this.html.find('#mcWidget_login_register').click(function(){new mcw.UserRegistrationForm().display();});this.html.find('#mcWidget_login_forgottenLogin').click(function(){var forgottenLoginForm=new mcw.ForgottenLoginForm();forgottenLoginForm.display();});};mcw.LoginForm.prototype.login=function(){var loginNumber=$('#mcWidget_login_accountNumber').val();mcw.server.callFunction('login',{accountNumber:loginNumber,password:$('#mcWidget_login_password').val()},function(response){mcw.messageForm.clear();if(response.loginType=='mpos'){mcw.dataCache.updateAllMposData(function(){new mcw.LogoutForm().display();mcw.menuForm.display();new mcw.MposUserListForm().display();});}else{mcw.dataCache.updateAllUserData(function(){new mcw.LogoutForm().display();mcw.menuForm.display();new mcw.ServicesForm().display();});}});};
mcw.LogoutForm=function(){};mcw.LogoutForm.prototype=new mcw.Form({htmlTemplateId:'logout'});mcw.LogoutForm.prototype.constructor=mcw.LogoutForm;mcw.LogoutForm.prototype.getDisplayElement=function(){return $('#mcWidget_loginArea');};mcw.LogoutForm.prototype.adjustHtml=function(){var loginNumber=mcw.dataCache.loginType=='mpos'?mcw.dataCache.mpos.loginNumber:mcw.dataCache.user.loginNumber;mcw.fillElementVariables(this.html,{loginUser:loginNumber,userName:this.formatUserName()});if(mcw.dataCache.loginType=='user'){this.adjustCredits();}else{this.html.find('.credit').remove();}};mcw.LogoutForm.prototype.formatUserName=function(){if(mcw.dataCache.loginType=='mpos'){return mcw.dataCache.mpos.person.firstName+' '+mcw.dataCache.mpos.person.lastName;}else{return mcw.dataCache.user.person.firstName+' '+mcw.dataCache.user.person.lastName;}};mcw.LogoutForm.prototype.adjustCredits=function(){var self=this;var liPrototype=this.html.find('ul.credits li');$.each(mcw.dataCache.user.balance,function(index,balance){var li=liPrototype.clone();mcw.fillElementVariables(li,{credit:self.formatCredit(balance)});li.insertBefore(liPrototype);});liPrototype.remove();};mcw.LogoutForm.prototype.formatCredit=function(balance){return mcw.i18n.formatCurrency(balance.amount,balance.currency);};
mcw.IntroductionForm=function(){};mcw.IntroductionForm.prototype=new mcw.Form({htmlTemplateId:'introduction',menuItem:'introduction',localizedHtmlTemplate:true});mcw.IntroductionForm.prototype.constructor=mcw.IntroductionForm;mcw.IntroductionForm.prototype.adjustHtml=function(){this.html.find('a.normal').attr('href','http://www.maternacz.com/cs/mobilni-platby-pro-firmy.php');};
mcw.FaqForm=function(){};mcw.FaqForm.prototype=new mcw.Form({htmlTemplateId:'faq',menuItem:'faq',localizedHtmlTemplate:true});mcw.FaqForm.prototype.constructor=mcw.FaqForm;mcw.FaqForm.prototype.adjustHtml=function(){mcw.fillElementVariables(this.html,{registrationPsmsText:'MMREG JMENO PRIJMENI',registrationPsmsBnumber:'9023099',userAttributeSettingSmsText:'MMNAST RZ hodnota',userAttributeSettingBnumber:'910304048'});};
mcw.AbstractRegistrationForm=function(){};mcw.AbstractRegistrationForm.prototype=new mcw.Form({htmlTemplateId:'registration',menuItem:'myAccount'});mcw.AbstractRegistrationForm.prototype.constructor=mcw.AbstractRegistrationForm;mcw.AbstractRegistrationForm.prototype.adjustHtml=function(){var self=this;mcw.countryManager.fillCountries(this.html.find('#mcWidget_registration_country'));mcw.countryManager.fillCountries(this.html.find('#mcWidget_registration_deliveryAddress_country'));mcw.countryManager.fillCountries(this.html.find('#mcWidget_registration_invoicingAddress_country'));mcw.countryManager.fillCallingCodes(this.html.find('#mcWidget_registration_phonePrefix'));this.html.find('#mcWidget_registration_specifyDeliveryAddress').click(function(){$('#mcWidget_registration .deliveryAddressField').toggle();});this.html.find('#mcWidget_registration_specifyCompany').click(function(){$('#mcWidget_registration .companyField').toggle();});this.html.find('#mcWidget_registration_specifyInvoicingAddress').click(function(){$('#mcWidget_registration .invoicingAddressField').toggle();});this.html.find('.deliveryAddressField, .invoicingAddressField, .companyField').hide();this.adjustAbstractRegistrationHtml();this.applyRegistrationConstraints();};mcw.AbstractRegistrationForm.prototype.adjustAbstractRegistrationHtml=function(){};mcw.AbstractRegistrationForm.prototype.applyRegistrationConstraints=function(){var formConstraintBuilder=new mcw.FormConstraintBuilder(mcw.dataCache.registrationConstraints,{prefix:this.html.find('#mcWidget_registration_prefix'),firstName:this.html.find('#mcWidget_registration_firstName'),middleName:this.html.find('#mcWidget_registration_middleName'),lastName:this.html.find('#mcWidget_registration_surname'),suffix:this.html.find('#mcWidget_registration_suffix'),companyName:this.html.find('#mcWidget_registration_companyName'),ic:this.html.find('#mcWidget_registration_companyRegistrationNumber'),dic:this.html.find('#mcWidget_registration_vatRegistrationNumber'),city:[this.html.find('#mcWidget_registration_city'),this.html.find('#mcWidget_registration_deliveryAddress_city'),this.html.find('#mcWidget_registration_invoicingAddress_city')],country:[this.html.find('#mcWidget_registration_country'),this.html.find('#mcWidget_registration_deliveryAddress_country'),this.html.find('#mcWidget_registration_invoicingAddress_country')],streetnumber:[this.html.find('#mcWidget_registration_streetNumber'),this.html.find('#mcWidget_registration_deliveryAddress_streetNumber'),this.html.find('#mcWidget_registration_invoicingAddress_streetNumber')],street:[this.html.find('#mcWidget_registration_street'),this.html.find('#mcWidget_registration_deliveryAddress_street'),this.html.find('#mcWidget_registration_invoicingAddress_street')],zip:[this.html.find('#mcWidget_registration_postalCode'),this.html.find('#mcWidget_registration_deliveryAddress_postalCode'),this.html.find('#mcWidget_registration_invoicingAddress_postalCode')],phone:this.html.find('#mcWidget_registration_phone'),email:this.html.find('#mcWidget_registration_email')});formConstraintBuilder.build();};mcw.AbstractRegistrationForm.prototype.buildParameters=function(){var primaryAddress={city:$('#mcWidget_registration_city').val(),street:$('#mcWidget_registration_street').val(),number:$('#mcWidget_registration_streetNumber').val(),zipCode:$('#mcWidget_registration_postalCode').val(),countryIsoCode:$('#mcWidget_registration_country').val(),addressType:'primary'};var addresses=[primaryAddress];if($('#mcWidget_registration_specifyDeliveryAddress').is(':checked')){var deliveryAddress={city:$('#mcWidget_registration_deliveryAddress_city').val(),street:$('#mcWidget_registration_deliveryAddress_street').val(),number:$('#mcWidget_registration_deliveryAddress_streetNumber').val(),zipCode:$('#mcWidget_registration_deliveryAddress_postalCode').val(),countryIsoCode:$('#mcWidget_registration_deliveryAddress_country').val(),addressType:'delivery'};addresses.push(deliveryAddress);}
if($('#mcWidget_registration_specifyInvoicingAddress').is(':checked')){var invoicingAddress={city:$('#mcWidget_registration_invoicingAddress_city').val(),street:$('#mcWidget_registration_invoicingAddress_street').val(),number:$('#mcWidget_registration_invoicingAddress_streetNumber').val(),zipCode:$('#mcWidget_registration_invoicingAddress_postalCode').val(),countryIsoCode:$('#mcWidget_registration_invoicingAddress_country').val(),addressType:'invoicing'};addresses.push(invoicingAddress);}
var company;if($('#mcWidget_registration_specifyCompany').is(':checked')){company={name:$('#mcWidget_registration_companyName').val(),IC:$('#mcWidget_registration_companyRegistrationNumber').val(),DIC:$('#mcWidget_registration_vatRegistrationNumber').val()};}else{company=null;}
var parameters={phone:$('#mcWidget_registration_phonePrefix').val()+$('#mcWidget_registration_phone').val(),fax:'',email:$('#mcWidget_registration_email').val(),address:addresses,person:{salutation:'',prefix:$('#mcWidget_registration_prefix').val(),firstName:$('#mcWidget_registration_firstName').val(),middleName:$('#mcWidget_registration_middleName').val(),lastName:$('#mcWidget_registration_surname').val(),suffix:$('#mcWidget_registration_suffix').val()},company:company,marketingAgreement:$('#mcWidget_registration_marketingAgreement').is(':checked'),url:mcw.getPageUrl()};return this.adjustParameters(parameters);};mcw.AbstractRegistrationForm.prototype.adjustParameters=function(parameters){return parameters;};
mcw.RegistrationForm=function(){};mcw.RegistrationForm.prototype=new mcw.AbstractRegistrationForm();mcw.RegistrationForm.prototype.constructor=mcw.RegistrationForm;mcw.RegistrationForm.prototype.adjustAbstractRegistrationHtml=function(){var self=this;this.html.find('.myAccount').remove();this.html.find('#mcWidget_registration_password1').blur(function(){$('#mcWidget_registration_password2').valid();});this.html.find('form').validate({submitHandler:function(){self.getSubmitHandler()},rules:{mcWidget_registration_password1:{rangelength:[6,13]},mcWidget_registration_password2:{equalTo:'#mcWidget_registration_password1'}},messages:{mcWidget_registration_password1:{required:mcw.i18n.localizeCode('registration.password1.required'),rangelength:mcw.i18n.localizeCode('registration.password.length')},mcWidget_registration_password2:{required:mcw.i18n.localizeCode('registration.password2.required'),equalTo:mcw.i18n.localizeCode('registration.passwords.equal')}},errorPlacement:function(error,element){element.parent().append(error);}});this.adjustRegistrationHtml();};mcw.RegistrationForm.prototype.getSubmitHandler=function(){this.register();};mcw.RegistrationForm.prototype.adjustRegistrationHtml=function(){};mcw.RegistrationForm.prototype.register=function(){mcw.logger.logWarning('The method "mcw.UserRegistrationForm.prototype.register" is not overriden');};mcw.RegistrationForm.prototype.adjustParameters=function(parameters){parameters.password=$('#mcWidget_registration_password1').val();return parameters;};
mcw.UserRegistrationForm=function(){};mcw.UserRegistrationForm.prototype=new mcw.RegistrationForm();mcw.UserRegistrationForm.prototype.constructor=mcw.UserRegistrationForm;mcw.UserRegistrationForm.prototype.adjustRegistrationHtml=function(){this.fillRegistrationParameters();};mcw.UserRegistrationForm.prototype.getSubmitHandler=function(){this.verifyMsisdn();};mcw.UserRegistrationForm.prototype.verifyMsisdn=function(){var self=this;this.registrationParameters=this.buildParameters();var msisdn=$('#mcWidget_registration_phonePrefix').val()+$('#mcWidget_registration_phone').val();var form=new mcw.AnonymousMsisdnVerificationForm({msisdn:msisdn});form.displaySuccessResult=function(){self.register();};mcw.messageForm.clear();form.display();};mcw.UserRegistrationForm.prototype.register=function(){var self=this;mcw.server.callFunction('registerAndLogin',this.registrationParameters,function(response){mcw.dataCache.updateAllUserData(function(){self.displayLoggedInUser();});},function(response){self.display();mcw.server.displayErrors(response.errors);});};mcw.UserRegistrationForm.prototype.displayLoggedInUser=function(){new mcw.LogoutForm().display();mcw.menuForm.display();mcw.messageForm.reset();mcw.messageForm.addSuccessCode('registration.register.success',{accountNumber:mcw.dataCache.user.loginNumber});mcw.messageForm.addSuccessCode('registration.register.success.setServices');mcw.messageForm.addSuccessCode('registration.register.success.topup');if(mcw.dataCache.user.email){mcw.messageForm.addNotificationCode('registration.register.success.sentToEmail',{email:mcw.dataCache.user.email});}
mcw.messageForm.display();new mcw.ServicesForm().display();};mcw.UserRegistrationForm.prototype.fillRegistrationParameters=function(){var self=this;if(!this.registrationParameters){return;}
this.html.find('#mcWidget_registration_prefix').val(this.registrationParameters.person.prefix);this.html.find('#mcWidget_registration_firstName').val(this.registrationParameters.person.firstName);this.html.find('#mcWidget_registration_middleName').val(this.registrationParameters.person.middleName);this.html.find('#mcWidget_registration_surname').val(this.registrationParameters.person.lastName);this.html.find('#mcWidget_registration_suffix').val(this.registrationParameters.person.suffix);if(this.registrationParameters.company){this.html.find('.companyField').show();this.html.find('#mcWidget_registration_companyName').val(this.registrationParameters.company.name);this.html.find('#mcWidget_registration_companyRegistrationNumber').val(this.registrationParameters.company.IC);this.html.find('#mcWidget_registration_vatRegistrationNumber').val(this.registrationParameters.company.DIC);}
$.each(this.registrationParameters.address,function(index,address){var fieldNamePrefix;switch(address.addressType){case'delivery':fieldNamePrefix='deliveryAddress_';self.html.find('.deliveryAddressField').show();break;case'invoicing':fieldNamePrefix='invoicingAddress_';self.html.find('.invoicingAddressField').show();break;default:fieldNamePrefix='';break;}
self.html.find('#mcWidget_registration_'+fieldNamePrefix+'street').val(address.street);self.html.find('#mcWidget_registration_'+fieldNamePrefix+'streetNumber').val(address.number);self.html.find('#mcWidget_registration_'+fieldNamePrefix+'city').val(address.city);self.html.find('#mcWidget_registration_'+fieldNamePrefix+'postalCode').val(address.zipCode);self.html.find('#mcWidget_registration_'+fieldNamePrefix+'country').val(address.countryIsoCode);});var phone=mcw.countryManager.splitPhone(this.registrationParameters.phone);this.html.find('#mcWidget_registration_phonePrefix').val(phone.callingCode);this.html.find('#mcWidget_registration_phone').val(phone.localNumber);this.html.find('#mcWidget_registration_email').val(this.registrationParameters.email);};mcw.UserRegistrationForm.prototype.adjustDom=function(){if(!this.registrationParameters){return;}
if(this.registrationParameters.company){$('#mcWidget_registration_specifyCompany').attr('checked','checked');}
$.each(this.registrationParameters.address,function(index,address){switch(address.addressType){case'delivery':$('#mcWidget_registration_specifyDeliveryAddress').attr('checked','checked');break;case'invoicing':$('#mcWidget_registration_specifyInvoicingAddress').attr('checked','checked');break;}});if(this.registrationParameters.marketingAgreement){$('#mcWidget_registration_marketingAgreement').attr('checked','checked');}};
mcw.EditForm=function(){};mcw.EditForm.prototype=new mcw.AbstractRegistrationForm();mcw.EditForm.prototype.constructor=mcw.EditForm;mcw.EditForm.prototype.adjustAbstractRegistrationHtml=function(){var self=this;this.html.find('.registration').remove();this.fillData();this.html.find('form').validate({submitHandler:function(){self.save();},rules:{mcWidget_registration_currentPassword:{required:'#mcWidget_registration_newPassword1:filled'},mcWidget_registration_newPassword1:{required:'#mcWidget_registration_currentPassword:filled',rangelength:[6,13]},mcWidget_registration_newPassword2:{required:'#mcWidget_registration_currentPassword:filled',equalTo:'#mcWidget_registration_newPassword1'}},messages:{mcWidget_registration_currentPassword:{required:mcw.i18n.localizeCode('registration.currentPassword.required')},mcWidget_registration_newPassword1:{required:mcw.i18n.localizeCode('registration.newPassword1.required'),rangelength:mcw.i18n.localizeCode('registration.password.length')},mcWidget_registration_newPassword2:{required:mcw.i18n.localizeCode('registration.newPassword2.required'),equalTo:mcw.i18n.localizeCode('registration.newPasswords.equal')}},errorPlacement:function(error,element){element.parent().append(error);}});this.html.find('#mcWidget_registration_verifyMsisdn').click(function(){self.verifyMsisdn();});this.html.find('#mcWidget_registration_verifyEmail').click(function(){self.verifyEmail();});this.html.find('#mcWidget_registration_newPassword1').blur(function(){$('#mcWidget_registration_newPassword2').valid();});};mcw.EditForm.prototype.fillData=function(){var user=this.getUserData();this.html.find('#mcWidget_registration_prefix').val(user.person.prefix);this.html.find('#mcWidget_registration_firstName').val(user.person.firstName);this.html.find('#mcWidget_registration_middleName').val(user.person.middleName);this.html.find('#mcWidget_registration_surname').val(user.person.lastName);this.html.find('#mcWidget_registration_suffix').val(user.person.suffix);this.html.find('#mcWidget_registration_companyName').val(user.company.name);this.html.find('#mcWidget_registration_companyRegistrationNumber').val(user.company.IC);this.html.find('#mcWidget_registration_vatRegistrationNumber').val(user.company.DIC);var phone=mcw.countryManager.splitPhone(user.phone);this.html.find('#mcWidget_registration_phonePrefix').val(phone.callingCode);this.html.find('#mcWidget_registration_phone').val(phone.localNumber);this.html.find('#mcWidget_registration_email').val(user.email);this.fillAddresses();if(user.emailVerified){this.html.find('#mcWidget_registration_verifyEmail').remove();}
if(user.phoneVerified){this.html.find('#mcWidget_registration_verifyMsisdn').remove();}};mcw.EditForm.prototype.getUserData=function(){mcw.logger.logWarning('The method "mcw.EditForm.prototype.getUserData" is not overriden');return{};};mcw.EditForm.prototype.fillAddresses=function(){var self=this;var user=this.getUserData();if(!user.address){return;}
$.each(user.address,function(index,address){var fieldName;switch(address.addressType){case'delivery':fieldName='deliveryAddress_';break;case'invoicing':fieldName='invoicingAddress_';break;default:fieldName='';break;}
self.html.find('#mcWidget_registration_'+fieldName+'street').val(address.street);self.html.find('#mcWidget_registration_'+fieldName+'streetNumber').val(address.number);self.html.find('#mcWidget_registration_'+fieldName+'city').val(address.city);self.html.find('#mcWidget_registration_'+fieldName+'postalCode').val(address.zipCode);self.html.find('#mcWidget_registration_'+fieldName+'country').val(address.countryIsoCode);});};mcw.EditForm.prototype.adjustDom=function(){var user=this.getUserData();if(user.marketingAgreement){$('#mcWidget_registration_marketingAgreement').attr('checked','checked');}
if(this.isFilledCompany()){$('#mcWidget_registration_specifyCompany').click();}
if(this.isDifferentAddress('delivery')){$('#mcWidget_registration_specifyDeliveryAddress').click();}
if(this.isDifferentAddress('invoicing')){$('#mcWidget_registration_specifyInvoicingAddress').click();}};mcw.EditForm.prototype.isFilledCompany=function(){return $('#mcWidget_registration_companyName').val()||$('#mcWidget_registration_companyRegistrationNumber').val()||$('#mcWidget_registration_vatRegistrationNumber').val();};mcw.EditForm.prototype.isDifferentAddress=function(addressType){return $('#mcWidget_registration_'+addressType+'Address_street').val()!=$('#mcWidget_registration_street').val()||$('#mcWidget_registration_'+addressType+'Address_streetNumber').val()!=$('#mcWidget_registration_streetNumber').val()||$('#mcWidget_registration_'+addressType+'Address_city').val()!=$('#mcWidget_registration_city').val()||$('#mcWidget_registration_'+addressType+'Address_postalCode').val()!=$('#mcWidget_registration_postalCode').val()||$('#mcWidget_registration_'+addressType+'Address_country').val()!=$('#mcWidget_registration_country').val();};mcw.EditForm.prototype.adjustParameters=function(parameters){parameters.currentPassword=$('#mcWidget_registration_currentPassword').val();parameters.newPassword=$('#mcWidget_registration_newPassword1').val();return parameters;};mcw.EditForm.prototype.verifyMsisdn=function(){if(!$('#mcWidget_registration form').valid()){return;}
var self=this;var msisdn=$('#mcWidget_registration_phonePrefix').val()+$('#mcWidget_registration_phone').val();var msisdnVerificationForm=new mcw.MsisdnVerificationForm({msisdn:msisdn});msisdnVerificationForm.isVerified=function(callback){mcw.server.callFunction('isPhoneVerified',{},function(response){callback(response.result);});};msisdnVerificationForm.displaySuccessResult=function(){mcw.messageForm.reset();mcw.dataCache.updateAllUserData(function(){mcw.messageForm.addSuccessCode('msisdnVerification.success');mcw.messageForm.display();self.display();});};if(msisdn!=mcw.dataCache.user.phone){this.save(function(){msisdnVerificationForm.display();});}else{msisdnVerificationForm.display();}};mcw.EditForm.prototype.verifyEmail=function(){if(!$('#mcWidget_registration form').valid()){return;}
var email=$('#mcWidget_registration_email').val();var emailVerificationAction=new mcw.EmailVerificationAction({email:email});if(email!=mcw.dataCache.user.email){this.save(function(){emailVerificationAction.perform();});}else{emailVerificationAction.perform();}};
mcw.UserEditForm=function(){};mcw.UserEditForm.prototype=new mcw.EditForm();mcw.UserEditForm.prototype.constructor=mcw.UserEditForm;mcw.UserEditForm.prototype.getUserData=function(){return mcw.dataCache.user;};mcw.UserEditForm.prototype.save=function(callback){var self=this;var parameters=this.buildParameters();mcw.server.callFunction('updateRegistration',parameters,function(response){mcw.dataCache.updateAllUserData(function(){if(callback){callback();return;}
mcw.messageForm.reset();mcw.messageForm.addSuccessCode('myAccount.save.success');try{var updatedServices=[];$.each(response.propagatedToServices.serviceName,function(index,serviceCode){updatedServices.push(mcw.i18n.localizeCode('serviceName.'+serviceCode));});mcw.messageForm.addNotificationCode('myAccount.save.updatedServices',{services:updatedServices.join(', ')});}catch(error){}
mcw.messageForm.display();self.display();});});};
mcw.TopupForm=function(){};mcw.TopupForm.prototype=new mcw.Form({htmlTemplateId:'topup',menuItem:'topup'});mcw.TopupForm.prototype.constructor=mcw.TopupForm;mcw.TopupForm.prototype.adjustHtml=function(){this.html.find('#mcWidget_topup_bankTransfer').click(function(){new mcw.BankTransferInstructionsForm().display();});this.html.find('#mcWidget_creditCard').click(function(){new mcw.CreditCardInstructionsForm().display();});this.html.find('#mcWidget_sms').click(function(){new mcw.SmsInstructionsForm().display();});};mcw.TopupForm.prototype.adjustDom=function(){$('#mcWidget_topup_bankTransfer').click();};
mcw.BankTransferInstructionsForm=function(){};mcw.BankTransferInstructionsForm.prototype=new mcw.Form({htmlTemplateId:'bankTransferInstructions'});mcw.BankTransferInstructionsForm.prototype.constructor=mcw.BankTransferInstructionsForm;mcw.BankTransferInstructionsForm.prototype.getDisplayElement=function(){return $('#mcWidget_topup_instructions');};mcw.BankTransferInstructionsForm.prototype.adjustHtml=function(){var self=this;var topupInfo=mcw.dataCache.user.bankAccountTopupInfo;mcw.fillElementVariables(this.html,{bankAccountNumber:topupInfo.accountNumber,variableSymbol:topupInfo.vs,specificSymbol:topupInfo.ss});$('#mcWidget_topup_amount').change(function(){self.html.find('#mcWidget_topup_bankTransferAmount').html($('#mcWidget_topup_amount option:selected').html());});};mcw.BankTransferInstructionsForm.prototype.adjustDom=function(){$('#mcWidget_topup_amountRow').show();$('#mcWidget_topup_amount').change();};
mcw.CreditCardInstructionsForm=function(){};mcw.CreditCardInstructionsForm.prototype=new mcw.Form({htmlTemplateId:'creditCardInstructions'});mcw.CreditCardInstructionsForm.prototype.constructor=mcw.CreditCardInstructionsForm;mcw.CreditCardInstructionsForm.prototype.getDisplayElement=function(){return $('#mcWidget_topup_instructions');};mcw.CreditCardInstructionsForm.prototype.adjustHtml=function(){this.html.find('#mcWidget_creditCardInstructions_acceptedPaymentCards img').attr('src',mcw.configuration.mcwUrl+'/images/acceptedPaymentCards.gif');};mcw.CreditCardInstructionsForm.prototype.adjustDom=function(){var self=this;$('#mcWidget_topup_amountRow').show();$('#mcWidget_topup form').validate({submitHandler:function(){self.topup();}});};mcw.CreditCardInstructionsForm.prototype.topup=function(){mcw.server.callFunction('getPaymuzoTopupUrl',{amount:$('#mcWidget_topup_amount').val(),currency:'CZK'},function(response){window.open(response.url,'payMuzo');});};
mcw.SmsInstructionsForm=function(){};mcw.SmsInstructionsForm.prototype=new mcw.Form({htmlTemplateId:'smsInstructions'});mcw.SmsInstructionsForm.prototype.constructor=mcw.SmsInstructionsForm;mcw.SmsInstructionsForm.prototype.getDisplayElement=function(){return $('#mcWidget_topup_instructions');};mcw.SmsInstructionsForm.prototype.adjustHtml=function(){var topupInfo=mcw.dataCache.user.smsTopupInfo;var serviceInfo;try{serviceInfo=topupInfo.serviceInfo[0];}catch(error){this.html.find('.instruction').remove();return;}
this.html.find('.serviceUnavailable').remove();mcw.fillElementVariables(this.html,{smsText:'<strong class="smsText">'+serviceInfo.smsKeyword+' '+topupInfo.gpcsId+'</strong>',smsTextWithoutAccountNumber:'<strong class="smsText">'+serviceInfo.smsKeyword+'</strong>',smsTargetPhone:'<strong>'+serviceInfo.smsNumber+'</strong>'});};mcw.SmsInstructionsForm.prototype.adjustDom=function(){$('#mcWidget_topup_amountRow').hide();};
mcw.MsisdnVerificationForm=function(parameters){this.msisdn=parameters.msisdn;this.timer=null;this.bNumber=null;this.totalTimeout=0;};mcw.MsisdnVerificationForm.prototype=new mcw.Form({htmlTemplateId:'msisdnVerification'});mcw.MsisdnVerificationForm.prototype.constructor=mcw.MsisdnVerificationForm;mcw.MsisdnVerificationForm.prototype.loadData=function(callback){var self=this;mcw.server.callFunction('requestVerification',{type:'msisdn',value:this.msisdn,url:mcw.getPageUrl()},function(response){$.each(response.parameters,function(index,parameter){switch(parameter.name){case'bNumber':self.bNumber=parameter.value;break;case'timeout':self.totalTimeout=parameter.value;break;}});callback();});};mcw.MsisdnVerificationForm.prototype.adjustHtml=function(){var self=this;mcw.fillElementVariables(this.html,{aNumber:'<strong>'+this.msisdn+'</strong>',bNumber:'<strong>'+this.bNumber+'</strong>',timeout:'<span class="timeout">'+this.totalTimeout+'</span>',totalTimeout:'<strong>'+this.totalTimeout+'</strong>'});this.html.find('#mcWidget_msisdnVerification_progressBar').progressbar({value:100});this.html.find('#mcWidget_msisdnVerification_tryAgain').click(function(){mcw.messageForm.clear();self.display();});this.html.find('#mcWidget_msisdnVerification_verificationRequest').hide();this.timer=new mcw.Timer({id:'msisdnVerification',interval:5,time:this.totalTimeout});this.timer.checkStop=function(){return $('#mcWidget_msisdnVerification').length==0;};this.timer.callback=function(){self.verify();};};mcw.MsisdnVerificationForm.prototype.adjustDom=function(){this.timer.start();};mcw.MsisdnVerificationForm.prototype.verify=function(){$('#mcWidget_msisdnVerification_progressBar').progressbar('value',this.getPercentageTimeout());$('#mcWidget_msisdnVerification .timeout').html(this.timer.remainingTime);if(this.timer.remainingTime<=0){this.displayTimeoutElapsedResult();return;}
var self=this;this.isVerified(function(verified){if(verified){self.timer.stop();self.displaySuccessResult();}});};mcw.MsisdnVerificationForm.prototype.getPercentageTimeout=function(){return this.timer.remainingTime/(this.totalTimeout/100);};mcw.MsisdnVerificationForm.prototype.isVerified=function(callback){mcw.logger.logError('The method mcw.MsisdnVerificationForm.prototype.isVerified is not overriden');callback(false);};mcw.MsisdnVerificationForm.prototype.displaySuccessResult=function(){mcw.logger.logError('The method mcw.MsisdnVerificationForm.prototype.displaySuccessResult is not overriden');};mcw.MsisdnVerificationForm.prototype.displayTimeoutElapsedResult=function(){mcw.messageForm.reset();mcw.messageForm.addErrorCode('msisdnVerification.error.timeout');mcw.messageForm.display();$('#mcWidget_msisdnVerification_verificationRequest').show();};
mcw.AnonymousMsisdnVerificationForm=function(parameters){this.msisdn=parameters.msisdn;};mcw.AnonymousMsisdnVerificationForm.prototype=new mcw.MsisdnVerificationForm({});mcw.AnonymousMsisdnVerificationForm.prototype.constructor=mcw.AnonymousMsisdnVerificationForm;mcw.AnonymousMsisdnVerificationForm.prototype.loadData=function(callback){var self=this;mcw.server.callFunction('requestAnonymousMsisdnVerification',{msisdn:this.msisdn},function(response){$.each(response.parameters,function(index,parameter){switch(parameter.name){case'bNumber':self.bNumber=parameter.value;break;case'timeout':self.totalTimeout=parameter.value;break;}});callback();});};mcw.AnonymousMsisdnVerificationForm.prototype.isVerified=function(callback){mcw.server.callFunction('isMsisdnVerified',{msisdn:this.msisdn,seconds:60},function(response){callback(response.result);});};
mcw.ServicesForm=function(){};mcw.ServicesForm.prototype=new mcw.Form({htmlTemplateId:'services',menuItem:'services'});mcw.ServicesForm.prototype.constructor=mcw.ServicesForm;mcw.ServicesForm.prototype.adjustHtml=function(){var self=this;var prototypeTr=this.html.find('tbody tr');$.each(mcw.dataCache.user.services,function(index,service){var serviceTr=prototypeTr.clone();mcw.fillElementVariables(serviceTr,{serviceCode:service.name,serviceName:mcw.i18n.localizeCode('serviceName.'+service.name),serviceStatus:service.active?mcw.i18n.localizeCode('services.serviceStatus.active'):mcw.i18n.localizeCode('services.serviceStatus.inactive')});if(service.active){new mcw.IconSetIcon(serviceTr.find('td.serviceStatus'),'activeService','activeService').display();new mcw.IconSetButton(serviceTr.find('td.serviceActivation'),'activateServiceDisabled',false).display();new mcw.IconSetButton(serviceTr.find('td.serviceDeactivation'),'deactivateServiceEnabled',true).display();new mcw.IconSetButton(serviceTr.find('td.serviceConfiguration'),'configureServiceEnabled',true).display();}else{new mcw.IconSetIcon(serviceTr.find('td.serviceStatus'),'inactiveService','inactiveService').display();new mcw.IconSetButton(serviceTr.find('td.serviceActivation'),'activateServiceEnabled',true).display();new mcw.IconSetButton(serviceTr.find('td.serviceDeactivation'),'deactivateServiceDisabled',false).display();new mcw.IconSetButton(serviceTr.find('td.serviceConfiguration'),'configureServiceDisabled',false).display();}
serviceTr.insertBefore(prototypeTr);serviceTr.find('.serviceActivation input').click(function(){self.activateService(service.name);});serviceTr.find('.serviceDeactivation input').click(function(){self.deactivateService(service.name);});serviceTr.find('.serviceConfiguration input').click(function(){self.configureService(service.name);});});prototypeTr.remove();};mcw.ServicesForm.prototype.activateService=function(serviceCode){var self=this;mcw.server.callFunction('serviceSettings',{serviceName:serviceCode,active:true},function(response){mcw.dataCache.updateAllUserData(function(){mcw.messageForm.reset();mcw.messageForm.addSuccessCode('services.serviceActivation.success');mcw.messageForm.display();mcw.menuForm.display();self.display();});},function(response){self.displayRequiredData(serviceCode,response.errors);});};mcw.ServicesForm.prototype.displayRequiredData=function(serviceCode,errors){var dataToVerify=[];if($.inArray('error.emailVerificationRequired',errors)!=-1){dataToVerify.push('email');}
if($.inArray('error.phoneVerificationRequired',errors)!=-1){dataToVerify.push('msisdn');}
if(dataToVerify.length==0){mcw.server.displayErrors(errors);return;}
var form=new mcw.DataVerificationForm({serviceCode:serviceCode,dataToVerify:dataToVerify});form.display();};mcw.ServicesForm.prototype.deactivateService=function(serviceCode){var self=this;mcw.server.callFunction('serviceSettings',{serviceName:serviceCode,active:false},function(response){mcw.dataCache.updateAllUserData(function(){mcw.messageForm.reset();mcw.messageForm.addSuccessCode('services.serviceDeactivation.success');mcw.messageForm.display();mcw.menuForm.display();self.display();});});};mcw.ServicesForm.prototype.configureService=function(serviceCode){var form;switch(serviceCode){case'MMP':form=new mcw.MmpConfigurationForm();break;case'AWEG':form=new mcw.AwegConfigurationForm();break;default:mcw.logger.logError('The service "'+serviceCode+'" has no configuration form');return;break;}
form.display();};
mcw.DataVerificationForm=function(parameters){this.serviceCode=parameters.serviceCode;this.dataToVerify=parameters.dataToVerify;};mcw.DataVerificationForm.prototype=new mcw.Form({htmlTemplateId:'dataVerification'});mcw.DataVerificationForm.prototype.constructor=mcw.DataVerificationForm;mcw.DataVerificationForm.prototype.getDisplayElement=function(){return $('#mcWidget_services_dataVerification');};mcw.DataVerificationForm.prototype.adjustHtml=function(){mcw.fillElementVariables(this.html,{service:mcw.i18n.localizeCode('serviceName.'+this.serviceCode)});var liPrototype=this.html.find('li');$.each(this.dataToVerify,function(index,data){var li=liPrototype.clone();mcw.fillElementVariables(li,{data:mcw.i18n.localizeCode('dataVerification.data.'+data)});li.insertBefore(liPrototype);});liPrototype.remove();this.html.find('#mcWidget_dataVerification_verify').click(function(){new mcw.UserEditForm().display();});};
mcw.ForgottenLoginForm=function(){};mcw.ForgottenLoginForm.prototype=new mcw.Form({htmlTemplateId:'forgottenLogin'});mcw.ForgottenLoginForm.prototype.constructor=mcw.ForgottenLoginForm;mcw.ForgottenLoginForm.prototype.adjustHtml=function(){var self=this;this.html.find('#mcWidget_forgottenLogin_emailForm').validate({submitHandler:function(){self.resetPasswordByEmail();},messages:{mcWidget_forgottenLogin_loginNumber:{required:mcw.i18n.localizeCode('form.field.required')}}});};mcw.ForgottenLoginForm.prototype.resetPasswordByEmail=function(){mcw.server.callFunction('resetPassword',{login:$('#mcWidget_forgottenLogin_loginNumber').val(),url:mcw.getPageUrl()},function(response){mcw.messageForm.reset();mcw.messageForm.addSuccessCode('forgottenLogin.email.sent');mcw.messageForm.display();});};
mcw.PasswordResetConfirmationForm=function(parameters){this.key=parameters.key;this.loginNumber=null;};mcw.PasswordResetConfirmationForm.prototype=new mcw.Form({htmlTemplateId:'passwordResetConfirmation'});mcw.PasswordResetConfirmationForm.prototype.constructor=mcw.PasswordResetConfirmationForm;mcw.PasswordResetConfirmationForm.prototype.loadData=function(callback){var self=this;mcw.server.callFunction('validateVerification',{action:'resetPassword',code:this.key},function(response){self.loginNumber=response.login;callback();},function(response){callback();});};mcw.PasswordResetConfirmationForm.prototype.adjustHtml=function(){var self=this;if(this.loginNumber){this.html.find('.failure').remove();}else{this.html.find('.success').remove();}
this.html.find('form').validate({submitHandler:function(){self.resetPassword();},rules:{mcWidget_passwordResetConfirmation_newPassword1:{rangelength:[6,13]},mcWidget_passwordResetConfirmation_newPassword2:{equalTo:'#mcWidget_passwordResetConfirmation_newPassword1'}},messages:{mcWidget_passwordResetConfirmation_newPassword1:{required:mcw.i18n.localizeCode('form.field.required'),rangelength:mcw.i18n.localizeCode('registration.password.length')},mcWidget_passwordResetConfirmation_newPassword2:{required:mcw.i18n.localizeCode('form.field.required'),equalTo:mcw.i18n.localizeCode('passwordResetConfirmation.newPasswords.equal')}}});this.html.find('#mcWidget_passwordResetConfirmation_newPassword1').blur(function(){$('#mcWidget_passwordResetConfirmation_newPassword2').valid();});};mcw.PasswordResetConfirmationForm.prototype.resetPassword=function(){mcw.server.callFunction('changePassword',{login:this.loginNumber,newPassword:$('#mcWidget_passwordResetConfirmation_newPassword1').val()},function(response){$('#mcWidget_passwordResetConfirmation form').remove();mcw.messageForm.reset();mcw.messageForm.addSuccessCode('passwordResetConfirmation.reset.success');mcw.messageForm.display();});};
mcw.AwegConfigurationForm=function(){};mcw.AwegConfigurationForm.prototype=new mcw.Form({htmlTemplateId:'awegConfiguration'});mcw.AwegConfigurationForm.prototype.constructor=mcw.AwegConfigurationForm;mcw.AwegConfigurationForm.prototype.adjustHtml=function(){var self=this;var parameters=mcw.dataCache.user.services.AWEG.parameters;mcw.countryManager.fillCallingCodes(this.html.find('#mcWidget_awegConfiguration_redirectingPhonePrefix'));mcw.fillElementVariables(this.html,{maximumDailyLimit:parameters.maximumLimit.value,todaySentSms:parameters.used.value});this.html.find('#mcWidget_awegConfiguration_messageValidity').val(parameters.smATExpiry.value);this.html.find('#mcWidget_awegConfiguration_dailyLimit').val(parameters.limit2.value);this.html.find('#mcWidget_awegConfiguration_redirectingEmail').val(parameters.smForwardTargetEmail.value);if(parameters.smForwardTargetNo.value){var phone=mcw.countryManager.splitPhone(parameters.smForwardTargetNo.value);this.html.find('#mcWidget_awegConfiguration_redirectingPhonePrefix').val(phone.callingCode);this.html.find('#mcWidget_awegConfiguration_redirectingPhone').val(phone.localNumber);}
this.html.find('form').validate({submitHandler:function(){self.save();},errorPlacement:function(error,element){element.parent().append(error);}});var formConstraintBuilder=new mcw.FormConstraintBuilder(parameters,{smForwardTargetEmail:this.html.find('#mcWidget_awegConfiguration_redirectingEmail'),smForwardTargetNo:this.html.find('#mcWidget_awegConfiguration_redirectingPhone'),limit2:this.html.find('#mcWidget_awegConfiguration_dailyLimit')});formConstraintBuilder.build();this.html.find('#mcWidget_awegConfiguration_pcMessageDelivery').click(function(){$('.pcMessageDelivery').show('fast');});this.html.find('#mcWidget_awegConfiguration_mobilePhoneMessageDelivery').click(function(){$('.pcMessageDelivery').hide('fast');});this.html.find('#mcWidget_awegConfiguration_noMessageRedirecting').click(function(){$('.redirectingTarget').hide('fast');$('.redirectingTarget input').attr('disabled','disabled');});this.html.find('#mcWidget_awegConfiguration_conditionalMessageRedirecting, #mcWidget_awegConfiguration_permanentMessageRedirecting').click(function(){$('.redirectingTarget input').removeAttr('disabled');$('.redirectingTarget').show('fast');});};mcw.AwegConfigurationForm.prototype.save=function(){var self=this;mcw.server.callFunction('serviceSettings',{serviceName:'AWEG',active:true,parameterValue:[{name:'smReceiveAT',value:$('input[name="messageDelivery"]:checked').val()},{name:'smATExpiry',value:$('#mcWidget_awegConfiguration_messageValidity').val()},{name:'smForwardType',value:$('input[name="messageRedirecting"]:checked').val()},{name:'smForwardTargetEmail',value:$('#mcWidget_awegConfiguration_redirectingEmail').val()},{name:'smForwardTargetNo',value:$('#mcWidget_awegConfiguration_redirectingPhonePrefix').val()+$('#mcWidget_awegConfiguration_redirectingPhone').val()},{name:'limit2',value:$('#mcWidget_awegConfiguration_dailyLimit').val()}]},function(response){mcw.dataCache.updateAllUserData(function(){mcw.messageForm.reset();mcw.messageForm.addSuccessCode('awegConfiguration.save.success');mcw.messageForm.display();self.display();});});};mcw.AwegConfigurationForm.prototype.adjustDom=function(){var parameters=mcw.dataCache.user.services.AWEG.parameters;if(parameters.smReceiveAT.value=='1'){$('#mcWidget_awegConfiguration_pcMessageDelivery').click();}else{$('#mcWidget_awegConfiguration_mobilePhoneMessageDelivery').click();}
switch(parameters.smForwardType.value){case'MFO':$('#mcWidget_awegConfiguration_conditionalMessageRedirecting').click();break;case'MFU':$('#mcWidget_awegConfiguration_permanentMessageRedirecting').click();break;default:$('#mcWidget_awegConfiguration_noMessageRedirecting').click();break;}};
mcw.AwegSendSmsForm=function(){this.charsPerSms=160;this.charsPerSplittedSms=156;this.maxUsedChars=780;};mcw.AwegSendSmsForm.prototype=new mcw.Form({htmlTemplateId:'awegSendSms',menuItem:'aweg'});mcw.AwegSendSmsForm.prototype.constructor=mcw.AwegSendSmsForm;mcw.AwegSendSmsForm.prototype.adjustHtml=function(){var self=this;this.html.find('form').validate({submitHandler:function(){self.sendSms();},rules:{mcWidget_awegSendSms_phone:{regularExpression:/^(\+)?\d+(,(\+)?\d+)*$/}},messages:{mcWidget_awegSendSms_phone:{required:mcw.i18n.localizeCode('form.field.required')}}});this.html.find('#mcWidget_awegSendSms_message').bind('keydown keyup',function(){self.trimMessage();var usedChars=$(this).val().length;var smsCount=(usedChars<=self.charsPerSms)?1:Math.ceil(usedChars/self.charsPerSplittedSms);$('#mcWidget_awegSendSms_usedChars').html(usedChars);$('#mcWidget_awegSendSms_charsLeft').html(self.maxUsedChars-usedChars);$('#mcWidget_awegSendSms_smsCount').html(smsCount);});};mcw.AwegSendSmsForm.prototype.trimMessage=function(){if(this.maxUsedChars<$('#mcWidget_awegSendSms_message').val().length){$('#mcWidget_awegSendSms_message').val($('#mcWidget_awegSendSms_message').val().substr(0,this.maxUsedChars));alert(mcw.i18n.localizeCode('form.field.trimMessage'));}};mcw.AwegSendSmsForm.prototype.sendSms=function(){var self=this;mcw.server.callFunction('awegSendSms',{recipients:$('#mcWidget_awegSendSms_phone').val(),text:$('#mcWidget_awegSendSms_message').val(),deliveryReport:$('#mcWidget_awegSendSms_withAdvice').is(':checked'),anumber:$('#mcWidget_awegSendSms_withSenderNumber').is(':checked')},function(response){var success=true;var recipients=$('#mcWidget_awegSendSms_phone').val().split(/,/);mcw.messageForm.reset();$.each(response.sendStatus,function(index,status){if(status.result>=200&&status.result<=209){mcw.messageForm.addSuccessCode('awegSendSms.success.'+status.result,{msisdn:recipients[index]});}else{success=false;mcw.messageForm.addErrorCode('awegSendSms.error.'+status.result,{msisdn:recipients[index]});}});mcw.messageForm.display();if(success){self.display();}});};
mcw.MmpConfigurationForm=function(){};mcw.MmpConfigurationForm.prototype=new mcw.Form({htmlTemplateId:'mmpConfiguration'});mcw.MmpConfigurationForm.prototype.constructor=mcw.MmpConfigurationForm;mcw.MmpConfigurationForm.prototype.adjustHtml=function(){var self=this;var trPrototype=this.html.find('tbody tr');$.each(mcw.dataCache.user.services.MMP.msisdns,function(msisdn,msisdnAccount){var tr=trPrototype.clone();mcw.fillElementVariables(tr,{msisdn:msisdn,status:msisdnAccount.blocked?mcw.i18n.localizeCode('mmpConfiguration.status.disabled'):mcw.i18n.localizeCode('mmpConfiguration.status.enabled')});if(msisdnAccount.primary){new mcw.IconSetButton(tr.find('td.deleteMsisdn'),'mmpRemoveMsisdnDisabled',false).display();}else{new mcw.IconSetButton(tr.find('td.deleteMsisdn'),'mmpRemoveMsisdnEnabled',true).display();}
if(msisdnAccount.blocked){new mcw.IconSetButton(tr.find('td.verifyMsisdn'),'mmpVerifyMsisdnEnabled',true).display();new mcw.IconSetButton(tr.find('td.blockMsisdn'),'mmpBlockMsisdnDisabled',false).display();}else{new mcw.IconSetButton(tr.find('td.verifyMsisdn'),'mmpVerifyMsisdnDisabled',false).display();new mcw.IconSetButton(tr.find('td.blockMsisdn'),'mmpBlockMsisdnEnabled',true).display();}
new mcw.IconSetButton(tr.find('td.configureMsisdn'),'mmpConfigureMsisdnEnabled',true).display();tr.find('.deleteMsisdn input').click(function(){self.deleteMsisdn(msisdn);});tr.find('.verifyMsisdn input').click(function(){self.verifyMsisdn(msisdn);});tr.find('.blockMsisdn input').click(function(){self.blockMsisdn(msisdn);});tr.find('.configureMsisdn input').click(function(){self.configureMsisdn(msisdn);});tr.insertBefore(trPrototype);});trPrototype.remove();mcw.countryManager.fillCallingCodes(this.html.find('#mcWidget_mmpConfiguration_newPhonePrefix'));this.html.find('#mcWidget_mmpConfiguration_addMsisdn').click(function(){new mcw.MmpNewMsisdnForm().display();});this.html.find('#mcWidget_mmpConfiguration_configureService').click(function(){new mcw.MmpGlobalParametersForm().display();});};mcw.MmpConfigurationForm.prototype.deleteMsisdn=function(msisdnCode){var self=this;mcw.server.callFunction('mmpDeleteMsisdn',{msisdn:msisdnCode},function(response){mcw.dataCache.updateAllUserData(function(){mcw.messageForm.reset();mcw.messageForm.addSuccessCode('mmpConfiguration.deleteMsisdn.success');mcw.messageForm.display();self.display();});});};mcw.MmpConfigurationForm.prototype.verifyMsisdn=function(msisdnCode){var self=this;var form=new mcw.MsisdnVerificationForm({msisdn:msisdnCode});form.isVerified=function(callback){mcw.server.callFunction('mmpIsMsisdnVerified',{msisdn:msisdnCode},function(response){callback(response.result);});};form.displaySuccessResult=function(){mcw.messageForm.reset();mcw.dataCache.updateAllUserData(function(){mcw.messageForm.addSuccessCode('msisdnVerification.success');mcw.messageForm.display();self.display();});};form.display();};mcw.MmpConfigurationForm.prototype.blockMsisdn=function(msisdnCode){var self=this;mcw.server.callFunction('mmpBlockMsisdn',{msisdn:msisdnCode},function(response){mcw.dataCache.updateAllUserData(function(){mcw.messageForm.reset();mcw.messageForm.addSuccessCode('mmpConfiguration.blockMsisdn.success');mcw.messageForm.display();self.display();});});};mcw.MmpConfigurationForm.prototype.configureMsisdn=function(msisdnCode){var form=new mcw.MmpMsisdnParametersForm({msisdn:msisdnCode});form.display();};
mcw.MmpNewMsisdnForm=function(){};mcw.MmpNewMsisdnForm.prototype=new mcw.Form({htmlTemplateId:'mmpMsisdnParameters'});mcw.MmpNewMsisdnForm.prototype.constructor=mcw.MmpNewMsisdnForm;mcw.MmpNewMsisdnForm.prototype.getDisplayElement=function(){return $('#mcWidget_mmpConfiguration_parameters');};mcw.MmpNewMsisdnForm.prototype.adjustHtml=function(){var self=this;this.html.find('.globalParameters, .msisdnParameters').not('.newMsisdn').remove();this.serviceParameters=new mcw.ServiceParameters(mcw.dataCache.user.services.MMP.msisdnParameters,this.html.find('#mcWidget_mmpMsisdnParameters_parameters'),'mmpMsisdnParameters');this.serviceParameters.display();this.html.find('form').validate({submitHandler:function(){self.addMsisdn();}});this.serviceParameters.applyConstraints();};mcw.MmpNewMsisdnForm.prototype.addMsisdn=function(){var parameters=this.serviceParameters.getValues();mcw.server.callFunction('mmpAddMsisdn',{attribute:parameters},function(response){mcw.dataCache.updateAllUserData(function(){mcw.messageForm.reset();mcw.messageForm.addSuccessCode('mmpNewMsisdn.addMsisdn.success');mcw.messageForm.display();new mcw.MmpConfigurationForm().display();});});};
mcw.MmpGlobalParametersForm=function(){};mcw.MmpGlobalParametersForm.prototype=new mcw.Form({htmlTemplateId:'mmpMsisdnParameters'});mcw.MmpGlobalParametersForm.prototype.constructor=mcw.MmpGlobalParametersForm;mcw.MmpGlobalParametersForm.prototype.getDisplayElement=function(){return $('#mcWidget_mmpConfiguration_parameters');};mcw.MmpGlobalParametersForm.prototype.adjustHtml=function(){var self=this;this.html.find('.msisdnParameters, .newMsisdn').not('.globalParameters').remove();this.serviceParameters=new mcw.ServiceParameters(mcw.dataCache.user.services.MMP.parameters,this.html.find('#mcWidget_mmpMsisdnParameters_parameters'),'mmpMsisdnParameters');this.serviceParameters.display();this.html.find('form').validate({submitHandler:function(){self.save();}});this.serviceParameters.applyConstraints();};mcw.MmpGlobalParametersForm.prototype.save=function(){var parameters=this.serviceParameters.getValues();mcw.server.callFunction('serviceSettings',{serviceName:'MMP',active:true,parameterValue:parameters},function(response){mcw.dataCache.updateAllUserData(function(){mcw.messageForm.reset();mcw.messageForm.addSuccessCode('mmpGlobalParameters.save.success');mcw.messageForm.display();});});};
mcw.MmpMsisdnParametersForm=function(parameters){this.msisdn=parameters.msisdn;};mcw.MmpMsisdnParametersForm.prototype=new mcw.Form({htmlTemplateId:'mmpMsisdnParameters'});mcw.MmpMsisdnParametersForm.prototype.constructor=mcw.MmpMsisdnParametersForm;mcw.MmpMsisdnParametersForm.prototype.getDisplayElement=function(){return $('#mcWidget_mmpConfiguration_parameters');};mcw.MmpMsisdnParametersForm.prototype.adjustHtml=function(){var self=this;this.html.find('.globalParameters, .newMsisdn').not('.msisdnParameters').remove();mcw.fillElementVariables(this.html,{msisdn:this.msisdn});var parameters=mcw.dataCache.user.services.MMP.msisdns[this.msisdn].parameters;delete parameters.msisdn;this.serviceParameters=new mcw.ServiceParameters(parameters,this.html.find('#mcWidget_mmpMsisdnParameters_parameters'),'mmpMsisdnParameters');this.serviceParameters.display();this.html.find('form').validate({submitHandler:function(){self.save();}});this.serviceParameters.applyConstraints();};mcw.MmpMsisdnParametersForm.prototype.save=function(){var parameters=this.serviceParameters.getValues();mcw.server.callFunction('mmpSetMsisdnAttributes',{msisdn:this.msisdn,attributes:parameters},function(response){mcw.dataCache.updateAllUserData(function(){mcw.messageForm.reset();mcw.messageForm.addSuccessCode('mmpMsisdnParameters.save.success');mcw.messageForm.display();});});};
mcw.EventLogForm=function(){this.data=null;this.dateRange=new mcw.FormDateRange({from:mcw.calendar.getMonthFirstDay(),to:mcw.calendar.getMonthLastDay()});this.paging=new mcw.FormPaging();};mcw.EventLogForm.prototype=new mcw.Form({htmlTemplateId:'eventLog',menuItem:'eventLog'});mcw.EventLogForm.prototype.constructor=mcw.EventLogForm;mcw.EventLogForm.prototype.loadData=function(callback){var self=this;mcw.server.callFunction('getAllUserEvents',{from:this.dateRange.getServerFrom(),to:this.dateRange.getServerTo(),pageNumber:this.paging.pageNumber,pageSize:this.paging.pageSize},function(response){self.data=response;callback();});};mcw.EventLogForm.prototype.adjustHtml=function(){var self=this;this.paging.setElementCount(this.data.total);this.paging.adjustHtml(this.html);this.paging.changePage=function(){self.display();};this.dateRange.adjustHtml(this.html.find('#mcWidget_eventLog_from'),this.html.find('#mcWidget_eventLog_to'));var trPrototype=this.html.find('tbody tr');var oddRow=true;$.each(this.data.rows,function(index,row){var tr=trPrototype.clone();mcw.fillElementVariables(tr,{service:mcw.i18n.localizeCode('eventLog.service.'+row.service),operation:mcw.i18n.localizeCode('eventLog.operation.'+row.operation),date:mcw.i18n.formatDate(new Date(row.whenCreated),mcw.i18n.dateFormats.dateTime),description:self.formatDescription(row)});if(oddRow){tr.addClass('odd');}
tr.insertBefore(trPrototype);oddRow=!oddRow;});trPrototype.remove();this.html.find('#mcWidget_eventLog_display').click(function(){self.display();});};mcw.EventLogForm.prototype.formatDescription=function(row){var description=row.description;if(!description.action){return'';}
var action=description.action;delete description.action;var variables;switch(action){case'setAttributes':variables={};break;default:variables=description;break;}
variables.service=mcw.i18n.localizeCode('serviceName.'+row.service);if(variables.amount&&variables.currency){variables.amountAndCurrency=mcw.i18n.formatCurrency(variables.amount,variables.currency);}
var formattedDescription=mcw.i18n.localizeCode('eventLog.description.'+row.operation+'.'+action,variables);if(row.mposLoginNumber){formattedDescription+=' ('+mcw.i18n.localizeCode('eventLog.description.changeMadeByAdministrator')+')';}
return formattedDescription;};
mcw.DandoAssociatedMsisdnListForm=function(){this.dandoElementListForm=null;this.dandoDocumentListForm=null;this.data=null;this.verSerNum=null;};mcw.DandoAssociatedMsisdnListForm.prototype=new mcw.Form({htmlTemplateId:'dandoAssociatedMsisdnList',menuItem:'dando'});mcw.DandoAssociatedMsisdnListForm.prototype.constructor=mcw.DandoAssociatedMsisdnListForm;mcw.DandoAssociatedMsisdnListForm.prototype.loadData=function(callback){var self=this;mcw.server.callFunction('dandoGetAllUserAssociatedMsisdn',{},function(response){self.data=response;self.verSerNum=response.verSerNum;callback();});};mcw.DandoAssociatedMsisdnListForm.prototype.adjustHtml=function(){var self=this;if(mcw.dataCache.msisdn){mcw.fillElementVariables(this.html,{msisdn:mcw.dataCache.msisdn.msisdn});}
var trPrototype=this.html.find('tbody tr');var oddRow=true;$.each(this.data.rows,function(index,row){var tr=trPrototype.clone();mcw.fillElementVariables(tr,{associatedMsisdn:row.username,whenVerified:self.formatWhenValidated(row.whenVerifiedAssociated),bNumber:self.showAppeal(row.whenVerifiedAssociated,self.verSerNum),hideOnVerified:self.getStyle(row.whenVerifiedAssociated)});if(row.parentUserId){tr.find('td.deleteMsisdn a').click(function(){self.deleteMsisdn(row.id);});}else{tr.find("td.deleteMsisdn").empty();}
if(oddRow){tr.addClass('odd');}
tr.insertBefore(trPrototype);oddRow=!oddRow;});trPrototype.remove();this.html.find('.tabLabels .dandoTaxElements').click(function(){self.displayElementList();});this.html.find('.tabLabels .dandoTaxDocuments').click(function(){self.displayDocumentList();});this.html.find('#mcWidget_dandoAssociatedMsisdnList_display').click(function(){self.display();});this.html.find('#mcWidget_dandoAssociatedMsisdnList_addNew').click(function(){var newMsisdn=$('#mcWidget_dandoAssociatedMsisdnList_newMsisdn').val();self.addNewMsisdn(newMsisdn);});};mcw.DandoAssociatedMsisdnListForm.prototype.deleteMsisdn=function(userId){var self=this;mcw.messageForm.clear();mcw.server.callFunction('dandoRemoveAssociatedMsisdn',{removeId:userId},function(response){self.display();});};mcw.DandoAssociatedMsisdnListForm.prototype.addNewMsisdn=function(addMsisdn){var self=this;mcw.messageForm.clear();mcw.server.callFunction('dandoAddAssociatedMsisdn',{addMsisdn:addMsisdn},function(response){self.display();});};mcw.DandoAssociatedMsisdnListForm.prototype.displayElementList=function(){if(!this.dandoElementListForm){this.dandoElementListForm=new mcw.DandoElementListForm();this.dandoElementListForm.dandoAssociatedMsisdnForm=this;}
this.dandoElementListForm.display();};mcw.DandoAssociatedMsisdnListForm.prototype.displayDocumentList=function(){if(!this.dandoDocumentListForm){this.dandoDocumentListForm=new mcw.DandoDocumentListForm();this.dandoDocumentListForm.dandoAssociatedMsisdnForm=this;}
this.dandoDocumentListForm.display();};mcw.DandoAssociatedMsisdnListForm.prototype.formatWhenValidated=function(dateString){if(dateString==null||dateString==0){return" - ";}
return mcw.i18n.formatDate(new Date(dateString),mcw.i18n.dateFormats.date);};mcw.DandoAssociatedMsisdnListForm.prototype.showAppeal=function(dateString,number){if(dateString==null||dateString==0){return(number);}
return"";};mcw.DandoAssociatedMsisdnListForm.prototype.getStyle=function(dateString){if(dateString==null||dateString==0){return"";}
return("hideInfo");};
mcw.DandoElementListForm=function(){this.dandoDocumentListForm=null;this.dandoAssociatedMsisdnForm=null;this.data=null;this.dateRange=new mcw.FormDateRange({from:mcw.calendar.getMonthFirstDay(),to:mcw.calendar.getMonthLastDay()});this.paging=new mcw.FormPaging();};mcw.DandoElementListForm.prototype=new mcw.Form({htmlTemplateId:'dandoElementList',menuItem:'dando'});mcw.DandoElementListForm.prototype.constructor=mcw.DandoElementListForm;mcw.DandoElementListForm.prototype.loadData=function(callback){var self=this;mcw.server.callFunction('dandoGetAllUserTaxElements',{from:this.dateRange.getServerFrom(),to:this.dateRange.getServerTo(),pageNumber:this.paging.pageNumber,pageSize:this.paging.pageSize,locale:mcw.configuration.locale},function(response){self.data=response;callback();});};mcw.DandoElementListForm.prototype.adjustHtml=function(){var self=this;if(mcw.dataCache.msisdn){mcw.fillElementVariables(this.html,{msisdn:mcw.dataCache.msisdn.msisdn});}
this.paging.setElementCount(this.data.total);this.paging.adjustHtml(this.html);this.paging.changePage=function(){self.display();};this.dateRange.adjustHtml(this.html.find('#mcWidget_dandoElementList_from'),this.html.find('#mcWidget_dandoElementList_to'));var oddRow=true;var trPrototype=this.html.find('tbody tr');var dandoType=this.data.dandoType;$.each(this.data.rows,function(index,row){var tr=trPrototype.clone();mcw.fillElementVariables(tr,{id:row.id,price:mcw.i18n.formatCurrency(row.price,row.currency),duzp:self.formatDuzp(row.duzp),type:mcw.i18n.localizeCode('dando.serviceType.'+row.type),balance:mcw.i18n.formatCurrency(row.balanceAfter,row.currency),detail:self.formatDetail(row.type,row.info),shortDetail:self.formatShortDetail(row.type,row.info),taxDescription:row.taxDocDescription,sourceMsisdn:row.userName});if(oddRow){tr.addClass('odd');}
if(row.price<0){tr.find('td.price').addClass('negativePrice');}
if(dandoType==0){var doc=row.taxDocIdPartner;}else{var doc=row.taxDocId;}
if(doc){tr.find('td.checkbox').empty();tr.find('td.taxDocument a').click(function(){mcw.openFileLink('dandoTaxDocument',{taxDocumentId:doc,locale:mcw.configuration.locale},doc);});}else{tr.find('td.taxDocument').empty();}
tr.insertBefore(trPrototype);oddRow=!oddRow;});trPrototype.remove();this.html.find('#mcWidget_dandoElementList_createTaxDocuments').click(function(){self.createTaxDocuments();});this.html.find('#mcWidget_dandoElementList_createDateIntervalTaxDocument').click(function(){self.createDateIntervalTaxDocument();});this.html.find('#mcWidget_dandoElementList_createCsv').click(function(){self.createCsv();});this.html.find('#mcWidget_dandoElementList_update').click(function(){self.update();});this.html.find('#mcWidget_dandoElementList_display').click(function(){self.display();});this.html.find('.tabLabels .dandoTaxDocuments').click(function(){self.displayDocumentList();});this.html.find('.tabLabels .dandoAssociatedMsisdnList').click(function(){self.displayAssociatedMsisdnList();});this.displayPreprocessingStatus();if(this.data.status=='PROCESSING'){this.html.find('#mcWidget_dandoElementList_update').attr('disabled','disabled');}};mcw.DandoElementListForm.prototype.displayAssociatedMsisdnList=function(){if(!this.dandoAssociatedMsisdnForm){this.dandoAssociatedMsisdnForm=new mcw.DandoAssociatedMsisdnListForm();this.dandoAssociatedMsisdnForm.dandoDocumentListForm=this;}
this.dandoAssociatedMsisdnForm.display();};mcw.DandoElementListForm.prototype.displayDocumentList=function(){if(!this.dandoDocumentListForm){this.dandoDocumentListForm=new mcw.DandoDocumentListForm();this.dandoDocumentListForm.dandoElementListForm=this;}
this.dandoDocumentListForm.display();};mcw.DandoElementListForm.prototype.displayPreprocessingStatus=function(){mcw.messageForm.reset();switch(this.data.status){case'OK':mcw.messageForm.addSuccessCode('dandoElementList.preprocessing.success');break;case'FAILED':mcw.messageForm.addErrorCode('dandoElementList.preprocessing.failure');break;case'PROCESSING':mcw.messageForm.addNotificationCode('dandoElementList.preprocessing.processing');break;default:break;}
mcw.messageForm.display();};mcw.DandoElementListForm.prototype.formatDuzp=function(dateString){return mcw.i18n.formatDate(new Date(dateString),mcw.i18n.dateFormats.date);};mcw.DandoElementListForm.prototype.formatDetail=function(type,info){var detail;switch(type){case'CALL':detail=new mcw.DandoElementCallInfo(type,info).format();break;case'FEE':detail=new mcw.DandoElementFeeInfo(type,info).format();break;case'PARKING':detail=new mcw.DandoElementParkingInfo(type,info).format();break;case'SMS':detail=new mcw.DandoElementSmsInfo(type,info).format();break;case'CANCEL':detail=new mcw.DandoElementCancelInfo(type,info).format();break;case'TARIF':detail=new mcw.DandoElementTarifInfo(type,info).format();break;case'TICKET':detail=new mcw.DandoElementTicketInfo(type,info).format();break;case'TOPUP':detail=new mcw.DandoElementTopupInfo(type,info).format();break;default:mcw.logger.logWarning('Unknown tax element info type "'+type+'"');detail='';break;}
return detail;};mcw.DandoElementListForm.prototype.formatShortDetail=function(type,info){var shortDetail=this.formatDetail(type,info);if(shortDetail.length>30){shortDetail=shortDetail.substr(0,30)+'&hellip;';}
return shortDetail;};mcw.DandoElementListForm.prototype.createTaxDocuments=function(){var self=this;var taxDocumentIds=[];$('#mcWidget_dandoElementList tbody :checkbox:checked').each(function(){taxDocumentIds.push($(this).val());});if(taxDocumentIds.length==0){return;}
mcw.server.callFunction('dandoCreateDocumentRequest',{ids:taxDocumentIds},function(response){self.display();$.each(response.docId,function(index,docId){mcw.openFileLink('dandoTaxDocument',{taxDocumentId:docId,locale:mcw.configuration.locale},docId);});});};mcw.DandoElementListForm.prototype.createDateIntervalTaxDocument=function(){var self=this;mcw.server.callFunction('dandoCreateDocumentRequestForInterval',{from:this.dateRange.getServerFrom(),to:this.dateRange.getServerTo()},function(response){if(!response.docId){return;}
self.display();$.each(response.docId,function(index,taxDocumentId){mcw.openFileLink('dandoTaxDocument',{taxDocumentId:taxDocumentId,locale:mcw.configuration.locale},taxDocumentId);});});};mcw.DandoElementListForm.prototype.update=function(){mcw.server.callFunction('dandoRequestPreprocessing',{},function(response){mcw.messageForm.reset();mcw.messageForm.addNotificationCode('dandoElementList.preprocessing.start');mcw.messageForm.display();});};mcw.DandoElementListForm.prototype.getMsisdn=function(infoString){var info=infoString;if(info==null||info.length==0){return"";}
var start=info.indexOf("A=");if(start<0){return"";}
var msisdn=info.substring(start+2,info.length-1);if(msisdn.length<1){return"";}
var end=msisdn.indexOf(" ");if(start<0){return"";}
return msisdn.substring(0,end);};
mcw.DandoDocumentListForm=function(){this.dandoElementListForm=null;this.dandoAssociatedMsisdnForm=null;this.data=null;this.dateRange=new mcw.FormDateRange({from:mcw.calendar.getMonthFirstDay(),to:mcw.calendar.getMonthLastDay()});this.paging=new mcw.FormPaging();};mcw.DandoDocumentListForm.prototype=new mcw.Form({htmlTemplateId:'dandoDocumentList',menuItem:'dando'});mcw.DandoDocumentListForm.prototype.constructor=mcw.DandoDocumentListForm;mcw.DandoDocumentListForm.prototype.loadData=function(callback){var self=this;mcw.server.callFunction('dandoGetAllUserTaxDocuments',{from:this.dateRange.getServerFrom(),to:this.dateRange.getServerTo(),pageNumber:this.paging.pageNumber,pageSize:this.paging.pageSize},function(response){self.data=response;callback();});};mcw.DandoDocumentListForm.prototype.adjustHtml=function(){var self=this;if(mcw.dataCache.msisdn){mcw.fillElementVariables(this.html,{msisdn:mcw.dataCache.msisdn.msisdn});}
this.paging.setElementCount(this.data.total);this.paging.adjustHtml(this.html);this.paging.changePage=function(){self.display();};this.dateRange.adjustHtml(this.html.find('#mcWidget_dandoDocumentList_from'),this.html.find('#mcWidget_dandoDocumentList_to'));var trPrototype=this.html.find('tbody tr');var oddRow=true;$.each(this.data.rows,function(index,row){var tr=trPrototype.clone();mcw.fillElementVariables(tr,{id:row.id,name:row.name,duzp:self.formatDuzp(row.duzp),creationDate:self.formatCreationDate(row.whenCreated),totalPrice:mcw.i18n.formatCurrency(row.totalPrice+row.totalPriceFactoring,row.currency),type:mcw.i18n.localizeCode('dandoDocumentList.type.'+row.type)});tr.find('td.taxDocumentName a').click(function(){mcw.openFileLink('dandoTaxDocument',{taxDocumentId:row.id,locale:mcw.configuration.locale},row.id);});tr.find('td.downloadPdf a').click(function(){mcw.openFileLink('downloadDandoTaxDocumentPdf',{taxDocumentId:row.id,locale:mcw.configuration.locale},row.id);});if(oddRow){tr.addClass('odd');}
tr.insertBefore(trPrototype);oddRow=!oddRow;});trPrototype.remove();this.html.find('#mcWidget_dandoDocumentList_displayTaxDocuments').click(function(){self.displayTaxDocuments();});this.html.find('#mcWidget_dandoDocumentList_display').click(function(){self.display();});this.html.find('.tabLabels .dandoTaxElements').click(function(){self.displayElementList();});this.html.find('.tabLabels .dandoAssociatedMsisdnList').click(function(){self.displayAssociatedMsisdnList();});};mcw.DandoDocumentListForm.prototype.displayElementList=function(){if(!this.dandoElementListForm){this.dandoElementListForm=new mcw.DandoElementListForm();this.dandoElementListForm.dandoDocumentListForm=this;}
this.dandoElementListForm.display();};mcw.DandoDocumentListForm.prototype.displayAssociatedMsisdnList=function(){if(!this.dandoAssociatedMsisdnForm){this.dandoAssociatedMsisdnForm=new mcw.DandoAssociatedMsisdnListForm();this.dandoAssociatedMsisdnForm.dandoDocumentListForm=this;}
this.dandoAssociatedMsisdnForm.display();};mcw.DandoDocumentListForm.prototype.formatDuzp=function(dateString){return mcw.i18n.formatDate(new Date(dateString),mcw.i18n.dateFormats.date);};mcw.DandoDocumentListForm.prototype.formatCreationDate=function(dateString){return mcw.i18n.formatDate(new Date(dateString),mcw.i18n.dateFormats.date);};mcw.DandoDocumentListForm.prototype.displayTaxDocuments=function(){var taxDocumentIds=[];$('#mcWidget_dandoDocumentList tbody :checkbox:checked').each(function(){taxDocumentIds.push($(this).val());});$.each(taxDocumentIds,function(index,taxDocumentId){mcw.openFileLink('dandoTaxDocument',{taxDocumentId:taxDocumentId,locale:mcw.configuration.locale},taxDocumentId);});};
mcw.DandoPsmsLoginForm=function(){};mcw.DandoPsmsLoginForm.prototype=new mcw.Form({htmlTemplateId:'dandoPsmsLogin',menuItem:'dando'});mcw.DandoPsmsLoginForm.prototype.constructor=mcw.DandoPsmsLoginForm;mcw.DandoPsmsLoginForm.prototype.adjustHtml=function(){var self=this;mcw.countryManager.fillCallingCodes(this.html.find('#mcWidget_dandoPsmsLogin_phonePrefix'));this.html.find('form').validate({submitHandler:function(){self.login();},rules:{mcWidget_dandoPsmsLogin_password:{required:function(){return!$('#mcWidget_dandoPsmsLogin_knowPassword').is(':checked');}}},messages:{mcWidget_dandoPsmsLogin_phone:{required:mcw.i18n.localizeCode('form.field.required')},mcWidget_dandoPsmsLogin_password:{required:mcw.i18n.localizeCode('form.field.required')}}});this.html.find('#mcWidget_dandoPsmsLogin_knowPassword').click(function(){$('#mcWidget_dandoPsmsLogin .knowPassword').toggle('normal');$('label[for=mcWidget_dandoPsmsLogin_password]').toggleClass('required');});},mcw.DandoPsmsLoginForm.prototype.login=function(){var msisdn=$('#mcWidget_dandoPsmsLogin_phonePrefix').val()+$('#mcWidget_dandoPsmsLogin_phone').val();if($('#mcWidget_dandoPsmsLogin_knowPassword').is(':checked')){var form=new mcw.DandoPsmsMsisdnVerificationForm({msisdn:msisdn});form.display();}else{mcw.server.callFunction('dandoLogin',{username:msisdn,password:$('#mcWidget_dandoPsmsLogin_password').val()},function(response){mcw.dataCache.updateAllMsisdnData(function(){new mcw.MsisdnLogoutForm().display();mcw.menuForm.display();new mcw.DandoElementListForm().display();});});}};
mcw.DandoPsmsMsisdnVerificationForm=function(parameters){this.msisdn=parameters.msisdn;};mcw.DandoPsmsMsisdnVerificationForm.prototype=new mcw.MsisdnVerificationForm({});mcw.DandoPsmsMsisdnVerificationForm.prototype.constructor=mcw.DandoPsmsMsisdnVerificationForm;mcw.DandoPsmsMsisdnVerificationForm.prototype.loadData=function(callback){var self=this;mcw.server.callFunction('dandoGetVerificationInfo',{msisdn:this.msisdn},function(response){self.bNumber=response.bnumber;self.totalTimeout=response.timeout;callback();});};mcw.DandoPsmsMsisdnVerificationForm.prototype.isVerified=function(callback){mcw.server.callFunction('dandoIsVerified',{msisdn:this.msisdn},function(response){callback(response.result);});};mcw.DandoPsmsMsisdnVerificationForm.prototype.displaySuccessResult=function(){mcw.messageForm.reset();mcw.messageForm.addSuccessCode('dandoPsmsMsisdnVerification.success');mcw.messageForm.display();var form=new mcw.DandoPsmsPasswordSettingForm({msisdn:this.msisdn});form.display();};
mcw.DandoPsmsPasswordSettingForm=function(parameters){this.msisdn=parameters.msisdn;};mcw.DandoPsmsPasswordSettingForm.prototype=new mcw.Form({htmlTemplateId:'dandoPsmsPasswordSetting'});mcw.DandoPsmsPasswordSettingForm.prototype.constructor=mcw.DandoPsmsPasswordSettingForm;mcw.DandoPsmsPasswordSettingForm.prototype.adjustHtml=function(){var self=this;this.html.find('form').validate({submitHandler:function(){self.setPassword();},rules:{mcWidget_dandoPsmsPasswordSetting_password1:{minlength:4},mcWidget_dandoPsmsPasswordSetting_password2:{equalTo:'#mcWidget_dandoPsmsPasswordSetting_password1'}},messages:{mcWidget_dandoPsmsPasswordSetting_password1:{required:mcw.i18n.localizeCode('registration.password1.required'),minlength:mcw.i18n.localizeCode('registration.password1.minlength')},mcWidget_dandoPsmsPasswordSetting_password2:{required:mcw.i18n.localizeCode('registration.password2.required'),equalTo:mcw.i18n.localizeCode('registration.passwords.equal')}}});this.html.find('#mcWidget_dandoPsmsPasswordSetting_password1').blur(function(){$('#mcWidget_dandoPsmsPasswordSetting_password2').valid();});};mcw.DandoPsmsPasswordSettingForm.prototype.setPassword=function(){var self=this;mcw.server.callFunction('dandoSetPassword',{username:this.msisdn,password:$('#mcWidget_dandoPsmsPasswordSetting_password1').val()},function(response){mcw.server.callFunction('dandoLogin',{username:self.msisdn,password:$('#mcWidget_dandoPsmsPasswordSetting_password1').val()},function(response2){mcw.dataCache.updateAllMsisdnData(function(){mcw.messageForm.reset();mcw.messageForm.addSuccessCode('dandoPsmsPasswordSetting.setPassword.success');mcw.messageForm.display();new mcw.MsisdnLogoutForm().display();mcw.menuForm.display();new mcw.DandoElementListForm().display();});});});};
mcw.MsisdnLogoutForm=function(){};mcw.MsisdnLogoutForm.prototype=new mcw.Form({htmlTemplateId:'msisdnLogout'});mcw.MsisdnLogoutForm.prototype.constructor=mcw.MsisdnLogoutForm;mcw.MsisdnLogoutForm.prototype.getDisplayElement=function(){return $('#mcWidget_loginArea');};mcw.MsisdnLogoutForm.prototype.adjustHtml=function(){mcw.fillElementVariables(this.html,{msisdn:mcw.dataCache.msisdn.msisdn});};
mcw.MposUserListForm=function(parameters){this.data=null;this.paging=new mcw.FormPaging();this.filter={loginNumber:'',firstName:'',lastName:'',msisdn:'',email:''};};mcw.MposUserListForm.prototype=new mcw.Form({htmlTemplateId:'mposUserList',menuItem:'userList'});mcw.MposUserListForm.prototype.constructor=mcw.MposUserListForm;mcw.MposUserListForm.prototype.loadData=function(callback){var self=this;mcw.server.callFunction('mposGetUsers',{pageNumber:this.paging.pageNumber,pageSize:this.paging.pageSize,loginNumber:this.filter.loginNumber,firstName:this.filter.firstName,lastName:this.filter.lastName,phone:this.filter.msisdn,email:this.filter.email},function(response){self.data=response;callback();});};mcw.MposUserListForm.prototype.adjustHtml=function(){var self=this;this.paging.setElementCount(this.data.total);this.paging.adjustHtml(this.html);this.paging.changePage=function(){self.display();};var trPrototype=this.html.find('tbody tr');var oddRow=true;$.each(this.data.rows,function(index,row){var tr=trPrototype.clone();mcw.fillElementVariables(tr,{id:row.loginName,loginNumber:row.loginName,firstName:row.firstName,lastName:row.lastName,phone:row.phone,email:row.email});if(oddRow){tr.addClass('odd');}
tr.find('a.userDetail').click(function(){self.displayUserDetail(row.loginName);});tr.insertBefore(trPrototype);oddRow=!oddRow;});trPrototype.remove();this.html.find('form').validate({submitHandler:function(){self.display();}});this.html.find('#mcWidget_mposUserList_loginNumberFilter').val(this.filter.loginNumber);this.html.find('#mcWidget_mposUserList_firstNameFilter').val(this.filter.firstName);this.html.find('#mcWidget_mposUserList_lastNameFilter').val(this.filter.lastName);this.html.find('#mcWidget_mposUserList_msisdnFilter').val(this.filter.msisdn);this.html.find('#mcWidget_mposUserList_emailFilter').val(this.filter.email);this.html.find('#mcWidget_mposUserList_loginNumberFilter').change(function(){self.filter.loginNumber=$(this).val();});this.html.find('#mcWidget_mposUserList_firstNameFilter').change(function(){self.filter.firstName=$(this).val();});this.html.find('#mcWidget_mposUserList_lastNameFilter').change(function(){self.filter.lastName=$(this).val();});this.html.find('#mcWidget_mposUserList_msisdnFilter').change(function(){self.filter.msisdn=$(this).val();});this.html.find('#mcWidget_mposUserList_emailFilter').change(function(){self.filter.email=$(this).val();});};mcw.MposUserListForm.prototype.displayUserDetail=function(loginNumber){mcw.dataCache.mpos.selectedUserLoginNumber=loginNumber;mcw.dataCache.updateAllMposSelectedUserData(function(){new mcw.MposUserDetailForm().display();});};
mcw.MposFindUserForm=function(parameters){};mcw.MposFindUserForm.prototype=new mcw.Form({htmlTemplateId:'mposFindUser',menuItem:'findUser'});mcw.MposFindUserForm.prototype.constructor=mcw.MposFindUserForm;mcw.MposFindUserForm.prototype.adjustHtml=function(){var self=this;this.html.find('form').validate({submitHandler:function(){self.findUser();},messages:{mcWidget_mposFindUser_loginNumber:{required:mcw.i18n.localizeCode('form.field.required')}}});};mcw.MposFindUserForm.prototype.adjustDom=function(){$('#mcWidget_mposFindUser_loginNumber').focus();};mcw.MposFindUserForm.prototype.findUser=function(){var loginNumber=$('#mcWidget_mposFindUser_loginNumber').val();mcw.server.callFunction('mposUserExists',{loginNumber:loginNumber},function(response){if(response.result){mcw.dataCache.mpos.selectedUserLoginNumber=loginNumber;mcw.dataCache.updateAllMposSelectedUserData(function(){new mcw.MposUserDetailForm().display();});}else{mcw.messageForm.reset();mcw.messageForm.addErrorCode('mposFindUser.findUser.userNotFound');mcw.messageForm.display();}});};
mcw.MposUserDetailForm=function(){};mcw.MposUserDetailForm.prototype=new mcw.Form({htmlTemplateId:'mposUserDetail'});mcw.MposUserDetailForm.prototype.constructor=mcw.MposUserDetailForm;mcw.MposUserDetailForm.prototype.adjustHtml=function(){var self=this;mcw.fillElementVariables(this.html,{loginNumber:mcw.dataCache.mpos.selectedUserLoginNumber,name:this.buildPersonName()});if(mcw.dataCache.mpos.selectedUser.phoneVerified){this.html.find('#mcWidget_mposUserDetail_verifyMsisdn').attr('disabled','disabled');}
this.html.find('#mcWidget_mposUserDetail_edit').click(function(){mcw.messageForm.clear();self.editUser();});this.html.find('#mcWidget_mposUserDetail_block').click(function(){mcw.messageForm.clear();self.blockUser();});this.html.find('#mcWidget_mposUserDetail_verifyMsisdn').click(function(){mcw.messageForm.clear();self.verifyMsisdn();});this.html.find('#mcWidget_mposUserDetail_acceptCash').click(function(){mcw.messageForm.clear();self.acceptCash();});this.html.find('#mcWidget_mposUserDetail_topup').click(function(){mcw.messageForm.clear();self.topup();});};mcw.MposUserDetailForm.prototype.buildPersonName=function(){var nameParts=[];var person=mcw.dataCache.mpos.selectedUser.person;if(person.prefix){nameParts.push(person.prefix);}
if(person.firstName){nameParts.push(person.firstName);}
if(person.middleName){nameParts.push(person.middleName);}
if(person.lastName){nameParts.push(person.lastName);}
if(person.suffix){nameParts.push(person.suffix);}
return nameParts.join(' ');};mcw.MposUserDetailForm.prototype.editUser=function(){new mcw.MposUserEditForm().display();};mcw.MposUserDetailForm.prototype.blockUser=function(){var self=this;mcw.server.callFunction('mposBlockUser',{loginNumber:mcw.dataCache.mpos.selectedUserLoginNumber},function(response){mcw.dataCache.mpos.selectedUserLoginNumber=null;mcw.dataCache.mpos.selectedUser=null;mcw.messageForm.reset();mcw.messageForm.addSuccessCode('mposUserDetail.block.success');mcw.messageForm.display();new mcw.MposUserListForm().display();});};mcw.MposUserDetailForm.prototype.verifyMsisdn=function(){var self=this;mcw.server.callFunction('mposActivateUserMsisdn',{loginNumber:mcw.dataCache.mpos.selectedUserLoginNumber},function(response){mcw.dataCache.updateAllMposSelectedUserData(function(){mcw.messageForm.reset();mcw.messageForm.addSuccessCode('mposUserDetail.verifyMsisdn.success');mcw.messageForm.display();self.display();});});};mcw.MposUserDetailForm.prototype.acceptCash=function(){new mcw.MposAcceptCashForm().display();};mcw.MposUserDetailForm.prototype.topup=function(){new mcw.MposTopupForm().display();};
mcw.MposAcceptCashForm=function(){};mcw.MposAcceptCashForm.prototype=new mcw.Form({htmlTemplateId:'mposAcceptCash'});mcw.MposAcceptCashForm.prototype.constructor=mcw.MposAcceptCashForm;mcw.MposAcceptCashForm.prototype.getDisplayElement=function(){return $('#mcWidget_mposUserDetail_actionForm');};mcw.MposAcceptCashForm.prototype.adjustHtml=function(){var self=this;$.each(mcw.dataCache.currencies,function(currencyCode,currency){var option='<option value="'+currencyCode+'">'
+currency.symbol
+'</option>';self.html.find('#mcWidget_mposAcceptCash_currency').append(option);});this.html.find('form').validate({submitHandler:function(){self.acceptCash();},rules:{mcWidget_mposAcceptCash_amount:{number:true,min:0}},messages:{mcWidget_mposAcceptCash_amount:{required:mcw.i18n.localizeCode('form.field.required'),number:mcw.i18n.localizeCode('form.field.nonNegativeNumber'),min:mcw.i18n.localizeCode('form.field.nonNegativeNumber')}},errorPlacement:function(error,element){element.parent().append(error);}});};mcw.MposAcceptCashForm.prototype.acceptCash=function(){var self=this;mcw.server.callFunction('mposTopup',{loginNumber:mcw.dataCache.mpos.selectedUserLoginNumber,amount:$('#mcWidget_mposAcceptCash_amount').val(),currency:$('#mcWidget_mposAcceptCash_currency').val()},function(response){mcw.dataCache.updateAllMposSelectedUserData(function(){mcw.messageForm.reset();if(response.result){mcw.messageForm.addSuccessCode('mposAcceptCash.accept.success');new mcw.MposUserDetailForm().display();}else{mcw.messageForm.addErrorCode('mposAcceptCash.accept.error');}
mcw.messageForm.display();});});};
mcw.MposTopupForm=function(){};mcw.MposTopupForm.prototype=new mcw.Form({htmlTemplateId:'mposTopup'});mcw.MposTopupForm.prototype.constructor=mcw.MposTopupForm;mcw.MposTopupForm.prototype.getDisplayElement=function(){return $('#mcWidget_mposUserDetail_actionForm');};mcw.MposTopupForm.prototype.adjustHtml=function(){var self=this;$.each(mcw.dataCache.currencies,function(currencyCode,currency){var option='<option value="'+currencyCode+'">'
+currency.symbol
+'</option>';self.html.find('#mcWidget_mposTopup_currency').append(option);});this.html.find('form').validate({submitHandler:function(){self.topup();},rules:{mcWidget_mposTopup_amount:{number:true,min:0}},messages:{mcWidget_mposTopup_amount:{required:mcw.i18n.localizeCode('form.field.required'),number:mcw.i18n.localizeCode('form.field.nonNegativeNumber'),min:mcw.i18n.localizeCode('form.field.nonNegativeNumber')}},errorPlacement:function(error,element){element.parent().append(error);}});};mcw.MposTopupForm.prototype.adjustDom=function(){if(mcw.dataCache.mpos.selectedUser.callVer){$('#mcWidget_mposTopup_callVerify').attr('checked','checked');}};mcw.MposTopupForm.prototype.topup=function(){var self=this;mcw.server.callFunction('mposGetWebpaymentTopupUrl',{loginNumber:mcw.dataCache.mpos.selectedUserLoginNumber,amount:$('#mcWidget_mposTopup_amount').val(),currency:$('#mcWidget_mposTopup_currency').val(),callVerify:$('#mcWidget_mposTopup_callVerify').is(':checked'),backUrl:mcw.getPageUrl()+'?loginNumber='+mcw.dataCache.mpos.selectedUserLoginNumber},function(response){location.href=response.url;});};
mcw.MposUserRegistrationForm=function(){};mcw.MposUserRegistrationForm.prototype=new mcw.RegistrationForm();mcw.MposUserRegistrationForm.prototype.constructor=mcw.MposUserRegistrationForm;mcw.MposUserRegistrationForm.prototype.adjustRegistrationHtml=function(){var self=this;this.html.find('#mcWidget_registration_loginNumber').blur(function(){self.verifyLoginNumber();});this.html.find('#mcWidget_registration_generatedLoginNumber').click(function(){$('#mcWidget_registration_loginNumber').attr('disabled','disabled');});this.html.find('#mcWidget_registration_userLoginNumber').click(function(){$('#mcWidget_registration_loginNumber').removeAttr('disabled');if($('#mcWidget_registration_loginNumber').is(':filled')){$('#mcWidget_registration_loginNumber').valid();}});};mcw.MposUserRegistrationForm.prototype.adjustDom=function(){$('#mcWidget_registration_generatedLoginNumber').click();};mcw.MposUserRegistrationForm.prototype.register=function(){var self=this;var parameters=this.buildParameters();if($('#mcWidget_registration_userLoginNumber').is(':checked')){parameters.loginNumber=$('#mcWidget_registration_loginNumber').val();}
mcw.server.callFunction('mposRegister',parameters,function(response){mcw.messageForm.reset();mcw.messageForm.addSuccessCode('mposRegistration.register.success',{accountNumber:response.loginNumber});mcw.messageForm.display();new mcw.MposUserListForm().display();});};mcw.MposUserRegistrationForm.prototype.verifyLoginNumber=function(){var loginNumber=$('#mcWidget_registration_loginNumber').val();mcw.server.callFunction('isLoginAvailable',{loginNumber:loginNumber},function(response){if(!response.available){$('#mcWidget_registration form').validate().showErrors({mcWidget_registration_loginNumber:mcw.i18n.localizeCode('error.loginNotAvailable')});}},function(response){});};
mcw.MposUserEditForm=function(){};mcw.MposUserEditForm.prototype=new mcw.EditForm();mcw.MposUserEditForm.prototype.constructor=mcw.MposUserEditForm;mcw.MposUserEditForm.prototype.getDisplayElement=function(){return $('#mcWidget_mposUserDetail_actionForm');};mcw.MposUserEditForm.prototype.getUserData=function(){return mcw.dataCache.mpos.selectedUser;};mcw.MposUserEditForm.prototype.save=function(){var self=this;var parameters=this.buildParameters();parameters.currentPassword='';parameters.loginNumber=mcw.dataCache.mpos.selectedUserLoginNumber;mcw.server.callFunction('mposUpdateRegistration',parameters,function(response){mcw.dataCache.updateAllMposSelectedUserData(function(){mcw.messageForm.reset();mcw.messageForm.addSuccessCode('mposRegistration.save.success');mcw.messageForm.display();new mcw.MposUserDetailForm().display();});});};
mcw.EmailVerificationAction=function(parameters){this.email=parameters.email;};mcw.EmailVerificationAction.prototype.perform=function(){var self=this;mcw.server.callFunction('requestVerification',{type:'email',value:this.email,url:mcw.getPageUrl()},function(response){mcw.messageForm.reset();mcw.messageForm.addNotificationCode('emailVerification.par1',{email:self.email});mcw.messageForm.display();});};
mcw.DandoElementDetailInfo=function(type,info){this.type=type;this.parameters={};this.parse(info);};mcw.DandoElementDetailInfo.prototype.parse=function(info){var self=this;var parts=info.split(',');$.each(parts,function(index,part){var nameAndValue=part.split('=',2);var name=nameAndValue[0];var value=nameAndValue.length==2?nameAndValue[1]:'';self.parameters[name]=value;});};mcw.DandoElementDetailInfo.prototype.format=function(){return mcw.i18n.localizeCode('dandoElementList.detail.'+this.type,this.getFormatParameters());};
mcw.DandoElementCallInfo=function(type,info){this.detailInfo=new mcw.DandoElementDetailInfo(type,info);this.detailInfo.getFormatParameters=function(){return{};};};mcw.DandoElementCallInfo.prototype.format=function(){return this.detailInfo.format();};
mcw.DandoElementCancelInfo=function(type,info){this.detailInfo=new mcw.DandoElementDetailInfo(type,info);this.detailInfo.getFormatParameters=function(){return{};};};mcw.DandoElementCancelInfo.prototype.format=function(){return this.detailInfo.format();};
mcw.DandoElementFeeInfo=function(type,info){this.detailInfo=new mcw.DandoElementDetailInfo(type,info);this.detailInfo.getFormatParameters=function(){return{};};};mcw.DandoElementFeeInfo.prototype.format=function(){return this.detailInfo.format();};
mcw.DandoElementParkingInfo=function(type,info){this.detailInfo=new mcw.DandoElementDetailInfo(type,info);this.detailInfo.getFormatParameters=function(){return{};};};mcw.DandoElementParkingInfo.prototype.format=function(){return this.detailInfo.format();};
mcw.DandoElementSmsInfo=function(type,info){this.detailInfo=new mcw.DandoElementDetailInfo(type,info);this.detailInfo.getFormatParameters=function(){return{aNumber:this.parameters.aNumber,bNumber:this.parameters.bNumber};};};mcw.DandoElementSmsInfo.prototype.format=function(){return this.detailInfo.format();};
mcw.DandoElementTariffInfo=function(type,info){this.detailInfo=new mcw.DandoElementDetailInfo(type,info);this.detailInfo.getFormatParameters=function(){return{};};};mcw.DandoElementTariffInfo.prototype.format=function(){return this.detailInfo.format();};
mcw.DandoElementTicketInfo=function(type,info){this.detailInfo=new mcw.DandoElementDetailInfo(type,info);this.detailInfo.getFormatParameters=function(){return{};};};mcw.DandoElementTicketInfo.prototype.format=function(){return this.detailInfo.format();};
mcw.DandoElementTopupInfo=function(type,info){this.detailInfo=new mcw.DandoElementDetailInfo(type,info);this.detailInfo.getFormatParameters=function(){return{};};};mcw.DandoElementTopupInfo.prototype.format=function(){return this.detailInfo.format();};