var Utils = {
getNextSiblingByTag : function(object, tagName)
{
    if(object.nextSibling == null)
    {
        return null;
    }
    else if(object.nextSibling.tagName != tagName.toUpperCase())
    {
        return Utils.getNextSiblingByTag(object.nextSibling,tagName.toUpperCase());
    }
    else
    {
        var o = object.nextSibling;
        return o;
    }
},
getPreviousSiblingByTag : function(object, tagName)
{
    if(object.nextSibling == null)
    {
        return null;
    }
    else if(object.previousSibling.tagName != tagName.toUpperCase())
    {
        return Utils.getPreviousSiblingByTag(object.previousSibling,tagName.toUpperCase());
    }
    else
    {
        var o = object.previousSibling;
        return o;
    }
},
getFirstChildNode : function(object,tagName)
{
    for(var i = 0; i < object.childNodes.length; i++)
    {
        if(object.childNodes[i].tagName == tagName.toUpperCase())
        {
            return object.childNodes[i];
        }
    }
},
getChildNodeCountByTag : function(object,tagName)
{
    return object.getElementsByTagName(tagName).length;
}

};

////NextSibling e PreviousSibling
function getNextObject (node) {
    var n = node.nextSibling;
    while (n && n.nodeType != 1)
        n = n.nextSibling;    
    return n;  
}
function getPreviousObject (node) {
    var p = node.previousSibling;
    while (p && p.nodeType != 1)
        p = p.previousSibling;
    return p;
}

function setMousePointer(Control, mousePointer)
{
    var panel = getObject(Control);
    
    if (panel != null)
	    panel.style.cursor = mousePointer;
}

///////////////////////////////////////////////////////////////////////////////
// BROWSER TYPE AND VERSION                                                  //
///////////////////////////////////////////////////////////////////////////////

var isNav  = (navigator.appName.indexOf("Netscape")>=0);
var isMoz  = (navigator.appName.indexOf("Mozzila")==0);
var is5up  = false;
var isNav4 = false;
var isIE5  = false;
var isIE4  = false;
var searchReturnValue = '-1|-1';

if (isMoz)
{
	if (parseFloat(navigator.appVersion)>=5)
	{
		is5up = true;
	}
	else
	{
		isIE4=true;
	}
}
else if (isNav)
{
	if (parseFloat(navigator.appVersion)<5)
	{
		isNav4=true;
	}
	else
	{
		is5up = true;
	}
}
else
{
	if (navigator.appVersion.indexOf("MSIE")>0)
	{
		isIE5 = true;
		is5up = true;
	}
	else
	{
		isIE4=true;
	}
}


///////////////////////////////////////////////////////////////////////////////
// ELEMENT POSITION															 //
///////////////////////////////////////////////////////////////////////////////
function findPos(obj) {
	var curleft = curtop = 0;
	if (obj.offsetParent) {
		curleft = obj.offsetLeft
		curtop = obj.offsetTop
		while (obj = obj.offsetParent) {
			curleft += obj.offsetLeft
			curtop += obj.offsetTop
		}
	}
	return [curleft,curtop];
}

function findPosX(obj)
{
	var curleft = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curleft += obj.offsetLeft
			obj = obj.offsetParent;
		}
	}
	else if (obj.x)
	{
		curleft += obj.x;
	}
	return curleft;
}

function findPosY(obj)
{
	var curtop = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curtop += obj.offsetTop
			obj = obj.offsetParent;
		}
	}
	else if (obj.y)
	{
		curtop += obj.y;
	}
	return curtop;
}

///////////////////////////////////////////////////////////////////////////////
// DHTML LAYER FUNCTIONS                                                     //
///////////////////////////////////////////////////////////////////////////////

function LayerCreate(name, inleft, intop, width, height, visible, content)
{
	if (isNav4)
	{
		document.writeln("<layer name='" + name + "' left=" + inleft + " top=" + intop + " width=" + width + " height=" + height +	" visibility=" + (visible ? "'show'" : "'hide'") +  ">");
		document.writeln(content);
		document.writeln("</layer>");
	}
	else
	{		
		document.writeln("<div id='" + name + "' style='position:absolute; overflow:hidden; left:" + inleft + "px; top:" + intop + "px; width:" + width + "px; height:" + height + "px; z-index:6010; visibility:" + (visible ? "visible;" : "hidden;") + "'>");
		document.writeln(content);
		document.writeln("</div>");
	}
}

