
//////////////////////////////////////////////////////////////////////////////////////

// PROTOTYPES

/////////////

if( typeof HTMLElement != "undefined" && !HTMLElement.prototype.insertAdjacentElement ) {

    HTMLElement.prototype.insertAdjacentElement = function( where , parsedNode ) 	{
    
        switch ( where ) {
        
        case 'beforeBegin':
        this.parentNode.insertBefore( parsedNode ,this )
        break;
        
        case 'afterBegin':
        this.insertBefore( parsedNode , this.firstChild );
        break;
        
        case 'beforeEnd':
        this.appendChild( parsedNode );
        break;
        
        case 'afterEnd':
        
        if ( this.nextSibling ) 
        this.parentNode.insertBefore( parsedNode , this.nextSibling );
        else this.parentNode.appendChild( parsedNode );
        break;
        
        }
    		
    }

    HTMLElement.prototype.insertAdjacentHTML = function( where , htmlStr ) {
	
    var r = this.ownerDocument.createRange();
    r.setStartBefore( this );
    var parsedHTML = r.createContextualFragment( htmlStr );
    this.insertAdjacentElement( where , parsedHTML );
		
    }

    HTMLElement.prototype.insertAdjacentText = function ( where , txtStr ) {
    
    var parsedText = document.createTextNode( txtStr );
    this.insertAdjacentElement( where , parsedText );
    
    }
	
}

//////////////////////////////////////////////////////////////////////////////////////

// ONLOAD

/////////////

function addLoadEvent(func) {

var oldonload = window.onload; 

    if (typeof window.onload != 'function') { 
    
    window.onload = func; 
    
    } else { 
    
        window.onload = function() { 
        
            if (oldonload) { 
            
            oldonload(); 
            
            } 
        
        func(); 
        
        } 
    
    } 

} 


//////////////////////////////////////////////////////////////////////////////////////

// FRAMES

/////////////

if ( self != top ) {

top.location = self.location;

} 

//////////////////////////////////////////////////////////////////////////////////////

// NUMBERS

/////////////


function number_format(elem) {

var field = document.forms[elem.form.name].elements[elem.name]; 
var text = field.value;

// Strip off anything to the right of the DP
var rightOfDp = '';
var dpPos = text.indexOf('.');
if (dpPos != -1) {
    rightOfDp = text.substr(dpPos);
    text = text.substr(0, dpPos);
}

var leftOfDp = '';
var counter = 0;
// Format the remainder into 3 char blocks, starting from the right
for (var loop=text.length-1; loop>-1; loop--) {
    var char = text.charAt(loop);

    // Ignore existing spaces
    if (char == ' ') continue;

    leftOfDp = char + leftOfDp;
    counter++;
    if (counter % 3 == 0) leftOfDp = ' ' + leftOfDp;
}

// Strip leading space if present
if (leftOfDp.charAt(0) == ' ') leftOfDp = leftOfDp.substr(1);

var output = leftOfDp + rightOfDp;

output = output.replace(' ,',',');

field.value = output;

}

//////////////////////////////////////////////////////////////////////////////////////

// LINKS

/////////////

function defocus( x ) {

    if( navigator.appName == 'Microsoft Internet Explorer' ) {

    self.focus();
    
    } else {

    x.blur();
    
    }

}

function clearSelection() {

var sel;

    if(document.selection && document.selection.empty) {
    
    document.selection.empty();
    
    } else if(window.getSelection) {
    
    sel=window.getSelection();
    
        if(sel && sel.removeAllRanges) sel.removeAllRanges() ;
    
    }

}

//////////////////////////////////////////////////////////////////////////////////////

// TABLES

/////////////

function elem_tr_add( top_elem_name , sub_elem_name , method , parent_num , content_html ) {

var parent_id = sub_elem_name + parent_num;

    if ( !row_num ) var row_num = document.getElementById( top_elem_name ).getElementsByTagName( 'tr' ).length; 

row_num++;

var new_id = sub_elem_name + row_num;

    if ( method == 'before' ) {
    
    var next_elem = document.getElementById( parent_id );
    
    }
    
    if ( method == 'after' ) {
    
    var next_elem = document.getElementById( parent_id ).nextSibling;
    
    }

var tbody = document.getElementById( parent_id ).parentNode;
var tr = document.createElement( 'tr' );
//var td = document.createElement( 'td' );

tr.setAttribute( 'id' , new_id );
//tr.appendChild( td );

tbody.insertBefore( tr , next_elem );

var tr_content_new = content_html[1];

//tr_content_new = tr_content_new.replace( /{id}/g , new_id );
tr_content_new = tr_content_new.replace( /{row_num}/g , row_num );

document.getElementById( new_id ).innerHTML = tr_content_new;

}

