String.prototype.trim = function() {
	
	// skip leading and trailing whitespace
	// and return everything in between
	  var x=this;
	  x=x.replace(/^\s*(.*)/, "$1");
	  x=x.replace(/(.*?)\s*$/, "$1");
	  return x;
}	
function checkrequired(which) {
		var pass=true;
		if (document.images) {
		for (i=0;i<which.length;i++) {
		var tempobj=which.elements[i];
		if (tempobj.name.substring(0,8)=="required") {
		if (((tempobj.type=="text"||tempobj.type=="textarea"||tempobj.type=="file")&&
		space_out(tempobj.value.trim())=='')||(tempobj.type.toString().charAt(0)=="s"&&
		tempobj.selectedIndex==0)) {
		//alert(tempobj.value);
		pass=false;
		break;
				 }
			  }
		   }
		}
		if (!pass) {
		shortFieldName=tempobj.name.substring(8,30);
		alert("Please enter "+shortFieldName+" field value.");
		tempobj.value='';
		return false;
		}
		else
		//alert(tempobj.value);
		which.datebox.disabled=false;
		return true;
}
function space_out(val)
{
	var output = "";
	for (var i = 0; i < val.length;) 
	{
		
		if(val.charAt(i) == '&' && val.charAt(i+1) == 'n' && val.charAt(i+2) == 'b' && val.charAt(i+3) == 's' && val.charAt(i+4) == 'p' && val.charAt(i+5) == ';') 
		{
			i=i+6;			
		} 
		else 
		{
			output += val.charAt(i);		
			i++;
   		}
	}	
	output1="";	
	for (var i = 0; i < output.length;) 
	{	
		if(output.charAt(i) == '<' && output.charAt(i+1) == 'P' && output.charAt(i+2) == '>') 
		{
			i=i+3;		
		} 
		else 
		{		
			output1 += output.charAt(i);	
			i++;
   		}
	}	
	output2="";
	for (var i = 0; i < output1.length;) 
	{
		
		if(output1.charAt(i) == '<' && output1.charAt(i+1) == '/' && output1.charAt(i+2) == 'P' && output1.charAt(i+3) == '>') 
		{
			i=i+4;			
		} 
		else 
		{		
			output2 += output1.charAt(i);		
			i++;
   		}
	}
	//===============================	
	output3="";
	for (var i = 0; i < output2.length; i++) 
	{
		if ((output2.charCodeAt(i) == 13) && (output2.charCodeAt(i + 1) == 10)) 
		{
			i++;			
		}
		else
		{		
			output3 += output2.charAt(i);
  		}
	}

	//=================================	
	output4="";
	for (var i = 0; i < output3.length;) 
	{
		if ((output3.charCodeAt(i) == 32) || (output3.charCodeAt(i) == 160)) 
		{
			i++;		
		}
		else
		{			
			output4 += output3.charAt(i);
			i++;
  		}		
	}	
	
	return output4;

}
function TestFileType( fileName, fileTypes ) {
	if (!fileName) return;

	dots = fileName.split(".")
	//get the part AFTER the LAST period.
	fileType = "." + dots[dots.length-1];	
	if(fileTypes.join(".").indexOf(fileType)!= -1)
	{		
		return true;
	}
	else
	{
		alert("Please only upload files that end in types: \n\n" + (fileTypes.join(" .")) + "\n\nPlease select a new file and try again.");
		return false;
	}
}
//  End -->
