function webnet_ShowModalDialog(strUrl, nLeft, nTop, nWidth, nHeight, bCenter, bResizable, bScroll, bStatus)
{
	var nReturn = 0;
	var arArguments = new Array(strUrl,window);
	if (bCenter == 0)
	{
		nReturn = window.showModalDialog('../Main/Modal.htm',arArguments,'dialogHeight:' + nHeight + 'px;dialogLeft:' + nLeft + 'px;dialogTop:' + nTop + 'px;dialogWidth:' + nWidth + 'px;center:0;dialogHide:0;edge:raised;help:0;resizable:' + bResizable + ';scroll:' + bScroll + ';status:' + bStatus + ';unadorned:0;');
	}
	else
	{
		nReturn = window.showModalDialog('../Main/Modal.htm',arArguments,'dialogHeight:' + nHeight + 'px;dialogWidth:' + nWidth + 'px;center:1;dialogHide:0;edge:raised;help:0;resizable:' + bResizable + ';scroll:' + bScroll + ';status:' + bStatus + ';unadorned:0;');
	}
	
	if (nReturn == 123)
	{
		document.forms[0].submit();
	}
	else if (nReturn == 456)
	{
		document.location.reload(true);
	}
	else
	{
		return nReturn;
	}
}

function webnet_ShowDialog(strUrl, nLeft, nTop, nWidth, nHeight, bCenter, bResizeable, bScroll, bStatus)
{
	var newWnd1;
	var strResizeable = 'no';
	var strScroll = 'no';
	var strStatus = 'no';
	if (bResizeable)
		strResizeable = 'yes';
	if (bScroll)
		strScroll = 'yes';
	if (bStatus)
		strStatus = 'yes';
	newWnd1 = window.open(strUrl, '', 'height='+nHeight+',width='+nWidth+',directories=no,location=no,scrollbars='+strScroll+',menubar=no,resizeable='+strResizeable+',status='+strStatus+',toolbar=no,top='+nTop+',left='+nLeft);
}

function webnet_ConfirmationOnLoad() {
    if ( !webnet_ConfirmationBrowserCapable() ) return;
    if (typeof(webnet_Page_Confirmations) == "undefined") return;
    var i, confirmButton;
    for (i = 0; i < webnet_Page_Confirmations.length; i++) {
        confirmButton = webnet_Page_Confirmations[i];
        if (typeof(confirmButton) == "string") {
            confirmButton = document.getElementById( confirmButton );
        }
        if ( typeof(confirmButton.confirmationmessage ) == "undefined" ) {
            if ( typeof( confirmButton.attributes ) != "undefined" ) {
                confirmButton.confirmationmessage = confirmButton.attributes["confirmationmessage"].value;
            } else {
                confirmButton.confirmationmessage = "Opravdu chcete provést zvolenou akci?";
            }
        }
        webnet_ConfirmationHookupControl(confirmButton);
    }
}

function webnet_ConfirmationBrowserCapable() {
    if ( typeof( document.getElementById ) == "undefined" ) {
        if ( typeof( document.all ) != "undefined" ) {
            document.getElementById = function( elementId ) { return document.all[elementId]; };
            return true;
        }
        return false;
    }
    return true;
}

function webnet_ConfirmationHookupControl( confirmButton ) {
    var ev = confirmButton.onclick;
    if (typeof(ev) == "function" ) {            
        ev = ev.toString();
        ev = ev.substring(ev.indexOf("{") + 1, ev.lastIndexOf("}"));
    }
    else {
        ev = "";
    }
    var func = new Function("if ( !webnet_ConfirmationOnClick( this ) ){return false;} " + ev);
    
    confirmButton.onclick = func;
}

function webnet_ConfirmationOnClick( confirmButton ) {
   var strMessage = confirmButton.confirmationmessage;
   strMessage = strMessage.replace(/\\n/g, "\n");
    return confirm( strMessage );
}

