				
												
	/*
	
	Creates a sortable number field
	
	Needs:
	
	hidden input field with an id of "yoursortablefield_text"
	
	Add "js_sortable_integer" to the input fields class attribute
	
	You dont need to have a valid integer, but it is best to add js_validate_integer to your class
	
	*/		



	function fnIntegerSort() {
	
		if(this.value){
			// Get the integer value
			var v = this.value;
			
			// Strip blanks
			v.split(" ").join("");
			
			// Get the length of value
			var integer_length = v.length;
			
			//Safe value just in case length is larger then 4
			var integer_zeroes = v;
			
			// Add number of leading zeros based on length of value
			if(integer_length == 1) {
				integer_zeroes = '0000' + v;
			}
			if(integer_length == 2) {
				integer_zeroes = '000' + v;
			}
			if(integer_length == 3) {
				integer_zeroes = '00' + v;
			}
			if(integer_length == 4) {
				integer_zeroes = '0' + v;
			}
			
		
			//put the modified integer into the hidden field
			document.getElementById((this.id).split("_text")[0]).value = integer_zeroes;
			
			return true;
			
		}
		
		return false;

	
	}
	
	
	
	function fnAddIntegerListeners()
	{
		//Add the listener to input fields
		e = YAHOO.util.Dom.getElementsByClassName("js_sortable_integer", "input");

		for(var i=0; i<e.length; i++)
		{													
			YAHOO.util.Event.addListener(e[i], 'blur', fnIntegerSort); 												 
		}
	}
	
	
	
	/*
	
	Selects the correct icon image for an attachment
	
	Requires:
	
	hidden input field with an id of "yourattachmentfield_icon"	

	Your attachment field to have a class of "js_attach_icon"
	
	NOTE: If you're going to add this to repeatable fieldsets, you'll need to manually add a event handler for the template fieldset
	
	
	If you want to change where the icon images are sourced from, change the ICONDIR variable.  This is usually set to /ixa/images/icons/
	
	*/		
	

	function fnAttachmentIcon()
	{ 
		var ICONDIR = "/ixa/images/icons/";
	
	
		var thefile;
		var splitstr;
		var xten;
		
		thefile = this.value;

		delete_field = document.getElementById(this.id + "_delete");
		
		icon_field = document.getElementById(this.id + "_icon");
		
		
		if(delete_field != null)
		{
			if(delete_field.checked && thefile == "")
			{			
				//We're deleting the attachment, lets get out of here!
		 		icon_field.value =  "";		 	
		 		return true;
	 		}
		}		

		
		if(thefile == "") // No (new) document, return true
		{
			return true;
		}
		else // New document, reset icon
		{

			splitstr = thefile.split(".");
			xten = splitstr[splitstr.length - 1];
			xten = xten.toLowerCase();
			if(xten=="htm")  
			{ 
				xten = "html";
			} 
			if(xten=="jpeg")  
			{ 
				xten = "jpg"; 
			} 
			if(xten=="rtf")  
			{ 
				xten = "doc"; 
			} 
			if ((xten=="doc") || 
					(xten=="html") || 
					(xten=="pdf") || 
					(xten=="jpg") || 
					(xten=="gif") ||  
					(xten=="ppt") || 
					(xten=="pub") ||  
					(xten=="xls") || 
					(xten=="zip"))  
			{  
				icon_field.value = ICONDIR + xten + '.gif';
				return true; 
			} 	

			icon_field.value = ICONDIR + "unknown.gif";
		}
		
		return false;
		
	}
	

	function fnAddAttachmentIconListeners()
	{

		//Add the listener to input fields
		e = YAHOO.util.Dom.getElementsByClassName("js_attach_icon", "input");

		for(var i=0; i<e.length; i++)
		{		
				
				YAHOO.util.Event.addListener(e[i], 'blur', fnAttachmentIcon);

		}
	}	


	YAHOO.util.Event.onDOMReady(fnAddIntegerListeners);
	YAHOO.util.Event.onDOMReady(fnAddAttachmentIconListeners);

	
	
	