preloader = new $.materialPreloader({
    position: 'top',
    height: '5px',
    col_1: '#159756',
    col_2: '#da4733',
    col_3: '#3b78e7',
    col_4: '#fdba2c',
    fadeIn: 300,
    fadeOut: 300
});
preloader.on();

var imeiUrl = GetURLParameter('imei')?.padStart(16,"0");
var ServiceProfileUrl = GetURLParameter('ServiceProfile');



var DealerTokenUrl = $('#dealerToken').val();

if(!DealerTokenUrl){
	DealerTokenUrl = GetURLParameter('DealerToken');
}
if(!DealerTokenUrl){
	DealerTokenUrl = '00000000-0000-0000-0000-000000000000'
}
 $('#dealerToken').val(DealerTokenUrl);
 
 var accountNameUrl = GetURLParameter('AccountName');
 
//var DealerNameUrl = GetURLParameter('DealerName');
var referral = GetURLParameter('ref') | 0;
var operator = 2;
switch (referral){
 case 1:
 operator = 8;
}

var DealerNameUrl = $('#dealerName').val();

var projectNumberUrl = GetURLParameter('pn');

var emailUrl = GetURLParameter('email');
var loginUrl = GetURLParameter('LoginName');
var countryCodeUrl = GetURLParameter('CountryCode');
var phoneUrl = GetURLParameter('Phone');
var fromAppFlagUrl = GetURLParameter('FromApp');
//var fromAgentPortalFlagUrl = GetURLParameter('Agent');
var dealerTypeUrl = GetURLParameter('DealerType');



	var curSolution = '';
	var curPlan = '';

var isStripe = false





var FITMENTOPTIONS = {
		RemoteImmob: '1',
		AlarmIntegration: '2',
		SOSButton: '4',
		NotConnectedIgn: '8',
		FitmentAfterIsolater: '16',
		EngineTheft: '32',
		Siren: '64',
		BilgeAlarm: '128',
		ShorePowerDisconn: '256',
		RemoteDoor: '512'
	}

	var PRODUCTFEATURES = {
		Input1: 16777216,
		Input2: 131072,

		Input3: 33554432,
		Input4: 67108864,
		Output1: 134217728,
		Output2: 268435456,

		Power: 128,
	}

//var parsedUrl = psl.parse(window.document.referrer);


/*if(!fromAgentPortalFlagUrl){
    let agentUrls = ['quiktrak.eu', 'www.quiktrak.eu', 'quiktrak.co', 'www.quiktrak.co', 'enduser.quiktrak.co', 'enduser1.quiktrak.co', 'witigps.quiktrak.co'];

    if (document.referrer){
        const url = new URL(document.referrer)
        if(agentUrls.indexOf(url.host) !== -1){
            fromAgentPortalFlagUrl = 1
        }
    }
}*/

//'5f87b4fc-d25b-4' //"Annual"
//'33ENPEYR38SRC' //"Monthly"
//2e929111-26a2-4c31-95cd-17d070542946  //"monthly iridium"
//witi live prices
let PRICES = {
	QProtect: {
        '5f87b4fc-d25b-4': {
            val: '$49.00',
            id: 'price_1O7diQLhZvibZX5gnl3XWl1M'//price_1O7LisLhZvibZX5g2e06Ci6S --price_1Jq3YiLhZvibZX5gcY87Wz3F
        },
    },
    Loc8: {
        '5f87b4fc-d25b-4': {
            val: '$98.00 inc GST',
            id: 'price_1O7dggLhZvibZX5gfyPglEmE',//'--price_1Jq3XTLhZvibZX5g71DQDDNQ'
        },
    },
    Track: {
        '5f87b4fc-d25b-4': {
            val: '$228.00 inc GST',
            id: 'price_1O7dbBLhZvibZX5gk3wADq5h',//'--price_1Jq3VyLhZvibZX5g66lvGmFB',
        },
        '33ENPEYR38SRC': {
            val: '$19.00 inc GST',
            id: 'price_1O7dcaLhZvibZX5gaAvJhdDt',//'--price_1Jq3VxLhZvibZX5glI6LZNmE',
        }
    },
	Iridium: {
        '33ENPEYR38SRC': {
            val: '$55.00 inc GST',
            id: 'price_1PprEmLhZvibZX5g8y2p8ffV',//'--price_1Jq3VxLhZvibZX5glI6LZNmE',
        }
    },
	AnnualTrackIncluded: { //2e0ebf88-5375-4497-8afb-bfd8624cc2aa
        '2e0ebf88-5375-4497-8afb-bfd8624cc2aa': {
            val: '',
            id: 'price_1O7dbBLhZvibZX5gk3wADq5h',//'--price_1Jq3VyLhZvibZX5g66lvGmFB',
        },
    },
    Watch: {
        '5f87b4fc-d25b-4': {
            val: '$360.00 inc GST',
            id: 'price_1O7dkOLhZvibZX5gZ3ZTImK0',//'--price_1JqlPULhZvibZX5gp8vvdgWw',
        },
        '33ENPEYR38SRC': {
            val: '$33.00 inc GST',
            id: 'price_1O7djnLhZvibZX5gmo5RtRtb',//--'price_1JqlPULhZvibZX5gSf3V6AYu',
        }
    },
}


//1-11227-12354

/*if (DealerTokenUrl && referral) {
    if (ServiceProfileUrl && ServiceProfileUrl != '0000000000000' && ServiceProfileUrl != 'QUIKLOC800000' && !fromAppFlagUrl) {
        $('.groupAutoSuspend').show();
    }else{
        $('.groupAutoSuspend').hide();
    }
}else{
    $('.groupAutoSuspend').hide();
}*/
if (imeiUrl) {
    $('#imei').val(imeiUrl);
}

if (DealerNameUrl) {
    $('#invoiceName').val(decodeURIComponent(DealerNameUrl));
}

if (projectNumberUrl){
    $('#projectNumber').val(parseInt(projectNumberUrl));
}
if (emailUrl) {
    $('#account').val(decodeURIComponent(emailUrl));
    $('#email').val(decodeURIComponent(emailUrl));
}
if (accountNameUrl) {
    $('#accountName').val(decodeURIComponent(accountNameUrl));
}

if(dealerTypeUrl){
    $('.other_payment_method').removeClass('display-none');
}

$(function(){

    $('[data-toggle="tooltip"]').tooltip();

    /* mask input START */
    $('#ccExpiryDate').mask("99/99");
    $('input[name="ccNumber"]').mask("9999 9999 9999 9999");
    $("#ccCVV").mask("999");
    $("#voucherCode").mask("********-****-****-****-************");
    //cb3ed0c4-ea04-4cb9-b9db-2e3993706b81

    $('input[name="ccType"]').on('change', function(){
        var val = $(this).val();
        if (val == 'Amex') {
            $('input[name="ccNumber"]').mask("9999 9999 9999 999");
            $("#ccCVV").mask("9999");
        }else{
            $('input[name="ccNumber"]').mask("9999 9999 9999 9999");
            $("#ccCVV").mask("999");
        }
    });

    //getAdditionalData();
    preloader.off();

    if (imeiUrl) { 
        getDefaultParams(imeiUrl,DealerTokenUrl);
    }

    if (emailUrl) {
        $('#email').val(decodeURIComponent(emailUrl));
    }
    if (loginUrl) {
        $('#account').val(decodeURIComponent(loginUrl));
    }
    if (countryCodeUrl) {
        $('#country').val(countryCodeUrl).change();   // fix to change phone code value
        $('#country').selectpicker('val', countryCodeUrl);
        setTimeout(function(){
            $('#country').change();
        },500);
    }
    if (phoneUrl) {
        $('#mobile').val(decodeURIComponent(phoneUrl));
    }

    $('#modalIsDeviceInstalled').modal({keyboard: false, show: true, backdrop: 'static'});
    $('.changeIsInstalled').on('click',function(){
        if($(this).data('is-installed') === 'yes'){
            $('input[name=isDeviceInstalled][value=yes]').prop('checked', true);
        }else{
            $('input[name=isDeviceInstalled][value=no]').prop('checked', true);
            $('#modalDeviceInstalledWarning').modal('show');
            $('.deivceInstalledTopWarning').show();
        }
    })


});


function GetURLParameter(sParam){
    var sParameterName = '';
    var sPageURL = window.location.search.substring(1);
    var sURLVariables = sPageURL.split('&');
    for (var i = 0; i < sURLVariables.length; i++)
    {
        sParameterName = sURLVariables[i].split('=');
        if (sParameterName[0] == sParam)
        {
            return sParameterName[1];
        }
    }
}

function checkDeviceFeatures(deviceTypeFeatures){
		let $elRowInput1 = $('.row-Input1')
		let $elRowInput2 = $('.row-Input2')

		if(!deviceTypeFeatures || !parseInt(deviceTypeFeatures)){
			$elRowInput1.hide()
			$elRowInput2.hide()
			$elColLowerPower.hide()
			$elColDisconnectPower.hide()
			$elColIgnitionPower.hide()
			return
		}
		if( (deviceTypeFeatures & PRODUCTFEATURES.Input1) > 0 ){
			$elRowInput1.show();
		}
		if( (deviceTypeFeatures & PRODUCTFEATURES.Input2) > 0 ){
			$elRowInput2.show();
		}

	}

function getAdditionalData(data){
    $.ajax({
        type: "POST",
        url: "https://testapi.quiktrak.co/Common/V1/Activation/SSP",
        dataType: 'json',
        data: data,
        async: true,
        cache: false,
        beforeSend: function(){
            $('#servicePlan, #solution').prop('disabled',true).selectpicker('refresh');
            preloader.on();
        },
        success: function(result){
            preloader.off();

            if (result.MajorCode == '000') {

                if (result.Data && result.Data.ServiceProfiles && result.Data.ServiceProfiles.length && result.Data.Solutions && result.Data.Solutions.length) {
                    if (data.ProductCode && data.SolutionCode) {
                        setServicePlans(result.Data, data.SolutionCode);
                    }else{
						let product = result.Data.Products.find( itm => itm.Code === data.ProductCode)
							if(product){
								$('#deviceType').data('features', product.Features)
							}

							checkDeviceFeatures(product ? product.Features : '')

							setSolutionTypes(result.Data);
                    }
                }else{
                    alert('There is no Solution Types for this IMEI');
                }
            }
        },
        error: function(XMLHttpRequest, textStatus, errorThrown){
            console.log(XMLHttpRequest);
            console.log(textStatus);
            console.log(errorThrown);
            $('#servicePlan').prop('disabled',false).selectpicker('refresh');
            preloader.off();
        }
    });
}



function setExtraAgent (solutionCode){
	console.log('dealerToken',DealerTokenUrl)
	$.ajax({
		type: "GET",
		url: "https://testapi.quiktrak.co/Quiktrak/V2/Customer/GetAgentExtraPlans?CsCode=" + DealerTokenUrl,
		dataType: 'json',
		data: {},
		async: true,
		cache: false,
		beforeSend: function(){
			preloader.on();
		},
		success: function(result){
			preloader.off();
			//console.log('extraagent',result)
			if(result?.Data?.CustomerExtraPlans?.length || result?.Data?.ExtraWarranty > 0){
				console.log('extra agent add')
				setAgentExtraServicePlans(result, solutionCode)
            }
			//if(result) window.location = 'https://forms.quiktrak.com.au/renewed/'
			
		},
		error: function(XMLHttpRequest, textStatus, errorThrown){
			console.log(XMLHttpRequest);
			console.log(textStatus);
			console.log(errorThrown);
			preloader.off();
		}
	});
}