// -------------------------------------------------------------------------------------

function hd_table_row_hover( this_row , bg_color ) {

    if (bg_color) {
    
    this_row.style.backgroundColor = bg_color;
    
    } else {
    
    this_row.style.backgroundColor = '';
    
    }

}

//////////////////////////////////////////////////////////////////////////////////////

// FORMS

/////////////

var nav = window.Event ? true : false;

    if (nav) {
    
    window.captureEvents(Event.KEYDOWN);
    window.onkeydown = NetscapeEventHandler_KeyDown;
    
    } else {
    
    document.onkeydown = MicrosoftEventHandler_KeyDown;
    
    }

function NetscapeEventHandler_KeyDown(e) {

  if (e.which == 13 && e.target.type != 'textarea' && e.target.type != 'submit') { return false };
  
  return true;

}

function MicrosoftEventHandler_KeyDown() {

  if (event.keyCode == 13 && event.srcElement.type != 'textarea' && event.srcElement.type != 'submit')

return false;
return true;

}

// -------------------------------------------------------------------------------------

function form_input_maxlength(obj) {

var mlength=obj.getAttribute? parseInt(obj.getAttribute("maxlength")) : ""

    if (obj.getAttribute && obj.value.length>mlength) {
    
     obj.value=obj.value.substring(0,mlength);
     
        if (obj.createTextRange) {
        
        var range = obj.createTextRange();
        range.collapse(false);
        range.select();
        
        } else if (obj.setSelectionRange) {
        
        obj.focus();
        var length = obj.value.length;
        obj.setSelectionRange(length, length);
        
        }
     
    }
    
}

// -------------------------------------------------------------------------------------

var chars_after_space = 0;

function form_input_wrapforce( limit , obj ) {

    if (obj.value.lastIndexOf(' ') == (obj.value.length - 1)) {
    
    chars_after_space = 0;
    
    } else {
    
    chars_after_space++;
    
    }

    if ( chars_after_space > limit ) {
    
    obj.value = obj.value + " ";
    chars_after_space = 0;
    
    }
    
}


// -------------------------------------------------------------------------------------

function form_elem_string_insert(myForm, myField, myValue) {

myField = document.forms[myForm].elements[myField];

    //IE support
    if (document.selection) {
    
    myField.focus();
    sel = document.selection.createRange();
    sel.text = myValue;
    
    //MOZILLA/NETSCAPE support
    } else if (myField.selectionStart || myField.selectionStart == '0') {
    
    var startPos = myField.selectionStart;
    var endPos = myField.selectionEnd;
    myField.value = myField.value.substring(0, startPos)
    + myValue
    + myField.value.substring(endPos, myField.value.length);
    
    } else {
    
    myField.value += myValue;
    
    }

}

// -------------------------------------------------------------------------------------

function form_elem_text_tabbing(event,obj) {
	var tabKeyCode = 9;
	if (event.which) // mozilla
		var keycode = event.which;
	else // ie
		var keycode = event.keyCode;
	if (keycode == tabKeyCode) {
		if (event.type == "keydown") {
			if (obj.setSelectionRange) {
				// mozilla
				var s = obj.selectionStart;
				var e = obj.selectionEnd;
				obj.value = obj.value.substring(0, s) + 
					"\t" + obj.value.substr(e);
				obj.setSelectionRange(s + 1, s + 1);
				//obj.focus();
			} else if (obj.createTextRange) {
				// ie
				document.selection.createRange().text="\t"
				obj.onblur = function() { this.focus(); this.onblur = null; };
			} else {
				// unsupported browsers
			}
		}
		if (event.returnValue) // ie ?
			event.returnValue = false;
		if (event.preventDefault) // dom
			event.preventDefault();
		return false; // should work in all browsers
	}
	return true;
}

