function selectOnline(v) {
    var ton = "checked";
    var toff = "";
    if (v == 0) {
        ton = "";
        toff = "checked";
    }
    $("div[id='sclient-div'] input").each(function() {
        if ($(this).attr("rel") == "Online") {
            $(this).attr("checked", ton)
        } else {
            $(this).attr("checked", toff)
        }
    });

    i = 0;
    $("div[id='sclient-div']").find('INPUT:checkbox:checked').not('.selectAll').each(function () {
        i++;
    })
    if (i == 0) {
        $("div[id='sclient-div']").prev('INPUT.multiSelect').val("");
    } else {
        m = '% vybráno'
        $("div[id='sclient-div']").prev('INPUT.multiSelect').val(m.replace('%', i));
    }
}

function blockLinkTypeClick(t) {
    if (t == 1) {
        $("#blockLinkTypeExisting").show()
        $("#blockLinkTypeNew").hide()
        $("#blockLinkTypeOut").hide()
    }
    if (t == 2) {
        $("#blockLinkTypeExisting").hide()
        $("#blockLinkTypeNew").show()
        $("#blockLinkTypeOut").hide()
    }
    if (t == 3) {
        $("#blockLinkTypeExisting").hide()
        $("#blockLinkTypeNew").hide()
        $("#blockLinkTypeOut").show()
    }
}

function showNote(obj, m, x, y) {
    clearTimeout(noteTO)
    if (!x) x = 10
    if (!y) y = 3
    x = findPosX(obj) - x
    y = findPosY(obj) - y
    document.getElementById('note').style.left = x + 'px'
    document.getElementById('note').style.top = y + 'px'
    document.getElementById('note').style.display = 'block'
    document.getElementById('note').innerHTML = m
}

var noteTO
function prepareHideNote(m) {
    document.getElementById('note').innerHTML = '<b>' + m + '</b>'
    noteTO = setTimeout('hideNote()', 1000)
}

function hideNote() {
    document.getElementById('note').style.display = 'none'
}

function returnToGallery() {
    if ($('.gallery').length > 0) {
        $('.gallery').gallery({
            interval: 5500,
            height: '260px',
            width: '272px',
            toggleBar: false,
            slideshow: false,
            showOverlay: true,
            thumbHeight: 46,
            thumbWidth: 62
        });
    }
}

function transferFilter() {
    var checkboxes = document.getElementsByName('hcountry[]');
    var cboxLength = checkboxes.length;

    country = ""
    for (i = 0; i < cboxLength; i++) {
        if (checkboxes[i].checked) {
            if (country != "") country += ","
            country += checkboxes[i].value
        }
    }

    var checkboxes = document.getElementsByName('hstate[]');
    var cboxLength = checkboxes.length;

    state = ""
    for (i = 0; i < cboxLength; i++) {
        if (checkboxes[i].checked) {
            if (state != "") state += ","
            state += checkboxes[i].value
        }
    }

    var checkboxes = document.getElementsByName('hcity[]');
    var cboxLength = checkboxes.length;

    city = ""
    for (i = 0; i < cboxLength; i++) {
        if (checkboxes[i].checked) {
            if (city != "") city += ","
            city += checkboxes[i].value
        }
    }

    var checkboxes = document.getElementsByName('hclient[]');
    var cboxLength = checkboxes.length;

    client = ""
    for (i = 0; i < cboxLength; i++) {
        if (checkboxes[i].checked) {
            if (client != "") client += ","
            client += checkboxes[i].value
        }
    }
    dfrom = document.searchform.fromDate.value
    dto = document.searchform.toDate.value
    cfrom = ""
    cto = ""
    cena = document.searchform.cena.value
    hn = document.searchform.hotelname.value
    lm = document.searchform.lm.checked ? "Yes" : "No"
    fm = document.searchform.fm.checked ? "Yes" : "No"
    strava = document.searchform.strava.value

    var checkboxes = document.getElementsByName('htype[]');
    var cboxLength = checkboxes.length;

    stype = ""
    for (i = 0; i < cboxLength; i++) {
        if (checkboxes[i].checked) {
            if (city != "") stype += ","
            stype += checkboxes[i].value
        }
    }

    doprava = document.searchform.doprava.value
    var checkboxes = document.getElementsByName('hmisto[]');
    var cboxLength = checkboxes.length;

    misto = ""
    if (doprava != "") {
        for (i = 0; i < cboxLength; i++) {
            if (checkboxes[i].checked) {
                if (misto != "") misto += ","
                misto += checkboxes[i].value
            }
        }
    }
    vbselect = document.searchform.vlastnibusselect.value
    stars = document.searchform.stars.value

    nurl=""
    if (stype != "") nurl += "stype=" + stype + "&"
    if (country != "") nurl += "country=" + country + "&"
    if (state != "") nurl += "state=" + state + "&"
    if (city != "") nurl += "city=" + city + "&"
    if (client != "") nurl += "client=" + client + "&"
    if (dfrom != "") nurl += "dfrom=" + dfrom + "&"
    if (dto != "") nurl += "dto=" + dto + "&"
    if (cena != "") nurl += "cena=" + cena + "&"
    if (hn != "") nurl += "hn=" + hn + "&"
    if (lm != "") nurl += "lm=" + lm + "&"
    if (fm != "") nurl += "fm=" + fm + "&"
    if (strava != "") nurl += "strava=" + strava + "&"
    if (doprava != "") nurl += "doprava=" + doprava + "&"
    if (misto != "") nurl += "misto=" + misto + "&"
    if (stars != "") nurl += "stars=" + stars + "&"
    if (vbselect != "") nurl += "vlastnibusselect=" + vlastnibusselect

    document.pageform.filteroptions.value = nurl
    document.pageform.submit()
}

