var timer = 0;

function auto_logout() {
	if (!logout_need) return;
	if (timer != 0) clearTimeout (timer);
	timer = setTimeout ("document.location.href='" + logout_url + "';", 10 * 60 * 1000);
} // auto_logout()

function details (ean) {
	document.getElementById ('grey_content').style.width = "710px";
	document.getElementById ('grey_content').style.height = "510px";
	document.getElementById ('grey_details').style.width = "710px";
	document.getElementById ('grey_details').style.height = "460px";
	document.getElementById ('grey_details').src = "/search_detail.php?EAN=" + ean;
	blankoutsize();
	document.getElementById ('grey').style.display = "block";
	document.getElementById ('grey_content').style.display = "block";
	auto_logout();
} // open_details()

function close_details() {
	document.getElementById ('grey_content').style.display = "none";
	document.getElementById ('grey').style.display = "none";
	auto_logout();
} // close_details()

function auto_close_details (sec) {
	setTimeout ('close_details()', sec * 1000);
} // close_details()

function complain_comment (id) {
	document.getElementById ('grey_content').style.width = "660px";
	document.getElementById ('grey_content').style.height = "510px";
	document.getElementById ('grey_details').style.width = "660px";
	document.getElementById ('grey_details').style.height = "460px";
	document.getElementById ('grey_details').src = "/manage/complain_comment.php?id=" + id;
	blankoutsize();
	document.getElementById ('grey').style.display = "block";
	document.getElementById ('grey_content').style.display = "block";
	auto_logout();
} // complain_comment()

function entry_text (id) {
	document.getElementById ('grey_content').style.width = "660px";
	document.getElementById ('grey_content').style.height = "510px";
	document.getElementById ('grey_details').style.width = "660px";
	document.getElementById ('grey_details').style.height = "460px";
	document.getElementById ('grey_details').src = "/manage/pay_card_disable_text.php?id=" + id;
	blankoutsize();
	document.getElementById ('grey').style.display = "block";
	document.getElementById ('grey_content').style.display = "block";
	auto_logout();
} // entry_text()

function logout_warning() {
	document.getElementById ('grey_content').style.width = "460px";
	document.getElementById ('grey_content').style.height = "220px";
	document.getElementById ('grey_details').style.width = "460px";
	document.getElementById ('grey_details').style.height = "170px";
	document.getElementById ('grey_details').src = "/logout_warning.html";
	blankoutsize();
	document.getElementById ('grey').style.display = "block";
	document.getElementById ('grey_content').style.display = "block";
} // logout_warning()

function get_full_size() {
	if (window.innerHeight)
		return [window.innerWidth - 0, window.innerHeight - 0, window.pageXOffset, window.pageYOffset];
	else if (document.documentElement.clientHeight)
		return [document.documentElement.clientWidth - 0, document.documentElement.clientHeight - 0, document.documentElement.scrollLeft, document.documentElement.scrollTop];

	return [document.body.clientWidth, document.body.clientHeight, document.body.scrollLeft, document.body.scrollTop];
}

function blankoutsize() {
	if (document.getElementById ('grey') != null) {
		var winDimen = get_full_size();

		document.getElementById ('grey').style.width = winDimen[0] + "px";
		document.getElementById ('grey').style.height = winDimen[1] + "px";
		document.getElementById ('grey_content').style.left = parseInt ((winDimen[0] / 2) - 330) + "px";
		document.getElementById ('grey_content').style.top = parseInt ((winDimen[1] / 2) - 230) + "px";
		new_width = winDimen[0] - 205;
		if (new_width < 0) new_width = 0;
		new_height = winDimen[1] - 173;
		if (new_height < 0) new_height = 0;
		document.getElementById ('desktop_frame').style.width = new_width + "px";
		document.getElementById ('desktop_frame').style.height = new_height + "px";
	}

	check_site_height();
}

/* this makes the resize script fire on page-loading */
if (document.attachEvent) {
	window.attachEvent ("onload", function (e) {
		blankoutsize();
	});
}
else if (document.addEventListener) {
	window.addEventListener ("load", function (e) {
		blankoutsize();
	},false);
}
else {
	window.onload = function (e) {
		bankoutsize();
	};
}

/* this makes the resize script fire on resizing the page */
if (document.attachEvent) {
	window.attachEvent ("onresize", function (e) {
		blankoutsize();
	});
}
else if (document.addEventListener) {
	window.addEventListener ("resize", function (e) {
		blankoutsize();
	},false);
}
else {
	window.onresize = function (e) {
		bankoutsize();
	};
}

function check_site_height() {
	if (document.getElementById ('left_menus') == null) return;
	var window_size = get_full_size();
	var dmenu_height = window_size[1] - 192 - 54; // Teljes magasság - logó - lábléc

	if (dmenu_height < 331) {
		if (dmenu_height < 0) dmenu_height = 0;
		document.getElementById ('left_menus').className = "left_menus_notebook";
		document.getElementById ('left_menus').style.height = dmenu_height + "px";
	}
	else {
		document.getElementById ('left_menus').style.height = "";
		document.getElementById ('left_menus').className = "left_menus_normal";
		document.getElementById ('left_menus').scrollTop = 0;
	}
} // check_site_height()

