var agt = navigator.userAgent.toLowerCase();
var is_major = parseInt(navigator.appVersion);
var is_minor = parseFloat(navigator.appVersion);
var is_ie = ((agt.indexOf("msie") != -1) && (agt.indexOf("opera") == -1));
var is_ie3 = (is_ie && (is_major < 4));
var is_ie4 = (is_ie && (is_major == 4) && (agt.indexOf("msie 4")!=-1) );
var is_ie4up = (is_ie && (is_major >= 4));
var is_ie5 = (is_ie && (is_major == 4) && (agt.indexOf("msie 5.0")!=-1) );
var is_ie5_5 = (is_ie && (is_major == 4) && (agt.indexOf("msie 5.5") !=-1));
var is_ie5up = (is_ie && !is_ie3 && !is_ie4);
var is_ie5_5up = (is_ie && !is_ie3 && !is_ie4 && !is_ie5);
var is_ie6    = (is_ie && (is_major == 4) && (agt.indexOf("msie 6.")!=-1) );
var is_ie6up  = (is_ie && !is_ie3 && !is_ie4 && !is_ie5 && !is_ie5_5);
var is_ie5_5_or_higher = is_ie5_5 || is_ie5_5up || is_ie6 || is_ie6up;
var is_opera = (agt.indexOf("opera") != -1);
var is_opera2 = (agt.indexOf("opera 2") != -1 || agt.indexOf("opera/2") != -1);
var is_opera3 = (agt.indexOf("opera 3") != -1 || agt.indexOf("opera/3") != -1);
var is_opera4 = (agt.indexOf("opera 4") != -1 || agt.indexOf("opera/4") != -1);
var is_opera5 = (agt.indexOf("opera 5") != -1 || agt.indexOf("opera/5") != -1);
var is_opera5up = (is_opera && !is_opera2 && !is_opera3 && !is_opera4);
var isNC=navigator.appName=="Netscape";
var isNC4=isNC;

if(is_ie5)
    window.onerror = onSiteError;

function onSiteError() {
   return true;
}

function cb_showModalDialog(url, width, height, win, scroll, menubar, x_y_mouse) {
    var winname = parseInt(Math.round(10000 * Math.random()));
    //alert(event);
    //alert(event_objx+ '| '+event_objy);
    if(is_ie) { 
        if(win == 1) {
            if(x_y_mouse == 1) {
                if(event != null) {
                    var event_objx =  event.screenX;
                    var event_objy =  event.screenY;
                }
                wleft = event_objx;
                wtop = event_objy;
            }
            else
               get_center (width, height);
    		w = window.open(url, winname,'resizable=0,scrollbars='+scroll+',menubar='+menubar+',height='+height+',width='+width+', left=' +wleft+ ', top='+wtop);
        }
        else 
            w = showModalDialog(url,null,'dialogWidth:'+width+'px;dialogHeight:'+height+'px;center:yes;help:no;status:0;');
    }
    if(is_opera5up) {
        get_center (width, height);
		w = window.open(url,winname,'resizable=0,scrollbars='+scroll+',height='+height+',width='+width+', left=' +wleft+ ', top='+wtop);
    }
    if(isNC) {
        get_center (width, height);
        var attr = 'screenX=' + wleft + ',screenY='+wtop+', scrollbars='+scroll+',resizable=no,width='+width+',height='+(height + 120);
        w = window.open(url,winname, attr);
    }
    return w;
}

function get_center (width, height) {
   if(is_opera5up || isNC) {
       wleft = window.screenX + ((window.outerWidth - width) / 2);
       wtop = window.screenY + ((window.outerHeight - height) / 2);
   }
   else if(is_ie) {
        wtop = Math.round((screen.height-height) / 2);
        wleft = Math.round((screen.width-width) / 2);
   }
   return wleft, wtop;
}

function global_get_file_name(form_name, file_name_form, with_ext) {
    var file_name = document.getElementById(form_name).value;
    file_name = file_name.split('\\');
    file_name = file_name[file_name.length-1];
    if(with_ext != 1) {
        var file_type = file_name.substring(file_name.lastIndexOf('.')+1, file_name.length);
        var file_type_length = file_type.length;
        if(file_type_length == file_name.length) 
            file_type_length = -1;
        file_name = file_name.substring(0, file_name.length - (file_type_length+1));
    }
    if(document.getElementById(file_name_form).value == '')
        document.getElementById(file_name_form).value = file_name;
}

function global_return_name(editor_txt, url) {
    var data = '';
    if(editor_txt.replace(/ /g, '') != '') {
        editor_txt = editor_txt.trim();
        editor_txt = editor_txt.substr(0, 100);
        editor_txt = editor_txt.split(' ');
        for(i=0;i<=3;i++) {
            if(editor_txt[i] != undefined)
                data += editor_txt[i]+' ';
        }
    }
    var results = showModalDialog(url,data,'dialogWidth:400px;dialogHeight:100px;center:yes;help:no;status:0;');
    if (results != undefined) {
        return results;
    }
    else
        return false;
}

function global_extract_left(total_chars) {
    return this.substring(0, total_chars);
}

function global_extract_right(total_chars) {
    return this.substring(this.length - total_chars);
}

function global_trim_spaces(from_where) {
    var temp_string = this;
    if (arguments.length == 0)
        from_where = 'BOTH';
    if (from_where.toUpperCase() == 'LEFT' || from_where == 'BOTH') {
        while (temp_string.left(1) == ' ') {
            temp_string = temp_string.substring(1);
        }
    }
    if (from_where.toUpperCase() == 'RIGHT' || from_where == 'BOTH') {
        while (temp_string.right(1) == ' ') {
            temp_string = temp_string.substring(0, temp_string.length - 1);
        }
    }
    return temp_string;
}
String.prototype.right = global_extract_right;
String.prototype.left = global_extract_left;
String.prototype.trim = global_trim_spaces;

function AddToFavorites(fav_title) {
    var tmp = location.href.split('/');
    var fav_url = tmp[0]+'//'+tmp[2];
    
    if (is_ie)
        window.external.AddFavorite(fav_url, fav_title);
    else if(isNC) {
       if ((typeof window.sidebar == "object") && (typeof window.sidebar.addPanel == "function")) 
           window.sidebar.addPanel (fav_title,  fav_url, '');
    }
}

function MakeFirst() {
    var tmp = location.href.split('/');
    var fav_url = tmp[0]+'//'+tmp[2];
    if (is_ie) {
        document.body.style.behavior = 'url(#default#homepage)';
        document.body.setHomePage(fav_url);
    }
     else if(isNC) { 
         netscape.security.PrivilegeManager.enablePrivilege('UniversalPreferencesWrite');
         navigator.preference('browser.startup.homepage', fav_url);
     }
}

function global_show_block(block_name) {
    var block_object = document.getElementById(block_name).style.display;
    if(block_object == 'none') 
        document.getElementById(block_name).style.display = 'block';
    else if(block_object == 'block')  
        document.getElementById(block_name).style.display = 'none';
}