function bookginsByFilter(p, stype, country, state, city, client, dfrom, dto, cena, hn, lm, fm, nights, strava, ubytovani, doprava, misto, stars, vbselect, hchecked, firstpage, burl, sort, sortdir) {
    $("#mainlist .mainlistbody table").addClass("transp50")
    setLoading($("#mainlist .mainlistbody table"))
    lastbaseurl=burl
    lbokvars = [p, stype, country, state, city, client, dfrom, dto, cena, hn, lm, fm, nights, strava, ubytovani, doprava, misto, stars, vbselect, hchecked, firstpage, sort, sortdir, "No", lastbaseurl]
    ts = new Date().getTime();
    $.ajax({
        type: "POST",
        url: "/ajax/ajax.aspx?action=getBookings" + "&ts=" + ts,
        data: "p=" + p + "&stype=" + stype + "&country=" + country + "&state=" + state + "&city=" + city + "&client=" + client + "&dfrom=" + dfrom + "&dto=" + dto + "&cena=" + cena + "&hn=" + hn + "&lm=" + lm + "&fm=" + fm + "&nights=" + nights + "&strava=" + strava + "&ubytovani=" + ubytovani + "&doprava=" + doprava + "&misto=" + misto + "&stars=" + stars + "&vbselect=" + vbselect + "&hchecked=" + hchecked + "&firstpage=" + firstpage + "&sort=" + sort + "&sortdir=" + sortdir + "&updatecookies=No&baseurl=" + burl + "&session_hash=" + session_hash,
        success: function (msg) {
            listtab(msg)
        }
    });
}

function nextPage(p, url) {
    window.location.href= url + "/page=" + p
}

function recalc2(obj) {
    v = $("#selectormainprice").attr("value")
    a = parseInt($("#mainprice").text().replace(/ /, ""))

    total = v * a

    $(".extraprice").each(function() {
        id = $(this).attr("id").replace("selector", "")
        v = $("#selector" + id).attr("value")
        a = parseInt($("#extras" + id).text().replace(/ /, ""))
        total += v * a
    });

    $("#AutohintTotalDiscountedPrice").html("<b>"+formatCurrency(total)+"</b>")
}

function formatCurrency(num) {
    num = num.toString().replace(/\$|\,/g, '');
    if (isNaN(num))
        num = "0";
    sign = (num == (num = Math.abs(num)));
    num = Math.floor(num * 100 + 0.50000000001);
    cents = num % 100;
    num = Math.floor(num / 100).toString();
    if (cents < 10)
        cents = "0" + cents;
    for (var i = 0; i < Math.floor((num.length - (1 + i)) / 3); i++)
        num = num.substring(0, num.length - (4 * i + 3)) + ' ' + num.substring(num.length - (4 * i + 3));
    return (((sign) ? '' : '-') + '' + num );
}

function mover(obj, v) {
    if (v == 1) {
        $(obj).css("background", "#e1eaee")
    } else {
        $(obj).css("background", "#c2e8fa")
    }
}

function showSBOptions() {
    $("#cont_editor").css("visibility", "hidden")
    $("#cont_editor_body").css("visibility", "hidden")
    $("#sb_options").show()
}

