<!--
/*
	============================================================
	Basic fce
	============================================================
	Copyright: www.eastburger.cz (c) 2011 All rights reserved.
	============================================================
	Verze: 2.0.0
	------------------------------------------------------------
 	Spoluprace:
 		./js/lang-"idLang".js
	------------------------------------------------------------
*/


var cfgErrColor = 'red';

function ConfirmWindow(sMsg){
	if(sMsg == '') sMsg = lgCheckDeleteItem;
	else if(sMsg == 'del-items') sMsg = lgCheckDeleteItems;
	return confirm(sMsg);
}

function CreateLink(str3, str2, str1){
	atsign = '@';
	document.write('<a href="mailto:' + str1 + atsign + str2 + '.' + str3 + '">' + str1 + atsign + str2 + '.' + str3 + '</a>');
}

function GetLabelDesc(oLabel){
	sLabel = oLabel.firstChild.data;
	if(sLabel.substring(sLabel.length - 1, sLabel.length) == ':') sLabel = sLabel.substring(0, sLabel.length-1);	
	return sLabel;
}

function GetRadioValue(radioArray){
	var iLength = radioArray.length;
	if(iLength){  // vice hodnot
		var i;
		for(i = 0; i < iLength; i++){
			if(radioArray[i].checked == true) return radioArray[i].value;
		}
	}
	else{  // pouze jedna hodnota
		if(radioArray.checked == true) return radioArray.value;
	}
	return null;
}

function GoToPage(theElement, sUrl, sUrlEnd){
	window.location.href = sUrl+theElement.value+sUrlEnd;
}

function GoToUrl(sUrl){
	window.location.href = sUrl;
}

function CharCounter(theElement, maxLength, charInElement, charRemainElement){
	msgLength = theElement.value.length;
	if (msgLength > maxLength){
		theElement.value = theElement.value.substring(0,maxLength);
		msgLength = theElement.value.length;
	}
	else{
		document.getElementById(charInElement).value = msgLength;
		document.getElementById(charRemainElement).value = (maxLength - msgLength);
	}
} 

function CheckEmptyElement(idElement){
	var sMsg = '';
	var oLabel = document.getElementById('lb_' + idElement);
	var sLabel = '';

	if(Trim(document.getElementById(idElement).value) == ''){
		if(oLabel){
			sLabel = GetLabelDesc(oLabel);
			SetLabel(oLabel, 'err');
			sMsg = lgValidateEmptyElement + ': ' + sLabel + '.';
		}
		else sMsg = lgValidateEmptyElement + '.';
		return sMsg;
	}
	else{
		SetLabel(oLabel);
		return true;
	}
}

function CheckEmptyCheckbox(idElement){
	var sMsg = '';
	var oLabel = document.getElementById('lb_' + idElement);
	var sLabel = '';

	if(document.getElementById(idElement).checked == false){
		if(oLabel){
			sLabel = GetLabelDesc(oLabel);
			SetLabel(oLabel, 'err');
			sMsg = lgValidateEmptyElement + ': ' + sLabel + '.';
		}
		else sMsg = lgValidateEmptyElement + '.';
		return sMsg;
	}
	else{
		SetLabel(oLabel);
		return true;
	}
}

function CheckEmptyRadio(idForm, idElement){
	var sMsg = '';
	var sElementName = document.getElementById(idElement).name;
	var oLabel = document.getElementById('lb_' + sElementName);
	var sLabel = '';
	var radioValue = GetRadioValue(document.getElementById(idForm).elements[sElementName]);

	if(radioValue == null){
		if(oLabel){
			sLabel = GetLabelDesc(oLabel);
			SetLabel(oLabel, 'err');
			sMsg = lgValidateEmptyElement + ': ' + sLabel + '.';
		}
		else sMsg = lgValidateEmptyElement + '.';
		return sMsg;
	}
	else{
		SetLabel(oLabel);
		return true;
	}
}

function CheckFileImg(idElement){
	var sMsg = '';
	var oLabel = document.getElementById('lb_' + idElement);
	var sLabel = '';

	if(!document.getElementById(idElement)) return true;
	sValue = Trim(document.getElementById(idElement).value);
	if(sValue == '') return true;
	fileEnd = sValue.substr(StrrPos(sValue, '.'), sValue.length);

	if(fileEnd != '.jpg' && fileEnd != '.jpeg' && fileEnd != '.png' && fileEnd != '.gif'){
		if(oLabel){
			sLabel = GetLabelDesc(oLabel);
			SetLabel(oLabel, 'err');
			sMsg = lgValidateFileImg + ': ' + sLabel + lgValidateFileImg2;
		}
		else sMsg = lgValidateFileImg + lgValidateFileImg2;
		return sMsg;
	}
	else{
		SetLabel(oLabel);
		return true;
	}
}

function CheckFormat(idElement, sRegStr){
	var sMsg = '';
	var oLabel = document.getElementById('lb_' + idElement);
	var sLabel = '';
	var sValue = Trim(document.getElementById(idElement).value);
	var sRe  = sRegStr;

	if(sValue != ''){
		if(!RegExpTest(sValue,sRe)){
			if(oLabel){
				sLabel = GetLabelDesc(oLabel);
				SetLabel(oLabel, 'err');
				sMsg = lgValidateBadFormat + ': ' + sLabel + '.';
			}
			else sMsg = lgValidateBadFormat + '.';
			return sMsg;	
		}
		else{
			SetLabel(oLabel);
			return true;			
		}
	}
	else return true;
}

function NewWindow(theElement){
	var objWnd = window.open(theElement.href);
	objWnd.focus();
}

function RegExpTest(test,reg){
	return test.search(reg) == 0;
}

function StrrPos(haystack, needle, offset){
	var i = haystack.lastIndexOf(needle, offset); // returns -1
	return i >= 0 ? i : false;
}

function Trim(s){
	while(s.substring(0,1) == ' '){
		s = s.substring(1,s.length);
	}
	while(s.substring(s.length-1,s.length) == ' '){
		s = s.substring(0,s.length-1);
	}
	return s;
}

function SetLabel(oLabel, type){
	if(oLabel){
		if(type == 'err') oLabel.style.color = cfgErrColor;
		else oLabel.style.color = '';
	}
}

function SetTr(theElement, theAction){
	if(theAction == 'over'){
		if(theElement.className != 'tr-click') theElement.className = 'tr-over';
	}
	else if(theAction == 'out'){
		if(theElement.className != 'tr-click') theElement.className = '';
	}
	else if(theAction == 'click'){
		if(theElement.className == 'tr-click') theElement.className = '';
		else theElement.className = 'tr-click';
	}
}

function Validate(){  // libovolny pocet argumentu, prvni musi byt ID formulare
	var iArgumentsCount = arguments.length;  // pocet argumentu funkce
	var idForm = arguments[0];  // ID formulare
	var sMsgAlert = '';

	for(i = 1; i < iArgumentsCount; i++){
		idElement = arguments[i];
		//if(!document.getElementById(idElement)) continue;	// pokud prvek NEexistuje // ladicka
		if(document.getElementById(idElement).type == 'radio') tmp = CheckEmptyRadio(idForm, idElement);
		else if(document.getElementById(idElement).type == 'checkbox') tmp = CheckEmptyCheckbox(idElement);
		else tmp = CheckEmptyElement(idElement);
		if(tmp != true){
			if(sMsgAlert == '') document.getElementById(idElement).focus();
			sMsgAlert += tmp + '\n';
		}
	}

	if(sMsgAlert == '') return true;
	else{
		alert(lgValidate + '\n\n' + sMsgAlert);
		return false;
	}
}

//-->
