// check browser 
var ie = (document.all);
var ie4 = (document.all && !document.getElementById);
var ie5 = (document.all && document.getElementById);
var nn4 = (document.layers);
var nn6 = (document.getElementById && !ie);
var mz = (document.getElementById && !ie);
//alert('Navigator\nappName = '+navigator.appName+'\nappCodeName = '+navigator.appCodeName+'\nappVersion = '+navigator.appVersion+'\nuserAgent = '+navigator.userAgent);
var bVersion = parseInt(navigator.appVersion);


// **********************************************************************************
// ====================== UNIVERSAL FUNCTIONS ==================================
// **********************************************************************************

var $mainDivWidth = 1000; // ******* change main DIV width 

// ALL MEASURES OF SCREEN, WINDOW, FRAME etc. 
var frameWidth = 0;
var frameHeight = 0;
var $innerW = 0;
var $innerH = 0;
var screenWidth = 0;
var screenHeight = 0;
var $mainDivLeft = 0;
var $mainDivTop = 0;

function allMeasures() {
	if (mz) { // MZ... 
		frameWidth = window.innerWidth;
		frameHeight = window.innerHeight;
		$innerW = window.innerWidth;
		$innerH = window.innerHeight;
	} else if (self.innerWidth) { // all except IE = FireFox, MZ, NN... 
		frameWidth = self.innerWidth;
		frameHeight = self.innerHeight;
		$innerW = self.innerWidth;
		$innerH = self.innerHeight;
	} else if (document.documentElement && document.documentElement.offsetWidth) { // IE 6 
		frameWidth = document.documentElement.offsetWidth;
		frameHeight = document.documentElement.offsetHeight;
		$innerW = document.documentElement.offsetWidth;
		$innerH = document.documentElement.offsetHeight;
	} else if (document.body) { // other IE 
		frameWidth = document.body.clientWidth;
		frameHeight = document.body.clientHeight;
		$innerW = document.body.clientWidth;
		$innerH = document.body.clientHeight;
	}
	if (self.screen) {
		screenWidth = screen.width;
		screenHeight = screen.height;
	}
	$mainDivLeft = $innerW > $mainDivWidth ? Math.ceil(($innerW - $mainDivWidth) / 2) : 0;
	$mainDivTop = 0;
	//alert(screenWidth + ' * ' + screenHeight + ' | ' + frameWidth + ' * ' + frameHeight);
	//setStatusOuter();
}
window.onresize = allMeasures;
allMeasures();

function setStatValues()	{
	document.cookie = "cnt_monitor="+ screenWidth +"x"+ screenHeight;
	//document.cookie = "cnt_window="+ frameWidth +"x"+ frameHeight;
	//document.cookie = "cnt_color="+ (screen.pixelDepth ? screen.pixelDepth : screen.colorDepth);
}

// FOR TESTS... 
// show outer width and height in status 
function setStatusOuter() {
	$measuresMessage = '';
	//$measuresMessage += 'window outer width and height = ' + window.outerWidth + ' * ' + window.outerHeight;
	$measuresMessage += 'window inner width and height = ' + window.innerWidth + ' * ' + window.innerHeight;
	//$measuresMessage += ' :: screen width & height = ' + window.screen.availWidth + ' * ' + window.screen.availHeight;
	$measuresMessage += ' :: window from top and left = ' + window.screenY + ' * ' + window.screenX;
	$measuresMessage += ' :: main div from top and left = ' + $mainDivTop + ' * ' + $mainDivLeft;
	window.status = $measuresMessage;
	//alert($measuresMessage);
}

var $windowFromTop = window.screenY;
var $windowFromLeft = window.screenX;

// shortcut for "getElementById" (only for mz) 
function gid(what)	{
	if (document.getElementById(what)) return document.getElementById(what);
	else if (eval(what)) return eval(what);
	else return false;
}

// shortcut for "getElementById" or for ie4 or for nn4 
function elem(what)	{
	if(mz || ie5) {
		if (document.getElementById(what)) return document.getElementById(what);
		else if (eval(what)) return eval(what);
		else return false;
	}
	if(ie4) {
		if (document.all.what) return document.all.what;
		else if (eval(what)) return eval(what);
		else return false;
	}
	if(nn4) {
		if (document.layers[what]) return document.layers[what];
		else if (eval(what)) return eval(what);
		else return false;
	}
}

// **** POPUPS  **** //
// INIT 
document.onmousemove = getMouseXY;
if (nn4 || mz) document.captureEvents(Event.CLICK | Event.MOUSEMOVE)

var $axisX = 0;
var $axisY = 0;

function getMouseXY(e) {
	if (ie)	{
		$axisX = event.clientX + document.body.scrollLeft;
		$axisY = event.clientY + document.body.scrollTop;
	} else {
		$axisX = e.pageX;
		$axisY = e.pageY;
	}  
	if ($axisX < 0) { axisX = 0; }
	if ($axisY < 0) { axisY = 0; }
	//window.status = 'mouse x * y = ' + axisX + ' * ' + axisY;
	return $axisX;
	return $axisY;
}

/*
// FOR TEST MOUSE X & Y 
var mX = 0;
var mY = 0;
//if (!ie) document.captureEvents(Event.MOUSEMOVE);
function mouseXY(e) {
	if (ie) { // if browser is IE 
		mX = event.clientX + document.body.scrollLeft;
		mY = event.clientY + document.body.scrollTop;
	} else {  // if browser is other as IE 
		mX = e.pageX;
		mY = e.pageY;
	}
	if (mX < 0) { mX = 0; }
	if (mY < 0) { mY = 0; }
	window.status = 'mouse x * y = ' + mX + ' * ' + mY;
	return true;
}
// show mouse coordinate in status 
//document.onmousemove = mouseXY;
*/
/* // ORIG
function show(str)	{
	if (ie5 || nn6) {
		document.getElementById(str).style.left = axisX;
		document.getElementById(str).style.top = axisY;
	}
	if (ie4) {
		document.all.str.style.left = axisX;
		document.all.str.style.top = axisY;
	}
	if (nn4) {
		document.layers[str].style.left = axisX;
		document.layers[str].style.top = axisY;
	}
	if (ie5 || nn6)	{	document.getElementById(str).style.display = "block";	}
	if (ie4)	{	document.all.str.style.display = "block";	}
	if (nn4)	{	document.layers[str].style.display = "block";	}
}
*/

