function CObject(id, refresh) {
 this.id = id;
 this.refresh = refresh;
 this.failcount = 0;
 this.time = 0;
 this.content;
}

function CImage(id, refresh, src) {
 this.id = id;
 this.refresh = refresh;
 this.time = 0;
 var im = new Image();
 im.src = src;
 this.i = im;
 this.done = 0;
 this.width = 0;
 this.height = 0;
 this.link = "";
 this.alt = "";
}

function CDialog(id, x, y) {
 this.id = id;
 this.x = x;
 this.y = y;
 this.offsetx = 0;
 this.offsety = 0;
 this.active;
}
var contr = new Array();
var imgs = new Array();
var dialogs = new Array();
var sinc = 0;
window.settingMessage = false;
window.message = "";
window.lastmessage = "";
window.requestPending = 0;
window.norequest = 0;
var maxscroll = 0;

function refresh(element) {
 sendMessage("refresh#" + element);
}

function sendMessage(param) {
 if (window.message.indexOf(param) != -1) return;
 window.settingMessage = true;
 if (window.message.length != 0) window.message += "&";
 window.message += param;
 window.settingMessage = false;
}


function gotopage(element) {
 setHash("?command=gotopage%23" + element);
 sendMessage("gotopage#" + element);
}

function gototeam(team) {
 setHash("?command=gototeam%23" + team);
 sendMessage("gototeam#" + team);
}

function gotomomcad(team) {
 setHash("?command=gotomomcad%23" + team);
 sendMessage("gotomomcad#" + team);
}

function gotoarticle(element) {
 setHash("?command=gotoarticle%23" + element);
 sendMessage("gotoarticle#" + element);
}

function gotousermanagement(userID) {
 sendMessage("gotousermanagement#" + userID);
}

function gotonewuser() {
 sendMessage("gotonewuser");
}



function gotoforum() {
 setHash("?command=gotoforum%23");
 sendMessage("gotoforum#");
}

function gotosubforum(forum) {
 setHash("?command=gotosubforum%23" + forum);
 sendMessage("gotosubforum#" + forum);
}

function gotothread(thread) {
 setHash("?command=gotothread%23" + thread);
 sendMessage("gotothread#" + thread);
}

function gotomessage(mess) {
 setHash("?command=gotomessage%23" + mess);
 sendMessage("gotomessage#" + mess);
}


function gotousermanagementlist() {
 sendMessage("gotousermanagementlist#");
}

function showaddcommentdialog(art) {
 sendMessage("showaddcommentdialog#" + art)
}

function showaddfeedbackdialog(replyto,parent) {
 sendMessage("showaddfeedbackdialog#" + replyto + "#" + parent)
}





function getHash(str) {
 if (str == null) return 0;
 var out = 0;
 var k = 0;
 for (k = 0; k < str.length; k++) {
  out += str.charCodeAt(k);
 }
 return out;
}

