﻿//This file defines the pricing for all TMarque sites
//Fees are in local currency
//Then converted to relevant currency in the relevant country

//Exchange rates - Interbank rates
var AUD_x_AUD_rate = 1;
var EUR_x_AUD_rate = 1.505117399;  // http://www.google.com/search?q=convert+1+EUR+to+AUD
var USD_x_AUD_rate = 1.254862592;  // http://www.google.com/search?q=convert+1+USD+to+AUD
var NZD_x_AUD_rate = 0.837731423;  // http://www.google.com/search?q=convert+1+NZD+to+AUD
var GBP_x_AUD_rate = 1.827819411;  // http://www.google.com/search?q=convert+1+GBP+to+AUD

//AU Trademark - AUD

AU_tm_app_fee_first_class_rpl = 385.00;
AU_tm_app_fee_first_class_govt = 160.00;
AU_tm_app_fee_extra_class_rpl = 385.00;
AU_tm_app_fee_extra_class_govt = 160.00;

AU_tm_reg_fee_first_class_rpl = 385.00;
AU_tm_reg_fee_first_class_govt = 250.00;
AU_tm_reg_fee_extra_class_rpl = 385.00;
AU_tm_reg_fee_extra_class_govt = 250.00;

AU_tm_app_fee_first_class = AU_tm_app_fee_first_class_rpl + AU_tm_app_fee_first_class_govt;
AU_tm_app_fee_extra_class = AU_tm_app_fee_extra_class_rpl + AU_tm_app_fee_extra_class_govt;
AU_tm_reg_fee_first_class = AU_tm_reg_fee_first_class_rpl + AU_tm_reg_fee_first_class_govt;
AU_tm_reg_fee_extra_class = AU_tm_reg_fee_extra_class_rpl + AU_tm_reg_fee_extra_class_govt;

AU_tm_app_fee_first_class_discount = (AU_tm_app_fee_first_class_rpl * 0.75) + AU_tm_app_fee_first_class_govt;
AU_tm_app_fee_extra_class_discount = (AU_tm_app_fee_extra_class_rpl * 0.75) + AU_tm_app_fee_extra_class_govt;
AU_tm_reg_fee_first_class_discount = (AU_tm_reg_fee_first_class_rpl * 0.75) + AU_tm_reg_fee_first_class_govt;
AU_tm_reg_fee_extra_class_discount = (AU_tm_reg_fee_extra_class_rpl * 0.75) + AU_tm_reg_fee_extra_class_govt;

//NZ Trademark - NZD

NZ_tm_app_fee_first_class_rpl = 250;
NZ_tm_app_fee_first_class_govt = 100;
NZ_tm_app_fee_extra_class_rpl = 20;
NZ_tm_app_fee_extra_class_govt = 100;

NZ_tm_reg_fee_first_class_rpl = 0;
NZ_tm_reg_fee_first_class_govt = 0;
NZ_tm_reg_fee_extra_class_rpl = 0;
NZ_tm_reg_fee_extra_class_govt = 0;

NZ_tm_app_fee_first_class = NZ_tm_app_fee_first_class_rpl + NZ_tm_app_fee_first_class_govt;
NZ_tm_app_fee_extra_class = NZ_tm_app_fee_extra_class_rpl + NZ_tm_app_fee_extra_class_govt;
NZ_tm_reg_fee_first_class = NZ_tm_reg_fee_first_class_rpl + NZ_tm_reg_fee_first_class_govt;
NZ_tm_reg_fee_extra_class = NZ_tm_reg_fee_extra_class_rpl + NZ_tm_reg_fee_extra_class_govt;

NZ_tm_app_fee_first_class_discount = (NZ_tm_app_fee_first_class_rpl * 0.75) + NZ_tm_app_fee_first_class_govt;
NZ_tm_app_fee_extra_class_discount = (NZ_tm_app_fee_extra_class_rpl * 0.75) + NZ_tm_app_fee_extra_class_govt;
NZ_tm_reg_fee_first_class_discount = (NZ_tm_reg_fee_first_class_rpl * 0.75) + NZ_tm_reg_fee_first_class_govt;
NZ_tm_reg_fee_extra_class_discount = (NZ_tm_reg_fee_extra_class_rpl * 0.75) + NZ_tm_reg_fee_extra_class_govt;

//UK Trademark - GBP

