//=========================
//	Trim the leading and trailing spaces of the OBJECT of the String constructor
//=========================
String.prototype.trim = function()
	{	
	// Use a regular expression to replace leading and trailing
	// spaces with the empty string
	return this.replace(/(^\s*)|(\s*$)/g, "");
	}

function openwindow(url)
{
// open url in a new window without location bar, etc

 window.open(url,'','location=no,menubar=no,status=no,toolbar=no,resizable=yes,scrollbars=yes');
}

// Postback the form to retrieve the sorted data when a specific header column is clicked
function submitform(sortType, textboxSortOrderClientID, textboxSortByClientID, textboxListPageClientID, formClientID)
{
				var	oForm = document.getElementById(textboxSortOrderClientID);		
				var oSortItem = document.getElementById(textboxSortByClientID);	

				if (sortType!=null)
								{
												if (oSortItem.value==sortType || oSortItem.value=="")
												{
																if (oForm.value == "desc")
																				oForm.value = "asc";
																else
																				oForm.value = "desc";
												}			
												else
																oForm.value = "asc";				
								oSortItem.value = sortType;		
								}
				else if(oSortItem.value=="")
								{
												if (oForm.value == "desc")
																oForm.value = "asc";
												else
																oForm.value = "desc";
								}			
				else
												oForm.value = "asc";		
			
				var oListPage = document.getElementById(textboxListPageClientID);	
				oListPage.value = "true";	
				oForm = document.getElementById(formClientID);		
				oForm.submit();
}

//	Postback form to retrieve the data for a specific page
function getpagedata(pagenum, previouspagenum, textboxPageNumberClientID, textboxPreviousPageNumberClientID, formClientID)
{
				var oform = document.getElementById(textboxPageNumberClientID);				
				oform.value = pagenum;
				oform = document.getElementById(formClientID);		
				if (previouspagenum!=null)
								{
								var oprevpage = document.getElementById(textboxPreviousPageNumberClientID);
								oprevpage.value = previouspagenum;
								}
				oform.submit();		
}

// Place the image indicator on the column that is used for sorting
function order(columnNameList, textboxSortOrderClientID, textboxSortByClientID, sortImage)
{
//alert(sortImage);
//alert("List: " + columnNameList);
				var columnNameArray = columnNameList.split(",")
				var sortorder = document.getElementById(textboxSortOrderClientID);	
//alert(sortorder.value);
				if (sortorder!=null)
				{			
//alert("textboxsortbyclientid: " + textboxSortByClientID);
								var osortby = document.getElementById(textboxSortByClientID).value;		
//alert("sort by: " + osortby);
								for (var z=0; z<columnNameArray.length; z++)
								{											
												if (osortby.toLowerCase()==columnNameArray[z].trim().toLowerCase())
												{		var i=z; break;	}
								}

								oimage = document.getElementsByName(sortImage);				
								for (var j=0; j<oimage.length; j++)
								{				
												oimage[j].src = "common/ui/images/sort.gif";
												if (i==j)
												{				
//alert("i==j; i: " + i + ", j: " + j);
																oimage[j].style.display = "";
																if (sortorder.value == "desc")						
																				oimage[j].style.filter = "FlipV";
												}
												else
												{
//alert("i!=j; i: " + i + ", j: " + j);
																oimage[j].src = "common/ui/images/sort.gif";
																oimage[j].style.display = "none";
												}
								}			
				}
				return;
}