// inicializace defaultních tlačítek
function webnet_AttachedButton_Init() {
   // pokud prohlížeč nepodporuje žádnou z metod getElementByID
   // ani document.all, 
   // tak nelze provést inicializaci
	if ( !webnet_AttachedButton_BrowserCapable() ) return false; 
	
	// v cyklu procházej všechna tlačítka definovaná v seznamu defaultních tlačítek
   for( var i=0; i<webnet_AttachedButtons.length; i++ ) {
      // každý záznam obsahuje 3 pole ClientID, PostBackEventReference, causesValidation
		var attachedButtonSetting = webnet_AttachedButtons[i].split("Â©");
		// pokud ne, tak skonci
		if ( attachedButtonSetting.length != 3 ) { return; }
		// naplneni promennych
		var inputControl = document.getElementById( attachedButtonSetting[0] ); //ClientID
		var postBackScript = attachedButtonSetting[1]; // PostBackEventReference
		var causesValidation = ( attachedButtonSetting[2] == 'True' ); 
		if ( inputControl != null ) { // pokud control existuje
			if ( i==0 ) { // u prvniho controlu inicializuj formular - reset nastaveni
				var theForm = inputControl.form;
				theForm.EnsureDefault = false;
				theForm.attachedButtonPostBackScript = "";
				theForm.causesValidation = false;
			}
			inputControl.attachedButtonPostBackScript = postBackScript;
			inputControl.causesValidation = causesValidation;
			
			if ( typeof( inputControl.addEventListener ) != "undefined" ) {
			   // je-li na controlu naveseny EventListener, pak naves na focus a blur moje funkce
				inputControl.addEventListener("focus",webnet_AttachedButton_RegisterDefault,false);
				inputControl.addEventListener("blur",webnet_AttachedButton_UnRegisterDefault,false);
			} else if ( typeof ( inputControl.attachEvent ) != "undefined" ) {
			   // je-li na controlu naveseny Event, pak naves na onfocus a onblur moje funkce
				inputControl.attachEvent("onfocus",webnet_AttachedButton_RegisterDefault);
				inputControl.attachEvent("onblur",webnet_AttachedButton_UnRegisterDefault);
			} else {
			   // jinak naves u controlu onfocus a onblur na moje funkce
				inputControl.onfocus = webnet_AttachedButton_RegisterDefault;
				inputControl.onblur = webnet_AttachedButton_UnRegisterDefault;
			}
		}
	}
}

// funkce kontroluje zda prohlizec podporuje getElementById nebo
// document.all, pokud podporuje jen document.all, vytvori funkci
// getElementById a tu na to navesi
function webnet_AttachedButton_BrowserCapable() {
	if ( typeof( document.getElementById ) == "undefined" ) {
		if( typeof( document.all ) != "undefined" ) {
			document.getElementById = function( elementId ) { return document.all[elementId]; };
		} else {
			return false;
		}
	}
	return true;
}

// funkce zaregistruje na formulari volani funkci pro kontrolu defualtnich tlacitek
function webnet_AttachedButton_RegisterDefault(e) {
   // ziskej element na ktery je navazana udalost e
	var src = webnet_AttachedButton_GetSrcElement(e);
	// a zaregistruj ho
	src.form.EnsureDefault = true;
	src.form.attachedButtonPostBackScript = src.attachedButtonPostBackScript;
	src.form.causesValidation = src.causesValidation;
}

// funkce odregistruje z formulare volani funkci pro kontrolu defualtnich tlacitek
function webnet_AttachedButton_UnRegisterDefault(e) {
   // ziskej element na ktery je navazana udalost e
	var src = webnet_AttachedButton_GetSrcElement(e);
	// a odregistruj ho
	src.form.EnsureDefault = false;
	src.form.attachedButtonPostBackScript = "";
	src.form.causesValidation = false;
}

// udalost navesena na Submit stranky
function webnet_AttachedButton_RequireOwnPostback(form) {
   // pokud ma formular overovat defaultni tlacitka a je definovany script pro 
   // postback u defaultnich tlacitek
	if ( form.EnsureDefault && form.attachedButtonPostBackScript != "" ) {
	   // zrus priznak overovani defaultnich tlacitek
		form.EnsureDefault = false;
		// a zavolej funkci ktera provede postback pro defaultni tlacitko
		window.setTimeout( 'webnet_AttachedButton_Postback( "' + form.attachedButtonPostBackScript + '", ' + form.causesValidation + ');', 10 );
		return true;
	} else {
		return false;
	}
}

// funkce ktera provede postback defaultniho tlacitka
function webnet_AttachedButton_Postback( postBackScript, causesValidation ) {
	if (typeof(Page_ClientValidate) == 'function' && causesValidation) {
		if (  Page_ClientValidate() ) {
			eval(postBackScript);
		}
	} else {
		eval(postBackScript);
	}
}

// funkce vrati element na ktery je navazana udalost e
function webnet_AttachedButton_GetSrcElement(e) {
   // jestli prohlizec podporuje window.event
	if ( typeof( window.event ) != "undefined" ) {
		return window.event.srcElement;
	}
	// pokud je udalost definovana a prohlizec podporuje e.target
	if ( e != null && typeof( e.target ) != "undefined" ) {
		return e.target;
	}
	return null;
}

function webnet_GetElementById(sElementID)
{
    if (document.getElementById) {
        return document.getElementById(sElementID);
    }
    else if (document.all) {
        return document.all[sElementID];
    }
    else return null;
}

function webnet_getInnerHTML(oElement)
{
	if (typeof(oElement.innerHTML) != 'undefined')
		return oElement.innerHTML;
	else
	{
		var strReturn = '';
		for (var i = 0; i < oElement.childNodes.length; i++)
			strReturn += webnet_getOuterHTML(oElement.childNodes[i]);

		return strReturn;
	}
}