function isSubscribed(imei){
	$.ajax({
		type: "POST",
		url: "https://newapi.quiktrak.co/Common/V1/Activation/CheckSubscription?imei=" + imei,
		dataType: 'json',
		data: {},
		async: true,
		cache: false,
		beforeSend: function(){
			preloader.on();
		},
		success: function(result){
			preloader.off();

			if(result) window.location = 'https://forms.quiktrak.com.au/renewed/'
			
		},
		error: function(XMLHttpRequest, textStatus, errorThrown){
			console.log(XMLHttpRequest);
			console.log(textStatus);
			console.log(errorThrown);
			preloader.off();
		}
	});
}

function getDefaultParams(imei, DealerToken){
    var USER_DATA = {};
    USER_DATA.imei = imei;
	//const witiarr = []
    //const witiarr = ['0863795050707471','0863795050706614','0868450045039037','0868450045039888','0868450041795640','0862708041950473','0868450045036652','0868450045048723','0863795050726109','0863795050710384','0862708041951505','0868450045038450','0868450040533505','0863795050750133','0863795050706697','0868450045014733','0868450041942770','0868450041929777','0863795050713776','0868450045037817','0868450040995068','0863795050714097','0868450041909464','0863795050719427','0868450041996222','0863795050774539','0868450045035696','0868450041967173','0868450040497123','0868450045046966','0863795050718403','0868450041777655','0863795050735712','0863795050712653','0863795050778399','0868450045045166','0868450045043088','0868450045041009','0863795050780197','0863795050724658','0868450041975200','0868450045036694','0863795050731265','0863795050736066','0868450042005619','0868450041921543','0868450045019369','0868450045014832','0868450045024161','0868450041587666','0868450045040381','0868450045048822','0868450045042197','0863795050770594','0868450041933746','0868450041656131','0868450041903319','0868450041963529','0868450041942911','0863795050768234','0868450045041637','0863795050729152','0868450041933431','0868450040591255','0862708041951620','0862708041878575','0868450041910413','0357424100007807','0868450045035456','0868450040595595','0863795050707588','0863795050773523','0868450040996827','0863795050722868','0868450041842095','0868450040507368','0868450041919695','0863795050744037','0863795050729202','0863795050745695','0863795050701532','0862708041933180','0863795050774299','0868450041965961','0863795050767525','0868450041976810','0862708041901237','0868450041366566','0868450045016043','0863795050716472','0868450041746536','0868450041934793','0868450040991919','0868450041746460','0863795050709139','0863795050768598','0868450041921683','0868450041936590','0868450041969112','0868450041841030','0868450041965342','0868450041909456','0868450041003540','0868450045047394','0864292042552180','0868450041827070','0868450041381185','0868450041852516','0868450041776715','0868450041996842','0862708041924908','0868450041776335','0868450041782119','0863795050730549','0868450041933928','0868450040583922','0868450045019898','0862708041945135','0868450041842046','0868450041920248','0863795050720672','0868450041852383','0868450040991422','0863795050714428','0868450041854579','0868450041968817','0868450040583880','0868450040523704','0868450041662709','0863795050719435','0868450041746759','0863795050714139','0862708041866885','0863795050708636','0868450041776459','0864292042963080','0862708041919718','0352544073916927','0863795050775114','0868450045042171','0864292042936904','0868450041901677','0868450041973809','0862708041943130','0868450041919661','0862708041950424','0862708041946182','0868450041929587','0868450041985175','0868450042037489','0868450041915172','0868450041920685','0868450041888957','0868450041842533','0868450041915412','0868450041892678','0862708041877585','0868450041852854','0868450040588947','0862708041945531','0862708041939799','0864292042933497','0868450041942671','0868450041967736','0868450041841063','0862708041945986','0868450040518423','0868450041015841','0862708041954012','0868450041392646','0862708041916037','0864292042511947','0868450041356070','0868450040521740','0862708041866422','0868450041929637','0862708041869038','0868450041915073','0868450041902451','0862708041945358','0868450041909449','0868450041776665','0868450042037646','0862708041941795','0862708041907374','0862708041919775','0868450041495076','0868450042016038','0868450041929405','0868450041777606','0862708041874228','0868450041910405','0862708041907465','0862708041940904','0868450041942630','0868450041929447','0868450041810670','0868450041915362','0868450041921204','0868450041902105','0868450041933142','0868450040996280','0868450041898899','0868450041841683','0868450041574433','0868450041549393','0868450041549765','0868450041891118','0868450041776178','0868450041998186','0864292043405289','0862708041934311','0868450040993980','0868450041260033','0868450041915081','0868450041908904','0868450041893429','0868450041852276','0868450041946870','0868450041894120','0868450041849827','0868450041891035','0868450041907724','0868450041776889','0868450041934306','0864292040977058','0868450041908011','0868450041970805','0868450041795467','0868450041941384','0868450041965813','0868450041978147','0868450041976943','0868450042005767','0868450041645829','0868450041902303','0868450041936673','0868450041920750','0868450041777127','0868450042037554','0868450042011476','0868450042005841','0868450041381797','0868450041840917','0868450041842541','0868450042035848','0868450041852748','0868450041929272','0868450041965979','0868450041929264','0864292042927234','0868450041964782','0868450041777317','0868450041634047','0868450040986539','0868450041921360','0868450041795624','0868450041795442','0868450041648401','0868450041929330','0868450041921873','0868450042005650','0868450041963743','0868450041921287','0868450040998674','0868450041841451','0868450041970698','0868450041893239','0868450041015684','0868450041579333','0864292042955029','0868450041627298','0868450041811264','0868450041942523','0868450041749837','0868450041776426','0868450041662865','0864292043424454','0868450041634039','0868450041746338','0868450041968957','0868450041964808','0868450041908300','0868450041654128','0868450041911114','0868450040575472','0868450041934017','0864292042938363','0868450041811462','0868450041901594','0868450041933191','0868450041963826','0868450041888908','0868450041995976','0868450041648641','0868450041794924','0868450041005578','0868450041369925','0868450041933589','0868450041929843','0868450041920867','0868450041648567','0868450041281351','0868450041577766','0868450041799105','0868450041933605','0868450041920123','0864292042523058','0352544073914575','0868450041750132','0868450041976729','0868450041810910','0868450041585405','0868450041008390','0868450041777713','0868450041000447','0868450041000371','0864292042948974','0868450041795327','0868450041924307','0868450041830314','0868450041577410','0868450041811371','0868450040590687','0868450041975465','0868450041920370','0868450040988790','0868450041589183','0868450040588525','0868450041795483','0868450041776921','0868450041910470','0868450041998392','0868450041870914','0868450041498641','0868450041509405','0868450041933373','0868450041936830','0868450041894963','0864292043428141','0868450041891092','0868450041841360','0868450040480301','0868450041996115','0868450040996686','0868450041006139','0868450041941020','0868450041778026','0864292042923928','0868450041782481','0868450040992297','0868450041779842','0864292042964237','0868450041996263','0868450041841352','0864292040965186','0868450041995935','0868450041012673','0868450041632850','0868450041820091','0868450041970391','0868450041010040','0868450041614239','0868450041653971','0868450041846344','0868450041382175','0868450041907427','0864292042549913','0868450041895085','0868450041367325','0868450041007749','0864292042518009','0868450040546028','0868450041010867','0868450041650977','0868450041012566','0868450040998971','0868450040484295','0868450041287069','0868450040589515','0868450041968783','0868450041217413','0868450041512789','0868450041485390','0868450040494625','0868450041920669','0868450042040871','0868450041945674','0864292043427200','0868450042037273','0868450041826163','0868450041645597','0868450041660398','0868450041579028','0868450041571314','0868450042035707','0868450041812312','0868450041592690','0868450041965284','0868450041776640','0868450041545938','0868450041749936','0868450041799121','0868450041392323','0868450040987347','0868450041371293','0868450041007962','0868450041581875','0868450041658764','0868450040987230','0868450041573880','0868450040997783','0868450041328491','0868450040495275','0357424100038422','0868450041579630','0868450040451682','0864292042955219','0868450040595165','0868450041015783','0868450041570100','0868450041576628','0868450041634062','0868450041631639','0868450041591205','0868450041508191','0868450040992578','0868450041013291','0868450041589381','0868450041577485','0868450040577007','0868450041569193','0868450041013705','0868450041594282','0868450041007921','0868450041577865','0868450041017813','0868450041631860','0868450041012095','0868450040999946','0868450041302165','0868450041488147','0868450040989038','0864292042948248','0868450041632785','0868450041646363','0868450040990937','0868450040527507','0868450041814623','0868450041814748','0868450040417253','0868450041289776','0868450040594705','0868450041015064','0868450041802685','0868450041012590','0868450040589135','0868450041775352','0868450041008226','0868450041289735','0357424100081398','0864292042525863','0868450040588269','0868450041014612','0868450041793926','0868450041600519','0357424100202507','0864292042945806','0868450040526897','0868450040509000','0868450041015262','0868450041334408','0868450041802909','0868450041000868','0868450041512987','0868450040552984','0868450041332600','0868450041497627','0868450041485465','0868450040443598','0868450040575076','0868450041000587','0868450040990960','0868450041484484','0868450041315001','0864292043409034','0868450040983270','0868450040588657','0868450041651678','0868450041017763','0868450041016062','0868450041006436','0868450041012848','0868450041005404','0868450041775519','0868450041010750','0868450040993410','0868450041004092','0868450041005461','0868450041380831','0868450040994079','0868450040557843','0868450040542456','0868450041013929','0868450040983726','0863795050708180','0868450041012897','0868450041012798','0868450040999573','0868450040484493','0868450040993170','0868450040998203','0868450041015189','0868450041008606','0868450041011592','0868450040519439','0868450041012145','0868450040523753','0868450041004134','0868450040983536','0868450040495044','0868450040995613','0868450040989996','0868450041000850','0868450040999490','0868450040595900','0868450041002757','0868450040537274','0868450041016492','0864292042921807','0868450041015106','0864292042927192','0868450041012137','0868450041005354','0864292043405305','0868450040992974','0868450040991489','0868450040575845','0864292042940567','0868450040986034','0864292042967073','0868450040587899','0868450041006774','0868450040986851','0868450040996868','0868450041000686','0868450040990655','0868450040584839','0868450040564427','0868450040457341','0868450040461665','0868450041008689','0868450040544916','0868450040506279','0868450041010099','0000000000000091','0000000000000091','0868450040992479','0868450040574665','0868450040997122','0868450040991836','0868450040441899','0864292043410982','0864292042937803','0357424100075051','0868450040983668','0864292043406089','0864292043408481','0864292042546539','0868450040592287','0868450040533521','0864292042938751','0864292043402039','0868450040483339','0864292042964211','0868450041012889','0868450040590455','0868450040584417','0868450040562108','0868450040506295','0868450040528356','0864292043400884','0864292043406246','0864292043403425','0868450040416883','0864292042945129','0868450040595702','0864292042924645','0352544073915325','0868450040592261','0868450040594903','0868450040539247','0868450040451807','0868450040586404','0868450040556605','0868450040548339','0868450040494617','0868450040483768','0868450040517243','0864292043407632','0864292042939361','0868450040481903','0868450040452102','0868450040523548','0864292042940112','0868450040580431','0868450040589051','0864292043426699','0864292043406063','0868450040460568','0864292043407079','0868450040454827'];
    
	var $form0 = $("form[name='activation']")
    if($form0.hasClass('form-replace') || $form0.hasClass('form-upgrade')){

    }else{
        /*if(witiarr.indexOf(imei) != -1){
            //alert('This asset has an active subscription set.')
            location.href="https://forms.quiktrak.com.au/renewed/"
        }*/
		isSubscribed(imei);
    }

    if (DealerToken) {
        USER_DATA.DealerToken = DealerToken;
    }

	if( $('[name="activation"]').hasClass('form-activate')){
	    USER_DATA.NewAccount = $('[name="account"]').val();
    }

    $.ajax({
        type: "POST",
        url: "https://testapi.quiktrak.co/Common/V1/Activation/VerifyTesting",
        dataType: 'json',
        data: USER_DATA,
        async: true,
        cache: false,
        beforeSend: function(){
            preloader.on();
        },
        success: function(result){
            preloader.off();

			if(($('[name="activation"]').hasClass('form-register') || $('[name="activation"]').hasClass('form-activate')) && (result?.Data?.IMEI == 'ACTIVATED' || (result?.Data?.SOLUTION_CODE != 'NonActivated' && result?.Data?.SOLUTION_CODE != 'NONE')) ){
				
				window.location = 'https://forms.quiktrak.com.au/status/'
            }else if($('[name="activation"]').hasClass('form-upgrade') && !referral){// 
        		//isSubscribed(imei);
				sendLog1({});
				window.location = 'https://forms.quiktrak.com.au/renewal-atga/?imei='+imei+'&isupgrade=1'
			}else{
				
            }

			isStripe = $('[name="activation"]').hasClass('form-register') && result.Data?.TREE?.indexOf('1-11227-12354-') == -1 && result.Data?.TREE?.indexOf('1-11227-') == 0 ? true : false;
			if( $('[name="activation"]').hasClass('form-activate')){
                isStripe = $('[name="activation"]').hasClass('form-activate') && result.Data.IS_LOCAL_RENEWALL == 'true' && result.Data?.TREE?.indexOf('1-11227-12354-') == -1 && result.Data?.TREE?.indexOf('1-11227-') == 0 ? true : false;
            }else if($('[name="activation"]').hasClass('form-upgrade') && referral){
            	isStripe = true
				//window.location = 'https://forms.quiktrak.com.au/renewal-atga/?imei='+imei
			}

    
      
	  

        
            if(result.Data?.PLAN_CODE == '2e0ebf88-5375-4497-8afb-bfd8624cc2aa'){
				isStripe = false
            }

            if(isStripe){
				$('.is-stripe').removeClass('display-none')
				$('.no-stripe').addClass('display-none')
				$('input[name=paymentType][value=12]').prop('checked', true);
			}else{
      
				$('.is-stripe').addClass('display-none')
				$('.no-stripe').removeClass('display-none')
			}

			
			if(result.Data?.PLAN_CODE != '2e0ebf88-5375-4497-8afb-bfd8624cc2aa'){
			 if(!referral){
               
				$('.no-stripe').addClass('display-none')
			 }else{
				$('.no-stripe').removeClass('display-none')
			 }
            }else{
				$('input[name=paymentType][value=3]').prop('checked', true);
				$('.is-invoice').removeClass('display-none')
				$('.no-invoice').addClass('display-none')
            }
        
        	
        	if(referral){
				$('.groupRenewal').show();
            	$('.groupAutoSuspend').show();
			 }
			 
			/*~~if(result.Data?.TREE?.indexOf('1-11227-') == -1)  {
				$('.no-stripe').addClass('display-none')
				$('.no-invoice').addClass('display-none')
				$('.is-invoice').addClass('display-none')
				$('.form_section_payment').addClass('display-none')
            }*/
			
			
            var MajorCode = result.MajorCode;
            var MinorCode = result.MinorCode;
            var $form = $("form[name='activation']")

            //if (MajorCode == '000') {
                if (result.Data) {
					
                    setDefaultData(result.Data, USER_DATA);
					if(!curSolution.length){
							curSolution = result.Data?.SOLUTION_CODE;
							curPlan = result.Data?.PLAN_CODE;
						}
						
						/*var isDealer = '00000000-0000-0000-0000-000000000000'
						if(DealerToken){
                        	if(DealerToken != '00000000-0000-0000-0000-000000000000'){
                            	isDealer = DealerToken
							}
                        }
						if(result.Data.DEALER_TOKEN){
                        	if(result.Data.DEALER_TOKEN != '00000000-0000-0000-0000-000000000000'){
                            	isDealer = result.Data.DEALER_TOKEN
							}
                        }*/
						
						
                    getAssetDetails({
                        imeis: imei,
                        majortoken: DealerTokenUrl,
                    });
                    if($form.hasClass('form-replace') || $form.hasClass('form-upgrade')){
                        getClientDetailsByIMEI(imei)
                    }

                }
            //}
        },
        error: function(XMLHttpRequest, textStatus, errorThrown){
            console.log(XMLHttpRequest);
            console.log(textStatus);
            console.log(errorThrown);
            preloader.off();
        }
    });
}