// NEW DX 
// elementId, slide in x, slide in y, abs. pos. elem. from left, abs. pos. elem. from top, elem. width, elem.height 
function show($elemId, $x, $y, $absX, $absY, $elemW, $elemH) {
	if (mz) {
		// coord of mouse x|y + abs. pos. elem. from left|top + slide x|y + element W|H + 15 scroll 
		if($axisX + $x + $elemW + 25 > $innerW) {
			$totalX = $axisX - $absX - $x - $elemW;
		} else {
			$totalX = $axisX - $absX + $x;
		}
		elem($elemId).style.left = $totalX;
		if($axisY + $y + $elemH + 25 > $innerH) {
			$totalY = $axisY - $absY + $y - $elemH;
			//elem($str).style.bottom = $totalY;
			elem($elemId).style.top = $totalY;
		} else {
			$totalY = $axisY - $absY + $y;
			elem($elemId).style.top = $totalY;
		}
		elem($elemId).style.display = "block";
		// status bar 
		/*
		window.status = ''
			+ 'outer W|H = ' + $outerW + '|' + $outerH 
			+ ' :: inner W|H = ' + $innerW + '|' + $innerH 
			+ ' :: $axisX + $x = ' + $axisX + ' + ' + $x + ' = ' + ($axisX + $x) + ' :: $axisY + $y = ' + $axisY + ' + ' + $y + ' = ' + ($axisY + $y) 
			+ ' :: element W|H = ' + $elemW + '|' + $elemH
			+ ' :: $axisX - $absX + $x + $elemW = ' + ($axisX - $absX + $x + $elemW);
			*/
	}
}

// SHOW on CLIENT WEB 
function showNoOrderMessage($elemId)	{
	elem($elemId).style.left = '86px';
	elem($elemId).style.top = '30px';
	elem($elemId).style.display = "block";
}
function showChangeTerminMessage($elemId, $x, $y, $elemW, $elemH)	{
	$totalX = $axisX - $mainDivLeft;
	$totalY = $axisY - $mainDivTop;
	//alert('total X|Y = ' +$totalX + '|' +$totalY); // TEST 
	// coord of mouse x|y + abs. pos. elem. from left|top + slide x|y + element W|H + 20 scroll 
	if($axisX + $x + $elemW + 20 > $innerW - 20) {
		$totalX = $totalX - ($x +20 + $elemW);
	} else {
		$totalX = $totalX + $x + 20;
	}
	if($axisY + $y + $elemH + 20 > $innerH - 20) {
		$totalY = $totalY - ($y + 20 + $elemH);
	} else {
		$totalY = $totalY + $y;
	}
	elem($elemId).style.left = $totalX;
	elem($elemId).style.top = $totalY;
	elem($elemId).style.display = "block";
	$testMessage = ''
		+ ' :: inner W|H = ' + $innerW + '|' + $innerH 
		+ ' :: $axisX + $x = ' + $axisX + ' + ' + $x + ' = ' + ($axisX + $x) + ' :: $axisY + $y = ' + $axisY + ' + ' + $y + ' = ' + ($axisY + $y) 
		+ ' :: element W|H = ' + $elemW + '|' + $elemH
		+ ' :: total X|Y = ' + $totalX + '|' + $totalY;
	//window.status = $testMessage;
	//alert($testMessage); // TEST 
}

function hide($elemId)	{
	elem($elemId).style.display = "none";
}
// **** end POPUPS  **** //

// ADMIN - sections / rubrics 
function switchRows(trid,last) {
	var dsp,ael = document.getElementById("tr"+trid);	
	if(navigator.appName == "Microsoft Internet Explorer") dsp="block"; else dsp="block";
	if (ael.style.display != "none") {
		ael.style.display = "none";
		document.getElementById("img"+trid).src="../img/ik_tree_p"+last+".gif";
	} else {
		ael.style.display = dsp;
		document.getElementById("img"+trid).src = "../img/ik_tree_m"+last+".gif";
	}
}
function switch_disp(trid, last) {
	var dsp,ael = document.getElementById("tr"+trid);	
	if(navigator.appName == "Microsoft Internet Explorer") dsp="block"; else dsp="table-row";
	if (ael.style.display != "none") {
		ael.style.display = "none";
		document.getElementById("img"+trid).src = "../img/ik_tree_p"+last+".gif";
	} else {
		ael.style.display = dsp;
		document.getElementById("img"+trid).src = "../img/ik_tree_m"+last+".gif";
	}
}

// function that escapes a string  ******************************************************** FCE encode URI ******
function encode(uri) {
	if (encodeURIComponent) {
		return encodeURIComponent(uri);
	}
	if (escape) {
		return escape(uri);
	}
}

// CLOSE POPUP WINDOW 
function closeWin()	{
	window.close();
}

// PRINT WINDOW 
function printWin()	{
	window.print();
}

// FUNCTION NOT ACTIVE 
function functionNotActive() {
	alert(LNG_WE_ARE_SORRY + "\n" + LNG_THIS_FUNCTION_IS_NOT_AVAILABLE_AT_THIS_TIME);
}
// NO USER RIGHTS 
function noRights() {
	alert(LNG_WE_ARE_SORRY + "\n" + LNG_USER_RIGHTS_DISALOW_THIS_ACTION + "\n" + LNG_CONTACT_ADMINISTRATOR);
}

// COLOR BUTTON BackGround 
function colorButtonBg($id) { document.getElementById($id).style.background = '#FF3'; }
function colorOutButtonBg($id, $bgColor) { if($bgColor) document.getElementById($id).style.background = $bgColor; else  document.getElementById($id).style.background = '#FFF'; }


// SPRINTF = like at PHP, just limited to max. 5 parts 
function sprintf($string, $part0, $part1, $part2, $part3, $part4) {
	$splitedString = $string.split("%s"); // array 
	$returnedText = $splitedString[0];
	for($i=0; $i<$splitedString.length; $i++) {
		if($i==1) { $returnedText += $part0 + $splitedString[$i]; }
		if($i==2) { $returnedText += $part1 + $splitedString[$i]; }
		if($i==3) { $returnedText += $part2 + $splitedString[$i]; }
		if($i==4) { $returnedText += $part3 + $splitedString[$i]; }
		if($i==5) { $returnedText += $part4 + $splitedString[$i]; }
	}
	return $returnedText;
}

