﻿//Open a popup window for the editor
function openPopupCMS(url) {
    width = 580;
    height = 390;
    x = parseInt(screen.width / 2.0) - (width / 2.0);
    y = parseInt(screen.height / 2.0) - (height / 2.0);

    var win = window.open(url, "editorPopup", "top=" + y + ",left=" + x + ",scrollbars=yes,dialog=yes,minimizable=no,modal=yes,width=" + width + ",height=" + height + ",resizable=no");
}

function flip() {

    if (document.getElementById("sales").checked) {
        document.getElementById("quicksearch").innerHTML = "";
        document.getElementById("searchscript").innerHTML = "";

        var s = document.createElement("script");
        s.type = "text/javascript";
        s.src = "http://testwww.vebra.com/stagsnew/property/quicksearch/1.js";
        document.getElementById("searchscript").appendChild(s);
    } else {
        document.getElementById("quicksearch").innerHTML = "";
        document.getElementById("searchscript").innerHTML = "";

        var s = document.createElement("script");
        s.type = "text/javascript";
        s.src = "http://testwww.vebra.com/stagsnew/property/quicksearch/2.js";
        document.getElementById("searchscript").appendChild(s);
    }

    /* Change default id / name so asp link buttons work. Only works if you have sales OR lettings quicksearch */
    //submitButton.setAttribute("id", "qsSubmit");
    //submitButton.setAttribute("name", "qsSubmit");
}

function gotoURL(url) {
    window.location.href = url;
}

//Open a popup window for the cropper
function openPopupCrop(url) {
    width = 600;
    height = 775;
    x = parseInt(screen.width / 2.0) - (width / 2.0);
    y = parseInt(screen.height / 2.0) - (height / 2.0);

    var win = window.open(url, "editorPopup", "top=" + y + ",left=" + x + ",scrollbars=yes,dialog=yes,minimizable=no,modal=yes,width=" + width + ",height=" + height + ",resizable=no");
}


function addOnLoadEvent(func) {
    var oldOnLoad = window.onload;

    if (typeof window.onload == 'function') {
        window.onload = function() {
            if (oldOnLoad) oldOnLoad();
            func();
        }
    }
    else {
        window.onload = func;
    }
}

// Login form functions
function myStagsOver(img) { img.src = "http://stags.co.uk/images/btn_go_to_my_stags_dn.png" }
function myStagsOut(img) { img.src = "http://stags.co.uk/images/btn_go_to_my_stags.png" }
function createProfileOver(img) { img.src = "http://stags.co.uk/images/btn_create_new_profile_dn.png" }
function createProfileOut(img) { img.src = "http://stags.co.uk/images/btn_create_new_profile.png" }
function loginOver(img) { img.src = "http://stags.co.uk/images/btn_log_in_dn.png" }
function loginOut(img) { img.src = "http://stags.co.uk/images/btn_log_in.png" }
function logoutOver(img) { img.src = "http://stags.co.uk/images/btn_log_out_dn.png" }
function logoutOut(img) { img.src = "http://stags.co.uk/images/btn_log_out.png" }

function isLoggedIn() {
    var name = "ASPXAUTH";
    var nameEQ = name + "=";
    var ca = document.cookie.split(';');
    for (var i = 0; i < ca.length; i++) {
        var c = ca[i];
        while (c.charAt(0) == ' ') c = c.substring(1, c.length);
        if (c.indexOf(nameEQ) == 1) return true;
    }
    return false;
}

function setLoginTarget() {

    var img = document.getElementById("LogInOut");
    var logLink = document.getElementById("LoginLink")
    if (img && logLink) {
        if (isLoggedIn()) {
            img.src = "http://stags.co.uk/images/btn_log_out.png";
            img.alt = "Log Out";
            img.className = "imgLogOut";
            img.onmouseover = function() { logoutOver(img) };
            img.onmouseout = function() { logoutOut(img); } 
            logLink.href = "http://www.vebra.com/stagsnew/myprofile/logout";
        }
    }
}

addOnLoadEvent(setLoginTarget);

