var gSafeOnload = new Array();
function SafeAddOnload(f)
{
	if  (window.onload)
	{
		if (window.onload != SafeOnload)
		{
			gSafeOnload[0] = window.onload;
			window.onload = SafeOnload;
		}		
		gSafeOnload[gSafeOnload.length] = f;
	}
	else
		window.onload = f;
}
function SafeOnload()
{
	for (var i=0;i<gSafeOnload.length;i++)
		gSafeOnload[i]();
}



// Check or uncheck all checkboxes on the page
function checkUncheckAll(theElement,checkit)
{
	if (typeof(checkit) == 'undefined')
	{
		var checkit = theElement.checked;
		var theForm = theElement.form, z = 0;
	}
	else
	{
		var theForm = theElement, z = 0;
	}

	if (checkit == 'checked')
	{
		checkit = true;
	}
	while (theForm[z])
	{
		if(theForm[z].type == 'checkbox')
		{
			theForm[z].checked = checkit;
		}
		z++;
	}
}

// Function highlights the selected row when appropriate checkbox is checked
function chkoxHlRow(rowid,defaultclass)
{
	var row = document.getElementById('row_'+rowid);
	
	if (document.getElementById('checkbox_'+rowid).checked == true)
	{
		row.className = 'highlightall' + (defaultclass != '' ? '-'+defaultclass:'');
	}
	else
	{
		row.className = defaultclass;
	}
}


// Highlights all rows in a table
function hlAllRows(table)
{
	table 	= document.getElementById(table);
	for (var c = 0; c < table.rows.length; c++)
	{
		rowid 		= table.rows[c].id;
		rowid = rowid.replace(/row_/g,'');
		defaultclass 	= table.rows[c].className;
		defaultclass	= defaultclass.replace(/highlightall(-)?/g,'');
		
		if (rowid != '')
		{
			chkoxHlRow(rowid,defaultclass);
		}
	}	
}


function highlight(action,id)
{
	// Function to highlight selected row & column in an "L" format
	var ids = new Array();
	ids = id.split('-');
	
	
	if (action == 's')
		changeClass = 'color1';
	else
	{
		changeClass = '';
		// Remove style from the active cell
		document.getElementById(id).className = '';
	}	
	// Highlight column
	for (i = ids[1]; i > 0; i--)
	{
		this_id = ids[0] + '-' + i + '-' + ids[2];
		document.getElementById(this_id).className=changeClass;
	}
	// Highlight row
	for (i = ids[2]; i > 0; i--)
	{
		this_id = ids[0] + '-' + ids[1] + '-' + i;
		document.getElementById(this_id).className=changeClass;
	}
	if (action == 's')
	{
		// Apply style to the active cell
		document.getElementById(id).className = 'active-cell';
	}
}

function isset(variable)
{
    var undefined;
    return ( variable == undefined ? false : true );
}

function page_param(URL, page_count)
{
	page = parseInt(prompt('Goto Page:',''));
	if (isNaN(page)||page>page_count||page<=0) 
		return false;
	document.location=URL+'page_no='+page;
}

function openWindow(filename,wide,high,popname,scrollbars)
{
        if(typeof(scrollbars)=="undefined")
        {
                scrollbars = 0;
        }
        else
        {
                scrollbars = 1;
        }
        popupWin = window.open(filename, popname, 'scrollbars='+scrollbars+',status=1,resizable=yes,width='+wide+',height='+high+'')
}




