// utilities.js

// History:
// 071102 Function gehe()
//        Spezialbehandlung für calType == "p"

// t.b.d.
// (1) Browser Unterscheidung noch verbessern
// (2) besser programmieren
// (3) evtl die vars verschieden benennen hier und in den kjjmmddb.htm

// Screen
var screenWidth = screen.width;
var screenHeight = screen.height;
//alert('utilities:screenWidth='+screenWidth);
var windowWidth=400; // default
var windowHeight=400;
if(screenWidth >= 1600){windowWidth=800;windowHeight=800;}
  else if(screenWidth >= 1280){windowWidth=640;windowHeight=640;}
  else if(screenWidth >= 1152){windowWidth=576;windowHeight=576;}
  else if(screenWidth >= 1024){windowWidth=512;windowHeight=512;}
  else if(screenWidth >= 800){windowWidth=400;windowHeight=400;}
  else if(screenWidth >= 640){windowWidth=320;windowHeight=320;}
  else {windowWidth=320;windowHeight=320;}
//alert('utilities:windowWidth='+windowWidth);

// clock
var Titel = " © guyton art gallery - www.kunstkalenderblatt.de - ";

function uhr(){
  zeit = new Date();
  stunde = zeit.getHours();
  minute = zeit.getMinutes();
  sekunde = zeit.getSeconds();
  //if (stunde==0) {
  //  if (minute<2) {
	  // lade neues Kalenderblatt
  //  window.opener.location="m060104a.htm";
  //}
  //}

  if(lang=="en"){
    if (stunde > 12) {hour = stunde - 12;}
  }
  if (stunde < 10) {
  stunde = "0" + stunde;
  }
  if (minute < 10) {
  minute = "0" + minute;
  }
  if (sekunde < 10) {
  sekunde = "0" + sekunde;
  }

  // Zeit in Titelzeile schreiben + Uhr sich selber jede Sekunde starten
  if(lang=="en"){
    if (stunde > 12) {
      parent.document.title = hour +   ":" + minute + ":" + sekunde + "pm" + Titel + calName;}else{
	  parent.document.title = stunde + ":" + minute + ":" + sekunde + "am" + Titel + calName;
	}
  }else{
	parent.document.title = stunde + ":" + minute + ":" + sekunde + Titel + calName;
  }
  setTimeout("uhr()", 1000);
}

// fuer cSide full Image
full=null;
function fullscreenWindow()
{
  //alert('utilities:fullscreenWindow()');
  //now   = new Date();
  //date  = now.getDate(); date=(date<10)?"0"+date:date;
  //month = now.getMonth()+1; month=(month<10)?"0"+month:month;
	  
  //if (navigator.appName == "Netscape") {      // (1)
    //year  = now.getYear()-100; year="0"+year; // (2)
  //}else{
    //year  = now.getYear()-2000; year="0"+year; // (2)
  //}
  
  locat = cSide;
  //locat = calType+year+month+date+"c"+".htm";
  //alert('utilities:fullscreenWindow:locat: '+locat);

  if (navigator.appName == "Microsoft Internet Explorer") {
    // nur Microsoft Internet Explorer kann window.open("","full",..
	full=window.open("","full","fullscreen=yes,directories=0,location=0,menubar=1,resizeable=1,scrollbars=1,status=0,toolbar=0");
    if (full!=null)
    {
      if (full.opener==null) full.opener=self;
	  full.location.href=locat;
    }
  } else {
    full=window.open("","full","directories=0,location=0,menubar=0,resizeable=1,scrollbars=1,status=0,toolbar=0,width=100,height=100");
    if (full!=null)
    {
      if (full.opener==null) full.opener=self;
      full.moveTo(0,0);
	  full.outerHeight = screen.availHeight;
	  full.outerWidth = screen.availWidth;
	  full.location.href=locat;
    }
  }
}

// Cookie functions
function SetCookie (name,value,expires,path,domain,secure) {
  document.cookie = name + "=" + escape (value) +
    ((expires) ? "; expires=" + expires.toGMTString() : "") +
    ((path) ? "; path=" + path : "") +
    ((domain) ? "; domain=" + domain : "") +
    ((secure) ? "; secure" : "");
}

function getCookieVal (offset) {

  var endstr = document.cookie.indexOf (";", offset);
  
  if (endstr == -1)
    endstr = document.cookie.length;
  return unescape(document.cookie.substring(offset, endstr));

}

function GetCookie (name) {

  var arg = name + "=";
  var alen = arg.length;
  var clen = document.cookie.length;
  var i = 0;

  while (i < clen) {
    var j = i + alen;
    if (document.cookie.substring(i, j) == arg)
      return getCookieVal (j);
    i = document.cookie.indexOf(" ", i) + 1;
    if (i == 0) break; 
  }
  return null;
}

// Visibility of layers
var ivisibility="";
if(ivisibility!="hidden")ivisibility="visible";
//var ivisibility="visible";
function setVisibility(obj,val){
  switch(obj) {
    case "image":
	  //ivisibility = val;
	  document.getElementById("xyz").visibility = val;
	  //document.getElementsByName("xyz").visibility = val;
	  alert('utilities:obj='+im+', visibility='+val);
	  //location.reload();
      break;
   default:
     break;
  }
}

