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;
var isMoz=(agt.indexOf('mozilla') != -1);
var GL_ROOT_URL = 'http://'+window.location.host+'/';
var undefined;


function writeFlash(movieLocation,width,height){
document.write('<object codeBase="http://download-staging.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=5,0,0,0" width="'+width+'" height="'+height+'" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"><param name="_cx" value="4233"><param name="_cy" value="4022"><param name="FlashVars" value=""><param name="Movie" value="'+movieLocation+'"><param name="Src" value="'+movieLocation+'"><param name="WMode" value="Transparent"><param name="Play" value="-1"><param name="Loop" value="-1"><param name="Quality" value="High"><param name="SAlign" value=""><param name="Menu" value="0"><param name="Base" value=""><param name="AllowScriptAccess" value="always">	<param name="Scale" value="ShowAll"><param name="DeviceFont" value="0"><param name="EmbedMovie" value="0"><param name="BGColor" value=""><param name="SWRemote" value=""><param name="MovieData" value=""><param name="SeamlessTabbing" value="1"><param name="Profile" value="0"><param name="ProfileAddress" value=""><param name="ProfilePort" value="0"><embed src="'+movieLocation+'" 	pluginspage="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash" type="application/x-shockwave-flash" width="'+width+'" height="'+height+'" wmode="transparent"></embed></object>');
}

function writeFlashSSL(movieLocation,width,height){
document.write('<object codeBase="https://download-staging.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=5,0,0,0" width="'+width+'" height="'+height+'" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"><param name="_cx" value="4233"><param name="_cy" value="4022"><param name="FlashVars" value=""><param name="Movie" value="'+movieLocation+'"><param name="Src" value="'+movieLocation+'"><param name="WMode" value="Transparent"><param name="Play" value="-1"><param name="Loop" value="-1"><param name="Quality" value="High"><param name="SAlign" value=""><param name="Menu" value="0"><param name="Base" value=""><param name="AllowScriptAccess" value="always">	<param name="Scale" value="ShowAll"><param name="DeviceFont" value="0"><param name="EmbedMovie" value="0"><param name="BGColor" value=""><param name="SWRemote" value=""><param name="MovieData" value=""><param name="SeamlessTabbing" value="1"><param name="Profile" value="0"><param name="ProfileAddress" value=""><param name="ProfilePort" value="0"><embed src="'+movieLocation+'" 	pluginspage="https://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash" type="application/x-shockwave-flash" width="'+width+'" height="'+height+'" wmode="transparent"></embed></object>');
}