// COUNT CHARACTER in form, fieldId, maxLength   
function countChar($inputId, $maxLimit) {
	$alertText = sprintf(LNG_FIELD_CAN_CONTAIN_MAX_X_CHARACTER, $maxLimit);
	$fieldToCount = document.getElementById($inputId);
	if($fieldToCount.tagName == 'TEXTAREA') {
		//$fieldValue = $fieldToCount.firstChild.nodeValue;
		$fieldValue = $fieldToCount.value;
	} else {
		$fieldValue = $fieldToCount.value;
	}
	//alert($inputId +' * '+ $maxLimit +' * '+ $fieldToCount.tagName +' * '+ $fieldValue);
	if ($fieldValue.length > $maxLimit) {
		window.alert($alertText);
		$fieldToCount.value = $fieldValue.substring(0, $maxLimit);
	}
}


// check DATE (Year=YYYY, Month=MM, Day=DD, Year From, Year To) 
function checkDate($YYYY, $MM, $DD, $yearFrom, $yearTo) {
	//alert($YYYY+' '+$MM+' '+$DD);
	if(!$yearFrom) $yearFrom = 1900;
	if(!$yearTo) $yearTo = 2100;
	var $al = '';
	
	if ($DD && (!/^[0-9]{1,2}$/.test($DD))) { $al += sprintf(LNG_IN_FIELD_ONLY_NUMBERS, "'"+LNG_DAY+"'") +"\n"; }
	if ($MM && (!/^[0-9]{1,2}$/.test($MM))) { $al += sprintf(LNG_IN_FIELD_ONLY_NUMBERS, "'"+LNG_MONTH+"'") +"\n"; }
	if ($YYYY && (!/^[0-9]{1,4}$/.test($YYYY))) { $al += sprintf(LNG_IN_FIELD_ONLY_NUMBERS, "'"+LNG_YEAR+"'") +"\n"; }
	
	if ($DD < 1) { $al += sprintf(LNG_FILL_UP_X, "'"+LNG_DAY+"'") +"\n"; }
	if (!($MM>=1 && $MM <= 12)) {
		$al += LNG_FILL_MONTH_BETWEEN +"\n"; }
	if (!($YYYY >= $yearFrom && $YYYY <= $yearTo)) {
		$al += sprintf(LNG_FILL_YEAR_BETWEEN, $yearFrom, $yearTo) +"\n"; }
	if ($YYYY%4 != 0 && $MM == 2 && $DD > 28) {
		$al += LNG_FEBRUARY_28_DAYS +"\n"; }
	if ($YYYY%4 == 0 && $MM == 2 && $DD > 29) {
		$al += LNG_FEBRUARY_29_DAYS +"\n"; }
	if (($MM == 1 || $MM == 3 || $MM == 5 || $MM == 7 || $MM == 8 || $MM == 10 || $MM == 12) && ($DD > 31)) {	// in months = 1,3,5,7,8,10,12 = 31 days
		$al += LNG_MONTH_MAX_31_DAYS +"\n"; }
	if (($MM == 4 || $MM == 6 || $MM == 9 || $MM == 11) && ($DD > 30)) {	// in months = 4,6,9,11 = 30 days
		$al += LNG_MONTH_MAX_30_DAYS +"\n"; }
	
	return $al;
}

// check TIME (Hour=HH, Minute=ii, Second=ss) 
function checkTime($HH, $ii, $ss) {
	//alert($HH+' '+$ii+' '+$ss);
	var $al = '';
	
	if ($HH && (!/^[0-9]{1,2}$/.test($HH))) { $al += sprintf(LNG_IN_FIELD_ONLY_NUMBERS, "'"+LNG_HOURS+"'") +"\n"; }
	if ($ii && (!/^[0-9]{1,2}$/.test($ii))) { $al += sprintf(LNG_IN_FIELD_ONLY_NUMBERS, "'"+LNG_MINUTES+"'") +"\n"; }
	if ($ss && (!/^[0-9]{1,2}$/.test($ss))) { $al += sprintf(LNG_IN_FIELD_ONLY_NUMBERS, "'"+LNG_SECONDS+"'") +"\n"; }
	
	if (!(parseInt($HH) >= 0 && parseInt($HH) <= 23)) {
		$al += LNG_FILL_HOURS_BETWEEN +"\n"; }
	if (!(parseInt($ii) >= 0 && parseInt($ii) <= 59)) {
		$al += LNG_FILL_MINUTES_BETWEEN +"\n"; }
	if (!(parseInt($ss) >= 0 && parseInt($ss) <= 59)) {
		$al += LNG_FILL_SECONDS_BETWEEN +"\n"; }
	
	return $al;
}


// check ALL DATES form like EU with dots "28.05.2006" or "28.05.06", EU without dots "28052006" or "280506" and SQL "2006-05-28" 
function checkAllDates($date, $type) {
	
	var $yearTwoDigits = 29;  // yeras with 2 digits => 1930 - 2029 
	
	//alert($date+' '+$type);
	if($type == 'value') { $value = $date; }
	if($type == 'input') { $value = document.getElementById($date).value; }
	if($type == 'tag') { $value = document.getElementById($date).firstChild.nodeValue; }

	if (/^[0-9]{1,2}\.[0-9]{1,2}\.[0-9]{4}$/.test($value)) {
		// for EU date with dots like "28.5.2006" 
		var $array = $value.split(".");
		var $DD = $array[0];
		var $MM = $array[1];
		var $YYYY = $array[2];
		
	} else if (/^[0-9]{1,2}\.[0-9]{1,2}\.[0-9]{2}$/.test($value)) {
		// for EU date with dots like "28.5.06" 
		var $array = $value.split(".");
		var $DD = $array[0];
		var $MM = $array[1];
		var $YY = $array[2];
		if($YY <= $yearTwoDigits) $YYYY = '20'+$YY; else $YYYY = '19'+$YY;
		
	} else if (/^[0-9]{4}-[0-9]{1,2}-[0-9]{1,2}$/.test($value)) {
		// for date from "2006-5-28" 
		var $array = $value.split("-");
		var $DD = $array[2];
		var $MM = $array[1];
		var $YYYY = $array[0];
		
	} else if (/^[0-9]{8}$/.test($value)) {
		// for EU date without dots like "28052006" 
		var $DD = $value.substring(0,2);
		var $MM = $value.substring(2,4);
		var $YYYY = $value.substring(4,8);
		
	} else if (/^[0-9]{6}$/.test($value)) {
		// for EU date without dots like "280506" 
		var $DD = $value.substring(0,2);
		var $MM = $value.substring(2,4);
		var $YY = $value.substring(4,6);
		if($YY <= $yearTwoDigits) $YYYY = '20'+$YY; else $YYYY = '19'+$YY;
	}
	//alert($DD+' * '+$MM+' * '+$YYYY+' * '+$value);
	
	return checkDate($YYYY, $MM, $DD);
}