function GetFromServer(sadrzaj, context) {
 var filled = false;
 var strings = sadrzaj.split("###")
 var i = 0;
 var last = -1;
 while (i < strings.length) {
  if (last == i) {
   alert(sadrzaj);
   sinc = 0;
   requestPending = 0;
   message = oldmessage + "&" + message;
   return;
  }
  last = i;
  if (strings[i] == "empty") {
   i++;
   continue;
  }
  if (strings[i] == "message") {
   i++;
   alert(strings[i]);
   i++;
   continue;
  }
  if (strings[i] == "settitle") {
   i++;
   var title = strings[i];
   if (window.IE) {
    var k = 0
    title += '   ';
    for (k = 0; title.length < 200; k++) {
     title += String.fromCharCode(171);
    }
   }
   document.title = title;
   i++;
   continue;
  }
  if (strings[i] == "fill") {
   i++;
   if (document.getElementById(strings[i]) != null) {
    var c = getControl(strings[i]);
    var width = "auto";
    var height = "auto";
    try { width = document.getElementById(strings[i]).style.width; } catch (e) { }
    try { height = document.getElementById(strings[i]).style.height; } catch (e) { }
    if (width == "" && document.getElementById(strings[i]).width!=null ) { try { width = document.getElementById(strings[i]).width; } catch (e) { } }
    if (height == "" && document.getElementById(strings[i]).height != null) { try { height = document.getElementById(strings[i]).height; } catch (e) { } }
    var refr = false;
    var myhash = getHash(strings[i + 1]);
    if (c == null) refr = true;
    else {
     if (c.content != myhash || strings[i + 1] == "") refr = true;
    }
    if (refr) {
     lastscroll = -1;
     filled = true;
     if (c != null) c.content = myhash;
     strings[i + 1] = strings[i + 1].replace("<#rand#>", "rand=" + Math.random());
     document.getElementById(strings[i]).innerHTML = strings[i + 1];
     if (strings[i + 1] == "") {
      //document.getElementById(strings[i]).style.height = "0px";
      //document.getElementById(strings[i]).style.width = "0px";
      document.getElementById(strings[i]).style.display = "none";
      //document.getElementById(strings[i]).style.position = "absolute";
     }
     else {
      //document.getElementById(strings[i]).style.position = "static";
      document.getElementById(strings[i]).style.display = "inherit";
      document.getElementById(strings[i]).style.height = height;
      document.getElementById(strings[i]).style.width = width;
     }
    }
   } else if (strings[i] != "MainContent") {
    sendMessage("delete#" + strings[i]);
    removeControl(strings[i]);
   }
   if (strings[i] == "MainContent") {
    window.visibleHeight = -2;
    scrollheight = -1;
   }
   i += 2;
   continue;
  }

  if (strings[i] == "append") {
   i++;
   if (document.getElementById(strings[i]) != null) {
    document.getElementById(strings[i]).innerHTML += strings[i + 1];
   } else {
    sendMessage("delete#" + strings[i]);
    removeControl(strings[i]);
   }
   i += 2;
   continue;
  }

  if (strings[i] == "dialog") {
   i++;
   getScroll();
   var sw = window.width;
   var sh = window.height;
   document.getElementById("dialog").innerHTML = "<table id=\"diatable\" width=" + (sw - 20) + "px height=" + (sh-20) + "px background=\"images/forum/back.gif\" cellpadding=0 cellspacing=0 border=0><tr valign=middle><td align=center>" + strings[i] + "</td></tr></table>";
   document.getElementById("dialog").style.visibility = "visible";
   scrollEvent();
   i++;
   continue;
  }

  if (strings[i] == "dialog1") {
   getScroll();
   i++;
   showdialog1(strings[i]);
   scrollEvent();
   i++;
   continue;
  }

  if (strings[i] == "searchdialog") {
   i++;
   showsearchdialog(strings[i]);
   i++;
   continue;
  }

  if (strings[i] == "messagedialog") {
   i++;
   showmessagedialog(strings[i]);
   i++;
   continue;
  }



  if (strings[i] == "popup") {
   window.popuptime = 0;
   i++;
   document.getElementById("popupdialog").innerHTML = strings[i];
   var sw = window.width;
   var sh = window.height;
   var w = document.getElementById("popupdialog").offsetWidth;
   var h = document.getElementById("popupdialog").offsetHeight;
   document.getElementById("popupdialog").style.left = (sw - w - 40 + window.scrollx) + "px";
   document.getElementById("popupdialog").style.top = (40 + window.scrolly) + "px";
   document.getElementById("popupdialog").style.visibility = "visible";
   i++;
   continue;
  }
  if (strings[i] == "closedialog") {
   i++;
   closedialog();
   continue;
  }
  if (strings[i] == "closedial") {
   i++;
   closedial(strings[i + 1]);
   i++;
   continue;
  }

  if (strings[i] == "closedialog1") {
   i++;
   closedialog1();
   continue;
  }

  if (strings[i] == "filldialog") {
   window.popuptime = 0;
   i++;
   document.getElementById(strings[i]).innerHTML = strings[i + 1];
   var sw = window.width;
   var sh = window.height;
   var w = document.getElementById(strings[i]).offsetWidth;
   var h = document.getElementById(strings[i]).offsetHeight;
   var posx = parseInt(strings[i + 2]);
   if (posx < 0) posx = (sw - w - posx + window.scrollx);
   var posy = parseInt(strings[i + 3]);
   if (posy < 0) posy = (sh - h - posx + window.scrolly);
   if (posx != 0) document.getElementById(strings[i]).style.left = posx + "px";
   if (posy != 0) document.getElementById(strings[i]).style.top = posy + "px";
   document.getElementById(strings[i]).style.visibility = "visible";
   document.getElementById(strings[i]).style.position = "absolute";
   i += 4;
   continue;
  }


  if (strings[i] == "refreshall") {
   i++;
   var j = 0;
   for (j = 0; j < contr.length; j++) {
    if (contr[j].id.indexOf("Menu") == -1 && contr[j].id.indexOf("Template") == -1) contr[j].time = 2000000;
   }
   continue;
  }

  if (strings[i] == "refresh") {
   i++;
   var j = 0;
   for (j = 0; j < contr.length; j++) {
    if (contr[j].id == strings[i]) contr[j].time = 2000000;
   }
   i++;
   continue;
  }

  if (strings[i] == "fileuploaddone") {
   i++;
   onafterfiledone(strings[i], strings[i + 1], strings[i + 2]);
   i += 3;
   continue;
  }

  if (strings[i] == "documentuploaddone") {
   i++;
   window.afterdocumentdone(strings[i], strings[i + 1]);
   i += 2;
   continue;
  }


  if (strings[i] == "playsound") {
   i++;
   document.getElementById("sound1").Play();
   i++;
   continue;
  }



  if (strings[i] == "register") {
   i++;
   if (!controlExists(strings[i])) {
    var c = new CObject(strings[i], strings[i + 1]);
    c.time = 2000000;
    contr[contr.length] = c;
   }
   else {
    getControl(strings[i]).time = 2000000;
   }
   i += 2;
   continue;
  }
  if (strings[i] == "image") {
   i++;
   var io = new CImage(strings[i], 10000, strings[i + 1]);
   io.alt = strings[i + 2];
   io.width = strings[i + 3];
   io.height = strings[i + 4];
   io.link = strings[i + 5];
   imgs[imgs.length] = io;
   i += 6;
   continue;
  }
  if (strings[i] == "sethash") {
   i++;

   setHash(strings[i]);
   i++;
   continue;
  }
  if (strings[i] == "loadmenu") {
   i++;
   eval(strings[i]);
   i++;
   continue;
  }
  if (strings[i] == "runscript") {
   i++;
   eval(strings[i]);
   i++;
   continue;
  }
  if (strings[i] == "changetemplate") {
   i++;
   window.triedToWriteMenus = false;
   contr = new Array();
   imgs = new Array();
   var c = new CObject(strings[i], 1900000);
   c.time = 2000000;
   contr[contr.length] = c;
   i++;
   continue;
  }



 } //end while
 oldmessage = "";
 if (filled) {
  getScroll();
  lastscroll = -1;
  window.scrollTo(0, window.scrolly);
 }
 sinc = 0;
 requestPending = 0;
}
var skip = 0;
var scrolldone = true;

