
/*interaktivni mapa*/
var previewWidth;

$(document).ready(function() {
    previewWidth = parseInt($('#preview').css('width'));
    $('#preview').append('<div id="previewArea" style="position:absolute;display:none;"></div>');

    $('#map1 area').mouseover(function(e) {
        var index = $(this).attr('rel');
        if (!isNaN(index))
            $('#preview').css('background-position', (-index * previewWidth) + 'px 0');
    });

    $('#map1 area').mouseout(function(e) {
        $('#preview').css('background-position', '0 0');
        $('#previewArea').css('display', 'none');
    });

    $('#map1 area').mousemove(function(e) {
        $('#previewArea').css('left', (e.pageX - 30) + 'px');
        $('#previewArea').css('top', (e.pageY + 25) + 'px');
        $('#previewArea').text(this.className.substr(0, 1).toUpperCase() + this.className.substr(1));
        $('#previewArea').show();
    });
});

//field.value = field.value.substr(0, 1).toUpperCase() + field.value.substr(1);

// 19.6.2004 Radek Prochazka - zmena jazyka pres Listbox
function processLanguage(tf){
		tf.submit();
}

// 22.6.2003 Jan Pokorny
function check_all_checkboxes(strForm, strPrefix, bOn)
{
	var arrChk, i;
	arrChk = eval('self.document.'+strForm).elements;
	for (i = 0; i < arrChk.length; i++)
	{
		if(arrChk[i].name.substr(0, strPrefix.length) == strPrefix) arrChk[i].checked = bOn;
	}
};

// 9.6.2009 Vojta Bartos
function checkMe(tf,pars)
{
	pole=pars.split(',');
	for(i=0;i<pole.length;i+=2)
	{
		if(eval('typeof  tf.'+pole[i])!='undefined'){
		    
		    if(eval('tf.'+pole[i]+'.type')=='checkbox')
			{
			    
			    if (eval('tf.'+pole[i]+'.checked')=='')
			    {
			        alert(pole[(i+1)]+' je povinná položka.');
			        eval('tf.'+pole[i]+'.focus()');
			        return false;			
			    }
			} else {
			    if(eval('tf.'+pole[i]+'.value')=='')
			    {
				    alert(pole[(i+1)]+' je povinná položka.');
				    eval('tf.'+pole[i]+'.focus()');
				    return false;
			    }
			}
			
		}
	}
	return true;
}

// 18.6.2004 Lukas Nemec
function checkEmail(tf,pars)
{
	var strEmail
	pole=pars.split(',');
	for(i=0;i<pole.length;i+=2)
	{
		strEmail = eval('tf.'+pole[i]+'.value')
		if(strEmail=='')
		{
			alert(pole[(i+1)]+' je povinná položka.');
			return (false);
		}

		if(strEmail.length != 0)
		{
			sta = 0
			for (i = 0; i < strEmail.length; i++)
			{
				if (strEmail.substring(i, i+1) == '.'  && sta == 1)
				{
					sta++;
				}
				if (strEmail.substring(i, i+1) == '@')
				{
					sta++;
				}
			}
		}
		if (sta != 2)
		{
	    	alert('Prosim zadejte správně email.');
	    	return (false);
		}
	}
	return true;
}




// 18.6.2004 Lukas Nemec
// Declaring valid date character, minimum year and maximum year
var dtCh= ".";
var minYear=1900;
var maxYear=2100;

function isInteger(s){
	var i;
    for (i = 0; i < s.length; i++){
        // Check that current character is number.
        var c = s.charAt(i);
        if (((c < "0") || (c > "9"))) return false;
    }
    // All characters are numbers.
    return true;
}

// 18.6.2004 Lukas Nemec
function stripCharsInBag(s, bag){
	var i;
    var returnString = "";
    // Search through string's characters one by one.
    // If character is not in bag, append to returnString.
    for (i = 0; i < s.length; i++){
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }
    return returnString;
}

