
var serverDateFormat = 0;
var serverTimeFormat = 0;
var serverDateSeparator = 0;
var serverTimeSeparator = 0;

var LSearch = {}
LSearch.Base = function() {};
LSearch.Base.prototype = {
 baseInitialize: function(LB_element,  options) {
    this.ctrlcaller      = LB_element
    this.LB	     = $(LB_element);
    
    if(this.setOptions)
      this.setOptions(options);
    else
      this.options = options || {};
      
    this.viewname    = this.options.viewname;
    this.xwhere	     = this.options.xwhere;
    this.xfrom       = this.options.xfrom;
    this.listaction   = this.options.listaction;
    
    this.PB = $(this.LB.id+'_PB_SELECTOR')
    this.PK = $(this.LB.id+'_EF_PK')
    this.SELECTION = $(this.LB.id+'_EF_SELECTION')
    
    }
}






Ajax.LSearch = Class.create();

Object.extend(Object.extend(Ajax.LSearch.prototype, LSearch.Base.prototype), {
  initialize: function(LB_element,options ) {
  this.baseInitialize(LB_element,options);
    this.options.asynchronous  = true;
    this.options.defaultParams = this.options.parameters || null;
    if (this.options.jsfunc && this.options.jsfunc != '')
   		{
   			var x = $(this.LB.id+'_PB_SELECTOR')
   			Event.observe(x, "click", this.onClick.bindAsEventListener(this));
   			
   		}
	else
		{
    		//var x = $(this.LB.id+'_PB_SELECTOR')
   		//x.onClick = function () {setLoading();}
   	}
  },
  
  onClick: function(event)
  {
  var jsstr = this.options.jsfunc + "('"+ $(this.LB.id+'_EF_PK').value +"');"
  eval(jsstr);
  Event.stop(event);
  return false;
},

  getView: function() {
    this.LB.innerHTML='Loading...'
    this.options.onComplete    = this.onComplete.bind(this);
    this.options.method = 'get';
    var crit ='<GETVIEW HEADERONLY ="'+this.options.headeronly+'"><'+this.viewname+' XFROM="'+this.xfrom+'" XWHERE="'+this.xwhere+'" ACTION="'+this.listaction+'" CALLER="'+this.ctrlcaller+'" /></GETVIEW>';
    crit = encodeURIComponent(crit);

    //We dont care about theese
    Ajax.activeRequestCount--;
    
    if (this.options.page)
    	{
    	var surl = this.options.url+this.options.page+'?'+crit;    		

	}
    else
    	{
	var surl = this.options.url+'ajax_search.pwexec?'+crit;
	}
    	
    new Ajax.Request(surl, this.options);

  },
  
onCompleteExpFile: function (request) {
//alert(request.responseText);
var dom = parse(request.responseText);
var root = dom.firstChild;
var attributes = root.attributes;
for (var i = 0; i < attributes.length; i++)
	{
	if (attributes[i].name == 'TEMPFILENAME')
		var openFileName = attributes[i].value;
	else if (attributes[i].name == 'MAX_REACHED')
		pobAlert(attributes[i].value);
	}

$('URL').value = $('URLLOO').value;
$('PARAM0').value = openFileName;

openwindow("PW_UPLOAD.WFILOPEN?P1=");

},
  
  
ajax_export_list: function (pThis)
{

if (this.table.rows && this.table.rows.length > 0) {
        var firstRow = this.table.rows[0];
    }
    if (!firstRow) return;
//pwh = window.open('about:blank');    	
var iRows = this.table.rows;
var str = '';
var maxReached = 'N';
for (var j=0;j<this.table.rows.length;j++) {
	firstRow = this.table.rows[j];
	//listCellSelection, listCellSelected
	if ((firstRow.className == 'listCellSelection') || (firstRow.className == 'listCellSelected')||(this.SELECTION.value==''))
		{
		for (var i=0;i<firstRow.cells.length;i++) {
		        var cell = firstRow.cells[i];
		        var txt = ts_getInnerText(cell);
		        if (j == 0)
		        	{
		        	txt = txt.substring(0,txt.length-2);
		        	}
		        str = str + txt + ';'
		}
		str = str + '<BR>';
		if (str.length > 15000) 
			{
				maxReached = 'Y';
				break;
			}
		}
	//str = str + String.fromCharCode(13) + String.fromCharCode(10)
	

}
	{
	var surl = $('URLLOO').value+'ajax_misc.expfile';
	//if (UnicodeUsed==false)
	//{
	//	str=UTF8.decode(str);
	//	}
	new Ajax.Request(surl, {asynchronous:false, method:"get", requestHeaders: ['FILE', str, 'MAXREACHED', maxReached], onComplete:this.onCompleteExpFile.bind(this)});
	}

return 0;        
       
i = 0
try
{
pwh.document = str;       
}
catch(e)
{
	 i = 0
	 while (i<2000)
	 	{
	 		i = i + 1
	 	}
	 	try
	 	{
 		pwh.document.body.innerHTML = str;       
 		}
 		catch(e){}
	 	
}
       
},

  

  onComplete: function(request) {
    //We dont care about theese
    Ajax.activeRequestCount++;
    this.LB.innerHTML=request.responseText
    serverDateFormat = request.getResponseHeader('SERVER_DATE_FORMAT');
    serverTimeFormat = request.getResponseHeader('SERVER_TIME_FORMAT');
    serverDateSeparator = request.getResponseHeader('SERVER_DATE_SEPARATOR');
    serverTimeSeparator = request.getResponseHeader('SERVER_TIME_SEPARATOR');
    
    //alert(serverDateFormat);
    if (this.options.headeronly == 0)
        try
	{
	if (this.options.nocount==null)
		{
	 	var msgTxt = request.getResponseHeader('RESULT_TXT');
	 	var expTxt = request.getResponseHeader('EXPORT_TXT');

	 	var recCount = ((this.LB.firstChild.rows.length)-1);
	 	msgTxt = msgTxt.replace('(P1)', recCount.toString());
	 	objTDRecFound = $(this.ctrlcaller+'_EF_NO')
	 	if (objTDRecFound == null)
	 		{
			//new Insertion.Before(this.LB, '<table class="listRecsFound" cellspacing="0" cellpadding="0"><tr><td ID="'+this.ctrlcaller+'_EF_NO">'+msgTxt+'</td><td><input type="button" onclick="ajax_export_list('+"'"+this.viewname+"'"+');" value="export"></td>');
			new Insertion.Before(this.LB, '<table width="100%" class="listRecsFound" cellspacing="0" cellpadding="0"><tr><td ID="'+this.ctrlcaller+'_EF_NO">'+msgTxt+'</td><td align="right"><a Class="zoom" href ="#" id="'+this.ctrlcaller+'_EXP">'+expTxt+'</a></td>');
	   		new Insertion.After(this.LB, '</tr><tr><td></td></tr></table>');
	   		
	   		Event.observe($(this.ctrlcaller+'_EXP'), "click", this.ajax_export_list.bindAsEventListener(this));
	   		
			}
		else
			{
			objTDRecFound.innerHTML = msgTxt;
			}
		}

	}
	catch(e)
	{
	//alert('e');	
	}
   
   
   
   var selected = this.SELECTION.value;   	
   if (selected != '')
   	{
   	this.aSelected    = selected.split('|');
	}
   else
	{
	this.aSelected = new Array();
	}
   
   this.table = gEBI(this.ctrlcaller+"_Table3");
   if (this.listaction == 2)
   {
    //table.onmouseover = table.onmouseout = this.ps_multiSelectOverOutHandler;
    Event.observe(this.table, "mouseover", this.ps_multiSelectOverOutHandler.bindAsEventListener(this));
    Event.observe(this.table, "mouseout", this.ps_multiSelectOverOutHandler.bindAsEventListener(this));
    
    //table.onclick = this.ps_multiSelectClickHandler; this.ps_multiSelectItems(table);
    Event.observe(this.table, "click", this.ps_multiSelectClickHandler.bindAsEventListener(this));
    this.ps_multiSelectItems();
   }
   else
   	{
   	if (this.listaction < 2)
   	{
   	//table.onmouseover = table.onmouseout = this.ps_multiSelectOverOutHandler;
   	Event.observe(this.table, "mouseover", this.ps_multiSelectOverOutHandler.bindAsEventListener(this));
        Event.observe(this.table, "mouseout", this.ps_multiSelectOverOutHandler.bindAsEventListener(this));
   	
   	//table.onclick = this.ps_clickHandler; this.ps_multiSelectItems(table);
   	Event.observe(this.table, "click", this.ps_clickHandler.bindAsEventListener(this));
    	this.ps_multiSelectItems();
   	
	}
	//else	
    	//	this.table.onmouseover = this.table.onmouseout = ps_overOutHandler;	
    	}
    if (this.options.postList != null)
    	eval(this.options.postList);
    
    
    	
  },
  //OK
  ps_multiSelectOverOutHandler: function (ev) {
	// Standard cross-browser event code
	ev = ev || event;
	var target = ev.target || ev.srcElement;
	if (target.nodeName == "IMG")
	{
		target = target.parentNode;
	}	
	if (target.nodeName == "NOBR")
	{
		target = target.parentNode;
	}
	
	if (target.nodeName == "DIV")
	{
		target = target.parentNode;
	}
	if (target.nodeName != "TD") return;
	if (ev.type == "mouseover")
	{
		if (!this.ps_isSelected(target.parentNode))
		{
			target.parentNode.className = "listCellHighlight";
		};	
	}
	else
	{
		if (!this.ps_isSelected(target.parentNode))
		{
			target.parentNode.className = "listCell";
		};
	};
	
	// stop bubbling, IE event model
	ev.cancelBubble = true; 
	// stop bubbling, W3C event model
	if (ev.stopPropagation) ev.stopPropagation();
},

ps_multiSelectClickHandler: function (ev) {
	//alert('ps_multiSelectClickHandler');
	ev = ev || event;
	var target = ev.target || ev.srcElement;
	if (target.nodeName == "IMG")
	{
		target = target.parentNode;
	}	
	if (target.nodeName == "NOBR")
	{
		target = target.parentNode;
	}
	if (target.nodeName == "DIV")
	{
		target = target.parentNode;
	}
	if (target.nodeName != "TD") return;
	var tableObject = target.parentNode;
	tableObject = tableObject.parentNode;
	tableObject = tableObject.parentNode;
	this.ps_unselectSelection(tableObject, 1);
	this.ps_multiSelectItem(target.parentNode);
	
	// stop bubbling, IE event model
	ev.cancelBubble = true; 
	// stop bubbling, W3C event model
	if (ev.stopPropagation) ev.stopPropagation();
},

ps_clickHandler : function (ev) {
	//alert('ps_clickHandler');
	ev = ev || event;
	var target = ev.target || ev.srcElement;
	if (target.nodeName == "IMG")
	{
		target = target.parentNode;
	}	
	if (target.nodeName == "NOBR")
	{
		target = target.parentNode;
	}
	
	if (target.nodeName == "DIV")
	{
		target = target.parentNode;
	}

	if (target.nodeName != "TD") return;
	//if (event.ctrlKey == true)
	if (ev.ctrlKey == true)
		{
		var tableObject = target.parentNode;
		tableObject = tableObject.parentNode;
		tableObject = tableObject.parentNode;
		this.ps_unselectSelection(tableObject, 1);
		this.ps_multiSelectItem(target.parentNode);
		}
	else
		{
		var tableObject = target.parentNode;
		tableObject = tableObject.parentNode;
		tableObject = tableObject.parentNode;
		this.ps_unselectSelection(tableObject, 0);
		this.ps_clickItem(target.parentNode);
		}
	
	// stop bubbling, IE event model
	ev.cancelBubble = true; 
	// stop bubbling, W3C event model
	if (ev.stopPropagation) ev.stopPropagation();
},

 //OK
 ps_multiSelectItems : function () {
	// itertate through all rows in the tableObject
	var tableObject = this.table;
	var row = tableObject.firstChild;
	// skip TBODY
	while (row.nodeName != "TBODY") 
	{
		row = row.nextSibling;
		if (row == null) break;
	}
	
	row = row.firstChild;
	while (row.nodeName != "TR")
	{	
		row = row.nextSibling;
		if (row == null) break;
	}
	//Skip header row
	row = row.nextSibling;
	if (row == null) return;
	while (row.nodeName != "TR")
	{
		row = row.nextSibling;
		if (row == null) break;
	}
	
	while (row != null)
	{
		var keyTd = row.firstChild;		
		while (keyTd.nodeName=='#text')	keyTd = keyTd.nextSibling;	
		var sel = keyTd.firstChild;
		if (sel.nodeName != 'DIV') return;
		var selPk = sel.attributes.getNamedItem("name").value;
		
		var found = false;
		if (selPk == this.PK.value)
			{
			row.className = "listCellSelection";
			}
		else {
			found = false;
			for (i = 0; i < this.aSelected.length; i++)
				{
				 	if (this.aSelected[i] == selPk)
				 		{
				 		row.className = "listCellSelected";
				 		i = this.aSelected.length
				 		found = true;
				 		}
					
				}
			if (found == false)
				{
				row.className = "listCell";
				}	
			}

		// advance to the next row
		row = row.nextSibling;
		if (row == null) break;
		while (row.nodeName != "TR")
		{
			row = row.nextSibling;
			if (row == null) break;
		}
	}	
},

//OK
ps_isSelected : function (row) {
	if (row.className == "listCellSelection")
		return true;
	if (row.className == "listCellSelected")
		return true;
	return false;
},

//SEMI OK
ps_unselectSelection : function (tableObject, newVal) {
	//alert('ps_unselectSelection '+newVal);
	// itertate through all rows in the tableObject
	var row = tableObject.firstChild;
	// skip TBODY
	while (row.nodeName != "TBODY") 
	{
		row = row.nextSibling;
		if (row == null) break;
	}
	
	//if (row.nodeName == "TBODY") 
	row = row.firstChild;
	while (row.nodeName != "TR")
	{	
		row = row.nextSibling;
		if (row == null) break;
	}
	
	while (row != null)
	{
		if (row.className == "listCellSelection")
			{
				if (newVal == 1)
					{
					row.className = "listCellSelected";
					}
				else	{
					//This should delete it from SELECTION
					var keyTd = row.firstChild;
					while (keyTd.nodeName=='#text')	keyTd = keyTd.nextSibling;	
					var sel = keyTd.firstChild;
					var selPk = sel.attributes.getNamedItem("name").value;

					for (i = 0; i < this.aSelected.length; i++)
						{
				 		if (this.aSelected[i] == selPk)
				 			{
				 			   this.aSelected.splice(i,1)
				 			}
				 		}
					
					this.SELECTION.value = this.aSelected.join('|');
					row.className = "listCell";
					
					}
			}
		else if (row.className == "listCellSelected" && newVal==0)
			{
				var keyTd = row.firstChild;
				while (keyTd.nodeName=='#text')	keyTd = keyTd.nextSibling;	
				var sel = keyTd.firstChild;
				var selPk = sel.attributes.getNamedItem("name").value;

				for (i = 0; i < this.aSelected.length; i++)
					{
			 		if (this.aSelected[i] == selPk)
			 			{
			 			   this.aSelected.splice(i,1)
			 			}
			 		}
				
				this.SELECTION.value = this.aSelected.join('|');
				row.className = "listCell";
				
			}
		
		
		// advance to the next row
		row = row.nextSibling;
		if (row == null) break;
		while (row.nodeName != "TR")
		{
			row = row.nextSibling;
			if (row == null) break;
		}
	}	
},

 ps_multiSelectItem : function(row) {		
	//alert('ps_multiSelectItem');
	var keyTd = row.firstChild;
	while (keyTd.nodeName=='#text')	keyTd = keyTd.nextSibling;	
	var sel = keyTd.firstChild;
	var selPk = sel.attributes.getNamedItem("name").value;
	
	if (this.ps_isSelected(row))
	{
		// change the class to highlight because the mouse is over this item
		row.className = "listCellHighlight";
		//alert('remove this '+selPk);
		//alert(this.aSelected.join('|'));	
		for (i = 0; i < this.aSelected.length; i++)
			{
	 		if (this.aSelected[i] == selPk)
	 			{
	 			//alert('del i '+i);
	 			this.aSelected.splice(i,1)
	 			}
	 		}
	 		
	 			
		
		
		this.SELECTION.value = this.aSelected.join('|');		
		this.PK.value = '';
		
		userMUnSelect(row);	
		
	}
	else
	{
		// select the item
		
		if ((this.SELECTION.value.length + selPk.length + 1) < 255)
			{
			window.status = '';
			row.className = "listCellSelection";
			this.PK.value = selPk;
			//alert('Add this '+selPk);
			this.aSelected.push(selPk);
			this.SELECTION.value = this.aSelected.join('|');
			userMSelect(row);	
			}
		else	
			window.status = 'You have selected too many rows';
	}
	//alert(getPkFromRow(row));
	
	return true;
},

ps_clickItem: function (row) {
	var keyTd = row.firstChild;
	while (keyTd.nodeName=='#text')	keyTd = keyTd.nextSibling;	
	if (keyTd.className == "listHeader") return false;
	var sel = keyTd.firstChild;
	var selPk = sel.attributes.getNamedItem("name").value;
	

	this.ps_unselectSelection(this.table, 0);
	if (row.className != "listCellSelected")
		{
		if ((this.SELECTION.value.length + selPk.length + 1) < 255)
			{
			//Select the row
			window.status = '';
			row.className = "listCellSelection";
			this.PK.value = selPk;
			this.aSelected.push(selPk);
			this.SELECTION.value = this.aSelected.join('|');
			this.PB.click();
			}
		else	
			window.status = 'You have selected too many rows';
		
		}	

	return true;
}
  
  
  
}
);