// -------------------------------------------------------------------------------------

function form_elem_reorder ( elem_name ) {

// reset order fields
var elem_num = document.getElementsByName( elem_name );
var elem_tot = elem_num.length;

    for ( i=0 ; i<elem_tot ; i++ ) {

    elem_num[i].value = i + 1;

    }
    z
}

// -------------------------------------------------------------------------------------

function form_empty_option_to_text(oldObject, oType) {

    if (oldObject.value == '') {
    
    var newObject = document.createElement('input');
    newObject.type = oType;
        
        if(oldObject.size) newObject.size = oldObject.size;
        //if(oldObject.value) newObject.value = oldObject.value;
        if(oldObject.name) newObject.name = oldObject.name;
        if(oldObject.id) newObject.id = oldObject.id;
        if(oldObject.className) newObject.className = oldObject.className;

    oldObject.parentNode.replaceChild(newObject,oldObject);
    newObject.focus();
    return newObject;
         
    }
  
}

// -------------------------------------------------------------------------------------

function form_textarea_count_lines (strtocount, cols) {

var hard_lines = 1;
var last = 0;

    while ( true ) {

    last = strtocount.indexOf("\n", last+1);
    hard_lines ++;
    
        if ( last == -1 ) break;

    }

var soft_lines = Math.round(strtocount.length / (cols-1));
var hard = eval("hard_lines  " + unescape("%3e") + "soft_lines;");

    if ( hard ) soft_lines = hard_lines;

    return soft_lines;

    }

function form_textarea_auto_resize() {

var the_form = document.forms[0];

    for ( var x in the_form ) {
    
        if ( ! the_form[x] ) continue;
        if( typeof the_form[x].rows != "number" ) continue;
        
    the_form[x].rows = form_textarea_count_lines(the_form[x].value,the_form[x].cols) +1;
    
    }

setTimeout("form_textarea_auto_resize();", 300);

}

//////////////////////////////////////////////////////////////////////////////////////

// LAYERS

/////////////

function id_hide ( targetId ) {

    if ( document.getElementById ) {

    document.getElementById( targetId ).style.display = 'none';

    }
    
}

// -------------------------------------------------------------------------------------

function id_show ( targetId ) {

    if ( document.getElementById ) {

    document.getElementById( targetId ).style.display = '';

    }
    
}

// -------------------------------------------------------------------------------------

function id_toggle ( targetId ) {

    if ( document.getElementById ) {
    
    target = document.getElementById( targetId );
    
        if ( target.style.display == 'none' ) {
        
        target.style.display = '';
        
        } else {
        
        target.style.display = 'none';
        
        }
        
    }
    
}

// -------------------------------------------------------------------------------------

function id_blink ( _tag , _class ) {

var el = document.body.getElementsByTagName( _tag );

    for (var i = 0; i < el.length; i++) {
    
        if (el[i].className == _class){
        
        el[i].style.visibility = el[i].style.visibility == 'hidden' ? 'visible' : 'hidden';
        
        }
    
    }

}

// -------------------------------------------------------------------------------------

function id_class_swap ( _tag , _class1 , _class2 ) {

var el = document.body.getElementsByTagName( _tag );

    for (var i = 0; i < el.length; i++) {

        if (el[i].className == _class1) {
        
        el[i].className = _class2;
        
        } else if (el[i].className == _class2) {
        
        el[i].className = _class1;
        
        }

    }

}

// -------------------------------------------------------------------------------------