// 18.6.2004 Lukas Nemec
function daysInFebruary (year){
	// February has 29 days in any year evenly divisible by four,
    // EXCEPT for centurial years which are not also divisible by 400.
    return (((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0))) ? 29 : 28 );
}
// 18.6.2004 Lukas Nemec
function DaysArray(n) {
	for (var i = 1; i <= n; i++) {
		this[i] = 31
		if (i==4 || i==6 || i==9 || i==11) {this[i] = 30}
		if (i==2) {this[i] = 29}
   }
   return this
}
// 18.6.2004 Lukas Nemec
function isDate(dtStr){
	var daysInMonth = DaysArray(12)
	var pos1=dtStr.indexOf(dtCh)
	var pos2=dtStr.indexOf(dtCh,pos1+1)
	var strDay=dtStr.substring(0,pos1)
	var strMonth=dtStr.substring(pos1+1,pos2)
	var strYear=dtStr.substring(pos2+1)
	strYr=strYear
	if (strDay.charAt(0)=="0" && strDay.length>1) strDay=strDay.substring(1)
	if (strMonth.charAt(0)=="0" && strMonth.length>1) strMonth=strMonth.substring(1)
	for (var i = 1; i <= 3; i++) {
		if (strYr.charAt(0)=="0" && strYr.length>1) strYr=strYr.substring(1)
	}
	day=parseInt(strDay)
	month=parseInt(strMonth)
	year=parseInt(strYr)
	if (pos1==-1 || pos2==-1){
		alert("Formát datumu musí byt v teto formě : dd.mm.rrrr")
		return false
	}
	if (strDay.length<1 || day<1 || day>31 || (month==2 && day>daysInFebruary(year)) || day > daysInMonth[month]){
		alert("Prosím zadejte platný den")
		return false
	}
	if (strMonth.length<1 || month<1 || month>12){
		alert("Prosím zadejte platný měsíc")
		return false
	}

	if (strYear.length != 4 || year==0 || year<minYear || year>maxYear){
		alert("Prosím zadejte správný 4 místný rok, mezi léty "+minYear+" a "+maxYear)
		return false
	}
	if (dtStr.indexOf(dtCh,pos2+1)!=-1 || isInteger(stripCharsInBag(dtStr, dtCh))==false){
		alert("Prosím vložte správné datum (cele)")
		return false
	}
return true
}
// 18.6.2004 Lukas Nemec
function checkDate(tf,pars)
{
	pole=pars.split(',');
	for(i=0;i<pole.length;i+=2)
	{
		if (isDate(eval('tf.'+pole[i]+'.value'))==false){
			eval('tf.'+pole[i]+'.focus()');
			return false;
		}
	}
	return true;
}

// 17.2.2003 Jan Pokorny
function OpenPicture(filename, title, width, height)
{
	wi = Math.floor(Math.random() * 1000) + 1000
	ImageWindow = window.open('', wi.toString(), 'status=no,width='+width.toString()+',height='+height.toString()+',resizable=no,menubar=no,scrollbars=no,toolbar=no')
	ImageWindow.document.write('<html><head><title>'+title+'</title></head><body leftmargin=0 topmargin=0 marginwidth=0 marginheight=0>')
	ImageWindow.document.write('<img src="'+filename+'" width='+width.toString()+' height='+height.toString()+'><br>')
	ImageWindow.document.write('</body></html>')
}

// 16.1.2003 Jan Pokorny
function file_show(strFile)
{
	var wndShow;
	wi = Math.floor(Math.random() * 1000) + 1000
	wndShow = window.open(strFile, wi.toString(), 'left=410,top=210,width=350,height=450,toolbar=no,location=no,status=yes,menubar=no,scrollbars=yes,resizable=yes');
	wndShow.focus();
}
// 27.5.2002 - Vojtech Braun
function open_file_select(strField,figID)
{
	var wndFileSel;
	wi = Math.floor(Math.random() * 1000) + 1000
	wndFileSel = window.open('../fileman/list.asp?viewSend=1&viewSendWhat=file&viewSendValue='+strField+'&fig_id='+figID, wi.toString(), 'left=100,top=100,height=500,width=900,status=yes,resizable=yes,toolbar=no,menubar=no,location=no,scrollbars=yes');
	wndFileSel.focus();
}

// 09.07.2002 - Vojtech Braun
function file_clear(strFormName, strFieldName)
{
	document.forms[strFormName].elements[strFieldName+'_id'].value = '';
	document.forms[strFormName].elements[strFieldName+'_name'].value = '';
	document.forms[strFormName].elements[strFieldName+'_file'].value = '';
}

