_IE6 = false;
if(navigator.userAgent.indexOf("MSIE 7") != -1)
_IE7 = true;
else if(navigator.userAgent.indexOf("MSIE 6") != -1)
_IE6 = true;
else if(navigator.userAgent.indexOf("Firefox/2") != -1)
_FIREFOX2 = true;
else if(navigator.userAgent.indexOf("Firefox") != -1)
_FIREFOX = true;
else if(navigator.userAgent.indexOf("Netscape/7") != -1)
_NETSCAPE7 = true;
else if(navigator.userAgent.indexOf("Netscape") != -1)
_NETSCAPE = true;
else if(navigator.userAgent.indexOf("Opera/9") != -1)
_OPERA9 = true;
else if(navigator.userAgent.indexOf("Opera") != -1)
_OPERA = true;
else
_AUTRE = true;

/* VERY USEFUL ! 
* Returns the value of the selected radio button in the radio group, null if
* none are selected, and false if the button group doesn't exist
*
* @param {radio Object} or {radio id} el
* OR
* @param {form Object} or {form id} el
* @param {radio group name} radioGroup
*/
function $RF(el, radioGroup) {
    if($(el).type && $(el).type.toLowerCase() == 'radio') {
        var radioGroup = $(el).name;
        var el = $(el).form;
    } 
    else if ($(el).tagName.toLowerCase() != 'form') {
        return false;
    }

    var checked = $(el).getInputs('radio', radioGroup).find(
            function(re) {return re.checked;}
            );
    return (checked) ? $F(checked) : null;
}

// Functions on arrays ! (Extension of the Array class)
Object.extend(Array.prototype, {remove: ArrayRemove});
 function ArrayRemove(val) {
  var tmparr = new Array();
  for (var i=0; i<this.length; i++) if (this[i] != val) tmparr[tmparr.length] = this[i];
   return tmparr;
 }

function string_is_a_date(str, sep)
{
    if (!sep) { var sep = '/'; }
    var pattern = new RegExp('[0-3]?[0-9]' + sep + '0|1?[0-9]' + sep + '19|20[0-9]{2}');
    if (!str.match(pattern)) { alert('Date format not valid. Please use "dd/mm/yyyy" format.'); return false; }
    var tab = str.split(sep);
    if (tab.length != 3) return false;

    var day = tab[0];
    var month = tab[1] - 1;
    var year = tab[2];
    var source_date = new Date(year, month, day);
    if(year != source_date.getFullYear() || month != source_date.getMonth() || day != source_date.getDate())
    {
        alert('Date format not valid. Please use "dd/mm/yyyy" format.');
        return false;
    }
    return [day,month,year];
}

function get_today_date(sep)
{
    if (!sep) var sep = '/';
    var date = new Date();
    var day, month;
    if ((day = date.getDate()) < 10)
        day = '0' + day;
    if ((month = date.getMonth() + 1) < 10)
        month = '0' + month;
    return day + sep + month + sep + date.getFullYear();
}

/* Adds a function at window.onload event */
function onload_add_function(func)
{
    if(typeof window.addEventListener != 'undefined') //.. gecko, safari, konqueror and standard 
        window.addEventListener('load', func, false);
    else if(typeof document.addEventListener != 'undefined') //.. opera 7 
        document.addEventListener('load', func, false);
    else if(typeof window.attachEvent != 'undefined') //.. win/ie 
        window.attachEvent('onload', func);
}


function find_position(obj) {
	var curleft = curtop = 0;
	if (obj.offsetParent) {
		do {
			curleft += obj.offsetLeft;
			curtop += obj.offsetTop;
		} while (obj = obj.offsetParent);
	}
	return [curleft,curtop];
}


function get_middle_screen_x(popup_width)
{
    if (!popup_width) 
        popup_width = 0;
    x = (1024 - popup_width)/2;
    if (screen)
        x = (screen.availWidth - popup_width)/2;
    return x;
}
        
function get_middle_screen_y(popup_height)
{
    if (!popup_height) 
        popup_height = 0;
    x = (768 - popup_height)/2;
    if (screen)
        x = (screen.availHeight - 200 - popup_height)/2;
    return x;
}

