function SubmitForm(id)
{
	document.forms['form_'+id].submit();
}

function Redirect(url)
{
	self.location.href = url;	
}

function IfCheck(obj)
{
	if(obj.checked)
	{
		return 'true';
	}
	else
	{
		return 'false';
	}
}

function RedirectSubmit(ac)
{
	document.forms['form_-1'].form_main_ac.value = ac;
	SubmitForm('-1');
}

function OpenJSLWindow(url,w,h) 
{
	Fokus = window.open(url,'','scrollbars=0,resizable=0,top=0,status=1,left=0,menubar=0,width=' + w + ',height=' + h);
    Fokus.resizeTo(w,h)
	Fokus.focus()
}

function CheckValue(obj,value)
{
	if(obj.value == value)
	{
		obj.value = '';
	}
}

function RefreshParent(url)
{
	window.opener.location=url;
}

function set(obj,hodnota)
{
	if(obj.value != '')
	{
		obj.value = hodnota;
	}
}

function setOnBlur(obj,hodnota)
{
	if(obj.value == '')
	{
		obj.value = hodnota;
	}
}

function getLeft(o) {

    if (o == null) {
        return 0;
    }
    else {
        return o.offsetLeft + getLeft(o.offsetParent);
    }
}
function getTop(o) {
    if (o == null)
        return 0;
    else
        return o.offsetTop + getTop(o.offsetParent);
}

function igmenu_getTopPos(element) {
    var y = 0;
    var parent = element;
    while(parent != null) {
		if(parent.tagName=="BODY")
			break;
		y += parent.offsetTop;
        parent = parent.offsetParent;
	}
  return y;
}
function igmenu_getLeftPos(element) {
    var x = 0;
    var parent = element;
    while (parent != null) {
		if(parent.tagName=="BODY")
			break;
        x += parent.offsetLeft;
        parent = parent.offsetParent;
    }
    return x;
}
function f_clientWidth() {
    return f_filterResults(
		window.innerWidth ? window.innerWidth : 0,
		document.documentElement ? document.documentElement.clientWidth : 0,
		document.body ? document.body.clientWidth : 0
	);
}
function f_clientHeight() {
    return f_filterResults(
		window.innerHeight ? window.innerHeight : 0,
		document.documentElement ? document.documentElement.clientHeight : 0,
		document.body ? document.body.clientHeight : 0
	);
}
function f_scrollLeft() {
    return f_filterResults(
		window.pageXOffset ? window.pageXOffset : 0,
		document.documentElement ? document.documentElement.scrollLeft : 0,
		document.body ? document.body.scrollLeft : 0
	);
}
function f_scrollTop() {
    return f_filterResults(
		window.pageYOffset ? window.pageYOffset : 0,
		document.documentElement ? document.documentElement.scrollTop : 0,
		document.body ? document.body.scrollTop : 0
	);
}
function f_filterResults(n_win, n_docel, n_body) {
    var n_result = n_win ? n_win : 0;
    if (n_docel && (!n_result || (n_result > n_docel)))
        n_result = n_docel;
    return n_body && (!n_result || (n_result > n_body)) ? n_body : n_result;
}

var ShowPanelPriceQtyPrev = null;
function ShowPanelPriceQty(pButton, pID, pAlign) {
    var p = document.getElementById(pID);
    if (p == null)
        return;

    var pTop = 0;
    var pLeft = 0;

    p.style.display = (p.style.display == 'none' ? '' : 'none');
    var y = getTop(pButton);
    //p.style.top = igmenu_getTopPos(pButton); p.style.left = igmenu_getLeftPos(pButton) + pButton.offsetWidth + 10;
    pTop = y + pButton.offsetHeight + 10;
    //p.style.left = igmenu_getLeftPos(pButton);
    if (pAlign == 'right')
        pLeft = getLeft(pButton) - (p.offsetWidth - pButton.offsetWidth) + 2;
    else
        pLeft = getLeft(pButton);

    var scrt = f_scrollTop();
    var docheight = f_clientHeight();

    if (y - scrt > 400) {
        pTop = y - p.offsetHeight - 10;
    }

    p.style.left = pLeft + 'px';
    p.style.top = pTop + 'px';


    if (ShowPanelPriceQtyPrev != null && ShowPanelPriceQtyPrev != p) {
        ShowPanelPriceQtyPrev.style.display = 'none';
    }

    ShowPanelPriceQtyPrev = p;
}
function ChoosePriceQty(pAnchor, pName) {
    var q = document.getElementsByName(pName);
    if (q == null)
        return;
    if (q.length == 0)
        return;

    q.item(0).value = pAnchor.innerHTML;
    if (ShowPanelPriceQtyPrev != null)
        ShowPanelPriceQtyPrev.style.display = 'none';
}