//--------------------------------------------------------------------------------------
// 18.12.2003 - Jan Pokorny
// Smaze input v zadanem formulari a policku
//--------------------------------------------------------------------------------------
function input_clear(strFormName, strFieldName)
{
	document.forms[strFormName].elements[strFieldName].value = '';
}
//--------------------------------------------------------------------------------------
// 18.12.2003 - Jan Pokorny
// Otevre dokument v nvem okne (pouziva file_show)
//--------------------------------------------------------------------------------------
function document_show(docID,path){
	if(docID!='') file_show(path+docID);
}

//--------------------------------------------------------------------------------------
// 18.12.2003 - Jan Pokorny
// Otevre v novem okne formular pro zadani dokumentu
//--------------------------------------------------------------------------------------
function open_document_select(script,strField,docID,itmName,itmFrom,itmTo)
{
	var wndFileSel;
	wndFileSel = window.open('../document/'+script+'&doIt=insert&field='+strField+'&id='+docID+'&docName='+itmName+'&docFrom='+itmFrom+'&docTo='+itmTo, 'wndFileSel', 'left=100,top=100,height=400,width=850,status=yes,resizable=yes,toolbar=no,menubar=no,location=no,scrollbars=yes');
	wndFileSel.focus();
}

//--------------------------------------------------------------------------------------
// 6.1.2004 - Krystof Nemec
// Otevre v novem okne formular pro zadani odkazu
//--------------------------------------------------------------------------------------
function open_link_select(script, sourceThemaID, strFieldThema, strFieldItem, themaID, itmID)
{
	var wndFileSel;
	wndFileSel = window.open(script+'?doIt=insert&temID='+sourceThemaID+'&id='+themaID+'&itmID='+itmID +'&fieldthema='+strFieldThema +'&fielditem='+strFieldItem, 'wndLinkSel', 'left=100,top=100,height=400,width=700,status=yes,resizable=yes,toolbar=no,menubar=no,location=no,scrollbars=yes');
	wndFileSel.focus();
}

function Validate(theForm, arr)
{
    for(var i = 0; i < theForm.length; i++)
    {
        if(arr[i])
        {
            if(!arr[i].Validate(theForm.elements[i]))
                return false
        }
    }
    return true;
}

function MeText(strName, fAllowEmpty)
{
    this.strName = strName
    this.fAllowEmpty = fAllowEmpty
    this.Validate = function(field)
    {
        if ((!this.fAllowEmpty) && (field.value == ""))
        {
            alert('Vložte prosím text do pole "' + this.strName + '".')
            field.focus()
            return false
        }
        return true
    }
}

function link(left1, main1)
{
	if (left1!='') 	parent.left.location.href = left1;
	if (main1!='') 	parent.main.location.href = main1;
}

function link1(main1, left1)
{
	if (main1!='') 	parent.main.location.href = main1;
	if (left1!='') 	parent.left.location.href = left1;
	return false;
}

function newWindow(url)
{
	window.open(url);
}
function new_window(url)
{
	newWindow(url);
}
function makeWindow(url)
{
	window.open(url, '', "toolbar=no,status=no,scrollbars=no,resizable=yes,width=700,height=400");
}

function makeWindow1(url)
{
	window.open(url, '', "toolbar=no,status=no,scrollbars=no,resizable=yes,width=730,height=1000");
}

function makeWindowScrollable(url)
{
	window.open(url, '', "menubar=yes,toolbar=no,status=no,scrollbars=yes,resizable=yes,width=700,height=400");
}

function previewWindow(url, title)
{
	window.open(url, title, "toolbar=no,status=no,scrollbars=yes,resizable=yes,width=800,height=600");
}

function change_color()
{
	document.aa.style.textColor = '#00FF00';
}

function VRWindow(url, title)
{
	window.open(url, title, "toolbar=no,status=no,scrollbars=yes,resizable=yes,width=780,height=450");
}
function hop(ts,adr,what){
	if(ts.options[ts.selectedIndex].value=='0' || ts.options[ts.selectedIndex].value=='') return false;
	else document.location = adr+'?'+what+'='+ts.options[ts.selectedIndex].value;
}

//--------------------------------------------------------------------------------------
// Meni style.display u divu s divID na opacny
// 1.12.2003 Jan Pokorny
//--------------------------------------------------------------------------------------
function divSwapDisplay(divName){
	var myDiv=document.getElementById(divName);
	var myStyle=myDiv.style.display;
	if(myStyle==''){
		myDiv.style.display='none';
	}else{
		myDiv.style.display='';
	}
	return true;
}

