/* MusicOfVienna - Calendar Application
 * -----------------------------------------------------------
 * (c) 2007 - CrossOVER - Thomas Zettelmayr
 * Use of this script is forbidden without written permission.
 *
 * Version 0.9
 */
 
// Localisation
var gLanguage="en"; // Language, default english
var monthNames=Array();
monthNames['en']=Array('January','February','March','April','May','June','July','August','September','October','November','December'); 
monthNames['de']=Array('Januar','Februar','März','April','Mai','Juni','Juli','August','September','Oktober','November','Dezember'); 

var prefixDay=Array();
prefixDay['en']="day_";
prefixDay['de']="tag_";

// Globals
var gFirstYear=null;
var gFirstMonth=null;
var gFirstDay=null;

var gActiveMonth=null;
var gActiveYear=null;

var gFirstActive=0;
var gLastActive=41;
var gStartCount=0;

var gMaxDays=Array(31,28,31,30,31,30,31,31,30,31,30,31);
var gCActive=false;


function highLight(calId) {
	var cSelect=calId.id.slice(7);
    if (cSelect >=gFirstActive && cSelect <=gLastActive ) calId.className="highlight";		
	}
	
function offLight(calId) {
	var cSelect=calId.id.slice(7);
    if (cSelect >=gFirstActive && cSelect <=gLastActive ) { 
    	calId.className="isactive";
    	}	
	}		
	
function gotoDate(fieldId) {
	if (fieldId >=gFirstActive && fieldId <=gLastActive ) { 
		var currentDay=fieldId-gStartCount;
		var goalString="/"+((gLanguage=="en") ? "" : gLanguage+"/")+prefixDay[gLanguage]+gActiveYear+( (gActiveMonth<10) ? '0'+gActiveMonth : gActiveMonth )+( (currentDay<10) ? "0"+currentDay : currentDay )+".htm";
		document.location.href=goalString;
		}
	return;		
	}	

function showMonth(yMonth) {
	alert(yMonth);
	}
	
function monthChanged(month) {
	gActiveMonth=month;
	createMonth();
	
	}	
	
function yearChanged(year) {
	gActiveYear=year;
	createMonth();
	}	

/* This function is called from the onload function of the page
 * fYear = the current Year
 * fMonth = the current Month
 * fDay = the current day
 */
	
function initialiseCalendar (fYear, fMonth, fDay, fLanguage) {
	// set the Month to the current one
	document.getElementById('calMonth').selectedIndex=fMonth-1;
    gLanguage=fLanguage;
	gFirstYear=fYear;
	gFirstMonth=fMonth;
	gFirstDay=fDay;
	
	// Set the active values:
	gActiveMonth=fMonth;
	gActiveYear=fYear;
	
	createMonth();
	}	
	
function initialiseCalendarOther (fYear, fMonth, fDay, fLanguage,otherMonth,otherYear) {
	// set the Month to the current one
	document.getElementById('calMonth').selectedIndex=otherMonth-1;
	document.getElementById('calYear').selectedIndex=otherYear-fYear;	
    gLanguage=fLanguage;
	gFirstYear=fYear;
	gFirstMonth=fMonth;
	gFirstDay=fDay;
	
	// Set the active values:
	gActiveMonth=otherMonth;
	gActiveYear=otherYear;
	createMonth();
	}		
	
/* Populates the select field with the options of the given year + 5 years
 * fYear = the current Year
 */	

function populateYears (fYear) {
	var yearsMax=fYear+5;
	var optSelected=true;		
	for (var i=fYear;i<=yearsMax;i++) {
	  	document.getElementById('calYear').add (new Option(i, i, optSelected), document.getElementById('calYear').length);
  		optSelected=false;
		}
	}	
	
	
	
	
/* This function creates the calendar display 
 * fYear = the current Year
 * defMonth = month 1-12
 * fDay = the current day
 */	
	
function createMonth () {
	// clear all entries
	for (var i=0;i<=41;i++) {
		currentCalendarElement=document.getElementById('calDate'+i);
		currentCalendarElement.innerHTML=" ";
		currentCalendarElement.className="disabled";
		}
	
	// update the title
	document.getElementById('calHeader').innerHTML=monthNames[gLanguage][gActiveMonth-1]+" "+gActiveYear;
			
		
	// if the date is in the past, bail out
	if (gActiveYear <= gFirstYear && gActiveMonth < gFirstMonth) {
		gLastActive=0;
		return;
	}
	
	// find the first Day and the last Day of the given Month
	var firstDate= new Date (gActiveYear,gActiveMonth-1,1);
	var firstDay = firstDate.getDay();
	var lastDay = gMaxDays[gActiveMonth-1];
	
	// treat leapyears accordingly in here
	if (gActiveMonth == 2 && (gActiveYear==2008 || gActiveYear == 2012 || gActiveYear == 2016)) lastDay++;
	
	
	var dayRunner = 1;
	gLastActive=lastDay+firstDay-1;
	gStartCount=firstDay-1;	
	// is the calendar close to the first month given
	if (gActiveMonth == gFirstMonth && gActiveYear == gFirstYear) {
		dayRunner=gFirstDay;
		firstDay=firstDay+gFirstDay-1;
		}
	gFirstActive=firstDay;
	
	var currentCalendarElement=null;
	for (i=firstDay;i<=gLastActive;i++) {
		currentCalendarElement=document.getElementById('calDate'+i);
		currentCalendarElement.innerHTML=dayRunner++;
		currentCalendarElement.className="isactive";
		}		


	
	
}

