var emailWindow;
var printWindow;

function openEmailWindow(id, what) {
	emailWindow = window.open("index.php?p=suggestEmail&what=" + what + "&id=" + id,
		"emailWindow",
		"left=0,top=0,width=500,height=350,menubar=no,toolbar=no,location=no,directories=no,personalbar=no,status=no,resizable=no,scrollbars=no");
    emailWindow.moveTo(parseInt((window.screen.width-500)/2),parseInt((window.screen.height-350)/2));
    emailWindow.focus();
}

function openPrintWindow(id, what) {
	printWindow = window.open("index.php?p=printVersion&what=" + what + "&id=" + id,
		"printWindow",
		"left=0,top=0,width=750,height=550,menubar=no,toolbar=no,location=no,directories=no,personalbar=no,status=no,resizable=no,scrollbars=yes");
    printWindow.moveTo(parseInt((window.screen.width-750)/2),parseInt((window.screen.height-550)/2));
    printWindow.focus();
}

function dateDropDown(parentObject, timestamp, name, firstyear) {
	// class variables
	var	months = new Array("január", "február", "március", "április", "május", "június", "július", "augusztus", "szeptember", "október", "november", "december");		
	var yearSelector;
	var monthSelector;
	var daySelector;
	var hcdd;

	// constructor (todo: constructor with prototype)
	var parentObject = parentObject;
	var timestamp = (timestamp.length == 0) ? new Date() : new Date(timestamp.substr(0,4), (timestamp.substr(4,2) - 1), timestamp.substr(6,2));
	var name = name;
	var firstyear = (firstyear.length == 0) ? new Date().getFullYear() : parseInt(firstyear);
		
	this.update = function() {
		var daysInMonth;
		switch ( parseInt(monthSelector.value) ) {
			case 1:
			case 3:
			case 5:
			case 7:
			case 8:
			case 10:
			case 12:
				daysInMonth = 31;
				break;
			case 2:
				daysInMonth = ((yearSelector.value % 4) == 0) ? 29 : 28; 
				break;
			default:
				daysInMonth = 30;
		}
		if ( daySelector.options.length != daysInMonth ) {
			var dayWas = daySelector.selectedIndex;
			if ( dayWas == -1 ) dayWas = timestamp.getDate() - 1; // first call
			daySelector.options.length = null;
			for ( var i = 1; i <= daysInMonth; i++ ) {
				daySelector.options[i-1] = new Option(i, (( i < 10 ) ? "0" + i : i));
				if ( dayWas == (i - 1) ) daySelector.options[i-1].selected = true;
			}
		}
	}
	
	this.updateHCDD = function() {
		hcdd.value = yearSelector.value + monthSelector.value + daySelector.value;
	}
	
	this.show = function() {
		var i = j = 0;
		// Years
		yearSelector = document.createElement('select');
		parentObject.appendChild(yearSelector);
		yearSelector.style.width = "55px";
		yearSelector.style.marginRight = "5px";
		for ( i = firstyear; i <= new Date().getFullYear(); i++ ) {
			yearSelector.options[j] = new Option(i, i);
			if ( timestamp.getFullYear() == i ) yearSelector.options[j].selected = true;
			j++;
		}
		
		// Months
		monthSelector = document.createElement('select');
		parentObject.appendChild(monthSelector);
		monthSelector.style.width = "95px";
		monthSelector.style.marginRight = "5px";
		j = 0;
		for ( i = 1; i <= 12; i++ ) {
			monthSelector.options[j] = new Option(months[i-1], (( i < 10) ? "0" + i : i));
			if ( (timestamp.getMonth()+1) == i ) monthSelector.options[j].selected = true;
			j++;
		}

		// Days
		daySelector = document.createElement('select');
		parentObject.appendChild(daySelector);
		daySelector.style.width = "auto";
	
		// Hook the event handlers (might parentObject onsubmit event could be use to sync. w/ the HCDD)
		if ( document.addEventListener ) { // Mozilla
			yearSelector.addEventListener("change", this.update, true);
			yearSelector.addEventListener("change", this.updateHCDD, true);
			monthSelector.addEventListener("change", this.update, true);
			monthSelector.addEventListener("change", this.updateHCDD, true);
			daySelector.addEventListener("change", this.updateHCDD, false);
		} else if ( document.attachEvent ) { // Internet Explorer
			yearSelector.attachEvent("onchange", this.update);
			yearSelector.attachEvent("onchange", this.updateHCDD);
			monthSelector.attachEvent("onchange", this.update);
			monthSelector.attachEvent("onchange", this.updateHCDD);
			daySelector.attachEvent("onchange", this.updateHCDD);
		}
		
		// Create the hidden form element
		hcdd = document.createElement('input');
		hcdd.setAttribute('type', 'hidden');
		hcdd.setAttribute('name', name);
		parentObject.appendChild(hcdd);
		
		this.update();
		this.updateHCDD();
	}
	
}

function showHide(objId) {
	var obj = document.getElementById(objId);
	if(obj) {
		obj.style.display = obj.style.display=='block' ? 'none' : 'block';
	}
}