//
var SORT_COLUMN_INDEX;

function sortables_init() {
    // Find all tables with class sortable and make them sortable
    if (!document.getElementsByTagName) return;
    tbls = document.getElementsByTagName("table");
    for (ti=0;ti<tbls.length;ti++) {
        thisTbl = tbls[ti];
        if (((' '+thisTbl.className+' ').indexOf("sortable") != -1) && (thisTbl.id)) {
            //initTable(thisTbl.id);
            ts_makeSortable(thisTbl);
        }
    }
}

function ts_makeSortable(table) {
    if (table.rows && table.rows.length > 0) {
        var firstRow = table.rows[0];
    }
    if (!firstRow) return;
    
    // We have a first row: assume it's the header, and make its contents clickable links
    for (var i=0;i<firstRow.cells.length;i++) {
        var cell = firstRow.cells[i];
        var txt = ts_getInnerText(cell);
        cell.innerHTML = '<a href="#" class="sortheader" onclick="ts_resortTable(this);return false;">'+txt+'<span class="sortarrow">&nbsp;&nbsp;</span></a>';
    }
}

function ts_getInnerText(el) {

	if (typeof el == "string") return el;
	if (typeof el == "undefined") { return el };
	if (el.innerText) {return el.innerText;}	//Not needed but it is faster
	var str = "";
	
	var cs = el.childNodes;
	//alert(el.tagName);
	var l = cs.length;
	for (var i = 0; i < l; i++) {
		//alert(cs[i].tagName);
		if (cs[i].tagName == 'INPUT')
			return cs[i].value
		switch (cs[i].nodeType) {
			case 1: //ELEMENT_NODE
				str += ts_getInnerText(cs[i]);
				break;
			case 3:	//TEXT_NODE
				str += cs[i].nodeValue;
				break;
		}
	}

	return str;
}

