﻿var map;
var geocoder;
var addresses = {
    1: { "zip": "62100", "city": "Brno", "street": "Hudcova 72", "name": "PHARMOS, a.s. Brno", "central": "538 727 211", "sale": "538 727 201-8", "gsm": "606 758 762", "mail": "recepce.brno@pharmos.cz" },
    2: { "zip": "50003", "city": "Hradec Králové", "street": "Kladská 916", "name": "PHARMOS, a.s., Hradec Králové", "central": "498 777 011", "sale": "498 777 001-6", "gsm": "602 11 94 59", "mail": "romana.hankova@pharmos.cz" },
    3: { "zip": "37004", "city": "České Budějovice", "street": "Pekárenská 253/54", "name": "PHARMOS, a.s., České Budějovice", "central": "386 352 200", "sale": "386 352 300", "gsm": "", "mail": "zbynek.hornik@pharmos.cz" },
    4: { "zip": "32600", "city": "Plzeň - Božkov", "street": "K Jezu 32", "name": "PHARMOS, a.s., Plzeň", "central": "377 222 078", "sale": "", "gsm": "724 114 068", "mail": "blanka.paulikova@pharmos.cz", "name2": "Plzeňská lékárnická s.r.o.", "central2": "377 222 078", "sale2": "", "gsm2": "", "mail2": "milan.krabec@pharmos.cz" },
    5: { "zip": "27341", "city": "Brandýsek", "street": "Slánská 79", "name": "PHARMOS, a.s., Brandýsek", "central": "312 777 011", "sale": "312 777 077", "gsm": "606 617 216", "mail": "leona.kosakova@pharmos.cz", "name2": "Pražská lékárnická s.r.o., Brandýsek", "central2": "312 777 011", "sale2": "312 587 581-82", "gsm2": "", "mail2": "jana.losova@pharmos.cz" },
    6: { "zip": "79601", "city": "Prostějov", "street": "Kojetínská 10", "name": "PHARMOS, a.s., Prostějov", "central": "582 777 011", "sale": "582 777 000-5", "gsm": "602 584 294", "mail": "info@pharmos.cz", "name2": "Pharmacy - distribuce léčiv s.r.o.", "central2": "582 777 050", "sale2": "582 777 032, 582 777 018, 582 777 033", "gsm2": "", "mail2": "pharmacy.stbk@pharmos.cz" },
    7: { "zip": "58601", "city": "Jihlava", "street": "Pávovská 73", "name": "PHARMOS, a. s., Jihlava", "central": "", "sale": "", "gsm": "", "mail": "miroslav.dousa@pharmos.cz", "name2": "Jihlavská lékárnická s.r.o., Jihlava", "central2": "567 579 011", "sale2": "567 579 013", "gsm2": "", "mail2": "miroslav.dousa@pharmos.cz" },
    8: { "zip": "71600", "city": "Ostrava - Radvanice", "street": "Těšínská 1349/296", "name": "PHARMOS, a.s., Ostrava", "central": "597 575 211", "sale": "597 575 200", "gsm": "602 715 868", "mail": "info@pharmos.cz", "name2": "Česká lékárnická, a.s.", "central2": "597 575 211", "sale2": "", "gsm2": "", "mail2": "info@pharmos.cz" }
};

/*$(function () {

    setTimeout(changeHeader, 10000);

});*/

function changeHeader1() {
    
    $('#header').removeClass('header1');
    $('#header').removeClass('header2');
    $('#header').removeClass('header3');
    $('#header').removeClass('header4');
    $('#header').removeClass('header5');
    $('#header').removeClass('header6');
        
    var randomnumber = Math.floor(Math.random() * 3) + 1;
        
    $('#header').addClass('header' + randomnumber);

    setTimeout(changeHeader1, 10000);
}

function changeHeader2() {

    $('#header').removeClass('header1');
    $('#header').removeClass('header2');
    $('#header').removeClass('header3');
    $('#header').removeClass('header4');
    $('#header').removeClass('header5');
    $('#header').removeClass('header6');

    var randomnumber = Math.floor(Math.random() * 3) + 4;

    $('#header').addClass('header' + randomnumber);

    setTimeout(changeHeader2, 10000);
}