function id_autoscroll(id, sx, sy) {

ns = (navigator.appName.indexOf("Netscape") != -1);
d = document;

var el = d.getElementById?d.getElementById(id):d.all?d.all[id]:d.layers[id];
var px = document.layers ? "" : "px";

window[id.replace(/\W/g,'') + "_obj"] = el;

var offset_y_first = el.offsetTop;
var offset_y_temp = 0;

    if (d.layers) el.style = el;
    
el.cx = el.sx = sx;
el.cy = el.sy = sy;

el.sP = function(x,y) {

        this.style.left = x + px;
        this.style.top = y + px;

        };

    el.id_scroll = function() {
    
    var pX, pY;
    
    pX = (this.sx >= 0) ? 0 : ns ? innerWidth :
    document.documentElement && document.documentElement.clientWidth ?
    document.documentElement.clientWidth : document.body.clientWidth;
    
    pY = ns ? pageYOffset : document.documentElement && document.documentElement.scrollTop ?
    document.documentElement.scrollTop : document.body.scrollTop;
    
        if (this.sy < 0) {
        
        pY += ns ? innerHeight : document.documentElement && document.documentElement.clientHeight ?
        document.documentElement.clientHeight : document.body.clientHeight;
        
        }
     
    this.cx += (pX + this.sx - this.cx) / 2;
    
        if(offset_y_first < 1) offset_y_first = this.offsetTop;
        if(pY > offset_y_first) offset_y_temp = offset_y_first - sy;
        
        if(pY < offset_y_first) {
        
        offset_y_temp = 0 + sy;    

        this.cy =  offset_y_first - offset_y_first;
        
        } else {
        
        this.cy += (pY + this.sy - this.cy - offset_y_temp) / 2;
        
        }
    
    this.sP(this.cx, this.cy);
        
    setTimeout(this.id.replace(/\W/g,'') + "_obj.id_scroll()", 10);

    }
   
return el;

}

// -------------------------------------------------------------------------------------
// tabs management
function id_toggle_tabs ( tabname , zonename , targetid , idnum ) {
    
    // fix possible targetid errors
    if ( targetid >= idnum || targetid == 0 ) targetid = 1;
    
    // loop through zones
    for ( var j=1; j <= idnum; j++ ) {
        
        if ( document.getElementById( zonename+j ) ) {

        // hide zones linked to unclicked tabs
        document.getElementById( zonename+j ).style.display = 'none';
        
            // fix look of unclicked tabs
            if ( j != targetid ) document.getElementById( tabname+j ).className = tabname + 'off';
        
        }
        
    }

    if ( document.getElementById( zonename + targetid ) ) {
    
    // change look of clicked tab
    document.getElementById( tabname + targetid ).className = tabname+'on';
    
    // unhide zone linked to specified tab
    //document.getElementById( zonename + targetid ).style.display = '';
    Effect.Appear( zonename + targetid );
    
    
    // save clicked tab number in cookie
    cookie_make( 'admin_tab_num' , targetid , 2 );
   
    }

}

// -------------------------------------------------------------------------------------

function elem_div_add ( top_elem_name , sub_elem_name , method , parent_num , cat_parent_ID , pixel_num , content_html ) {

parent_id = sub_elem_name + parent_num;

    if ( !row_num ) var row_num = document.getElementById( top_elem_name ).getElementsByTagName( 'div' ).length - 1;
    if ( method == 'before' ) var next_elem = document.getElementById( parent_id );
    if ( method == 'after' ) var next_elem = document.getElementById( parent_id ).nextSibling;

row_num++;

var new_id = sub_elem_name + row_num;

    if ( pixel_num > 0 ) {
    
    var prefix = content_html[0];
    
    } else {
    
    var prefix = '';
    
    }

var div_content_new = '';
div_content_new = prefix + content_html[1];

div_content_new = div_content_new.replace( /{cat_parent_ID}/g , cat_parent_ID );
div_content_new = div_content_new.replace( /{row_num}/g , row_num );
div_content_new = div_content_new.replace( /{pixel_num}/g , pixel_num );
div_content_new = div_content_new.replace( /{parent_id}/g , parent_id );


var div = document.createElement( 'div' );
div.setAttribute( 'id' , new_id );

    if ( method == 'inside' ) {
    
    var parent_node = document.getElementById( parent_id );
    parent_node.appendChild( div );
        
    } else {
    
    var parent_node = document.getElementById( parent_id ).parentNode;
    parent_node.insertBefore( div , next_elem );

    }

document.getElementById( new_id ).style.padding =  '0px 0px 0px ' + pixel_num + 'px';
document.getElementById( new_id ).innerHTML = div_content_new;

}

// -------------------------------------------------------------------------------------

