// Only allows digits to be entered in a text field
function checkIt(evt)
{
	var chCode = (evt.which)?evt.which:evt.keyCode;
	if (typeof document.getElementById!="undefined" && typeof document.all=="undefined")
	{
	
	
		//	if ((34<evt.charCode && evt.charCode<41) || evt.charCode==46) return false;     // charCode 46 is for . (dot)
		if ( chCode == 46 ) return true;
		if ( 34<evt.charCode && evt.charCode<41 ) return false;
		if ((34<chCode && chCode<41) || chCode==46) return true;
	}
	if ( chCode == 46 ) return true;
	if((chCode<48 || 57<chCode) && chCode>31) return false;
	return true;
}

function checkLength( element, maxLength )
{
	return ( element.value.length < maxLength ) ? ( true ) : ( false );
}


// Some stupid scripts to check if checkboxes are checked b4 the form is submitted and also
// for checking/unchecking all the checkboxes in the page
allChecked = false;
function checkUncheckAll()
{
	for (i=0; i<document.getElementsByTagName("input").length; i++)
		if ( document.getElementsByTagName("input")[i].type == "checkbox" )
			document.getElementsByTagName("input")[i].checked = ( allChecked == false ) ? ( true ) : ( false );

	allChecked = ( allChecked == true ) ? ( false ) : ( true );
}

function checkChecked()
{
	var anyThingIsChecked = false;
	for (i=0; i<document.getElementsByTagName("input").length; i++)
		if ( document.getElementsByTagName("input")[i].type == "checkbox" )
			if ( document.getElementsByTagName("input")[i].checked )
			{
				anyThingIsChecked = true;
				break;
			}
	
	return anyThingIsChecked;
	
}


// Haha!
function toggleCheckBox( id )
{
	if ( document.getElementById(id).checked )
		document.getElementById(id).checked = false;
	else
		document.getElementById(id).checked = true;
}


//////////////////////////////////////// The Scroll /////////////////////////////////////////////////////////////
function moveUp( id, speed, leftover )
{
	var top = parseInt(document.getElementById(id).style.top);
	var height = parseInt(document.getElementById(id).offsetHeight);
	if ( top - leftover > -1 * height )
	{
		document.getElementById(id).style.top = top - speed;
		window[id + "Timeout"] = setTimeout( "moveUp( '" + id + "', " + speed + ", " + leftover + ")", 10 );
	}
}

function moveDown( id, speed, leftover )
{
	var top = parseInt(document.getElementById(id).style.top);
	if ( top < 0 )
	{
		document.getElementById(id).style.top = top + Math.min( 0 - top, speed );
		window[id + "Timeout"] = setTimeout( "moveDown( '" + id + "', " + speed + ", " + leftover + ")", 10 );
	}
}
		

function ceaseScroll( id )
{
	clearTimeout( window[id + "Timeout"] );
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////


///////////////////////////////////////// Some cool string functions!! ////////////////////////////////////////
String.prototype.reverse = function() 
						   { 
						   	   var temp = "";
						   	   for(var i=this.length-1; i>=0; i--)
							   	   temp += this.charAt(i);
							   return temp;
						   }

String.prototype.commaDelimited = function( chunkLength )
								  {
								  	  // Striping all unwanted commas and spaces, in case
									  // the string was comma delimited before!
								  	  var ourValue = "";
									  var re = /,*\s*/g;
									  ourValue = this.replace(re, "");
									  
								  	  if ( typeof(chunkLength) == "undefined" || typeof(chunkLength) == "string" )
									  	  chunkLength = 3;
									  else
									      chunkLength = Math.max(1, parseInt(chunkLength) );
									  
								  	  var newVal = "", reversed;
									  reversed = ourValue.reverse();

									  for (var counter = 0; counter < reversed.length; counter++)
									  {
									  	  if ( counter % chunkLength == 0 && counter != 0 )
										  	  newVal += ",";
										  newVal += reversed.charAt(counter);
									  }
									  
									  return newVal.reverse();
								 }
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