function initializeMap() {
    // initialize map
    var mapLatlng = new google.maps.LatLng(49.85, 15.41);
    var mapOptions = {
        zoom: 7,
        center: mapLatlng,
        mapTypeId: google.maps.MapTypeId.ROADMAP
    };
    map = new google.maps.Map(document.getElementById("map_canvas"), mapOptions);
    geocoder = new google.maps.Geocoder();

    // add addresses
    for (i = 1; i <= 8; i++) {
        addToMap(addresses[i]);
    }

    // Create the DIV to hold the control and
    // call the HomeControl() constructor passing
    // in this DIV.
    var homeControlDiv = document.createElement('DIV');
    var homeControl = new HomeControl(homeControlDiv, map);

    homeControlDiv.index = 1;
    map.controls[google.maps.ControlPosition.TOP_RIGHT].push(homeControlDiv);
}

function addToMap(address) {
    geocoder.geocode({ 'address': address.street + ',' + address.city }, function (results, status) {
        if (status == google.maps.GeocoderStatus.OK) {
            var latlng = results[0].geometry.location;

            var marker = new google.maps.Marker({
                position: latlng,
                title: address.city,
                zoom: 9
            });

            marker.setMap(map);

            google.maps.event.addListener(marker, 'click', function () {
                map.setZoom(16);
                map.setCenter(marker.position);
                var html = "<table class='wtable'><tr><td colspan=\"2\"><h3>" + address.name + "</h3></td>";
                html = html + "<tr><th>Ústředna:</th> " + "<td>" + address.central + "</td>";
                if (address.sale != "") {
                    html = html + "<tr><th>Prodej:</th> " + "<td>" + address.sale + "</td>";
                }
                if (address.gsm != "") {

                    html = html + "<tr><th>GSM:</th> " + "<td>" + address.gsm + "</td>";
                }
                html = html + "<tr><th>E-mail:</th> " + "<td>" + address.mail + "</td></tr></table>";

                if (address.name2 != undefined) {
                    html = html + "<table class='wtable'><tr><td colspan=\"2\"><h3>" + address.name2 + "</h3></td>";
                    html = html + "<tr><th>Ústředna:</th> " + "<td>" + address.central2 + "</td>";
                    if (address.sale2 != "") {
                        html = html + "<tr><th>Prodej:</th> " + "<td>" + address.sale2 + "</td>";
                    }
                    if (address.gsm2 != "") {

                        html = html + "<tr><th>GSM:</th> " + "<td>" + address.gsm2 + "</td>";
                    }
                    html = html + "<tr><th>E-mail:</th> " + "<td>" + address.mail2 + "</td></tr></table>";
                }

                html = html + "<div class=\"clear\"></div><h3>Adresa</h3>";
                html = html + address.zip + ", " + address.city + "<br>" + address.street + "<br>";


                html = html + "<br>";

                $('#contacts').html(html);
            });

        }
    });
}




function Set_Cookie( name, value, expires, path, domain, secure )
{
    // set time, it's in milliseconds
    var today = new Date();
    today.setTime( today.getTime() );

    if ( expires )
    {
    expires = expires * 1000 * 60 * 60 * 24;
    }
    var expires_date = new Date( today.getTime() + (expires) );

    document.cookie = name + "=" +escape( value ) +
    ( ( expires ) ? ";expires=" + expires_date.toGMTString() : "" ) +
    ( ( path ) ? ";path=" + path : "" ) +
    ( ( domain ) ? ";domain=" + domain : "" ) +
    ( ( secure ) ? ";secure" : "" );
}

function Get_Cookie( name ) {

    var start = document.cookie.indexOf( name + "=" );
    var len = start + name.length + 1;
    if ( ( !start ) &&
    ( name != document.cookie.substring( 0, name.length ) ) )
    {
    return null;
    }
    if ( start == -1 ) return null;
    var end = document.cookie.indexOf( ";", len );
    if ( end == -1 ) end = document.cookie.length;
    return unescape( document.cookie.substring( len, end ) );
}