// check DATE SQL FORM "2006-05-28" 
function checkDateSql($date, $type) {
	//alert($date+' '+$type);
	if($type == 'value') { $value = $date; }
	if($type == 'input') { $value = document.getElementById($date).value; }
	if($type == 'tag') { $value = document.getElementById($date).firstChild.nodeValue; }
	//alert($value);
	
	var $DD = $value.substring(8, 10);
	var $MM = $value.substring(5, 7);
	var $YYYY = $value.substring(0, 4);
	//alert($DD+' * '+$MM+' * '+$YYYY);
	
	return checkDate($YYYY, $MM, $DD);
}

// check DATE EU FORM "28.05.2006" or "28.05.06" 
function checkDateEuWithDots($date, $type, $length) {
	//alert($date+' '+$type);
	if($type == 'value') { $value = $date; }
	if($type == 'input') { $value = document.getElementById($date).value; }
	if($type == 'tag') { $value = document.getElementById($date).firstChild.nodeValue; }
	//alert($value);
	
	var $DD = $value.substring(0, 2);
	var $MM = $value.substring(3, 5);
	if(!$length || $length=='long') {
		var $YYYY = $value.substring(6, 10);	// for 4-position year 
	} else if($length=='short') {
		var $YY = $value.substring(6, 8);	// for 2-position year 
		if($YY <= 29) $YYYY = '20'+$YY; else $YYYY = '19'+$YY; // yeras with 2 digits => 1930 - 2029 
	}
	//alert($DD+' * '+$MM+' * '+$YYYY);
	
	return checkDate($YYYY, $MM, $DD);
}

// check DATE EU FORM "28052006" or "280506" 
function checkDateEuWithoutDots($date, $type, $length) {
	//alert($date+' '+$type);
	if($type == 'value') { $value = $date; }
	if($type == 'input') { $value = document.getElementById($date).value; }
	if($type == 'tag') { $value = document.getElementById($date).firstChild.nodeValue; }
	//alert($value);
	
	var $DD = $value.substring(0, 2);
	var $MM = $value.substring(2, 4);
	if(!$length || $length=='long') {
		var $YYYY = $value.substring(4, 8);	// for 4-position year 
	} else if($length=='short') {
		var $YY = $value.substring(4, 6);	// for 2-position year 
		if($YY <= 29) $YYYY = '20'+$YY; else $YYYY = '19'+$YY; // yeras with 2 digits => 1930 - 2029 
	}
	//alert($DD+' * '+$MM+' * '+$YYYY);
	
	return checkDate($YYYY, $MM, $DD);
}

// from '27052007' returns '27.05.2007' 
function changeBlankDateToEuDate($value) {
	if($value && $value != '00000000' && $value.length == 8) {
		var $DD = $value.substring(0,2);
		var $MM = $value.substring(2,4);
		var $YY = $value.substring(4,8);	// (4,6) for 2-position year (4,8) for 4-position year 
		return $DD+'.'+$MM+'.'+$YY;
	} else { return ''; }
}

// from '2007-05-27' returns '27.05.2007' 
function changeSqlDateToEuDate($value) {
	if($value && $value != '0000-00-00' && $value.length == 10) {
		var $DD = $value.substring(8,10);
		var $MM = $value.substring(5,7);
		var $YY = $value.substring(0,4);
		return $DD+'.'+$MM+'.'+$YY;
	} else { return ''; }
}

// from '2007-05-27' returns '27052007' 
function changeSqlDateToBlankDate($value) {
	if($value && $value != '0000-00-00' && $value.length == 10) {
		var $DD = $value.substring(8,10);
		var $MM = $value.substring(5,7);
		var $YY = $value.substring(0,4);
		return $DD+'.'+$MM+'.'+$YY;
	} else { return ''; }
}

// from '27052007' returns '2007-05-27' 
function changeBlankDateToSqlDate($value) {
	if($value && $value != '00000000' && $value.length == 8) {
		var $DD = $value.substring(0,2);
		var $MM = $value.substring(2,4);
		var $YY = $value.substring(4,8);	// (4,6) for 2-position year (4,8) for 4-position year 
		return $DD+'.'+$MM+'.'+$YY;
	} else { return ''; }
}

// from date '27.05.2007' returns year '2007' 
function changeEuDateToYear($value) {
	if($value && $value.length == 10) {
		var $YY = $value.substring(6,10);
		return $YY;
	} else { return ''; }
}

// fieldId1 = date '27.05.2007' change fieldId2 to year '2007' 
function setEuDateToYear($fieldId1, $fieldId2) {
	document.getElementById($fieldId2).value = changeCzDateToYear(document.getElementById($fieldId1).value);
	document.getElementById($fieldId2).focus();
	document.getElementById($fieldId2).select();
}

// return Year or nothing 
function returnYear($fieldId) {
	if($fieldId && $fieldId != '0000' && /^[0-9]+$/.test($fieldId) && $fieldId >= 1900 && $fieldId <= 2100) {
		return $fieldId;
	} else { return ''; }
}

// TIME - from '1245' returns '12:45:00' 
function changeBlankTimeWoSecondsToSqlTime($value) {
	if($value && $value != '0000' && $value.length == 4) {
		var $HH = $value.substring(0,2);
		var $ii = $value.substring(2,4);
		return $HH+':'+$ii+':00';
	} else { return ''; }
}

