<?php
?>
var g_triggers = Array();
function triggers()
{
var els = document.getElementsByTagName("*");
var regex = new RegExp(/\s(\w+)((\s(arg-[\w-]+\b))+|\b)/);
var k = 0;
var res = null;
var parts = null;
for ( var i = 0; i < els.length; i = i + 1 ) {
if ( els[i].className ) {
x_class = ' ' + els[i].className;
parts = x_class.split( /\bjs\b/ );
for ( var j = 1; j < parts.length; j = j + 1 ) {
if( res = regex.exec(parts[j]) ) {
k = g_triggers.length;
if( typeof eval( "window." + res[1] ) == 'function' ) {
eval( "g_triggers[" + k + "] = new " + res[1] + "(" + k + ");" );
g_triggers[k].init( els[i], res[2].replace( / arg-/g, ',' ).replace( /^,/, '' ) );
}
}
}
}
}
}
trigger_popup_window = false;
function popup(trigger_id)
{
this.trigger_id = trigger_id;
this.size = { small: [250,250], medium: [400,400], large: [600,580] };
this.init = function( el, args )
{
el.trigger = this;
if( this.size[args] ) {
this.width = this.size[args][0];
this.height = this.size[args][1];
} else {
this.width = this.size["medium"][0];
this.height = this.size["medium"][1];
}
el.onclick = function(e) { return this.trigger.onclick(this) }
}
this.onclick = function(a) {
trigger_popup_window = window.open( a.href, 'trigger_popup_window', 'width='+ this.width + ',height='+this.height+',toolbar=no,directories=no,location=no,scrollbars=yes,left=200,top=150' );
trigger_popup_window.focus();
return false;
}
}
function closepopup()
{
if( trigger_popup_window )
{
trigger_popup_window.close();
}
}
function hasClass( el, className )
{
var regex = new RegExp("\\b"+className+"\\b");
return regex.exec( el.className );
}
function getElementsByClassName( node, classname )
{
var nodes = node.getElementsByTagName( "*" );
var els = new Array(), j = 0;
for ( var i = 0; i < nodes.length; i++ ) {
if ( hasClass( nodes[i], classname ) ) {
els[j] = nodes[i];
j++;
}
}
return els;
};
function paging( trigger_id )
{
this.trigger_id = trigger_id;
this.init = function( el, args )
{
this.el = el;
this.xmlhttp = new AJAX();
var _self = this;
if ( this.el.getElementsByTagName( "tfoot" ).length != 1 ) {
return;
}
this.prev_element = getElementsByClassName( this.el.getElementsByTagName( "tfoot" )[0], "prev" )[0];
this.next_element = getElementsByClassName( this.el.getElementsByTagName( "tfoot" )[0], "next" )[0];
if ( this.next_element.getElementsByTagName( "a" ).length == 1 ) {
this.addAction( this.next_element.getElementsByTagName( "a" )[0] );
}
if ( this.prev_element.getElementsByTagName( "a" ).length == 1 ) {
this.addAction( this.prev_element.getElementsByTagName( "a" )[0] );
}
};
this.addAction = function( obj )
{
var _self = this;
obj.onclick = function( e ) {
_self.sendRequest( this.href );
return false;
};
};
this.sendRequest = function( url )
{
var _self = this;
var query = new String(url).split( "?" );
var url = query.shift();
query.push( "ajax=1" );
_self.xmlhttp.open( "GET", url + "?" + query.join( "&"), true );
_self.xmlhttp.onreadystatechange = function() {
if ( _self.xmlhttp.readyState == 4 ) {
if ( _self.xmlhttp.status == 200 ) {
_self.readRecordSet( _self.xmlhttp.responseXML );
}
}
};
_self.xmlhttp.send( null );
};
this.readRecordSet = function( xml )
{
var recordset = xml.getElementsByTagName( "recordset" )
if ( recordset.length != 1 ) {
return;
}
recordset = recordset[0];
var records = recordset.getElementsByTagName( "record" );
if ( records.length >= 1 ) {
this.buildBody( records );
}
var pagination = recordset.getElementsByTagName( "pagination" );
if ( pagination.length == 1 ) {
this.buildPaging( pagination[0] );
}
};
this.buildBody = function( rows )
{
var tbody = this.el.getElementsByTagName( "tbody" )[0];
var row = tbody.firstChild;
while ( tbody.hasChildNodes() ) {
tbody.removeChild( tbody.lastChild );
}
for ( var i = 0; i < rows.length; i++ ) {
var tr = document.createElement( "tr" );
tr.style.background = rows[i].getAttribute("background");
var fields = rows[i].getElementsByTagName( "field" );
for ( var j = 0; j < fields.length; j++ ) {
var td = document.createElement( "td" );
if ( null != fields[j].getAttribute( "nbsp-on-empty" ) ) {
if( null == fields[j].firstChild ) {
td.innerHTML = " ";
}
}
if ( null != fields[j].getAttribute( "img" ) ) {
if ( 1 == fields[j].getAttribute( "bool" ) ) {
var image = document.createElement( "img" );
image.src = fields[j].getAttribute( "img" );
td.appendChild( image );
} else if ( 1 == fields[j].getAttribute( "edit" ) ) {
var a = document.createElement( "a" );
a.href = fields[j].firstChild.nodeValue;
var image = document.createElement( "img" );
image.src = fields[j].getAttribute( "img" );
a.appendChild( image );
td.appendChild( a );
} else {
td.innerHTML = " ";
}
}
if ( null != fields[j].firstChild && "" == td.innerHTML ) {
td.innerHTML = fields[j].firstChild.nodeValue;
}
tr.appendChild( td );
}
tbody.appendChild( tr );
}
};
this.buildPaging = function( o )
{
var prev = o.getElementsByTagName( "prev" )[0];
this.prev_element.innerHTML = "";
if ( "" != prev.getAttribute("link") ) {
var link = document.createElement( "a" );
link.href = prev.getAttribute("link");
link.innerHTML = prev.childNodes[0].data;
this.prev_element.appendChild( link );
} else {
this.prev_element.innerHTML = prev.childNodes[0].data;
}
var next = o.getElementsByTagName( "next" )[0];
this.next_element.innerHTML = "";
if ( "" != next.getAttribute("link") ) {
var link = document.createElement( "a" );
link.href = next.getAttribute("link");
link.innerHTML = next.childNodes[0].data;
this.next_element.appendChild( link );
} else {
this.next_element.innerHTML = next.childNodes[0].data;
}
if ( this.next_element.getElementsByTagName( "a" ).length == 1 ) {
this.addAction( this.next_element.getElementsByTagName( "a" )[0] );
}
if ( this.prev_element.getElementsByTagName( "a" ).length == 1 ) {
this.addAction( this.prev_element.getElementsByTagName( "a" )[0] );
}
};
}
addEvent( window, 'load', triggers, false );