function zmen(adresa) {
    document.lform.action = adresa;
    action = document.lform.action;
    if (action == 'http://shop.pharmos.cz/login.php') {
        changeeshop();
    } else {
        changebonus();
    }
}
      
function odeslatFormular() {      
    action = document.lform.action;
    if (action == 'http://vyberte/') {
        alert('Vyberte prosím aplikaci, na kterou se chcete přihlásit.');
    } else {
        if (document.lform.save.checked == true) {
            if (action == 'http://shop.pharmos.cz/login.php') {
                Set_Cookie('usrshop', document.lform.username.value, 365, '/', '', ''); 
                Set_Cookie('pdshop', document.lform.pd.value, 365, '/', '', ''); 
            } else {
                Set_Cookie('usrbonus', document.lform.username.value, 365, '/', '', ''); 
                Set_Cookie('pdbonus', document.lform.pd.value, 365, '/', '', ''); 
            }
        } else {
            if (action == 'http://shop.pharmos.cz/login.php') {
                Set_Cookie('usrshop', '', 365, '/', '', ''); 
                Set_Cookie('pdshop', '', 365, '/', '', ''); 
            } else {
                Set_Cookie('usrbonus', '', 365, '/', '', ''); 
                Set_Cookie('pdbonus', '', 365, '/', '', ''); 
            }
        }
        document.forms[0].submit(); 
    }
}
      
function changeeshop() {
    usr = Get_Cookie('usrshop');
    pd = Get_Cookie('pdshop');
         
    //usr2 = document.lform.username.value;
    //pd2 = document.lform.pd.value;
         
    if (usr != null && usr != '' && pd != '' && pd != null) {
    document.lform.save.checked = true;
    document.lform.username.value = usr;
    document.lform.pd.value = pd;
    } else {
    document.lform.save.checked = false;
    }
         
    test = document.lform.choose;
    test.selectedIndex = 2;
    document.lform.action = 'http://shop.pharmos.cz/login.php';
}
      
function changebonus() {
    usr = Get_Cookie('usrbonus');
    pd = Get_Cookie('pdbonus');
         
    //usr2 = document.lform.username.value;
    //pd2 = document.lform.pd.value;
         
    if (usr != null && usr != '' && pd != '' && pd != null) {
    document.lform.save.checked = true;
    document.lform.username.value = usr;
    document.lform.pd.value = pd;
    } else {
    document.lform.save.checked = false;
    }
         
    test = document.lform.choose;
    test.selectedIndex = 1;
    document.lform.action = 'http://bonuskonto.pharmos.cz/web/?action=login&do=form-submit&presenter=Login';
}

function show(selector) {
    if ($(selector).is(":visible")) {
        $(selector).fadeOut(1000);    
    } else {
        $(selector).fadeIn(1000);    
    }
}

function HomeControl(controlDiv, map) {

    // Set CSS styles for the DIV containing the control
    // Setting padding to 5 px will offset the control
    // from the edge of the map
    controlDiv.style.padding = '5px';
    //controlDiv.id = "reset";

    // Set CSS for the control border
    var controlUI = document.createElement('DIV');
    controlUI.style.backgroundColor = 'white';
    controlUI.style.borderStyle = 'solid';
    controlUI.style.borderWidth = '2px';
    controlUI.style.cursor = 'pointer';
    controlUI.style.textAlign = 'center';
    controlUI.title = 'Click to set the map to Home';
    controlDiv.appendChild(controlUI);

    // Set CSS for the control interior
    var controlText = document.createElement('DIV');
    controlText.style.fontFamily = 'Arial,sans-serif';
    controlText.style.fontSize = '12px';
    controlText.style.paddingLeft = '4px';
    controlText.style.paddingRight = '4px';
    controlText.innerHTML = '<b id="reset">Reset</b>';
    controlUI.appendChild(controlText);

    // Setup the click event listeners: simply set the map to
    // Chicago
    
    google.maps.event.addDomListener(controlUI, 'click', function () {
        var mapLatlng = new google.maps.LatLng(49.85, 15.41);
        map.setCenter(mapLatlng);
        map.setZoom(7);
        $('#contacts').html("");
    });

    
}
