/* fragment load code */
function loadPage(page, divId, navlinkId) {
    var newText = getText(page);
    var div = document.getElementById(divId);
    div.innerHTML = newText;
    clearLinkStyles();
    document.getElementById(navlinkId).className = "navlink-current";
}

function clearLinkStyles() {
    var navLinks = document.getElementsByTagName("a");
    for (var i=0; i<navLinks.length; i++) {
        var link=navLinks[i];
        link.className="";
    }
}

function goSetHeight() {
  if (parent == window)
    return;
   // no way to obtain id of iframe object doc loaded into? no parentNode or parentElement or ...
  else
    parent.setIframeHeight('content-iframe');
}


function getDocHeight(doc) {
  var docHt = 0, sh, oh;
  if (doc.height) {
    docHt = doc.height;
  }
  else if (doc.body) {
    if (doc.body.scrollHeight)
        docHt = sh = doc.body.scrollHeight;
    if (doc.body.offsetHeight)
        docHt = oh = doc.body.offsetHeight;
    if (sh && oh)
        docHt = Math.max(sh, oh);
    if(navigator.userAgent.match("Safari") != null) {
    }
  }
  return docHt;
}

function setIframeHeight(iframeName) {
  var iframeWin = window.frames[iframeName];
  var iframeEl = document.getElementById? document.getElementById(iframeName): document.all? document.all[iframeName]: null;
  if ( iframeEl && iframeWin ) {
    iframeEl.style.height = "auto"; // helps resize (for some) if new doc shorter than previous  
    var docHt = getDocHeight(iframeWin.document);
    // need to add to height to be sure it will all show

    if (docHt)
        iframeEl.style.height = docHt + 30 + "px";
    else
      alert("no height!");
  }
}

function loadIframe(iframeName, url) {
  if ( window.frames[iframeName] ) {
    window.frames[iframeName].location = url;   

    return false;
  }
  else return true;
}

moz=document.getElementById&&!document.all
mozHeightOffset=20

function resize_iframe(){
document.getElementById("content-iframe").height=100 // required for Moz bug, value can be "", null, or integer
document.getElementById('content-iframe').height=window.frames["content-iframe"].document.body.scrollHeight+(moz?mozHeightOffset:0)
}


_factories  = [
    function() {return new ActiveXObject("Msxml2.XMLHTTP.5.0"); },
    function() {return new ActiveXObject("Msxml2.XMLHTTP.4.0"); },
    function() {return new ActiveXObject("Msxml2.XMLHTTP.3.0"); },
    function() {return new ActiveXObject("Msxml2.XMLHTTP"); },
    function() {return new ActiveXObject("Microsoft.XMLHTTP"); },
    function() {return new XMLHttpRequest(); },
];

_factory = null;

newRequest = function() {
    if (_factory != null) return _factory();
    
    for (var i=0; i<_factories.length; i++) {
        try {
            var factory = _factories[i];
            var request = factory();
            if (request != null) {
                _factory = factory;
                return request;
            }
        } catch (e) {
            continue;
        }
    }
    
    _factory = function() {
        throw new Error("XMLHttpRequest not supported");
    }
    _factory();
};

getText = function(url) {
    var request = newRequest();
    request.open("GET", url, false); // false makes it synchronous
    request.send(null);
    return request.responseText;
};

changeDiv1 = function() {
    document.getElementById("div1").innerHTML = "New div1 content!";
};

changeDiv2 = function(url) {
    document.getElementById("div2").innerHTML = getText(url);
};

showLargeImage = function (myImage,myWidth,myHeight,origLeft,origTop) {
    myHeight += 24;
    myWidth += 24;
    TheImgWin = window.open(myImage,'image','height=' +
    myHeight + ',width=' + myWidth +
    ',toolbar=no,directories=no,status=no,' +
    'menubar=no,scrollbars=no,resizable=no');
    TheImgWin.resizeTo(myWidth+2,myHeight+30);
    TheImgWin.moveTo(origLeft,origTop);
    TheImgWin.focus();
};

loadProduct = function(dataUrl, div) {
    var data = getText(dataUrl);
    var dataObj = eval(data);
    console.debug(data);
}



