
// to decrypt email addresses
// php counterpart ICH::mailEncryptGetHtml()

function decrypt_string(crypted_string) {
    var numbers = crypted_string.split(' ');
    n = numbers[0];                                     //  assume the decryption key and n are stored as the first two
    decryption_key = numbers[1];                        // numbers in crypted string. Remove them from the crypted string
    numbers[0] = ""; numbers[1] = "";
    crypted_string = numbers.join(" ").substr(2);

    var decrypted_string = '';
    var crypted_characters = crypted_string.split(' ');

    for(var i in crypted_characters) {
        var current_character = crypted_characters[i];
        var decrypted_character = exponentialModulo(current_character,n,decryption_key);
        decrypted_string += String.fromCharCode(decrypted_character);
    }

    // with mailto
    decrypted_string = '<a href="mailto:' + decrypted_string + '">' + decrypted_string + '</a>';

    document.write(decrypted_string);
    return true;
}

// helper function for decrypt_string
// finds base^exponent % y for large values of (base^exponent)

function exponentialModulo(base,exponent,y) {
    if (y % 2 == 0) {
        answer = 1;
        for(var i = 1; i <= y/2; i++) {
            temp = (base*base) % exponent;
            answer = (temp*answer) % exponent;
        }
    } else {
        answer = base;
        for(var i = 1; i <= y/2; i++) {
            temp = (base*base) % exponent;
            answer = (temp*answer) % exponent;
        }
    }
    return answer;
}

// used to display the google maps location in a new window

function fenCentre(url,largeur,hauteur){
    var Dessus=(screen.height/2)-(hauteur/2);
    var Gauche=(screen.width/2)-(largeur/2);
    var features= 'height='+hauteur+',width='+largeur+',top='+Dessus +',left='+Gauche+",scrollbars=yes";
    thewin=window.open(url,'',features);
}