/*******************************************************************************
 *Copyright 2009, 2010 Innovation Gate GmbH. All Rights Reserved.
 *
 *This file is part of the OpenWGA server platform.
 *
 *OpenWGA is free software: you can redistribute it and/or modify
 *it under the terms of the GNU General Public License as published by
 *the Free Software Foundation, either version 3 of the License, or
 *(at your option) any later version.
 *
 *In addition, a special exception is granted by the copyright holders
 *of OpenWGA called "OpenWGA plugin exception". You should have received
 *a copy of this exception along with OpenWGA in file COPYING.
 *If not, see <http://www.openwga.com/gpl-plugin-exception>.
 *
 *OpenWGA is distributed in the hope that it will be useful,
 *but WITHOUT ANY WARRANTY; without even the implied warranty of
 *MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *GNU General Public License for more details.
 *
 *You should have received a copy of the GNU General Public License
 *along with OpenWGA in file COPYING.
 *If not, see <http://www.gnu.org/licenses/>.
 ******************************************************************************/
F={}
F.util={}

F.util.editDivText=function (el, value, callback){
	var dh = Ext.DomHelper;
	var span = dh.insertBefore(el, {tag:"span"})
	var input_el = dh.append(span, {tag:"input"})
	Ext.fly(el).setDisplayed(false);
	input_el.value=value;
	input_el.select();
	Ext.fly(input_el).on("blur", function(){
		Ext.fly(span).remove();
		if(input_el.value!=value)
			callback(input_el.value)
		Ext.fly(el).show();
	})
	
	Ext.fly(input_el).on("keydown", function(ev){
		switch(ev.getKey()){
		case 27:
			Ext.fly(span).remove();
			Ext.fly(el).show();
			break;
		case 13:
			Ext.fly(span).remove();
			Ext.fly(el).show();
			if(input_el.value!=value)
				callback(input_el.value)
			ev.stopEvent();
		}
	})
	
	Ext.fly(input_el).on("click", function(ev){
		ev.stopEvent();
	})
	
}

F.util.addTouchScroll =	function(el){
    var scrollStartPos=0;

    el.addEventListener("touchstart", function(event) {
        scrollStartPos=this.scrollTop+event.touches[0].pageY;
        //event.preventDefault();
    },false);

    el.addEventListener("touchmove", function(event) {
        this.scrollTop=scrollStartPos-event.touches[0].pageY;
        event.preventDefault();
    },false);

}