// TIME - from '1245' returns '12:45' 
function changeBlankTimeWoSecondsToTimeWoSeconds($value) {
	if($value && $value != '0000' && $value.length == 4) {
		var $HH = $value.substring(0,2);
		var $ii = $value.substring(2,4);
		return $HH+':'+$ii;
	} else { return ''; }
}

// TIME - from SQL '12:45:00' returns '12:45' 
function changeSqlTimeToTimeWoSeconds($value) {
	if($value && $value != '00:00:00' && $value.length == 8) {
		return $value.substring(0,5);
	} else { return ''; }
}

// CHECK TIME FORM '1245' 
function checkBlankTimeWoSeconds($time, $type) {
	//alert($time+' '+$type);
	if($type == 'value') { $value = $time; }
	if($type == 'input') { $value = document.getElementById($time).value; }
	if($type == 'tag') { $value = document.getElementById($time).firstChild.nodeValue; }
	//alert($value);
	
	var $HH = $value.substring(0, 2);
	var $ii = $value.substring(2, 4);
	var $ss = '00';
	//alert($HH+' * '+$ii+' * '+$ss);
	
	return checkTime($HH, $ii, $ss);
}


// **********************************************************************************
// ====================== PROJECT SPEC. FUNCTIONS ===============================
// **********************************************************************************


// CONFIRM user changes  
var $confirm = false; // global variable -> set confirm 

// POPUP WINDOWS STAY ALL THE TIME IN FRONT 
// break refresh window on top -> show alert -> restore window on top 
var $popupOn = false; // global variable -> set confirm 

function myAlert($what) {
	if($popupOn == true) { stayBack(); }
	window.alert($what);
	if($popupOn == true) { stayOnTop(); }
}

var $stayTop = false;
var $timer = '';
// Brings the current window on top of others 
function stayOnTop() {
	$timer = window.setTimeout("stayOnTop()", 200);
	$stayTop = true;
	window.focus();
}

// Cancel bringing the current window on top of others 
function stayBack() {
	if($stayTop) {
		window.clearTimeout($timer);
		$stayTop = false;
	}
}


// STONE COLOR popUp 
var $stoneColorWindow = null; // global variable
var $stoneColorTimer = ''; // global variable
function popStoneColor($url, $target) {
	if($stoneColorWindow == null || $stoneColorWindow.closed) {
		if($popupOn == true) { stayBack(); }
		$stoneColorWindow = window.open($url, $target, 'left='+ ($windowFromLeft+50) +',top='+ ($windowFromTop+50) +',width=600,height=400,toolbar=no,location=no,directories=no,status=no,menubar=no,resizable=yes,scrollbars=yes');
		//$stoneColorTimer = window.setTimeout('popStoneColor("'+$url+'", "'+$target+'", "'+$popupOn+'");', 200);
	} else {
    $stoneColorWindow.focus();
		if($popupOn == true) { stayBack(); }
		//$stoneColorTimer = window.setTimeout('popStoneColor("'+$url+'", "'+$target+'", "'+$popupOn+'");', 200);
	}
}

// PARAMETERS popUp (color sleeves, nailfiles etc.)
var $parametersWindow = null; // global variable
var $parametersTimer = ''; // global variable
function popParameters($url, $target, $value, $id) {
	if($parametersWindow == null || $parametersWindow.closed) {
		if($popupOn == true) { stayBack(); }
		$parametersWindow = window.open($url + $value + '&fieldId='+$id, $target, 'left='+ ($windowFromLeft+50) +',top='+ ($windowFromTop+50) +',width=620,height=600,toolbar=no,location=no,directories=no,status=no,menubar=no,resizable=yes,scrollbars=yes');
		//$parametersTimer = window.setTimeout('popParameters("'+$url+'", "'+$target+'", "'+$popupOn+'");', 200);
	} else {
    $parametersWindow.focus();
		if($popupOn == true) { stayBack(); }
		//$parametersTimer = window.setTimeout('popParameters("'+$url+'", "'+$target+'", "'+$popupOn+'");', 200);
	}
}

// PASSWORD popUp 
var $passwordWindow = null; // global variable
var $passwordTimer = ''; // global variable
function popPassword($url, $target) {
	if($passwordWindow == null || $passwordWindow.closed) {
		if($popupOn == true) { stayBack(); }
		$passwordWindow = window.open($url, $target, 'left='+ ($windowFromLeft+200) +',top='+ ($windowFromTop+200) +',width=460,height=200,toolbar=no,location=no,directories=no,status=no,menubar=no,resizable=yes,scrollbars=no');
		//$passwordTimer = window.setTimeout('popPassword("'+$url+'", "'+$target+'", "'+$popupOn+'");', 200);
	} else {
    $passwordWindow.focus();
		if($popupOn == true) { stayBack(); }
		//$passwordTimer = window.setTimeout('popPassword("'+$url+'", "'+$target+'", "'+$popupOn+'");', 200);
	}
}

// RECOMMEND popUp 
var $recommendWindow = null; // global variable
var $recommendTimer = ''; // global variable
function popRecommend($url, $target) {
	if($recommendWindow == null || $recommendWindow.closed) {
		if($popupOn == true) { stayBack(); }
		$recommendWindow = window.open($url, $target, 'left='+ ($windowFromLeft+200) +',top='+ ($windowFromTop+200) +',width=500,height=440,toolbar=no,location=no,directories=no,status=no,menubar=no,resizable=yes,scrollbars=no');
		//$recommendTimer = window.setTimeout('popRecommend("'+$url+'", "'+$target+'", "'+$popupOn+'");', 200);
	} else {
    $recommendWindow.focus();
		if($popupOn == true) { stayBack(); }
		//$recommendTimer = window.setTimeout('popRecommend("'+$url+'", "'+$target+'", "'+$popupOn+'");', 200);
	}
}

// SEND WISH popUp 
var $sendWishWindow = null; // global variable
var $sendWishTimer = ''; // global variable
function popSendWish($url, $target) {
	if($sendWishWindow == null || $sendWishWindow.closed) {
		if($popupOn == true) { stayBack(); }
		$sendWishWindow = window.open($url, $target, 'left='+ ($windowFromLeft+200) +',top='+ ($windowFromTop+200) +',width=500,height=460,toolbar=no,location=no,directories=no,status=no,menubar=no,resizable=yes,scrollbars=no');
		//$sendWishTimer = window.setTimeout('popSendWish("'+$url+'", "'+$target+'", "'+$popupOn+'");', 200);
	} else {
    $sendWishWindow.focus();
		if($popupOn == true) { stayBack(); }
		//$sendWishTimer = window.setTimeout('popSendWish("'+$url+'", "'+$target+'", "'+$popupOn+'");', 200);
	}
}