//--------------------------------------------------------------------------------------
// Zavola zmenu zobrazeni divu a vytvori obrazek ... jenz nahraje do session stav mapy
// 2.2.2004 Jan Pokorny
//--------------------------------------------------------------------------------------
function divSwapMap(divName,temID) {
	divSwapDisplay(divName);
	var myDiv=document.getElementById(divName);
	var myStyle=myDiv.style.display;
	if(document.images){
		//alert("showHideMap.asp?thema="+temID+"&display="+myStyle);
		(new Image()).src="showHideMap.asp?thema="+temID+"&display="+myStyle;
	}
	return true;
}

//--------------------------------------------------------------------------------------
// Vola se na onfocus u checkboxu, zobraci confirm okno s textem a dle anvratove hodnoty
// pripadne prepne stav checkboxu
// druhym parametrem je originalni hodnota (true,false - textove)
// 1.12.2003 Jan Pokorny
//--------------------------------------------------------------------------------------
function checkboxFocusChange(tc,tcorig,textUncheck,textCheck){
	var origvalue
	origvalue=(tcorig=='true'?true:false)
	if (tc.checked && origvalue!=tc.checked){
		if (textUncheck!='') tc.checked=!window.confirm(textUncheck)
	}else{
		if (!tc.checked && origvalue==tc.checked){
			if (textCheck!='') tc.checked=window.confirm(textCheck)
		}
	}
}

// vraci hodnotu z popup okna zpet do formulara
function backToForm(formID, elName, newId, newName){
	var opnr=window.opener;
	var desForm=opnr.document.getElementById(formID);
	opnr.document.getElementById(elName+'_fk').value=newId;
	opnr.document.getElementById(elName+'_name').innerHTML=newName;
	window.setTimeout('window.close()',10);
}

// smaza hodnoty z formulare u tematu
function deleteThemaForm(name){
	document.getElementById(name+'_fk').value='';
	document.getElementById(name+'_name').innerHTML='';
}

//--------------------------------------------------------------------------------------
// Prepina mezi _map1.gif a map2.gif
// 16.1.2004 Jan Pokorny
//--------------------------------------------------------------------------------------
function swapMap(){
	var myDiv=document.getElementById('mapPicture');
	var imgSrc=myDiv.src;
	var ImgName
	var tmp=myDiv.src;
	imgName=imgSrc.substr(imgSrc.lastIndexOf('/')+1,imgSrc.length-(imgSrc.lastIndexOf('/')+1));
	if(imgName=='_map1.gif') {
		//alert('myDiv.src=\'images/_map2.gif\'');
		window.setTimeout('document.getElementById(\'mapPicture\').src=\'images/_map2.gif\'');
		//myDiv.src='images/_map2.gif?';
		//myDiv.src=mapImg2.src;
	}else{
		window.setTimeout('document.getElementById(\'mapPicture\').src=\'images/_map1.gif\'');
		//myDiv.src='images/_map1.gif?';
		//myDiv.src=mapImg1.src;

	}
	//alert(tmp+'\n'+myDiv.src);
}

// ------------------------------
// Okno na vybirani ZIPu a mesta
// ------------------------------
function validateZipField (eRef) {
	if (!eRef.value) {
		alert ('Prosím zadejte alespoň 3 číslice do pole PSČ.')
		eRef.focus();
		return false;

	}
	return true;
}

function validateZip(zipCode, zipAddress) {
	var zipE = document.getElementById(zipCode);
	if (!validateZipField (zipE)) {
		return false;
	}

	window.zipCode = zipCode;
	window.zipAddress = zipAddress;

	if (window.showModalDialog) {
		showModalDialog ("zip.asp?search=yes&zip=" +zipE.value, window, "dialogheight=200px;dialogwidth=300px;status=no;toolbar=no;menubar=no;location=no;resizable=yes;scroll:yes")
	} else {
		window.open("zip.asp?search=yes&zip=" +zipE.value, 'zipWindow', 'width=300,height=200,status=no,toolbar=no,menubar=no,location=no,resizable=yes,scroll=yes,')
	}

}


// porovna dve pole formulare , arg1 je objekt , arg2 je ID pole 2

