var element_id =''; //Define Global Variables,

var countries = new Array(
    "Argentina",
    "Australia",
    "Belgique",
    "België",
    "Brasil",
    "Canada(en)",
    "Canada(fr)",
    "Ceská Republika",
    "Danmark",
    "Deutschland",
    "Eesti",
    "España",
    "France",
    "Ireland", 
    "Italia",
    "Latvija",
    "Lietuva",
    "Luxembourg",
    "Magyarország",
    "Nederland",
    "New Zealand",
    "Norway",
    "Österreich",
    "Polska",
    "Portugal",
    "Poccии",
    "Schweiz",
    "South Africa",
    "Suisse",
    "Suomi",
    "Sverige",
    "Svizzera",
    "Türkiye",
    "UK",
    "United States",
    "Ελλάδα",
    "México",
    "Maroc",
    "Other countries"

    )

var callinfo_data=new Array(
    "011-4109-3000#Lunes-Viernes: 8am - 5pm GMT-3",//Argentina
    "1300 135 604#Monday - Friday: 9:00 a.m. to 5:30 p.m. AEST", //Australia
    "078250157#du lundi au vendredi de 10h00 à 16h30 CET",  // Belgium (fr)
    "078250156#Maandag t/m vrijdag van 09.00 tot 18.30 CET", // Belgium (nl)
    "Sao Paulo:<span style ='line-height:14pt; font-weight:normal; font-size:9pt'>11 4062 0115</span><br/>Campinas:<span style ='line-height:14pt; font-weight:normal; font-size:9pt'>19 4062 0115</span><br/>Rio de Janeiro:<span style ='line-height:14pt; font-weight:normal; font-size:9pt'>21 3005 3413</span>#<span style='margin-left:45px;'><b>Email:</b> <a href='mailto:sac@tomtom.com.br'>sac@tomtom.com.br</a></span>", //Brazil
    "+1 866 486 6866#Monday - Friday: 8:30 a.m. to 7:00 p.m. EST<br/>Saturday: 9:00 a.m. to 6:00 p.m. EST", //Canada (en)
     "+1 866 486 6866 (en anglais)#lundi - vendredi:08h30 - 19h00 EST<br/>samedi:09h00 - 18h00 EST", //Canada (fr)
    "+420 23 90 00 491#pondelí-pátek 09:00 - 16:00", // Czech Republic
    "35 25 65 14#Mandag - Fredag: 10:00 til 17:00", //Denmark
    "0180 500 38 42#Mo - Fr: 10:00 - 18:30<br /><span style='font-size:7.5pt; color:rgb(175,175,175)'>14 Cent/Min. vom deutschen Festnetz (mobile Tarife können variieren)</span>", //Germany
   "003728000044381#Monday - Friday: 09:00 - 17:00 CET+1", //Estonia
   "913496508#Lunes-Viernes: 10:00 - 17:00 CET", //Spain
    "01 70 36 35 82#du lundi au vendredi de 10h00 à 16h30 CET", //France
    "1890 812 008#Monday - Friday: 09:00 - 17:00 GMT", //Ireland
    "0245281004#lunedì-venerdì: ore 10:00 - 17:00 CET", //Italy
    "0037180003446#Monday - Friday: 09:00 - 17:00 CET+1", //Latvia
    "00370880030896#Monday - Friday: 09:00 - 17:00 CET+1", //Lithuania
     "+33 1 7036 3582#lundi - vendredi<br/>10h00 - 17h30",//Luxembourg
    "0036 177 792 27#hétfő - péntek: 09:00 - 17:30", //Hungary
    "0208501007#Maandag t/m vrijdag van 09.00 tot 18.30 CET", //Netherlands
    "0800 450 973#Monday - Friday: 09:00 - 17:30 NZT", //New Zealand
    "81556710#Mandag - Fredag: 10:00 til 17:00 GMT+1", //Norway
    "0810102557#Montag bis Freitag von 10:00 bis 18:30 Uhr MEZ", //Austria
    "+48 22 34 91 598#Poniedziałek - Piątek 09:00 - 16:00", //Poland
    "808781222#De Segunda à Sexta : Das 09.30 às 17.00 GMT", //Portugal
    "007 499 271 3190#Понедельник - пятница: с 09:00 до 17:30 по московскому времени", //Russia
    "0844000016#Mo - Fr:10:00 - 18:30", //Switzerland (de)
    "0800 980670#Monday - Friday: 9:00 to 18:00 GMT+1 ", //South Africa
    "0844000091#du lundi au vendredi de 10h00 à 16h30 CET", //Switzerland (fr)
    "0303 9038#Maanantaista - Perjantaihin: 11:00 - 18:00", //Finland (Suomi)
    "077-662-00-10#Måndag-Fredag: 10:00 - 17:00", //Sweden
    "0844000040#lunedì-venerdì: ore 10:00 - 17:00 CET", //Switzerland (it)
    "212 356 9707#Hafta içi her gün: 10:00 - 18:00", //Turkey
    "0845 1610009#Monday - Friday: <bold>10:00</bold> a.m. to <bold>5:00</bold> p.m. GMT", //UK
    "866 486 6866#Monday - Friday: 7:00 a.m. to 11:00 p.m. EST<br />Saturday: 9:00 a.m. to 8:00 p.m. EST", //USA
     "0080044144676#Δευτέρα - Παρασκευή : 11:00 - 18:00", //Greece
     "800 186 6866#Lunes-Viernes:7:30 - 18:00<br />Sábado: 8:00-17:00", //Mexico
    "Maroc: email seulement# ", //Morocco
    "+31208501004#Monday - Friday: 9:00 a.m. to 7:30 p.m. GMT+1", //other countries
    " # ");

