function $_GET( name ){
    name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
    var regexS = "[\\?&]"+name+"=([^&#]*)";
    var regex = new RegExp( regexS );
    var results = regex.exec( window.location.href );
    if( results == null ){
        return "";
    }else{
        return results[1];
    }
}

function escapeHTML (str){
    var div = document.createElement('div');
    var text = document.createTextNode(str);
    div.appendChild(text);
    return div.innerHTML;
}

function debug(obj) {
    var generator=window.open('','name');
        generator.innerHTML = '';
        generator.document.write('<table width=100% border=1>');
    try { 
        for (var oCtrl in obj) {
            if (oCtrl == null) {break;}
            generator.document.writeln('<tr><td>'+ oCtrl +': '+obj[oCtrl] +'</td></tr>');
        }
    }
    catch(everything) { alert('error found'); }
    generator.document.write('</table>');
}

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

function fixdivX()
{
    alert("sdafasd");
    var str=new String(window.dialogHeight);
    str=str.replace(/px/,'');
    document.all['divcontent'].style.height=str-2;
}

function setDisplay(active, deactive){

    if(active != null){
        var divs = $('data_form').getElementsByClassName(active);
        
        for(i=0; i<divs.length; i++){
            divs[i].show();
        }
    }
    if(deactive != null){
        var divs = $('data_form').getElementsByClassName(deactive);
        
        for(i=0; i<divs.length; i++){
            divs[i].hide();
        }
    }

}

function file_delete(type){
    $(type).value = "";
    $(type+'_input').show();
    $(type+'_image').hide();
    $(type+'_file_id').value=-1;
}
function delNotesRow( obj ){
    var id=0;
    try{
        td = obj.parentNode.parentNode.getElementsByTagName('td');
        id = td[0].getElementsByTagName('input')[0];
        id = id.value;
    }catch(e){}
    new Ajax.Request('rpc.php?module=notes&action=notes.deletenote&id='+id, 
        {onSuccess: function(transport){
                if( transport.responseText == 1 || transport.responseText == ''){
                    delRow( obj, 'notes_table' );
                }else{
                    alert( transport.responseText );
                }                            
            }
        }
    );
}
function delFilesRow( obj ){
    var id=0, file_id=0;
    try{
        td = obj.parentNode.parentNode.getElementsByTagName('td');
        file_id = td[0].getElementsByTagName('input')[0];
        id = td[0].getElementsByTagName('input')[1];
        
        file_id = file_id.value;
        id = id.value;
    }catch(e){}
    new Ajax.Request('rpc.php?module=files&action=files.deleteFile&id='+id+'&file_id='+file_id, 
        {'onSuccess': function(transport){
                if( transport.responseText == 1){
                    delRow( obj, 'files_table' );
                }else{
                    alert( transport.responseText );
                }                            
            }
        }
    );
}

function getSelectedTabId(){
    
    return $j('#tabs>ul>li.ui-tabs-selected').attr("id");
}

var current_tab;
function change_tab(id){
    if(id == '') id = '1';
    
    var x=id.match(/[\d\.]+/g);
    
    current_tab=x;
    var c=10;
    for(i=1;i<c;i++){
        try {
            if(x==i){
                changeClassName('tab'+i,'current');
                $('page'+i).show();
            }else{
                changeClassName('tab'+i,'');
                $('page'+i).hide();
            }
        }catch(e){c=0;}
    }
}

function get_ids(name){
    var ids=new String('');
    for (i=0;i<document.getElementsByName(name).length;i++){
        if(i>0) ids=ids.concat(',')
        ids=ids.concat(document.getElementsByName(name).item(i).value);
    }
    return ids;
}

function delRow(obj, table_id){
    if( !table_id ) table_id  = 'default_table';
    if(obj.parentNode.parentNode.parentNode.parentNode.rows.length == 3) $j('#no_rs_'+table_id).show();
    obj.parentNode.parentNode.parentNode.parentNode.deleteRow(obj.parentNode.parentNode.rowIndex);
    
}