function elem_div_page_add ( method , root_num, row_prefix , row_num , row_parent_ID , row_order ) {

var tab = cookie_read('admin_tab_num');
    
    if (!tab) tab = 0;

row_num_last[tab]++;
row_ID[tab]++;

var pixel_num = 80;

var prefix = pages_html_temp[tab][root_num][0];

id_parent = row_prefix + row_num;

    if ( method == 'before' ) {
    
    var next_elem = document.getElementById( id_parent );
    row_order--;
    
    }
    
    if ( method == 'after' ) {
    
    var next_elem = document.getElementById( id_parent ).nextSibling;
    row_order++;
    
    }
    
    if ( method == 'inside' ) row_order++;

var id_new = row_prefix + row_num_last[tab];

var div = document.createElement( 'div' );
div.setAttribute( 'id' , id_new );

    if ( method == 'inside' ) {
    
    var parent_node = document.getElementById( id_parent );
    parent_node.appendChild( div );
    
        if ( parent_node.style.padding == '' ) pixel_num /= 2;
    
    var div_padding = '0px 0px 0px ' + pixel_num + 'px';
    
    } else {

    var parent_node = document.getElementById( id_parent ).parentNode;
    var div_padding = document.getElementById( id_parent ).style.padding;

        if ( div_padding == '' ) prefix = '';

    parent_node.insertBefore( div , next_elem );

    }

var div_content_new = '';

    if ( max_pixel[tab] > 0 && row_num_parent != 'NULL' && pixel_num >= max_pixel[tab] ) {

    div_content_new = prefix + pages_html_temp[tab][root_num][1] + pages_html_temp[tab][root_num][3] + pages_html_temp[tab][root_num][4];

    } else {
    
    div_content_new = prefix + pages_html_temp[tab][root_num][1] + pages_html_temp[tab][root_num][2] + pages_html_temp[tab][root_num][3] + pages_html_temp[tab][root_num][4];
        
    }

    if ( row_parent_ID == 'NULL' ) {
    
    row_parent_ID = '\'NULL\'';

    }

div_content_new = div_content_new.replace( /{row_ID}/g , row_ID[tab] );
div_content_new = div_content_new.replace( /{row_parent_ID}/g , row_parent_ID );
div_content_new = div_content_new.replace( /{row_num_last}/g , row_num_last[tab] );
div_content_new = div_content_new.replace( /{row_order}/g , (row_order) );

    if (set_path == 'yes') {
    
    var row_path = '';
    
        if (row_parent_ID == '\'NULL\'') {
        
        row_path = '';
    
        } else {
        
            if ( method == 'inside' ) {
            
            row_path = document.getElementById( 'path_' + row_num ).value + '' + row_parent_ID + '.';
            
            } else {
            
            row_path = document.getElementById( 'path_' + row_num ).value;
            
            }
        
        }
     
    div_content_new = div_content_new.replace( /{row_path}/g , row_path );
    
    document.getElementById( id_new ).style.padding = div_padding;
    document.getElementById( id_new ).innerHTML = div_content_new;
    
        if (document.getElementById( 'path_' + row_num_last[tab] )) {
        
        document.getElementById( 'path_' + row_num_last[tab] ).value = row_path;
        
        }
    
    } else {
    
    document.getElementById( id_new ).style.padding = div_padding;
    document.getElementById( id_new ).innerHTML = div_content_new;    

    }

}


// -------------------------------------------------------------------------------------

function elem_div_html_multiply ( div_id , content_html , num ) {

var div_content_new = '';

    for ( i=0 ; i<num ; i++ ) {
    
    div_content_new += content_html;
    
    }

document.getElementById( div_id ).innerHTML = div_content_new;

}

// -------------------------------------------------------------------------------------

function elem_del ( this_id ) {
   
var el = document.getElementById( this_id );
el.parentNode.removeChild( el );

}

// -------------------------------------------------------------------------------------

function elem_move(this_id , nstep) {

    if (nstep == null) {
    
    var el = document.getElementById(this_id);
    el.parentNode.appendChild(el);    
    
    } else {
    
        //nstep=1 move down 1, nstep=-1 move up 1
        var el = document.getElementById( this_id );
        var idx;
        
        if (el) {
        
            var cel=el.parentNode.getElementsByTagName(el.tagName);
            for (var i=0;i<cel.length;i++) {
            
                if (el==cel[i]) {
                
                idx=i;
                break;
                
                }
            }
            
            if (idx==null) {
                //alert("element not found");
            } else {
            
                if ((idx+nstep)>-1 && (idx+nstep)<cel.length) {
    
                    el.parentNode.insertBefore(el, cel[idx+nstep]);
                    if (nstep>0) {
                    
                    el.parentNode.insertBefore(cel[idx+nstep],el);
                    
                    }
                    
                } else {
                    //alert("move steps out of range")
                }
                
            }
            
        }
        
    }
    
}