function selectBox(t, s) {
    $("#sb_currencies").hide()
    $("#sb_weather").hide()
    if (t == "search" || t == "mostvisited" || t == "weather" || t == "currencies" || t == "search" || t == "newsletter") {
        $("#cont_editor").css("visibility", "visible")
        $("#cont_editor_body").css("visibility", "hidden")
        document.pageform.special.value = t
        if (t == "currencies") $("#sb_currencies").show()
        if (t == "weather") $("#sb_weather").show()
        $("#cont_banner").hide()
    } else if (t == "banner") {
        $("#cont_editor").css("visibility", "hidden")
        $("#cont_editor_body").css("visibility", "hidden")
        $("#sb_currencies").hide()
        $("#sb_weather").hide()
        $("#cont_banner").show()
    } else {
        $("#cont_banner").hide()
        $("#cont_editor").css("visibility", "visible")
        $("#cont_editor_body").css("visibility", "visible")
        document.pageform.special.value = "custom"
        if (s == "1") {
            document.pageform.style.value = "empty"
        } else {
            document.pageform.style.value = "box"
        }
    }
    
    $("#sb_options").hide()
}

var menuto
var normalmenuto
var lastmenu
var lastnormalmenu
function initMenus() {
    $(".search_sidebar").mouseenter(function () {
        clearTimeout(menuto)
        if (lastmenu) hideOptions()
        x = $(this).position().left + 1
        y = $(this).position().top + 3

        $(this).next(".opencms").css("left", x + "px")
        $(this).next(".opencms").css("top", y + "px")
        $(this).next(".opencms").css("left", x + "px")
        $(this).next(".opencms").show()
        $(this).next(".opencms").click(function (event) {
            event.stopPropagation();
            ty = y + 12
            $(this).next(".cmsoptionsside").css("left", x + "px")
            $(this).next(".cmsoptionsside").css("top", ty + "px")
            $(this).next(".cmsoptionsside").show()
            $(this).next(".cmsoptionsside").click(function (event) {
                event.stopPropagation();
            });
        });

    }).mouseleave(function () {
        lastmenu = $(this).next(".opencms")
        menuto = setTimeout("hideOptions()", 400)
    });

    $(".homepageblock").mouseenter(function () {
        clearTimeout(menuto)
        if (lastmenu) hideOptions()
        x = $(this).position().left + 5
        y = $(this).position().top + 3

        $(this).next(".opencms").css("left", x + "px")
        $(this).next(".opencms").css("top", y + "px")
        $(this).next(".opencms").css("left", x + "px")
        $(this).next(".opencms").show()
        $(this).next(".opencms").click(function (event) {
            event.stopPropagation();
            ty = y + 12
            $(this).next(".cmsoptionsside").css("left", x + "px")
            $(this).next(".cmsoptionsside").css("top", ty + "px")
            $(this).next(".cmsoptionsside").show()
            $(this).next(".cmsoptionsside").click(function (event) {
                event.stopPropagation();
            });
        });

    }).mouseleave(function () {
        lastmenu = $(this).next(".opencms")
        menuto = setTimeout("hideOptions()", 400)
    });

    $("#mainmenu .relativac").mouseenter(function () {
        clearTimeout(menuto)
        clearTimeout(normalmenuto)
        if (lastmenu) hideOptions()
        if (lastnormalmenu) hideNormalOptions()
        x = $(this).offset().left + 3
        y = $(this).offset().top + 1
        $(this).next(".opencms").css("left", x + "px")
        $(this).next(".opencms").css("top", y + "px")
        $(this).next(".opencms").show()
        $(this).next(".opencms").click(function (event) {
            event.stopPropagation();
            ty = y + 12
            $(this).next(".cmsoptionsside").css("left", x + "px")
            $(this).next(".cmsoptionsside").css("top", ty + "px")
            $(this).next(".cmsoptionsside").show()
            $(this).next(".cmsoptionsside").click(function (event) {
                event.stopPropagation();
            });
        });

        x = $(this).offset().left
        y = $(this).offset().top
        thisid = $(this).attr("id").replace("mainmenuitem", "")
        $("#submenu" + thisid).css("left", x + "px")
        $("#submenu" + thisid).css("top", y + "px")
        $("#submenu" + thisid).show()
    }).mouseleave(function () {
        lastmenu = $(this).next(".opencms")
        menuto = setTimeout("hideOptions()", 400)
        thisid = $(this).attr("id").replace("mainmenuitem", "")
        lastnormalmenu = $("#submenu" + thisid)
        normalmenuto = setTimeout("hideNormalOptions()", 400)
    });


    $("#menu ul li").mouseenter(function () {
        clearTimeout(menuto)
        clearTimeout(normalmenuto)
        if (lastmenu) hideOptions()
        if (lastnormalmenu) hideNormalOptions()
        x = $(this).offset().left + 3
        y = $(this).offset().top + 1
        $(this).next(".opencms").css("left", x + "px")
        $(this).next(".opencms").css("top", y + "px")
        $(this).next(".opencms").show()
        $(this).next(".opencms").click(function (event) {
            event.stopPropagation();
            ty = y + 12
            $(this).next(".cmsoptionsside").css("left", x + "px")
            $(this).next(".cmsoptionsside").css("top", ty + "px")
            $(this).next(".cmsoptionsside").show()
            $(this).next(".cmsoptionsside").click(function (event) {
                event.stopPropagation();
            });
        });

        x = $(this).offset().left
        y = $(this).offset().top
        thisid = $(this).attr("id").replace("mainmenuitem", "")
        $("#submenu" + thisid).css("left", x + "px")
        $("#submenu" + thisid).css("top", y + "px")
        $("#submenu" + thisid).show()
    }).mouseleave(function () {
        lastmenu = $(this).next(".opencms")
        menuto = setTimeout("hideOptions()", 400)
        thisid = $(this).attr("id").replace("mainmenuitem", "")
        lastnormalmenu = $("#submenu" + thisid)
        normalmenuto = setTimeout("hideNormalOptions()", 400)
    });
    
    $(".submenu").mouseenter(function() {
        clearTimeout(normalmenuto)
    }).mouseleave(function() {
        normalmenuto = setTimeout("hideNormalOptions()", 400)
    });

    $("#headerright").mouseenter(function () {
        clearTimeout(menuto)
        if (lastmenu) hideOptions()
        x = $(this).offset().left + 3
        y = $(this).offset().top + 1
        $(this).next(".opencms").css("left", x + "px")
        $(this).next(".opencms").css("top", y + "px")
        $(this).next(".opencms").show()
        $(this).next(".opencms").click(function(event) {
            event.stopPropagation();
        });
    }).mouseleave(function() {
        lastmenu = $(this).next(".opencms")
        menuto = setTimeout("hideOptions()", 400)
    });

    $(".opencms").mouseenter(function() {
        clearTimeout(menuto)
    }).mouseleave(function() {
        lastmenu = $(this)
        menuto = setTimeout("hideOptions()", 400)
    });
    $(".cmsoptionsside").mouseenter(function() {
        clearTimeout(menuto)
    }).mouseleave(function() {
        lastmenu = $(this)
        menuto = setTimeout("hideOptions()", 400)
    });
}