function preferenceAddBank(){

    options = $('bank_id1').innerHTML;

    options = options.replace(/selected="selected"/g, "");
    options = options.replace(/selected='selected'/g, "");

    banks_num = parseInt($('banks_num').value);
    index = banks_num + 1;

    all = document.getElementsByName('as_account[]');
    if(all.length == 0){
        banks_num = 1;
        index = 2;
        $('as_account_div_'+banks_num).insert({'after':bank_div_template.replace(/{#index}/g, index).replace(/{#listbox}/g, options)});
    }
    else{
        
        $(all[all.length-1].parentNode.parentNode.id).insert({'after':bank_div_template.replace(/{#index}/g, index).replace(/{#listbox}/g, options)});
    }
    
    //all[all.length-1].parentNode.parentNode.insert({'after':as_account_div_template.replace(/{#index}/g, index)});
    
    $('bank_div_'+index).insert({'after':as_account_div_template.replace(/{#index}/g, index)});

    $('banks_num').value = index;

    $('bank_id_'+index).options[0].selected = true;

}

function preferenceDeleteBank(index){
    
    index_now = parseInt($('banks_num').value) - 1;
    
    if(index_now < 1) index_now = 1;
    
    //$('banks_num').value = index_now;
    
    $('bank_div_'+index).remove();
    
    $('as_account_div_'+index).remove();

}

function delAllRows(id, table_id){
    if(!table_id) table_id = 'default_table';
    var table = $(id).rows.length-2;
    
    for (i=0; i<table; i++){
        $(id).deleteRow(2);
    }
    $('no_rs_'+table_id).show();
    return true;
}

function fixed(num, digits){

    return parseFloat(num).toFixed(parseInt(digits));

}

function today(id){
    date = new Date();
    $(id).value = formatDate(date,"yyyy-MM-dd");
}

function previousMonth(id){
    day_in_month = new Array();
    date = new Date();
    input = $(id).value;
    
    input_date = input.split('-');
    var year = input_date[0];
    var month = input_date[1];
    var day = input_date[2];
    
    if(month == 1){
        year--;
        month = 12;
    }
    else month--;
    
    var isLeapYear=year%4==0;
    if(isLeapYear)    
    day_in_month = [31,29,31,30,31,30,31,31,30,31,30,31];
    else
    day_in_month = [31,28,31,30,31,30,31,31,30,31,30,31];
    
    day = day_in_month[month-1];
    
    date.setYear(year);
    date.setMonth(month-1);
    date.setDate(day);
    
    weekday = date.getDay();

    //alert(weekday);
    
    if(weekday == 6) day--;
    if(weekday == 0) day = day-2;
    
    date.setDate(day);
    
    $(id).value = formatDate(date,"yyyy-MM-dd"); 
}

function setFocus( id ){
    $j(document).ready(function(){
        $j("#"+id).focus();
    });
}

function renew_currency(){
    new Ajax.Request('rpc.php?module=banks&action=currency.currencyrenew',{
                            method:'get', 
                            onSuccess: function(transport){
                                $j('#tabs').tabs('load', $tabs.data('selected.tabs'));
                                $('note').innerHTML = transport.responseText;
                                $('note').show();
                            }
                        }); 

}

function renew_templates(){ 
    new Ajax.Request('rpc.php?module=reports&action=reports.reporttemplatesrenew',{
                            method:'get', 
                            onSuccess: function(transport){
                                $j('#tabs').tabs('load', $tabs.data('selected.tabs'));
                                $('note').innerHTML = transport.responseText;
                                $('note').show();
                            }
                        }); 

}

function save_form(id, module, action, back, dont_check){
    var form = 'data_form';
    if(!dont_check){
        if(!check_form()) return false;
    }
    $j("#window_block_div").show();
    $j('#loader').show();
    var url = 'rpc.php?module='+module+'&action='+action+'&id='+id;

    new Ajax.Request(url, {
        method:'post',
        contentType:'application/x-www-form-urlencoded',
        postBody:Form.serialize($(form)),
        onSuccess: function(transport) {         
            
            if( isNaN( transport.responseText ) ){
                $j("#window_block_div").hide();
                alert(transport.responseText);
            }else{
                //alert(transport.responseText);
                if( back ){
                    location.href=back;
                }
            }
        }
    });
    
}

function create_new_temp(module, action, back){
    $j("#window_block_div").show();
    new Ajax.Request('rpc.php?module='+module+'&action='+action,{
        'onSuccess': function(transport){
            if( isNaN( transport.responseText ) ){
                $j("#window_block_div").hide();
                alert(transport.responseText);
            }else{
                if( back ){
                    location.href = back.replace(/#id/gi, transport.responseText);
                }
            }
        }
    });
}

function htmlspecialchars(string, quote_style) {
    // http://kevin.vanzonneveld.net
    // +   original by: Mirek Slugen
    // +   improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +   bugfixed by: Nathan
    // +   bugfixed by: Arno
    // +    revised by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // -    depends on: get_html_translation_table
    // *     example 1: htmlspecialchars("<a href='test'>Test</a>", 'ENT_QUOTES');
    // *     returns 1: '&lt;a href=&#039;test&#039;&gt;Test&lt;/a&gt;'
 
    var histogram = {}, symbol = '', tmp_str = '', entity = '';
    tmp_str = string.toString();
    
    if (false === (histogram = get_html_translation_table('HTML_SPECIALCHARS', quote_style))) {
        return false;
    }
    
    for (symbol in histogram) {
        entity = histogram[symbol];
        tmp_str = tmp_str.split(symbol).join(entity);
    }
    
    return tmp_str;
}
function get_html_translation_table(table, quote_style) {
    // http://kevin.vanzonneveld.net
    // +   original by: Philip Peterson
    // +    revised by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +   bugfixed by: noname
    // +   bugfixed by: Alex
    // +   bugfixed by: Marco
    // %          note: It has been decided that we're not going to add global
    // %          note: dependencies to php.js. Meaning the constants are not
    // %          note: real constants, but strings instead. integers are also supported if someone
    // %          note: chooses to create the constants themselves.
    // %          note: Table from http://www.the-art-of-web.com/html/character-codes/
    // *     example 1: get_html_translation_table('HTML_SPECIALCHARS');
    // *     returns 1: {'"': '&quot;', '&': '&amp;', '<': '&lt;', '>': '&gt;'}
    
    var entities = {}, histogram = {}, decimal = 0, symbol = '';
    var constMappingTable = {}, constMappingQuoteStyle = {};
    var useTable = {}, useQuoteStyle = {};
    
    useTable      = (table ? table.toUpperCase() : 'HTML_SPECIALCHARS');
    useQuoteStyle = (quote_style ? quote_style.toUpperCase() : 'ENT_COMPAT');
    
    // Translate arguments
    constMappingTable[0]      = 'HTML_SPECIALCHARS';
    constMappingTable[1]      = 'HTML_ENTITIES';
    constMappingQuoteStyle[0] = 'ENT_NOQUOTES';
    constMappingQuoteStyle[2] = 'ENT_COMPAT';
    constMappingQuoteStyle[3] = 'ENT_QUOTES';
    
    // Map numbers to strings for compatibilty with PHP constants
    if (!isNaN(useTable)) {
        useTable = constMappingTable[useTable];
    }
    if (!isNaN(useQuoteStyle)) {
        useQuoteStyle = constMappingQuoteStyle[useQuoteStyle];
    }
    
    if (useQuoteStyle != 'ENT_NOQUOTES') {
        entities['34'] = '&quot;';
    }
 
    if (useQuoteStyle == 'ENT_QUOTES') {
        entities['39'] = '&#039;';
    }
 
    if (useTable == 'HTML_SPECIALCHARS') {
        // ascii decimals for better compatibility
        entities['38'] = '&amp;';
        entities['60'] = '&lt;';
        entities['62'] = '&gt;';
    } else if (useTable == 'HTML_ENTITIES') {
        // ascii decimals for better compatibility
      entities['38']  = '&amp;';
      entities['60']  = '&lt;';
      entities['62']  = '&gt;';
      entities['160'] = '&nbsp;';
      entities['161'] = '&iexcl;';
      entities['162'] = '&cent;';
      entities['163'] = '&pound;';
      entities['164'] = '&curren;';
      entities['165'] = '&yen;';
      entities['166'] = '&brvbar;';
      entities['167'] = '&sect;';
      entities['168'] = '&uml;';
      entities['169'] = '&copy;';
      entities['170'] = '&ordf;';
      entities['171'] = '&laquo;';
      entities['172'] = '&not;';
      entities['173'] = '&shy;';
      entities['174'] = '&reg;';
      entities['175'] = '&macr;';
      entities['176'] = '&deg;';
      entities['177'] = '&plusmn;';
      entities['178'] = '&sup2;';
      entities['179'] = '&sup3;';
      entities['180'] = '&acute;';
      entities['181'] = '&micro;';
      entities['182'] = '&para;';
      entities['183'] = '&middot;';
      entities['184'] = '&cedil;';
      entities['185'] = '&sup1;';
      entities['186'] = '&ordm;';
      entities['187'] = '&raquo;';
      entities['188'] = '&frac14;';
      entities['189'] = '&frac12;';
      entities['190'] = '&frac34;';
      entities['191'] = '&iquest;';
      entities['192'] = '&Agrave;';
      entities['193'] = '&Aacute;';
      entities['194'] = '&Acirc;';
      entities['195'] = '&Atilde;';
      entities['196'] = '&Auml;';
      entities['197'] = '&Aring;';
      entities['198'] = '&AElig;';
      entities['199'] = '&Ccedil;';
      entities['200'] = '&Egrave;';
      entities['201'] = '&Eacute;';
      entities['202'] = '&Ecirc;';
      entities['203'] = '&Euml;';
      entities['204'] = '&Igrave;';
      entities['205'] = '&Iacute;';
      entities['206'] = '&Icirc;';
      entities['207'] = '&Iuml;';
      entities['208'] = '&ETH;';
      entities['209'] = '&Ntilde;';
      entities['210'] = '&Ograve;';
      entities['211'] = '&Oacute;';
      entities['212'] = '&Ocirc;';
      entities['213'] = '&Otilde;';
      entities['214'] = '&Ouml;';
      entities['215'] = '&times;';
      entities['216'] = '&Oslash;';
      entities['217'] = '&Ugrave;';
      entities['218'] = '&Uacute;';
      entities['219'] = '&Ucirc;';
      entities['220'] = '&Uuml;';
      entities['221'] = '&Yacute;';
      entities['222'] = '&THORN;';
      entities['223'] = '&szlig;';
      entities['224'] = '&agrave;';
      entities['225'] = '&aacute;';
      entities['226'] = '&acirc;';
      entities['227'] = '&atilde;';
      entities['228'] = '&auml;';
      entities['229'] = '&aring;';
      entities['230'] = '&aelig;';
      entities['231'] = '&ccedil;';
      entities['232'] = '&egrave;';
      entities['233'] = '&eacute;';
      entities['234'] = '&ecirc;';
      entities['235'] = '&euml;';
      entities['236'] = '&igrave;';
      entities['237'] = '&iacute;';
      entities['238'] = '&icirc;';
      entities['239'] = '&iuml;';
      entities['240'] = '&eth;';
      entities['241'] = '&ntilde;';
      entities['242'] = '&ograve;';
      entities['243'] = '&oacute;';
      entities['244'] = '&ocirc;';
      entities['245'] = '&otilde;';
      entities['246'] = '&ouml;';
      entities['247'] = '&divide;';
      entities['248'] = '&oslash;';
      entities['249'] = '&ugrave;';
      entities['250'] = '&uacute;';
      entities['251'] = '&ucirc;';
      entities['252'] = '&uuml;';
      entities['253'] = '&yacute;';
      entities['254'] = '&thorn;';
      entities['255'] = '&yuml;';
    } else {
        throw Error("Table: "+useTable+' not supported');
        return false;
    }
    
    // ascii decimals to real symbols
    for (decimal in entities) {
        symbol = String.fromCharCode(decimal);
        histogram[symbol] = entities[decimal];
    }
    
    return histogram;
}
function htmlspecialchars_decode(string, quote_style) {
    // http://kevin.vanzonneveld.net
    // +   original by: Mirek Slugen
    // +   improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +   bugfixed by: Mateusz "loonquawl" Zalega
    // +      input by: ReverseSyntax
    // +      input by: Slawomir Kaniecki
    // +      input by: Scott Cariss
    // +      input by: Francois
    // +   bugfixed by: Onno Marsman
    // +    revised by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // -    depends on: get_html_translation_table
    // *     example 1: htmlspecialchars_decode("<p>this -&gt; &quot;</p>", 'ENT_NOQUOTES');
    // *     returns 1: '<p>this -> &quot;</p>'
 
    var histogram = {}, symbol = '', tmp_str = '', entity = '';
    tmp_str = string.toString();
    
    if (false === (histogram = get_html_translation_table('HTML_SPECIALCHARS', quote_style))) {
        return false;
    }
 
    // &amp; must be the last character when decoding!
    delete(histogram['&']);
    histogram['&'] = '&amp;';
 
    for (symbol in histogram) {
        entity = histogram[symbol];
        tmp_str = tmp_str.split(entity).join(symbol);
    }
    
    return tmp_str;
}


function checkenter(e){
    if(e && e.which){ //if which property of event object is supported (NN4)
        e = e;
        code = e.which; //character code is contained in NN4's which property
    }
    else{
        e = event
        code = e.keyCode; //character code is contained in IE's keyCode property
    }
    //alert(code);
    if(code == 13 && now_sel > -1) return false;
}

var ctrl=0;

function resetKey(e){
    var code;
    
    if(e && e.which){ //if which property of event object is supported (NN4)
        e = e
        code = e.which; //character code is contained in NN4's which property
    }
    else{
        e = event
        code = e.keyCode; //character code is contained in IE's keyCode property
    }
   
    if ((code==17)||(code==16)||(code==18)) ctrl=0;
}

function checkEmail(email){

    if(email != ''){
        if(email.match(/^[a-z0-9]+([-_\.]?[a-z0-9])+@[a-z0-9]+([-_\.]?[a-z0-9])+\.[a-z]{2,4}/) == null){
           return true;
        }
        else return false;
    }
}


function checknumber(e){
    var code;
    
    if(e && e.which){ //if which property of event object is supported (NN4)
        e = e
        code = e.which; //character code is contained in NN4's which property
    }
    else{
        e = event
        code = e.keyCode; //character code is contained in IE's keyCode property
    }
    
    if (e.ctrlKey) return 1; 
    if ((code>47&&code<58)||(code>95&&code<106)||code==9||code==8||code==116||code==13||code==37||code==39||code==45||code==36||code==33||code==35||code==46) {
        return true;
    }
    e.returnValue=false;
    return false;
}

function checksum(e,obj){   
    
    var code;
    
    if(e && e.which){ //if which property of event object is supported (NN4)
        e = e
        code = e.which; //character code is contained in NN4's which property
    }
    else{
        e = event
        code = e.keyCode; //character code is contained in IE's keyCode property
    }
    
    //obj=e.srcElement;
    
    if (code==110||code==190) {   
        var bla = new String(obj.value);
        if (bla.search(/\./)==-1) {
            //obj.value=obj.value+'.';
            e.returnValue=true;
            return true;
        }
        e.returnValue=false;
        return false;
    }

    if (code==109||code==189) {
        var bla=new String(obj.value);
        if (bla.search(/-/)==-1) {
            e.returnValue=true;
            return true;
        }
        e.returnValue=false;
        return false;
    }

    if (e.ctrlKey) return 1; 
    if ((code>47&&code<58)||(code>95&&code<106)||code==9||code==110||code==190||code==8||code==116||code==13||code==37||code==39||code==45||code==36||code==33||code==35||code==46) {
        e.returnValue=true; 
        return true;
    }
    e.returnValue=false;
    return false;
}


function checkphone(e,obj){   
    var code;
    if(e && e.which){ //if which property of event object is supported (NN4)
        e = e
        code = e.which; //character code is contained in NN4's which property
    }
    else{
        e = event
        code = e.keyCode; //character code is contained in IE's keyCode property
    }
    
    /*
    if (code==110||code==190) {   
        var bla = new String(obj.value);
        if (bla.search(/\./)==-1) {
            //obj.value=obj.value+'.';
            e.returnValue=true;
            return true;
        }
        e.returnValue=false;
        return false;
    }
    */
    

    if (code==107) {
        var bla=new String(obj.value);
        if (bla.search(/\+/)==-1) {
            e.returnValue=true;
            return true;
        }
        e.returnValue=false;
        return false;
    }

    if (e.ctrlKey) return 1; 
    if ((code>47&&code<58)||(code>95&&code<106)||code==9||code==8||code==116||code==13||code==37||code==39||code==45||code==36||code==33||code==35||code==46) {
        e.returnValue=true; 
        return true;
    }
    e.returnValue=false;
    return false;
}

function URLEncode(str) {
	var result = "";
	
	for (i = 0; i < str.length; i++) {
		if (str.charAt(i) == " ") result += "+";
		else result += str.charAt(i);
	}
	
	return escape(result);
}

function getObject(name) {
	if (document.getElementById) {
		// this is the way the standards work
		return document.getElementById(name);
	}
	else if (document.all) {
		// this is the way old msie versions work
		return document.all[name];
	}
	else if (document.layers) {
		// this is the way nn4 works
        return 	document.layers[name];
	}
}

function hideLayer(whichLayer) {
	if (document.getElementById) {
		// this is the way the standards work
		document.getElementById(whichLayer).style.display = "none";
	}
	else if (document.all) {
		// this is the way old msie versions work
		document.all[whichlayer].style.display = "none";
	}
	else if (document.layers) {
		// this is the way nn4 works
		document.layers[whichLayer].display = "none";
	}
}

function showLayer(whichLayer) {

		//	alert(whichLayer);
	if (document.getElementById) {
		// this is the way the standards work
		document.getElementById(whichLayer).style.display = "block";
	}
	else if (document.all) {
		// this is the way old msie versions work
		document.all[whichlayer].style.display = "block";
	}
	else if (document.layers) {
		// this is the way nn4 works
		document.layers[whichLayer].display = "block";
	}
}

function changeClassName(id,classname)
{
	if (document.getElementById) {
		// this is the way the standards work
		document.getElementById(id).className = classname;
		//document.getElementById(id).style.backgroundColor='#ffffff'
	}
	else if (document.all) {
		// this is the way old msie versions work
		document.all[id].style.className = classname;
		//document.all[id].style.backgroundColor='#ffffff'
	}
	else if (document.layers) {
		// this is the way nn4 works
		document.layers[id].style.className = classname;
	}
}


function roll_tab(img_name, img_src){
  document[img_name].src = "../images/main/"+img_src;
}

//document['tabright'].src = '../images/main/tab_right_big.gif'



function isArray(obj) {
   if (obj.constructor.toString().indexOf("Array") == -1)
      return false;
   else
      return true;
}

//datos formatavimo funkcijos

// ===================================================================
// Author: Matt Kruse <matt@mattkruse.com>
// WWW: http://www.mattkruse.com/
//
// NOTICE: You may use this code for any purpose, commercial or
// private, without any further permission from the author. You may
// remove this notice from your final code if you wish, however it is
// appreciated by the author if at least my web site address is kept.
//
// You may *NOT* re-distribute this code in any way except through its
// use. That means, you can include it in your product, or your web
// site, or any other form where the code is actually being used. You
// may not put the plain javascript up on your site for download or
// include it in your javascript libraries for download. 
// If you wish to share this code with others, please just point them
// to the URL instead.
// Please DO NOT link directly to my .js files from your site. Copy
// the files to your server and use them there. Thank you.
// ===================================================================

// HISTORY
// ------------------------------------------------------------------
// May 17, 2003: Fixed bug in parseDate() for dates <1970
// March 11, 2003: Added parseDate() function
// March 11, 2003: Added "NNN" formatting option. Doesn't match up
//                 perfectly with SimpleDateFormat formats, but 
//                 backwards-compatability was required.

// ------------------------------------------------------------------
// These functions use the same 'format' strings as the 
// java.text.SimpleDateFormat class, with minor exceptions.
// The format string consists of the following abbreviations:
// 
// Field        | Full Form          | Short Form
// -------------+--------------------+-----------------------
// Year         | yyyy (4 digits)    | yy (2 digits), y (2 or 4 digits)
// Month        | MMM (name or abbr.)| MM (2 digits), M (1 or 2 digits)
//              | NNN (abbr.)        |
// Day of Month | dd (2 digits)      | d (1 or 2 digits)
// Day of Week  | EE (name)          | E (abbr)
// Hour (1-12)  | hh (2 digits)      | h (1 or 2 digits)
// Hour (0-23)  | HH (2 digits)      | H (1 or 2 digits)
// Hour (0-11)  | KK (2 digits)      | K (1 or 2 digits)
// Hour (1-24)  | kk (2 digits)      | k (1 or 2 digits)
// Minute       | mm (2 digits)      | m (1 or 2 digits)
// Second       | ss (2 digits)      | s (1 or 2 digits)
// AM/PM        | a                  |
//
// NOTE THE DIFFERENCE BETWEEN MM and mm! Month=MM, not mm!
// Examples:
//  "MMM d, y" matches: January 01, 2000
//                      Dec 1, 1900
//                      Nov 20, 00
//  "M/d/yy"   matches: 01/20/00
//                      9/2/00
//  "MMM dd, yyyy hh:mm:ssa" matches: "January 01, 2000 12:30:45AM"
// ------------------------------------------------------------------

var MONTH_NAMES=new Array('January','February','March','April','May','June','July','August','September','October','November','December','Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec');
var DAY_NAMES=new Array('Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday','Sun','Mon','Tue','Wed','Thu','Fri','Sat');
function LZ(x) {return(x<0||x>9?"":"0")+x}

// ------------------------------------------------------------------
// isDate ( date_string, format_string )
// Returns true if date string matches format of format string and
// is a valid date. Else returns false.
// It is recommended that you trim whitespace around the value before
// passing it to this function, as whitespace is NOT ignored!
// ------------------------------------------------------------------
function isDate(val,format) {
	var date=getDateFromFormat(val,format);
	if (date==0) { return false; }
	return true;
	}

// -------------------------------------------------------------------
// compareDates(date1,date1format,date2,date2format)
//   Compare two date strings to see which is greater.
//   Returns:
//   1 if date1 is greater than date2
//   0 if date2 is greater than date1 of if they are the same
//  -1 if either of the dates is in an invalid format
// -------------------------------------------------------------------
function compareDates(date1,dateformat1,date2,dateformat2) {
	var d1=getDateFromFormat(date1,dateformat1);
	var d2=getDateFromFormat(date2,dateformat2);
	if (d1==0 || d2==0) {
		return -1;
		}
	else if (d1 > d2) {
		return 1;
		}
	return 0;
	}

// ------------------------------------------------------------------
// formatDate (date_object, format)
// Returns a date in the output format specified.
// The format string uses the same abbreviations as in getDateFromFormat()
// ------------------------------------------------------------------
function formatDate(date,format) {
	format=format+"";
	var result="";
	var i_format=0;
	var c="";
	var token="";
	var y=date.getYear()+"";
	var M=date.getMonth()+1;
	var d=date.getDate();
	var E=date.getDay();
	var H=date.getHours();
	var m=date.getMinutes();
	var s=date.getSeconds();
	var yyyy,yy,MMM,MM,dd,hh,h,mm,ss,ampm,HH,H,KK,K,kk,k;
	// Convert real date parts into formatted versions
	var value=new Object();
	if (y.length < 4) {y=""+(y-0+1900);}
	value["y"]=""+y;
	value["yyyy"]=y;
	value["yy"]=y.substring(2,4);
	value["M"]=M;
	value["MM"]=LZ(M);
	value["MMM"]=MONTH_NAMES[M-1];
	value["NNN"]=MONTH_NAMES[M+11];
	value["d"]=d;
	value["dd"]=LZ(d);
	value["E"]=DAY_NAMES[E+7];
	value["EE"]=DAY_NAMES[E];
	value["H"]=H;
	value["HH"]=LZ(H);
	if (H==0){value["h"]=12;}
	else if (H>12){value["h"]=H-12;}
	else {value["h"]=H;}
	value["hh"]=LZ(value["h"]);
	if (H>11){value["K"]=H-12;} else {value["K"]=H;}
	value["k"]=H+1;
	value["KK"]=LZ(value["K"]);
	value["kk"]=LZ(value["k"]);
	if (H > 11) { value["a"]="PM"; }
	else { value["a"]="AM"; }
	value["m"]=m;
	value["mm"]=LZ(m);
	value["s"]=s;
	value["ss"]=LZ(s);
	while (i_format < format.length) {
		c=format.charAt(i_format);
		token="";
		while ((format.charAt(i_format)==c) && (i_format < format.length)) {
			token += format.charAt(i_format++);
			}
		if (value[token] != null) { result=result + value[token]; }
		else { result=result + token; }
		}
	return result;
	}
	
// ------------------------------------------------------------------
// Utility functions for parsing in getDateFromFormat()
// ------------------------------------------------------------------
function _isInteger(val) {
	var digits="1234567890";
	for (var i=0; i < val.length; i++) {
		if (digits.indexOf(val.charAt(i))==-1) { return false; }
		}
	return true;
	}
function _getInt(str,i,minlength,maxlength) {
	for (var x=maxlength; x>=minlength; x--) {
		var token=str.substring(i,i+x);
		if (token.length < minlength) { return null; }
		if (_isInteger(token)) { return token; }
		}
	return null;
	}
	
// ------------------------------------------------------------------
// getDateFromFormat( date_string , format_string )
//
// This function takes a date string and a format string. It matches
// If the date string matches the format string, it returns the 
// getTime() of the date. If it does not match, it returns 0.
// ------------------------------------------------------------------
function getDateFromFormat(val,format) {
	val=val+"";
	format=format+"";
	var i_val=0;
	var i_format=0;
	var c="";
	var token="";
	var token2="";
	var x,y;
	var now=new Date();
	var year=now.getYear();
	var month=now.getMonth()+1;
	var date=1;
	var hh=now.getHours();
	var mm=now.getMinutes();
	var ss=now.getSeconds();
	var ampm="";
	
	while (i_format < format.length) {
		// Get next token from format string
		c=format.charAt(i_format);
		token="";
		while ((format.charAt(i_format)==c) && (i_format < format.length)) {
			token += format.charAt(i_format++);
			}
		// Extract contents of value based on format token
		if (token=="yyyy" || token=="yy" || token=="y") {
			if (token=="yyyy") { x=4;y=4; }
			if (token=="yy")   { x=2;y=2; }
			if (token=="y")    { x=2;y=4; }
			year=_getInt(val,i_val,x,y);
			if (year==null) { return 0; }
			i_val += year.length;
			if (year.length==2) {
				if (year > 70) { year=1900+(year-0); }
				else { year=2000+(year-0); }
				}
			}
		else if (token=="MMM"||token=="NNN"){
			month=0;
			for (var i=0; i<MONTH_NAMES.length; i++) {
				var month_name=MONTH_NAMES[i];
				if (val.substring(i_val,i_val+month_name.length).toLowerCase()==month_name.toLowerCase()) {
					if (token=="MMM"||(token=="NNN"&&i>11)) {
						month=i+1;
						if (month>12) { month -= 12; }
						i_val += month_name.length;
						break;
						}
					}
				}
			if ((month < 1)||(month>12)){return 0;}
			}
		else if (token=="EE"||token=="E"){
			for (var i=0; i<DAY_NAMES.length; i++) {
				var day_name=DAY_NAMES[i];
				if (val.substring(i_val,i_val+day_name.length).toLowerCase()==day_name.toLowerCase()) {
					i_val += day_name.length;
					break;
					}
				}
			}
		else if (token=="mm"||token=="m") {
			month=_getInt(val,i_val,token.length,2);
			if(month==null||(month<1)||(month>12)){return 0;}
			i_val+=month.length;}
		else if (token=="dd"||token=="d") {
			date=_getInt(val,i_val,token.length,2);
			if(date==null||(date<1)||(date>31)){return 0;}
			i_val+=date.length;}
		else if (token=="hh"||token=="h") {
			hh=_getInt(val,i_val,token.length,2);
			if(hh==null||(hh<1)||(hh>12)){return 0;}
			i_val+=hh.length;}
		else if (token=="HH"||token=="H") {
			hh=_getInt(val,i_val,token.length,2);
			if(hh==null||(hh<0)||(hh>23)){return 0;}
			i_val+=hh.length;}
		else if (token=="KK"||token=="K") {
			hh=_getInt(val,i_val,token.length,2);
			if(hh==null||(hh<0)||(hh>11)){return 0;}
			i_val+=hh.length;}
		else if (token=="kk"||token=="k") {
			hh=_getInt(val,i_val,token.length,2);
			if(hh==null||(hh<1)||(hh>24)){return 0;}
			i_val+=hh.length;hh--;}
		else if (token=="MM"||token=="M") {
			mm=_getInt(val,i_val,token.length,2);
			if(mm==null||(mm<0)||(mm>59)){return 0;}
			i_val+=mm.length;}
		else if (token=="ss"||token=="s") {
			ss=_getInt(val,i_val,token.length,2);
			if(ss==null||(ss<0)||(ss>59)){return 0;}
			i_val+=ss.length;}
		else if (token=="a") {
			if (val.substring(i_val,i_val+2).toLowerCase()=="am") {ampm="AM";}
			else if (val.substring(i_val,i_val+2).toLowerCase()=="pm") {ampm="PM";}
			else {return 0;}
			i_val+=2;}
		else {
			if (val.substring(i_val,i_val+token.length)!=token) {return 0;}
			else {i_val+=token.length;}
			}
		}
	// If there are any trailing characters left in the value, it doesn't match
	if (i_val != val.length) { return 0; }
	// Is date valid for month?
    
	if (month==2) {
		// Check for leap year
		if ( ( (year%4==0)&&(year%100 != 0) ) || (year%400==0) ) { // leap year
			if (date > 29){ return 0; }
			}
		else { if (date > 28) { return 0; } }
		}
	if ((month==4)||(month==6)||(month==9)||(month==11)) {
		if (date > 30) { return 0; }
		}
	// Correct hours value
	if (hh<12 && ampm=="PM") { hh=hh-0+12; }
	else if (hh>11 && ampm=="AM") { hh-=12; }
	var newdate=new Date(year,month-1,date,hh,mm,ss);
	return newdate.getTime();
	}

// ------------------------------------------------------------------
// parseDate( date_string [, prefer_euro_format] )
//
// This function takes a date string and tries to match it to a
// number of possible date formats to get the value. It will try to
// match against the following international formats, in this order:
// y-M-d   MMM d, y   MMM d,y   y-MMM-d   d-MMM-y  MMM d
// M/d/y   M-d-y      M.d.y     MMM-d     M/d      M-d
// d/M/y   d-M-y      d.M.y     d-MMM     d/M      d-M
// A second argument may be passed to instruct the method to search
// for formats like d/M/y (european format) before M/d/y (American).
// Returns a Date object or null if no patterns match.
// ------------------------------------------------------------------
function parseDate(val) {
	var preferEuro=(arguments.length==2)?arguments[1]:false;
	generalFormats=new Array('y-M-d','MMM d, y','MMM d,y','y-MMM-d','d-MMM-y','MMM d');
	monthFirst=new Array('M/d/y','M-d-y','M.d.y','MMM-d','M/d','M-d');
	dateFirst =new Array('d/M/y','d-M-y','d.M.y','d-MMM','d/M','d-M');
	var checkList=new Array('generalFormats',preferEuro?'dateFirst':'monthFirst',preferEuro?'monthFirst':'dateFirst');
	var d=null;
	for (var i=0; i<checkList.length; i++) {
		var l=window[checkList[i]];
		for (var j=0; j<l.length; j++) {
			d=getDateFromFormat(val,l[j]);
			if (d!=0) { return new Date(d); }
			}
		}
	return null;
	}


function FormatNumber2(num,decimalNum,bolLeadingZero,bolParens,bolCommas)
/**********************************************************************
	IN:
		NUM - the number to format
		decimalNum - the number of decimal places to format the number to
		bolLeadingZero - true / false - display a leading zero for
										numbers between -1 and 1
		bolParens - true / false - use parenthesis around negative numbers
		bolCommas - put commas as number separators.
 
	RETVAL:
		The formatted number!
 **********************************************************************/
{ 
        if (isNaN(parseInt(num))) return "NaN";

	var tmpNum = num;
	var iSign = num < 0 ? -1 : 1;		// Get sign of number
	
	// Adjust number so only the specified number of numbers after
	// the decimal point are shown.
	tmpNum *= Math.pow(10,decimalNum);
	tmpNum = Math.round(Math.abs(tmpNum))
	tmpNum /= Math.pow(10,decimalNum);
	tmpNum *= iSign;					// Readjust for sign
	
	
	// Create a string object to do our formatting on
	var tmpNumStr = new String(tmpNum);

	// See if we need to strip out the leading zero or not.
	if (!bolLeadingZero && num < 1 && num > -1 && num != 0)
		if (num > 0)
			tmpNumStr = tmpNumStr.substring(1,tmpNumStr.length);
		else
			tmpNumStr = "-" + tmpNumStr.substring(2,tmpNumStr.length);
		
	// See if we need to put in the commas
	if (bolCommas && (num >= 1000 || num <= -1000)) {
		var iStart = tmpNumStr.indexOf(".");
		if (iStart < 0)
			iStart = tmpNumStr.length;

		iStart -= 3;
		while (iStart >= 1) {
			tmpNumStr = tmpNumStr.substring(0,iStart) + "," + tmpNumStr.substring(iStart,tmpNumStr.length)
			iStart -= 3;
		}		
	}

	// See if we need to use parenthesis
	if (bolParens && num < 0)
		tmpNumStr = "(" + tmpNumStr.substring(1,tmpNumStr.length) + ")";

	return tmpNumStr;		// Return our formatted string!
}



function formatDecimal(argvalue, addzero, decimaln) {
  var numOfDecimal = (decimaln == null) ? 2 : decimaln;
  var number = 1;

  number = Math.pow(10, numOfDecimal);

  argvalue = Math.round(parseFloat(argvalue) * number) / number;
  // If you're using IE3.x, you will get error with the following line.
  // argvalue = argvalue.toString();
  // It works fine in IE4.
  argvalue = "" + argvalue;

  if (argvalue.indexOf(".") == 0)
    argvalue = "0" + argvalue;

  if (addzero == true) {
    if (argvalue.indexOf(".") == -1)
      argvalue = argvalue + ".";

    while ((argvalue.indexOf(".") + 1) > (argvalue.length - numOfDecimal))
      argvalue = argvalue + "0";
  }

  return argvalue;
}

function FormatNumber( number ){
	var result = formatDecimal( number, true, 2 );
	return result;
}

// Window opener functions  v1.0.6
// http://www.dithered.com/javascript/window/index.html
// code by Chris Nott (chris@NOSPAMdithered.com - remove NOSPAM)

/*******************************************************************************
Popup Window openers
*******************************************************************************/

var winReference = null;
// Open a window at a given position on the screen
function openPositionedWindow(url, name, width, height, x, y, status, scrollbars, moreProperties, openerName) {
	
	// ie 4.5 and 5.0 mac - windows are 2 pixels too short; if a statusbar is used, the window will be an additional 15 pixels short
	var agent = navigator.userAgent.toLowerCase();
	if (agent.indexOf("mac") != -1 && agent.indexOf("msie") != -1 && (agent.indexOf("msie 4") != -1 || agent.indexOf("msie 5.0") != -1) ) {
	height += (status) ? 17 : 2;
	}
	// Adjust width if scrollbars are used (pc places scrollbars inside the content area; mac outside) 
	width += (scrollbars != '' && scrollbars != null && agent.indexOf("mac") == -1) ? 16 : 0;
	var properties = 'width=' + width + ',height=' + height + ',screenX=' + x + ',screenY=' + y + ',left=' + x + ',top=' + y + ((status) ? ',status' : '') + ',scrollbars' + ((scrollbars) ? '' : '=no') + ((moreProperties) ? ',' + moreProperties : '');
	var reference = openWindow(url, name, properties, openerName);
	
	// resize window in ie if we can resize in ns; very messy
	// commented out because openPositionedWindow() doesn't set the resizable attribute
	// left in for reference
	/*if (resizable && agent.indexOf("msie") != -1) {
	if (agent.indexOf("mac") != -1) {
	height += (status) ? 15 : 2;
	if (parseFloat(navigator.appVersion) > 5) width -= 11;
	}
	else {
	height += (status) ? 49 : 31;
	width += 13;
	}
	setTimeout('if (reference != null && !reference.closed) reference.resizeTo(' + width + ',' + height + ');', 150);
	}*/
	return reference;
}

// Open a window at the center of the screen
function openCenteredWindow(url, name, width, height, status, scrollbars, moreProperties, openerName) {
	var x, y = 0;
	if (screen) {
	x = (screen.availWidth - width) / 2;
	y = (screen.availHeight - height) / 2;
	}
	if (!status) status = '';
	if (!openerName) openerName = '';
	var reference = openPositionedWindow(url, name, width, height, x, y, status, scrollbars, moreProperties, openerName);
	return reference;
}

// Open a window at the center of the parent window
function openCenteredOnOpenerWindow(url, name, width, height, status, scrollbars, moreProperties, openerName) {
	var centerX = 0;
	var centerY = 0;
	if (window.screenX != null && window.outerWidth) {
	centerX = window.screenX + (window.outerWidth / 2);
	centerY = window.screenY + (window.outerHeight / 2);
	}
	else if (window.screenLeft) {
	if (document.documentElement) {
	centerX = window.screenLeft + (document.documentElement.offsetWidth / 2);
	centerY = window.screenTop + (document.documentElement.offsetHeight / 2);
	}
	else if (document.body && document.body.offsetWidth) {
	centerX = window.screenLeft + (document.body.offsetWidth / 2);
	centerY = window.screenTop + (document.body.offsetHeight / 2);
	}
	}
	
	if (centerX == 0) {
	openCenteredWindow(url, name, width, height, status, scrollbars, moreProperties, openerName);
	}
	var x = parseInt(centerX - (width / 2));
	var y = parseInt(centerY - (height / 2));
	if (!status) status = '';
	if (!openerName) openerName = '';
	var reference = openPositionedWindow(url, name, width, height, x, y, status, scrollbars, moreProperties, openerName);
	return reference;
}
// Open a full-screen window (different from IE's fullscreen option)
function openMaxedWindow(url, name, scrollbars, openerName) {
	var x, y = 0;
	var width  = 600;
	var height = 800;
	if (screen) {
	if (screen.availLeft) {
	x = screen.availLeft;
	y = screen.availTop;
	}
	width  = screen.availWidth - 6;
	height = screen.availHeight - 29;
	}
	var reference = openPositionedWindow(url, name, width, height, x, y, false, scrollbars, openerName);
	return reference;
}

// Open a full-chrome (all GUI elements) window
// This is like using a target="_blank" in a normal link but allows focussing the window
function openFullChromeWindow(url, name, openerName) {
	return openWindow(url, name, 'directories,location,menubar,resizable,scrollbars,status,toolbar');
}

// Open a sized full-chrome (all GUI elements) window 
function openSizedFullChromeWindow(url, name, width, height, openerName) {
	return openCenteredWindow(url, name, width, height, true, true, 'directories,location,menubar,resizable,toolbar', openerName)
}

// Core utility function that actually creates the window and gives focus to it
function openWindow(url, name, properties, openerName) {
	// ie4.x pc can't give focus to windows containing documents from a different domain
	// in this case, initially load a local interstisial page to allow focussing before loading final url
	var agent = navigator.userAgent.toLowerCase();
	if (agent.indexOf("msie") != -1 && parseInt(navigator.appVersion) == 4 && agent.indexOf("msie 5") == -1 && agent.indexOf("msie5") == -1 && agent.indexOf("win") != -1 && url.indexOf('http://') == 0) {
	winReference = window.open('about:blank', name, properties);
	
	setTimeout('if (winReference && !winReference.closed) winReference.location.replace("' + url + '")', 300);
	}
	else {
	winReference = window.open(url, name, properties);
	}
	// ie doesn't like giving focus immediately (to new window in 4.5 on mac; to existing ones in 5 on pc)
	setTimeout('if (winReference && !winReference.closed) winReference.focus()', 200);
	
	if (openerName) self.name = openerName;
	return winReference;
}

/*******************************************************************************
Modal Dialog controls
*******************************************************************************/
// Close a dialog
// Call from onunload event handler of any page that can create a dialog
function closeDialog(dialog) {
	if (dialog && dialog.closed != true) dialog.close();
}

// Close parent popup
// Call from onload event handler of any page that could be created from a dialog
function closeParentDialog() {
	if (top.opener && isWindowPopup(top.opener)) {
	root = top.opener.top.opener;
	top.opener.close();
	top.opener = root;
	}
}

// Check if a window is a popup
function isWindowPopup(win) {
	return ((win.opener) ? true : false);
}

/*******************************************************************************
	Additional functions
*******************************************************************************/

function openImagePopupID(id, width, height, title){
	var url = 'get.asp?id=' + id;
	return openImagePopup(url, width, height, "image_" + id, title, 0);
}

function openFlashPopupID(id, width, height, title){
	var url = base_href + 'get.php?i.' + id;
	return openImagePopup(url, width, height, "image_" + id, title, 1);
}

function openImagePopup(url, width, height, window_name, title, flash){
	if(title + "" == "undefined"){
		title = "::";
	}
	win = openCenteredWindow("", window_name, parseInt(width), parseInt(height), 0, 0, "");
	var body = "<html><head><title>"+title+"</title></head><body onload='FitPic();'topmargin=0 leftmargin=0 marginwidth=0 marginheight=0>";
	if(!width && !height){
		body += '<script language=javascript>';
	  body += 'var arrTemp=self.location.href.split("?"); ';
	  body += 'var picUrl = (arrTemp.length>0)?arrTemp[1]:""; ';
		body += 'var NS = (navigator.appName=="Netscape")?true:false; ';
	
		body += 'function FitPic() { ';
		body += 'iWidth = (NS)?window.innerWidth:document.body.clientWidth; ';
		body += 'iHeight = (NS)?window.innerHeight:document.body.clientHeight; ';
		body += 'iWidth = document.images[0].width - iWidth; ';
		body += 'iHeight = document.images[0].height - iHeight; ';
		body += 'window.resizeBy(iWidth, iHeight); ';
		body += 'window.moveTo((screen.availWidth-document.images[0].width)/2, (screen.availHeight-document.images[0].height)/2); ';
	  body += 'self.focus(); ';
		body += '}; ';
		body += '</script>';
	}else{
		body += '<script>function FitPic(){}</script>';
	}
	if(!flash){
		body += "<img style=\"\" onclick=\"window.close();\" alt=\""+title+"\" src=\""+url+"\">";
	}
	else{
		body += '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0" width="'+width+'" height="'+height+'"><param name="movie" value="'+url+'"><param name="quality" value="high"><param name="menu" value="false"><embed src="'+url+'" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width='+width+' height='+height+'></embed></object>';
	}
	body += "</body></html>";
	
	win.document.write(body);
	win.document.close();
	return false;
}

function openWinInModal(url, width, height, params, title, charset){ // IE 5.5+ (because encodeURI used)
	url = base_href + "index.php?page=services/window_frame&title=" + encodeURIComponent(title) + "&charset=" + charset + "&url=" + encodeURIComponent(url);
	return openDialog(url, width, height, params, params["scrollbars"], params["resizable"]);
}

function openDialog(url, width, height, param, scroll, resizable){
	if(scroll + "" == "undefined"){ scroll = 0 }
	if(resizable + "" == "undefined"){ resizable = 0 }
	
	var rnd = Math.round((Math.random()*999)+1);
	var r = showModalDialog(url + "&r=" + rnd, param, 'dialogWidth:' + width + 'px;dialogHeight:' + height + 'px;center:1;dialogHide:0;help:0;edge:raised;status:0;unadorned:1;resizable:' + resizable + ';scroll:' + scroll);
	
	if (typeof(r) != "undefined")
		return r;
	else 
		return true;
}

if(!encodeURI){// Emulating encodeURI
	eval('function encodeURI(str){ return escape(str); }');
}

if(!encodeURIComponent){// Emulating encodeURIComponent
	eval('function encodeURIComponent(str){ return escape(str); }');
}


function getBrowserEngine() {
 if (document.adoptNode) {
  return 'mozilla';
 }
  else if (window.opera) {
  return 'mozilla';
 }
 else if (document.getElementById) {
  return 'explorer';
 } else {
  return null;
 }
}

var browserEngine = getBrowserEngine();