function ts_resortTable(lnk) {
    // get the span
    //OK debugger;	
    var span;
    for (var ci=0;ci<lnk.childNodes.length;ci++) {
        if (lnk.childNodes[ci].tagName && lnk.childNodes[ci].tagName.toLowerCase() == 'span') span = lnk.childNodes[ci];
    }
    var spantext = ts_getInnerText(span);
    var td = lnk.parentNode;
    var column = td.cellIndex;
    var table = getParent(td,'TABLE');
    //>>OK
    //var column = table.parentElement.cellIndex;
    //table = getParent(table.parentElement,'TABLE');
    //<<OK
     
    // Work out a type for the column
    if (table.rows.length <= 1) return;
    for (var ci=1;ci<table.rows.length;ci++) {
    	var itm = ts_getInnerText(table.rows[ci].cells[column]);
    	if (itm != '')
    		break;
    }

    if (itm == '') return;
    //var itm = ts_getInnerText(table.rows[1].cells[column]);
    
    sortfn = ts_sort_caseinsensitive;
    //if (itm.match(/^\d\d[\/-]\d\d[\/-]\d\d\d\d$/)) sortfn = ts_sort_date;
    //if (itm.match(/^\d\d[\/-]\d\d[\/-]\d\d$/)) sortfn = ts_sort_date;
    if (itm.match(/^\d{2}[\/-]\d{2}[\/-]\d{4}/)) sortfn = ts_sort_pobdate;
    if (itm.match(/^\d{1}[\/-]\d{1}[\/-]\d{4}/)) sortfn = ts_sort_pobdate;
    if (itm.match(/^\d{2}[\/-]\d{1}[\/-]\d{4}/)) sortfn = ts_sort_pobdate;
    if (itm.match(/^\d{1}[\/-]\d{2}[\/-]\d{4}/)) sortfn = ts_sort_pobdate;
    if (itm.match(/^\d{4}[\/-]\d{2}[\/-]\d{2}/)) sortfn = ts_sort_pobdate;

    
    
    
    
    if (itm.match(/^[£$]/)) sortfn = ts_sort_currency;
    if (itm.match(/^[\d\.]+$/)) sortfn = ts_sort_numeric;
    SORT_COLUMN_INDEX = column;
    var firstRow = new Array();
    var newRows = new Array();
    for (i=0;i<table.rows[0].length;i++) { firstRow[i] = table.rows[0][i]; }
    for (j=1;j<table.rows.length;j++) { newRows[j-1] = table.rows[j]; }

    newRows.sort(sortfn);

    if (span.getAttribute("sortdir") == 'down') {
        ARROW = '&nbsp;&uarr;';
        newRows.reverse();
        span.setAttribute('sortdir','up');
    } else {
        ARROW = '&nbsp;&darr;';
        span.setAttribute('sortdir','down');
    }
    
    // We appendChild rows that already exist to the tbody, so it moves them rather than creating new ones
    // don't do sortbottom rows
    for (i=0;i<newRows.length;i++) { if (!newRows[i].className || (newRows[i].className && (newRows[i].className.indexOf('sortbottom') == -1))) table.tBodies[0].appendChild(newRows[i]);}
    // do sortbottom rows only
    for (i=0;i<newRows.length;i++) { if (newRows[i].className && (newRows[i].className.indexOf('sortbottom') != -1)) table.tBodies[0].appendChild(newRows[i]);}
    
    // Delete any other arrows there may be showing
    var allspans = document.getElementsByTagName("span");
    for (var ci=0;ci<allspans.length;ci++) {
        if (allspans[ci].className == 'sortarrow') {
            if (getParent(allspans[ci],"table") == getParent(lnk,"table")) { // in the same table as us?
                allspans[ci].innerHTML = '&nbsp;&nbsp;';
            }
        }
    }
        
    span.innerHTML = ARROW;
}