function sendLog1(LOG_DATA){
LOG_DATA.Dealer = 'TRY UPGRADE'
LOG_DATA.Login =  $('[name="account"]').val();
LOG_DATA.DealerToken = $('[name="dealerToken"]').val();
LOG_DATA.IMEI = $('[name="imei"]').val();

	
	$.ajax({
						type: "POST",
						url: "https://cartrack.co/activation/al3rtgps/php/log_upgrade.php",
						dataType: 'json',
						data: LOG_DATA,
						async: true,
						cache: false,
						beforeSend: function(){
							
						},
						success: function(data){
						},
						error: function(XMLHttpRequest, textStatus, errorThrown){
												
						}
					});
}


function getAssetDetails(params){
    $.ajax({
        type: "GET",
        url: "https://newapi.quiktrak.co/Common/v1/Activation/GetAssetsInfo",
        dataType: 'json',
        data: params,
        async: true,
        cache: false,
        success: function(result){
            if (result.MajorCode == '000') {
                if (result.Data) {
                    setAssetDetails(result.Data);
                }
            }
        },
        error: function(XMLHttpRequest, textStatus, errorThrown){
            console.log(XMLHttpRequest);
            console.log(textStatus);
            console.log(errorThrown);
        }
    });
}

function setDefaultData(data, prevData){
    if (data) {
        var countryCode = data.DEALER_COUNTRY_CODE;
        var timeZone = data.DEALER_TIME_ZONE;
		console.log('tree',data.TREE?.indexOf('1-11227-'))
        var dealerName = data.DEALER_NAME //data.TREE?.indexOf('1-11227-') != 0 ? data.DEALER_NAME : 'Automotive Technology Group Australia';
        var dealerEmail = data.DEALER_EMAIL;
        var deviceType = data.DEVICETYPE;
        var productName = data.PRODUCTNAME;
        var urlDName = GetURLParameter('DealerName');

        if (countryCode) {
            $('#country').val(countryCode).change();   // fix to change phone code value
            $('#country').selectpicker('val', countryCode);
        }
        /*if (timeZone) {
            $('#timeZone').selectpicker('val', timeZone);
        }*/
        if (!urlDName){
            $('#dealerName').val(decodeURIComponent(dealerName));
            $('#invoiceName').val(decodeURIComponent(dealerName));
        }
		
		
		if (!DealerTokenUrl) {
            $('#dealerToken').val(data.DEALER_TOKEN);
        }
        if (dealerEmail) {
            $('#invoiceEmail').val(decodeURIComponent(dealerEmail));
        }
        if (deviceType && deviceType != 'NONE') {
            $('#deviceType').val(productName).data('code',deviceType);
            $('.info').empty();
			
			
            			if(prevData.DealerToken){
                        	if(prevData.DealerToken != '00000000-0000-0000-0000-000000000000'){
                            	DealerTokenUrl = prevData.DealerToken
							}
                        }
						if(data.DEALER_TOKEN){
                        	if(data.DEALER_TOKEN != '00000000-0000-0000-0000-000000000000'){
                            	DealerTokenUrl = data.DEALER_TOKEN
							}
                        }
						
						$('#dealerToken').val(DealerTokenUrl);
        
			
            getAdditionalData(
                {
                    ProductCode: deviceType,
                    IMEI: prevData.imei,
                    DealerToken: DealerTokenUrl,
                },
                { get: 'solutions' }
            );
            setFitmentOptions($('[name="assetType"]').val());
        }else{
            $('.info').html('<div class="errors">IMEI not found</div>');
            $('#imei').closest('.form-group').addClass('has-error has-danger');
            $('#servicePlan, #solution').empty().prop('disabled',true).selectpicker('refresh');
            $('#deviceType').val('');
            //$('#solution').empty().prop('disabled',true)
        }
    }
}

function setAssetDetails(params) {
    if (params && typeof(params) == 'object' && params.Assets && typeof(params.Assets) == 'object' && params.Assets[0] && typeof(params.Assets[0]) == 'object') {
        if (params.Assets[0].Name) {
            $('#name').val(params.Assets[0].Name);
        }
		if (params.Assets[0].IMEI2) {
            $('#imei2').val(params.Assets[0].IMEI2);
        }
        if (params.Assets[0].Make) {
            $('#describe1').val(params.Assets[0].Make);
        }
        if (params.Assets[0].Model) {
            $('#describe2').val(params.Assets[0].Model);
        }
        if (params.Assets[0].Color) {
            $('#describe3').val(params.Assets[0].Color);
        }
        if (params.Assets[0].Year) {
            $('#describe4').val(params.Assets[0].Year);
        }
        if (params.Assets[0].InstallLocation) {
            $('#instalLocation').val(params.Assets[0].InstallLocation);
        }
        if (params.Assets[0].Notes) {
            $('#notes').val(params.Assets[0].Notes);
        }
        if (params.Assets[0].InitAccHours && parseFloat(params.Assets[0].InitAccHours)) {
            $('#initialEngineHours').val(params.Assets[0].InitAccHours);
        }
        if (params.Assets[0].InitMileage && parseFloat(params.Assets[0].InitMileage)) {
            $('#initialMileage').val(params.Assets[0].InitMileage);
        }
        if (params.Assets[0].Voucher && params.Assets[0].Voucher != 'NONE') {
            processVoucherDetails(params.Assets[0]);
        }else{
            $('#imei').data('binded-solution-code', '');
            $('#imei').data('binded-plan-code', '');
        }


        if (params.Assets[0].AssetType) {
            $('.asset-type-icon-wrapper[data-type="'+params.Assets[0].AssetType+'"]').click();
            setFitmentOptions($('[name="assetType"]').val(),params.Assets[0].FitmentOptions);
        }

    }
}