function webnet_setInnerHTML(oElement, strValue)
{
	if (typeof(oElement.innerHTML) != 'undefined')
		oElement.innerHTML = strValue;
	else
	{
		var range = document.createRange();
		range.selectNodeContents(oElement);
		range.deleteContents();
		oElement.appendChild(range.createContextualFragment(strValue));
	}
}

function webnet_getOuterHTML(oNode)
{
	if (typeof(oNode.outerHTML) != 'undefined')
		return oNode.outerHTML;
	var str = '';
	switch (oNode.nodeType)
	{
		case 1: // Element, 2 Attribute
			str += '<' + oNode.nodeName;
    		for (var i = 0; i < oNode.attributes.length; i++)
			{
				if (oNode.attributes[i].nodeValue != null)
					str += ' ' + oNode.attributes[i].nodeName + '="' + oNode.attributes[i].nodeValue + '"';
			}
			if (oNode.childNodes.length == 0 && in_array(oNode.nodeName.toLowerCase(), ['hr', 'input', 'img', 'link', 'meta', 'br']))
				str += ' />';
			else
				str += '>' + webnet_getInnerHTML(node) + '</' + oNode.nodeName + '>';
			break;
		case 3: //Text
			str += oNode.nodeValue;
			break;
		case 4: // A CDATA section.
			str += '<![CDATA' + '[' + oNode.nodeValue + ']' + ']>';
			break;
		case 5: // Entity reference, 6 Actual entity, 7 PI
			str += '&' + oNode.nodeName + ';';
			break;
		case 8: //Comment
			str += '<!--' + oNode.nodeValue + '-->';
			break;
	}
	return str;
}

function webnet_setOuterHtml(oElement, strValue)
{
    if (typeof(oElement.outerHTML) != 'undefined')
        oElement.outerHTML = strValue;
    else
    {
        var range = document.createRange();
        range.setStartBefore(oElement);
        oElement.parentNode.replaceChild(range.createContextualFragment(strValue), oElement);
    }
}

function webnet_LinkButtonEx_PreventMultiplePostBack(strElementID, strWaitingText, strWaitingTitle, strWaitingClass)
{
    var oElement = webnet_GetElementById(strElementID);
    if(oElement)
    {
        var strNewElement;
        var strInnerHTML = webnet_getInnerHTML(oElement);
        if(strWaitingText.length > 0)
            strNewElement = "<span id=\"" + strElementID + "\">" + strWaitingText + "</span>";
        else
            strNewElement = "<span id=\"" + strElementID + "\">" + strInnerHTML + "</span>";
        webnet_setOuterHtml(oElement, strNewElement);
        oElement = webnet_GetElementById(strElementID);
        if(strWaitingTitle.length > 0)
            oElement.title = strWaitingTitle;
        if(strWaitingClass.length > 0)
            oElement.className = strWaitingClass;
    }
}

/*CalendarPicker functions start*/
function webnet_calendarpicker_controlselecteddate(picker)
{
    if ((picker.GetSelectedDate() == null) || (picker.GetSelectedDate() == new Date(1,1,1)))
        webnet_calendarpicker_clearselecteddate(picker);
}
function webnet_calendarpicker_clearselecteddate(picker)
{
  picker.ClearSelectedDate();
  picker.AssociatedCalendar.SetSelectedDate(picker.GetSelectedDate());
}
function webnet_calendarpicker_picker_keyup(picker)
{
  if (event.keyCode == 8)
  {
    webnet_calendarpicker_clearselecteddate(picker)
    event.cancelBubble=true;
    event.returnValue=false;
    return false;
  }
  else
  {
    return true;
  }
}
function webnet_calendarpicker_picker_onselectionchanged(picker)
{
  picker.AssociatedCalendar.SetSelectedDate(picker.GetSelectedDate());
}
function webnet_calendarpicker_calendar_onselectionchanged(calendar)
{
  calendar.AssociatedPicker.SetSelectedDate(calendar.GetSelectedDate());
}
function webnet_calendarpicker_imgbutton_onclick(alignElement, calendar)
{
  if (calendar.PopUpObjectShowing)
  {
    calendar.Hide();
  }
  else
  {
    calendar.SetSelectedDate(calendar.AssociatedPicker.GetSelectedDate());
    calendar.Show(alignElement);
  }
}
function webnet_calendarpicker_imgbutton_ondblclick(picker)
{
    webnet_calendarpicker_clearselecteddate(picker);
    picker.AssociatedCalendar.Hide();
}

function webnet_calendarpicker_imgbutton_onmouseup(calendar)
{
  if (calendar.PopUpObjectShowing)
  {
    event.cancelBubble=true;
    event.returnValue=false;
    return false;
  }
  else
  {
    return true;
  }
}
/*CalendarPicker functions end*/
