var winCol = new Date();
function wshow(url, width, height)
{
    if (!width) width = 640;
    if (!height) height = 480;
    window.open(url, (winCol++), 
                'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,width=' 
                + width + 
                ',height=' + height + 
                ',left=' + ((screen.width - width) / 2) + 
                ',top=' + ((screen.height - height) / 2));
    return false;
}
function __get(id) {

    if (document.layers) { return document.layers[id]; }
    if (document.getElementById) { return document.getElementById(id); }       
    if (document.all) { return document.all[id]; }
}
function setTableStyle(tableObject) {

    var topLevel = tableObject.childNodes;
    
    for (var j = 0; j < topLevel.length; j++) {

        if (topLevel[j].nodeName == "TBODY") {

            var nodes;
            nodes = topLevel[j].childNodes;

            for (var i = 0, tr = 0; i < nodes.length; i++) {
                
                if ((nodes[i].nodeName == "TR")
                    && (!nodes[i].className || (nodes[i].className == "ligth") || (nodes[i].className == "dark") || (nodes[i].className == "head"))) {
                    
                    if (tr == 0) { nodes[i].className = 'head'; }
                    else {
                        if (tr % 2) { nodes[i].className = 'ligth'; }
                        else { nodes[i].className = 'dark'; }
                    }
                }
                tr++;
            }
        }
    }
}
function updateTables() {

    var all = document.getElementsByTagName("table");
    for (var i = 0; i < all.length; i++) {
  
        var obj = all[i];
        setTableStyle(obj);
    }
}


// прячет/показывает текстовое поле "Other" в формах "talk_to", "commercial_brochure", "residential_brochure", "schedule_tour"
function showOther() {

    if (typeof(formName) != "undefined") { 
    
        ch = $("#" + formName + "\\[interestedIn\\]\\[6\\]");
    
        $("#" + formName + "\\[other\\]div1").css("display", (ch.attr("checked"))?"block":"none");
        $("#" + formName + "\\[other\\]div2").css("display", (ch.attr("checked"))?"block":"none");
    }
}

function showOtherIam() {

    if (typeof(formNameIam) != "undefined") { 
    
        sel = $("#" + formNameIam + "\\[iam\\]");
        
        $("#" + formNameIam + "\\[otherIam\\]div1").css("display", (sel.attr("value") == 8)?"block":"none");
        $("#" + formNameIam + "\\[otherIam\\]div2").css("display", (sel.attr("value") == 8)?"block":"none");
    }
}


function showsub(type, id) {
    var maxh = $('#submenu_' + id + ' li').length * 19;
    var curh = $('#submenu_' + id).height();
    var speed= 20;
    var time = type ? (maxh - curh) * speed : curh * speed;

    if (time < speed * 2 + 1) time = maxh * speed;

    var hei  = type ? maxh + 'px' : "1px";

    $("#submenu_"+id).stop();
    $("#submenu_"+id + ":hidden").css("height", "1px");
    $("#submenu_"+id).show();
    $("#submenu_"+id).animate({"height": hei}, { queue:false, duration:time }); 
    if (type == 1) {
        $("#topmenu_"+id).addClass('activetext');
    } else {
        $("#topmenu_"+id).removeClass('activetext');
    }
}


$(document).ready(function() {
    $('.menudiviecorrect').hide();
    $('.activeSubmenu').show();

    $('.hiddendiv').hide();
});

var curdiv = -1;
function getPassword(actionURL, id) {
    $('.hiddendiv').hide();
    if (curdiv != id) {
        $('#div'+id).show();
        $('#div'+id + " input").focus();
        curdiv = id;
    } else {
        curdiv = -1;
    }
    $('#getFileForm').attr('action', actionURL);
}

function setPassword(id) {
    $('#password').val($('#inp'+id).val());
    $('.hiddendiv').hide();
    curdiv = -1;
    $('#getFileForm').submit();
}

function slideup() {
    $('#house').animate({ top: "-202px" }, { queue:false, duration:'slow', easing:'linear' });
    $('#picture').animate({ top: "-202px" }, { queue:false, duration:'slow', easing:'linear' });
    $(document).ready(function() {
        $('#house').animate({ top: "-202px" }, { queue:false, duration:'slow', easing:'linear' });
        $('#picture').animate({ top: "-202px" }, { queue:false, duration:'slow', easing:'linear' });
    });
}
function slidedown() {
//    $('#house').animate({ top: "0px" },    { queue:false, duration:'fast', easing:'linear' });
    $('#house').hide();
    $('#picture').hide();
}