
var ua=navigator.userAgent.toLowerCase();
var KO = ua.match(/konqueror\/(\d+)/);
var KO3 = KO && KO[1] == 3;
//var SA = ua.match(/safari\/(\d+)/)
//var SA1 = SA && SA[1]<86;
//KO=!!KO; SA=!!SA;
//var MAC = /mac/.test(ua);
//var OP = !!self.opera;
//var WEBTV = /webtv/.test(ua);
//var IE = /msie/.test(ua) && !OP && !WEBTV && !SA && !KO;
//var GK = /gecko/.test(ua)
//var OP8 = /opera 8/.test(ua) && OP;
//var NN4 = IE4 = NS6 = false;
//var IE5 = IE && ![].push && !IE4;

function dm(msgStr) {
    window.status = msgStr;
    document.MM_returnValue = true;
}

/* Function that swaps images. */

function di20(id, newSrc) {
    var theImage = FWFindImage(document, id, 0);
    if (theImage) {
        theImage.src = newSrc;
    }
}

/* Functions that track and set toggle group button states. */

function FWFindImage(doc, name, j) {
    var theImage = false;
    if (doc.images) {
        theImage = doc.images[name];
    }
    if (theImage) {
        return theImage;
    }
    if (doc.layers) {
        for (j = 0; j < doc.layers.length; j++) {
            theImage = FWFindImage(doc.layers[j].document, name, 0);
            if (theImage) {
                return (theImage);
            }
        }
    }
    return (false);
}

function open_popup(url, w, h)
{
    var str="toolbar=no, menubar=no, directories=no, resizable=yes, scrollbars=auto, width="
      + w + ", height=" + h;
    objWindow = window.open(url, '', str);
    objWindow.focus();
}

function print_page()
{
    var url = location.href;
    if ( url.indexOf('?') > 0 ) {
        url += '&forprinting';
    } else {
        url += '?forprinting';
    }

    var params = "toolbar=yes, menubar=yes, directories=no, resizable=yes, scrollbars=auto, width="
      + window.screen.width + ", height=" + window.screen.height;
      + ', top=' + 0  + ', left=' + 0;

    objWindow = window.open(url, 'print', params);
    objWindow.focus();
    objWindow.print();
}

function get_win_size(w)
{
	if ( w.innerWidth ) {
		return [w.innerWidth-16, w.innerHeight, w.pageXOffset, w.pageYOffset];
	} else if ( w.document.compatMode=='CSS1Compat' ) {
		with ( w.document.documentElement ) {
		    return [clientWidth,clientHeight,scrollLeft,scrollTop];
        }
	} else {
		with ( w.document.body ) {
		    return [clientWidth,clientHeight,scrollLeft,scrollTop];
        }
    }
}

function get_xy(a, offset)
{
	var p = offset ? offset.slice(0) : [0,0];
    var tn;

	while ( a )
	{
		tn = a.tagName.toUpperCase();
		p[0] += a.offsetLeft - (!KO3 && tn=="DIV"
		    && (a.scrollLeft ? a.scrollLeft : 0));
		p[1] += a.offsetTop - (!KO3 && tn=="DIV"
		    && (a.scrollTop ? a.scrollTop : 0));

		if ( tn=="BODY" ) break;
		a = a.offsetParent;
	}

	return p;
}


/*********** Big Image View ***********/

var bidiv = null;
var bitable = null;
var bidiv_l = 0;
var bidiv_t = 0;
var bimg = null;

var biwidth = null;
var biheight = null;

/*
var winw = 0;
var winh = 0;
var scrollw = 0;
var scrollh = 0;
*/

var winsize = null;

var img_cash = new Image;
var timo = null;

var resw = 0;
var resh = 0;

var descrtext = '';

