﻿function CreateGoogleStoreMap() {

    // Only show GoogleMap if StoreName object can be found.
    //Otherwise we assume that we are not on store page.
    if (document.getElementById("storename")) {
        // Get params from Browser Page

        var name = document.getElementById("storename").getAttribute("value");
        var street = document.getElementById("storeaddress").getAttribute("value");
        var zip = document.getElementById("storezip").getAttribute("value");
        var city = document.getElementById("storecity").getAttribute("value");
        var mapdiv = "map_canvas";

        showAddress(name, street, zip, city, mapdiv);
    }
}

function isInteger(val) {
    if (val == null) {
        return false;
    }

    if (val.length == 0) {
        return false;
    }

    for (var i = 0; i < val.length; i++) {
        var ch = val.charAt(i)
        if (i == 0 && ch == "-") {
            continue
        }
        if (ch < "0" || ch > "9") {
            return false
        }
    }
  return true
}
function CreateGooleMapWithRouteDesc() {

    var mapdiv = "map_canvas";
    var directionsdiv = "directions";

    
    var end_street = document.getElementById("storeaddress").getAttribute("value");
    var end_zip = document.getElementById("storezip").getAttribute("value");
    var end_city = document.getElementById("storecity").getAttribute("value");

    var start_street = document.getElementById("start_street").value;
    var start_zip = document.getElementById("start_zip").value;
    var start_city = document.getElementById("start_city").value;


    var btn = document.getElementsByName("unitDistance");

    
    var valid;
    var unittype;
    for (var x = 0; x < btn.length; x++) {
        valid = btn[x].checked
        if (valid) {
        unittype = btn[x].value; break }
    }

    if (start_street != "") {
        if (start_city != "") {
            if (!isInteger(start_city)) {
                calcRoute(mapdiv, directionsdiv, unittype, start_street, start_zip, start_city, end_street, end_zip, end_city);
            }
            else
                alert("Bynavns feltet kan ikke indeholde postnummer");
        }
        else alert("Indtast venligst både Gade og By");
    }
    
    
}


function CreateGoolePrintMapWithRouteDesc() {
    var mapdiv = "map_canvas";
    var directionsdiv = "directions";

    var end_street = document.getElementById("content_0_storeaddress").getAttribute("value");
    var end_zip = document.getElementById("content_0_storezip").getAttribute("value");
    var end_city = document.getElementById("content_0_storecity").getAttribute("value");

    var start_street = document.getElementById("content_0_start_street").value;
    var start_zip = document.getElementById("content_0_start_zip").value;
    var start_city = document.getElementById("content_0_start_city").value;


    var btn = document.getElementsByName("unitDistance");
    
    var valid
    var unittype;
    for (var x = 0; x < btn.length; x++) {
        valid = btn[x].checked
        if (valid) {
            unittype = btn[x].value; break
        }
    }

    if (start_street != "") {
        if (start_city != "") {
            if (!isInteger(start_city)) {
                calcRoute(mapdiv, directionsdiv, unittype, start_street, start_zip, start_city, end_street, end_zip, end_city);
            }
            else
                alert("Bynavns feltet kan ikke indeholde postnummer");
        }
        else alert("Indtast venligst både Gade og By");
    }


}
function switchMenu(obj1, obj2) {
  
    var el1 = document.getElementById(obj1);
    var el2 = document.getElementById(obj2);
    if (el1.style.display != "none") {
        el1.style.display = 'none';
        el2.style.display = '';
    }
    else {
        el1.style.display = '';
        el2.style.display = 'none';
    }

}





function PrintRouteDesc() {

    var start_street = document.getElementById("start_street").value;
    var start_city = document.getElementById("start_city").value;
    var start_zip = document.getElementById("start_zip").value;
    var storeaddress = document.getElementById("storeaddress").getAttribute("value");
    var storecity = document.getElementById("storecity").getAttribute("value");
    var storezip = document.getElementById("storezip").getAttribute("value");
    window.open("?p=1&start_street=" + start_street + "&start_city=" + start_city + "&start_zip=" + start_zip + "&storeaddress = " + storeaddress + "&storecity=" + storecity + "&storezip=" + storezip, "Rutebeskrivelse", "scrollbars=yes, width=800, height=600, resizable=yes", null);
}

function doquizStyle() {
   hideBox("#box1");
   hideBox("#box2");
    jQuery("select.scfDropList").children().each(function() {
        var val = jQuery(this).html();
        if (val.indexOf("&amp;") != -1) {
            val = val.replace("&amp;#248;", "ø");
            val = val.replace("&amp;#197;", "å");
            val = val.replace("&amp;#71;", "æ");
            if (val.indexOf("ø") == 0)
                val = "Ø" + val.substring(1, val.length);
            if (val.indexOf("æ") == 0)
                val = "Æ" + val.substring(1, val.length);
            if (val.indexOf("å") == 0)
                val = "Å" + val.substring(1, val.length);
            jQuery(this).html(val);
        }

    });

  
    jQuery(".tilmeld").hover(function() { showBox("#box1"); }, function() { hideBox("#box1"); });
    jQuery(".Rules").hover(function() { showBox("#box2"); }, function() { hideBox("#box2"); });
}

function showBox(id) {
    jQuery(id + " .textbox2, " + id + " .textbox1").css("z-index", "999999");
   jQuery(id).show();
}
function hideBox(id) {
    jQuery(id).hide();
    jQuery(id + " .textbox2, " + id + " .textbox1").css("z-index", "0");
}
function ShareOnFacebook(url, title) {

  var fbUrl = "http://www.facebook.com/sharer.php?u=www.damask.dk/konkurrencen.aspx&t=" + encodeURIComponent(title);
    window.open(fbUrl,"");
}








