var gauche_on = new Image(10, 26); gauche_on.src='/img/nav_gauche_on.gif'
var droite_on = new Image(10, 26); droite_on.src='/img/nav_droite_on.gif';
//var gauche_off = new Image(10, 26); gauche_off.src='/img/nav_gauche_off.gif'
//var droite_off = new Image(10, 26); droite_off.src='/img/nav_droite_off.gif';


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;


var timo = null;
var mdelay = 350;

var def_menu_id = '';

var def_menu = null
var cur_menu = null

function menu_on(item, key, fl_first, fl_last)
{
    item.style.background='#FFB200';

    if ( fl_first ) {
        document.getElementById('gauche').src='/img/nav_gauche_on.gif'
    } else if ( fl_last ) {
        document.getElementById('droite').src='/img/nav_droite_on.gif';
    }

    if ( key ) {
        show_menu(key, item, fl_last);
    }

    return true;
}

function menu_out(item, fl_first, fl_last)
{
    item.style.background='#00396E';

    if ( fl_first ) {
        document.getElementById('gauche').src='/img/nav_gauche_off.gif'
    } else if ( fl_last ) {
        document.getElementById('droite').src='/img/nav_droite_off.gif';
    }

    hide_menu();

    return true;
}

function show_menu(menu_id, anchor, fl_last)
{
    stay_show_menu();

    if ( !cur_menu || cur_menu.id != menu_id )
    {
        if ( cur_menu )
        {
            cur_menu.style.display = 'none';

        } else {
            if ( def_menu ) {
                def_menu.style.display = 'none';
            }
        }

        cur_menu = document.getElementById(menu_id);

        if ( !cur_menu ) return;

        cur_menu.style.display = '';

        if ( parseInt(cur_menu.style.top) < 0 )
        {
            var xy = get_xy(anchor, [0, 29]);
            var ww = 760;
            var w = anchor.offsetWidth + (fl_last ? 10 : 0);
            var mw = cur_menu.clientWidth;
            var mx = xy[0];
            if ( mx + mw > ww ) mx += w - mw;
            if ( mx < 124 ) mx = xy[0];

            cur_menu.style.left = mx;
            cur_menu.style.top = xy[1];

        }
    }

    return true;
}

function stay_show_menu()
{
    if ( timo ) {
        clearTimeout(timo);
        timo = null;
    }

    return true;
}

function hide_menu()
{
    timo = setTimeout('do_hide_menu()', mdelay);

    return true;
}

function do_hide_menu()
{
    if ( cur_menu ) {
        cur_menu.style.display = 'none';
        cur_menu = null;
    }
    if ( def_menu ) {
        def_menu.style.display = '';
    }
}

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;

function show_big_img(img_url)
{
    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;
    }

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


    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()
{
    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;
    }
}

function hide_big_img()
{
    show_top_controls();

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

    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;
}

/***** Layout calendar open *****/

function calendar_start_date(form_name)
{
    Calendar.selectStartDate(
        document.forms[form_name].fld_start_date,
        document.forms[form_name].fld_end_date);
}

function calendar_end_date(form_name)
{
    Calendar.selectEndDate(
        document.forms[form_name].fld_start_date,
        document.forms[form_name].fld_end_date);
}


function show_calendar(form_name, fld_name)
{
    Calendar.popupShow(document.forms[form_name][fld_name]);
}





function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

