// Default scripts - to be displayed on every page

// get the max number from any number of arguments
function getMax() {

	var args = getMax.arguments;
	var maxNumber = 0;
	
	for (i=0; i<args.length; i++) {
		if (args[i] > maxNumber) {
			maxNumber = args[i];
		}
	}

	return maxNumber;

}

function newSizedNamedWindow(url, windowName, width, height) {

		newWindow = window.open(url, windowName, 'menubar=no,status=no,scrollbars=auto,resizeable=no,width=' + width + ',height=' + height + ',toolbar=no,location=no,directories=no,top=0,left=0,screenX=0,screenY=0'); 
	    newWindow.focus();
			
}

function newSizedScrollingWindow(url, windowName, width, height) {

		newWindow = window.open(url, windowName, 'menubar=no,status=no,scrollbars=yes,resizeable=no,width=' + width + ',height=' + height + ',toolbar=no,location=no,directories=no,top=0,left=0,screenX=0,screenY=0'); 
			newWindow.focus();
			
}

function newSizedResizeableWindow(url, windowName, width, height) {

		newWindow = window.open(url, windowName, 'menubar=no,status=no,scrollbars=auto,resizable=yes,width=' + width + ',height=' + height + ',toolbar=no,location=no,directories=no,top=0,left=0,screenX=0,screenY=0'); 
	    newWindow.focus();
			
}

function imageSwap(theImage, newSRC) {
	theImage.src = newSRC;
}


function simplePreload() { 

  var args = simplePreload.arguments;

  document.imageArray = new Array(args.length);

  for(var i=0; i<args.length; i++) {

    document.imageArray[i] = new Image;
    document.imageArray[i].src = args[i];

  }

}

function cancelEdit()
{
	if (confirm('Are you sure you want to cancel? You will lose all of your changes.'))
	{
		window.opener.focus();
		window.close();
	}
}

function confirmDelete(objectName, objectID, deleteUrl, queryString)
{
	if (confirm('Are you sure you want to delete this ' + objectName + '? Once you do, you will not be able to undo the delete.'))
	{
		newLocation = deleteUrl + '?deleteID=' + objectID;
		
		if (queryString != '')
			newLocation = newLocation + '&' + queryString;
			
		window.location.href = newLocation;
	}
}

function wordCount(theTextArea, displaySpan)
{
	var y = theTextArea.value;
	var r = 0;
	
	a=y.replace(/\s/g,' ');
	a=a.split(' ');
	
	for (z=0; z<a.length; z++) 
	{
		if (a[z].length > 0) 
			r++;
	}
	
	displaySpan.innerHTML = r;
}

function charCount(theTextArea, displaySpan)
{

	var y = theTextArea.value;
	var r = y.length;

	displaySpan.innerHTML = r;
}

function trim(stringToTrim) {
	return stringToTrim.replace(/^\s+|\s+$/g,"");
}
function ltrim(stringToTrim) {
	return stringToTrim.replace(/^\s+/,"");
}
function rtrim(stringToTrim) {
	return stringToTrim.replace(/\s+$/,"");
}