function comparePasswordFields(tf, Field1, Field2){
	eval('oField1 = tf.'+Field1);
	eval('oField2 = tf.'+Field2);
	if(oField1.value != oField2.value){
		alert("Heslo se neshoduje s ověření hesla, zadejte je prosím znovu!");
		oField1.value = "";
		oField2.value = "";
		oField1.focus();
		return false;
	}
	return true;
}

//*****************************************************************
//	Discuss
//*****************************************************************
function changeViewDisplayPost(oButton){
	var sArrowClose = "images/discuss_ico_close.gif";
	var sArrowOpen = "images/discuss_ico_open.gif";
	var oLI = oButton.parentNode.parentNode.parentNode.parentNode;
	var aUL = oLI.getElementsByTagName("UL");
	
	if(aUL.length >= 1){
		ul = aUL[0];
		if(ul.style.display == 'none'){
			ul.style.display = "block";
			oButton.src = sArrowClose;
			oButton.title = "skrýt reakce na tento příspěvek";
		}else{
			ul.style.display = "none";
			oButton.src = sArrowOpen;
			oButton.title = "zobrazit reakce na tento příspěvek";
		}			
	}
}

function changeViewDisplayText(oButton){
	var oParent = oButton.parentNode;
	var aSpan = oParent.getElementsByTagName("SPAN");
	
	for(i=0;i<aSpan.length;i++){
		if(aSpan[i].className == "discussTextEnd"){
			if(aSpan[i].style.display == 'none'){
				aSpan[i].style.display = "inline";
				oButton.innerText = "schovat část příspěvku";
			}else{
				aSpan[i].style.display = "none";
				oButton.innerText = "zobrazit celý příspěvek";
			}
		}
	}
}

function initDiscuss(sID){
	var oUL = document.getElementById(sID);
	var aUL = oUL.getElementsByTagName("UL");
	var oButton;
	var aLI = oUL.getElementsByTagName("LI");

	//schova odpovedi na prispevky a zobrai tlacitka	
	for(i=0;i<aUL.length;i++){
    	aUL[i].style.display = "none";
		aButton = aUL[i].parentNode.firstChild.getElementsByTagName("SPAN");

		for(y=0;y<aButton.length;y++){
			if(aButton[y].className == "discussPack" || aButton[y].className == "discussPackImage"){
				aButton[y].style.display = "inline";
			}
		}
	}

	//schova delsi texty a zobrazi tlacitka
	for(i=0; i<aLI.length;i++){
		//aLI(i).firstChild.style.border = "1px solid red";
		//aLI(i).firstChild.lastChild.className);
		aSpan = aLI[i].firstChild.lastChild.getElementsByTagName("SPAN");
		
		for(y=0;y<aSpan.length;y++){
			if(aSpan[y].className == "discussTextEnd"){
				aSpan[y].style.display = "none";
			}
			
			if(aSpan[y].className == "discussTextDisplay"){
				aSpan[y].style.display = "inline";
			}
		}
	}
}

// MM 2007/03/21 (implementace Ekaterina Salomatova)
function confirmBotDefender(sElementBaseName, sCode, nTimeStamp) {
    document.getElementById(sElementBaseName +'_code_hidden').value = sCode;
    document.getElementById(sElementBaseName +'_stamp_hidden').value = nTimeStamp;
}


function searchOnblur(input, svalue) {
    if (input.value.length == 0)
        input.value = svalue;
}



function searchOnfocus(input, svalue) {
    if (input.value == svalue)
        input.value = '';
}


function loginOnblur(input, svalue) {
    if (input.value.length == 0)
        input.value = svalue;
}



function loginOnfocus(input, svalue) {
    if (input.value == svalue)
        input.value = '';
}

function addVideoRow() {
    var table, row, col, countVideo;

    countVideo = Number(document.getElementById('item_video_count').value) + 1;

    table = document.getElementById('countVideo');

    if (table) {
        row = table.insertRow(document.getElementById('videoBar').rowIndex);

        col = row.insertCell(0);
        col.className = 'leva';
        col.innerHTML = 'Video ' + countVideo;
        //alert(countVideo);
        col = row.insertCell(1);

        col.innerHTML = 'Název:&nbsp;<input type="text" size="88" name="item_video_name_' + countVideo + '">\n' +
                        'Kód:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<textarea class="placata2" name="item_video_code_' + countVideo + '"></textarea>';

        document.getElementById('item_video_count').value = countVideo;

    }
}