function processVoucherDetails(assetDetails){
    if (assetDetails) {
        var solutionSelect = $('#solution');
        if (assetDetails.Solution) {
            solutionSelect.selectpicker('val', assetDetails.Solution).prop('disabled',true).selectpicker('refresh');
            $('#imei').data('binded-solution-code', assetDetails.Solution);
            $('#imei').data('binded-plan-code', assetDetails.ServicePlanCode);

            $('#voucherCode').val(assetDetails.Voucher);
            $('input[name="paymentType"][value="4"]').closest('label').click();
        }

    }

}

function resizeIframe(obj) {
    obj.style.height = obj.contentWindow.document.body.scrollHeight + 'px';
}



function setAgentExtraServicePlans(data, solutionCode){
console.log('ea',data)
/*~~extra plan*/
  var extraOptionsHTML = '';
  var extraWarrantyOptionsHTML = '';
  var extendedServicePlanSelect = $('#extendedServicePlan');
  var extendedWarrantySelect = $('#extendedServiceWarranty'); 
  	
  if (solutionCode.toLowerCase()?.indexOf('track') != -1) { 
		let extraTrackPrices = data.Data.CustomerExtraPlans?.find(el=>el.Solution=='TRACK')
    	if(extraTrackPrices?.ANNUAL > 0) {
        	extraOptionsHTML += `<option value="ExtraAnnual" data-extraplanvalue="${ extraTrackPrices?.ANNUAL }">Extend Plan by 1 year - ${ extraTrackPrices?.ANNUAL } $</option>`;
		}
  		if(extraTrackPrices?.YEAR_2 > 0) {
        	extraOptionsHTML += `<option value="ExtraYears2" data-extraplanvalue="${ extraTrackPrices?.YEAR_2 }">Extend Plan by 2 years - ${ extraTrackPrices?.YEAR_2 } $</option>`;
		}
		if(extraTrackPrices?.YEAR_3 > 0) {
        	extraOptionsHTML += `<option value="ExtraYears3" data-extraplanvalue="${ extraTrackPrices?.YEAR_3 }">Extend Plan by 3 years - ${ extraTrackPrices?.YEAR_3 } $</option>`;
		}
		if(extraTrackPrices?.YEAR_4 > 0) {
        	extraOptionsHTML += `<option value="ExtraYears4" data-extraplanvalue="${ extraTrackPrices?.YEAR_4 }">Extend Plan by 4 years - ${ extraTrackPrices?.YEAR_4 } $</option>`;
		}
   }else  if (solutionCode.toLowerCase()?.indexOf('loc8') != -1) { 
        let extraLoc8Prices = data.Data.CustomerExtraPlans?.find(el=>el.Solution=='LOC8')
        if(extraLoc8Prices?.ANNUAL > 0) {
            extraOptionsHTML += `<option value="ExtraAnnual" data-extraplanvalue="${ extraLoc8Prices?.ANNUAL }">Extend Plan by 1 year - ${ extraLoc8Prices?.ANNUAL } $</option>`;
        }
        if(extraLoc8Prices?.YEAR_2 > 0) {
            extraOptionsHTML += `<option value="ExtraYears2" data-extraplanvalue="${ extraLoc8Prices?.YEAR_2 }">Extend Plan by 2 years - ${ extraLoc8Prices?.YEAR_2 } $</option>`;
        }
        if(extraLoc8Prices?.YEAR_3 > 0) {
            extraOptionsHTML += `<option value="ExtraYears3" data-extraplanvalue="${ extraLoc8Prices?.YEAR_3 }">Extend Plan by 3 years - ${ extraLoc8Prices?.YEAR_3 } $</option>`;
        }
        if(extraLoc8Prices?.YEAR_4 > 0) {
            extraOptionsHTML += `<option value="ExtraYears4" data-extraplanvalue="${ extraLoc8Prices?.YEAR_4 }">Extend Plan by 4 years - ${ extraLoc8Prices?.YEAR_4 } $</option>`;
        }
   }else if (solutionCode.toLowerCase()?.indexOf('qprotect') != -1) { 
		let extraQProtectPrices = data.Data.CustomerExtraPlans?.find(el=>el.Solution=='QPROTECT')
        
    	if(extraQProtectPrices?.ANNUAL > 0) {
        	extraOptionsHTML += `<option value="ExtraAnnual" data-extraplanvalue="${ extraQProtectPrices?.ANNUAL }">Extend Plan by 1 year - ${ extraQProtectPrices?.ANNUAL } $</option>`;
		}
  		if(extraQProtectPrices?.YEAR_2 > 0) {
        	extraOptionsHTML += `<option value="ExtraYears2" data-extraplanvalue="${ extraQProtectPrices?.YEAR_2 }">Extend Plan by 2 years - ${ extraQProtectPrices?.YEAR_2 } $</option>`;
		}
		if(extraQProtectPrices?.YEAR_3 > 0) {
        	extraOptionsHTML += `<option value="ExtraYears3" data-extraplanvalue="${ extraQProtectPrices?.YEAR_3 }">Extend Plan by 3 years - ${ extraQProtectPrices?.YEAR_3 } $</option>`;
		}
		if(extraQProtectPrices?.YEAR_4 > 0) {
        	extraOptionsHTML += `<option value="ExtraYears4" data-extraplanvalue="${ extraQProtectPrices?.YEAR_4 }">Extend Plan by 4 years - ${ extraQProtectPrices?.YEAR_4 } $</option>`;
		}
   }
		
    if(data.Data.ExtraWarranty > 0) {
        extraWarrantyOptionsHTML += `<option value="addAnnualWarranty"  data-extrawarrantyvalue="${data.Data?.ExtraWarranty}" >Add additional year of warranty  $ ${data.Data?.ExtraWarranty}</option>`;
	}	
	//Client=2,Dealers=4,Agents=8 if((IsExtraPlan & 2)>0){ it means clients enable  
	//ExtraPayment 0=None,1=Stripe,2=Agent
	
	$('#extraPaymentMethod').val(data.Data?.ExtraPlanPaymentMethod);
	$('#operator').val(operator);

	if((data.Data?.IsExtraPlan & operator) > 0) {
		//if(extendedServicePlanSelect.is(':disabled')) { 
   		 extendedServicePlanSelect.prop('disabled',false);
   		 extendedServicePlanSelect.html(extraOptionsHTML);
   		 extendedServicePlanSelect.selectpicker('refresh');
    	//}
    }
	if((data.Data?.IsExtraWarranty & operator) > 0) {
		//if(extendedWarrantySelect.is(':disabled')) { 
  		  extendedWarrantySelect.prop('disabled',false);
   	      extendedWarrantySelect.html(extraWarrantyOptionsHTML);
  		  extendedWarrantySelect.selectpicker('refresh');
    	//}
    }
}

function setExtraServicePlans(data, solutionCode){
/*~~extra plan*/
  var extraOptionsHTML = '';
  var extraWarrantyOptionsHTML = '';
  var extendedServicePlanSelect = $('#extendedServicePlan');
  var extendedWarrantySelect = $('#extendedServiceWarranty'); 
  	
  if (solutionCode.toLowerCase()?.indexOf('track') != -1) { 
		let extraTrackPrices = data.ExtraPrices?.find(el=>el.Solution=='TRACK')
    	if(extraTrackPrices?.Annual > 0) {
        	extraOptionsHTML += `<option value="ExtraAnnual" data-extraplanvalue="${ extraTrackPrices?.Annual }">Extend Plan by 1 year - ${ extraTrackPrices?.Annual } $</option>`;
		}
  		if(extraTrackPrices?.Years2 > 0) {
        	extraOptionsHTML += `<option value="ExtraYears2" data-extraplanvalue="${ extraTrackPrices?.Years2 }">Extend Plan by 2 years - ${ extraTrackPrices?.Years2 } $</option>`;
		}
		if(extraTrackPrices?.Years3 > 0) {
        	extraOptionsHTML += `<option value="ExtraYears3" data-extraplanvalue="${ extraTrackPrices?.Years3 }">Extend Plan by 3 years - ${ extraTrackPrices?.Years3 } $</option>`;
		}
		if(extraTrackPrices?.Years4 > 0) {
        	extraOptionsHTML += `<option value="ExtraYears4" data-extraplanvalue="${ extraTrackPrices?.Years4 }">Extend Plan by 4 years - ${ extraTrackPrices?.Years4 } $</option>`;
		}/*
		if(DealerTokenUrl == '95b6e884-2943-4027-9d92-512c8a626f0e') {
        	extraOptionsHTML += `<option value="ExtraYears4" data-extraplanvalue="230">Extend Plan by 4 years</option>`;
		}*/

   }else  if (solutionCode.toLowerCase()?.indexOf('loc8') != -1) { 
        let extraLoc8Prices = data.ExtraPrices?.find(el=>el.Solution=='LOC8')
        if(extraLoc8Prices?.Annual > 0) {
            extraOptionsHTML += `<option value="ExtraAnnual" data-extraplanvalue="${ extraLoc8Prices?.Annual }">Extend Plan by 1 year - ${ extraLoc8Prices?.Annual } $</option>`;
        }
        if(extraLoc8Prices?.Years2 > 0) {
            extraOptionsHTML += `<option value="ExtraYears2" data-extraplanvalue="${ extraLoc8Prices?.Years2 }">Extend Plan by 2 years - ${ extraLoc8Prices?.Years2 } $</option>`;
        }
        if(extraLoc8Prices?.Years3 > 0) {
            extraOptionsHTML += `<option value="ExtraYears3" data-extraplanvalue="${ extraLoc8Prices?.Years3 }">Extend Plan by 3 years - ${ extraLoc8Prices?.Years3 } $</option>`;
        }
        if(extraLoc8Prices?.Years4 > 0) {
            extraOptionsHTML += `<option value="ExtraYears4" data-extraplanvalue="${ extraLoc8Prices?.Years4 }">Extend Plan by 4 years - ${ extraLoc8Prices?.Years4 } $</option>`;
        }/*
		if(DealerTokenUrl == '95b6e884-2943-4027-9d92-512c8a626f0e') {
        	extraOptionsHTML += `<option value="ExtraYears4" data-extraplanvalue="145">Extend Plan by 4 years</option>`;
		}*/
   }else if (solutionCode.toLowerCase()?.indexOf('qprotect') != -1) { 
		let extraQProtectPrices = data.ExtraPrices?.find(el=>el.Solution=='QPROTECT')
        
    	if(extraQProtectPrices?.Annual > 0) {
        	extraOptionsHTML += `<option value="ExtraAnnual" data-extraplanvalue="${ extraQProtectPrices?.Annual }">Extend Plan by 1 year - ${ extraQProtectPrices?.Annual } $</option>`;
		}
  		if(extraQProtectPrices?.Years2 > 0) {
        	extraOptionsHTML += `<option value="ExtraYears2" data-extraplanvalue="${ extraQProtectPrices?.Years2 }">Extend Plan by 2 years - ${ extraQProtectPrices?.Years2 } $</option>`;
		}
		if(extraQProtectPrices?.Years3 > 0) {
        	extraOptionsHTML += `<option value="ExtraYears3" data-extraplanvalue="${ extraQProtectPrices?.Years3 }">Extend Plan by 3 years - ${ extraQProtectPrices?.Years3 } $</option>`;
		}
		if(extraQProtectPrices?.Years4 > 0) {
        	extraOptionsHTML += `<option value="ExtraYears4" data-extraplanvalue="${ extraQProtectPrices?.Years4 }">Extend Plan by 4 years - ${ extraQProtectPrices?.Years4 } $</option>`;
		}
   }
		
    if(data.ExtraPricesConfig?.ExtraWarranty > 0) {
        extraWarrantyOptionsHTML += `<option value="addAnnualWarranty"  data-extrawarrantyvalue="${data.ExtraPricesConfig?.ExtraWarranty}" >Add additional year of warranty  $ ${data.ExtraPricesConfig?.ExtraWarranty}</option>`;
	}	
	//Client=2,Dealers=4,Agents=8 if((IsExtraPlan & 2)>0){ it means clients enable  
	//ExtraPayment 0=None,1=Stripe,2=Agent
	
	$('#extraPaymentMethod').val(data.ExtraPricesConfig?.PaymentMethod);
	$('#operator').val(operator);

	if((data.ExtraPricesConfig?.IsExtraPlans & operator) > 0) {
		//if(extendedServicePlanSelect.is(':disabled')) { 
   		 extendedServicePlanSelect.prop('disabled',false);
   		 extendedServicePlanSelect.html(extraOptionsHTML);
   		 extendedServicePlanSelect.selectpicker('refresh');
    	//}
    }
	if((data.ExtraPricesConfig?.IsExtraWarranty & operator) > 0) {
		//if(extendedWarrantySelect.is(':disabled')) { 
  		  extendedWarrantySelect.prop('disabled',false);
   	      extendedWarrantySelect.html(extraWarrantyOptionsHTML);
  		  extendedWarrantySelect.selectpicker('refresh');
    	//}
    }
	setExtraAgent(solutionCode);
}



