Fujar.Utils = {
	getTopPos : function(inputObj)  
	{		
		var returnValue = inputObj.offsetTop;
		while((inputObj = inputObj.offsetParent) != null){
			if(inputObj.tagName!='HTML')returnValue += inputObj.offsetTop;
		}
		return returnValue;
	},
	_script : function(url){
		var oscript = document.createElement("script");
		oscript.src = url;
		oscript.type = 'text/javascript';
		document.getElementsByTagName("head")[0].appendChild(oscript);
	},
	addEvent :  function(obj,eventType,functionName,suffix)
	{ 
	  if(!suffix)suffix = '';
	  if(obj.attachEvent){ 
	    obj['e'+eventType+functionName+suffix] = functionName; 
	    obj[eventType+functionName+suffix] = function(){obj['e'+eventType+functionName+suffix]( window.event );} 
	    obj.attachEvent( 'on'+eventType, obj[eventType+functionName+suffix] ); 
	  } else 
	    obj.addEventListener(eventType,functionName,false); 	    
	},
	getLeftPos : function(inputObj)
	{
		var returnValue = inputObj.offsetLeft;
		while((inputObj = inputObj.offsetParent) != null){
			if(inputObj.tagName!='HTML')returnValue += inputObj.offsetLeft;
		}
		return returnValue;
	},
	nav : function(){
    	var bodyWidth = document.documentElement.clientWidth;
    	var bodyHeight = document.documentElement.clientHeight;
    	
		var bodyWidth, bodyHeight; 
		if (window.innerHeight){ // all except Explorer 
		 
		   bodyWidth = window.innerWidth; 
		   bodyHeight = window.innerHeight; 
		}  else if (document.documentElement && document.documentElement.clientHeight) {
		   // Explorer 6 Strict Mode 		 
		   bodyWidth = document.documentElement.clientWidth; 
		   bodyHeight = document.documentElement.clientHeight;

		} else if (document.body) {// other Explorers 		 
		   bodyWidth = document.body.clientWidth; 
		   bodyHeight = document.body.clientHeight; 

		}
		propiedades = new Object();
		propiedades.w = bodyWidth;
		propiedades.h = bodyHeight;
		return propiedades;		
	}, 
	_xml : {
		_str2xml : function(strXML){
			if (window.ActiveXObject)
			{
				var doc=new ActiveXObject("Microsoft.XMLDOM");
				doc.async="false";
				doc.loadXML(strXML);
			}
			// code for Mozilla, Firefox, Opera, etc.
			else
			{
				var parser=new DOMParser();
				var doc=parser.parseFromString(strXML,"text/xml");
			}// documentElement always represents the root node
			return doc;
		},
		_xml2string : function(xmlDom){
			var strs = null;
			var doc = xmlDom.documentElement;
			if(doc.xml == undefined){
				strs = (new XMLSerializer()).serializeToString(xmlDom);
			}else strs = doc.xml;
			return strs;
			
		},
		insertAfter : function( referenceNode, newNode ){
			referenceNode.parentNode.insertBefore( newNode, referenceNode.nextSibling );
		},
		
		_nodevalue : function(nodo){
			valor = (nodo.childNodes.length > 0)?nodo.firstChild.nodeValue:"";
			return valor;
		},
		_subnodevalue : function(nodo,nombre){
			var sbnodolist = nodo.getElementsByTagName(nombre);
			var valor = "";
			
			if(sbnodolist.length<=0){
				valor ="";
			}
			else{
				var sbnodo = sbnodolist[0];
				valor = this._nodevalue(sbnodo);
			}
			return valor;
			
		},
		setText : function(nodo,str){
			var doc = nodo.ownerDocument;
			nodo.appendChild(doc.createTextNode(str));
		},
		get_nextsibling : function(n)
		{
			var x = n.nextSibling;
			if(!x)return null;
			while (x.nodeType != 1)
			{
				x=x.nextSibling;
			}
			return x;
		},
		get_previoussibling : function(n)
		{
			var x = n.previousSibling;
			if(!x)return null;
			while (x.nodeType!=1)
			{
				x=x.previousSibling;
			}
			return x;
		},
		SwapNodes : function(nodoA,arriba,doc){
			if(!doc)doc = document;
		    nodoB = (arriba) ? nodoA.previousSibling : nodoA.nextSibling;
		    while(nodoB && nodoB.nodeType != 1){
			    nodoB = (arriba) ?  nodoB.previousSibling : nodoB.nextSibling;
		    }
		    if(!nodoB || nodoB.nodeType != 1)return;
		    nodoAux = doc.createElement(nodoB.nodeName);
		    nodoA.parentNode.replaceChild(nodoAux,nodoA);
		    nodoB.parentNode.replaceChild(nodoA,nodoB);
		    nodoAux.parentNode.replaceChild(nodoB,nodoAux);
		}
	},
	
	Form :{
		setComboIndexByValue : function(combo,value,asInt){
			for(var f=0;f <combo.options.length;f++){
				var vcombo = combo.options[f].value;
				if(asInt){
					vcombo = parseInt(vcombo);
					value = parseInt(value);
				}
				if(vcombo == value){
					combo.selectedIndex = f;
					return;
				} 
			}
			combo.selectedIndex = 0;
		}
	},
	//Estas son las funcione de texto
	trim : function(str){
	    str = str.replace(/^\s+/,'');
	    str = str.replace(/\s+$/,'');
	    return str;
	},
	htmlentities : function(str){
	    str = str.replace(/&/g,"&amp;");
	    str = str.replace(/\"/g,"&quot;");
        str = str.replace(/\'/g,"&#39;");
        str = str.replace(/</g,"&lt;");
        str = str.replace(/>/g,"&gt;");
        return str;
	},
	un_htmlentities : function(str){
        str = str.replace(/&gt;/g,"<");
        str = str.replace(/&anmp;/g,">");
        return str;
	},
	escapa : function(cadena){ return escape(cadena).replace(/\+/g, '%2B').replace(/\//g, '%2F');}
}