function getParent(el, pTagName) {
	if (el == null) return null;
	else if (el.nodeType == 1 && el.tagName.toLowerCase() == pTagName.toLowerCase())	// Gecko bug, supposed to be uppercase
		return el;
	else
		return getParent(el.parentNode, pTagName);
}

function ts_sort_pobdate(a,b) {
    // y2k notes: two digit years less than 50 are treated as 20XX, greater than 50 are treated as 19XX
    aa = ts_getInnerText(a.cells[SORT_COLUMN_INDEX]);
    bb = ts_getInnerText(b.cells[SORT_COLUMN_INDEX]);
 
	dt1 = str2DateTime(aa)
    	dt2 = str2DateTime(bb)

    //alert(dt1 + ' ' + dt2)
    
    if (dt1==dt2) return 0;
    if (dt1<dt2) return -1;
    return 1;
}

function ts_sort_date(a,b) {
    // y2k notes: two digit years less than 50 are treated as 20XX, greater than 50 are treated as 19XX
    aa = ts_getInnerText(a.cells[SORT_COLUMN_INDEX]);
    bb = ts_getInnerText(b.cells[SORT_COLUMN_INDEX]);
   
    if (aa.length == 10) {
        dt1 = aa.substr(6,4)+aa.substr(3,2)+aa.substr(0,2);
    } else {
        yr = aa.substr(6,2);
        if (parseInt(yr) < 50) { yr = '20'+yr; } else { yr = '19'+yr; }
        dt1 = yr+aa.substr(3,2)+aa.substr(0,2);
    }
    if (bb.length == 10) {
        dt2 = bb.substr(6,4)+bb.substr(3,2)+bb.substr(0,2);
    } else {
        yr = bb.substr(6,2);
        if (parseInt(yr) < 50) { yr = '20'+yr; } else { yr = '19'+yr; }
        dt2 = yr+bb.substr(3,2)+bb.substr(0,2);
    }
    //alert(dt1 + ' ' + dt2)
    if (dt1==dt2) return 0;
    if (dt1<dt2) return -1;
    return 1;
}