function setServicePlans(data, solutionCode){
    var serviceSelect = $('#servicePlan');
    var selectedOption = GetURLParameter('ServiceProfile');
    var deviceTypeInput = $('#deviceType');
    var solutionSelect = $('#solution');
    var imeiInput = $('#imei');


console.log('extra',data, solutionCode)
setExtraServicePlans(data, solutionCode)

/*~~extra plan
  var extraOptionsHTML = '';
  var extraWarrantyOptionsHTML = '';
  var extendedServicePlanSelect = $('#extendedServicePlan');
  var extendedWarrantySelect = $('#extendedServiceWarranty'); 
  	
  if (solutionCode.toLowerCase()?.indexOf('track') != -1) { 
		let extraTrackPrices = data.ExtraPrices?.find(el=>el.Solution=='TRACK')
    	if(extraTrackPrices?.Annual > 0) {
        	extraOptionsHTML += `<option value="ExtraAnnual" data-extraplanvalue="${ extraTrackPrices?.Annual }">Extend Plan by 1 year - ${ extraTrackPrices?.Annual } $</option>`;
		}
  		if(extraTrackPrices?.Years2 > 0) {
        	extraOptionsHTML += `<option value="ExtraYears2" data-extraplanvalue="${ extraTrackPrices?.Years2 }">Extend Plan by 2 years - ${ extraTrackPrices?.Years2 } $</option>`;
		}
		if(extraTrackPrices?.Years3 > 0) {
        	extraOptionsHTML += `<option value="ExtraYears3" data-extraplanvalue="${ extraTrackPrices?.Years3 }">Extend Plan by 3 years - ${ extraTrackPrices?.Years3 } $</option>`;
		}
   }else  if (solutionCode.toLowerCase()?.indexOf('loc8') != -1) { 
        let extraLoc8Prices = data.ExtraPrices?.find(el=>el.Solution=='LOC8')
        if(extraLoc8Prices?.Annual > 0) {
            extraOptionsHTML += `<option value="ExtraAnnual" data-extraplanvalue="${ extraLoc8Prices?.Annual }">Extend Plan by 1 year - ${ extraLoc8Prices?.Annual } $</option>`;
        }
        if(extraLoc8Prices?.Years2 > 0) {
            extraOptionsHTML += `<option value="ExtraYears2" data-extraplanvalue="${ extraLoc8Prices?.Years2 }">Extend Plan by 2 years - ${ extraLoc8Prices?.Years2 } $</option>`;
        }
        if(extraLoc8Prices?.Years3 > 0) {
            extraOptionsHTML += `<option value="ExtraYears3" data-extraplanvalue="${ extraLoc8Prices?.Years3 }">Extend Plan by 3 years - ${ extraLoc8Prices?.Years3 } $</option>`;
        }
   }else if (solutionCode.toLowerCase()?.indexOf('qprotect') != -1) { 
		let extraQProtectPrices = data.ExtraPrices?.find(el=>el.Solution=='QPROTECT')
        
    	if(extraQProtectPrices?.Annual > 0) {
        	extraOptionsHTML += `<option value="ExtraAnnual" data-extraplanvalue="${ extraQProtectPrices?.Annual }">Extend Plan by 1 year - ${ extraQProtectPrices?.Annual } $</option>`;
		}
  		if(extraQProtectPrices?.Years2 > 0) {
        	extraOptionsHTML += `<option value="ExtraYears2" data-extraplanvalue="${ extraQProtectPrices?.Years2 }">Extend Plan by 2 years - ${ extraQProtectPrices?.Years2 } $</option>`;
		}
		if(extraQProtectPrices?.Years3 > 0) {
        	extraOptionsHTML += `<option value="ExtraYears3" data-extraplanvalue="${ extraQProtectPrices?.Years3 }">Extend Plan by 3 years - ${ extraQProtectPrices?.Years3 } $</option>`;
		}
   }
		
    if(data.ExtraPricesConfig?.ExtraWarranty > 0) {
        extraWarrantyOptionsHTML += `<option value="addAnnualWarranty"  data-extrawarrantyvalue="${data.ExtraPricesConfig?.ExtraWarranty}" >Add additional year of warranty  $ ${data.ExtraPricesConfig?.ExtraWarranty}</option>`;
	}	
	//Client=2,Dealers=4,Agents=8 if((IsExtraPlan & 2)>0){ it means clients enable  
	//ExtraPayment 0=None,1=Stripe,2=Agent
	
	$('#extraPaymentMethod').val(data.ExtraPricesConfig?.PaymentMethod);
	$('#operator').val(operator);

	if((data.ExtraPricesConfig?.IsExtraPlans & operator) > 0) {
		//if(extendedServicePlanSelect.is(':disabled')) { 
   		 extendedServicePlanSelect.prop('disabled',false);
   		 extendedServicePlanSelect.html(extraOptionsHTML);
   		 extendedServicePlanSelect.selectpicker('refresh');
    	//}
    }
	if((data.ExtraPricesConfig?.IsExtraWarranty & operator) > 0) {
		//if(extendedWarrantySelect.is(':disabled')) { 
  		  extendedWarrantySelect.prop('disabled',false);
   	      extendedWarrantySelect.html(extraWarrantyOptionsHTML);
  		  extendedWarrantySelect.selectpicker('refresh');
    	//}
    }

		

end extra plan*/




    if (data && data.ServiceProfiles && data.ServiceProfiles.length > 0) {
        if (serviceSelect.is(':disabled')) {
            serviceSelect.prop('disabled',false);
                serviceSelect.selectpicker('refresh');
        }
        if (solutionSelect.is(':disabled')) {
            solutionSelect.prop('disabled',false);
                solutionSelect.selectpicker('refresh');
        }
        var optionsHTML = '';
        var planType = 0;
        var activationForm = serviceSelect.closest('form');
        var planPrice = '';
        var iridiumServicePlans = ["2e929111-26a2-4c31-95cd-17d070542946"];

        $.each(data.ServiceProfiles, function(key, val){
                planType = getPlanType(val.Code);
                planPrice = getPlanPrice(val.Code, solutionSelect.val());
                if(planPrice && planPrice.id){
                    if(solutionSelect.val() !== 'WiTiTrack'
                        || deviceTypeInput.val() && deviceTypeInput.val().toLowerCase().indexOf("iridium") === -1 && iridiumServicePlans.indexOf(val.Code) === -1
                        || deviceTypeInput.val() && deviceTypeInput.val().toLowerCase().indexOf("iridium") !== -1 && iridiumServicePlans.indexOf(val.Code) >= 0
                    ){

                        //
                        optionsHTML += `<option value="${ val.Code }" data-plantype="${ planType }" data-priceid="${ planPrice.id }">${ val.Name } ${ !planPrice ? '' : ' - ' + planPrice.val  }</option>`;
                    }

                }

        });

		//iridium condition
		if(deviceTypeInput.val() && deviceTypeInput.val().toLowerCase().indexOf("iridium") !== -1){
			optionsHTML = `<option value="2e929111-26a2-4c31-95cd-17d070542946" data-plantype="3" data-priceid="price_1PprEmLhZvibZX5g8y2p8ffV">Monthly $55 inc GST</option>`;
            
        }

        serviceSelect.html(optionsHTML);
        serviceSelect.selectpicker('refresh');


        if (selectedOption && serviceSelect.find('option[value="' + selectedOption + '"]').length > 0) {
            serviceSelect.selectpicker('val', selectedOption);
        }else if(deviceTypeInput.val() && deviceTypeInput.val().toLowerCase().indexOf("iridium") !== -1 && serviceSelect.find('option[value="' + iridiumServicePlans[0] + '"]').length > 0){
                serviceSelect.selectpicker('val', iridiumServicePlans[0]);
            }else{
                serviceSelect.selectpicker('val', '5f87b4fc-d25b-4');
            }


			if (data.ServiceProfiles.findIndex(el => el.Code == curPlan) != -1) { 
    			serviceSelect.selectpicker('val', curPlan);
    		}
			
		if(curPlan=='2e0ebf88-5375-4497-8afb-bfd8624cc2aa'){ //annualtrackincluded
			optionsHTML = `<option value="2e0ebf88-5375-4497-8afb-bfd8624cc2aa" data-plantype="3" data-priceid="price_1O7dbBLhZvibZX5gk3wADq5h">Annual Service Included</option>`;
          	serviceSelect.html(optionsHTML);
        	serviceSelect.selectpicker('refresh');
			serviceSelect.selectpicker('val', '2e0ebf88-5375-4497-8afb-bfd8624cc2aa');
		}

        if (imeiInput.data('binded-plan-code')) {
            selectedOption = imeiInput.data('binded-plan-code');
        
            serviceSelect.selectpicker('val', selectedOption).prop('disabled',true).selectpicker('refresh');
            solutionSelect.prop('disabled',true).selectpicker('refresh');
        }


    }
}

