// 	Video settings
var conf = {

    // default clip configuration 
    defaults: {
    
        autoPlay: false,
        autoBuffering: true,
        baseUrl: 'http://vesterkopi.net.dynamicweb.dk/Files/Billeder/video',
        
        // functions are also supported 
        onBegin: function(){
        
            // make controlbar visible in 4000 seconds 
            this.getControls().fadeIn(4000);
        }
        
    },
    
    // my skins 
    skins: {
        gray: {
            backgroundColor: '#666666',
            buttonColor: '#333333',
            opacity: 0,
            time: false
        }
    
        // setup additional skins here ...         
    }

}

// Tooltips settings

var supernote = new SuperNote('supernote', {});

// Available config options are:
//allowNesting: true/false    // Whether to allow triggers within triggers.
//cssProp: 'visibility'       // CSS property used to show/hide notes and values.
//cssVis: 'inherit'
//cssHid: 'hidden'
IESelectBoxFix: true / false // Enables the IFRAME select-box-covering fix.
showDelay: 0 // Millisecond delays.
hideDelay: 300
//animInSpeed: 0.1            // Animation speeds, from 0.0 to 1.0; 1.0 disables.
//animOutSpeed: 0.1

// You can pass several to your "new SuperNote()" command like so:
//{ name: value, name2: value2, name3: value3 }


// All the script from this point on is optional!

// Optional animation setup: passed element and 0.0-1.0 animation progress.
// You can have as many custom animations in a note object as you want.
function animFade(ref, counter){
    //counter = Math.min(counter, 0.9); // Uncomment to make notes translucent.
    var f = ref.filters, done = (counter == 1);
    if (f) {
        if (!done && ref.style.filter.indexOf("alpha") == -1) 
            ref.style.filter += ' alpha(opacity=' + (counter * 100) + ')';
        else 
            if (f.length && f.alpha) 
                with (f.alpha) {
                    if (done) 
                        enabled = false;
                    else {
                        opacity = (counter * 100);
                        enabled = true
                    }
                }
    }
    else 
        ref.style.opacity = ref.style.MozOpacity = counter * 0.999;
};
supernote.animations[supernote.animations.length] = animFade;


addEvent(document, 'click', function(evt){
    var elm = evt.target || evt.srcElement, closeBtn, note;
    
    while (elm) {
        if ((/note-close/).test(elm.className)) 
            closeBtn = elm;
        if ((/snb-pinned/).test(elm.className)) {
            note = elm;
            break
        }
        elm = elm.parentNode;
    }
    
    if (closeBtn && note) {
        var noteData = note.id.match(/([a-z_\-0-9]+)-note-([a-z_\-0-9]+)/i);
        for (var i = 0; i < SuperNote.instances.length; i++) 
            if (SuperNote.instances[i].myName == noteData[1]) {
                setTimeout('SuperNote.instances[' + i + '].setVis("' + noteData[2] +
                '", false, true)', 100);
                cancelEvent(evt);
            }
    }
});

addEvent(supernote, 'show', function(noteID){
    // Do cool stuff here!
});
addEvent(supernote, 'hide', function(noteID){
    // Do cool stuff here!
});


// Google Map settings
function ShowMap(dealerID, dealerInfoDivID){
    if (GBrowserIsCompatible()) {
        // initialize google map
        GUnload();
        var point = GetPoint(dealerID);
        var map = new GMap2(document.getElementById("map_canvas"), {
            size: new GSize(740, 400)
        });
        map.setMapType(G_NORMAL_MAP);
        map.setCenter(point, 13);
        // set marker
        var markerIcon = new GIcon(G_DEFAULT_ICON);
        markerIcon.image = "/Files/System/VK2.0/images/vk.png";
        markerIcon.shadow = "/Files/System/VK2.0/images/shadow-vk.png";
        markerIcon.iconSize = new GSize(20, 20);
        map.addOverlay(new GMarker(point, {
            icon: markerIcon
        }));
        
        // set bubble
        map.openInfoWindow(point, document.getElementById(dealerInfoDivID).innerHTML);
        // cusomize UI (remove hybrid and terrain map types)
        var customUI = map.getDefaultUI();
        customUI.maptypes.hybrid = false;
        customUI.maptypes.physical = false;
        map.setUI(customUI);
        //map.setUIToDefault();        
        
        // set content for right panel 
        //$('#map_history')[0].innerHTML = document.getElementById(dealerInfoDivID).innerHTML;
    }
}

