﻿var lang;
var isCanada = true;

// Make the <select> for all countries.
function makeCountrySelect(pgLang) {
  lang = pgLang;
  // Get unique country names by creating a hash/object.  Keys to the hash
  // are automatically unique, so use that to get unique countries.
  var countryNames = new Object();
  for (var i in countries) {
    // Erase everything after the first pipe.
    var firstPipe = countries[i].indexOf("|");
    var country = countries[i].substring(0, firstPipe);

    // We can assign the value to anything.  Value is not important.  Only

    // the key is important.
    countryNames[country] = "";
  }

  // The string that contain the <select> and <option>s.
  var selectString = "";
  selectString += '<select name="countrySelect" onchange="showRates(this.value);">\n';
  if (lang == "en") {
	selectString += '<option value="">-- Select Country --</option>\n';
  }
  else if (lang == "fr") {
	selectString += '<option value="">-- Select Country --</option>\n';
  }
  // Loop through all country names and show each in an <option>.
  for (var country in countryNames) {
    selectString += '<option value="' + country + '">' + country;
    selectString += '</option>\n';
  }
  selectString += '</select>\n';

  document.writeln(selectString);
}

// Show rates for user-specified country.
function showRates(country) {

  // If no country was passed, clear the rate info.
  if (! country) {
    return;
  }
var specialchar = new Array ("é","ï","ô","d\'","Î","è","É","ë","ê");
var specialcharfull = new Array ("&eacute;","&iuml;","&ocirc;","d\'","&Icirc;","&egrave;","&Eacute;","&euml;","&ecirc;");

for(var j=0;j<country.length;j++){
for(var k=0;k<specialchar.length;k++){
if(country.charAt(j)==specialchar[k]){
country =country.replace(country.charAt(j),specialcharfull[k]);
}
}
}

  // The table that will show the rate info.
  var tableString = "\n";

  // The number of matches found.
  var found = 0;

  isCanada = true;	

  // Loop through the countries array and try to find a match.
  for (var i in countries) {
    // If no match found, continue looping.
    if ((countries[i].indexOf(country + "|")) == -1) {
      continue;
    }

    // Match was found.
    found++;

    // Split the string by the pipe character.
    var rateArray = countries[i].split("|");

    var country = rateArray[0];
    var countryCode = rateArray[1];
    var operator = rateArray[2];
    var operatorCode = rateArray[3];
    var frequency = rateArray[4];
    var vRate1 = rateArray[5];
	var vRate2 = rateArray[6];
	var vRate3 = rateArray[7];
	var vRate4 = rateArray[8];
    var sms = rateArray[9];
    var gprs = rateArray[10];
    var rate = rateArray[11];
    var volume = rateArray[12];
    var increment = rateArray[13];
    var edge = rateArray[14];

	if (vRate2 == "" && vRate3 == "" && vRate3 == "" ) { isCanada = false; } 

    // Show the table headers and the link for country only once.
    if (found == 1) {
      tableString += showCountryLink(countryCode);
      tableString += startTable();
    }

    // Alternate colours for table row, easier for user to read.
    if (found % 2) {
      tableString += '<tr style="background-color: #f8f8f1">\n';
    }
    else {
      tableString += '<tr style="background-color:#e5e5e5">\n';
    }

    // Show the link for the operator.
    tableString += '<td>' + showOperatorLink(countryCode, operator, operatorCode) + '</td>\n';

    tableString += '<td>' + frequency + '</td>\n';
    tableString += '<td>$' + vRate1 + '</td>\n';
	if (isCanada) {
		tableString += '<td>$' + vRate2 + '</td>\n';
		tableString += '<td>$' + vRate3 + '</td>\n';
		tableString += '<td>$' + vRate4 + '</td>\n';
	}
	
    tableString += '<td>' + sms + '&cent;</td>\n';
    tableString += '<td>' + gprs + '</td>\n';

    if (rate) {
      tableString += '<td>' + rate + '&cent; per KB</td>\n';
    }
    else {
      tableString += '<td></td>\n';
    }

    tableString += '<td>' + volume + '</td>\n';
    tableString += '<td>' + increment + '</td>\n';
    tableString += '<td>' + edge + '</td>\n';
    tableString += '</tr>\n\n';
  }

  // End the HTML table.
  tableString += '</table>\n';

  //WIP 33193 - Bhargav: move roaming table to new pop-up window.
  var roamingTable = "";
  
  roamingTable += '<html xmlns=http://www.w3.org/1999/xhtml>\n';
  roamingTable += '<head><meta http-equiv=Content-Type content=text/html; charset=utf-8 />\n';
  roamingTable += '<title>Rogers.com - International GSM/GPRS Roaming - ' + country + '</title>\n';
  roamingTable += '<script type=text/javascript language=javascript src=/web/framework/skins/rogers/js/rogers.js></script>\n';
  roamingTable += '</head>\n';
  roamingTable += '<body leftmargin="0" topmargin="0">\n';
  // CSS style for table fonts.
  roamingTable += '<style type="text/css">\n';
  roamingTable += '.checkOutTable td {\n';
  roamingTable += '  font-size:11px;\n';
  roamingTable += '  font-family:Arial, Helvetica, sans-serif;\n';
  roamingTable += '}\n';
  roamingTable += '.checkOutTable th {\n';
  roamingTable += '  font-size:11px;\n';
  roamingTable += '  font-family:Arial, Helvetica, sans-serif;\n';
  roamingTable += '  padding:1px;\n';
  roamingTable += '}\n';
  roamingTable += '.boldText {\n';
  roamingTable += 'font-family:Arial, Helvetica, sans-serif;\n';
  roamingTable += 'font-size:11px;\n';
  roamingTable += 'font-weight:bold;\n';
  roamingTable += 'text-decoration:none;\n';
  roamingTable += '}\n';
  roamingTable += '.boldText a:hover{\n';
  roamingTable += 'font-family:Arial, Helvetica, sans-serif;\n';
  roamingTable += 'font-size:11px;\n';
  roamingTable += 'font-weight:bold;\n';
  roamingTable += 'text-decoration:underline;\n';
  roamingTable += '}\n';
  roamingTable += '</style>\n\n';  
  roamingTable += '<table width=100% cellpadding=0 cellspacing=0 border=0><tr bgcolor="#BB1523">'
  roamingTable += '<td align="right" class="boldText"><a href="javascript:window.close();"><span style="color:#FFFFFF;">';
  if (lang == "en") { roamingTable += 'Close Window'; }
  else if (lang == "fr") { roamingTable += 'Fermez fen&ecirc;tre'; }
  roamingTable += '</span></a></td>';
  roamingTable += '<td width=25 align="right"><a href="javascript:window.close();"><img src="//your.rogers.com/mq/images/button_mqpopup-close.gif" width="23" height="30" alt="" border="0"></a></td></tr>'
  roamingTable += '<tr><td colspan=2><img src="/images/blank.gif" alt="" width="1" height="1" border="0"></td></tr>'
  roamingTable += '<tr><td bgcolor="#D1C7C6" colspan=3><img src="/images/blank.gif" alt="" width="1" height="1" border="0"></td></tr></table>'
  roamingTable += tableString;
  roamingTable += '</body>\n';
  roamingTable += '</html>\n';

  var roamingWin = window.open('','_blank','width=675,height=300,toolbar=0,scrollbars=1,resizable=1,status=0');
  roamingWin.document.write(roamingTable);

}