function setSolutionTypes(data){
    var solutionSelect = $('#solution');
    //var serviceSelect = $('#servicePlan');
    var imeiInput = $('#imei');
    var selectedOption = GetURLParameter('SolutionType');
    var urlServProf = GetURLParameter('ServiceProfile');
        var $form = $('form');
    var deviceTypeInput = $('#deviceType');

    if (data && data.Solutions && data.Solutions.length > 0) {
        if (solutionSelect.is(':disabled')) {
            solutionSelect.prop('disabled',false);
                solutionSelect.selectpicker('refresh');
        }

        var optionsHTML = '';
        var planType = 0;

        $.each(data.Solutions, function(key, val){

                if (val.Code === 'QProtect' || val.Code === 'Track'|| val.Code === 'AnnualTrackIncluded' || val.Code === 'Loc8' || val.Code === 'Watch') {
                    optionsHTML += '<option value="' + val.Code + '" data-features="' + val.Features + '" >' + val.Name + '</option>';
                }

        });
    //iridium condition
		if(deviceTypeInput.val() && deviceTypeInput.val().toLowerCase().indexOf("iridium") !== -1){
        	optionsHTML = '<option value="Track" data-features="" >Iridium Track</option>';
        }
       
        solutionSelect.html(optionsHTML);
        solutionSelect.selectpicker('refresh');

            if (solutionSelect.find('option').length <= 2) {
                solutionSelect.selectpicker('val', solutionSelect.find('option')[solutionSelect.find('option').length-1].value);
            } else if(selectedOption === 'QProtect' || selectedOption === 'Protect' || selectedOption === 'WiTiProtect' || selectedOption === 'WiTiQProtect' || urlServProf === 'QProtect' || urlServProf === 'Protect' || urlServProf === 'WiTiProtect' || urlServProf === 'WiTiQProtect'){
                solutionSelect.selectpicker('val', 'QProtect');
            } else if(selectedOption === 'Track' || selectedOption === 'WiTiTrack'){
                solutionSelect.selectpicker('val', 'Track');
			} else if(selectedOption === 'AnnualTrackIncluded'){
                solutionSelect.selectpicker('val', 'AnnualTrackIncluded');
			} else if(selectedOption === 'Loc8' || selectedOption === 'WitiLoc8'){
                solutionSelect.selectpicker('val', 'Loc8');
			} else if($form.hasClass('form-upgrade')){
                solutionSelect.selectpicker('val', 'Watch');
            }
			
			if (data.Solutions.findIndex(el => el.Code == curSolution) != -1) { 
    			solutionSelect.selectpicker('val', curSolution);
    		}

    
		//iridium condition
		if(deviceTypeInput.val() && deviceTypeInput.val().toLowerCase().indexOf("iridium") !== -1){
        	solutionSelect.selectpicker('val', 'Track');
        }


        if (imeiInput.data('binded-solution-code')) {
            selectedOption = imeiInput.data('binded-solution-code');
            solutionSelect.selectpicker('val', selectedOption).prop('disabled',true).selectpicker('refresh');
        }
    }
}

function setFitmentOptions(selected, preset = 0){
    var fitoptionsSelect = $('#fitoptions');
    var optionsHTML = '';
    var optionsArry = [];

    if (selected && selected.toLowerCase() == 'boatwatch' || selected && selected.toLowerCase() == 'boatloc8' ||
        selected && selected.toLowerCase() == 'boat' || selected && selected.toLowerCase() == 'jetski') {
        optionsArry = [
            { Code: '128',	Name: 'Bilge Alarm', },
            { Code: '32',	Name: 'Engine Theft', },
            { Code: '1',	Name: 'Remote Immobilisation', },
            { Code: '256',	Name: 'Shore Power Disconnect', },
            { Code: '64',	Name: 'Siren', },
        ];
    }else{
            optionsArry = [
                { Code: '2',	Name: 'Alarm Integration' },//, Selected: true
                { Code: '16',	Name: 'Fitment After Isolator', },
                { Code: '8',	Name: 'Not Connected to Ignition / Accessory Power', },
                { Code: '512',	Name: 'Remote Door', },
                { Code: '1',	Name: 'Remote Immobilisation', },
            ];
    }

	if(preset){
		optionsArry = [];

		if((preset & FITMENTOPTIONS.RemoteImmob) > 0){
        	optionsArry.push({ Code: '1',	Name: 'Remote Immobilisation', Selected: true})
		}else{
        	optionsArry.push({ Code: '1',	Name: 'Remote Immobilisation', Selected: false})
        }
		if((preset & FITMENTOPTIONS.ShorePowerDisconn) > 0){
        	optionsArry.push({ Code: '256',	Name: 'Shore Power Disconnect', Selected: true})
		}else{
        	optionsArry.push({ Code: '256',	Name: 'Shore Power Disconnect', Selected: false})
        }
		if((preset & FITMENTOPTIONS.AlarmIntegration) > 0){
        	optionsArry.push({ Code: '2',	Name: 'Alarm Integration', Selected: true})
		}else{
        	optionsArry.push({ Code: '2',	Name: 'Alarm Integration', Selected: false})
        }
		if((preset & FITMENTOPTIONS.BilgeAlarm) > 0){
        	optionsArry.push({ Code: '128',	Name: 'Bilge Alarm', Selected: true})
		}else{
        	optionsArry.push({ Code: '128',	Name: 'Bilge Alarm', Selected: false})
        }
		if((preset & FITMENTOPTIONS.EngineTheft) > 0){
        	optionsArry.push({ Code: '32',	Name: 'Engine Theft', Selected: true})
		}else{
        	optionsArry.push({ Code: '32',	Name: 'Engine Theft', Selected: false})
        }
		if((preset & FITMENTOPTIONS.SOSButton) > 0){
        	optionsArry.push({ Code: '4',	Name: 'SOS Button', Selected: true})
		}else{
        	optionsArry.push({ Code: '4',	Name: 'SOS Button', Selected: false})
        }
		if((preset & FITMENTOPTIONS.NotConnectedIgn) > 0){
        	optionsArry.push({ Code: '8',	Name: 'Not Connected to Ignition / Accessory Power', Selected: true})
		}else{
        	optionsArry.push({ Code: '8',	Name: 'Not Connected to Ignition / Accessory Power', Selected: false})
        }
		if((preset & FITMENTOPTIONS.FitmentAfterIsolater) > 0){
        	optionsArry.push({ Code: '16',	Name: 'Fitment After Isolator', Selected: true})
		}else{
        	optionsArry.push({ Code: '16',	Name: 'Fitment After Isolator', Selected: false})
        }
		if((preset & FITMENTOPTIONS.Siren) > 0){
        	optionsArry.push({ Code: '64',	Name: 'Siren', Selected: true})
		}else{
        	optionsArry.push({ Code: '64',	Name: 'Siren', Selected: false})
        }
		if((preset & FITMENTOPTIONS.RemoteDoor) > 0){
        	optionsArry.push({ Code: '512',	Name: 'Remote Door', Selected: true})
		}else{
        	optionsArry.push({ Code: '512',	Name: 'Remote Door', Selected: false})
        }
	}

    $.each(optionsArry, function(key, val){
            optionsHTML += `<option value="${ val.Code }" ${ val.Selected ? 'selected' : '' }>${ val.Name }</option>`;
    });

    if (fitoptionsSelect) {
        fitoptionsSelect.html(optionsHTML);
        if (fitoptionsSelect.is(':disabled')) {
            fitoptionsSelect.prop('disabled',false);
        }
		
		let fitmentValue = fitoptionsSelect.val();
		var $elInputConfigurationSection = $('.input-configuration-section')
	
		if(fitmentValue && fitmentValue.includes(FITMENTOPTIONS.AlarmIntegration)){
			$('input[name=isDeviceInputsConnected][value=yes]').prop('checked', true);
			$elInputConfigurationSection.show()
		}else{
			$('input[name=isDeviceInputsConnected][value=no]').prop('checked', true);
			$elInputConfigurationSection.hide()
		}


		
        fitoptionsSelect.selectpicker('refresh');
    }

}

function getPlanType(code){
    var ret = 0;
        switch(code){
            case '0000000000000':
                ret = 0;
                break;
            case 'QUIKLOC800000':
                ret = 8;
                break;
            case '1C783FA4TRAK':
                ret = 1;
                break;
            case 'LR6Z8YPFC8PHJ':
                ret = 3;
                break;
            case '2Y6Z8YPFC8P2Y':
                ret = 10;
                break;
            case '4Y6Z8YPFC8P4Y':
                ret = 11;
                break;
            case '1C8D3EDEMOTI':
                ret = 2;
                break;
            case '33ENPEYR38SRC':
            case '2e929111-26a2-4c31-95cd-17d070542946':
                ret = 3;
                break;
            case '5f87b4fc-d25b-4':
                ret = 1;
        }
    return ret;
}

function getPlanPrice(servicePlanCode, solutionTypeCode){

    let ret = false;
    if(PRICES[solutionTypeCode] && PRICES[solutionTypeCode][servicePlanCode]){
        ret = PRICES[solutionTypeCode][servicePlanCode]
    }
    return ret
}

function getClientDetailsByIMEI(imei){

    $.ajax({
        type: "POST",
        url: "https://newapi.quiktrak.co/Common/V1/Activation/GetContactInfo",
        dataType: 'json',
        data: {IMEI: [imei]},
        async: true,
        cache: false,
        success: function(result){
            if (result.MajorCode == '000') {
                if (result.Data && result.Data[0]) {
                    //$('[name="firstName"]').val(result.Data[0].FirstName);
                    //$('[name="subName"]').val(result.Data[0].LastName);
                    //$('[name="email"]').val(result.Data[0].Email);

                }
            }
        },
        error: function(XMLHttpRequest, textStatus, errorThrown){
            console.log(XMLHttpRequest);
            console.log(textStatus);
            console.log(errorThrown);
        }
    });
}


$('#solution').on('changed.bs.select', function (e, clickedIndex, newValue, oldValue) {
    var selected = $(e.currentTarget).val();
    var sectionPayment = $('.form_section_payment');
    var autosuspendGroup = $('.groupAutoSuspend');
    var $formUpgrade = $('.form-upgrade');
	
	var solutionTypeFeatures = $(e.currentTarget).find('option:selected').data('features');
		var deviceTypeFeatures = $('#deviceType').data('features');
	var $elInputConfigurationSectionWrapper = $('.input-configuration-section-wrapper')
	var $elIridiumConfigurationSectionWrapper = $('.iridium-configuration-section-wrapper')
	
		var $elPowerSettingsWrapper = $('.power_settings_wrapper')
		let $elColLowerPower = $('.col_lower_power')
		let $elColDisconnectPower = $('.col_disconnect_power')
		let $elColIgnitionPower = $('.col_ignition_power')

    if (selected ) {
       
        /*if (DealerTokenUrl && !fromAppFlagUrl && referral) {
            autosuspendGroup.show();
        }else{
            autosuspendGroup.hide();
        }*/
        sectionPayment.show();
        $('input[name="paymentType"]').attr('required',true);

        getAdditionalData({
            SolutionCode: selected,
            ProductCode: $('#deviceType').data('code'),
            IMEI: $('#imei').val(),
            DealerToken: DealerTokenUrl //DealerTokenUrl ? DealerTokenUrl : $('#dealerToken').val(),
        });
		
						
    }else{
        console.log('there in no Solution selected');
    }
	
	
		$elInputConfigurationSectionWrapper.hide();
		if(solutionTypeFeatures && solutionTypeFeatures.indexOf("IO,") >= 0){ 
			if((deviceTypeFeatures & PRODUCTFEATURES.Input1) > 0
				|| (deviceTypeFeatures & PRODUCTFEATURES.Input2) > 0 )
			{
				$elInputConfigurationSectionWrapper.show();
			}
		}
//
$elIridiumConfigurationSectionWrapper.hide();
		if($('#deviceType').data('code') == '4GQTLTEIridium'){ 
				$elIridiumConfigurationSectionWrapper.show();
		}
//
		
		$elPowerSettingsWrapper.hide();
		if(solutionTypeFeatures && solutionTypeFeatures.indexOf("LOWER_POWER,") >= 0
			|| solutionTypeFeatures && solutionTypeFeatures.indexOf("DISCONNECT_POWER,") >= 0
			|| solutionTypeFeatures && solutionTypeFeatures.indexOf("IGNITION_ON,") >= 0 )
		{
			if((deviceTypeFeatures & PRODUCTFEATURES.Power) > 0){
				$elPowerSettingsWrapper.show();
			}
			if( (deviceTypeFeatures & PRODUCTFEATURES.Power) > 0 && solutionTypeFeatures.indexOf("LOWER_POWER,") >= 0 ){
				$elColLowerPower.show()
			}
			if( (deviceTypeFeatures & PRODUCTFEATURES.Power) > 0 && solutionTypeFeatures.indexOf("DISCONNECT_POWER,") >= 0 ){
				$elColDisconnectPower.show()
			}
			if( (deviceTypeFeatures & PRODUCTFEATURES.Power) > 0 && solutionTypeFeatures.indexOf("IGNITION_ON,") >= 0 ){
				$elColIgnitionPower.show()
			}
		}

});