/*** AJAX ***/

var post_target = "";
var http_request = false;

function alert_contents() {
	if (http_request.readyState == 4) {
		if (http_request.status == 200) {
			result = http_request.responseText;
			document.getElementById (post_target).innerHTML = result;
		}
	}
} // alert_contents()

function get_book (get_type, ean) {
	var poststr = "ean=" + escape (ean) + "&submit_" + get_type + "=1";

	http_request = false;
	post_target = 'user_data_frame';

	if (window.XMLHttpRequest) { // Mozilla, Safari, stb
		http_request = new XMLHttpRequest();
		if (http_request.overrideMimeType)
			http_request.overrideMimeType ('text/html');
	}
	else if (window.ActiveXObject) { // IE
		try {
			http_request = new ActiveXObject ("Msxml2.XMLHTTP");
		}
		catch (e) {
			try {
				http_request = new ActiveXObject ("Microsoft.XMLHTTP");
			}
			catch (e){}
		}
	}
	if (!http_request) {
		//alert ('A kérés elküldése nem sikerült!');
		return false;
	}

	http_request.onreadystatechange = alert_contents;
	http_request.open ('POST', '/user_data_frame.php', true);
	http_request.setRequestHeader ("Content-type", "application/x-www-form-urlencoded");
	http_request.setRequestHeader ("Content-length", poststr.length);
	http_request.setRequestHeader ("Connection", "close");
	http_request.send (poststr);
} // ajax_player()

function start_user_scroll (first) {
	el = document.getElementById ('user_data_scroll');

	if (first > 0)
		pos_x = -500;
	else
		pos_x = parseInt (el.style.left) - 5;

	if (pos_x < -400) {
		fs = get_full_size();
		pos_x = fs[0] + 20;
	}

	//el.innerHTML = parseInt (el.style.left);
	el.style.left = pos_x + "px";
	setTimeout ('start_user_scroll (0)', 66);
}

function show_help_video (id) {
	switch (id) {
		case 1: default: var url = "http://www.youtube.com/v/TA6JmzwFElg&amp;hl=hu_HU&amp;fs=1?color1=0x234900&amp;color2=0x4e9e00"; break;
		case 2: var url = "http://www.youtube.com/v/TA6JmzwFElg&amp;hl=hu_HU&amp;fs=1?color1=0x234900&amp;color2=0x4e9e00"; break;
		case 3: var url = "http://www.youtube.com/v/TA6JmzwFElg&amp;hl=hu_HU&amp;fs=1?color1=0x234900&amp;color2=0x4e9e00"; break;
		case 4: var url = "http://www.youtube.com/v/TA6JmzwFElg&amp;hl=hu_HU&amp;fs=1?color1=0x234900&amp;color2=0x4e9e00"; break;
		case 5: var url = "http://www.youtube.com/v/TA6JmzwFElg&amp;hl=hu_HU&amp;fs=1?color1=0x234900&amp;color2=0x4e9e00"; break;
		case 6: var url = "http://www.youtube.com/v/TA6JmzwFElg&amp;hl=hu_HU&amp;fs=1?color1=0x234900&amp;color2=0x4e9e00"; break;
		case 7: var url = "http://www.youtube.com/v/TA6JmzwFElg&amp;hl=hu_HU&amp;fs=1?color1=0x234900&amp;color2=0x4e9e00"; break;
		case 8: var url = "http://www.youtube.com/v/TA6JmzwFElg&amp;hl=hu_HU&amp;fs=1?color1=0x234900&amp;color2=0x4e9e00"; break;
		case 9: var url = "http://www.youtube.com/v/TA6JmzwFElg&amp;hl=hu_HU&amp;fs=1?color1=0x234900&amp;color2=0x4e9e00"; break;
	}

	document.getElementById ('help_video').innerHTML = "<object width=\"400\" height=\"250\"><param name=\"movie\" value=\"" + url + "\"></param><param name=\"allowFullScreen\" value=\"true\"></param><param name=\"allowscriptaccess\" value=\"always\"></param><embed src=\"" + url + "\" type=\"application/x-shockwave-flash\" allowscriptaccess=\"always\" allowfullscreen=\"true\" width=\"400\" height=\"250\"></embed></object>";
}

$(function() {
	$.datepicker.setDefaults ({
		dateFormat: 'yy/mm/dd',
		firstDay: 1,
		dayNamesMin: ['V', 'H', 'K', 'Sze', 'Cs', 'P', 'Szo'],
		dayNamesShort: ['Vas', 'Hé', 'Kedd', 'Sze', 'Csü', 'Pé', 'Szo'],
		dayNames: ['Vasárnap', 'Hétfő', 'Kedd', 'Szerda', 'Csütörtök', 'Péntek', 'Szombat'],
		monthNames: ['Január', 'Február', 'Március', 'Április', 'Május', 'Június', 'Július', 'Augusztus', 'Szeptember', 'Október', 'November', 'December'],
		monthNamesShort: ['Jan', 'Feb', 'Már', 'Ápr', 'Máj', 'Jún', 'Júl', 'Aug', 'Szep', 'Okt', 'Nov', 'Dec'],
		weekHeader: "Hét",
		prevText: "Előző",
		nextText: "Következő"
	});
});