// Start the HTML table.
function startTable() {
  var table = "";

  table += '<table class="checkOutTable" style="width:100%;padding:0 0 0 0">\n';
  table += '<thead>\n';
  table += '<tr style="background:#666666;">\n';
	if (lang == "en") {
		  table += '<th colspan="2">&nbsp;</th>\n';
		  
		  table += '<th';
		  if (isCanada) { table += ' colspan="4" '; }
		  table += '>Voice Rates</th>\n';
		  table += '<th>Text Messaging Rates</th>\n';
		  table += '<th colspan="4">Data Rates</th>\n';
		  table += '<th>3G Service<br>Available</th>\n';
		  table += '</tr>\n';
		  table += '</thead>\n\n';
		
		  table += '<tr style="background-color:#e5e5cc">\n';
		  table += '<td>GSM Operator</td>\n';
		  table += '<td>Frequency</td>\n';
		  if (isCanada) {
			table += '<td align="center">Calls back to<br>Canada/US</td>\n';
			table += '<td align="center">Incoming<br>Calls</td>\n';
			table += '<td align="center">In Country<br>Calls</td>\n';
			table += '<td align="center">Calls to<br>International Destinations</td>\n';
		  }
		  else {
			table += '<td align="center">ALL CALL TYPES<br>(Calls back to Canada/US, Incoming,<br>In Country & Calls to International Destinations)</td>\n';
		  }
		  table += '<td>SMS</td>\n';
		  table += '<td>Data Service<br>Available</td>\n';
		  table += '<td>Data<br>Rate</td>\n';
		  table += '<td>Data Minimum <br />Volume</td>\n';
		  table += '<td>Data <br />Increment</td>\n';
		  table += '<td></td>\n';
	}
	else if (lang == "fr") {
		  table += '<th colspan="2">&nbsp;</th>\n';
		  table += '<th';
		  if (isCanada) { table += ' colspan="4" '; }
		  table += '>Tarifs Voix</th>\n';
		  table += '<th>Tarifs De Messagerie Texte</th>\n';
		  table += '<th colspan="4">Tarifs De Transmission De Données</th>\n';
		  table += '<th>Service 3G <br />disponible</th>\n';
		  table += '</tr>\n';
		  table += '</thead>\n\n';
		
		  table += '<tr style="background-color:#e5e5cc">\n';
		  table += '<td>Nom de lop&eacute;ra<br>teur</td>\n';
		  table += '<td>Fr&eacute;quences</td>\n';
		  if (isCanada) {
			table += '<td>Appels &agrave; destination du Canada ou des&Eacute;tats-Unis</td>\n';
			table += '<td>Appels entrants</td>\n';
			table += '<td>Tarif la minute (&agrave; l\'&eacute;chelle nationale)</td>\n';
			table += '<td>Appels vers d\'autres destinations internationales</td>\n';
		  }
		  else {
			table += '<td align="center">TOUS LES GENRES D\'APPELS<br>(appels vers le Canada/États-Unis, appels entrants, appels à partir du Canada et les appels vers des destinations internationales)</td>\n'; 
		  }
		  table += '<td>Messages texte</td>\n';
		  table += '<td>Service de transmission de données disponible</td>\n';
		  table += '<td>Tarif de transmission de données</td>\n';
		  table += '<td>Volume minimum de la transmission de données</td>\n';
		  table += '<td>Échelon de transmission de données </td>\n';
		  table += '<td></td>\n';
	}

  table += '</tr>\n\n';	
  return table;
}

// Show the link for the country.
function showCountryLink(countryCode) {
  var url = "http://www.gsmworld.com/cgi-bin/ni_map_carw.pl?cc=" + countryCode + "&net=00";
  var link = "";
  if (lang == "en") {
	  link = "<a href=\"javascript:void srPopup('" + url + "','','width=500,height=450,scrollbars=0,resizable=1');\">View country coverage map.</a><br>\n";
  }
  else if (lang == "fr") {
	  link = "<a href=\"javascript:void srPopup('" + url + "','','width=500,height=450,scrollbars=0,resizable=1');\">Regarder la carte de couverture de pays.</a><br>\n";
  }
  return link;
}

// Show the link for the operator.
function showOperatorLink(countryCode, operator, operatorCode) {
  // If operator code was passed, build the link.
  if (operatorCode) {
    var url = "http://www.gsmworld.com/cgi-bin/ni_map_carw.pl?cc=" + countryCode + "&net=" + operatorCode + "&opts=1";
    var link = "<a href=\"javascript:void srPopup('" + url + "','','width=500,height=450,scrollbars=0,resizable=1');\">" + operator + "</a><br>\n";
    return link;
  }

  // If operator code was not passed, just return the operator name.
  else {
    return operator;
  }
}