$("input[name='paymentType']").change(function () {

    var val = $(this).val();
    $('.paymentFieldWrapper').hide();
    $('.byInvoiceWrapper input, .creditCardWrapper input, .bankDirectWrapper input, .byVoucherWrapper input').attr('required',false);

    switch (val){
        case '13':
            $('#mandate-acceptance').show();   
            break;
        case '12':
            $('.creditCardStripeWrapper').show();
            $('.creditCardStripeWrapper input').attr('required',true);
            break;
        case '1':
            $('.creditCardWrapper').show();
            $('.creditCardWrapper input').attr('required',true);
            break;
        case '2':
            $('.bankDirectWrapper').show();
            $('.bankDirectWrapper input').attr('required',true);
            break;

        case '3':
            var form = $(this).closest('form');
            if (form && form.attr('id')) {
                if (form.attr('id') == 'form-upgrade') {
                    $('.byInvoiceWrapper input[name="invoiceName"]').attr('required',true);
                }else if (form.attr('id') == 'form-register' || form.attr('id') == 'form-activate') {
                    $('.byInvoiceWrapper input[name="invoiceName"], .byInvoiceWrapper input[name="invoiceEmail"]').attr('required',true);
                }else{
                    $('.byInvoiceWrapper input').attr('required',true);
                }
            }else{
                $('.byInvoiceWrapper input').attr('required',true);
            }
            $('.byInvoiceWrapper').show();

            break;

        case '4':
            $('.byVoucherWrapper').show();
            $('.byVoucherWrapper input').attr('required',true);
            break;
    }
});

//var savedImei = $('#imei').val();
$('#imei').data('prev-imei', $('#imei').val() );
$('#imei').on('blur', function(){
    $(this).val( $(this).val().padStart(16,0) );
    if ( $(this).data('prev-imei') != this.value ) {
        $(this).data('prev-imei', this.value) ;
        getDefaultParams(this.value, DealerTokenUrl);
    }
});

$('#imei').on('input', function(){
    if (this.value.length == 16 && $(this).data('prev-imei') != this.value ) {
        $(this).data('prev-imei', this.value) ;
        getDefaultParams(this.value, DealerTokenUrl);
    }
});

$('#account').on('input', function(){
    if (this.value.length > 2) {
        //$(this).data('prev-imei', this.value) ;
        //getDefaultParams(this.value, DealerTokenUrl);
        newEmail(this.value)
    }
});


	$('[name="isDeviceInputsConnected"]').on('change', function (){
		var $elInputConfigurationSection = $('.input-configuration-section')
		if(this.value === 'yes'){
			$elInputConfigurationSection.show()
		}else{
			$elInputConfigurationSection.hide()
		}
	});



$('[name="fitoptions"]').on('change', function (){
		let fitmentValue = $('#fitoptions').val();
		var $elInputConfigurationSection = $('.input-configuration-section')
		/*if(fitmentValue && fitmentValue.includes(FITMENTOPTIONS.NotConnectedIgn)){
			$('input[name=isConnectedToIgnition][value=no]').prop('checked', true);
		}else{
			$('input[name=isConnectedToIgnition][value=yes]').prop('checked', true);
		}
		*/
		if(fitmentValue && fitmentValue.includes(FITMENTOPTIONS.AlarmIntegration)){
			$('input[name=isDeviceInputsConnected][value=yes]').prop('checked', true);
			$elInputConfigurationSection.show()
		}else{
			$('input[name=isDeviceInputsConnected][value=no]').prop('checked', true);
			$elInputConfigurationSection.hide()
		}
	});


/*new email*/


        
/*new email*/

var assetTypeIconWrapperEl = $('.asset-type-icon-wrapper');
assetTypeIconWrapperEl.on('click', function(){
    var that = $(this);
    var type = that.data('type');

    assetTypeIconWrapperEl.removeClass('active');
    that.addClass('active');
    $('input[name="assetType"]').val(that.data("type"));

    setFitmentOptions(type);
});


$('body').on('change keyup input click', '.only_numbers', function() {
    if (this.value.match(/[^0-9]/g)) {
        this.value = this.value.replace(/[^0-9]/g, '');
    }
});
$('body').on('change keyup input click', '.only_numbers_and_negative', function() {
    if (this.value.match(/[^0-9-]/g)) {
        this.value = this.value.replace(/[^0-9-]/g, '');
    }
});