function setscrollto(val) {
 if (scrolldone) {
  scrolldone = false;
  window.scrolltoval = val;
  setTimeout("doautoscroll()", 10);
 }
}


function ParseControls() {
 if (scrollheight != h) {
  var mc = document.getElementById("MainContent");
  if (mc != null) {
   var h = mc.offsetTop + mc.offsetHeight + 500;
   if (scrollheight == h) {
    window.visibleHeight = h;
    lastscroll = -1;
   }
   if (scrollheight < h) {
    scrollheight = h;
   }
  }
 }

 if (lastscroll != window.scrolly) {
  scrollEvent();
  lastscroll = window.scrolly;
  if (window.visibleHeight < window.scrolly && scrollheight != -1 && window.visibleHeight != -2) {
   var sval = window.visibleHeight - 600;
   if (sval < 0) sval = 0;
   setscrollto(sval)
  }
  if (maxscroll < document.body.scrollHeight) {
   maxscroll = document.body.scrollHeight + 50;
   window.scrolldiv.style.width = "2px";
   window.scrolldiv.style.height = maxscroll + "px";
  }
 }

 skip++;
 var i = 0;
 var coneffectcount = 0;
 for (i = 0; i < contr.length; i++) {
  if (document.getElementById(contr[i].id) == null) {
   if (contr[i].failcount > skip * 5) {
    sendMessage("delete#" + contr[i].id);
    removeControl(contr[i].id);
   }
   else {
    contr[i].failcount += 1;
   }
  }
  else {
   if (contr[i].time > contr[i].refresh) {
    if (sinc == 0 && Math.random() > -1) {
     if (coneffectcount > 10) {
      sinc = 1;
      coneffectcount = 0;
     }
     coneffectcount += 1;
     refresh(contr[i].id);
     contr[i].time = 0;
    }
   }
   if (skip > 5) {
    contr[i].time += 1;
   }
  }
 }
 if (skip > 5) {
  skip = 0;
  window.popuptime += 1;
  if (window.popuptime == 10) closepopup();
 }
 var loaded = 0;
 var j = 0;
 for (j = 0; j < imgs.length; j++) {
  if (document.getElementById(imgs[j].id) == null) {
   removeimage(imgs[j].id);
   j--;
   continue;
  }
  if (imgs[j].done == 0) {
   if (imgs[j].i != null) {
    if (imgs[j].i.complete) {
     var wh = "";
     if (imgs[j].width != 0) wh += " width=" + imgs[j].width;
     if (imgs[j].height != 0) wh += " height=" + imgs[j].height;
     var out = "<img src=" + imgs[j].i.src + wh + " alt=\"" + imgs[j].alt + "\" border=\"0\" />";
     if (imgs[j].link != "") {
      out = "<a href=\"" + imgs[j].link + "\">" + out + "</a>";
     }
     document.getElementById(imgs[j].id).innerHTML = out;
     imgs[j].done = 1;
    }
   }
  }
 }
 window.norequest++;
 if (window.settingMessage == false && window.message.length != 0) {
  var ins = document.getElementById('pageInstance').value;
  UseCallback(ins + "?" + window.message);
 }
 if (window.message.length == 0 && window.norequest > 20) {
  window.norequest = 0;
  var ins = document.getElementById('pageInstance').value;
  UseCallback(ins + "?" + "empty");
 }
 var hsh = "";
 if (window.IE) {
  if (document.getElementById('fakeframe').readyState != 'loading') {
   hsh = window.location.href;
   if (hsh.indexOf('#?') != -1) hsh = "#" + hsh.substr(hsh.indexOf('#?') + 1); else hsh = '';
   if (hsh != "" && hsh != window.lastHash) {
    setHash(hsh.substr(1));
    sendMessage(hsh.substr(hsh.indexOf('#?') + 2 + 8).replace("%23", "#"));
   } else {
    hsh = document.getElementById('fakeframe').contentWindow.location.href;
    if (hsh.indexOf('?') != -1) {
     hsh = "#" + hsh.substr(hsh.indexOf('?'));
    }
    else hsh = '';
   }
  }
  else hsh = window.lastHash;
 }
 else {
  hsh = window.location.href;
  if (hsh.indexOf('#?') != -1) hsh = "#" + hsh.substr(hsh.indexOf('#?') + 1); else hsh = '';
 }
 if (hsh != '' && window.lastHash != hsh) {
  setHash(hsh.substr(1));
  sendMessage(hsh.substr(hsh.indexOf('#?') + 2 + 8).replace("%23", "#"));
 }
 setTimeout("ParseControls();", 200);
}

