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 && !isDOM;
var isNC6=isMozilla=isNC && isDOM;

if(is_ie5)
    window.onerror = onSiteError;

function onSiteError() {
   return true;
}

function cb_showModalDialog(url, width, height) {
    if(is_ie)
        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,'opwin','height='+height+',width='+width+', left=' +wleft+ ', top='+wtop);
    }
    if(isNC) {
        get_center (width, height);
        var attr = 'screenX=' + wleft + ',screenY='+wtop+', resizable=no,width='+width+',height='+(height+(isNC4 ? 0 : 120));
        w = window.open(url, 'dnwin', attr);
    }
    return w;
}

function get_center (width, height) {
   wleft = window.screenX + ((window.outerWidth - width) / 2);
   wtop = window.screenY + ((window.outerHeight - height) / 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;