function goDoc() {
    var docNum = document.getElementById('DocNum');
    var docType = document.getElementById('DocType');
    var cls = docType.options[docType.selectedIndex].value;

    if (docNum.value == '') return false;
    if (cls == '') return false;

    document.location.href = 'main.aspx?cls=' + escape(cls) + '&doc_no=' + escape(docNum.value);

    return false;
  }
  function getServerDataPriceQty(pTag, pProId, pQty, pAlign) {
    var url = 'maindata.aspx?cls=priceqty&pro_id=' + pProId + "&qty_min=" + pQty;
    //getServerData(pTag, url, 'queue', 'wwindow');
    getServerData(pTag, url, 'pnMainData', 'wwindow', pAlign);
  }
  var getServerDataTagClick;
  var getServerDataRequest = null;
  function getServerDataRequestOnreadystatechange()
  {
    if (getServerDataRequest.readyState == 4 /* complete */) {
      if (getServerDataRequest.status == 200) {
        ShowWindows(getServerDataRequest.responseText, true);
      }
    }
  }
  function getServerDataRequestOnLoad()
  {
    ShowWindows(getServerDataRequest.responseText, true);
  }
  function getServerData(pTag, pUrl, pIdFrom, pIdTo, pAlign) {
    //window.alert(pUrl);
    
    var ifrm = document.getElementById('fwindow');
    if (ifrm == null)
      return;
    
    ifrm.setAttribute('tagFrom', pIdFrom);
    ifrm.setAttribute('tagTo', pIdTo);
    ifrm.setAttribute('tagAlign', pAlign);
    getServerDataTagClick = pTag;

    ShowWindows(document.getElementById('wwaitprice').innerHTML, false);

    var d = new Date();
    var downloadurl = pUrl + '&tista=' + d.getTime() + '' + d.getMilliseconds();

    getServerDataRequest = getXMLHTTPRequest();
    getServerDataRequest.open("GET", downloadurl, true);
    getServerDataRequest.send();
    getServerDataRequest.onload = getServerDataRequestOnLoad;
    getServerDataRequest.onreadystatechange = getServerDataRequestOnreadystatechange;
    //window.alert(downloadurl);
    //ifrm.src = downloadurl;
    
  }
  function getServerDownloads() {

    var ifrm = document.getElementById('fwindow');
    if (ifrm.attributes['tagFrom'] == null)
      return;

    var tagFrom = ifrm.contentWindow.document.getElementById(ifrm.attributes['tagFrom'].nodeValue);
    if (tagFrom == null)
      return;

    ShowWindows(tagFrom, true);
  }
  function ShowWindowsFromTag(pFrom, pCloseEvent) {
    ShowWindows(pFrom.innerHTML, pCloseEvent);
  }
  function ShowWindows(pHtml, pCloseEvent) {
    var ifrm = document.getElementById('fwindow');
    if (ifrm.attributes['tagFrom'] == null)
      return;

    var scrt = f_scrollTop();
    var docheight = f_clientHeight();

    var tagTo = document.getElementById(ifrm.attributes['tagTo'].nodeValue);
    if (tagTo == null)
      return;

    var tagToBody = document.getElementById(ifrm.attributes['tagTo'].nodeValue + 'body');
    if (tagToBody == null)
      tagToBody = tagTo;

    tagToBody.innerHTML = pHtml;
    tagTo.style.display = '';

    if (tagTo.style.position == '')
      return;
    var tleft = getLeft(getServerDataTagClick);
    var ttop = (getTop(getServerDataTagClick) + getServerDataTagClick.offsetHeight + 5);
    var talign = ifrm.attributes['tagAlign'].nodeValue;

    if (talign == 'left')
      tleft = tleft - tagTo.offsetWidth + getServerDataTagClick.offsetWidth;
    if (talign == 'windowcenter') {
      ttop = 100;
      tleft = f_clientWidth();
      if (tleft > tagTo.offsetWidth)
        tleft = Math.round((tleft - tagTo.offsetWidth) / 2);
      else
        tleft = 0;
    }
    else if (ttop-scrt > (docheight + tagTo.offsetHeight)/2) {
      ttop = ttop - getServerDataTagClick.offsetHeight - tagTo.offsetHeight - 10;
    }

    tagTo.style.left = '' + tleft + 'px';
    tagTo.style.top = '' + ttop + 'px';

    if (pCloseEvent)
      document.body.onclick = closewwindowbody;
  }
  function closewwindowbody(ev) {
    ev = ev || window.event;
    var obj = ev.target || ev.srcElement;
    if (obj.tagName == 'A')
      return;
    if (obj.parentNode != null && obj.parentNode.tagName == 'A')
      return;

    closewwindow();
    return;
  }
  function closewwindow() {
    var ww = document.getElementById('wwindow');
    ww.style.display = 'none';
    document.body.onclick = null;
  }

  function getXMLHTTPRequest() {
    try {
      req = new XMLHttpRequest();
    } catch (err1) {
      try {
        req = new ActiveXObject("Msxml2.XMLHTTP");
      } catch (err2) {
        try {
          req = new ActiveXObject("Microsoft.XMLHTTP");
        } catch (err3) {
          req = false;
        }
      }
    }
    return req;
  }