// ADMIN ORDER popUp 
var $adminOrderWindow = null; // global variable
var $adminOrderTimer = ''; // global variable
function popAdminOrder($url, $target) {
	if($adminOrderWindow == null || $adminOrderWindow.closed) {
		if($popupOn == true) { stayBack(); }
		$adminOrderWindow = window.open($url, $target, 'left='+ ($windowFromLeft+100) +',top='+ ($windowFromTop+100) +',width=800,height=700,toolbar=no,location=no,directories=no,status=no,menubar=no,resizable=yes,scrollbars=no');
		//$adminOrderTimer = window.setTimeout('popAdminOrder("'+$url+'", "'+$target+'", "'+$popupOn+'");', 200);
	} else {
    $adminOrderWindow.focus();
		if($popupOn == true) { stayBack(); }
		//$adminOrderTimer = window.setTimeout('popAdminOrder("'+$url+'", "'+$target+'", "'+$popupOn+'");', 200);
	}
}

// ADMIN ORDER -> ADD PRODUCT popUp 
var $adminOrderAddProductWindow = null; // global variable
var $adminOrderAddProductTimer = ''; // global variable
function popAdminOrderAddProduct($url, $target) {
	if($adminOrderAddProductWindow == null || $adminOrderAddProductWindow.closed) {
		if($popupOn == true) { stayBack(); }
		$adminOrderAddProductWindow = window.open($url, $target, 'left='+ ($windowFromLeft+100) +',top='+ ($windowFromTop+100) +',width=850,height=720,toolbar=no,location=no,directories=no,status=yes,menubar=no,resizable=yes,scrollbars=yes');
		//$adminOrderAddProductTimer = window.setTimeout('popAdminOrderAddProduct("'+$url+'", "'+$target+'", "'+$popupOn+'");', 200);
	} else {
    $adminOrderAddProductWindow.focus();
		if($popupOn == true) { stayBack(); }
		//$adminOrderAddProductTimer = window.setTimeout('popAdminOrderAddProduct("'+$url+'", "'+$target+'", "'+$popupOn+'");', 200);
	}
}

// CONTACT popUp 
var $contactWindow = null; // global variable
function popContact($url, $target) {
	if($contactWindow == null || $contactWindow.closed) {
	  $contactWindow = window.open($url, $target, 'left='+ ($windowFromLeft+50) +',top='+ ($windowFromTop+50) +',width=660,height=520,toolbar=no,location=no,directories=no,status=no,menubar=no,resizable=no,scrollbars=no');
	} else {
		$contactWindow.focus();
	}
}
// CONTACT from Movie 
var $fieldContactName = '';
var $fieldContactId = '';
function popContactfromMovie($url, $target, $form, $field, $id) {
	//document.getElementById('showAjax').innerHTML += 'fce(popContact) -> url * target * form * field * id = ' + $url +' * '+ $target +' * '+ $form +' * '+ $field +' * '+ $id + '<br>'; // TEST 
	if($contactWindow == null || $contactWindow.closed) {
	  $contactWindow = window.open($url, $target, 'left='+ ($windowFromLeft+50) +',top='+ ($windowFromTop+50) +',width=660,height=520,toolbar=no,location=no,directories=no,status=no,menubar=no,resizable=no,scrollbars=no');
	} else {
		$contactWindow.focus();
	}
	//$fieldContactName = eval("document." + $form + "." + $field);
	//$fieldContactId = eval("document." + $form + "." + $id);
	$fieldContactName = eval("document.getElementById('" + $field + "')");
	$fieldContactId = eval("document.getElementById('" + $id + "')");
	//document.getElementById('showAjax').innerHTML += 'fce(popContact) -> $fieldContactName.value = ' + $fieldContactName.value + '<br>'; // TEST 
}

// SELECTION popUp 
var $selectWindow = null; // global variable
var $selectTimer = ''; // global variable
function popSelect($url, $target, $popupOn) {
	if($selectWindow == null || $selectWindow.closed) {
		if($popupOn == true) { stayBack(); }
		$selectWindow = window.open($url, $target, 'left='+ $windowFromLeft +',top='+ ($windowFromTop+50) +',width=1020,height=650,toolbar=no,location=no,directories=no,status=no,menubar=no,resizable=no,scrollbars=yes');
		//$selectTimer = window.setTimeout('popSelect("'+$url+'", "'+$target+'", "'+$popupOn+'");', 200);
	} else {
    $selectWindow.focus();
		if($popupOn == true) { stayBack(); }
		//$selectTimer = window.setTimeout('popSelect("'+$url+'", "'+$target+'", "'+$popupOn+'");', 200);
	}
}

// PRINT popUp 
var $printWindow = null; // global variable 
var $printTimer = ''; // global variable
function popPrint($url, $target, $popupOn) {
	if($printWindow == null || $printWindow.closed) {
		if($popupOn == true) { stayBack(); }
		$printWindow = window.open($url, $target, 'left='+ ($windowFromLeft+50) +',top='+ ($windowFromTop+50) +',width=870,height=650,toolbar=no,location=no,directories=no,status=no,menubar=no,resizable=no,scrollbars=yes');
		//$printTimer = window.setTimeout('popPrint("'+$url+'", "'+$target+'", "'+$popupOn+'");', 200);
	} else {
    $printWindow.focus();
		if($popupOn == true) { stayBack(); }
		//$printTimer = window.setTimeout('popPrint("'+$url+'", "'+$target+'", "'+$popupOn+'");', 200);
	}
}

// PICTURES modul popUp 
var $picWindow = null; // global variable
function popPictures($url, $target, $popupOn) {
	if($picWindow == null || $picWindow.closed) {
		if($popupOn == true) { stayBack(); }
		$picWindow = window.open($url, $target, 'left='+ ($windowFromLeft+50) +',top='+ ($windowFromTop+50) +',width=1000,height=750,toolbar=no,location=no,directories=no,status=yes,menubar=no,resizable=no,scrollbars=yes');
	} else {
    $picWindow.focus();
		if($popupOn == true) { stayBack(); }
	}
}

