﻿// global variables for agenda
var currentDate=new Date();
var currentMonth=currentDate.getMonth();
var currentYear=currentDate.getFullYear();
var today=currentDate.getDate();
var thisMonth=currentDate.getMonth();
var thisYear=currentDate.getFullYear();
var daysInMonth=new Array(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
var monthLabels=new Array("images/agenda/jan.png", "images/agenda/feb.png", "images/agenda/mar.png", "images/agenda/apr.png", "images/agenda/may.png", "images/agenda/jun.png", "images/agenda/jul.png", "images/agenda/aug.png", "images/agenda/sep.png", "images/agenda/oct.png", "images/agenda/nov.png", "images/agenda/dec.png");

function GetXmlHttpObject() {
    var xmlHttp = null;
    try {
        // Firefox, Opera 8.0+, Safari
        xmlHttp = new XMLHttpRequest();
    }
    catch (e) {
        // Internet Explorer
        try {
            xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
        }
        catch (e) {
            xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
        }
    }
    return xmlHttp;
}

function showSchedule() {    
	myRand = parseInt(Math.random() * 999999); // cache buster
    theurl = "schedule.php?rand=" + myRand;
    xmlHttpSchedule = GetXmlHttpObject();
    if (xmlHttpSchedule == null) { alert("Your browser does not support AJAX!"); return; }
    xmlHttpSchedule.onreadystatechange = function() {
        if (xmlHttpSchedule.readyState == 4) document.getElementById("poster_schedule").innerHTML = xmlHttpSchedule.responseText;		
    }	
    xmlHttpSchedule.open("GET", theurl, true);
    xmlHttpSchedule.send(null);
}

function showReviews() {    
	myRand = parseInt(Math.random() * 999999); // cache buster
    theurl = "reviews.php?rand=" + myRand;
    xmlHttpReviews = GetXmlHttpObject();
    if (xmlHttpReviews == null) { alert("Your browser does not support AJAX!"); return; }
    xmlHttpReviews.onreadystatechange = function() {
        if (xmlHttpReviews.readyState == 4) document.getElementById("posterLiveReviews_text").innerHTML = xmlHttpReviews.responseText;		
    }	
    xmlHttpReviews.open("GET", theurl, true);
    xmlHttpReviews.send(null);
}

function showNews() {    
	myRand = parseInt(Math.random() * 999999); // cache buster
    theurl = "news.php?rand=" + myRand;
    xmlHttpNews = GetXmlHttpObject();
    if (xmlHttpNews == null) { alert("Your browser does not support AJAX!"); return; }
    xmlHttpNews.onreadystatechange = function() {
        if (xmlHttpNews.readyState == 4) document.getElementById("posters_news").innerHTML = xmlHttpNews.responseText;		
    }	
    xmlHttpNews.open("GET", theurl, true);
    xmlHttpNews.send(null);
}

function showSupported() {    
	myRand = parseInt(Math.random() * 999999); // cache buster
    theurl = "supported.php?rand=" + myRand;
    xmlHttpSupported = GetXmlHttpObject();
    if (xmlHttpSupported == null) { alert("Your browser does not support AJAX!"); return; }
    xmlHttpSupported.onreadystatechange = function() {
        if (xmlHttpSupported.readyState == 4) document.getElementById("posters_supportedEvents").innerHTML = xmlHttpSupported.responseText;		
    }	
    xmlHttpSupported.open("GET", theurl, true);
    xmlHttpSupported.send(null);
}

function showAgenda(whichMonth) {
	myRand = parseInt(Math.random() * 999999); // cache buster
    theurl = "agenda.php?whichMonth=" + whichMonth + "&rand=" + myRand;
    eval("xmlHttpAgendaTemp" + myRand + " = GetXmlHttpObject();");
	xmlHttpAgenda = eval("xmlHttpAgendaTemp" + myRand);	
    if (xmlHttpAgenda == null) { alert("Your browser does not support AJAX!"); return; }
    xmlHttpAgenda.onreadystatechange = function() {
        if (xmlHttpAgenda.readyState == 4) document.getElementById("poster_agenda_text").innerHTML = xmlHttpAgenda.responseText;		
    }	
    xmlHttpAgenda.open("GET", theurl, true);
    xmlHttpAgenda.send(null);
}

function changeProgramDay(a,b) {
    for (i = 0; i < b; i++) document.getElementById("programDay" + i).style.display = "none";
	document.getElementById("programDay" + a).style.display = "block";    
}

function showInfo(what,a) {	
	info=document.getElementById(what);
	pm=document.getElementById("plusminus"+a);
	if (info.style.display=="none") { info.style.display="block"; pm.src="images/minus.png"; }
	else if (info.style.display=="block") { info.style.display="none"; pm.src="images/plus.png"; }
}

function makeCalendar(eventsOfTheMonth, month, year) {	
	currentMonth = month - 1;
	currentYear = year;	
	var eventsDay = new Array();	
	var eventsDescription = new Array();
	var allEvents = eventsOfTheMonth.split("#");
	for (k = 0; k < allEvents.length; k++) { temp = allEvents[k].split("~"); tempDate = temp[0].split("."); eventsDay[k] = tempDate[0]; eventsDescription[k] = temp[1]; }
	
	var theAskedDate = month + "/1/" + currentYear;
	var firstDate = new Date(theAskedDate.toString());
	var firstDay = firstDate.getDay() + 1;
	
	if (currentMonth == 1) { daysInMonth[1] = ((currentYear % 400 == 0) || ((currentYear % 4 == 0) && (currentYear % 100 !=0))) ? 29 : 28; }

	var heading='<table><tr><td valign="middle" align="center"><a href="javascript:changeCalendar(\'-\',' + month + ',' + currentYear + ');">&laquo;</a></td><td valign="middle" align="center"><img src="' + monthLabels[currentMonth] + '" border="0" alt="freequency"/></td><td valign="middle" align="center"><a href="javascript:changeCalendar(\'+\',' + month + ',' + currentYear + ');">&raquo;</a></td></tr></table>';

	var rows;
	if (((daysInMonth[currentMonth] == 31) && (firstDay >= 6)) || ((daysInMonth[currentMonth] == 30) && (firstDay == 7))) { rows = 6; }
	else if ((daysInMonth[currentMonth] == 28) && (firstDay == 1)) { rows = 4; }
	else { rows = 5; }

	var htmlString = '';
	htmlString += '<table style="width:220px;" cellspacing="0" cellpadding="0">';
	htmlString += '<tr><td colspan="7" align="center">' + heading + '<br/></td></tr>';
	htmlString += '<tr><td align="center" class="agendaWeekDays"><b>Κυ</b></td><td align="center" class="agendaWeekDays"><b>Δε</b></td><td align="center" class="agendaWeekDays"><b>Τρ</b></td><td align="center" class="agendaWeekDays"><b>Τε</b></td><td align="center" class="agendaWeekDays"><b>Πε</b></td><td align="center" class="agendaWeekDays"><b>Πα</b></td><td align="center" class="agendaWeekDays"><b>Σα</b></td></tr>';
	htmlString += '<tr><td colspan="7" width="30">&nbsp;</td></tr>';
	var dayCounter = 1;	
	var dayLoop = 1;
	for (var j = 1; j <= rows; j++)
	{	
		htmlString += '<tr align="center" valign="top">';
		for (var i = 1; i < 8; i++)
		{
			if ((dayLoop >= firstDay) && (dayCounter <= daysInMonth[currentMonth]))
			{
				var eventExistsOnThisDate = "none";
				for (o = 0; o < allEvents.length; o++) if (eventsDay[o] == dayCounter) eventExistsOnThisDate = eventsDescription[o].toString();
				if (eventExistsOnThisDate != "none") htmlString += '<td width="30" height="30"><img style="cursor:pointer; height:24px; width:24px;" onmouseover="ddrivetip(\'' + eventExistsOnThisDate + '\',\'#000000\')" onmouseout="hideddrivetip()" src="images/agenda/' + dayCounter + 'active.png" border="0" alt="' + dayCounter + '"/></td>';
				else htmlString += '<td width="30" height="30"><img src="images/agenda/' + dayCounter + '.png" border="0" alt="' + dayCounter + '"/></td>';
				dayCounter++;				
			}
			else htmlString += '<td width="30" height="30">&nbsp;</td>';
			
			dayLoop++;
		}
		htmlString += '</tr>';
	}
	htmlString += "</table>";
	document.getElementById("poster_agenda_text").innerHTML = htmlString;
}

function changeCalendar(direction,selectedMonth,selectedYear) {
	if (direction == '+')
	{
		if (selectedMonth == 12) { selectedMonth = 1; selectedYear++; }
		else { selectedMonth++; }
	}
	else if (direction == '-')
	{
		if (selectedMonth == 0) { selectedMonth = 12; selectedYear--; }
		else { selectedMonth--; }
	}
	showAgenda(selectedYear + "-" + selectedMonth + "-1");
}

function openPopupWindow(a) {
	if (a == "radio") {
		var w = 355;
		var h = 50;
		var LeftPosition=(screen.width)?(screen.width-w)/2:100;
		var TopPosition=(screen.height)?(screen.height-h)/2:100;
		var settings='width='+w+',height='+h+',top='+TopPosition+',left='+LeftPosition+',scrollbars=no,location=no,directories=no,status=no,menubar=no,toolbar=no,resizable=no';
		win = window.open("radio.htm","freequency",settings);
	}
	else if (a == "chat") {
		var w = 325;
		var h = 445;
		var LeftPosition=(screen.width)?(screen.width-w)/2:100;
		var TopPosition=(screen.height)?(screen.height-h)/2:100;
		var settings='width='+w+',height='+h+',top='+TopPosition+',left='+LeftPosition+',scrollbars=no,location=no,directories=no,status=no,menubar=no,toolbar=no,resizable=no';
		win = window.open("chat.htm","freequency",settings);
	}
	else if (a == "request") {
		var w = 400;
		var h = 160;
		var LeftPosition=(screen.width)?(screen.width-w)/2:100;
		var TopPosition=(screen.height)?(screen.height-h)/2:100;
		var settings='width='+w+',height='+h+',top='+TopPosition+',left='+LeftPosition+',scrollbars=no,location=no,directories=no,status=no,menubar=no,toolbar=no,resizable=no';
		win = window.open("addRequests.php","freequency",settings);
	}
}

var scrollTips = {
	dx : null,
	init : function() {	
		if (window.addEventListener) {
		window.addEventListener("DOMMouseScroll", this.mouseScroll, false);
		} else document.attachEvent("onmousewheel", this.mouseScroll);
	},
	mouseScroll : function(e) {
		if (!e) var e = window.event;
		var scroll = e.detail ? e.detail * 20 : e.wheelDelta / -20;
		if (scroll>=0 ){  
		window.scrollBy(160,0);
		} else  window.scrollBy(-160,0) ; 
	},
	clearEvent : function() {
		if (window.addEventListener) {
		window.removeEventListener("DOMMouseScroll", this.mouseScroll, false);
		} else document.detachEvent("onmousewheel", this.mouseScroll);
	}	
}