﻿//JavaScript - Library
// All rights reserved on concept, design and solution as well as on attached files
// Copyright by medialink 2009 - v9.05.003e/22.05.2009
// -----------------------------------------------------------------------------------


//-----default-settings
var filename = "";
if (self.location.href.indexOf("?") > -1){
	filename=self.location.href.substring(self.location.href.lastIndexOf("/")+1,self.location.href.lastIndexOf("?"));
}else{
	filename=self.location.href.substring(self.location.href.lastIndexOf("/")+1,self.location.href.length);
}

//reading the rubric of file by directory (caused by weblication name-addons as wEdit/wdraft and so on)
rubricdirectory = self.location.href.substring(0,self.location.href.lastIndexOf("/"));
rubricdirectory = rubricdirectory.substring(rubricdirectory.indexOf("pages/")+6,rubricdirectory.indexOf("pages/")+8);
rubric = rubricdirectory;
sls = self.location.search.substring(1,self.location.search.length);

if (self.location.href.indexOf("evento") > -1){
	rubric = "AU";
}
if (self.location.href.indexOf("extranet") > -1){
	rubric = "IN";
}


//----- init-section ---------------------------------------------------------------------------
//defining the rubric (also for weblication-edit-filenames)
if ((rubric != "HO") && (rubric != "AN") && (rubric != "AU") && (rubric != "IN")){
	rubric= "HO"; //default if not specified
}



//setting the header images
function doinit(){
	if (document.images){
		document.images['topImageCenter'].src =  "/any/layout/images/topImageCenter" + rubric + ".jpg";
		document.images['topImageRight'].src  =  "/any/layout/images/topImageRight" + rubric + ".jpg";
	}
}



if (document.images){
	var imageov = new Array();
	var imageof = new Array();

	for (var z=1; z<=3; z++){
		imageov['fnc'+z] = new Image();
		imageov['fnc'+z].src = "http://www.zks-zuerich.ch/any/layout/images/fnc"+z+"ov.jpg";
		imageof['fnc'+z] = new Image();
		imageof['fnc'+z].src = "http://www.zks-zuerich.ch/any/layout/images/fnc"+z+"of.jpg";
	}
}


function imgov(i){
	if (document.images){
		document.images[i].src=imageov[i].src;
	}
}

function imgof(i){
	if (document.images){
		document.images[i].src = imageof[i].src;
	}
}




//----- div functions ------------------------------------------------------------------------------

function divToggle(divId){
	if (document.getElementById(divId).style.display == "none"){
		document.getElementById(divId).style.display = "block";
	}else{
		document.getElementById(divId).style.display = "none";
	}
}



//----- tooltip-handling ---------------------------------------------------------------------------
var leftOffset = 0;
var topOffset = 0;
tooltip = null;

if (w3c){
	document.onmousemove = updateTooltip;
}


function updateTooltip(e) {
	try {
		x = (document.all) ? window.event.x + document.body.scrollLeft : e.pageX;
		y = (document.all) ? window.event.y + document.body.scrollTop : e.pageY;
		if (tooltip != null) {
			tooltip.style.left = (x + leftOffset) + "px";
        	tooltip.style.top = (y + topOffset) + "px";
		}
	} catch (error) { error=null; }
}


function showTooltip(id,l,t) {
  	if (w3c){
  	
 	 	leftOffset = l;
	  	topOffset = t;
	  	
	  	//calculation depends on doctype of html-document!
 	 	if (ie && win){ 
  			if (document.body.scrollTop > 0){
  				topOffset = topOffset - document.body.scrollTop;
  			}
  			if (document.body.clientWidth > 970){
		  		leftOffset = leftOffset + ((document.body.clientWidth - 970)/2);
	  		}
	  	}
	  	
	    try {
	      tooltip = document.getElementById(id);
	      tooltip.style.display = "block"
	    } catch (error) { error=null; } 
	       
	}
}


function hideTooltip() {
	if (w3c){
		try {
			tooltip.style.display = "none";
		} catch (error) { error=null; }
	}
}




//-----form-functions---------------------------------------------------------------------------


//form-send
function formSend(t){

	if (t == "newsletter"){
		if ((document.formula.lastname.value=='') || (document.formula.firstname.value=='') || (document.formula.address.value=='') || (document.formula.zip.value=='') || (document.formula.location.value=='') || (document.formula.email.value=='')){
			alert(msgFormRequired);
		}else{
			document.formula.submit();
		}		
	}


	if (t == "event"){
		if ((document.formula.eventtitle.value=='') || (document.formula.eventdate.value=='') || (document.formula.eventlocation.value=='') || (document.formula.organizer.value=='') || (document.formula.lastname.value=='') || (document.formula.firstname.value=='') || (document.formula.email.value=='')){
			alert(msgFormRequired);
		}else{
			document.formula.submit();
		}		
	}


	if (t == "search"){		
		//hidden-field	0		ac
		//hidden-field	1		q
		//hidden-field	2		tpl_results (resultPage)
		//hidden-field	3		tpl_form (noResultPage)
		//hidden-field	4-7		limit[x] (searched directories)
		//hidden-field	8		displaylang
		//input-field 	9		searchterm
		//hidden-field	10		mode
		//hidden-field	11		word_match
		//hidden-field	12-15	type[x] (searched file types)	

		document.formSearch.q.value = document.formSearch.searchterm.value;
		if (document.formSearch.q.value == ""){
			alert(msgFormNoSearchEntry);
		}else{
			document.formSearch.submit();
		}
	}


}


  
  


//-----fnc-handling---------------------------------------------------------------------------

//print functions
function printPage(){
	if ((self.print) || (ie && win)){
		if (self.print){
			if (self.focus){
				self.focus();	//for E5W
			}
			self.print();
		}else{
			printo();	//E4W
		}
	}else{
		alert(msgPrintingFailed);
	}
}

function printo() {
	var OLECMDID_PRINT = 6;
	var OLECMDEXECOPT_DONTPROMPTUSER = 2;
	var OLECMDEXECOPT_PROMPTUSER = 1;
	var WebBrowser = '<OBJECT ID="WebBrowser1" WIDTH=0 HEIGHT=0 CLASSID="CLSID:8856F961-340A-11D0-A96B-00C04FD705A2"></OBJECT>';
	document.body.insertAdjacentHTML('beforeEnd', WebBrowser);
	oldHandler = window.onerror;
	window.onerror = deal;
	WebBrowser1.ExecWB(OLECMDID_PRINT, OLECMDEXECOPT_PROMPTUSER);
	WebBrowser1.outerHTML = "";
	window.onerror = oldHandler;
}

function deal(){
	WebBrowser1.outerHTML = "";
	window.onerror = oldHandler;
	return true;
}


//bookmark-functions
function setBookmark(){
	var bookmarkurl = self.location.href;
	var bookmarktitle = document.title;
	if (window.external && nomac){
		window.external.AddFavorite(bookmarkurl,bookmarktitle);
	}else{
		alert(msgBookmarkingFailed);
	}
}


//--- end of file
