function toggleOpenMenu(item_id)
{
    $(item_id + '_open').style.display = 'none';
    $(item_id).style.display = 'block';
    return false;
}

function toggleMenu(item_id)
{
    $(item_id + '_open').style.display = 'block';
    $(item_id).style.display = 'none';
   /* jq( '#'+item_id+'_open').slideToggle( '100' );
    jq( '#'+item_id+'_link' ).toggle( );
   // return false;
	
	jq( '#'+item_id+'_open').slideToggle( '100', function() {
		
	});*/
}

function setOver(obj)
{
    obj.className = obj.className.replace('new_no', 'new_over');
}

function setOut(obj)
{
    obj.className = obj.className.replace('new_over', 'new_no')
}

function showImage(pic)
{
    image = new Image();
    image.onload = function(){opw(pic, image.width, image.height);}
    image.src = pic;
}
function opw(pic,w,h) {
var x = "width=" + w + ",height=" + h + ";";
var ww = window.open("", "ww1", config=x);
if (pic.substr(0, 7) != 'http://' && pic.substr(0, 1) != '/') pic = '/' + pic;
ww.document.write("<html><head></head><body style='margin:0;padding:0;' onclick='self.close();'><img src='" + pic + "' alt=''></body></html>");
ww.document.close();
self.name="main";
}

//////////////////////////////////
function fieldChanged(obj)
{
    init_fields();
    return true;
}

function checkAll(obj)
{
    if (obj.value == 0) {
        for (i = 1; i < $('gfilter_form').elements[obj.name].length; i++) {
            $('gfilter_form').elements[obj.name][i].checked  = obj.checked;
            $('gfilter_form').elements[obj.name][i].disabled = obj.checked ? true : false;
        }
        return false;
    }
}

function toggleShown(obj_id, show)
{
//    alert(obj_id);
    //$(obj_id).disabled = show == 1 ? false : true;
//    alert(obj_id + ' -> ' + show);
    if (obj_id == undefined) return;
    $(obj_id  + '_div').style.display = show ? '' : 'none';
    if ($(obj_id + '_b')) $(obj_id + '_b').style.display = show ? '' : 'none';
}

function hide_field(obj_id)
{
    toggleShown(obj_id, 0);
}

function show_field(obj_id)
{
    toggleShown(obj_id, 1);
}

function dump(obj)
{
    msg = new Array();
    for (i in obj) {
        
        if (typeof(obj[i]) == 'object') {
            msg.push(obj[i].name + ': ' + obj[i]);
        } else {
            msg.push(i + ': ' + obj[i]);
        }
    }
    alert(msg.join("\n"));
}

otypes = new Array('otype_parch', 'otype_arch', 'otype_int', 'otype_pint');
perses = new Array('sq', 'nos', 'mtype');

function init_fields()
{
    if (!$('gfilter_form')) return;
    //show($('gfilter_form').elements);
    //if (!$('gfilter_form').elements['mtype']) return;
    
        
    isarch = $('gfilter_form').elements['isarch'][0].value == 1 ? 1 : 0;
    ispers = $('gfilter_form').elements['ispers'][0].checked ? 1 : 0;
    
    //alert($('gfilter_form').elements['isarch'][0].value);
    
    atype  = 'otype_' + (ispers ? 'p' : '') + (isarch ? 'arch' : 'int');
    
    for (i = 0; i < otypes.length; i++) {
        if (otypes[i] == atype) show_field(otypes[i]); else hide_field(otypes[i]);
    }
    
    for (i = 0; i < perses.length; i++) {
        if (ispers) show_field(perses[i]); else hide_field(perses[i]);
    }
}

function po_fieldChanged(obj)
{
    po_init_fields();
    return true;
}


function po_init_fields()
{
    if (!$('gal_form')) return;
    if (!$('gal_form').elements['mtype']) return;
    isarch = $('gal_form').elements['isarch'][0].checked ? 1 : 0;
    ispers = $('gal_form').elements['ispers'][0].checked ? 1 : 0;
    atype  = 'otype_' + (ispers ? 'p' : '') + (isarch ? 'arch' : 'int');
    otype  = $(atype).value;
    for (i = 0; i < otypes.length; i++) {
        if (otypes[i] == atype) show_field(otypes[i]); else hide_field(otypes[i]);
    }
    
    for (i = 0; i < perses.length; i++) {
        if (ispers) show_field(perses[i]); else hide_field(perses[i]);
    }
}

function toggleDispl(id)
{
    obj = $(id);
    obj.style.display = obj.style.display == 'none' ? '' : 'none';
    return false;
}


imagesArray = new Array();

function loadGalleryImages(iArray)
{
    imagesArray = iArray;
}

function showGalleryImage(image)
{
    alert(window.scrollTop);
    $('popup').style.offsettop = '0px';
    $('popup').style.display = 'block';
    alert($('popup').offsetTop);
    
    return false;
}

function _showGalleryImage(image)
{

}

function closeGalleryPopUp()
{
    $('popup').style.display = 'none';
    return false;
}

addEvent(window, 'load', init_fields);
addEvent(window, 'load', po_init_fields);