function ts_sort_currency(a,b) { 
    aa = ts_getInnerText(a.cells[SORT_COLUMN_INDEX]).replace(/[^0-9.]/g,'');
    bb = ts_getInnerText(b.cells[SORT_COLUMN_INDEX]).replace(/[^0-9.]/g,'');
    return parseFloat(aa) - parseFloat(bb);
}

function ts_sort_numeric(a,b) { 
    aa = parseFloat(ts_getInnerText(a.cells[SORT_COLUMN_INDEX]));
    if (isNaN(aa)) aa = 0;
    bb = parseFloat(ts_getInnerText(b.cells[SORT_COLUMN_INDEX])); 
    if (isNaN(bb)) bb = 0;
    return aa-bb;
}

function ts_sort_caseinsensitive(a,b) {

    aa = new String(ts_getInnerText(a.cells[SORT_COLUMN_INDEX]).toLowerCase());
    bb = ts_getInnerText(b.cells[SORT_COLUMN_INDEX]).toLowerCase();
    return aa.localeCompare(bb);
}

function ts_sort_default(a,b) {
		//alert('def');
    aa = ts_getInnerText(a.cells[SORT_COLUMN_INDEX]);
    bb = ts_getInnerText(b.cells[SORT_COLUMN_INDEX]);
    if (aa==bb) return 0;
    if (aa<bb) return -1;
    return 1;
}


