// www.soho-ku.com global website JavaScript

// Menu management
// function for folding/unfolding the menu items

function montre(id) {
var d = document.getElementById(id);
var display = 'block';

  //if the menu is already displayed, clicking again hides it
  if (d) 
  {
    if (d.style.display=='block') display='none';
  }
  for (var i = 1; i<=10; i++) {
		if (document.getElementById('smenu'+i)) 
    {
      document.getElementById('smenu'+i).style.display='none';
    }
	}

  if (d) d.style.display = display;
  
}

/// date and clock script
function display_date(){
  
  var mydate=new Date();
  var year=mydate.getYear();
  if (year < 1000) year+=1900

  //var day=two_digit(mydate.getDay());
  var month=two_digit(mydate.getMonth()+1);
  var daym=two_digit(mydate.getDate());
  
  var display;
  if (display = document.getElementById('date')) display.innerHTML = year+"/"+month+"/"+daym;
  
}
var clockID = 0;

function UpdateClock() {
   if(clockID) {
      clearTimeout(clockID);
      clockID  = 0;
   }

   var tDate = new Date();

   if (display = document.getElementById('clock')) display.innerHTML = "" 
                                   + two_digit(tDate.getHours()) + ":" 
                                   + two_digit(tDate.getMinutes()) + ":" 
                                   + two_digit(tDate.getSeconds());
   
   clockID = setTimeout("UpdateClock()", 1000);
}

function StartClock() {
   clockID = setTimeout("UpdateClock()", 100);
}

function KillClock() {
   if(clockID) {
      clearTimeout(clockID);
      clockID  = 0;
   }
}


// number display utility
function two_digit(num){
  if(num<10) return "0"+num;
  else return num;
} 
/// end-date and clock script


/// image popup function
function openImageWindow(address){
    //define the HTML code of the popup
    HTML_code = '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">\n';
    HTML_code += '<html>\n  <head>\n <meta http-equiv="content-type" content="text/html; charset=windows-1250">';
    HTML_code += '<title>Image Window</title>\n  </head>\n  <body style="text-align: center;" onBlur="javascript:window.close()">\n\n';
    HTML_code += '<table width="100%" height="100%" border="0"><tr><td valign="center" align="center">'
    
    imageCode = '<img src="'+address+'" style="display: block; margin: auto;" border="0" onClick="javascript:window.close()">\n';
    HTML_code += imageCode;
    
    HTML_code += '</td></tr></table>'
    HTML_code += '</body>';
    
    //compute the size of the popup corresponding to the size of the image
    image = new Image();
    image.src = (address);
    window_width = image.width + 20;
    window_height = image.height + 20;
    window_parameters = "width="+ window_width +",height="+ window_height + ",resizable=no,location=no,toolbar=no";

    imageWindow = window.open('', 'image_window', window_parameters);
    imageWindow.document.writeln(HTML_code);
    imageWindow.focus();
  }

/// page init and destroy scripts
function init(){
  StartClock();
  display_date();
}
function exit(){
  KillClock();
}