function initNormalMenus() {
    $("#mainmenu .relativac").mouseenter(function () {
        clearTimeout(normalmenuto)
        if (lastnormalmenu) hideNormalOptions()
        x = $(this).offset().left
        y = $(this).offset().top
        thisid = $(this).attr("id").replace("mainmenuitem", "")
        $("#submenu" + thisid).css("left", x + "px")
        $("#submenu" + thisid).css("top", y + "px")
        $("#submenu" + thisid).show()
    }).mouseleave(function () {
        thisid = $(this).attr("id").replace("mainmenuitem", "")
        lastnormalmenu = $("#submenu" + thisid)
        normalmenuto = setTimeout("hideNormalOptions()", 400)
    });

    $("#menu ul li").mouseenter(function () {
        clearTimeout(normalmenuto)
        if (lastnormalmenu) hideNormalOptions()
        x = $(this).offset().left
        y = $(this).offset().top
        thisid = $(this).attr("id").replace("mainmenuitem", "")
        $("#submenu" + thisid).css("left", x + "px")
        $("#submenu" + thisid).css("top", y + "px")
        $("#submenu" + thisid).show()
    }).mouseleave(function () {
        thisid = $(this).attr("id").replace("mainmenuitem", "")
        lastnormalmenu = $("#submenu" + thisid)
        normalmenuto = setTimeout("hideNormalOptions()", 400)
    });

    $(".submenu").mouseenter(function() {
        clearTimeout(normalmenuto)
    }).mouseleave(function() {
        normalmenuto = setTimeout("hideNormalOptions()", 400)
    });
}

function hideNormalOptions() {
    $(lastnormalmenu).hide()
    return
}
function hideOptions() {
    $(lastmenu).hide()
    $(lastmenu).next(".cmsoptionsside").hide()
    return
}