function GetPoint(dealerID){
    switch (dealerID) {
        //Aalborg  
        case 12:
            return new GLatLng(57.0236705, 9.8961117);
            break;
        //Århus
        case 11:
            return new GLatLng(56.1536558, 10.2087131);
            break;
        //Carlsberg 
        case 7:
            return new GLatLng(55.6661593, 12.5320954);
            break;
        //Frederiksberg
        case 3:
            return new GLatLng(55.6790618, 12.5335411);
            break;
        //Glostrup
        case 9:
            return new GLatLng(55.6820515, 12.4130067);
            break;
        //Gothersgade 
        case 5:
            return new GLatLng(55.6818949, 12.5837345);
            break;
        //Holmen
        case 6:
            return new GLatLng(55.6814312, 12.6034673);
            break;
        //Nørregade
        case 2:
            return new GLatLng(55.6789458, 12.5720645);
            break;
        //Odense
        case 10:
            return new GLatLng(55.4035182, 10.3991596);
            break;
        //Vesterbrogade 
        case 1:
            return new GLatLng(55.6726865, 12.5512784);
            break;
        //Virum 
        case 8:
            return new GLatLng(55.8008328, 12.4984337);
            break;
            
            
            
        //Vejdirektoratet
        case 18:
            return new GLatLng(56.0474964, 9.9438852);
            break;
        //TDC København 
        case 16:
            return new GLatLng(55.6661593, 12.5320954);
            break;
        //TDC Århus 
        case 17:
            return new GLatLng(56.1092968, 10.1389729);
            break;
        //Københavns Lufthavne A/S (CPH) 
        case 4:
            return new GLatLng(55.6789458, 12.5720645);
            break;
        //Hillerød Kommune
        case 13:
            return new GLatLng(55.9291766, 12.3080953);
            break;
        //Grontmij Carl Bro
        case 14:
            return new GLatLng(55.6820515, 12.4130067);
            break;
		//Ernst & Young  
        case 20:
            return new GLatLng(55.7411113, 12.4908475);
            break;
        //DTU 
        case 19:
            return new GLatLng(55.8008328, 12.4984337);
            break;
        //Alectia 
        case 15:
            return new GLatLng(55.8000491, 12.4963255);
            break;
    }
}

