function ShowToolTip(elementid,status,text) {
    if (status == "on") {
        document.getElementById(elementid).style.backgroundColor = "#EBF4FF";
        document.getElementById('ToolTip').style.visibility="visible";
        document.getElementById('ToolTip').style.backgroundColor = "#EBF4FF";
        document.getElementById('ToolTip').innerHTML = text;
    } else {
        document.getElementById(elementid).style.backgroundColor = "#FFFFFF";
        document.getElementById('ToolTip').style.visibility="hidden";
        document.getElementById('ToolTip').style.backgroundColor = "#FFFFFF";
        document.getElementById('ToolTip').innerHTML = text;
        
        
    }
}

function PrintFriendly(propertyID) {
    PrintWindow = window.open('/property.php?propertyID=' + propertyID + '&pf=1' ,'PrintWindowName','width=700,height=500,toolbar=0,menubar=0,scrollbars=1,resizeable=1');
    PrintWindow.focus();
}

function ShowPlan(propertyID,width,height) {
    PlanWindow = window.open('/property.php?propertyID=' + propertyID + '&showplan=1' ,'PlanWindowName','width='+(width+25)+',height='+(height+50)+',toolbar=0,menubar=0,scrollbars=1,resizeable=1');
    PlanWindow.focus();
}

function AddFavorite(propertyID) {

    if (parseInt(navigator.appVersion)>3) {
        if (navigator.appName=="Netscape") {
            winW = window.innerWidth;
            winH = window.innerHeight;
        }
        if (navigator.appName.indexOf("Microsoft")!=-1) {
            winW = document.body.offsetWidth;
            winH = document.body.offsetHeight;
        }
    }


    var popW = 300, popH = 200;
    var leftPos = (winW-popW)/2;
    var topPos = (winH-popH)/2;

    FavoriteWindow = window.open('/favorites.php?propertyID=' + propertyID ,'FavoriteWindowName','width=' + popW + ',height=' + popH + ',top=' + topPos + ',left=' + leftPos + ',toolbar=0,menubar=0,scrollbars=0,resizeable=1');
    FavoriteWindow.focus();
}

function ShowBig(fileID,width,height) {
    BigWindow = window.open('/property.php?fileID=' + fileID + '&showbig=1','BigWindowName','width='+(width+17)+',height=810,toolbar=0,menubar=0,scrollbars=0,resizeable=0');
    BigWindow.focus();
}

function SelectCurrency() {
    CurrencyWindow = window.open('/property.php?currencyselect=1','BigWindowName','width=300,height=200,toolbar=0,menubar=0,scrollbars=0,resizeable=0');
    CurrencyWindow.focus();
}

function SaveCurrency(object) {
    var selectedID = 0;
    for (var i = 0 ; i < object.selectedcurrency.length; i++) {
        if (object.selectedcurrency[i].checked) {
            selectedID = object.selectedcurrency[i].value;
        }
    }
    var today = new Date();
    var expires = new Date(today.getTime() + (60000 * 60 * 24 * 356));
    Set_Cookie("UserSelectedCurrency",selectedID,expires,"/","");
    opener.location.reload();
    window.close();
}

function CloseFavoriteWindow() {
    opener.location.reload();
    window.close();
}