//Using object literals to store all contact data
var contact_data={
    "Argentina": {
        "phone": "011-4109-3000",
        "hours": "Lunes-Viernes: 8am - 5pm GMT-3"
    },
    "Australia": {
        "phone": "1300 135 604",
        "hours": "Monday - Friday: 9:00 a.m. to 5:30 p.m. AEST"
    },
   "Belgique":{
        "phone":"078250157",
        "hours":"du lundi au vendredi de 10h00 à 16h30 CET"
    },
    "België": {
        "phone": "078250156",
        "hours": "Maandag t/m vrijdag van 09.00 tot 18.30 CET"
    },
    "Brasil":{
        "phone":"Sao Paulo:<span style ='line-height:14pt; font-weight:normal; font-size:9pt'>11 4062 0115</span><br/>Campinas:<span style ='line-height:14pt; font-weight:normal; font-size:9pt'>19 4062 0115</span><br/>Rio de Janeiro:<span style ='line-height:14pt; font-weight:normal; font-size:9pt'>21 3005 3413</span>",
        "hours":"<span style='margin-left:45px;'><b>Email:</b> <a href='mailto:sac@tomtom.com.br'>sac@tomtom.com.br</a></span>"
    },
    "Canada(en)": {
        "phone": "+1 866 486 6866",
        "hours": "Monday - Friday: 8:30 a.m. to 7:00 p.m. EST<br/>Saturday: 9:00 a.m. to 6:00 p.m. EST"
    },
   "Canada(fr)": {
        "phone": "+1 866 486 6866 (en anglais)",
        "hours": "lundi - vendredi:08h30 - 19h00 EST<br/>samedi:09h00 - 18h00 EST"
    },
    "Ceská Republika":{
         "phone": "+420 23 90 00 491",
         "hours": "pondelí-pátek 09:00 - 16:00"
    },
    "Danmark": {
        "phone": "35 25 65 14",
        "hours": "Mandag - Fredag: 10:00 til 17:00"
    },
    "Deutschland": {
        "phone": "0180 500 38 42",
        "hours": "Mo - Fr: 10:00 - 18:30<br/><span style='font-size:7.5pt; color:rgb(175,175,175)'>14 Cent/Min. vom deutschen Festnetz (mobile Tarife können variieren)</span>"
    },
    "Eesti": {
        "phone": "+3728000044381",
        "hours": "Monday - Friday:09:00 - 17:00 CET+1"
    },
    "España": {
        "phone": "913 496 508",
        "hours": "Lunes-Viernes: 10:00 - 17:00"
    },
   "France": {
        "phone": "01 70 36 35 82",
        "hours": "du lundi au vendredi de 10h00 à 16h30 CET"
    },
    "Ireland":{
        "phone": "1890 812 008",
        "hours": "Monday - Friday: 09:00 - 17:00 GMT"
    },
    "Italia": {
        "phone": "0245281004",
        "hours": "lunedì-venerdì: ore 10:00 - 17:00"
    },
    "Latvija": {
        "phone": "+37180003446",
        "hours": "Monday - Friday: 09:00 - 17:00 CET+1"
    },
     "Lietuva": {
        "phone": "+370880030896",
        "hours": "Monday - Friday: 09:00 - 17:00 CET+1"
    },
    "Luxembourg":{
        "phone": "+33 1 7036 3582",
        "hours": "lundi - vendredi:10h00 - 17h30"
    },
     "Magyarország":{
        "phone": "0036 177 792 27",
        "hours": "hétfő - péntek: 09:00 - 17:30"
    },
    "Nederland": {
        "phone": "020 850 10 07",
        "hours": "Maandag - Vrijdag:09.00 - 18.30"
    },
    "New Zealand": {
        "phone": "0800 450 973",
        "hours": "Monday - Friday: 09:00 - 17:30 NZT"
    },
    "Norway": {
        "phone": "81556710",
        "hours": "Mandag - Fredag: 10:00 til 17:00 GMT+1"
    },
    "Österreich": {
        "phone": "0810102557",
        "hours": "Montag bis Freitag von 10:00 bis 18:30 Uhr MEZ"
    },
    "Polska": {
        "phone": "+48 22 34 91 598",
        "hours": "Poniedziałek - Piątek 09:00 - 16:00"
    },
    "Portugal": {
        "phone": "808781222",
        "hours": "De Segunda à Sexta : Das 09.30 às 17.00 GMT"
    },
     "Poccии": {
         "phone":"007 499 271 3190",
         "hours":"Понедельник - пятница: с 09:00 до 17:30 по московскому времени"
     },
     "Schweiz": {
        "phone": "0844000016",
        "hours": "Mo - Fr:10:00 - 18:30"
    },
     "South Africa": {
        "phone": "0800 980670",
        "hours": "Monday - Friday: 9:00 to 18:00 GMT+1"
    },
     "Suisse": {
        "phone": "0844000091",
        "hours": "lundi - vendredi:10h00 - 16h30 CET"
    },
    "Suomi": {
        "phone": "0303 9038",
        "hours": "Maanantaista - Perjantaihin: 11:00 - 18:00"
    },
    "Sverige": {
        "phone": "077-662-00-10",
        "hours": "Måndag-Fredag: 10:00 - 17:00"
    },
    /*"Svizzera": {
        "phone": "0844000040",
        "hours": "lunedì-venerdì: ore 10:00 - 17:00 CET"
    },*/
    "Türkiye": {
        "phone": "212 356 9707",
        "hours": "Hafta içi her gün: 10:00 - 18:00"
    },
    "UK": {
        "phone": "0845 1610009",
        "hours": "Monday - Friday: <bold>09:00</bold> a.m. to <bold>5:00</bold> p.m. GMT"
    },
    "United States": {
        "phone": "866 486 6866",
        "hours": "Monday - Friday: 7:00 a.m. to 11:00 p.m. EST<br />Saturday: 9:00 a.m. to 8:00 p.m. EST"
    },
    "Ελλάδα": {
        "phone": "0080044144676", //Greek
        "hours": "Δευτέρα - Παρασκευή : 11:00 - 18:00"
    },
    "México":{
      "phone": "800 186 6866",
      "hours": "Lunes-Viernes:7:30 - 18:00<br />Sábado: 8:00-17:00"
    },
    //Morocco
    "Maroc":{
      "phone": "email seulement",
      "hours": ""
    },
    "Other countries": {
        "phone": "+31208501004",
        "hours": "Monday - Friday: 9:00 a.m. to 7:30 p.m. GMT+1"
    }
};
//Receive the cookies locale, and instance id from view.php
function locale2contact(locale, instance_id)
{
    this.element_id=instance_id; //assign the instance id into global variable
    //Build HTML
    /*var html=build_dropdown(locale)+"<h3>"+contact_data[locale]["phone"]+"</h3>";
    html+="<h4>"+contact_data[locale]["hours"]+"</h4>";
    writeContactInfo(html);*/
    
    var html="<img class='phoneIcon' src='http://www.tomtom.com/lib/img/cs/site/call_icon.png' alt=''><h3 style='margin:-20px 0 0 45px;'>"+contact_data[locale]["phone"]+"</h3>";
    html+="<h4>"+contact_data[locale]["hours"]+"</h4>"+build_dropdown(locale);
    writeContactInfo(html);

}
//Build the drop down menu with pre-selected option by using cookies.
function build_dropdown(locale)
{
    var dropdown = '<select name="caller_country" onChange="changeContactInfo(this);">';
    dropdown+='<option value="0">---</option>';
    for (i=0 ; i <countries.length; i++){
        dropdown+='<option value="'+i+'"'+(locale ==countries[i] ? 'selected' : '')+'>' + countries[i]+'</option>';
    }
    dropdown += '</select>';
    return dropdown;
}