function starttimer(mode) {
 scrollheight = -1;
 window.scrolldiv = document.getElementById("scrolldiv");
 window.htmlTag = document.getElementsByTagName("HTML")[0];
 window.bodyTag = document.getElementsByTagName("BODY")[0];
 getScroll();
 scrollEvent();
 if (mode == 0) setTimeout("ParseControls();", 50);
}




function removeControl(id) {
 var i = 0;
 for (i = 0; i < contr.length; i++) {
  if (contr[i].id == id) {
   contr.splice(i, 1);
   return;
  }
 }
}

function removeimage(id) {
 var i = 0;
 for (i = 0; i < imgs.length; i++) {
  if (imgs[i].id == id) {
   imgs.splice(i, 1);
   return;
  }
 }
}

function controlExists(id) {
 var i = 0;
 for (i = 0; i < contr.length; i++) {
  if (contr[i].id == id) {
   return true;
  }
 }
 return false;
}

function getControl(id) {
 var i = 0;
 for (i = 0; i < contr.length; i++) {
  if (contr[i].id == id) {
   return contr[i];
  }
 }
 return null;
}


function onEnter(e, fname) {
 var ev;
 if (e == null) ev = event; else ev = e;
 if (ev.keyCode == 13) {
  eval(fname);
  return true;
 }
 return false;
}

