var RETRYCOUNT = 5
var whatToPush = 'newdoc'

var whatToPush = ''
var pushRetryCount
var delayedDocId
var setDocIdRetryCount
var delayedDocPath
var setDocPathRetryCount

function push(button) {
  try {
    if (parent.head) parent.head.push(button)
  }
  catch(e) {
    whatToPush = button
    pushRetryCount = RETRYCOUNT
    setTimeout(delayedPush, 100)
  }
}

function delayedPush() {
  try {
    parent.head.push(whatToPush)
  }
  catch(e) {
    if (--pushRetryCount > 0) setTimeout(delayedPush, 100)
  }
}

function setButtons(info, approve) {
  if (parent && parent.head && !parent.head.windowloaded) location.reload()
  try {
    parent.head.setbuttons(info, approve)
  }
  catch(e) {
  }
}

function setDocId(id) {
  try {
   parent.docid = id
  }
  catch(e) {
    delayedDocId = id
    setDocIdRetryCount = RETRYCOUNT
    setTimeout(delayedSetDocId, 100)

  }
}

function delayedSetDocId(id) {
  try {
   parent.docid = delayedDocId
  }
  catch(e) {
    if (--setDocIdRetryCount > 0) setTimeout(delayedSetDocId, 100)
  }
}

function setDocPath(path) {
  try {
   parent.docpath = path
  }
  catch(e) {
    delayedDocPath = path
    setDocPathRetryCount = RETRYCOUNT
    setTimeout(delayedSetDocPath, 100)

  }
}

function delayedSetDocPath(paht) {
  try {
   parent.docpath = delayedDocPath
  }
  catch(e) {
    if (--setDocPathRetryCount > 0) setTimeout(delayedSetDocPath, 100)
  }
}

function uglyMSPatchEscape(s) {
  return s // !!! hack to avoid IE error removed, creates other problems
  var url = escape(s)
  url = url.replace(/%E6/g, 'æ')
  url = url.replace(/%F8/g, 'ø')
  url = url.replace(/%E5/g, 'å')
  url = url.replace(/%C6/g, 'Æ')
  url = url.replace(/%D8/g, 'Ø')
  url = url.replace(/%C5/g, 'Å')
  return url
}