// Not smart way in here, once the people select the drop down box, it reselect the drop down menu and reset the contact info
function changeContactInfo(obj)
{
    callinfo=document.getElementById(this.element_id);
    n=obj.value;
    info=callinfo_data[n].split("#");

    var html="<img class='phoneIcon' src='http://www.tomtom.com/lib/img/cs/site/call_icon.png' alt=''><h3 style='margin:-20px 0 0 45px;'>"+info[0]+"</h3>";
    html+="<h4>"+info[1]+"</h4>"+populatePhonelist(n);
    writeContactInfo(html);
    /*var html=populatePhonelist(n)+"<h3>"+info[0]+"</h3>"+"<h4>"+info[1]+"</h4>";
    writeContactInfo(html);*/
    
}

//Build the drop down menu
function populatePhonelist(selected)
{
    var dropdown = '<select name="caller_country" onChange="changeContactInfo(this);">';
    for (i=0 ; i <countries.length; i++){
        dropdown+='<option value="'+i+'"'+(selected ==i ? 'selected': '')+'>' + countries[i]+'</option>';
    }
    dropdown += '</select>';
    return dropdown;
}
//Back to view
function writeContactInfo(html)
{
   details= html;
   document.getElementById(this.element_id).innerHTML = details; //update the instance field in view
}
