//-------------------------------------------------------------------------------------------------------------------
// systemove funkce - ruzne funkce zajistujici javascriptovou obsluhu stranek
//-------------------------------------------------------------------------------------------------------------------

function wnd_open(img_url, target, wnd_param) {
	if (wnd_param > '') wnd_param = ", " + wnd_param;
	var new_wnd = window.open(img_url, target, "resizable=yes, toolbar=no, menubar=no, scrollbars=yes, status=yes" + wnd_param);
}

function mov_qm(id) {
	var obj = document.getElementById(id);
	obj.style.visibility = "visible";
	obj.style.display = "inline";
	obj.style.zindex = 1;
}

function mou_qm(id) {
	var obj = document.getElementById(id);
	obj.style.visibility = "hidden";
	obj.style.display = "none";
	obj.style.zindex = -1;
}

//funkce na dynamicke efekty polozek menu pro najeti/odjeti mysi
var prev_mit_bg = "";

function mov(obj, ObjBgColor) {
	//barva pozadi menupolozky
	prev_mit_bg = obj.style.backgroundColor;
	
	if (ObjBgColor) {
		obj.style.backgroundColor = ObjBgColor;
	} else {
		obj.style.backgroundColor = '#FFE680';
	}
	//obj.style.borderColor = '#FFE680';
	
	//barva textu menupolozky
	var atxt = obj.firstChild;
	//atxt.style.color = "#FFFFFF";
	
	//var bullet_obj = obj.firstChild;
	//bullet_obj.style.width = 0;
}

function mou(obj, ObjBgColor) {
	//barva pozadi menupolozky
	//obj.style.backgroundColor = prev_mit_bg;
	if (ObjBgColor) {
		obj.style.backgroundColor = ObjBgColor;
	} else {
		obj.style.backgroundColor = prev_mit_bg;
	}
	//obj.style.borderColor = prev_mit_bg;
	prev_mit_bg = "transparent";
	
	//barva textu menupolozky
	var atxt = obj.firstChild;
	//atxt.style.color="#000000";
	
	//var bullet_obj = obj.firstChild;
	//bullet_obj.style.width = 0;
}


//funkce na zabarvovani radku v tabulkach
var prev_bg = "";

function trmov(obj) {
	prev_bg = obj.style.backgroundColor;
	obj.style.backgroundColor = "#E1E8FF";
}

function trmou(obj) {
	obj.style.backgroundColor = prev_bg;
	prev_bg = "transparent";
}

//nevim... asi obrazky prezentace nacitane do pameti
var itmp = new Image();
itmp.src = "img/mi_bg_repeat.png";

//open new image window
function img_wnd_open( imw_object , imw_descriptionArg , imw_widthArg , imw_heightArg ) {
	if (imw_object.src) {
		imw_imgUrl = imw_object.src;
	} else {
		imw_imgUrl = imw_object.href;
	}
	imw_images = imw_object.getElementsByTagName( 'img' );
	
	if (imw_descriptionArg != undefined && /[a-zA-Z]{2,}/.test(imw_descriptionArg)) {
		//alert(imw_descriptionArg);
		imw_description = imw_descriptionArg;
	} else {
		imw_description = imw_images[0].alt;
	}
	
	imw_imageFull = new Image();
	imw_imageFull.src = imw_imgUrl;
	
	imw_fullWidth = (( imw_imageFull.width > 0 ) ? imw_imageFull.width : 550);
	imw_fullHeight = (( imw_imageFull.height > 0 ) ? imw_imageFull.height : 550);
	
	if (/[0-9]{2,}/.test(imw_widthArg)) {
		imw_width = imw_widthArg;
	} else {
		imw_width = imw_fullWidth + 100;
	}
	if (/[0-9]{2,}/.test(imw_heightArg)) {
		imw_height = imw_heightArg;
	} else {
		imw_height = imw_fullHeight + 150;
	}
	
	if( imw_width > ( screen.width * 0.8 ) ) { imw_width = screen.width * 0.8; }
	if( imw_height > ( screen.height * 0.8 ) ) { imw_height = screen.height * 0.8; }
	
	var imw_url_param = 'img_url='+ imw_imgUrl +'&img_descr='+ imw_description +' ';
	
	if (imw_object.src) {
		var imw_window_url = imw_object.src.replace("/normal/", "/preview_image.php?"+imw_url_param);
	} else {
		var imw_window_url = imw_object.href.replace("/normal/", "/preview_image.php?"+imw_url_param);
	}
	imw_window_url = imw_window_url.replace(/[a-zA-Z0-9\-\_\%\*]{1,}[\.][a-zA-Z0-9\-\_\%\*]{1,}$/, "");
	
	window.open(imw_window_url, 'imgwnd', 'scrollbars=yes, menubar=no, toolbar=no, resizable=yes, status=no, width='+imw_width+', height='+imw_height);
	
	return false;
}

//funkce vraci obj Date z datetime (mysql) v parametru
function datetime_to_jsdate(datetime) {
	//nacteni mysql datetime ( yyyy-mm-dd hh:mm:ss )
	var datetime_arr = datetime.replace( /[ :]/g , '-' );
	//rozdeleni do pole a do jednotlivych promennych
	datetime_arr = datetime_arr.split( "-" );

	var y = datetime_arr[0];
	var m = datetime_arr[1] - 1; //!!! Date bere mesice od 0 !!!
	var d = datetime_arr[2];
	var h = datetime_arr[3];
	var i = datetime_arr[4];
	var s = datetime_arr[5];

	//inicializace objektu Date
	var js_date = new Date( y , m , d , h , i , s );

	return( js_date );
}
//funkce vraci datetime (mysql) z obj Date v parametru
function jsdate_to_datetime(js_date) {
	var tmp_new_date = js_date;
	var dttm_string = '';
	
	dttm_string += tmp_new_date.getFullYear();
	dttm_string += '-';
	dttm_string += ( ( (tmp_new_date.getMonth() + 1) < 10) ? "0" + (tmp_new_date.getMonth() + 1) : (tmp_new_date.getMonth() + 1) );
	dttm_string += '-';
	dttm_string += ( (tmp_new_date.getDate() < 10) ? "0"+tmp_new_date.getDate() : tmp_new_date.getDate() );
	dttm_string += ' ';
	
	dttm_string += ( (tmp_new_date.getHours() < 10) ? "0"+tmp_new_date.getHours() : tmp_new_date.getHours() );
	dttm_string += ':';
	dttm_string += ( (tmp_new_date.getMinutes() < 10) ? "0"+tmp_new_date.getMinutes() : tmp_new_date.getMinutes() );
	dttm_string += ':';
	dttm_string += ( (tmp_new_date.getSeconds() < 10) ? "0"+tmp_new_date.getSeconds() : tmp_new_date.getSeconds() );
	

	return( dttm_string );
}