String.prototype.isEmail = function () {
    validmailregex = /^[-a-z0-9~!$%^&*_=+}{\'?]+(\.[-a-z0-9~!$%^&*_=+}{\'?]+)*@([a-z0-9_][-a-z0-9_]*(\.[-a-z0-9_]+)*\.([a-z][a-z]+)|([0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}))(:[0-9]{1,5})?$/i
    return validmailregex.test(this);
}

var infowindow;
function loadMap(elementName,centerLat,centerLng,zoomLevel,markerLat,markerLng,extraMarkers) {
    var latLng = new google.maps.LatLng(parseFloat(centerLat),parseFloat(centerLng));

    var options = {
        zoom: parseInt(zoomLevel),
        center: latLng,
        mapTypeId: google.maps.MapTypeId.ROADMAP
    };

    var markers = {};
    var infowindows = {};

    map = new google.maps.Map($(elementName),options);
    if (markerLat && markerLng) {

        var marker = new google.maps.Marker({position:new google.maps.LatLng(parseFloat(markerLat),parseFloat(markerLng)),icon:'/images/gmap/marker_red.png'});
        marker.setMap(map);

        if (extraMarkers) {
            for (var data in extraMarkers) {
                var positions = extraMarkers[data]['position'].split(',');
                var htmlContent = '';
                if (extraMarkers[data]['image'] != null) {
                    if (extraMarkers[data]['image'].length > 0) {
                        htmlContent += '<img style="margin-bottom:5px" src="' + extraMarkers[data]['image'] + '">';
                    }
                }
                if (extraMarkers[data]['name'] != null) {
                    htmlContent += '<div class="infowindow_header"><a target="_blank" href="' + extraMarkers[data]['url'] + '">' + extraMarkers[data]['name'] + '</a></div>';
                    htmlContent += '<div class="infowindow_content">' + extraMarkers[data]['intro'] + '</div>';
                }

                var marker = createMarker(map, htmlContent, new google.maps.LatLng(parseFloat(positions[0]),parseFloat(positions[1])));
                marker.setMap(map);
            }
        }
    }
}

function createMarker(map, htmlContent, latlng) {
    var marker = new google.maps.Marker({position: latlng, map: map,icon:'/images/gmap/marker_blue.png'});
    google.maps.event.addListener(marker, "click", function() {
        if (htmlContent) {
            if (infowindow) infowindow.close();
            infowindow = new google.maps.InfoWindow({content: htmlContent,maxWidth:'200'});
            infowindow.open(map, marker);
        }
    });
    return marker;
}

function ShowBigAreaMap(areaID) {
    BigWindow = window.open('/areas.php?areasID=' + areaID + '&mode=showbigmap','BigWindowName','width=800,height=600,toolbar=0,menubar=0,scrollbars=0,resizeable=0');
    BigWindow.focus();
}

function ShowBigArticleMap(articleID) {
    BigWindow = window.open('/articles.php?articlesID=' + articleID + '&mode=showbigmap','BigWindowName','width=800,height=600,toolbar=0,menubar=0,scrollbars=0,resizeable=0');
    BigWindow.focus();
}

function ShowBigCategoryMap(categoryID) {
    BigWindow = window.open('/categories_new.php?categoryID=' + categoryID + '&mode=showbigmap','BigWindowName','width=800,height=600,toolbar=0,menubar=0,scrollbars=0,resizeable=0');
    BigWindow.focus();
}

function CheckEmail(form,field)  {
    url = document[form][field].value
    var status = true;
    if (url != null && url != "") {
        a = url.lastIndexOf("@");
        b = url.lastIndexOf(".");
        c = url.indexOf(":");
        d = url.indexOf("/");
        e = url.substring(0,a);
        f = e.indexOf("@");
        g = url.substring(a+1,url.length);
        h = g.indexOf("[");
        i = g.indexOf("]");
        j = g.indexOf("<");
        k = g.indexOf(">");
        l = url.substring(a+1,b);
        m = url.substring(b+1,url.length);
        n = url.substring(0,a);
        o = 0;
        if (a > b) {o++};
        if (c != -1) {o++};
        if (d != -1) {o++};
        if (f != -1) {o++};
        if (h != -1) {o++};
        if (i != -1) {o++};
        if (j != -1) {o++};
        if (k != -1) {o++};
        if (l.length < 1) {o++};
        if (m.length < 2 || m.length > 4) {o++};
        if (n.length < 1) {o++};
        if (o == 0) {
            status = true;
        }
        else {
            status = false;
        }
    }
    else {
        status = false;
        url="";
    }
    return status;
}

function initializeCaptcha(language) {
    var RecaptchaOptions = {
        lang : language,
        theme : 'red'
    };
    
    if (language == 'da') {
        RecaptchaOptions['custom_translations'] = 
        {
            instructions_visual : "Skriv de to ord:",
            instructions_audio : "Skriv her, hvad du har hørt:",
            play_again : "Afspil lyd igen",
            cant_hear_this : "Download lyd som MP3",
            visual_challenge : "Læs ordene",
            audio_challenge : "Lyt til ordene",
            refresh_btn : "Opdater",
            help_btn : "Hjælp (engelsk)",
            incorrect_try_again : "Ikke korrekt. Prøv igen."
        };
    }
    return RecaptchaOptions;
}
