﻿/* setStyleBgImgPath.js
   Cambia el path de backgroungImage de todos los elementos de una página que lo tengan preasignado.
*/

function setStyleBgImgPath(pPath)
{
  IE = (document.all);
  var tNode = document.getElementsByTagName('body');
  setChildrenStyleBgImgPath(tNode[0], pPath);
}

function setChildrenStyleBgImgPath(pNode, pPath)
{
   var currStyle="";
   if (pNode.childNodes && pNode.childNodes.length)
   {
     setChildrenStyleBgImgPath(pNode.childNodes, pPath);
   }
   else
   {
  	 for (var i = 0; i < pNode.length; i++)
  	 {
  	    if (pNode[i].nodeType != 1) continue;
  	    currBgImage = (IE) ? pNode[i].currentStyle.backgroundImage 
  	                       : getComputedStyle(pNode[i],"").backgroundImage;
        if (currBgImage)
        {
            pNode[i].style.backgroundImage = chgImgPath(pPath, currBgImage);
        }
  	 }
   }
}

function chgImgPath(pPath, pImg)
{
  var str = new String(pImg);
  var pos = str.lastIndexOf("/");
  var pos2 = str.lastIndexOf(")");
  return (IE) ? "url(\"" + pPath + str.substr(pos + 1)
              : "url(\"" + pPath + str.substring(pos + 1, pos2) + "\")" ;
}