// Catalogue functions
function SetCatalogue(catalogueFile){
  //alert('utilities:catalogueFile='+catalogueFile);
  if(parent.window.opener.closed == true) alert("utilities:Not possible, you closed window before.");
  else parent.window.opener.location=catalogueFile;

}

// Menue functions
function SetMenue(){
  locat = "calMenue.htm";
  
  menue=window.open("","menue","directories=0,location=0,menubar=0,resizeable=0,scrollbars=0,status=0,toolbar=0,width=250,height=400");
  if (menue!=null)
  {
    if (menue.opener==null) menue.opener=self;
	  menue.location.href=locat;
      //menue.moveTo(windowX,windowY);
      //window.self.close();
  }

}

function gehe(calType) {
  now   = new Date();
  date  = now.getDate(); date=(date<10)?"0"+date:date;
  month = now.getMonth()+1; month=(month<10)?"0"+month:month;
	  
  if (navigator.appName == "Netscape") {      // (1)
    year  = now.getYear()-100; year="0"+year; // (2)
  }else{
    year  = now.getYear()-2000; year="0"+year; // (2)
  }
      //alert('utilities:calType: '+calType);
	  //alert('utilities:date: '+date);
	  //alert('utilities:month: '+month);
	  //alert('utilities:year: '+year);
	  
  if (calType == "p") {
    locat = calType+year+month+date+"a.htm";
  }else{
    locat = calType+year+month+date+".htm";
  }
  window.opener.location=locat;
  //window.self.close();
}

// Sprache
var lang = "de";  // Default value !!

// Wochen- und Monatsnamen
var Wochentag=new Array("SONNTAG","MONTAG","DIENSTAG","MITTWOCH","DONNERSTAG","FREITAG","SAMSTAG");
var WeekDay=new Array("SUNDAY","MONDAY","TUESDAY","WEDNESDAY","THURSDAY","FRYDAY","SATURDAY");
var Monat=new Array("JANUAR","FEBRUAR","MAERZ","APRIL","MAI","JUNI","JULI","AUGUST","SEPTEMBER","OKTOBER","NOVEMBER","DEZEMBER");
var Month=new Array("JANUARY","FEBRUARY","MARCH","APRIL","MAI","JUNE","JULY","AUGUST","SEPTEMBER","OCTOBER","NOVEMBER","DECEMBER");

// Language functions
function setLang(langVal){
  //set the date to delete cookies after 1 year from today
  var expdate = new Date ();
  expdate.setTime (expdate.getTime() + (1000 * 60 * 60 * 24 * 365));

  //alert('utilities:SetCookie name=Language, val='+langVal);
  SetCookie("Language",langVal,expdate);
}

function getLang(){
  return GetCookie('Language');
}

// overwrite lang as defined by latest cookie
var sprache = getLang();
if (sprache != null) {
  switch(sprache) {
    case "1":
	  lang = "de";
	  //alert('utilities:Sprache ist DEUTSCH');
      break;
    case "2":
	  lang = "en";
	  //alert('utilities:Sprache ist ENGLISH');
      break;
   default:
     break;
  }
}
// if no cookie defined lang="de" (default)

// Datum
var jetzt=new Date(); 
var weekdayNr=jetzt.getDay();
var monthNr=jetzt.getMonth();
var Tag = jetzt.getDate();
var jetztTag=Wochentag[weekdayNr];
var jetztMonat=Monat[monthNr];
if(lang=="de-DE"){
  jetztTag=Wochentag[weekdayNr];
  jetztMonat=Monat[monthNr];
} else if(lang=="de"){
  jetztTag=Wochentag[weekdayNr];
  jetztMonat=Monat[monthNr];
} else
{
  jetztTag=WeekDay[weekdayNr];
  jetztMonat=Month[monthNr];
}
//alert('utilities:jetztTag='+jetztTag);
//alert('utilities:jetztMonat='+jetztMonat);

// default css-Werte z.B. fuer B-Seite definieren (3)
var tFontFace = "Arial, Times New Roman, Helvetica";
tFontSize_pc = 2.0;
var tFontSize = Math.round((windowHeight*tFontSize_pc)/100);
var tFontWeight = "normal";
var aFontFace = "Arial, Times New Roman, Helvetica";
aFontSize_pc = 1.5;
var aFontSize = Math.round((windowHeight*aFontSize_pc)/100);
var aFontWeight = "normal";
var aFontColor = "black";

// Test functions (47/13)
function laden (f) {
  //alert(f.showDate.checked.value);
  //if (f.showDate.checked==true) {
    //parent.showDate="yes";
  //} else {
    //parent.showDate="no";
  //}
  locat=f.nachname.value+"."+f.vorname.value+"."+f.werknr.value+".a.htm";
  //alert('utilities:laden locat='+locat);
  location.href=locat;
}

function back () {
  locat=parent.aSide;
  //alert(locat);
  location.href=locat;
}

// Layer switch
function LayerSwitch(s){
  //alert('utilities:s='+s);
  switch(s) {
    case "1":
	  parent.locat="academic1.html";
      break;
   default:
	 break;
  }
  //alert('utilities:parent.locat='+parent.locat);
  this.location.href=parent.locat;
}

function donothing () {
  //nothing
}