function ignore(e, ID) {
 var ev;
 if (e == null) ev = event; else ev = e;
 if (ev.keyCode == 27) {
  if (document.getElementById(ID + 'suggestionsholder') != null) {
   document.getElementById(ID + 'suggestionsholder').style.display = 'none';
   if (document.getElementById(ID + "_sugsel") != null) document.getElementById(ID + "_sugsel").value = -1;
   ev.cancelBubble = true;
   ev.returnValue = false;
   return false;
  } else return true;
 } else return true;
}

function showEnter(e) {
 var ev;
 if (e == null) ev = event; else ev = e;
 alert(ev.keyCode);
}

function activateSuggestions(e, ID) {
 var ev;
 if (e == null) ev = event; else ev = e;
 var count = 0;
 if (document.getElementById(ID + "_sugcount") != null) count = parseInt(document.getElementById(ID + "_sugcount").value);
 var selected = parseInt(document.getElementById(ID + "_sugsel").value);
 if (ev.keyCode == 13) {
  if (selected > -1) {
   document.getElementById(ID + 'search').value = document.getElementById(ID + '_sugtext' + selected).value;
   document.getElementById(ID + '_sugselval').value = document.getElementById(ID + '_sugval' + selected).value;
  }
  submitDialogCommand(ID, 'setvalue', ID + '_sugselval^' + ID + 'search');
  document.getElementById(ID + 'suggestionsholder').style.display = 'none';
  document.getElementById(ID + "_sugsel").value = -1;
 } else if (ev.keyCode == 40) {
  document.getElementById(ID + "_sugsel").value = parseInt(document.getElementById(ID + "_sugsel").value) + 1;
  suggestionSelectionChanged(ID);
 } else if (ev.keyCode == 38) {
  document.getElementById(ID + "_sugsel").value = parseInt(document.getElementById(ID + "_sugsel").value) - 1;
  suggestionSelectionChanged(ID);
 } else if (ev.keyCode == 27) {
 document.getElementById(ID + 'suggestionsholder').style.display = 'none';
  ev.cancelBubble = true;
  ev.returnValue = false;
  return false;
 } else if (ev.keyCode == 33) {
  document.getElementById(ID + "_sugsel").value = 0;
  suggestionSelectionChanged(ID);
 } else if (ev.keyCode == 34) {
  document.getElementById(ID + "_sugsel").value = count - 1;
  suggestionSelectionChanged(ID);
 }
 else if (ev.keyCode >= 40 || ev.keyCode >= 8) {
 submitDialogCommand(ID, 'showsuggestions', ID + 'search');
  document.getElementById(ID + "_sugsel").value = -1;
  document.getElementById(ID + "_sugselval").value = -1;
 }
}
function suggestionSelectionChanged(ID) {
 if (document.getElementById(ID + "_sugcount") == null) return;
 var count = parseInt(document.getElementById(ID + "_sugcount").value);
 var selected = parseInt(document.getElementById(ID + "_sugsel").value);
 if (selected < -1) document.getElementById(ID + "_sugsel").value = -1;
 if (selected >= count) { document.getElementById(ID + "_sugsel").value = count - 1; selected = count - 1; }
 var i = 0;
 for (i = 0; i < count; i++) {
  if (i == selected) {
   document.getElementById(ID + "_sug" + i.toString()).className = "suggestionSelected";
  } else {
   document.getElementById(ID + "_sug" + i.toString()).className = "suggestions";
  }
 }
}