$(function() {

    $('#country').on('change', function(){
        var selected = $(this).val();
        switch (selected) {
            case 'ABW':	$("#phoneCode").val('+297'); 	break;
            case 'AFG': $("#phoneCode").val('+93'); 	break;
            case 'AGO':	$("#phoneCode").val('+244'); 	break;
            case 'AIA':	$("#phoneCode").val('+1'); 		break;
            case 'ALB': $("#phoneCode").val('+355'); 	break;
            case 'AND':	$("#phoneCode").val('+376'); 	break;
            case 'ANT':	$("#phoneCode").val('+376'); 	break;
            case 'ARE':	$("#phoneCode").val('+971'); 	break;
            case 'ARG':	$("#phoneCode").val('+54'); 	break;
            case 'ARM':	$("#phoneCode").val('+374'); 	break;
            case 'ASM':	$("#phoneCode").val('+1'); 		break;
            case 'ATA':	$("#phoneCode").val('+1'); 		break;
            case 'ATF':	$("#phoneCode").val('+1'); 		break;
            case 'ATG':	$("#phoneCode").val('+1'); 		break;
            case 'AUS':	$("#phoneCode").val('+61'); 	break;
            case 'AUT':	$("#phoneCode").val('+43'); 	break;
            case 'AZE':	$("#phoneCode").val('+994'); 	break;
            case 'BDI':	$("#phoneCode").val('+257'); 	break;
            case 'BEL':	$("#phoneCode").val('+32'); 	break;
            case 'BEN':	$("#phoneCode").val('+229'); 	break;
            case 'BFA':	$("#phoneCode").val('+226'); 	break;
            case 'BGD':	$("#phoneCode").val('+880'); 	break;
            case 'BGR':	$("#phoneCode").val('+359'); 	break;
            case 'BHR':	$("#phoneCode").val('+973'); 	break;
            case 'BHS':	$("#phoneCode").val('+1'); 		break;
            case 'BIH':	$("#phoneCode").val('+387'); 	break;
            case 'BLR':	$("#phoneCode").val('+375'); 	break;
            case 'BLZ':	$("#phoneCode").val('+501'); 	break;
            case 'BMU':	$("#phoneCode").val('+1'); 		break;
            case 'BOL':	$("#phoneCode").val('+591'); 	break;
            case 'BRA':	$("#phoneCode").val('+55'); 	break;
            case 'BRB':	$("#phoneCode").val('+1'); 		break;
            case 'BRN':	$("#phoneCode").val('+673'); 	break;
            case 'BTN':	$("#phoneCode").val('+975'); 	break;
            case 'BVT':	$("#phoneCode").val('+975'); 	break;
            case 'BWA':	$("#phoneCode").val('+267'); 	break;
            case 'CAF':	$("#phoneCode").val('+236'); 	break;
            case 'CAN':	$("#phoneCode").val('+1'); 		break;
            case 'CCK':	$("#phoneCode").val('+1'); 		break;
            case 'CHE':	$("#phoneCode").val('+41'); 	break;
            case 'CHL':	$("#phoneCode").val('+56'); 	break;
            case 'CHN':	$("#phoneCode").val('+86'); 	break;
            case 'CIV':	$("#phoneCode").val('+225'); 	break;
            case 'CMR':	$("#phoneCode").val('+237'); 	break;
            case 'COD':	$("#phoneCode").val('+242'); 	break;
            case 'COG':	$("#phoneCode").val('+243'); 	break;
            case 'COK':	$("#phoneCode").val('+682'); 	break;
            case 'COL':	$("#phoneCode").val('+57'); 	break;
            case 'COM':	$("#phoneCode").val('+269'); 	break;
            case 'CPV':	$("#phoneCode").val('+238'); 	break;
            case 'CRI':	$("#phoneCode").val('+506'); 	break;
            case 'CUB':	$("#phoneCode").val('+53'); 	break;
            case 'CXR':	$("#phoneCode").val('+1'); 		break;
            case 'CYM':	$("#phoneCode").val('+1'); 		break;
            case 'CYP':	$("#phoneCode").val('+357'); 	break;
            case 'CZE':	$("#phoneCode").val('+420'); 	break;
            case 'DEU':	$("#phoneCode").val('+49'); 	break;
            case 'DJI':	$("#phoneCode").val('+253'); 	break;
            case 'DMA':	$("#phoneCode").val('+1'); 		break;
            case 'DNK':	$("#phoneCode").val('+45'); 	break;
            case 'DOM':	$("#phoneCode").val('+1'); 		break;
            case 'DZA':	$("#phoneCode").val('+213'); 	break;
            case 'ECU':	$("#phoneCode").val('+593'); 	break;
            case 'EGY':	$("#phoneCode").val('+20'); 	break;
            case 'ERI':	$("#phoneCode").val('+291'); 	break;
            case 'ESH':	$("#phoneCode").val('+212'); 	break;
            case 'ESP':	$("#phoneCode").val('+34'); 	break;
            case 'EST':	$("#phoneCode").val('+372'); 	break;
            case 'ETH':	$("#phoneCode").val('+251'); 	break;
            case 'FIN':	$("#phoneCode").val('+358'); 	break;
            case 'FJI':	$("#phoneCode").val('+679'); 	break;
            case 'FLK':	$("#phoneCode").val('+500'); 	break;
            case 'FRA':	$("#phoneCode").val('+33'); 	break;
            case 'FRO':	$("#phoneCode").val('+298'); 	break;
            case 'FSM':	$("#phoneCode").val('+691'); 	break;
            case 'GAB':	$("#phoneCode").val('+241'); 	break;
            case 'GBR':	$("#phoneCode").val('+44'); 	break;
            case 'GEO':	$("#phoneCode").val('+995'); 	break;
            case 'GHA':	$("#phoneCode").val('+233'); 	break;
            case 'GIB':	$("#phoneCode").val('+350'); 	break;
            case 'GIN':	$("#phoneCode").val('+224'); 	break;
            case 'GLP':	$("#phoneCode").val('+590'); 	break;
            case 'GMB':	$("#phoneCode").val('+220'); 	break;
            case 'GNB':	$("#phoneCode").val('+245'); 	break;
            case 'GNQ':	$("#phoneCode").val('+240'); 	break;
            case 'GRC':	$("#phoneCode").val('+30'); 	break;
            case 'GRD':	$("#phoneCode").val('+1'); 		break;
            case 'GRL':	$("#phoneCode").val('+299'); 	break;
            case 'GTM':	$("#phoneCode").val('+502'); 	break;
            case 'GUF':	$("#phoneCode").val('+594'); 	break;
            case 'GUM':	$("#phoneCode").val('+1'); 		break;
            case 'GUY':	$("#phoneCode").val('+592'); 	break;
            case 'HKG':	$("#phoneCode").val('+852'); 	break;
            case 'HMD':	$("#phoneCode").val('+592'); 	break;
            case 'HND':	$("#phoneCode").val('+504'); 	break;
            case 'HRV':	$("#phoneCode").val('+385'); 	break;
            case 'HTI':	$("#phoneCode").val('+509'); 	break;
            case 'HUN':	$("#phoneCode").val('+36'); 	break;
            case 'IDN':	$("#phoneCode").val('+62'); 	break;
            case 'IND':	$("#phoneCode").val('+91'); 	break;
            case 'IOT':	$("#phoneCode").val('+246'); 	break;
            case 'IRL':	$("#phoneCode").val('+353'); 	break;
            case 'IRN':	$("#phoneCode").val('+98'); 	break;
            case 'IRQ':	$("#phoneCode").val('+964'); 	break;
            case 'ISL':	$("#phoneCode").val('+354'); 	break;
            case 'ISR':	$("#phoneCode").val('+972'); 	break;
            case 'ITA':	$("#phoneCode").val('+39'); 	break;
            case 'JAM':	$("#phoneCode").val('+1'); 		break;
            case 'JOR':	$("#phoneCode").val('+962'); 	break;
            case 'JPN':	$("#phoneCode").val('+81'); 	break;
            case 'KAZ':	$("#phoneCode").val('+7'); 		break;
            case 'KEN':	$("#phoneCode").val('+254'); 	break;
            case 'KGZ':	$("#phoneCode").val('+996'); 	break;
            case 'KHM':	$("#phoneCode").val('+855'); 	break;
            case 'KIR':	$("#phoneCode").val('+686'); 	break;
            case 'KNA':	$("#phoneCode").val('+1'); 		break;
            case 'KOR':	$("#phoneCode").val('+850'); 	break;
            case 'KWT':	$("#phoneCode").val('+965'); 	break;
            case 'LAO':	$("#phoneCode").val('+965'); 	break;
            case 'LBN':	$("#phoneCode").val('+961'); 	break;
            case 'LBR':	$("#phoneCode").val('+231'); 	break;
            case 'LBY':	$("#phoneCode").val('+218'); 	break;
            case 'LCA':	$("#phoneCode").val('+1'); 		break;
            case 'LIE':	$("#phoneCode").val('+423'); 	break;
            case 'LKA':	$("#phoneCode").val('+94'); 	break;
            case 'LSO':	$("#phoneCode").val('+266'); 	break;
            case 'LTU':	$("#phoneCode").val('+370'); 	break;
            case 'LUX':	$("#phoneCode").val('+352'); 	break;
            case 'LVA':	$("#phoneCode").val('+371'); 	break;
            case 'MAC':	$("#phoneCode").val('+853'); 	break;
            case 'MAR':	$("#phoneCode").val('+212'); 	break;
            case 'MCO':	$("#phoneCode").val('+377'); 	break;
            case 'MDA':	$("#phoneCode").val('+373'); 	break;
            case 'MDG':	$("#phoneCode").val('+261'); 	break;
            case 'MDV':	$("#phoneCode").val('+960'); 	break;
            case 'MEX':	$("#phoneCode").val('+52'); 	break;
            case 'MHL':	$("#phoneCode").val('+692'); 	break;
            case 'MKD':	$("#phoneCode").val('+389'); 	break;
            case 'MLI':	$("#phoneCode").val('+223'); 	break;
            case 'MLT':	$("#phoneCode").val('+356'); 	break;
            case 'MMR':	$("#phoneCode").val('+95'); 	break;
            case 'MNG':	$("#phoneCode").val('+976'); 	break;
            case 'MNP':	$("#phoneCode").val('+1'); 		break;
            case 'MOZ':	$("#phoneCode").val('+258'); 	break;
            case 'MRT':	$("#phoneCode").val('+222'); 	break;
            case 'MSR':	$("#phoneCode").val('+1'); 		break;
            case 'MTQ':	$("#phoneCode").val('+596'); 	break;
            case 'MUS':	$("#phoneCode").val('+230'); 	break;
            case 'MWI':	$("#phoneCode").val('+265'); 	break;
            case 'MYS':	$("#phoneCode").val('+60'); 	break;
            case 'MYT':	$("#phoneCode").val('+262'); 	break;
            case 'NAM':	$("#phoneCode").val('+264'); 	break;
            case 'NCL':	$("#phoneCode").val('+687'); 	break;
            case 'NER':	$("#phoneCode").val('+227'); 	break;
            case 'NFK':	$("#phoneCode").val('+672'); 	break;
            case 'NGA':	$("#phoneCode").val('+234'); 	break;
            case 'NIC':	$("#phoneCode").val('+505'); 	break;
            case 'NIU':	$("#phoneCode").val('+683'); 	break;
            case 'NLD':	$("#phoneCode").val('+31'); 	break;
            case 'NOR':	$("#phoneCode").val('+47'); 	break;
            case 'NPL':	$("#phoneCode").val('+977'); 	break;
            case 'NRU':	$("#phoneCode").val('+674'); 	break;
            case 'NZL':	$("#phoneCode").val('+64'); 	break;
            case 'OMN':	$("#phoneCode").val('+968'); 	break;
            case 'PAK':	$("#phoneCode").val('+92'); 	break;
            case 'PAN':	$("#phoneCode").val('+507'); 	break;
            case 'PCN':	$("#phoneCode").val('+507'); 	break;
            case 'PER':	$("#phoneCode").val('+51'); 	break;
            case 'PHL':	$("#phoneCode").val('+63'); 	break;
            case 'PLW':	$("#phoneCode").val('+680'); 	break;
            case 'PNG':	$("#phoneCode").val('+675'); 	break;
            case 'POL':	$("#phoneCode").val('+48'); 	break;
            case 'PRI':	$("#phoneCode").val('+1'); 		break;
            case 'PRK':	$("#phoneCode").val('+82'); 	break;
            case 'PRT':	$("#phoneCode").val('+351'); 	break;
            case 'PRY':	$("#phoneCode").val('+595'); 	break;
            case 'PSE':	$("#phoneCode").val('+970'); 	break;
            case 'PYF':	$("#phoneCode").val('+689'); 	break;
            case 'QAT':	$("#phoneCode").val('+974'); 	break;
            case 'REU':	$("#phoneCode").val('+262'); 	break;
            case 'ROM':	$("#phoneCode").val('+40'); 	break;
            case 'RUS':	$("#phoneCode").val('+7'); 		break;
            case 'RWA':	$("#phoneCode").val('+250'); 	break;
            case 'SAU':	$("#phoneCode").val('+966'); 	break;
            case 'SDN':	$("#phoneCode").val('+249'); 	break;
            case 'SEN':	$("#phoneCode").val('+221'); 	break;
            case 'SGP':	$("#phoneCode").val('+65'); 	break;
            case 'SGS':	$("#phoneCode").val('+65'); 	break;
            case 'SHN':	$("#phoneCode").val('+290'); 	break;
            case 'SJM':	$("#phoneCode").val('+290'); 	break;
            case 'SLB':	$("#phoneCode").val('+677'); 	break;
            case 'SLE':	$("#phoneCode").val('+232'); 	break;
            case 'SLV':	$("#phoneCode").val('+503'); 	break;
            case 'SMR':	$("#phoneCode").val('+378'); 	break;
            case 'SOM':	$("#phoneCode").val('+252'); 	break;
            case 'SPM':	$("#phoneCode").val('+508'); 	break;
            case 'STP':	$("#phoneCode").val('+239'); 	break;
            case 'SUR':	$("#phoneCode").val('+597'); 	break;
            case 'SVK':	$("#phoneCode").val('+421'); 	break;
            case 'SVN':	$("#phoneCode").val('+386'); 	break;
            case 'SWE':	$("#phoneCode").val('+46'); 	break;
            case 'SWZ':	$("#phoneCode").val('+268'); 	break;
            case 'SYC':	$("#phoneCode").val('+248'); 	break;
            case 'SYR':	$("#phoneCode").val('+963'); 	break;
            case 'TCA':	$("#phoneCode").val('+1'); 		break;
            case 'TCD':	$("#phoneCode").val('+235'); 	break;
            case 'TGO':	$("#phoneCode").val('+228'); 	break;
            case 'THA':	$("#phoneCode").val('+66'); 	break;
            case 'TJK':	$("#phoneCode").val('+992'); 	break;
            case 'TKL':	$("#phoneCode").val('+690'); 	break;
            case 'TKM':	$("#phoneCode").val('+993'); 	break;
            case 'TMP':	$("#phoneCode").val('+670'); 	break;
            case 'TON':	$("#phoneCode").val('+676'); 	break;
            case 'TTO':	$("#phoneCode").val('+1'); 		break;
            case 'TUN':	$("#phoneCode").val('+216'); 	break;
            case 'TUR':	$("#phoneCode").val('+90'); 	break;
            case 'TUV':	$("#phoneCode").val('+688'); 	break;
            case 'TWN':	$("#phoneCode").val('+886'); 	break;
            case 'TZA':	$("#phoneCode").val('+255'); 	break;
            case 'UGA':	$("#phoneCode").val('+256'); 	break;
            case 'UKR':	$("#phoneCode").val('+380'); 	break;
            case 'UMI':	$("#phoneCode").val('+380'); 	break;
            case 'UNK':	$("#phoneCode").val('+1'); 		break;
            case 'URY':	$("#phoneCode").val('+598'); 	break;
            case 'USA':	$("#phoneCode").val('+1'); 		break;
            case 'UZB':	$("#phoneCode").val('+998'); 	break;
            case 'VAT':	$("#phoneCode").val('+39'); 	break;
            case 'VCT':	$("#phoneCode").val('+1'); 		break;
            case 'VEN':	$("#phoneCode").val('+58'); 	break;
            case 'VGB':	$("#phoneCode").val('+1'); 		break;
            case 'VIR':	$("#phoneCode").val('+1'); 		break;
            case 'VNM':	$("#phoneCode").val('+84'); 	break;
            case 'VUT':	$("#phoneCode").val('+678'); 	break;
            case 'WLF':	$("#phoneCode").val('+681'); 	break;
            case 'WSM':	$("#phoneCode").val('+685'); 	break;
            case 'YEM':	$("#phoneCode").val('+967'); 	break;
            case 'YUG':	$("#phoneCode").val('+967'); 	break;
            case 'ZAF':	$("#phoneCode").val('+27'); 	break;
            case 'ZMB':	$("#phoneCode").val('+260'); 	break;
            case 'ZWE':	$("#phoneCode").val('+263'); 	break;
        }


    });

});