// -------------------------------------------------------------------------------------

function elem_chkbox_multi ( method , this_name , checked_status , field_name , value_checked , value_unchecked ) {

// method :  div or form
// this_name : div name or form name depending on method
// checked_status : true or false

    if ( method == 'div' ) {
    
    var this_div = document.getElementById( this_name );
    var elem_num = this_div.getElementsByTagName( 'input' );
    var elem_tot = elem_num.length;
    
    }
    
    if ( method == 'form' ) {
    
    var elem_num = document.forms[this_name].elements;
    var elem_tot = elem_num.length;

    }

var first_chkbox = -1;
var field_value = '';

    for ( i=0 ; i<elem_tot ; i++ ) {
    
        if ( elem_num[i].getAttribute( 'type' ) == 'checkbox' ) {

            if ( first_chkbox < 0 ) first_chkbox = i;
        
            if ( checked_status == null ) {
            
            checked_status = elem_num[first_chkbox].checked;
            
            }
        
        elem_num[i].checked = checked_status;
        
        }

        if (field_name != null) {
        
            if (elem_num[i].getAttribute( 'name' ) == field_name) {
            
                if (checked_status == true) field_value = value_checked;
                if (checked_status == false) field_value = value_unchecked;
    
            elem_num[i].value = field_value;

            }
        
        }

    }

}

// -------------------------------------------------------------------------------------

function elem_chkbox_to_field ( chkbox , value_checked , value_unchecked , field_id ) {

var field_value = '';

    if (chkbox.checked == true) field_value = value_checked;
    if (chkbox.checked == false) field_value = value_unchecked;

document.getElementById( field_id ).value = field_value;

}

//////////////////////////////////////////////////////////////////////////////////////

// COOKIES

/////////////

function cookie_make (name , value , days) {

	if ( days ) {
	
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	
  }
  
	else var expires = "";
	var ck = name+"="+value+expires+"; path=/";
	document.cookie = ck;
	
}

// -------------------------------------------------------------------------------------

function cookie_read ( name ) {

var nameEQ = name + "=";
var ca = document.cookie.split(';');

    for ( var i=0 ; i<ca.length ; i++ ) {
    
		var c = ca[i];
		
        while ( c.charAt(0) == ' ' ) c = c.substring(1,c.length);
    		if ( c.indexOf(nameEQ) == 0 ) return c.substring(nameEQ.length,c.length);
    
    }
	
return null;

}

// -------------------------------------------------------------------------------------

function cookie_delete ( name ) {

cookie_make( name , "" , -1 );
    
}

//////////////////////////////////////////////////////////////////////////////////////

// URLS

/////////////

function hd_redirect( url ) {

document.location.href = url;

}

// -------------------------------------------------------------------------------------

function bookmark_add(url, name) {

    if (document.all) {
    
    window.external.AddFavorite(url, name);
    
    } else {
    
    window.sidebar.addPanel(name, url, '');
    
    }

}


//////////////////////////////////////////////////////////////////////////////////////

// STATUS BAR

/////////////

function hidestatus () {

window.status=''
return true

}

// -------------------------------------------------------------------------------------

    if ( document.layers ) document.captureEvents( Event.MOUSEOVER | Event.MOUSEOUT )

document.onmouseover = hidestatus;
document.onmouseout = hidestatus;


//////////////////////////////////////////////////////////////////////////////////////

// AJAX

/////////////


function createRequestObject() {
    var ro;
    if (window.XMLHttpRequest) {
        try {
            ro = new XMLHttpRequest();
        } catch(e) {
            ro = false;
        }
    } 
    else if (window.ActiveXObject) {
        try {
            ro = new ActiveXObject("Microsoft.XMLHTTP");
        } catch(e) {
            ro = false;
        }
    } 
    return ro;
}

// -------------------------------------------------------------------------------------

var http = createRequestObject();
var busy = false;
var elementsToUpdate = new Array();

// -------------------------------------------------------------------------------------