function submitCommandValue(ID, command, value) {
 var out = "submitcommand#" + ID + "#" + command + "#" + value;
 sendMessage(out);
}


function setHash(str) {
 var title = document.title;
 var hsh = "";
 if (window.IE) {
  hsh = document.getElementById('fakeframe').contentWindow.location.href;
  if (hsh.indexOf('?') != -1) hsh = "#" + hsh.substr(hsh.indexOf('?')); else hsh = '';
 }
 else {
  hsh = window.location.href;
  if (hsh.indexOf('#?') != -1) hsh = "#" + hsh.substr(hsh.indexOf('#?') + 1); else hsh = '';
 }

 window.location.hash = str.replace('#', '%23');
 window.lastHash = "#" + str;
 if (window.IE) {
  var myElement = document.getElementById('fakeframe');
  myElement.contentWindow.location = "blank.html" + str;
 }

 if (window.IE) {
  var k = 0
  title += '   ';
  for (k = 0; title.length < 200; k++) {
   title += String.fromCharCode(171);
  }
 }
 document.title = title;
}

function getScroll() {
 var i = 0;
 if (window.navigator.appName.indexOf("Internet") == -1) {
  window.scrolly = window.pageYOffset;
  window.scrollx = window.pageXOffset;
  window.height = window.innerHeight;
  window.width = window.innerWidth;
 } else {
  window.scrolly = 0;
  window.scrollx = 0;
  var ob = document.body;
  if (ob.scrollTop != 0) window.scrolly = ob.scrollTop;
  if (ob.scrollLeft != 0) window.scrollx = ob.scrollLeft;
  window.height = ob.offsetHeight;
  window.width = ob.offsetWidth;
  var ob = window.htmlTag;
  if (ob.scrollTop != 0) window.scrolly = ob.scrollTop;
  if (ob.scrollLeft != 0) window.scrollx = ob.scrollLeft;
  window.height = ob.offsetHeight;
  window.width = ob.offsetWidth;
 }
}

function scrollEvent() {
 var diatable = document.getElementById("diatable");
 if (diatable != null) {
  var dial = document.getElementById("dialog");
  var sw = window.width;
  var sh = window.height;
  var w = dial.offsetWidth;
  var h = dial.offsetHeight;
  dial.style.left = (window.scrollx) + "px";
  dial.style.top = (window.scrolly) + "px";

  diatable.style.top = (window.scrolly) + "px";
  diatable.style.left = (window.scrollx) + "px";
  diatable.style.width = (sw-20) + "px";
  diatable.style.height = (sh-20) + "px";
 }
 var diatable1 = document.getElementById("diatable1");
 if (diatable1 != null) {
  var dialog1 = document.getElementById("dialog1");
  var sw = window.width;
  var sh = window.height;
  var w = dialog1.offsetWidth;
  var h = dialog1.offsetHeight;
  dialog1.style.left = (window.scrollx) + "px";
  dialog1.style.top = (window.scrolly) + "px";
  diatable1.style.top = window.scrolly + "px";
  diatable1.style.left = window.scrollx + "px";
  diatable1.style.width = (sw-20) + "px";
  diatable1.style.height = (sh-20) + "px";
 }
 var popup = document.getElementById("popupdialog");
 if (popup.innerHTML != "") {
  var sw = window.width;
  var sh = window.height;
  var w = popup.offsetWidth;
  var h = popup.offsetHeight;
  popup.style.left = (sw - w - 40 + window.scrollx) + "px";
  popup.style.top = (40 + window.scrolly) + "px";
 }
}