// PICTURE ORIGINAL SIZE popUp 
var $picOrigWindow = null; // global variable
var $picOrigTimer = ''; // global variable
function popOrigPicture($url, $target, $popupOn) {
	if($picOrigWindow == null || $picOrigWindow.closed) {
		if($popupOn == true) { stayBack(); }
		$picOrigWindow = window.open($url, $target, 'left='+ $windowFromLeft +',top='+ $windowFromTop +',toolbar=yes,location=yes,directories=yes,status=yes,menubar=yes,resizable=yes,scrollbars=yes');
		//$picOrigTimer = window.setTimeout('popOrigPicture("'+$url+'", "'+$target+'", "'+$popupOn+'");', 200);
	} else {
    $picOrigWindow.focus();
		if($popupOn == true) { stayBack(); }
		//$picOrigTimer = window.setTimeout('popOrigPicture("'+$url+'", "'+$target+'", "'+$popupOn+'");', 200);
	}
}

// PICTURE MIDDLE SIZE popUp 
var $picMiddleWindow = null; // global variable $popupPicture 
function popMiddlePicture($url, $target, $features, $popupOn) {
	//alert($url+' :: '+$target+' :: '+$features+' :: '+$popupOn);
	if($picMiddleWindow == null || $picMiddleWindow.closed) {
		if($popupOn == true) { stayBack(); }
		$picMiddleWindow = window.open($url, $target, $features);
	} else {
    $picMiddleWindow.focus();
		if($popupOn == true) { stayBack(); }
	}
}

// MOVIE popUp 
var $movieWindow = null; // global variable
var $movieTimer = ''; // global variable
function popMovie($url, $target, $popupOn) {
	if($movieWindow == null || $movieWindow.closed) {
		if($popupOn == true) { stayBack(); }
		$movieWindow = window.open($url, $target, 'left='+ $windowFromLeft +',top='+ ($windowFromTop+30) +',width=1020,height=670,toolbar=no,location=no,directories=no,status=no,menubar=no,resizable=no,scrollbars=yes');
		//$movieTimer = window.setTimeout('popMovie("'+$url+'", "'+$target+'", "'+$popupOn+'");', 200);
	} else {
    $movieWindow.focus();
		if($popupOn == true) { stayBack(); }
		//$movieTimer = window.setTimeout('popMovie("'+$url+'", "'+$target+'", "'+$popupOn+'");', 200);
	}
}

// PRICE popUp 
function popPrice($url, $target) {
  window.open($url, $target, 'left='+ ($windowFromLeft+100) +',top='+ ($windowFromTop+150) +',width=300,height=400,toolbar=no,location=no,directories=no,status=no,menubar=no,resizable=no,scrollbars=yes');
}
var $popupPrice = null; // global variable $popupPrice 
function popPriceFirst($url, $target) {
	if($popupPrice == null || $popupPrice.closed) {
		$popupPrice = window.open($url, $target, 'left='+ ($windowFromLeft+100) +',top='+ ($windowFromTop+150) +',width=290,height=400,toolbar=no,location=no,directories=no,status=no,menubar=no,resizable=no,scrollbars=yes');
		//window.setTimeout('popPrice("'+$url+'", "'+$target+'");', 100);
	} else {
    $popupPrice.focus();
		//window.setTimeout('popPrice("'+$url+'", "'+$target+'");', 100);
	}
}


// function onKeyPress event (Ctrl + Num) - for global keyboard shortcuts 
function keyboardCtrlEvent(e, $file) {
	//alert("Key Pressed: " + String.fromCharCode(e.charCode) + "\n" + "charCode: " + e.charCode + "\n" + "CTRL key pressed: " + e.ctrlKey + "\n");
	//document.getElementById('showAjax').innerHTML += 'CTRL + keypress code = ' + String.fromCharCode(e.charCode) + '<br>'; // for TEST 
	if(e.ctrlKey == true && e.charCode == 48) { // Ctrl + 0 
	} else if(e.ctrlKey == true && e.charCode == 49) { // Ctrl + 1 !!! window - used by SeaMonkey !!!
	} else if(e.ctrlKey == true && e.charCode == 50) { // Ctrl + 2
		var $url = 'search.php';
		location.replace($url);
	} else if(e.ctrlKey == true && e.charCode == 51) { // Ctrl + 3 
		if($file == 'search.php') { return checkSearch(); }
	} else if(e.ctrlKey == true && e.charCode == 52) { // Ctrl + 4  !!! editor - used by SeaMonkey !!!
	} else if(e.ctrlKey == true && e.charCode == 53) { // Ctrl + 5 
	} else if(e.ctrlKey == true && e.charCode == 54) { // Ctrl + 6 
	} else if(e.ctrlKey == true && e.charCode == 55) { // Ctrl + 7 
	} else if(e.ctrlKey == true && e.charCode == 56) { // Ctrl + 8 
	} else if(e.ctrlKey == true && e.charCode == 57) { // Ctrl + 9 
	}
}