function ajax_addElementToUpdate( el_id ) {

elementsToUpdate[elementsToUpdate.length] = el_id;

}

// -------------------------------------------------------------------------------------

function ajax_updateGroup( prefix , action ) {

    for (var i=0; i<elementsToUpdate.length; i++) {
    
        if (elementsToUpdate[i].substr(0, prefix.length) == prefix) {
        
        ajax_updateElement(elementsToUpdate[i], action);
            
        }
        
    }
    
}

// -------------------------------------------------------------------------------------

function ajax_updateElement( el_id , page , action ) { 

    if (busy == false) {
    
    busy = true;
    http.open('get', page + '?rnd=' + Math.random()*4 + '&ajax_div=' + el_id + '&ajax_var=' + action);
    http.onreadystatechange = ajax_doUpdate;
    http.send(null);
   
    } else {
    
    window.setTimeout("ajax_updateElement('" + el_id + "', '" + action + "')", 10);
    
    }
    
}

// -------------------------------------------------------------------------------------

function ajax_doUpdate() {

    if (http.readyState == 4) {
    
    var response = http.responseText;
    var update = new Array();
        
        if (response.indexOf('|') != -1) {
        
        update = response.split('|'); 
        var el_id = update.shift();
        el_id = el_id.replace(/^\s+|\s+$/g, '');
        var text = update.join("|");
        document.getElementById(el_id).innerHTML = text;
        
        }
        
    busy = false;
    
    }

}

// -------------------------------------------------------------------------------------

function documentOverlay() {
 
    // Shortcut to current instance of object:
    var instance = this,
 
    // Cached body height:
    bodyHeight = (function(){
        return getDocDim('Height','min');    
    })();
 
    // CSS helper function:
    function css(el,o) {
        for (var i in o) { el.style[i] = o[i]; }
        return el;
    };
 
    // Document height/width getter:
    function getDocDim(prop,m){
        m = m || 'max';
        return Math[m](
            Math[m](document.body["scroll" + prop], document.documentElement["scroll" + prop]),
            Math[m](document.body["offset" + prop], document.documentElement["offset" + prop]),
            Math[m](document.body["client" + prop], document.documentElement["client" + prop])
	);
    }
 
    // get window height: (viewport):
    function getWinHeight() {
        return window.innerHeight ||
                (document.compatMode == "CSS1Compat" && document.documentElement.clientHeight || document.body.clientHeight);
    }
 
    // Public properties:
 
    // Expose CSS helper, for public usage:
    this.css = function(o){
        css(instance.element, o);
        return instance;
    };
 
    // The default duration is infinity:
    this.duration = null;
 
    // Creates and styles new div element:
    this.element = (function(){
        return css(document.createElement('div'),{
            width: '100%',
            height: getDocDim('Height') + 'px',
            position: 'absolute', zIndex: 999,
            left: 0, top: 0,
            cursor: 'wait'
        });
    })();
 
    // Resize cover when window is resized:
    window.onresize = function(){
 
        // No need to do anything if document['body'] is taller than viewport
        if(bodyHeight>getWinHeight()) { return; }
 
        // We need to hide it before showing
        // it again, due to scrollbar issue.
        instance.css({display: 'none'});
        setTimeout(function(){
            instance.css({
                height: getDocDim('Height') + 'px',
                display: 'block'
            });
        }, 10);
 
    };
 
    // Remove the element:
    this.remove = function(){
        this.element.parentNode && this.element.parentNode.removeChild(instance.element);
    };
 
    // Show element:
    this.show = function(){};
 
    // Event handling helper:
    this.on = function(what,handler){
        what.toLowerCase() === 'show' ? (instance.show = handler)
        : instance.element['on'+what] = handler;
        return instance;
    };
 
    // Begin:
    this.init = function(duration){
 
        // Overwrite duration if parameter is supplied:
        instance.duration = duration || instance.duration;
 
        // Inject overlay element into DOM:
        document.getElementsByTagName('body')[0].appendChild(instance.element);
 
        // Run show() (by default, an empty function):
        instance.show.call(instance.element,instance);
 
        // If a duration is supplied then remove element after
        // the specified amount of time:
        instance.duration && setTimeout(function(){instance.remove();}, instance.duration);
 
        // Return instance, for reference:
        return instance;
 
    };
 
}