function movedialog(e) {
 try {
  var i = 0;
  for (i = 0; i < dialogs.length; i++) {
   if (dialogs[i].active == true) {
    var ev;
    if (e == null) ev = event; else ev = e;
    var deltax = ev.screenX - dialogs[i].x;
    var deltay = ev.screenY - dialogs[i].y;
    document.getElementById(dialogs[i].id).style.left = dialogs[i].offsetx + deltax + "px";
    document.getElementById(dialogs[i].id).style.top = dialogs[i].offsety + deltay + "px";
   }
  }
 } catch (err) { }
}

function doautoscroll() {
 var dist = Math.abs(window.scrolly - window.scrolltoval);
 if (dist < 20) {
  window.scrollTo(window.scrollx, window.scrolly - dist / 10);
  scrolldone = true;
  return;
 }
 window.scrollTo(window.scrollx, window.scrolly - dist / 10);
 setTimeout("doautoscroll()", 10);
}
var lastscroll = -1;
var sevent = false;
var scrollheight = -1;

function setLang(langID) {
 document.getElementById("lang").value = langID;
 var lang = 'lang%23' + document.getElementById("lang").value + "%26";
 //if (document.getElementById("lang").value == "1") lang = ""

 var hsh = window.lastHash.substr(window.lastHash.indexOf('?command=') + 9);
 var langid = hsh.indexOf("lang%23");
 if (langid != -1) {
  hsh = hsh.substr(langid + 11);
 }
 setHash("?command=" + lang + hsh);
 sendMessage(lang + hsh);
}

function startExchange(id, period) {
 try {
  var imagelist = document.getElementById(id + "imageList").value.split("|");
  var i = 0;
  var current = parseInt(document.getElementById(id + "currentImage").value, 10);
  var lastImage = imagelist[current];
  current += 1;
  if (current >= imagelist.length) { current = 0; }
  var newImage = imagelist[current];
  document.getElementById(id + "currentImage").value = current;
  document.getElementById(id + "fadebackground").style.backgroundImage = "url('" + lastImage + "')";
  changeOpac(0, id + "fadeimage");
  document.getElementById(id + "fadeimage").src = newImage;
  opacity(id + "fadeimage", 0, 100, 2000);
  setTimeout("startExchange('" + id + "'," + period + ");", period);
 }
 catch (e)
  { }
}

function opacity(id, opacStart, opacEnd, millisec) {
 try {
  //speed for each frame
  var speed = Math.round(millisec / 100);
  var timer = 0;

  //determine the direction for the blending, if start and end are the same nothing happens
  if (opacStart > opacEnd) {
   for (i = opacStart; i >= opacEnd; i--) {
    setTimeout("changeOpac(" + i + ",'" + id + "')", (timer * speed));
    timer++;
   }
  } else if (opacStart < opacEnd) {
   for (i = opacStart; i <= opacEnd; i++) {
    setTimeout("changeOpac(" + i + ",'" + id + "')", (timer * speed));
    timer++;
   }
  }
 } catch (e)
    { }

}

//change the opacity for different browsers
function changeOpac(opacity, id) {
 try {
  var object = document.getElementById(id).style;
  object.opacity = (opacity / 100);
  object.MozOpacity = (opacity / 100);
  object.KhtmlOpacity = (opacity / 100);
  object.filter = "alpha(opacity=" + opacity + ")";
 } catch (e) { }
}

function resetdialogmove() {
 try {
  var i = 0;
  for (i = 0; i < dialogs.length; i++) {
   dialogs[i].active = false;
  }
 } catch (err) { }
}