UK_tm_app_fee_first_class_rpl = 229;
UK_tm_app_fee_first_class_govt = 170;
UK_tm_app_fee_extra_class_rpl = 25;
UK_tm_app_fee_extra_class_govt = 50;

UK_tm_reg_fee_first_class_rpl = 0;
UK_tm_reg_fee_first_class_govt = 0;
UK_tm_reg_fee_extra_class_rpl = 0;
UK_tm_reg_fee_extra_class_govt = 0;

UK_tm_app_fee_first_class = UK_tm_app_fee_first_class_rpl + UK_tm_app_fee_first_class_govt;
UK_tm_app_fee_extra_class = UK_tm_app_fee_extra_class_rpl + UK_tm_app_fee_extra_class_govt;
UK_tm_reg_fee_first_class = UK_tm_reg_fee_first_class_rpl + UK_tm_reg_fee_first_class_govt;
UK_tm_reg_fee_extra_class = UK_tm_reg_fee_extra_class_rpl + UK_tm_reg_fee_extra_class_govt;

UK_tm_app_fee_first_class_discount = (UK_tm_app_fee_first_class_rpl * 0.9) + UK_tm_app_fee_first_class_govt;
UK_tm_app_fee_extra_class_discount = (UK_tm_app_fee_extra_class_rpl * 0.9) + UK_tm_app_fee_extra_class_govt;
UK_tm_reg_fee_first_class_discount = (UK_tm_reg_fee_first_class_rpl * 0.9) + UK_tm_reg_fee_first_class_govt;
UK_tm_reg_fee_extra_class_discount = (UK_tm_reg_fee_extra_class_rpl * 0.9) + UK_tm_reg_fee_extra_class_govt;

//US Trademark - USD

US_tm_app_fee_first_class_rpl = 500;
US_tm_app_fee_first_class_govt = 325;
US_tm_app_fee_extra_class_rpl = 120;
US_tm_app_fee_extra_class_govt = 325;

US_tm_reg_fee_first_class_rpl = 0;
US_tm_reg_fee_first_class_govt = 0;
US_tm_reg_fee_extra_class_rpl = 0;
US_tm_reg_fee_extra_class_govt = 0;

US_tm_app_fee_first_class = US_tm_app_fee_first_class_rpl + US_tm_app_fee_first_class_govt;
US_tm_app_fee_extra_class = US_tm_app_fee_extra_class_rpl + US_tm_app_fee_extra_class_govt;
US_tm_reg_fee_first_class = US_tm_reg_fee_first_class_rpl + US_tm_reg_fee_first_class_govt;
US_tm_reg_fee_extra_class = US_tm_reg_fee_extra_class_rpl + US_tm_reg_fee_extra_class_govt;

US_tm_app_fee_first_class_discount = (US_tm_app_fee_first_class_rpl * 0.95) + US_tm_app_fee_first_class_govt;
US_tm_app_fee_extra_class_discount = (US_tm_app_fee_extra_class_rpl * 0.95) + US_tm_app_fee_extra_class_govt;
US_tm_reg_fee_first_class_discount = (US_tm_reg_fee_first_class_rpl * 0.95) + US_tm_reg_fee_first_class_govt;
US_tm_reg_fee_extra_class_discount = (US_tm_reg_fee_extra_class_rpl * 0.95) + US_tm_reg_fee_extra_class_govt;

//EM Trademark - EUR

EM_tm_app_fee_first_class_rpl = 710;
EM_tm_app_fee_first_class_govt = 900;
EM_tm_app_fee_extra_class_rpl = 50;
EM_tm_app_fee_extra_class_govt = 900;

EM_tm_reg_fee_first_class_rpl = 0;
EM_tm_reg_fee_first_class_govt = 0;
EM_tm_reg_fee_extra_class_rpl = 0;
EM_tm_reg_fee_extra_class_govt = 0;

EM_tm_app_fee_first_class = EM_tm_app_fee_first_class_rpl + EM_tm_app_fee_first_class_govt;
EM_tm_app_fee_extra_class = EM_tm_app_fee_extra_class_rpl + EM_tm_app_fee_extra_class_govt;
EM_tm_reg_fee_first_class = EM_tm_reg_fee_first_class_rpl + EM_tm_reg_fee_first_class_govt;
EM_tm_reg_fee_extra_class = EM_tm_reg_fee_extra_class_rpl + EM_tm_reg_fee_extra_class_govt;

