function getIframeDocument(iframeNode) {
  if (iframeNode.contentDocument) return iframeNode.contentDocument
  if (iframeNode.contentWindow) return iframeNode.contentWindow.document
  return iframeNode.document
}
    
function setIframeSrc(iframeNode, src) {
  if (typeof iframeNode == 'string') {
    iframeNode = document.getElementById(iframeNode)
  }

  var doc = getIframeDocument(iframeNode)
  doc.location.replace(src)
}

function createIFrame(fname, turi, debug, container){
  
  var ifrstr = browser.isIE ? '<iframe name="'+fname+'" src="'+turi+'">' : 'iframe';
  var cframe = document.createElement(ifrstr);

  with(cframe){
    name = fname;
    setAttribute("name", fname);
    id = fname;
  }
  container = container || 'iframe_container';
  
  document.getElementById(container).appendChild(cframe);

  with(cframe.style){
        if (debug) {
            height = "480px"
            width = "350px";
        } else {
            if(!browser.isSafari){
                //We can't change the src in Safari 2.0.3 if absolute position. Bizarro.
                position = "absolute";
            }
            left = top = "0px";
            height = width = "1px";
            visibility = "hidden";
        }
  }
  
  if(!browser.isIE){
    setIframeSrc(cframe, turi);
  }
  
  return cframe
}


function postToIframe(content, action, target){
    if(typeof phonyForm == 'undefined'){
        phonyForm = document.createElement("form")
        phonyForm.style.display = "none"
        phonyForm.enctype = "application/x-www-form-urlencoded"
        phonyForm.method = "POST"        
    document.body.appendChild(phonyForm)
    }

    phonyForm.action = action
    phonyForm.target = target
    phonyForm.setAttribute("target", target);

    while(phonyForm.firstChild){
        phonyForm.removeChild(phonyForm.firstChild);
    }

    for(var x in content){
        var tn;
        if(browser.isIE){
            tn = document.createElement("<input type='hidden' name='"+x+"' value='"+content[x]+"'>")
            phonyForm.appendChild(tn)
        }else{
            tn = document.createElement("input");
            phonyForm.appendChild(tn);
            tn.type = "hidden";
            tn.name = x;
            tn.value = content[x]
        }
    }
    phonyForm.submit();
}

function createIEFrame(fname, src) {
  var rcvNode = new ActiveXObject("htmlfile");
  rcvNode.open();
  rcvNode.write("<html><head><title>ActiveX</title>")
  rcvNode.write("<script src='/cydia/style/browser.js'></sc"+"ript>")
  rcvNode.write("<script src='/cydia/style/iframe.js'></scr"+"ipt>")
  rcvNode.write("</head><body></body></html>")
  //rcvNode.write("<html><head><title>ActiveX</title></head><body></body></html>");
  rcvNode.close();
  
  rcvNode.parentWindow.deliver = deliver
                    
  var ifrDiv = rcvNode.createElement("div");
  rcvNode.appendChild(ifrDiv);
  ifrDiv.innerHTML = "<iframe name='"+fname+"' src='"+src+"'></iframe>"
  
  IEFrameNode = ifrDiv.firstChild
  IEFrameDocument = rcvNode
}
function download_deb(id){
  var data = new Object();
  data.id=id;
  postToIframe(data, 'download.php', 'download_frame')
}