function show_big_img(img_url, descr_text)
{
    descrtext = descr_text;

    if ( !bidiv ) {
        bidiv = document.getElementById('big_img_div');
        if ( !bidiv ) return;
    }

    if ( !bitable ) {
        bitable = document.getElementById('big_img_table');
        if ( !bitable ) return;
    }

    if ( !biwidth ) {
        biwidth = document.getElementById('bi_width');
        if ( !biwidth ) return;
    }

    if ( !biheight ) {
        biheight = document.getElementById('bi_height');
        if ( !biheight ) return;
    }

    if ( !bimg ) {
        bimg = document.getElementById('big_img');
        if ( !bimg ) return;
    }

    if ( !descr ) {
        descr = document.getElementById('descr');
        if ( !descr ) return;
    }

    winsize = get_win_size(window);
    /* */
    winsize[1]-=30;
    bidiv_t = winsize[3] + parseInt((winsize[1] - 100) / 2);
    bidiv_l = winsize[2] + parseInt((winsize[0] - 100) / 2);

    descr.style.visibility = "hidden";
    descr.style.width = 0;
    descr.innerHTML = '';

    bidiv.style.zIndex = 65535;
    bidiv.style.top = bidiv_t;
    bidiv.style.left = bidiv_l;
    bidiv.style.width = '100px';
    bidiv.style.height = '100px';
    bidiv.style.visibility = "visible";

    bimg.src = '/img/shim.gif';
    bimg.width = 32;
    bimg.height = 32;

    biwidth.width = 84;
    biheight.height = 72;

    img_cash.onload = display_img;
    img_cash.src = img_url;
}

function display_img()
{
    hide_top_controls()

    if ( !bidiv ) return;
    if ( !bitable ) return;
    if ( !biwidth ) return;
    if ( !biheight ) return;
    if ( !bimg ) return;

    setTimeout('resize_img_div()', 20);

    resw = img_cash.width;
    resh = img_cash.height;

}

function resize_img_div(descr_text)
{
    if ( bidiv.style.visibility != "visible" ) return;

    var w = parseInt(biwidth.width) + 10;
    var h = parseInt(biheight.height) + 10;

    if ( w > resw ) w = resw;
    if ( h > resh ) h = resh;

    if ( biwidth.width != w ) {
        biwidth.width = w;
        if ( bidiv_l > 0 ) {
            bidiv_l = parseInt((winsize[0] - w - 16) / 2);
            if ( bidiv_l < 0 ) bidiv_l = 0;
            bidiv_l += winsize[2];
            bidiv.style.left = bidiv_l + 'px';
        }
    }

    if ( biheight.height != h ) {
        biheight.height = h;
        if ( bidiv_t > 0 ) {
            bidiv_t = parseInt((winsize[1] - h - 28) / 2);
            if ( bidiv_t < 0 ) bidiv_t = 0;
            bidiv_t += winsize[3];
            bidiv.style.top = bidiv_t + 'px';
        }
    }

    if ( w < resw || h < resh )
    {
        setTimeout('resize_img_div()', 20);
    }
    else
    {
        bimg.src = img_cash.src;
        bimg.width = img_cash.width;
        bimg.height = img_cash.height;
	descr.style.width = img_cash.width;
        descr.innerHTML = descrtext;
        descr.style.visibility = "visible";
    }
}

function hide_big_img()
{
    show_top_controls();

    if ( !bidiv ) return;
    if ( !bitable ) return;
    if ( !bimg ) return;

    descr.style.visibility = "hidden";
    descr.style.width = 0;
    descr.innerHTML = '';

    bimg.src = '/img/shim.gif';
    bimg.width = 32;
    bimg.height = 32;

    bidiv.style.zIndex = 0;
    bidiv.style.top = -1000;
    bidiv.style.left = -1000;
    bidiv.style.visibility = "hidden";
}

function hide_top_controls()
{
    hidden_top_controls = document.getElementsByTagName('select');
    for ( var i = 0; i < hidden_top_controls.length; i++  )
    {
        if ( hidden_top_controls.item(i).style.visibility = "visible" )
        {
            hidden_top_controls.item(i).style.visibility = "hidden";
        } else {
            hidden_top_controls.item(i) = null;
        }
    }
}

function show_top_controls()
{
    if ( !hidden_top_controls ) return;

    for ( var i = 0; i < hidden_top_controls.length; i++  )
    {
        if ( hidden_top_controls.item(i) ) {
            hidden_top_controls.item(i).style.visibility = "visible";
        }
    }

    hidden_top_controls = null;
}

/***** for auto created JS form check *****/

function check_array_empty(form, name, type)
{
    for ( var i = 0; i < form[name].length; i++ )
    {
        if ( type ) {
            if ( form[name][i].checked ) return 0;
        } else {
            if ( form[name][i].value.length > 0 ) return 0;
        }
    }

    return 1;
}

