function fo(theObj, theDoc)
{
    var p, i, foundObj;

    if(!theDoc) theDoc = document;
    if( (p = theObj.indexOf('?')) > 0 && parent.frames.length)
    {
        theDoc = parent.frames[theObj.substring(p+1)].document;
        theObj = theObj.substring(0,p);
    }
    if(!(foundObj = theDoc[theObj]) && theDoc.all) foundObj = theDoc.all[theObj];
    
    for (i=0; !foundObj && i < theDoc.forms.length; i++) 
    foundObj = theDoc.forms[i][theObj];
    
    for(i=0; !foundObj && theDoc.layers && i < theDoc.layers.length; i++) 
    foundObj = fo(theObj,theDoc.layers[i].document);
    
    if(!foundObj && document.getElementById) foundObj = document.getElementById(theObj);

    return foundObj;
}

function URLEncode(sURL) 
{ 
    sURL = escape(sURL); 
	
	re = new RegExp("/","g")
    sURL = sURL.replace(re,"%2F"); 
    
    return sURL; 
}

function createRequest()
{
	var oReq=null;
	try{
		oReq=new ActiveXObject("Msxml2.XMLHTTP");
	}
	catch(e){
		try{
			oReq=new ActiveXObject("Microsoft.XMLHTTP");
		}
		catch(sc){
			oReq=null;
		}
	}
	
	if(!oReq&&typeof XMLHttpRequest!="undefined"){
		oReq=new XMLHttpRequest();
	}
	
	return oReq;
}

function getEventElement(e)
{

	if(typeof e.srcElement != 'undefined')
	{
		return e.srcElement;
	}
	else if(typeof e != 'undefined' && e != null)
	{
		return e.target;
	}
	
	return null;

}

function getElementPos(oElement)
{
	var oGeo = {x:0, y:0, height:0, width:0};
	
	oGeo.height = oElement.offsetHeight;
	oGeo.width = oElement.offsetWidth;
	if(oGeo.height == 0 && oGeo.width == 0 && typeof oElement.width != 'undefined')
	{
		oGeo.height = oElement.height;
		oGeo.width = oElement.width;
	}
	
	if (oElement.offsetParent)
	{
		while (oElement)
		{
			oGeo.x += oElement.offsetLeft;
			oGeo.y += oElement.offsetTop
			oElement = oElement.offsetParent;
		}
	}
	else if (oElement.x)
	{
		oGeo.x += oElement.x;
		oGeo.y += oElement.y;
	}
	
	return oGeo;
}

function addEvent(obj, evType, fn)
{
  if (obj.addEventListener)
  {
    obj.addEventListener(evType, fn, false);
    return true;
  }
  else if (obj.attachEvent)
  {
	
	var r = obj.attachEvent("on"+evType, fn);
    return r;
  }
  else if(typeof obj["on"+evType]  != 'undefined')
  {
	obj["on"+evType] = fn;
	return  (obj["on"+evType] == fn);
  }
  else
  {
	return false;
  }
}

function exeOnEnterKey(e, refFunction)
{
	var e = (e)? e : event;
	var nCode;
    
    if(e.charCode)
		nCode = e.charCode
    else
		nCode = (e.which) ? e.which : e.keyCode;
	
	if(nCode == 13 || nCode == 3)
	{
		refFunction();	
	} 
}

function sqlStr(str)
{
	str = String(str)
	if(str == '') return 'NULL';
	
	return '\'' + str.replace(/'/g,'\'\'')  + '\'' 
}	

function trim(str){
   return str.replace(/^\s*|\s*$/g,"");
}

function removeULSpace(s){
	return s.replace(/  */g,' ');
}

function countWords(s){
    return s.split(" ").length;
}
