var preloadFlag = true;
var bName = navigator.appName;
var bVer = parseInt(navigator.appVersion);
var whichBrowser;
var helpwindow;
var currentHelpHtml;
var ie  = (navigator.appName.toLowerCase().indexOf('microsoft') != -1);
var mac = (navigator.platform.toLowerCase().indexOf('mac') != -1);

if ((bName == 'Netscape') && (bVer ==3))  whichBrowser = 'n3';
if ((bName == 'Netscape') && (bVer >=4))  whichBrowser = 'n4';
if ((bName == 'Microsoft Internet Explorer') && (bVer ==3)) whichBrowser = 'i3';
if ((bName == 'Microsoft Internet Explorer') && (bVer >=4)) whichBrowser = 'i4';

function replace_amp(u) {
	return u.replace(/&amp;/g, "&");
}

function popPresentationWindow(u, nwidth, nheight) {
   var w, h, x, y, p;
   w = nwidth; h = nheight;
   x = (screen.availWidth - w)/2;
   y = (screen.availHeight - h)/2;
   p = 'resizable,left=' + x + ',top=' + y + ',width=' + w + ',height=' + h;
   popwin = window.open(u, 'Presentation', p);
   popwin.focus();
}

function popHostanoteSampleWindow(u) {
   var w, h, x, y, p;
   w = Math.min(800,screen.availWidth-40);
   h = Math.min(672,screen.availHeight-90);
   if (ie && mac) { w -= 16; h -= 16; }
   x = (screen.availWidth - w)/2;
   y = (screen.availHeight - h)/2;
   p = 'resizable,left=' + x + ',top=' + y + ',width=' + w + ',height=' + h;
   popwin = window.open(u, 'hostanotesample', p);
   popwin.focus();
}

function doTimedWindowFocus(theWindowRef) {
	/* if this is used, pop-up blockers will interfere! */
	theWindowRef.focus();
}

function popHelpWindow(u,u2,w,l,t) {
   currentHelpHtml = u2;
   helpwindow = window.open(u, w, 'toolbar=yes,resizable,left='+l+',top='+t+',width=790,height=600');
   /* helpwindow.help_content.location.href = currentHelpHtml;
   helpwindow.focus(); */
  checkOkayLoadHelpContent();
}

function checkOkayLoadHelpContent() {
   if (helpwindow.help_content) {
      setTimeout("loadHelpContent()",100);
   } else {
      setTimeout("checkOkayLoadHelpContent()",100);
   }
}

function loadHelpContent() {
      helpwindow.help_content.location.href = currentHelpHtml;
      helpwindow.focus();
}

function doSection (secName,imageName){
   var section_element = document.getElementById(secName);
   var image_element = document.getElementById(imageName);
   if (section_element.style.display=="none"){
      section_element.style.display=""
      image_element.src = "../images/triangle_down_shadow.gif";
   } else {
      section_element.style.display="none"
      image_element.src = "../images/triangle_right_shadow.gif";
   }
}

function doSection2 (secName,imageName){
   var section_element = document.getElementById(secName);
   var image_element = document.getElementById(imageName);
   if (section_element.style.display=="none"){
      section_element.style.display=""
      image_element.src = "images/triangle_down_shadow_sm.gif";
   } else {
      section_element.style.display="none"
      image_element.src = "images/triangle_right_shadow_sm.gif";
   }
}

/* function doSection (secName,imageName){
   if (secName.style.display=="none"){
      secName.style.display=""
      document[imageName].src = "../images/triangle_down_shadow.gif";
   } else {
      secName.style.display="none"
      document[imageName].src = "../images/triangle_right_shadow.gif";
   }
} */

function openGolfWindow() {
 if (whichBrowser == 'n4') {
      window.open('games/golf/main.html','main','width=608,height=300');
   } else if (whichBrowser == 'n3') {
      window.open('games/golf/main.html','main','width=624,height=316');
   } else if (whichBrowser == 'i3') {
      window.open('games/golf/main.html','main','width=624,height=316');
   } else if (whichBrowser == 'i4') {
      window.open('games/golf/main.html','main','width=608,height=300');
   }
}

function popDetail(szurl){window.open(szurl, '_dtl', 'width=600,height=400');}

function popDetail_lg(szurl){window.open(szurl, '_dtl', 'width=640,height=480');}

function popDetail_scr(szurl){window.open(szurl, '_dtl', 'top=20,left=20,resizable,scrollbars=1,width=500,height=500');}

function popCJWindow(u) {
   var w, h, x, y;
   if (screen.availHeight >= 650) { w = 800; h = 600; } else { w = 640; h = 480; }
   x = (screen.availWidth - w)/2;
   y = (screen.availHeight - h)/2;
   window.open(u, 'quiz', 'resizable,left=' + x + ',top=' + y + ',width=' + w + ',height=' + h);
}

function popVMdemoWindow(u) {
   var w, h, x, y;
   if (screen.availHeight >= 650) { w = 800; h = 600; } else { w = 640; h = 480; }
   x = (screen.availWidth - w)/2;
   y = (screen.availHeight - h)/2;
   window.open(u, 'quiz', 'resizable,left=' + x + ',top=' + y + ',width=' + w + ',height=' + h);
}

function popTourWindow(u) {
   var x;
   var y;
   var w = ((screen.availWidth/4)*3);
   var h = ((screen.availHeight/4)*3);
   x = (screen.availWidth - w)/2;
   y = (screen.availHeight - h)/2;
   window.open(u, 'quiz', 'resizable,left=' + x + ',top=' + y + ',width=' + w + ',height=' + h);
}

function popWindow(u) {
   helpwindow = window.open(u, 'Projects', 'resizable,left=20,top=20,width=780,height=600');
}

function newImage(u) {
   if (document.images) {
      i = new Image();
      i.src = u;
      return i;
   }
}

function changeImages() {
   if (document.images && preloadFlag == true) {
      for (var i=0; i<changeImages.arguments.length; i+=2) {
         document[changeImages.arguments[i]].src = changeImages.arguments[i+1];
      }
   }
}

function movr(strname) {
   changeImages(strname, 'theme/' + strname + '_over.gif');
}

function mout(strname) {
   changeImages(strname, 'theme/' + strname + '.gif');
}

function mr(cb, b) {
   var cn = b?'menuhover':'menu';
   if (navigator.appVersion.indexOf('MSIE') != -1)
      while (cb.tagName != 'TD') cb = cb.parentElement;
   else
      while (cb.tagName != 'TD') cb = cb.parentNode;
   cb.className = cn;
}