// function onKeyPress event (Ctrl + Alt + F) - for global keyboard shortcuts 
function keyboardCtrlAltEvent(e, $file) {
	//alert("Key Pressed: " + String.fromCharCode(e.charCode) + "\n" + "charCode: " + e.charCode + "\n" + "CTRL key pressed: " + e.ctrlKey + "\n" + "ALT key pressed: " + e.altKey + "\n");
	//document.getElementById('showAjax').innerHTML += 'CTRL + ALT + keypress code = ' + String.fromCharCode(e.charCode) + '<br>'; // for TEST 
	//document.getElementById('showAjax').innerHTML += 'CTRL + ALT + keypress code = ' + e.keyCode + '<br>'; // for TEST 
	if(e.ctrlKey == true && e.altKey == true && e.keyCode == 112) { // Ctrl + Alt + F1 
		if($file == 'index.php' || $file == 'search.php' || $file == 'selects.php' || $file == 'movies.php' || $file == 'movies_list.php' || $file == 'adm_users.php') {
			var $url = 'search.php';
			location.replace($url);
		} else if($file == 'movie.php') {
			var $url = 'search.php';
			window.opener.location.replace($url);
			window.close();
		}
	} else if(e.ctrlKey == true && e.altKey == true && e.keyCode == 113) { // Ctrl + Alt + F2 == SEARCH 
		if($file == 'search.php') { return checkSearch(); }
	} else if(e.ctrlKey == true && e.altKey == true && e.keyCode == 114) { // Ctrl + Alt + F3 == NEW MOVIE 
		if($file == 'index.php' || $file == 'search.php' || $file == 'selects.php' || $file == 'movies.php' || $file == 'movies_list.php' || $file == 'adm_users.php') {
			var $url = 'movie.php?page=1&orderBy=mov_id&sort=asc&movie=new';
			popMovie($url, 'movie');
		}
	} else if(e.ctrlKey == true && e.altKey == true && e.keyCode == 115) { // Ctrl + Alt + F4 
	} else if(e.ctrlKey == true && e.altKey == true && e.keyCode == 116) { // Ctrl + Alt + F5 
	} else if(e.ctrlKey == true && e.altKey == true && e.keyCode == 117) { // Ctrl + Alt + F6 
	} else if(e.ctrlKey == true && e.altKey == true && e.keyCode == 118) { // Ctrl + Alt + F7 
	} else if(e.ctrlKey == true && e.altKey == true && e.keyCode == 119) { // Ctrl + Alt + F8 
	} else if(e.ctrlKey == true && e.altKey == true && e.keyCode == 120) { // Ctrl + Alt + F9 
	} else if(e.ctrlKey == true && e.altKey == true && e.keyCode == 121) { // Ctrl + Alt + F10 == SAVE INTO THE SELECTION 
		if($file == 'movies.php' || $file == 'movie.php' || $file == 'movies_list.php') {
			return saveIntoSelection();
		}
	} else if(e.ctrlKey == true && e.altKey == true && e.keyCode == 122) { // Ctrl + Alt + F11 
		if($file == 'movies.php' || $file == 'movie.php' || $file == 'movies_list.php') {
			return saveAllIntoSelection();
		}
	} else if(e.ctrlKey == true && e.altKey == true && e.keyCode == 123) { // Ctrl + Alt + F12 
	}
}

// is Number ?? 
function isNum($str) {
	if (/^[0-9]+$/.test($str)) return true; else return false;
}

// if the number is smaller than 10, add in front of it "0"	[+ parameter how should be display zero "0" (e.g. "00")]
function toTen($str, $oo) {
	if ($str==0) { return $oo; }
	else if ($str>0 && $str<10) { return '0' + $str; }
	else { return $str; }
}

// SUBSTRING2 (from, length) 
function substring2($string, $start, $length) {
	if($string != '') {
		return $string.substring($start, $start + $length);
	} else { return ''; }
}

// from '12345678' returns '12.345.678' 
function makePrice($value) {
	if($value) {
		$length = $value.length;
		$parts = Math.ceil($length / 3);
		$rest = $length % 3 == 0 ? 3 : $length % 3;
		//alert($length +'*'+ $parts +'*'+ $rest);
		$array = new Array();
		for($i=0; $i<$parts; $i++) {
			
			if($i == 0) {
				$array[0] = substring2($value, 0, $rest);
			} else {
				$array[$i] = substring2($value, $rest + ($i-1) * 3, 3);
			}
		}
		return $array.join(".");
	} else { return ''; }
}

// split and replace part of string or url  
function splitUrl($string, $p1, $p2, $replace) {
	if(parseInt($string.indexOf('?')) == -1) $join = '?'; else $join = '&';
	$pos1 = parseInt($string.indexOf($p1));
	$pos2 = parseInt($string.indexOf($p2, ($pos1+1)));
	//alert($pos1 + ' * ' + $pos2);
	//alert($pos1 + ' * ' + parseInt($pos1) + ' * ' + ($pos1+1) + ' * ' + $pos2);
	if($pos1==-1) {
		if($replace=='') {
			$url = $string;
		} else {
			$url = $string + $join + $replace;
		}
	} else if($pos1 && $pos2==-1) {
		if($replace=='') {
			$url = $string.substring(0, ($pos1-1)) + $replace;
		} else {
			$url = $string.substring(0, $pos1) + $replace;
		}
	} else {
		if($replace=='') {
			$url = $string.substring(0, ($pos1-1)) + $replace + $string.substring($pos2);
		} else {
			$url = $string.substring(0, $pos1) + $replace + $string.substring($pos2);
		}
	}
	//alert($url);
	return $url;
}


// **********************************************************************************
// ==================== AJAX UNIVERSAL FUNCTIONS ================================
// **********************************************************************************

// for AJAX - onFocus - clear input value to edit 
function clearField($fieldId, $type) {
	$inputSelect = document.getElementById('inputSelect').value;
	//document.getElementById('showAjax').innerHTML += '$inputSelect (fce clearField) = ' + $inputSelect + '<br>'; // TEST
	if($inputSelect=='') {
		if($type=='select') {
		} else {
			var $input = document.getElementById($fieldId);
			var $value = $input.value;
			if($type == 'date' || $type == 'price') {
				$array = $value.split(".");
				$input.value = $array.join("");
			}
			$input.select();
		}
	} else {
		document.getElementById($inputSelect).focus(); // return to $fieldId 
		document.getElementById($inputSelect).select();
		document.getElementById('inputSelect').value = ''; // clear inputSelect value 
	}
}

// **********************************************************************************
// ==================== CZECH SPECIFIC CFUNCTIONS ================================
// **********************************************************************************

// BIRTHNUMBER TO BIRTHDATE  
function rcToBirthdate(idFrom, idDay, idMonth, idYear, idSex) {
	var rc = document.getElementById(idFrom).value;
	if(rc!='' && rc.length>=6) {
		dd = rc.substring(4,6);
		mm = rc.substring(2,4);
		yy = rc.substring(0,2);
		if(document.getElementById(idSex).checked==true) mm = mm-50;
		if(yy >= 0 && yy <= 10) yy = '20'+yy; else yy = '19'+yy;
		//alert(dd+mm+yy);
		document.getElementById(idDay).value = dd;
		document.getElementById(idMonth).value = mm;
		document.getElementById(idYear).value = yy;
	}
}

