User:Cbarr/Template:2011FR/Donate-now-country-specific-c

 { }
 * 1) amount_table

{ font-style: italic; font-weight:bold; }
 * 1) amount_table_header

td .td_amount { width: 33%; }

{ text-align: center; }
 * 1) cc-donate-button, #paypal-donate-button, #banktransfer-donate-button, #monthly-donation

select#input_currency_code { width:8em; font-size:70%; }



//--- Utility Functions--- function arrayToObject(variable) // helper function: converts an array to object literal with keys // then it can be used for quick "in" tests { var obj = {};

for (var i=0; i<variable.length; i++) {   obj[variable[i]]=''; }

return obj; }

function getQuerystring( key ) { key = key.replace( /[\[]/, '\\\[' ).replace( /[\]]/, '\\\]' ); var regex = new RegExp( '[\\?&]' + key + '=([a-zA-Z0-9\_\-]*)' ); var qs = regex.exec( window.location.search ); return qs == null ? '' : qs[1]; }

function getQuerystring2(key, default_) // a function to parse the information passed by central notice { if (default_==null) default_="";

key = key.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]"); var regex = new RegExp("[\\?&]"+key+"=([^&#]*)"); var queryed = regex.exec(window.location.href);

if(queryed == null) return default_; else return queryed[1]; }

function getLandingPage { var path = "  ";

if ( path == "default" ) {   pathArray = window.location.pathname.split( '/' ); return pathArray[2]; } else return path; }

// Template defined Arrays var currencyTypes = new Array ; var currencyDonationAmounts = { }; var currencyDisplay = new Array ;

//--constant Arrays--- var countryCurrency = { } var currencyPositions = { }; var euroPositions = { }; var currencySymbols = { }; var currencyMinimums = { }; var acceptedCC = arrayToObject([ ]); var acceptedPayPal = arrayToObject([ ]); var acceptedBankTransfer = arrayToObject([ ]);

//-Variables var countryCode = getQuerystring ( 'country' ); var languageCode = " "; var currencyCode = countryCurrency[countryCode]; if(currencyCode == undefined) currencyCode = 'USD'; var colWrap = " ";

//--- junk variables --- var enableOther = false;

//--form junk function validateForm(form) { var error = true;

// Get amount selection var amount = null; for ( var i = 0; i < form.amount.length; i++ ) {   if ( form.amount[i].checked ) {     amount = form.amount[i].value; } }  if ( form.amountGiven.value != "") {     var otherAmount = form.amountGiven.value; otherAmount = otherAmount.replace(/[,.](\d)$/, '\:$10'); otherAmount = otherAmount.replace(/[,.](\d)(\d)$/, '\:$1$2'); otherAmount = otherAmount.replace(/[,.]/g, ''); otherAmount = otherAmount.replace(/:/, '.'); form.amountGiven.value = otherAmount; amount = otherAmount; }

// Check amount is a real number error = ( amount == null || isNaN( amount ) || amount.value <= 0 ); // Check amount is at least the minimum var currencyCode = form.currency_code[form.currency_code.selectedIndex].value; if ( typeof( currencyMinimums[currencyCode] ) == 'undefined' ) {   currencyMinimums[currency] = 1; } if ( amount < currencyMinimums[currencyCode] || error ) {   alert( '  '.replace('$1', currencyMinimums[currencyCode] + ' ' + currencyCode ) ); error = true; } return !error; }

function DefaultSubmit(formfield, Action) { if(enableOther == false) form.amountGiven.value = "";

var keycode; if (window.event) {   keycode = window.event.keyCode; } else if (Action) {   keycode = Action.which; } else return true;

if (keycode == 13) {   if (document.getElementById('cc-donate-button').style.display == "block") {     redirectPayment('cc'); }   else if (document.getElementById('paypal-donate-button').style.display == "block") {     redirectPayment('pp'); }   return false; } else return true; }

function redirectPayment(paymentType) { if (paymentType == 'cc') {   var paymentType = 'cc'; var action_url = "https://payments.wikimedia.org/index.php/Special:PayflowProGateway?uselang= \x26masthead=\x26form_name=\x26text_template=\x26language= " ; } if (paymentType == 'pp') {   action_url="http://wikimediafoundation.org/wiki/Special:ContributionTracking/  "; } document.paypalcontribution.action = action_url; document.paypalcontribution.utm_source.value = getQuerystring( 'utm_source' ) + '.' + getLandingPage + '.' + paymentType; if(validateForm(document.paypalcontribution)) {   if(typeof(OWA) !== 'undefined') {     OWATracker.shareStateByPost( document.paypalcontribution ); }   document.paypalcontribution.submit; } }

document.write('' + '' +  '' +  '' +  '' +  '' +  '' +  '' +  '' +  '' +  '' + ' ');

var oTable = document.createElement("table"); document.getElementById("amount-div").appendChild(oTable); oTable.id = "amount_table";

var oTBody = []; //--- block for table title var oTHead = document.createElement("thead"); oTable.appendChild(oTHead); oTHead.id = "amount_table_header";

oRow = oTHead.insertRow(-1); oCell = oRow.insertCell(-1); oCell.innerHTML = "Select your gift:"; oCell.id = "amount_table_header"; oCell.colSpan = colWrap-1;

oCell = oRow.insertCell(-1); var oSelect = document.createElement("select"); oCell.appendChild(oSelect); oSelect.name="currency_code"; oSelect.id="input_currency_code"; oSelect.size="1"; oSelect.onchange = dropOnChange;

var opt = document.createElement("option"); opt.selected = true; opt.text = currencyCode + " – " + currencySymbols[currencyCode]; opt.value = currencyCode; oSelect.options.add(opt); var opt = document.createElement("option"); opt.text = "---"; opt.value = "USD"; oSelect.options.add(opt)

for(i=0; i<currencyTypes.length; i++) {   opt = document.createElement("option"); opt.text = currencyTypes[i] + " – " + currencySymbols[currencyTypes[i]]; opt.value = currencyTypes[i]; //opt.onkeypress = "loadGeneralValues; updateValue(this.value); updateSymbol(this.value); updateButtons(this.value);" //opt.onmouseover = "loadGeneralValues; updateValue(this.value); updateSymbol(this.value); updateButtons(this.value); selectedNew(this);" oSelect.options.add(opt); } //--- end block ---

//--- block for "would you like to know more" --- var oTFoot = document.createElement("tfoot"); oTable.appendChild(oTFoot); oTFoot.id = "amount_table_footer";

oRow = oTFoot.insertRow(-1); oCell = oRow.insertCell(-1); //consider changing template or at least clean for " oCell.id="monthly-donation";  oCell.innerHTML = ' Monthly donation stuff here ';  oCell.colSpan = colWrap;

oRow = oTFoot.insertRow(-1); oCell = oRow.insertCell(-1); oCell.innerHTML =' * *   *   * ';  oCell.colSpan = colWrap;

oRow = oTFoot.insertRow(-1); oCell = oRow.insertCell(-1); oCell.innerHTML = ' '; oCell.colSpan = colWrap;

//- end block //var oCaption = document.createElement("caption");

//block for radio options --- oTBody[0] = document.createElement("tbody"); oTable.appendChild(oTBody[0]); oTBody[0].id = "amount_table_options";

var inputRadio = []; var labelRadio = [];

for(i=0; i<10; i++) {   if(i%colWrap == 0) {      oRow = oTBody[0].insertRow(-1); oRow.id = "amount_table_row_" + i/colWrap; }   if(currencyDonationAmounts[currencyCode][i] == undefined ) {     break; }   if(currencyDisplay[i] != 0) {     oCell = document.createElement("td"); //oCell = oRow.insertCell(-1); oCell.id = "td_amount_" + i;     oCell.className = "td_amount";

inputRadio[i] = document.createElement("input"); oCell.appendChild(inputRadio[i]); inputRadio[i].type = "radio"; inputRadio[i].name = "amount"; inputRadio[i].id = "input_amount_" + i;     inputRadio[i].value = currencyDonationAmounts[currencyCode][i]; inputRadio[i].onclick = resetOtherBox; labelRadio[i] = document.createElement("label"); oCell.appendChild(labelRadio[i]); labelRadio[i].setAttribute("for","input_amount_" + i ); //labelRadio[i].for = "input_amount_" + i;     labelRadio[i].className = "amount-label"; labelRadio[i].id = "input_amount_label_" + i;     labelRadio[i].innerHTML = currencyDonationAmounts[currencyCode][i];

oRow.appendChild(oCell); } }  oCell = oRow.insertCell(-1); oCell.id = "td_amount_other"; oCell.className = "td_amount";

otherRadio = document.createElement("input"); oCell.appendChild(otherRadio); otherRadio.type = "radio"; otherRadio.name = "amount"; otherRadio.id = "input_amount_other"; otherRadio.value = ""; otherRadio.onclick = clearOtherBox; otherLabel = document.createElement("label");

oCell.appendChild(otherLabel); //otherLabel.for = "input_amount_other"; otherLabel.setAttribute("for","amountGiven"); //otherLabel.className = "amount-label";

var oSpan = document.createElement("span"); oCell.appendChild(oSpan); oSpan.className = "amount-label";

otherBox = document.createElement("input"); oSpan.appendChild(otherBox);

otherBox.type = "text"; otherBox.name = "amountGiven"; otherBox.id = "amountGiven"; otherBox.value = ""; otherBox.size = "3"; otherBox.style.color = "#666666"; otherBox.onclick = clearOtherBox; otherBox.onfocus = boxOnFocus; otherBox.onKeyPress = boxOnKeyPress;

// end block -- //--- block for dropdown - // oTBody[1] = document.createElement("tbody"); // oTable.appendChild(oTBody[1]); // oTBody[1].id = "amount_table_dropdown";

// oRow = oTBody[1].insertRow(-1); // oCell = oRow.insertCell(-1); // oCell.colSpan = colWrap;

//-- end block --- //-- block for buttons oTBody[2] = document.createElement("tbody"); oTable.appendChild(oTBody[2]); oTBody[2].id = "amount_table_buttons";

var oRow = oTBody[2].insertRow(-1); var oCell = oRow.insertCell(-1); oCell.colSpan = colWrap;

oDiv = document.createElement("div"); oCell.appendChild(oDiv);

//oDiv.id = 'button-block';

oDivSub = document.createElement("div"); oDiv.appendChild(oDivSub); oDivSub.id = 'cc-donate-button'; oDivSub.innerHTML = "";

oDivSub = document.createElement("div"); oDiv.appendChild(oDivSub); oDivSub.id = 'paypal-donate-button'; oDivSub.innerHTML = "<input type='button' value=' ' class='button' onclick='redirectPayment(\"pp\");' style='width: 15em;' />";

oDivSub = document.createElement("div"); oDiv.appendChild(oDivSub); oDivSub.id = 'banktransfer-donate-button'; oDivSub.innerHTML = "<input type='button' value=' ' class='button' onclick='redirectPayment(\"bt\");' style=width: 15em\; />";

//- end block ---

document.write(' ');

document.paypalcontribution.utm_medium.value = getQuerystring( 'utm_medium' ); document.paypalcontribution.utm_campaign.value = getQuerystring( 'utm_campaign' ); document.paypalcontribution.country.value = getQuerystring ( 'country_code' ); document.paypalcontribution.referrer.value = document.referrer;

//- Body functions --- function loadLocalValues { currencyDonationAmounts = {  }; }

function loadGeneralValues { currencyDonationAmounts = {  }; }

function updateButtons { // $('#cc-donate-button').style.display = "none"; // $('#paypal-donate-button').style.display = "none"; // $('#banktransfer-donate-button').style.display = "none"; document.getElementById('cc-donate-button').style.display = "none"; document.getElementById('paypal-donate-button').style.display = "none"; document.getElementById('banktransfer-donate-button').style.display = "none";

if ( currencyCode in acceptedCC ) {   //is this template still needed? //$('#cc-donate-button').style.display = " "; document.getElementById('cc-donate-button').style.display = " "; } if (currencyCode in acceptedPayPal ) {   //why not this? //$('#paypal-donate-button').style.display = "block"; document.getElementById('paypal-donate-button').style.display = "block"; } if (currencyCode in acceptedBankTransfer ) {   //or this? //$('#banktransfer-donate-button').style.display = "block"; document.getElementById('banktransfer-donate-button').style.display = "block"; } }

function updateSymbol { $('.amount-label-symbol').remove;

if ( currencySymbols[currencyCode] == undefined ) return;

if ( currencyPositions[currencyCode] == 'after' ) {   $('.amount-label').append(' ' + currencySymbols[currencyCode] + ' '); } else if( currencyPositions[currencyCode] == 'euro' ) {   if(euroPositions[languageCode] == 'before')//ga lv mt en    { $('.amount-label').prepend(' ' + currencySymbols[currencyCode] + ' '); }   else {     $('.amount-label').append(' ' + currencySymbols[currencyCode] + ' '); } }  else {   $('.amount-label').prepend(' ' + currencySymbols[currencyCode] + ' '); } }

function updateValue { for(i=0; i<10; i++) {   if(currencyDonationAmounts[currencyCode][i] == undefined) {     break; }

if(currencyDisplay[i] != 0) {     //$("#input_amount_" + i).value = currencyDonationAmounts[currencyCode][i]; //$("#input_amount_label_" + i).innerHTML = currencyDonationAmounts[currencyCode][i]; document.getElementById("input_amount_" + i).value = currencyDonationAmounts[currencyCode][i]; document.getElementById("input_amount_label_" + i).innerHTML = currencyDonationAmounts[currencyCode][i]; } } }

function resetOtherBox { //$("#amountGiven").style.color = "#666666"; //$("#amountGiven").value = "Other"; //document.getElementById("amountGiven").style.color = "#666666"; document.getElementById("amountGiven").value = ""; enableOther = false; }

function clearOtherBox { //$("#amountGiven").style.color = "#000000"; //$("#amountGiven").value=''; //document.getElementById("amountGiven").style.color = "#000000"; document.getElementById("amountGiven").value=''; enableOther = true; }

function dropOnChange { currencyCode = $("#input_currency_code").val; resetOtherBox; loadGeneralValues; updateValue; updateSymbol; updateButtons; }

function boxOnFocus { //$("#input_amount_other").checked=true; document.getElementById("input_amount_other").checked=true; }

function boxOnKeyPress { //return DefaultSubmit($("amountGiven"),event); return DefaultSubmit(document.getElementById("#amountGiven"),event); }

( function( $ ) { $(document).ready(function{ //currency = $("#input_currency_code").val; updateButtons; updateValue; updateSymbol; }) } )( jQuery );