EM_tm_app_fee_first_class_discount = (EM_tm_app_fee_first_class_rpl * 0.9) + EM_tm_app_fee_first_class_govt;
EM_tm_app_fee_extra_class_discount = (EM_tm_app_fee_extra_class_rpl * 0.9) + EM_tm_app_fee_extra_class_govt;
EM_tm_reg_fee_first_class_discount = (EM_tm_reg_fee_first_class_rpl * 0.9) + EM_tm_reg_fee_first_class_govt;
EM_tm_reg_fee_extra_class_discount = (EM_tm_reg_fee_extra_class_rpl * 0.9) + EM_tm_reg_fee_extra_class_govt;

//CN Trademark - CNY

CN_tm_app_fee_first_class_rpl = 200;
CN_tm_app_fee_first_class_govt = 325;
CN_tm_app_fee_extra_class_rpl = 200;
CN_tm_app_fee_extra_class_govt = 325;

CN_tm_reg_fee_first_class_rpl = 0;
CN_tm_reg_fee_first_class_govt = 0;
CN_tm_reg_fee_extra_class_rpl = 0;
CN_tm_reg_fee_extra_class_govt = 0;

CN_tm_app_fee_first_class = CN_tm_app_fee_first_class_rpl + CN_tm_app_fee_first_class_govt;
CN_tm_app_fee_extra_class = CN_tm_app_fee_extra_class_rpl + CN_tm_app_fee_extra_class_govt;
CN_tm_reg_fee_first_class = CN_tm_reg_fee_first_class_rpl + CN_tm_reg_fee_first_class_govt;
CN_tm_reg_fee_extra_class = CN_tm_reg_fee_extra_class_rpl + CN_tm_reg_fee_extra_class_govt;

CN_tm_app_fee_first_class_discount = (CN_tm_app_fee_first_class_rpl * 0.8) + CN_tm_app_fee_first_class_govt;
CN_tm_app_fee_extra_class_discount = (CN_tm_app_fee_extra_class_rpl * 0.8) + CN_tm_app_fee_extra_class_govt;
CN_tm_reg_fee_first_class_discount = (CN_tm_reg_fee_first_class_rpl * 0.8) + CN_tm_reg_fee_first_class_govt;
CN_tm_reg_fee_extra_class_discount = (CN_tm_reg_fee_extra_class_rpl * 0.8) + CN_tm_reg_fee_extra_class_govt;

//URL Base64 Encode and Decode utilities

var tm_keyString = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";

var tm_uTF8Encode = function(string) {
    string = string.replace(/\x0d\x0a/g, "\x0a");
    var output = "";
    for (var n = 0; n < string.length; n++) {
        var c = string.charCodeAt(n);
        if (c < 128) {
            output += String.fromCharCode(c);
        } else if ((c > 127) && (c < 2048)) {
            output += String.fromCharCode((c >> 6) | 192);
            output += String.fromCharCode((c & 63) | 128);
        } else {
            output += String.fromCharCode((c >> 12) | 224);
            output += String.fromCharCode(((c >> 6) & 63) | 128);
            output += String.fromCharCode((c & 63) | 128);
        }
    }
    return output;
};

var tm_uTF8Decode = function(input) {
    var string = "";
    var i = 0;
    var c = c1 = c2 = 0;
    while (i < input.length) {
        c = input.charCodeAt(i);
        if (c < 128) {
            string += String.fromCharCode(c);
            i++;
        } else if ((c > 191) && (c < 224)) {
            c2 = input.charCodeAt(i + 1);
            string += String.fromCharCode(((c & 31) << 6) | (c2 & 63));
            i += 2;
        } else {
            c2 = input.charCodeAt(i + 1);
            c3 = input.charCodeAt(i + 2);
            string += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));
            i += 3;
        }
    }
    return string;
}