function cb_showModalDialog(url, width, height, win, scroll, menubar, x_y_mouse, resizable, modal_val) {
    var winname = parseInt(Math.round(10000 * Math.random()));
    if(menubar == undefined)
        menubar = 0;
	if(resizable == undefined)
        resizable = 1;
    if(is_ie) {
        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);
        if(win == 1) {
//            alert(menubar);
      		w = window.open(url, winname,'resizable='+resizable+',scrollbars='+scroll+',status=0,menubar='+menubar+',height='+height+',width='+width+', left=' +wleft+ ', top='+wtop);
            //alert(scroll);
        }
        else {
            w = showModalDialog(url,modal_val,'dialogWidth:'+width+'px;dialogHeight:'+height+'px;'+(x_y_mouse == 1 ? 'dialogLeft:'+(wleft - 110)+'; dialogTop:'+(wtop-105)+';' : '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;
        //(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;
}

String.prototype.trim = function() {
    var x=this;
    x=x.replace(/^\s*|\s*$/g,"");
    return x;
}

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, not_hide) {
    var block_object = document.getElementById(block_name).style.display;
    var tag = document.getElementById(block_name).tagName;
    var displ;
    
    switch(tag) {
		case 'TABLE':
			displ = 'table';
			break;
		default:
			displ = 'block';
			break;
    }
    
    if(block_object == 'none') {
    	try { //FFox & friends
        	document.getElementById(block_name).style.display = displ;
        } catch (ex) { //IE...
        	document.getElementById(block_name).style.display = 'block';
        }
        //alert(document.getElementById(block_name+'_block_checkbox'));
        if(document.getElementById(block_name+'_block_checkbox') != null) {
            document.getElementById(block_name+'_block_checkbox').checked = true;
        }
    }
    else if((block_object == displ || block_object == 'block') && (not_hide == '' || typeof not_hide == 'undefined'))
        document.getElementById(block_name).style.display = 'none';
}

function global_swapImage(img_id, img_url) {
    document.getElementById(img_id).src = GL_ROOT_URL+img_url;
}

function global_swapImgRestore(img_id, img_url) {
    document.getElementById(img_id).src = GL_ROOT_URL+img_url;
}


if(window.showModelessDialog == undefined){
    window.showModelessDialog = function (url, name, params) {
        showMDialog(url, name, params);
    }

    window.showModalDialog = function (url, name, params) {
        showMDialog(url, name, params);
    }


    showModelessDialog = function (url, name, params) {
        showMDialog(url, name, params);
    }

    showModalDialog = function (url, name, params) {
        showMDialog(url, name, params);
    }


    function showMDialog(url, name, params){
        params = params.replace(/\:/g, '=');
        params = params.replace(/\;/g, ',');
        params = params.replace(/dialog/g, '');
        params = params.replace(/center=yes,/g, 'left=330px,top=160px,');
        params = params.toLowerCase();

        var newwindow = window.open(url, name, params);
        if (newwindow && window.focus)
            newwindow.focus();
    }
}


function GetAbsScrollTop( obj ){ var curTop=0; while( obj ){ obj = obj.parentNode; if(obj && obj.scrollTop) curTop += parseInt(obj.scrollTop); } return curTop; }
function GetAbsScrollLeft( obj ){ var curLeft=0; while( obj ){ obj = obj.parentNode; if(obj && obj.scrollLeft) curLeft += parseInt(obj.scrollLeft); } return curLeft; }
function findPosY(obj){ var curTop = 0 -GetAbsScrollTop(obj); if (obj.offsetParent){ while (obj.offsetParent){ curTop += obj.offsetTop; obj = obj.offsetParent; } } else if (obj.y) { curTop += obj.y; } return curTop; }
function findPosX(obj){ var curLeft = 0 -GetAbsScrollLeft(obj); if (obj.offsetParent){ while (obj.offsetParent){ curLeft += obj.offsetLeft; obj = obj.offsetParent; } } else if (obj.x) { curLeft += obj.x; } return curLeft; }

function Mult(a, b){ var a = floatVal(a); var b = floatVal(b); if(!a || !b) return 0; var sum = parseFloat(a) * parseFloat(b); a = a.toString().replace('.', ''); b = b.toString().replace('.', ''); var len = (a.length > b.toString().length) ? a.toString().length : b.toString().length; return round(sum, len); }
function Divide(a, b){ var a = floatVal(a); var b = floatVal(b); if(!a || !b) return 0; var sum = parseFloat(a) / parseFloat(b); a = a.toString().replace('.', ''); b = b.toString().replace('.', ''); var len = (a.length > b.toString().length) ? a.toString().length : b.toString().length; return round(sum, len); }
function round(num, precision){ var num = floatVal(num); var pos = parseInt(num.toString().indexOf('.')); if(pos < 0) { return parseFloat(num); } else{ var nm = Math.pow(10,precision); return Math.round(num*nm)/nm; } }
function Sum(a, b){ var a = floatVal(a); var b = floatVal(b); var sum = a + b; a = a.toString().replace('.', ''); b = b.toString().replace('.', ''); var len = (a.length > b.toString().length) ? a.toString().length : b.toString().length; return parseFloat(sum.toPrecision(len)); }
function floatVal(str){ if(!str || str == 'Infinity' || str == 'NaN') return 0; return parseFloat(str.toString().replace(/,/, '.')); }

