/**
 * @description Functions controlling cursor position, style
 * @author Rebecca Younes
 */

ILR.namespace("cursor");

ILR.cursor = {

	/** 
	 * @description Set cursor style of an element. Usually called by an event handler.
	 * @param {String|HTMLElement} el
	 * @param {String} style
	 */
	setCursorStyle : function(el, style) {
	
		if (typeof el == 'string') {
			el =  document.getElementById(el);
		}
		
		switch (style) {
			case "pointer" :
				el.style.cursor = "pointer";
				el.style.cursor = "hand";
				break;
			default :
				break;
		}
	},
	
		
	/**
	 * @description Move cursor to end of text in a textarea or text input form field
	 */
	setCursorToEnd : function() {

		var range, length;
		
		if (this.createTextRange) {
			range = this.createTextRange();
			range.collapse(false);
			range.select();
		}
		else if (this.setSelectionRange) {
			this.focus();
			length = this.value.length;
			this.setSelectionRange(length, length);
		}
	},

	/**
	 * @description Move cursor to beginning of text in a textarea or text input form field
	 */
	setCursorToStart : function() {
		
		var range;
		
		if (this.createTextRange) {
	   		range = this.createTextRange();
	    	range.collapse(true);
	    	range.select();
	  	}
	  	else if (this.setSelectionRange) {
	    	this.focus();
	    	this.setSelectionRange(0, 0);
	  	}
	},

	/**
	 * @description Move cursor to end of text in a textarea or text input form field
	 */
	setCursorToEnd1 : function(el) {
		
		var v, r;
		
		if (el.createTextRange) {
    		v = el.value;
    		r = el.createTextRange();
    		r.moveStart('character', v.length);
    		r.select();
  		}
	}

};