function checkForDoprava(obj) {
    lastdoprava=obj.value
    if (obj.value == "Letecky") {
        $("#mistoselect").show()
    } else {
        $("#mistoselect").hide()
    }
}

function checkForVlastni(obj) {
    if (obj.value == "Vlastní doprava/bus") {
        $("#vlastnibusselect").show()
    } else {
        $("#vlastnibusselect").hide()
    }
}

function showLogin() {
    $("#loginf").toggle()
}

function lostPass() {
    $("#loginf").hide()
    $("#lostpass").show()
}

function showLoginForm() {
    $("#loginf").show()
    $("#lostpass").hide()
}

function getPassword() {
    email = $("#fpemail").attr("value")
    if (email != "") {
        $("#fpbutton").attr("disabled", "disabled")
        $('#respfp').html("získávání informací...");
        $.get('admin/ajax/password.aspx?email=' + email, function(data) {
            $('#respfp').html(data);
            $("#fpbutton").attr("disabled", "")
        });
    }
}

function createCookie(name, value) {
    document.cookie = name + "=" + value + "; path=/";
}

	function transferInfo() {
		document.alexform.alexinfovalue.value = $("#BookingQuickInfoWidget").html().replace(/\n/g, '');
		document.alexform.submit()
	}

	function search(w) {
		document.searchform.page.value=0
		document.searchform.action="/"+w
		document.searchform.submit()
}

    function clearSearchForm() {
        clearSessions()
	    //return true;
        $("#sclient-div").find('INPUT:checkbox').attr('checked', false).parent().removeClass('checked');
        $("#stype-div").find('INPUT:checkbox').attr('checked', false).parent().removeClass('checked');
        allclicked($("#sclient-div"))
        setClients()
        var now = new Date
        dow = now.getDate()
        mm = now.getMonth() + 1
        yyyy = now.getFullYear()
        $("#fromDate").val(dow+"."+mm+"."+yyyy)
        mm = now.getMonth() + 2
        if (mm == 13) {
            mm = 1
            yyyy++
        }
        $("#toDate").val(dow + "." + mm + "." + yyyy)
        $("#searchhotelname").val("")
        $("#searchcena").val("")
        $("#searchlm").attr("checked", "")
        $("#searchfm").attr("checked", "")
        $("#vlastnibusselects").val("")
        $("#strava").val("")
        $("#nights").val("")
        lastdoprava = "";
        $("#doprava").val("")
        $("#stars").val("")
        $("#smisto-div").find('INPUT:checkbox').attr('checked', false).parent().removeClass('checked');
        allclicked($("#smisto-div"))
        $("#mistoselect").hide()
        
        return true
    }

    function clearSessions() {
        ts = new Date().getTime();
        $.ajax({
            type: "GET",
            url: "/ajax/ajax.aspx?action=clearSessions&ts=" + ts,
            success: function (msg) {
                return msg;
            }
        });
    }


    function advancedSearch() {
        //$("#starsdiv").toggle()
        //$("#stravadiv").toggle()
        //$("#lmdiv").toggle()
        //$("#odletdiv").toggle()
        //$("#ubytovanidiv").toggle()
        $("#advancedsearch").toggle()
    }

	function changeNights(val) {
		document.hotelForm.nights.value=val
		document.searchTabs.nights.value=val
		submitDate('hfrom', parseInt(document.searchTabs.hfromDay.value), parseInt(document.searchTabs.hfromMonth.value)-1, parseInt(document.searchTabs.hfromYear.value))
	}

	function page(p, sub) {
		document.searchform.page.value=p
		document.searchform.submit()
	}

	function findPosX(obj) {
	    offset = $(obj).offset();
	    return offset.left;
	}

	function findPosY(obj) {
	    offset = $(obj).offset();
	    return offset.top;
	}

	function getScrollTop(){
		if (typeof window.pageYOffset != 'undefined') {
			position = window.pageYOffset
		} else if (typeof document.documentElement.scrollTop!= 'undefined' && document.documentElement.scrollTop > 0) {
			position = document.documentElement.scrollTop
		} else if (typeof document.body.scrollTop != 'undefined') {
			position = document.body.scrollTop
		}
		return position;
	}

	function setLoadingImg(obj) {
		reX=findPosX(obj)
		reY=findPosY(obj)
		reW=obj.offsetWidth
		reH=obj.offsetHeight

		document.getElementById('transDiv').style.left=reX+"px"
		document.getElementById('transDiv').style.top=reY+"px"
		document.getElementById('transDiv').style.width=reW+"px"
		document.getElementById('transDiv').style.height=reH+"px"
		document.getElementById('transDiv').style.display="block"

		imX=reX+reW/2-10
		imY=reY+reH/2-10

		document.getElementById('loading').style.left=imX+"px"
		document.getElementById('loading').style.top=imY+"px"
		document.getElementById('loading').style.display="block"
	}

	function unsetLoadingImg(obj) {
		document.getElementById('loading').style.display="none"
	}

	var inW
	var inH
	var scr
	var objImage
	var tinW
	var tinH
	var objImage
	function bigPic(pic) {
		object = document.getElementById("canc");
		while (object.hasChildNodes())	{
			object.removeChild(object.firstChild);
		}
		if (window.innerWidth) {
			tinW=document.body.offsetWidth
			tinH=document.body.offsetHeight;
		} else {
			tinW=document.body.clientWidth
			tinH=document.body.clientHeight;
		}

		document.getElementById('transDiv').style.width=tinW+"px"
		document.getElementById('transDiv').style.height=tinH+"px"
		document.getElementById('transDiv').style.display="block"

		if (window.innerHeight) {
			inW = window.innerWidth-16;
			inH = window.innerHeight-16;
		} else if (document.body) {
			inW = document.body.offsetWidth-20;
			inH = self.screen.availHeight-20;
		}

		scrT=getScrollTop()
		scrT=parseInt(scrT)

		leftX=(inW-10)/2
		topX=inH/2-10/2+scrT
		if (!window.innerWidth) {
			topX=topX-50
		}
		document.getElementById('loading').style.left=leftX+"px"
		document.getElementById('loading').style.top=topX+"px"
		document.getElementById('loading').style.display="block"

		objImage = new Image();
		objImage.src=pic
		objImage.id="test"
		objImage.onLoad=loadImage();
	}

	function loadImage() {
		if (objImage.complete) {
			w=objImage.width
			h=objImage.height

			scrT=getScrollTop()
			scrT=parseInt(scrT)

			leftX=(inW-w)/2-10
			topX=inH/2-h/2+scrT-10
			if (!window.innerWidth) {
				topX=topX-50
			}
			if (topX<scrT+10) {
				diff=(scrT-topX)*2
				topX=scrT+10
				objImage.height=h-diff-10
				w=objImage.width
				leftX=(inW-w)/2-10
			}
			document.getElementById('canc').appendChild(objImage)
			document.getElementById('canc').style.left=leftX+'px'
			document.getElementById('canc').style.top=topX+'px'
			document.getElementById('loading').style.display='none'
			document.getElementById('canc').style.display='block'
		} else {
			setTimeout('loadImage()', 100)
		}
	}

	function closeThis() {
		document.getElementById('transDiv').style.display="none"
		document.getElementById('canc').style.display='none'
	}

	function changeGuests(obj) {
		v = obj.value
		for (i = 1; i <= v; i = i + 1) {
			document.getElementById("guest" + i).style.display = "block"
		}
		v++
		for (i = v; i <= 8; i = i + 1) {
			document.getElementById("guest" + i).style.display = "none"
		}
	}

	function validateGuests(g) {
		name=document.getElementById("ctl00_Content_PersonsControlObject_TxtOsobaJmeno").value
		surname=document.getElementById("ctl00_Content_PersonsControlObject_TxtOsobaPrijmeni").value
		address=document.getElementById("ctl00_Content_PersonsControlObject_TxtOsobaUlice").value
		city=document.getElementById("ctl00_Content_PersonsControlObject_TxtOsobaMesto").value
		zip=document.getElementById("ctl00_Content_PersonsControlObject_TxtOsobaSmerCis").value
		day=document.getElementById("ctl00_Content_PersonsControlObject_DdlOsobaNarozenDen").value
		month=document.getElementById("ctl00_Content_PersonsControlObject_DdlOsobaNarozenMesic").value
		year=document.getElementById("ctl00_Content_PersonsControlObject_DdlOsobaNarozenRok").value
		rc=document.getElementById("ctl00_Content_PersonsControlObject_TxtOsobaRC").value
		email=document.getElementById("ctl00_Content_PersonsControlObject_TxtOsobaEmail").value
		phone = document.getElementById("ctl00_Content_PersonsControlObject_TxtOsobaTelefon").value

		if (!name || !surname || !address || !city || !zip || !day || !month || !year || !rc || !email || !phone) {
			return false;
		}

		for (j = 1; j < g; j++) {
			name = document.getElementById("ctl00_Content_PersonsControlObject_jmeno_"+j).value
			surname = document.getElementById("ctl00_Content_PersonsControlObject_prijmeni_" + j).value
			address = document.getElementById("ctl00_Content_PersonsControlObject_ulice_" + j).value
			city = document.getElementById("ctl00_Content_PersonsControlObject_mesto_" + j).value
			day = document.getElementById("ctl00_Content_PersonsControlObject_narozen_den_" + j).value
			month = document.getElementById("ctl00_Content_PersonsControlObject_narozen_mesic_" + j).value
			year = document.getElementById("ctl00_Content_PersonsControlObject_narozen_rok_" + j).value
			//email = document.getElementById("ctl00_Content_PersonsControlObject_email_" + j).value
			//phone = document.getElementById("ctl00_Content_PersonsControlObject_telefon_" + j).value

			if (!name || !surname || !address || !city || !day || !month || !year) {
				return false;
			}
		}
		return true;
	}

	function checkSubmit(chk) {
		if (chk.checked==true) {
			$("#guestssubmitbutton").removeAttr("disabled")
		} else {
			$("#guestssubmitbutton").attr("disabled", "disabled")
		}
}

