﻿PWC.Utils = {
	getTopPos : function(inputObj)
	{		
		var returnValue = inputObj.offsetTop;
		while((inputObj = inputObj.offsetParent) != null){
			if(inputObj.tagName!='HTML')returnValue += inputObj.offsetTop;
		}
		return returnValue;
	},
	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;
			
		},
		_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;
			
		}
	},
	//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');}
}