var tm_base64Encode = function(input) {
    var output = "";
    var chr1, chr2, chr3, enc1, enc2, enc3, enc4;
    var i = 0;
    input = tm_uTF8Encode(input);
    while (i < input.length) {
        chr1 = input.charCodeAt(i++);
        chr2 = input.charCodeAt(i++);
        chr3 = input.charCodeAt(i++);
        enc1 = chr1 >> 2;
        enc2 = ((chr1 & 3) << 4) | (chr2 >> 4);
        enc3 = ((chr2 & 15) << 2) | (chr3 >> 6);
        enc4 = chr3 & 63;
        if (isNaN(chr2)) {
            enc3 = enc4 = 64;
        } else if (isNaN(chr3)) {
            enc4 = 64;
        }
        output = output + tm_keyString.charAt(enc1) + tm_keyString.charAt(enc2) + tm_keyString.charAt(enc3) + tm_keyString.charAt(enc4);
    }
    return output;
}
    
var tm_base64Decode = function(input) {
    var output = "";
    var chr1, chr2, chr3;
    var enc1, enc2, enc3, enc4;
    var i = 0;
    input = input.replace(/[^A-Za-z0-9\+\/\=]/g, "");
    while (i < input.length) {
        enc1 = tm_keyString.indexOf(input.charAt(i++));
        enc2 = tm_keyString.indexOf(input.charAt(i++));
        enc3 = tm_keyString.indexOf(input.charAt(i++));
        enc4 = tm_keyString.indexOf(input.charAt(i++));
        chr1 = (enc1 << 2) | (enc2 >> 4);
        chr2 = ((enc2 & 15) << 4) | (enc3 >> 2);
        chr3 = ((enc3 & 3) << 6) | enc4;
        output = output + String.fromCharCode(chr1);
        if (enc3 != 64) {
            output = output + String.fromCharCode(chr2);
        }
        if (enc4 != 64) {
            output = output + String.fromCharCode(chr3);
        }
    }
    output = tm_uTF8Decode(output);
    return output;
}

var tm_guid_decode = function(input) {
    input = input.replace(/_/g,"/").replace(/-/g,"+");
    var hex = "0123456789abcdef";
    var output = "";
    var chr1, chr2, chr3;
    var enc1, enc2, enc3, enc4;
    var i = 0;
    input = input.replace(/[^A-Za-z0-9\+\/\=]/g, "");
    while (i < input.length) {
        enc1 = tm_keyString.indexOf(input.charAt(i++));
        enc2 = tm_keyString.indexOf(input.charAt(i++));
        enc3 = tm_keyString.indexOf(input.charAt(i++));
        enc4 = tm_keyString.indexOf(input.charAt(i++));
        chr1 = (enc1 << 2) | (enc2 >> 4);
        chr2 = ((enc2 & 15) << 4) | (enc3 >> 2);
        chr3 = ((enc3 & 3) << 6) | enc4;
        output = output + hex.charAt(chr1 >> 4) + hex.charAt(chr1 % 16); 
        if (enc3 != 64) {
            output = output + hex.charAt(chr2 >> 4) + hex.charAt(chr2 % 16); 
        }
        if (enc4 != 64) {
            output = output + hex.charAt(chr3 >> 4) + hex.charAt(chr3 % 16);
        }
    }
    var o = output;
    return o[6] + o[7] + o[4] + o[5] + o[2] + o[3] + o[0] + o[1] + '-' + o[10] + o[11] + o[8] + o[9] + '-' + o[14] + o[15] + o[12] + o[13] + '-' + o.substring(16,20) + '-'  + o.substring(20, 32);
}

var tm_encode = function(input) {
    return tm_base64Encode(input).replace(/\+/g, "-").replace(/\//g, "_").replace(/=/g, "");  //return encodeURIComponent(tm_base64Encode(input));
}

var tm_decode = function(input) {
    return tm_base64Decode(input.replace(/_/g,"/").replace(/-/g,"+")); //return tm_base64Decode(decodeURIComponent(input))
}

function gup( name ){  name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");  var regexS = "[\\?&]"+name+"=([^&#]*)";  var regex = new RegExp( regexS );  var results = regex.exec( window.location.href );  if( results == null )    return "";  else    return results[1];}

function gupp (index) {
    return tm_decode(gup("d").split(".")[0]).split("|")[index];
}

function get_tm_application_id() {
    //First check for tm_application_id in the querystring
    var appID = gup("tm_application_id");
    if (appID != null && appID != "") {
        return appID;
    }
    //Else assume encoded id
    var tmArray = gup("d").split(".");
    var tmID = tmArray.length == 2 ? tmArray[1] : "";			
    return (tmID != null && tmID != "") ? tm_guid_decode(tmID) : "";
}