function translateDanishCharacters(str)
{
    return str.replace(/&#229;/g, 'å')
        .replace(/&#230;/g, 'æ')
        .replace(/&#248;/g, 'ø')
        .replace(/&aring;/g, 'å')
        .replace(/&aelig;/g, 'æ')
        .replace(/&oslash;/g, 'ø')        
        .replace(/&#197;/g, 'Å')
        .replace(/&#198;/g, 'Æ')
        .replace(/&#216;/g, 'Ø')
        .replace(/&Aring;/g, 'Å')
        .replace(/&Aelig;/g, 'Æ')
        .replace(/&Oslash;/g, 'Ø');
}

function extendLabelify()
        {
                jQuery.fn.labelify = function(settings) {
          settings = jQuery.extend({
            text: "title",
            labelledClass: ""
          }, settings);
          var lookups = {
            title: function(input) {
              return translateDanishCharacters($(input).attr("title"));
            },
            label: function(input) {
              return translateDanishCharacters($("label[for=" + input.id +"]").text());
            }
          };
          var lookup;
          var jQuery_labellified_elements = $(this);
          return $(this).each(function() {
            if (typeof settings.text === "string") {
              lookup = lookups[settings.text]; // what if not there?
            } else {
              lookup = settings.text; // what if not a fn?
            };
            // bail if lookup isn't a function or if it returns undefined
            if (typeof lookup !== "function") { return; }
            var lookupval = lookup(this);
            if (!lookupval) { return; }

            // need to strip newlines because the browser strips them
            // if you set textbox.value to a string containing them    
            $(this).data("label",lookup(this).replace(/\n/g,''));
            $(this).focus(function() {
              if (this.value === $(this).data("label")) {
                this.value = this.defaultValue;
                $(this).removeClass(settings.labelledClass);
              }
            }).blur(function(){
              if (this.value === this.defaultValue) {
                this.value = $(this).data("label");
                $(this).addClass(settings.labelledClass);
              }
            });
            
            var removeValuesOnExit = function() {
              jQuery_labellified_elements.each(function(){
                if (this.value === $(this).data("label")) {
                  this.value = this.defaultValue;
                  $(this).removeClass(settings.labelledClass);
                }
              })
            };
            
            $(this).parents("form").submit(removeValuesOnExit);
            $(window).unload(removeValuesOnExit);
            
            if (this.value !== this.defaultValue) {
              // user already started typing; don't overwrite their work!
              return;
            }
            // actually set the value
            this.value = $(this).data("label");
            $(this).addClass(settings.labelledClass);

          });
        };

}




/*
// $('select#RequestForm_Leveringsdato_year option').each(function(){if (this.value < 2000) this.parentNode.removeChild(this)});
 	
// $("#RequestForm_Leveringsdato_year option[value='1990', value='1991']").remove();

// $("#RequestForm_Leveringsdato_year").removeOption(/./); // remove all values


RequestForm_Tlf

$('select#RequestForm_Leveringsdato_year')
    .find('option')
    .remove()
    .end()
    .append('<option value="2010">2010</option>')
    .val('2010');



$("#wizard option[value='1990', value='1991']").addClass('debug');

$('#RequestForm_Leveringsdato_year').each(function(){if (this.value < 2000) this.parentNode.removeChild(this)});
*/

//$("#RequestForm_Tlf).addClass('debug');


function extendValidation()
{
    if ($("#FormSave8").length > 0)
    {
        $.validator.addMethod('requiredLabelify', function (value, element)
        {
            return value != '' && translateDanishCharacters(element.title) != value;
        }, 'This field is required');

        $.validator.addMethod('digitsLabelify', function (value, element)
        {
            return /\+|\d|\s|-/.test(value) || translateDanishCharacters(element.title) == value || value == '';
        }, 'Only digits allowed');

        // validation code (test)
        var validator = $("#FormSave8").validate({
            errorPlacement: function(error, element) {
                error.insertBefore( element.parent() );
            },
            rules: { 
                RequestForm_Navn: { requiredLabelify: true }, 
                RequestForm_Mobil: { digitsLabelify: false },
                RequestForm_Tlf: { 
                    requiredLabelify: true,
                    digitsLabelify: true }, 
                RequestForm_Antal_eksemplare: { 
                    requiredLabelify: false,
                    digitsLabelify: true }, 
                RequestForm_Antal_sider_ialt: { 
                    requiredLabelify: false,
                    digitsLabelify: true }, 
                RequestForm_Email: { 
	                requiredLabelify: true, 
	                email: true } 
            },
            messages: {
                RequestForm_Navn: { requiredLabelify: 'Udfyld venligst felt' },
                RequestForm_Tlf: { requiredLabelify: 'Udfyld venligst felt', digitsLabelify: 'Kun tal' },
                RequestForm_Antal_eksemplare: { digitsLabelify: 'Kun tal' },
                RequestForm_Antal_sider_ialt: { digitsLabelify: 'Kun tal' },
                RequestForm_Email: { requiredLabelify: 'Udfyld venligst felt', email: 'Forkert mail format' }
            }
        });
    }
}

function isFormValid(formID, step)
{
    switch (step)
    {
        case 0:
            return $(formID).validate().element("#RequestForm_Navn") & 
                   $(formID).validate().element("#RequestForm_Tlf") &  
                   $(formID).validate().element("#RequestForm_Email");
            break;
        case 1:
            return $(formID).validate().element("#RequestForm_Antal_eksemplare") & 
                   $(formID).validate().element("#RequestForm_Antal_sider_ialt");
            break;
    }
    return true;
}
        
function SubmitFormAsync(formID)
{
    var formElements = $("#" + formID).find("input[checked], input[type='text'], input[type='hidden'], input[type='password'], input[type='submit'], option[selected], textarea")
    var str = '';
    for (i = 0; i < formElements.length; i++)
    {
        str += formElements[i].name + '=' + formElements[i].value + '&';
    }
    
    $.ajax({
        async: true,
        //contentType: 'multipart/form-data',
        type: "POST",
        url: $('#' + formID)[0].action,
        data: str,
        success: function(data)
        {
            alert('sent successfully');
        }
    });
}