function copyBF() {
    f = document.getElementById("uniform")
    f.g_name.value = f.o_name.value
    f.g_surname.value = f.o_surname.value
    f.g_address.value = f.o_address.value
    f.g_city.value = f.o_city.value
    f.g_zip.value = f.o_zip.value
    f.g_country.value = f.o_country.value
    f.g_dob.value = f.o_dob.value
    f.g_phone.value = f.o_phone.value
    f.g_email.value = f.o_email.value
}

function validateemail(email) {
    var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
    if (reg.test(email) == false) {
        return false;
    }
    return true
}

function verifyUniForm() {
    f = document.getElementById("uniform")
    name = f.o_name.value
    surname = f.o_surname.value
    address = f.o_address.value
    city = f.o_city.value
    zip = f.o_zip.value
    country = f.o_country.value
    dob = f.o_dob.value
    phone = f.o_phone.value
    email = f.o_email.value

    var now = new Date;
    var minyear = now.getFullYear() - 18;

    dobs = dob.split(".")

    if (!name || !surname || !phone || !email) {
        alert("Prosím vyplňte povinné údaje (označené *)")
        return false;
    } else if (!validateemail(email)) {
        alert("E-mailová adresa není správná!");
        return false;
    } else if (dobs.length < 3 || dobs.length > 3) {
        alert("Prosím, zadejte datum narození ve správném formátu d.m.YYYY (např: 21.9.1971)");
        return false;
    } else if (dobs.length == 3) {
        if (parseInt(dobs[0]) > 31 || parseInt(dobs[0]) < 1 || parseInt(dobs[1]) > 12 || parseInt(dobs[1]) < 1 || parseInt(dobs[2]) > minyear || parseInt(dobs[2]) < 1920 || !parseInt(dobs[0]) || !parseInt(dobs[1]) || !parseInt(dobs[2])) {
            alert("Prosím, zadejte datum narození ve správném formátu d.m.YYYY (např: 21.9.1971)");
            return false;
        }
    } else {
        return true;
    }
}