function LayerGet(name)
{
	var retVal = null;
	if (isNav4)
	{
		retVal = document.layers[name];
	}
	else if (isIE4)
	{
		retVal = eval('document.all.' + name + '.style');
	}
	else if (is5up)
	{
		var theObj = document.getElementById(name);
		if(theObj != null)
		{
			retVal = theObj.style;
		}
	}
	return retVal;
}
function LayerBackgroundColorSet(name, color)
{
	var layer = LayerGet(name);
	if (layer == null) return;
	if (isNav4)
	{
		layer.bgColor = color;
	}
	else
	{
		layer.backgroundColor = color;
	}
}
function LayerMove(name, x, y)
{
	var layer = LayerGet(name);
	if (layer == null) return;
	if (isNav4)
	{
		layer.moveTo(x, y);
	}
	else
	{
		layer.left = x + "px";
		layer.top  = y + "px";
	}	
}
function LayerShow(name)
{
	var layer = LayerGet(name);
	if (layer != null)
	{
		if (isNav4)
		{
			layer.visibility = "show";
		}
		else
		{
			layer.visibility = "visible";
		}
	}
}
function LayerHide(name)
{
	var layer = LayerGet(name);
	if (layer == null) return;
	if (isNav4)
	{
		layer.visibility = "hide";
	}
	else
	{
		layer.visibility = "hidden";
	}
}
function LayerSizeSet(name, w, h)
{
	var layer = LayerGet(name);
	if (layer == null) return;
	if (isNav4)
	{
		//layer.width = w;
		//layer.height = h;
	}
	else
	{
		layer.width = w+"px";
		layer.height = h+"px";
	}
}
function LayerClip(name, clipleft, cliptop, clipright, clipbottom)
{
	var layer = LayerGet(name);
	if (layer == null) return;		
	
	if (isNav4)
	{
		layer.clip.left   = clipleft;
		layer.clip.top    = cliptop;
		layer.clip.right  = clipright;
		layer.clip.bottom = clipbottom;
    } else {            
        var top = 0;
        var left = 0;
        var right = 0;
        var bottom = 0;
        var left = 0;
        
        cliptop = (isNaN(cliptop) ? cliptop : cliptop + 'px');
        clipright = (isNaN(clipright) ? clipright : clipright + 'px');
        clipbottom = (isNaN(clipbottom ) ? clipbottom  : clipbottom  + 'px');
        clipleft =  (isNaN(clipleft) ? clipleft : clipleft + 'px');
        
		layer.clip = 'rect(' + cliptop + ' ' +  clipright + ' ' + clipbottom + ' ' + clipleft + ')';
	}
}

///////////////////////////////////////////////////////////////////////////////
// IMAGE MANIPULATION                                                        //
///////////////////////////////////////////////////////////////////////////////

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}
function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}
function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}


////////////////////////////////////////////////////////////////////////////////
// String Operations
//////////////////////////////////////////////////////////////////////////////
function replace(string,text,by) 
{ 
// Replaces text with by in string 
	var i = string.indexOf(text); 
	if (string.length == 0) return string; 
	if ((!i) && (text != string.substring(0,text.length))) return string; 
	if (i == -1) return string; 

	var newstr = string.substring(0,i) + by; 

	if (i+text.length < string.length) newstr += 
	replace(string.substring(i+text.length,string.length),text,by); 
	return newstr; 
}

function trim(value)
{
      var temp = value;
      var obj = /^(\s*)([\W\w]*)(\b\s*$)/;
      if (obj.test(temp)) { temp = temp.replace(obj, '$2'); }
      var obj = /  /g;
      while (temp.match(obj)) { temp = temp.replace(obj, " "); }
      return temp;
}

////////////////////////////////////////////////////////////////////////////////////////
// Scroll
///////////////////////////////////////////////////////////////////////////////////////
function getScrollXY() {
  var scrOfX = 0, scrOfY = 0;
  if( typeof( window.pageYOffset ) == 'number' ) {
    //Netscape compliant
    scrOfY = window.pageYOffset;
    scrOfX = window.pageXOffset;
  } else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
    //DOM compliant
    scrOfY = document.body.scrollTop;
    scrOfX = document.body.scrollLeft;
  } else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
    //IE6 standards compliant mode
    scrOfY = document.documentElement.scrollTop;
    scrOfX = document.documentElement.scrollLeft;
  }
  return [ scrOfX, scrOfY ];
}

////////////////////////////////////////////////////////////////////////////////////////
// Window Size
///////////////////////////////////////////////////////////////////////////////////////

function getClientWindowSize() {
  var mWidth = 0, mHeight = 0;
  
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    mWidth = window.innerWidth;
    mHeight = window.innerHeight;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    mWidth = document.documentElement.clientWidth;
    mHeight = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    mWidth = document.body.clientWidth;
    mHeight = document.body.clientHeight;
  }

  return [ mWidth, mHeight ];
}