function addEvent(elm, evType, fn, useCapture)
// addEvent and removeEvent
// cross-browser event handling for IE5+,  NS6 and Mozilla
// By Scott Andrew
{
  if (elm.addEventListener){
    elm.addEventListener(evType, fn, useCapture);
    return true;
  } else if (elm.attachEvent){
    var r = elm.attachEvent("on"+evType, fn);
    return r;
  } else {
    alert("Handler could not be removed");
  }
} 

function str2DateTime(str_date_time)
{
if (str_date_time.indexOf(' ') > 0)
	str_date = str_date_time.substr(0, str_date_time.indexOf(' '));
else
	str_date = str_date_time;

var arr_date = str_date.split(serverDateSeparator);
//alert(arr_date.length);
if (arr_date.length == 3) 	
	{
	if (serverDateFormat == 4)
		{
			
		yyyy = arr_date[2]
		mm = arr_date[1]
		dd = arr_date[0]
		}
	else if (serverDateFormat == 5)
		{
		yyyy = arr_date[2]
		mm = arr_date[0]
		dd = arr_date[1]
		}
	else if (serverDateFormat == 6)
		{
		yyyy = arr_date[0]
		mm = arr_date[1]
		dd = arr_date[2]
		}
	
	var timeStart = str_date_time.indexOf(' ')
	if (timeStart> 0 )
		time = str_date_time.substr(timeStart, 20);
	else
		time = '';
		
	if (time.length > 0)
		{
		var arr_time = time.split(serverTimeSeparator);
		if (arr_date.length > 1) 	
			{
			//HH/MM
			if (serverTimeFormat==1)
				{
				hh = arr_time[0]
				mi = arr_time[1]
				ss = 0
				}
			//H/M/SS A
			else if (serverTimeFormat==4)
				{
				hh = arr_time[0]
				mi = arr_time[1]
				ss = arr_time[2]
				if (ss.indexOf('AM')>0)
					{
					 ss = ss.replace('AM', '')	
					}
				else
					{
					 ss = ss.replace('PM', '')	
					 hh = parseInt(hh) + 12
					}
				}
			else if (serverTimeFormat==2)
				{
				hh = arr_time[0]
				mi = arr_time[1]
				ss = 0
				if (mi.indexOf('AM')>0)
					{
					 mi = mi.replace('AM', '')	
					}
				else
					{
					 mi = mi.replace('PM', '')	
					 hh = parseInt(hh) + 12
					}
				}
			else if (serverTimeFormat==3)
				{
				hh = arr_time[0]
				mi = arr_time[1]
				ss = arr_time[2]
				}
			
			}
		}
	else	{
		hh = 0
		mi = 0
		ss = 0
		}
		
		
		
	if (mm.indexOf('0')==0) {mm = mm.substr(1, 1); }		
	}
else
	{
	yyyy = 0;
	mm = '1';
	dd = 1;
	hh = 0;
	mi = 0;
	ss = 0;
	}
	//alert(yyyy)

	var dateVar1 = new Date(yyyy, parseInt(mm)-1, dd, hh, mi, ss)

return (dateVar1)
	
}

//this.viewname
function ajax_export_list(pView)
{
alert(pView)	
pwh = window.open('about:blank');
alert(pwh);
debugger;
pwh.document.body.innerHTML = 'ABS';
}