function verifyOfflineUniForm() {
    f = document.getElementById("uniform")
    name = f.k_name.value
    surname = f.k_surname.value

    if (!name || !surname) {
        alert("Prosím vyplňte povinné údaje (označené *)")
        return false
    } else {
        return true
    }
}

function morePrices(obj, ID) {
    if ($(".showedprice" + ID).length) {
        $(".showedprice" + ID).remove()
    } else {
        $(obj).parent().parent().after("<tr class=showedpriceload" + ID + "><td colspan=4>Loading...</td></tr>")
        $.get('ajax/prices.aspx?action=morePrices&ID=' + ID, function(data) {
            $(obj).parent().parent().after(data)
            $(".showedpriceload" + ID).remove()
        });
    }
}

function openImageBrowser() {
    winpop = window.open("/FileManager/index.html?action=js&type=Images&CKEditor=&CKEditorFuncNum=SetUrl", "slikaWin", 'width=896, height=560, top=100, left=100, tools=0')
    winpop.focus()
}

function openFileBrowser() {
    winpop = window.open("/FileManager/index.html?action=js&CKEditor=&CKEditorFuncNum=SetFile", "slikaWin", 'width=896, height=560, top=100, left=100, tools=0')
    winpop.focus()
}

function putFlash(o, u, bmx, bmy, bp) {
    flash1 = '<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0" width="' + bmx + '" height="' + bmy + '" id="menu" align="middle" style="margin-top:'+bp+'px">\n';
    flash1 = flash1 + '<param name="allowScriptAccess" value="sameDomain" />\n';
    flash1 = flash1 + '<param name="movie" value="' + u + '" />\n';
    flash1 = flash1 + '<param name="wmode" value="transparent" />\n';
    flash1 = flash1 + '<param name="quality" value="high" />\n';
    flash1 = flash1 + '<param name="bgcolor" value="#ffffff" />\n';
    flash1 = flash1 + '<embed wmode="transparent" src="' + u + '" quality="high" bgcolor="#ffffff" width="' + bmx + '" height="' + bmy + '" name="menu" align="middle" allowScriptAccess="sameDomain" style="margin-top:' + bp + 'px" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />\n';
    flash1 = flash1 + '</object>\n';

    o.innerHTML = flash1
}