function populateProducts () {
	// populates the list of products depending on the selection in the Providers
	
	// vorhandene Elemente löschen falls vorhanden
	// alert($('selectCode').length);
	
	if ($('selectCode').length > 0) {
		var limiter = $('selectCode').length;
		for (var i=0;i< limiter;i++) {
			$('selectCode').remove(0);
			}
		}

	var optSelected=true;		
	gAnbieter[$F('selectProvider')].each(function(pair) {
	  	$('selectCode').add (new Option(pair.value, pair.key, optSelected), $('selectCode').length);
  		optSelected=false;
		});
	}	
	

function addContactMail() {
	document.write('<a href="mailto');
	document.write(':office&#x40;musicofvienna');
	document.write('.com">office');
	document.write('&#x40;musicofvienna.com</a>');
	}

function addBookmarks (bUrl,bTitle) {
	document.write('<a href="http://digg.com/submit?phase=2&url='+bUrl+'&title='+bTitle+'" title="Submit to Digg">Digg It</a>&nbsp; ');
	document.write('<a href="http://www.stumbleupon.com/submit?url='+bUrl+'&title='+bTitle+'">Stumble it!</a>&nbsp; ');
	document.write('<a href="http://del.icio.us/post?url='+bUrl+'&title='+bTitle+'">Del.icio.us</a>&nbsp; ');
	document.write('<a href="http://technorati.com/faves?add='+bUrl+'" title="Add to Technorati Favorites">Technorati</a>&nbsp; ');
	document.write('<a href="http://reddit.com/submit?url='+bUrl+';title='+bTitle+'" title="Reddit">Reddit</a>&nbsp; ');
	document.write('<a href="http://www.facebook.com/sharer.php?u='+bUrl+'&t='+bTitle+'" title="Post to Facebook">Facebook</a>&nbsp; ');
	}	
	
function addBookmarks_de (bUrl,bTitle) {
	document.write('<a href="http://digg.com/submit?phase=2&url='+bUrl+'&title='+bTitle+'" title="Submit to Digg">Digg It</a>&nbsp; ');
	document.write('<a href="http://www.stumbleupon.com/submit?url='+bUrl+'&title='+bTitle+'">Stumble it!</a>&nbsp; ');
	document.write('<a href="http://del.icio.us/post?url='+bUrl+'&title='+bTitle+'">Del.icio.us</a>&nbsp; ');
	document.write('<a href="http://technorati.com/faves?add='+bUrl+'" title="Add to Technorati Favorites">Technorati</a>&nbsp; ');
	document.write('<a href="http://reddit.com/submit?url='+bUrl+';title='+bTitle+'" title="Reddit">Reddit</a>&nbsp; ');
	document.write('<a href="http://www.facebook.com/sharer.php?u='+bUrl+'&t='+bTitle+'" title="Post to Facebook">Facebook</a>&nbsp; ');
	}		
	
function addBookmarks_en (bUrl,bTitle) {
	document.write('<a href="http://digg.com/submit?phase=2&url='+bUrl+'&title='+bTitle+'" title="Submit to Digg">Digg It</a>&nbsp; ');
	document.write('<a href="http://www.stumbleupon.com/submit?url='+bUrl+'&title='+bTitle+'">Stumble it!</a>&nbsp; ');
	document.write('<a href="http://del.icio.us/post?url='+bUrl+'&title='+bTitle+'">Del.icio.us</a>&nbsp; ');
	document.write('<a href="http://technorati.com/faves?add='+bUrl+'" title="Add to Technorati Favorites">Technorati</a>&nbsp; ');
	document.write('<a href="http://reddit.com/submit?url='+bUrl+';title='+bTitle+'" title="Reddit">Reddit</a>&nbsp; ');
	document.write('<a href="http://www.facebook.com/sharer.php?u='+bUrl+'&t='+bTitle+'" title="Post to Facebook">Facebook</a>&nbsp; ');
	}			

