var gecko = /gecko/i.test(navigator.userAgent); 
var ns = (document.layers)? true:false;
var ie = (document.all)? true:false;

function sb(ID, Text) {
    ID.src = ID.src.replace(/-p\./,'-a.')
    window.status = Text;    
    return true;
}

function db(ID) {
    ID.src = ID.src.replace(/-a\./,'-p.')
}

function tg(ID) {
    var e = document.getElementById(ID);

    if (e.style.display == 'none') {
        e.style.display = 'block';
    } else {
        e.style.display = 'none';
    }
}

function ce(ID) {
    var e = document.getElementById(ID);

    if (/exp/.test(e.src))
        e.src = e.src.replace(/exp/,'col');
    else
        e.src = e.src.replace(/col/,'exp');
}

function getSelectionValue(aSelection) {

    return aSelection.options[aSelection.selectedIndex].value;
}

function setSelectionValue(aSelection, aValue) {
    
    for (var i = 0; i < aSelection.options.length; i++) {
        if (aSelection.options[i].value == aValue) {
            aSelection.selectedIndex = i;
            break;
        }
    }
}

function correctPNG() {
   for(var i = 0; i < document.images.length; i++)
      {
	  var img = document.images[i]
	  var imgName = img.src.toUpperCase()
	  if (imgName.substring(imgName.length-3, imgName.length) == "PNG")
	     {
		 var imgID = (img.id) ? "id='" + img.id + "' " : ""
		 var imgClass = (img.className) ? "class='" + img.className + "' " : ""
		 var imgTitle = (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' "
		 var imgStyle = "display:inline-block;" + img.style.cssText 
		 if (img.align == "left") imgStyle = "float:left;" + imgStyle
		 if (img.align == "right") imgStyle = "float:right;" + imgStyle
		 if (img.parentElement.href) imgStyle = "cursor:hand;" + imgStyle		
		 var strNewHTML = "<span " + imgID + imgClass + imgTitle
		 + " style=\"" + "width:" + img.width + "px; height:" + img.height + "px;" + imgStyle + ";"
	     + "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
		 + "(src=\'" + img.src + "\', sizingMethod='scale');\"></span>" 
		 img.outerHTML = strNewHTML
		 i = i-1
	     }
      }
}

function correctRolloverPNG() {
   for(var i = 0; i < document.images.length; i++)
      {
	  var img = document.images[i]
	  if (! /^THM/.test(img.id)) continue;
	  var imgName = img.src.toUpperCase()
	  if (imgName.substring(imgName.length-3, imgName.length) == "PNG")
	     {
		 var imgClass = (img.className) ? "class='" + img.className + "' " : ""
		 var imgTitle = (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' "
		 var imgStyle = "display:inline-block;" + img.style.cssText 
		 var imgAttribs = img.attributes;
		 for (var j=0; j<imgAttribs.length; j++)
			{
			var imgAttrib = imgAttribs[j];
			if (imgAttrib.nodeName == "align")
			   {		  
			   if (imgAttrib.nodeValue == "left") imgStyle = "float:left;" + imgStyle
			   if (imgAttrib.nodeValue == "right") imgStyle = "float:right;" + imgStyle
			   break
			   }
            }
		 var strNewHTML = "<span " + imgClass + imgTitle
		 strNewHTML += " style=\"" + "width:" + img.width + "px; height:" + img.height + "px;" + imgStyle + ";"
	         strNewHTML += "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
		 strNewHTML += "(src='" + img.src + "', sizingMethod='scale');\""
		 strNewHTML += " onmouseover=\"sbf(this);\" onmouseout=\"dbf(this);\""
		 strNewHTML += "></span>" 
		 img.outerHTML = strNewHTML
		 i = i-1
	     }
      }
}

function sbf(ID) {
    ID.filters(0).src = ID.filters(0).src.replace(/-p\./,'-a.')
}

function dbf(ID) {
    ID.filters(0).src = ID.filters(0).src.replace(/-a\./,'-p.')
}

function PNGswap(myID) {
   var strOver  = "-a"
   var strOff = "-p"
   var oSpan = myID; //document.getElementById(myID)
   alert(oSpan.filters(0).src)
   var currentAlphaImg = oSpan.filters(0).src
   if (currentAlphaImg.indexOf(strOver) != -1)
      oSpan.filters(0).src = currentAlphaImg.replace(strOver,strOff)
   else
      oSpan.filters(0).src = currentAlphaImg.replace(strOff,strOver)
}

function init() {
    if (ie) correctRolloverPNG();
}

function imgReplace(n, id) {
    if (! id) {
        id = 'IMG';
    }
    var e = document.getElementById(id);
    
    if (e) e.src = e.src.replace(/-\d\d\.jpg/, '-' + n + '.jpg');
}