function SetFile(u) {
    if (u.indexOf(".gif") > 0 || u.indexOf(".jpg") > 0 || u.indexOf(".jpeg") > 0 || u.indexOf(".png") > 0 || u.indexOf(".bmp") > 0) {
        SetUrl(u)
    } else if (u.indexOf(".swf") > 0) {
        document.forma.pic.value = u
        putFlash(document.getElementById("bannerholder"), u)
    }
}

var newImg
function SetUrl(u) {
    document.forma.pic.value = u
    document.getElementById("bannerholder").innerHTML="<img src='"+u+"' id=picimg>"

    newImg = new Image();
    newImg.src = u;
    setTimeout("checkIfLoaded()", 200)
}

function setVelicina(obj) {
    var width = obj.width;
    var height = obj.height;
    if (width > 400) {
        koef = 400 / width
        width = 400
        height = Math.floor(height * koef)
    }
    if (height > 300) {
        koef = 300 / height
        height = 300
        width = Math.floor(width * koef)
    }


    document.getElementById("picimg").style.display = "none"
    document.getElementById("picimg").src = obj.src
    document.getElementById("picimg").width = width
    document.getElementById("picimg").height = height
    document.getElementById("picimg").style.display = "block"
}

function checkIfLoaded() {
    if (newImg.width) {
        setVelicina(newImg)
    } else {
        setTimeout("checkIfLoaded()", 200)
    }
}

function assignColorPicker(c) {
    $('#colorSelector1').ColorPicker({
        color: '#0000ff',
        onShow: function(colpkr) {
            $(colpkr).fadeIn(100);
            return false;
        },
        onHide: function(colpkr) {
            $(colpkr).fadeOut(100);
            return false;
        },
        onChange: function(hsb, hex, rgb) {
            $('#colorSelector1 div').css('backgroundColor', '#' + hex);
            $('#myhexcode1').attr('value', hex);
        }
    });

    $('#colorSelector2').ColorPicker({
        color: '#0000ff',
        onShow: function(colpkr) {
            $(colpkr).fadeIn(100);
            return false;
        },
        onHide: function(colpkr) {
            $(colpkr).fadeOut(100);
            return false;
        },
        onChange: function(hsb, hex, rgb) {
            $('#colorSelector2 div').css('backgroundColor', '#' + hex);
            $('#myhexcode2').attr('value', hex);
        }
    });
}

function y2k(number) { return (number < 1000) ? number + 1900 : number; }

function isDate(d) {
    ds = d.split(".")
    day = ds[0]
    month = ds[1]
    year = ds[2]
    
    // checks if date passed is valid
    // will accept dates in following format:
    // isDate(dd,mm,ccyy), or
    // isDate(dd,mm) - which defaults to the current year, or
    // isDate(dd) - which defaults to the current month and year.
    // Note, if passed the month must be between 1 and 12, and the
    // year in ccyy format.

    var today = new Date();
    year = ((!year) ? y2k(today.getYear()) : year);
    month = ((!month) ? today.getMonth() : month - 1);
    if (!day) return false
    var test = new Date(year, month, day);
    if ((y2k(test.getYear()) == year) && (month == test.getMonth()) && (day == test.getDate()) && ds[0].length < 3 && ds[1].length < 3 && ds[2].length < 5)
        return true;
    else
        return false
}
