﻿
isPageLoad = false
addStartEvent(function(){isPageLoad = true})

function up(obj)
{
//	if(obj == null) obj = this
//	obj.className="buttonsOver";
	this.className="buttonsOver";
}
function dn(obj)
{
//	if(obj == null) obj = this
//	obj.className="buttonsDown";
	this.className="buttonsDown";
}
function out(obj)
{
//	if(obj == null) obj = this
//	obj.className="buttonsOut";
	this.className="buttonsOut";
}

function itemUp(obj)
{
	obj.style.border="outset 2px";
}
function itemDn(obj)
{
	obj.style.border="inset 2px";
}

function MyWindowOpen(url,win_id,width,height,resizeable,scrollable)
 {   
   //alert('Spustam ' + win_id);
 /*  xpos = (document.body.offsetWidth - width)/2;
   ypos = (document.body.offsetHeight - height)/2; */
   //alert('SCREEN.W=' + screen.width  + 'SCRREN.H=' + screen.height);
   //alert('WIDTH=' + width  + 'HEIGHT=' + height);
   xpos = (screen.availWidth - width)/2;
   ypos = (screen.availHeight - height)/2;
   myWin = self.open(url,win_id,'top=' + ypos + ',left=' + xpos +',width='+width+',height='+height+',scrollbars='+scrollable+',resizable='+resizeable+',status=yes')
   myWin.focus();
   return myWin;
 }

function MyWindowPopup(name,x,y,w,h,html)
{ 
 var popup = self.open('',name,'top=' + y + ',left=' + x + ',width=' + w + ',height=' + h + ',scrollbars=auto,resizeble=no,status=no'); 
 popup.document.body.style.backgroundColor="lightyellow";
 popup.document.body.style.border= "solid black 1px";
 popup.document.title=name;
 popup.document.body.innerHTML = "<div width='100%' style='cursor:pointer' onclick='self.close()'>" + html + "</div>";
 
 //popup.show(5,5,x,y,elm); 
}
function GetColor()
{
	MyWindowOpen(GetRootPath() + '/Admin/Forms/Colorer.html','Colorer',300,400,false,false);
}

function CisRecordEdit(layout,pk1,pk2)
{
	MyWindowOpen(GetRootPath() + '/Moduly/Common/Forms/CisRecordEdit.aspx?layout=' + layout,'Cis' + pk1 + pk2,400,500,false,false);
}

var refMax = 100;
var refCount = 0;
function AutoRefresh()
{			
	refCount++;
	if (refCount < refMax)
	{		
		var	img = new Image(1,1);	
		img.src = GetRootPath() + '/Admin/refresh.aspx';
		window.status = 'Link to Server Refreshed ' + refCount.toString()+' time(s)';
	}
}

function SetAutoRefresh(seconds)
{	
	window.setInterval("AutoRefresh()",1000*seconds);
}

function TovarStrom(mode)
{
	var url = GetRootPath() + '/detail.aspx?content=detail&nid=2&mode=' + mode;	
	MyWindowOpen(url,'TVRTREE',250,450,true,true);
}

function AccessLevel(controlId,currentAR,primaryKey,idCis)
{
	var addOn = '';
	if( primaryKey != null )	
				addOn = '&pk=' + primaryKey;
	
	MyWindowOpen( GetRootPath() + '/Controls/AccessLevel/AccessLevel.aspx?control=' + controlId + '&ar='+ currentAR + addOn ,'AL',300,400,true,true);
}
 
 
var popUp; 

function OpenCalendar(idname, postBack, time, yearFrom, yearTo,sharedDatumField, sharedInterval)
{ 	var addOn = '';
	if(time != null && time != 'no' && time != 'false' && time != false)
		addOn += '&time=True';

	if(yearFrom != null && !isNaN(yearFrom))
		addOn += '&from='+yearFrom
		
	if(yearTo != null && !isNaN(yearTo))
		addOn += '&to='+yearTo
		
	if(sharedDatumField != null && sharedDatumField != '')
	    addOn += '&sdf='+sharedDatumField;
	    
	if(sharedInterval != null )
	    addOn += '&shint='+sharedInterval;
	    

	popUp = window.open(GetRootPath() + '/Controls/Calendar/Calendar.aspx?formname=' + document.forms[0].name + 
		'&id=' + idname + '&selected=' + document.forms[0].elements[idname].value + '&postBack=' + postBack + addOn, 
		'popupcal', 
		'width=176,height=250,left=200,top=250');
}

function SetDate(formName, id, newDate, postBack)
{

	eval('var theform = document.' + formName + ';');
	popUp.close();
	theform.elements[id].value = newDate;
	if (postBack)
		__doPostBack(id,'');
}	


function Koder(id_cis,clientId,submit,quickselect,extrapar,mode)
{
	/*if( extrapar != null )
	 alert("Sql podm:" + extrapar);
	 */
	 if( mode == null )
		mode = 0;
	MyWindowOpen(GetRootPath() + "/Moduly/Common/Forms/Koder.aspx?id_cis=" + id_cis + "&id=" + clientId + "&submit=" + submit  + "&quick=" + quickselect + '&ep=' +  extrapar + '&mode=' + mode ,"Koder",800,280,'no','no');
}

function PopUpKoder(id_cis,clientId,submit,quickselect,extrapar,max)
{

	
	var url = "PopUpKoder.ashx?id_cis=" + id_cis + "&id=" + clientId + "&submit=" + submit  + "&quick=" + quickselect + '&ep=' +  extrapar + '&max=' + max;		
	UniMenu(url,id_cis);
}


function CisTreeKoder(id_cis,controlId,submit)
{
// window.opener.controlId.value = hodnota;
  //  + window.opener.__doPostBack('','');
  //Form1.controlId.value="ok";
  alert('ok');
}

function TovarInsert()
{
	MyWindowOpen( GetRootPath() + '/Moduly/Shop/Schemy/TovarInsert.aspx' ,'TovarInsert',450,400,true,true);
}




function CisProp(primarykey,idcis)
{
	//alert('Vlastnosti zaznamu s primarny klucom:' + primarykey +' a vzhladom ' + layout);
	//MyWindowOpen(GetRootPath() + '/Moduly/Common/Forms/CisRecordInfo.aspx?pk=' + primarykey + '&layout=' + layout ,'Prop' + primarykey ,400,450,true,true); 
	if( idcis == 263 )
	{
		DetailOP(primarykey);	
	}
	else
		MyWindowOpen(GetRootPath() + '/Moduly/Common/Forms/CisProperties.aspx?pk=' + primarykey  + '&idcis=' + idcis ,'cisp' + primarykey ,650,450,true,true); 		
}

function CisEdit(primarykey,idcis)
{
	//alert('Editacia zaznamu s primarny klucom:' + primarykey +' a vzhladom ' + layout);
	//MyWindowOpen(GetRootPath() + '/Moduly/Common/Forms/CisRecordEdit.aspx?pk=' + primarykey + '&layout=' + layout ,'Prop' + primarykey ,400,450,true,true); 		
	MyWindowOpen(GetRootPath() + '/Moduly/Common/Forms/CisProperties.aspx?pk=' + primarykey + '&idcis=' + idcis,'cisp' + primarykey ,650,450,true,true); 		
}

function CisId(cislo,par)
{//alert(cislo)
	switch(cislo)
	{
		case 7: Detail(1220,'pk;'+par); return
		case 90: Detail(61,'idk;'+par); return
		case 51: Detail(1093,'id;'+par); return
		case 'kon': Detail(1098,'kon;'+par); return
		case 266: Detail(1089,'RID;'+par); return
	}
}

function AddSysField()
{
	MyWindowOpen(GetRootPath() + '/Moduly/Common/Forms/AddSysField.aspx' ,'ASF' ,600,450,true,true); 			
}

function CisEngine(id)
{
	//alert('Vlastnosti pre zaznam '  + id);	
	MyWindowOpen(GetRootPath() + '/Moduly/Common/Forms/CisProperties.aspx?id=' + id ,'ASF' ,600,450,true,true); 		
}

function DDetail(masterId,nid,nparams,inline,width,height)
{
	var loc = '/detail.aspx';
	var url = GetRootPath() + loc + '?content=detail&nid=' + nid + '&mid=' + masterId;
	if( nparams != null && nparams != '' )
		url += '&nparams=' + nparams;
	if(width == "max") width = screen.availWidth
	if(height == "max") height = screen.availHeight
	if(!width) width = 200;
	if(!height) { height = 200; url += "&resizeme=yes"; }
		else url = url.concat("&resizeme=no");
	MyWindowOpen(url,'NID' + nid,width,height,'no','auto');	
}

function Detail(nid,nparams,inline,width,height,resizable)
{

	var loc = '';
	var scroll = "yes"
	if(nid == null || nid == '')
		return;
	if(!inline) 
		loc = GetRootPath() + '/detail.aspx';
	else
		loc = 'http://' + window.location.host + location.pathname; 

	var windowName = 'NID' + nid;    
	if(nparams != null && nparams.length)
	if(nparams.charAt(0) == "$")
	{	
		var endSeq = nparams.indexOf("$",1)
		if(endSeq !== false)
		{
			var params = nparams.substring(1, endSeq).split(";")
			for(var n = 0; n < params.length; n+=2)
				params[params[n]] = params[n+1]
			if(endSeq < nparams.length-1)
				nparams = nparams.substr(endSeq+1)
			else nparams = ""

			if( params["winid"] != null )
				windowName = params["winid"];

			if(params["scroll"] != null)
			{
				scroll = params["scroll"]				
			}
		}
	}

	var url = loc + '?nid=' + nid;
	if( nparams != null && nparams != '' )
		url += '&nparams=' + nparams;
	if( inline != null && inline != false )
	{
		//alert(url);
		location=url;
	}
	else
	{
		temp = '';
		if(width == "max") width = screen.availWidth
		if(height == "max") height = screen.availHeight

		if(!width || width == null) { sirka = 200; }
		else { sirka = width; temp += '&width=' + width; }
		if(!height || height == null) { vyska = 200; }
		else { vyska = height; temp += '&height=' + height;  }

		if(!width || width == null || !height || height == null) url += "&resizeme=yes"+temp;
		else url = url.concat("&resizeme=no");
		if(resizable == null || resizable == "") resizable = "yes"
		
		MyWindowOpen(url,windowName,sirka,vyska,resizable,scroll);
	}
}


function ShopJump(val,content)
{	
	pars = val.split(';');
	finContent = 'SHOP';	
	if( content != null )
		finContent = content;
	url='?content=' + finContent;
	nparams = '';
	if( pars[0] != null )
	{	 
	 nparams +='typ_t;' + pars[0];
	}
	if( pars[1] != null && pars[1] != '' )
	{
	 if(nparams != '' )
		nparams += ';';
	 nparams +='vyr;' + pars[1];
	}
	if( nparams != '' )
	  url = url + '&nparams=' + nparams;	
	
	window.location = url;
	
}

function AutoResize(width, height)
{
	var pridavok = 20
	var tbl1 = getE("t1")
	if (tbl1 == null) return
	var center =  ( getParam('center') != 'no')

	if(!width || width == null) width = tbl1.offsetWidth + tbl1.offsetLeft * 2
	if(!height || height == null) height = tbl1.offsetHeight + tbl1.offsetTop * 2

	if(width == document.body.clientWidth && height == document.body.clientHeight) return

	widthavail = screen.availWidth
	heightavail = screen.availHeight
	if(width > widthavail) width = widthavail
	if(height > heightavail) height = heightavail
	var rezervaX = widthavail - width
	var rezervaY = heightavail - height
	if(pridavok > rezervaY) pridavok = rezervaY
	
    if(center && width != -1)
    {        
		xpos = (screen.width - width)/2
		ypos = (heightavail - height)/2
		window.moveTo(xpos, ypos)
	}

	var rozdielX = 0
	if(width != -1)
	{
		window.resizeTo(width, height + pridavok);
		rozdielX = width - document.body.clientWidth
		if(rozdielX > rezervaX) rozdielX = rezervaX
	}

	var rozdielY = height - document.body.clientHeight
	if(rozdielY > rezervaY) rozdielY = rezervaY
	window.resizeBy(rozdielX, rozdielY)	
	if(center)
	{
	    window.moveBy(-rozdielX/2, -rozdielY/2)
	}
	
}

function NewSerZak(sk,op,md)
{
	var query='';	
	if(sk != null )
		query += '&sk=' + sk;
	if(op != null )
		query += '&op=' + op;
	if(md != null )
		query += '&md=' + md;

	MyWindowOpen(GetRootPath() + '/Moduly/System/Forms/NewSerZak.aspx?in=1' + query,'NSZ' ,510,550,"yes","yes"); 		
}


function NewSerZakO(rid,id_r)
{
	var addOn = '';
		if( id_r != null )
				addOn = '&idr=' + id_r;
	MyWindowOpen(GetRootPath() + '/Moduly/System/Forms/NewSerZakO.aspx?rid=' + rid + addOn ,'NSZO' + rid ,460,200,"no","no"); 
	
}


function EditSerZar(id)
{
	MyWindowOpen(GetRootPath() + '/Moduly/System/Forms/NewSerZar.aspx?svk=' + id ,'EDITSZ' + id ,510,550,"no","no");
}


function NewSerZar(skid,sn,rid)
{
	if(skid == null )
	{
		alert('Nezadaná skladová karta');
		return ;
   }	
    var addOn = '';
    if(sn != null )
    {
		addOn = '&sn=' + sn;
    }
    if(rid != null)
    {
		addOn = addOn + '&mrid=' + rid;
	}
	MyWindowOpen(GetRootPath() + '/Moduly/System/Forms/NewSerZar.aspx?skid=' + skid + addOn,'NEWSZ' ,510,550,"no","no"); 		
}

function NewFD(typ,rid_p,rid_m)
{
	MyWindowOpen(GetRootPath() + '/Moduly/System/Forms/NewFD.aspx?typ=' + typ + '&rid_p=' + rid_p + '&rid_m=' + rid_m ,'NFD' ,400,300,"no","no");
}

function MessageBox(caption,message)
{
	var oNewWindow = window.open('','','width=400,height=200,left=200,top=150,scrollbars=yes,resizable=yes');
	var sMsg = '<HTML><HEAD><TITLE>'+caption+'</TITLE></HEAD><BODY bgColor=\"activeborder\" style="font-size:8pt;font-face:verdana">'+message + '</BODY></HTML>';
	oNewWindow.document.write(sMsg);
}
	
function DetailPic(image)
{
	MyWindowOpen(GetRootPath() + "/Controls/DetailPic/detailpic.aspx?img=" + image,"imgwin",300,300,'yes','auto');		
}


function CRView(rid,prn,nparams)
{
	MyWindowOpen(GetRootPath() + "/Moduly/Common/Forms/ReportViewer.aspx?rid=" + rid +'&prn=' + prn + '&nparams=' + nparams,"RV" + rid,800,600,'yes','yes');		
}	


function Favorit(idcis,ridv,iduser)
{
	if( idcis == null || ridv== null )
								return;
	var url = GetRootPath() + "/Moduly/Common/Forms/UserFavorit.aspx?idcis=" + idcis + "&ridv=" + ridv;
	if(iduser!= null)
	{
		url = url + '&uid=' + iduser;
	}
	MyWindowOpen(url,'UF',320,50,'no','no');

}

function ChangeTree(ridorcis,ctrl,selected,snode)
{
	if( ridorcis== null )
				return;
	var url = GetRootPath() + "/Moduly/Common/Forms/ChangeTree.aspx?ridv=" + ridorcis;	
	if(snode != null)	
		url = url + '&snode=' + snode;
	if( ctrl != null)
		url = url + '&ctrl=' +  ctrl;
	if( selected != null)
		url = url + '&sel=' +  selected;
	MyWindowOpen(url,'CT',320,500,'yes','yes');

}


function QV(rid)
{
	Detail(20,'rid;' + rid ,false,910,500);
}



// Global variables
xMousePos = 0; // Horizontal position of the mouse on the screen
yMousePos = 0; // Vertical position of the mouse on the screen
xMousePosMax = 0; // Width of the page
yMousePosMax = 0; // Height of the page

mouseCapturingOn = false
function EnableMouseCapturing()
{
	if(mouseCapturingOn) return
	// Set Netscape up to run the "captureMousePosition" function whenever
	// the mouse is moved. For Internet Explorer and Netscape 6, you can capture
	// the movement a little easier.
	window.status='Capturing enabled';
	if (document.layers) { // Netscape
		document.captureEvents(Event.MOUSEMOVE);
		document.onmousemove = captureMousePosition;
	} else if (document.all) { // Internet Explorer
		document.onmousemove = captureMousePosition;
	} else if (document.getElementById) { // Netcsape 6
		document.onmousemove = captureMousePosition;  
}
mouseCapturingOn = true
}

function captureMousePosition(e) {
    if (document.layers) {
        // When the page scrolls in Netscape, the event's mouse position
        // reflects the absolute position on the screen. innerHight/Width
        // is the position from the top/left of the screen that the user is
        // looking at. pageX/YOffset is the amount that the user has
        // scrolled into the page. So the values will be in relation to
        // each other as the total offsets into the page, no matter if
        // the user has scrolled or not.
        xMousePos = e.pageX;
        yMousePos = e.pageY;
        xMousePosMax = window.innerWidth+window.pageXOffset;
        yMousePosMax = window.innerHeight+window.pageYOffset;
    } else if (document.all) {
        // When the page scrolls in IE, the event's mouse position
        // reflects the position from the top/left of the screen the
        // user is looking at. scrollLeft/Top is the amount the user
        // has scrolled into the page. clientWidth/Height is the height/
        // width of the current page the user is looking at. So, to be
        // consistent with Netscape (above), add the scroll offsets to
        // both so we end up with an absolute value on the page, no
        // matter if the user has scrolled or not.
        xMousePos = window.event.x+document.body.scrollLeft;
        yMousePos = window.event.y+document.body.scrollTop;
        xMousePosMax = document.body.clientWidth+document.body.scrollLeft;
        yMousePosMax = document.body.clientHeight+document.body.scrollTop;
    } else if (document.getElementById) {
        // Netscape 6 behaves the same as Netscape 4 in this regard
        xMousePos = e.pageX;
        yMousePos = e.pageY;
        xMousePosMax = window.innerWidth+window.pageXOffset;
        yMousePosMax = window.innerHeight+window.pageYOffset;
    }
}


/** XHConn - Simple XMLHTTP Interface - bfults@gmail.com - 2005-04-08        **
 ** Code licensed under Creative Commons Attribution-ShareAlike License      **
 ** http://creativecommons.org/licenses/by-sa/2.0/                           **/
function XHConn()
{
  var xmlhttp, bComplete = false;
  try { xmlhttp = new ActiveXObject("Msxml2.XMLHTTP"); }
  catch (e) { try { xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); }
  catch (e) { try { xmlhttp = new XMLHttpRequest(); }
  catch (e) { xmlhttp = false; }}}
  if (!xmlhttp) return null;
  this.connect = function(sURL, sMethod, sVars, fnDone)
  {
    if (!xmlhttp) return false;
    bComplete = false;
    sMethod = sMethod.toUpperCase();

    try {
      if (sMethod == "GET")
      {
        xmlhttp.open(sMethod, sURL+"?"+sVars, true);
        sVars = "";
      }
      else
      {
        xmlhttp.open(sMethod, sURL, true);
        xmlhttp.setRequestHeader("Method", "POST "+sURL+" HTTP/1.1");
        xmlhttp.setRequestHeader("Content-Type",
          "application/x-www-form-urlencoded");
      }
      xmlhttp.onreadystatechange = function(){
        if (xmlhttp.readyState == 4 && !bComplete)
        {
          bComplete = true;
          fnDone(xmlhttp);
        }};
      xmlhttp.send(sVars);
    }
    catch(z) { return false; }
    return true;
  };
  return this;
}


var selectedPopUp=null;
var selectedPopUpItem=null;
var popup_delay_msec=500;
var popupTimerID=null; 

function popupOff()
{		
	clearTimeout(popupTimerID);
	popupTimerID=null;
	if(selectedPopUp != null)
	{
//			selectedPopUp.parentElement.style.visibility="hidden";
		selectedPopUp.style.visibility="hidden";
		selectedPopUp=null;
		selectedPopUpItem=null;
	}
}


function PopUpOn(sPopUpId,x,y)
{
	if(selectedPopUp!=sPopUpId && sPopUpId != null)
	{
		if(selectedPopUp!=null) popupOff();
		selectedPopUp=sPopUpId;
		sPopUpId.style.left= x + "px";
		sPopUpId.style.top= y + "px";
		//sPopUpId.parentElement.style.visibility="visible";
		//alert(sPopUpId.id + ':' + sPopUpId.style.left+", "+sPopUpId.style.top + ' ' + sPopUpId.style.position )
		sPopUpId.style.visibility="visible";
		var firstTD = sPopUpId.getElementsByTagName("TD")[0]
		if(firstTD.className != "tblSlideMenuLabel") PopUpItemOn(firstTD)
		//PopUpOff()
	}
	else
	{
		clearTimeout(popupTimerID); 
		popupTimerID=null;
	}
}

function PopUpOff()
{
   popupTimerID=setTimeout("popupOff()",popup_delay_msec);
}

function PopUpItemOn(popUpItem)
{	
	clearTimeout(popupTimerID);	
	popupTimerID=null;
	if(popUpItem == null) return
	selectedPopUpItem=popUpItem;
	popUpItem.className='tblSlideMenuOn';
}

function PopUpItemOff(popUpItem)
{
	if(popUpItem != null)
	{
		popUpItem.className='tblSlideMenuOff';
		selectedPopUpItem=null;
	}
	PopUpOff();
}

function BarISMenuCis(zalId,idCis,obj)
{
        if( zalId == '' )  zalId = '0';
       if( getE(obj.id + 'Val').value == ''  )
            return;
       var nparams = 'CISID;' + idCis + ';VAL;' + getE(obj.id + 'Val').value + ';TEXT;' + obj.value;      
       BarISMenu(zalId,nparams);

}

function BarISMenu(zalId,nparams)
{				
	if( zalId == '' )  zalId = '0';
	UniMenu(GetRootPath() + "/menu.ashx",zalId,nparams);	  	
	//MenuOn("prop"+zalId)
}

function UniMenu(source,zalId,nparams)
{
    if(!mouseCapturingOn)
    {
//	    xMousePos = window.event.x+document.body.scrollLeft;
//        yMousePos = window.event.y+document.body.scrollTop;
	    xMousePos = window.event.x;
        yMousePos = window.event.y;
    }
    else
    {
	    xMousePos -= document.body.scrollLeft;
        yMousePos -= document.body.scrollTop;
    }
    
	var myConn = new XHConn();
	var fnWhenDone = function (oXML) 
	{
		InLinePopUp('prop' + zalId, oXML.responseText);
		document.getElementsByTagName("BODY")[0].style.cursor = "default"
	}
		
	if (!myConn) 
		alert("XMLHTTP not available. Try a newer/better browser.");
	else document.getElementsByTagName("BODY")[0].style.cursor = "wait"
	myConn.connect(source, "POST", "id=" + zalId + "&nparams=" + nparams, fnWhenDone);
}


function InLinePopUp(popUpId, obsah)
{
	var x = 0;
	var y = 0;
	if(obsah == null)
	{
		var objIn = getE(popUpId);
		objIn.onmouseover = function(){PopUpOn(this)}
		objIn.onmouseout = function(){PopUpOff(this)}
	}
	else
	{
		var inData = getE("inlineData");
		inData.innerHTML = obsah;
		var objIn = getE(popUpId);
	}

	if(window.event)
	{
		e = window.event
		x = e.clientX
		y = e.clientY
	}
	else
	{
		x = xMousePos
		y = yMousePos
	}


	if(x + objIn.offsetWidth > document.body.clientWidth) x = x - objIn.offsetWidth + 8;
	else x -= 8;
/*
	if(yMousePos + inData.offsetHeight > document.body.clientHeight)
	{
		inData.style.overflow = 'auto';
		inData.style.width = inData.offsetWidth + 16 + "px";
		inData.style.height = document.body.clientHeight - y + "px";
	}
*/
	y -= 8;
	PopUpOn(objIn,x+document.body.scrollLeft,y+document.body.scrollTop);
}



function DmsAction(action,rid,retControl,submit)
{  
  if( rid == null || rid == '' )
  {
	alert('Nie je vybrany dokument.');
	return;
   }
     
  if( action == null || action == '' )
  {
	alert('Ziadna akcia k dispozicii.');
	return;
   }
  MyWindowOpen(GetRootPath() +  '/Moduly/BArchive/Forms/DmsAction.aspx?aid=' + action + '&rid=' + rid +  '&control=' + retControl + '&submit=' +  submit ,'MoveAction',450,250);   
   return false;
}

function switchItem(obj, obr)
{
	hideItem(obj)

	if(obr.src.indexOf("minus") != -1) obr.src = obr.src.replace(/minus/,"plus")
	else obr.src = obr.src.replace(/plus/,"minus")
}

function hideItem(item,clearInput)
{

    var obj = getE(item);
	if(obj.style.display == '')
	{
		obj.style.display='none'
		if( clearInput)
		    obj.value = '';		    
	
	}
	else
	{
		obj.style.display=''
		if( clearInput)
		    obj.focus();
	}
}

//var hideStkStep = 10
//var hideStkTime = 10
function hideStk(obj, item, itemState)
{
	var stkBody = getE('stk' + item).rows[1]
	if(stkBody.style.display == '')
	{
//		hideStkAnim(item, hideStkStep)
		stkBody.style.display='none'
		getE(itemState).value=2;
		obj.src = "images/system/shift_dn.gif"
		obj.title = "show"
	}
	else
	{
		stkBody.style.display=''
		getE(itemState).value=1;
		obj.src = "images/system/shift_up.gif"
		obj.title = "hide"
	}
}
/*
function hideStkAnim(item, n, vyska)
{
	var stkBody = getE('stk' + item).rows[1]
	n--
	if(n == 0)
	{
		stkBody.style.display='none'
		stkBody.style.height = "auto"
		return
	}
	
	if(vyska == null) vyska = stkBody.offsetHeight
	stkBody.style.height = Math.round(vyska / hideStkStep * n) + "px"
	setTimeout("hideStkAnim('"+item+"',"+n+","+vyska+")", hideStkTime)
}
*/
function PLSQL(id,nparams)
{		
	var url = GetRootPath() + "/Moduly/Common/Forms/PLSQL.aspx?id=" + id + "&nparams=" + nparams;
//	alert(url);
	MyWindowOpen(url,'UF',320,50,'no','no');
}

function changeClass(obj, mode)
{
	var baseClass
	var poz = obj.className.indexOf("ROERR")

	if(poz == -1) poz = obj.className.indexOf("ERR")
	if(poz == -1) poz = obj.className.indexOf("RO")
	if(poz == -1) baseClass = obj.className
	else baseClass = obj.className.substr(0,poz)
	
	obj.className = baseClass + mode
	if(mode == "RO" || mode == "ROERR") obj.readOnly = true
	else obj.readOnly = false
}

function popUpMenu(id, popis, width)
{
	if(width == null) width = 100
	var temp = '<TABLE class="tblSlideMenu" id="s'+id+'" style="width:'+width+'px" CELLSPACING="0">'
	
	for(n in popis)
		temp += '<TR><TD onmouseover="PopUpItemOn(this)" onmouseout="PopUpItemOff(this)" onclick="popupOff();'+ id +'('+ n +')">'+ popis[n] +'</TD></TR>'

	temp += '</TABLE>'
	InLinePopUp("s"+id, temp);
}

function DatumOdDo(obj1, obj2)
{
	datumOdId = obj1
	datumDoId = obj2
	var popis = new Array("dnes", "akt. t&#253;&#382;de&#328;", "akt. mesiac", "1. kvart&#225;l", "2. kvart&#225;l", "3. kvart&#225;l", "4. kvart&#225;l", "akt. rok", "minul&#253; rok", "Janu&#225;r", "Febru&#225;r", "Marec", "Apr&#237;l", "M&#225;j", "J&#250;n", "J&#250;l", "August", "September", "Okt&#243;ber", "November", "December")
	popUpMenu("menuDatum", popis)
}

function menuDatum(n)
{
	putDates(datumOdId, datumDoId, n)
}

function putDates(obj1Id, obj2Id, n)
{
	obj1 = getE(obj1Id)
	obj2 = getE(obj2Id)

	var date = new Date()
	den = date.getDate()
	mesiac = date.getMonth() + 1
	rok = date.getFullYear()
	PocetDni = pocetDni()

	switch(n)
	{
		case 0: // dnes
			obj1.value = obj2.value = den +"."+ mesiac +"."+ rok
			break
		case 1: //akt. tyzden
			date.setDate(den - date.getDay() + 1)
			obj1.value = date.getDate() +"."+ (date.getMonth()+1) +"."+ date.getFullYear()
			date.setDate(date.getDate() + 6)
			obj2.value = date.getDate() +"."+ (date.getMonth()+1) +"."+ date.getFullYear()
			break
		case 2: // akt. mesiac
			obj1.value = "1."+ mesiac +"."+ rok
			obj2.value = PocetDni +"."+ mesiac +"."+ rok
			break
		case 3: // Q1
			obj1.value = "1.1."+ rok
			obj2.value = "31.3."+ rok
			break
		case 4: // Q2
			obj1.value = "1.4."+ rok
			obj2.value = "30.6."+ rok
			break
		case 5: // Q3
			obj1.value = "1.7."+ rok
			obj2.value = "30.9."+ rok
			break
		case 6: // Q4
			obj1.value = "1.10."+ rok
			obj2.value = "31.12."+ rok
			break
		case 7: // akt. rok
			obj1.value = "1.1."+ rok
			obj2.value = "31.12."+ rok
			break
		case 8: // min. rok
			obj1.value = "1.1."+ (rok-1)
			obj2.value = "31.12."+ (rok-1)
			break
		default: // mesiac
			obj1.value = "1."+ (n-8) +"."+ rok
			obj2.value = pocetDni(n-8) +"."+ (n-8) +"."+ rok
			break
	}
}

function pocetDni(mesiac)
{
	Calendar = new Date() // Today
	Calendar.setDate(28);
	if(mesiac != null) Calendar.setMonth(mesiac-1);
	for(var n = 28; n < 31; n++)
	{
		Calendar.setDate(Calendar.getDate()+1)
		if(Calendar.getDate() < n) break
	}
	return n
}


var progressTimerID;
var perc

function startProgressBar(msec, start,fnc)
{
	perc = start
	progressTimerID=window.setInterval(fnc, msec)
}

function progressBar(stav, bar, sirka, vyska)
{
	var sirkaNum = 46
	var sirkaProg = Math.round((sirka - sirkaNum - 4) / 100 * stav)
	getE(bar).innerHTML = '<TABLE cellspacing="0" style="width:'+sirka+'px;height:'+vyska+'px;padding:0px;border:solid 1px gray"><TR><TD><DIV style="width:'+sirkaProg+'px;height:100%;border:solid 1px green;background-color:#90FF84"></DIV></TD><TD align="right" width="'+sirkaNum+'">'+stav+'%</TD></TR></TABLE>'
}

function getParam(prem)
{
	var url = unescape(location.search.substr(1).replace(/\+/g, " "))
	var param = url.split("&")
	var nparams = ""
	for(n in param)
	{
		hodnoty = param[n].split("=")
		if(prem == null || "nparams" == hodnoty[0])
			eval(hodnoty[0] + "='" + hodnoty[1] + "'")
		else
			if(prem == hodnoty[0]) return hodnoty[1]
	}

	var nparam = nparams.split(";")
	var pocet = nparam.length
	if(pocet < 2) return
	for(n = 0; n < pocet; n+=2)
	{
		if(prem == null)
			eval(nparam[n] + "='" + nparam[n+1] + "'")
		else
			if(prem == nparam[n]) return nparam[n+1]
	}
}

function setNparam(prem, val)
{
	var url = unescape(location.href.replace(/\+/g, " "))
	var pos = url.search(/nparams=/) + 8
	if(pos == 7)
	{
		if(url.search(/\?/) == -1) return url + "?nparams=" + prem + ";" + val
		return url + "&nparams=" + prem + ";" + val
	}
	return url.substr(0, pos) + prem + ";" + val + ";" + url.substr(pos)
}

function unsetNparam(prem)
{
    var url = unescape(location.href.replace(/\+/g, " "))
    var pos = url.search(/nparams=/) + 8
    if(pos == 7 || url.indexOf(prem) == -1) return url
    else
    {
	    var end = url.indexOf("&", pos)
	    var params = end == -1 ? url.substring(pos) : url.substring(pos, end)
	    var data = params.split(";")
	    if (data.length == 0) return url
	    if (data.length % 2 == 1) data.length -= 1
	    var backUrl = url.substring(0, pos)
	    backUrl += data[0] != prem ? data[0] + ';' + data[1] : ''
	    for (i=2; i<data.length; i+=2)
	    {
		    backUrl += data[i] != prem ? ';' + data[i] + ';' + data[i+1] : ''
	    }
	    backUrl += end == -1 ? "" : url.substring(end)
	    return backUrl
    }
}

function DoklExport(rid,typdokl)
{
	window.location =  GetRootPath() + '/DataExport.ashx?td=' + typdokl + '&nparams=rid;' + rid;
}

function myAlert(typ,obsah,reload)
{
	var inlineData = getE("inlineData")
	if(inlineData == null) { alert(obsah); return }

	switch(typ)
	{
		case 'alert': head = 'Upozornenie'; obr = 'Alert.gif'; break
		case 'info': head = 'Inform&#225;cia'; obr = 'Info.gif'; break
		case 'hint': head = 'Inform&#225;cia'; obr = 'Info.gif'; break
		default: head = typ; obr = 'Info.gif'; break
	}
	var onClk = "myAlertDiv.style.visibility='hidden'"
	if(reload == true) onClk += ";window.location.href=window.location.href"
//	var temp = '<TABLE id="ma" class="myAlert" cellpadding="0" cellspacing="0"><TR><TD><TABLE cellspacing="0"><TR><TH colspan="2">' + head + '</TH></TR><TR><TD width="60"><IMG SRC="Images/System/' + obr + '" ALT=""></TD><TD>' + obsah + '</TD></TR><TR><TD colspan="2"><BUTTON onClick="tempDiv.innerHTML=\'\'" id="myAlertOK">OK</BUTTON></TD></TR></TABLE></TD></TR></TABLE>'
	var temp = '<TABLE id="ma" class="myAlert" cellspacing="0"><COL width="60"><TR><TD><TR><TH colspan="2">' + head + '</TH></TR><TR><TD><IMG SRC="Images/System/' + obr + '" ALT=""></TD><TD>' + obsah + '</TD></TR><TR><TD colspan="2"><BUTTON onClick="'+onClk+'" id="myAlertOK">OK</BUTTON></TD></TR></TABLE>'

	myAlertDiv = getE("myAlert")
	if(myAlertDiv == null)
	{
		var myAlert = document.createElement("div");
		myAlert.id = "myAlert"
		inlineData.appendChild(myAlert)
		myAlertDiv = getE("myAlert")
	}
	myAlertDiv.innerHTML = temp

	CenterElement("ma")
	myAlertDiv.style.visibility = "visible"
	inlineData.style.visibility = "visible"
	getE("myAlertOK").focus()
}

function CenterElement(objId)
{
	if(!isPageLoad) { addStartEvent(function(){CenterElement(objId)}); return }
	var obj = getE(objId)
	obj.style.left = (document.body.offsetWidth - obj.offsetWidth)/2 + "px";
	obj.style.top = (document.body.offsetHeight - obj.offsetHeight)/2 + "px";
}

function HFieldcollect()
{
	//alert('aaa');

}

function WebMail(from,to,subject,ctrlID,cc,attachment)
{	
	var nparams = 'xxx;xxx';
	if(from != null)
	nparams += ';from;' + from;
	if(to != null)
	nparams += ';to;'+ to;
	if(subject != null)
	nparams += ';subject;' + subject;
	if(ctrlID != null)
	nparams += ';ctrlID;'+ ctrlID; 
	if(cc != null)
	nparams += ';cc;'+ cc;
	if(attachment != null)
	nparams += ';att;' + attachment;
	
	Detail(1076,nparams,false);
}

function PrintSticker(nid)
{
	Detail(nid,nparams + ';previewmode;print',inline,width,height);
}

function PrintMe()
{
	print();
}

function MailSticker(nid,nparams,to,subject)
{
	Detail(nid,nparams + ';previewmode;mail;to;' + to + ';subject;' + subject,false);
}

function stripTags(oldString)
{
	return oldString.replace(/<[^>]*>/g, "");
}

function existInArray(pole, hodnota)
{
    for(var i = 0; i < pole.length; i++)
        if(pole[i] == hodnota) return i
        
    return -1
}

function ShowCrm(rid,id_kat,rid_v,rid_p)
{
 if(rid == null )
	Detail(1079,'id;' + id_kat);
 else
	Detail(1079,'RID;' + rid).name = rid;
}

function CrmChoose(katid,nparams)
{
	maxparams = 'id;' + katid;
	if( nparams != null )
		maxparams = maxparams + ';' + nparams;
	Detail(1079,maxparams);	
}

function tabs(tabsId, classOff)
{
	var tabObj
	if(tabsId == null || tabsId == "")
        tabObj = getE("tdTabs");
    else
		tabObj = getE(tabsId)
    if(tabObj == null) return;
    if(classOff == null || classOff == "") classOff = "tabOff"

	tags = tabObj.getElementsByTagName("DIV")
	for(i=0;i<tags.length;i++)
	{
		if(tags[i].getElementsByTagName("IMG").length > 1) continue
		if(tags[i].getElementsByTagName("IMG")[0] == null || tags[i].className != classOff) continue
		tags[i].getElementsByTagName("IMG")[0].style.filter = "gray"
		tags[i].onmouseover = tabColor
		tags[i].onmouseout = tabBW
		tags[i].unselectable = "on"
	}
}
function tabColor()
{
	this.getElementsByTagName("IMG")[0].style.filter=""
//	this.className="tabOffOver"
	this.style.color="black"
}

function tabBW()
{
	this.getElementsByTagName("IMG")[0].style.filter="gray"
	this.style.color=""
}

function stool(id, e)
{
	var inlineData = getE("inlineData")
	var tooltip = getE("tooltip")
	if(id == null)
	{
		if(tooltip != null) tooltip.style.visibility = "hidden"
		return
	}

	obsah = "<table class='tooltip'><tr><td class='tooltipHead'>" + evnt[id][2] + "</td></tr><tr><td>" + evnt[id][3] + "</td></tr><tr><td class='tooltipPartner'>" + evnt[id][0] + " - " + evnt[id][1] + " :: " + evnt[id][4] + "</td></tr></table>"

	if(!e) var e = window.event

	if(tooltip == null)
	{
		var tooltip = document.createElement("div");
		tooltip.id = "tooltip"
		tooltip.style.position = "absolute"
		inlineData.appendChild(tooltip)
	}
	tooltip.innerHTML = obsah
	tooltip.style.left = e.clientX + document.body.scrollLeft
	tooltip.style.top = e.clientY + document.body.scrollTop + 16
	tooltip.style.visibility = "visible"
	inlineData.style.visibility = "visible"
}

function sTool(id, e)
{
	if(id == null)
	{
		tooltip.style.visibility = "hidden"
		return
	}
	tooltip = getE(id)

	if(!e) var e = window.event

	tooltip.style.left = e.clientX + document.body.scrollLeft
	tooltip.style.top = e.clientY + document.body.scrollTop + 16
	tooltip.style.visibility = "visible"
}

function showPopUp(objId, e)
{
	if(objId == null)
	{
		if(popUp != null) popUp.style.visibility = "hidden"
		zobrazSelecty()
		return
	}

	popUp = getE(objId)

	if(!e) e = window.event

	var presahX = popUp.offsetWidth - document.body.clientWidth + e.clientX
	var posX = e.clientX + document.body.scrollLeft
	if(presahX > 0) posX -= presahX
	if(posX < document.body.scrollLeft) posX = document.body.scrollLeft

	var presahY = popUp.offsetHeight - document.body.clientHeight + e.clientY
	var posY = e.clientY + document.body.scrollTop + 16
	if(presahY > 0) posY -= presahY
	if(posY < document.body.scrollTop) posY = document.body.scrollTop

	popUp.style.left = posX + "px"
	popUp.style.top = posY + "px"
	
	if(VisibleLayerName != null) menuOff()
	popUp.style.visibility = "visible"
	skrySelecty()
}

function itemOver()
{
	this.className = "tblSlideMenuOn"
}

function itemOut()
{
	this.className = "tblSlideMenuOff"
}

function slideMenu(obj)
{
	var tags = getE(obj).getElementsByTagName("TD")
	for(i=0;i<tags.length;i++)
	{
		tags[i].onmouseover = itemOver
		tags[i].onmouseout = itemOut
		tags[i].unselectable = "on"
	}
}

function myTitle(id,stk)
{
	if(id == null)
	{
		if(objTitle) objTitle.className = "off"
		return
	}
	if(stk == null) stk = 1109
	objTitle = getE(id)
	if(window.event) e = window.event

	var pozice = findElement('dvTB_B_MP_'+stk+'_WebGrid1_')
	objTitle.style.left = e.clientX - pozice.x //+ document.body.scrollLeft
	objTitle.style.top = e.clientY + 16 - pozice.y //+ document.body.scrollTop
	objTitle.className = "on"
}

function addStartEvent(func)
{
  var oldonload = window.onload;
  if (typeof window.onload != 'function') { window.onload = func; }
  else
  {
    window.onload = function()
    {
      if (oldonload) { oldonload(); }
      func();
    }
  }
}

function maxVal(arr)
{
	var max = arr[0]
	for(n in arr)
		max = Math.max(max, arr[n])

	return max
}

function addCommas(nStr, sep)
{
	nStr += '';
	x = nStr.split(',');
	x1 = x[0];
	x2 = x.length > 1 ? ',' + x[1] : '';
	var rgx = /(\d+)(\d{3})/;
	while (rgx.test(x1)) {
		x1 = x1.replace(rgx, '$1' + sep + '$2');
	}
	return x1 + x2;
}

function jas(farba, percento)
{
	R = from10toradix(parseInt(255 - (255-parseInt(farba.substr(0, 2), 16)) * percento / 100), 16)
	G = from10toradix(parseInt(255 - (255-parseInt(farba.substr(2, 2), 16)) * percento / 100), 16)
	B = from10toradix(parseInt(255 - (255-parseInt(farba.substr(4, 2), 16)) * percento / 100), 16)

	return(R+G+B)
}

function from10toradix(value,radix)
{
    var retval = '';
    var ConvArray = "0123456789ABCDEF";
	var dlzka = 2;
	var i;

    if (isNaN(value)) return('A0');
    for(i = 0; i < dlzka; i++)
	{
        retval = ConvArray.charAt(value % radix) + retval;
        value = Math.floor(value / radix);
	}
    return retval;
}

function changeDF(obj,editable,clear)
{
    obj.readOnly=!editable; 
    if( clear != false )
        obj.value=''
    if(editable) changeClass(obj, "")
    else changeClass(obj, "RO")
}

function showPic(obj, e)
{
	var inData = getE("inlineData")
	if(obj == 'hide')
	{
		inData.style.visibility = "hidden"
		return
	}

	if(!e) e = window.event

	inData.style.left = e.clientX + document.body.scrollLeft
	inData.style.top = e.clientY + document.body.scrollTop + 16
	inData.innerHTML = '<img src="' + obj.src + '">'
	inData.style.visibility = "visible"
}

function skryP(objName,position)
{

    panel = getE(objName+"_TD");
    infof = getE(objName+"H");
    img = getE(objName+"P")
    panelhText = getE("PanelH").getElementsByTagName("td")[1]
    if(panel.style.display == "")
	{
		panel.style.display = "none"
		infof.value = "1";
		if( position == 'Left' )
		    img.src = "images/system/arr-r.gif"
		else
		    img.src = "images/system/arr-l.gif"
		panelhText.className = "PanelHTextHidd"
	}
	else
	{
		panel.style.display = ""
		infof.value = "0";
		if( position == 'Left' )
		    img.src = "images/system/arr-l.gif"
		else
		    img.src = "images/system/arr-r.gif"
		panelhText.className = "PanelHTextShow"
	}

}


function FillPopUpCombo(obj,id_cis,ep)
{       
alert(ep); 
    if(obj.options.length == 0 )
    {    
       var myConn = new XHConn();
        var fnWhenDone = function (oXML) 
		{
			var values = oXML.responseText.split(String.fromCharCode(164));			
			for(n = 0; n < values.length/2; n++)
            {                
	            obj.options[n] = new Option(values[2*n], values[2*n+1]);
            }
            obj.click()
		}							
		if (!myConn) 
			alert("XMLHTTP not available. Try a newer/better browser.");		
		var url = "PopUpKoder.ashx?mode=combo&id_cis=" + id_cis;
		if( ep != null )
		 url = url + '&ep=' + ep;
		myConn.connect(url, "POST","", fnWhenDone);
		obj.options[0] = new Option("WAIT...", "WAIT...");
		obj.options[1] = new Option("...", "...");
		obj.options[2] = new Option("..", "..");
		obj.options[3] = new Option(".", ".");
		return false;
	}			
    return true;
}


function CartAdd(kod_id,pocet,refresh)
{
    CartAction('a',kod_id,pocet,0,refresh); 
        
}

function CartRemove(id_r,refresh)
{    
    CartAction('r',0,0,id_r,refresh);    
}

function CartAction(action,kod_id,pocet,idr,refresh)
{
    if( pocet == null) 
        pocet = 1;    
    
    var myConn = new XHConn();
    var fnWhenDone = function (oXML) 
	{
	    alert(oXML.responseText);
	    window.location.reload();
	}	
	if (!myConn) 
			alert("XMLHTTP not available. Try a newer/better browser.");		
	var url = 'Cart.ashx?nparams=action;' + action + ';kod_id;' + kod_id + ';pocet;' + pocet + ';idr;' + idr + ';dummy;blah' ;	
    myConn.connect(url, "GET","", fnWhenDone);
}

function TextMaxLength(id, max)
{
	var textMsg = getE(id)
	textMsg.onpropertychange=function(){MaxLengthCnt(this, max)}
	textMsg.onclick=function(){MaxLengthCnt(this, max)}
	textMsg.onmousemove=function(){MaxLengthCnt(this, max)}
	textMsg.onblur=function(){MaxLengthCnt(this, max)}
	textMsg.onkeyup=function(){MaxLengthCnt(this, max)}
	textMsg.onfocus=function(){MaxLengthCnt(this, max)}
	textMsg.onchange=function(){MaxLengthCnt(this, max)}
	textMsg.onafterupdate=function(){MaxLengthCnt(this, max)}
}

var MaxLengthCntLock = false;
function MaxLengthCnt(obj, max)
{
	if(!MaxLengthCntLock)
	{
		MaxLengthCntLock = true;
		if(obj.value.length > max)
		{
	//		alert("Pole nesmie byť dlhšie ako " + max + "znakov!")
			obj.value = obj.value.substring(0, max)
		}
		MaxLengthCntLock = false;
	}
}

/* tovar detail */
function formatuj(id)
{
	var maxy = 400
	var obr = getE(id);
	maxx = getE('Table9').offsetWidth - 366
	if(maxx < 1) maxx = 1;
	if(!(xwidth = obr.offsetWidth)) return;
	if(!(xheight = obr.offsetHeight)) return;
	if(xwidth > maxx || xheight > maxy)
	{
		ratio = Math.min(maxx / xwidth, maxy / xheight)						
		obr.style.width = Math.round(xwidth * ratio)
		obr.style.height = Math.round(xheight * ratio)
	}
}

function BindToolTips()
{
	var subMenus = getE("subMenu");
	if( subMenus == null )	
	        return;	        
	subMenus = subMenus.getElementsByTagName("A");	
	objTT = null;
	for(n = 0; n < subMenus.length; n++)
	{
	    objTT = subMenus[n].getElementsByTagName('SPAN');
	    if(objTT != null && objTT.length > 0 )	            
		    subMenus[n].title = objTT[0].innerText // --> takto to bude BindToolTip(submenus[n],objTT[0])
		    
	}
}

function setFormEnter(locationId, buttId)
{
    var location =  getE(locationId)
    if( location == null) return;
	var inputs = location.getElementsByTagName("input")	
	for(var n = 0; n < inputs.length - 1; n++)
	{
		eval('if(inputs[n].type == "text") inputs[n].onkeydown = function(e) { if(!e) e = event; if(e.keyCode == 13) { inputs[' + (n+1) + '].select(); return false; } }')		
	}
	if(buttId != null)
	{
	    var buttObj = getE(buttId+"_tbl")
	    if(buttObj == null) buttObj = getE(buttId)
	    if(buttObj == null || buttObj.onclick == null )  return false;	    
		var fSubmit = buttObj.onclick;				
		if(inputs[n].type == "text") inputs[n].onkeydown = function(e) { if(!e) e = event; if(e.keyCode == 13) { fSubmit(); return false } }
	}
	return true;
}

function executeOnClick(buttId)
{

	if(buttId != null)
	{
	    var buttObj = getE(buttId+"_tbl")
	    if(buttObj == null) buttObj = getE(buttId)
	    if(buttObj == null || buttObj.onclick == null ) { alert(buttObj); return false;	 }   
		var fSubmit = buttObj.onclick;				
		alert('idem submitovat');
		fSubmit();
	}

}

function setCookie(name, value, exp, path, domain, secure)
{
	if(name=='') return;
	var cookie=name+'='+escape(value);
	if(value=='')
	{
		cookie+='; expires='+new Date((new Date()).getTime()-1).toGMTString();//zmaz cookie
	}
	else
	{
		if(exp) cookie+='; expires='+new Date((new Date()).getTime()+expire*(1000*60*60)).toGMTString();//hod na milisec
		else cookie+='; expires='+new Date((new Date()).getTime()+(1000*60*60*24*365)).toGMTString();//rok na milisec
		if(path) cookie+='; path='+path;
		if(domain) cookie+='; domain='+domain;
		if(secure) cookie+='; secure';
	}
	document.cookie=cookie;
}

function getCookie(name, def)
{
	var cookies=document.cookie;
	if(cookies=='') return def;
	var from=cookies.indexOf(name+'=');
	if(from<0) return def;
	var to=cookies.indexOf(';',from);
	if(to<0) to=cookies.length;
	return unescape(cookies.substring(from+name.length+1,to));
}

function calendarTitles(id)
{
	var n = 0;
	var fwd;
	var datum = '';
	var bunky = getE(id).getElementsByTagName("TD")
	for(var i = (calSobota+calNedela+6)*2+1; i < bunky.length; i++)
	{
		if(!bunky[i].getElementsByTagName("DIV").length)
		{
		    datum = date2string(calD);
			bunky[i].title = datum
			eval("bunky[i].onclick = function() { Detail(1084,'k;0;date;"+datum+"') }")			
		}
		bunky[i].style.cursor = "pointer"
		fwd = 1;
		if(n == 4 && !calSobota) { n++; fwd++; }
		if(n == 5 && !calNedela) { n++; fwd++; }
		calD.setDate(calD.getDate()+fwd)
		if(n == 6) { calD.setDate(calD.getDate()-7); calD.setMinutes(calD.getMinutes()+calTimeStep); i++; n=0 }
		else n++
	}
}

function date2string(calD, alsoTime)
{
	var datum = ((calD.getDate() < 9) ? "0" : "") + calD.getDate() + "." + ((calD.getMonth() < 9) ? "0" : "") + (calD.getMonth()+1) + "." + calD.getFullYear()
	if(alsoTime == null || alsoTime == true)
		datum += " " + ((calD.getUTCHours() < 10) ? "0" : "") + calD.getUTCHours() + ":" + ((calD.getMinutes() < 10) ? "0" : "") + calD.getMinutes()
	return datum
}

function xpButton(popis, onClk, img)
{
	if(img != null && img != "") img = '<img src="' + GetRootPath() + '/' + img + '"> '
	else img = ''
	var root = GetRootPath()+"/Images/tabs/"
	document.write('<table class="imgButt" cellpadding="0" cellspacing="0" onClick="'+onClk.replace(/"/g,"'")+'"><tr><td><img src="'+root+'xp_button_left.gif"></td><td style="background-image:url('+root+'xp_button_center.gif)">'+img+popis+'</td><td><img src="'+root+'xp_button_right.gif"></td></tr></table>')
}

function IncrementDate(dateIn, interval, alsoTime)
{
   
	var isDate = true
	
	if(typeof dateIn == 'string')
	{	    
		dateIn = string2date(dateIn)
		isDate = false;
	}

	dateIn.setMinutes(dateIn.getMinutes()+Number(interval));
    if(isDate)
			return dateIn;
		
	else	
		return date2string(dateIn, alsoTime);
}

function string2date(dateIn)
{

	var myDate = new Date();
	var pattern = /\D/
	var arr = dateIn.split(pattern)
	myDate.setDate(arr[0])
	myDate.setMonth(arr[1]-1)
	myDate.setFullYear(arr[2])
	if(arr.length > 3)
	{
		myDate.setUTCHours(arr[3])
		myDate.setMinutes(arr[4])
	}

	return myDate
}

function StoreData(data,name,value,delimiter)
{
    if(!delimiter)delimiter='¤'
    var index=data.indexOf(name)
    if(!data||index<0)
    {
        if(data.length!=0) data+=delimiter
        data+=name+delimiter+value
    } 
    else
    {
        var before=data.substring(0,index)
        var lastIndex=data.indexOf(delimiter,index+name.length+1)
        var after=''
        if(lastIndex>0) after=data.substring(lastIndex)
        data=before+name+delimiter+value+after
    }
    return data
}

function switchTab(id, obj, zal)
{
 	if(zal['lastZal'] != null) zal['lastZal'].className = zal['class']
	if(obj != null) { obj.className = zal['class']+"Sel"; zal['lastZal'] = obj }
	for(var n = 0; n < zal.length; n++)
	{
		if(zal[n] == id) getE(id).style.display = ""
		else getE(zal[n]).style.display = "none"
	}
}

function getE(id)
{
    if (id) return document.getElementById(id);
    return null;
}

function PopulateComboBox(idCombo, list)
{
    if (!idCombo || !(combo = getE(idCombo))) return
    combo.options.length = 0
    if (!list) return
    for(i=0;i<list.length;i+=2)
    {
        combo.options[i/2] = new Option(list[i],list[i+1])
    }
}

function switchEuroMode(textObj,valObj)
{   
    switch(valObj.value)
    {
        case '0':
           textObj.value = 'Sk';
           valObj.value = '1'; 
           break;
       case '1':
           textObj.value = '&euro;';
           valObj.value = '2'; 
           break;
       case '2':
           textObj.value = '&euro;/Sk';
           valObj.value = '0'; 
           break;       
                
    }         
 //   myAlert('info','Aktivovan reim zobrazovania ' +  textObj.value,true);
}

function PortalMap(pmId)
{    
    var links = getE(pmId).getElementsByTagName('A');
    var tt;
    for( n = 0; n != links.length; n++)
    {
        if( links[n].id.substr(0,4) == 'PAGE' )
        {
            tt = links[n].getElementsByTagName('DIV')[0];           
            if( tt != null  && tt.innerText != '')            
                links[n].parentNode.title = tt.innerText;
             else
                links[n].parentNode.title = links[n].innerText;
        }
     }
    
}


function ShowHint(rid)
{     

	var myConn = new XHConn();	
	var fnWhenDone = function (oXML) 
	{
	    var data = oXML.responseText.split('¤');
	    if( data.length == 1)
	        myAlert('alert',data[0],false);
	    else	    
		    myAlert(data[0],data[1],false);
		document.getElementsByTagName("BODY")[0].style.cursor = "default"
	}		
	if (!myConn) 
		alert("XMLHTTP not available. Try a newer/better browser.");
	else 
	    document.getElementsByTagName("BODY")[0].style.cursor = "wait"	    
	myConn.connect('Common.ashx?action=gethint&ridv=' + rid, 'POST', '', fnWhenDone);

}


function CallTo(rid,idCis,action)
{     

	var myConn = new XHConn();	
	var fnWhenDone = function (oXML) 
	{
	    var data = oXML.responseText;
		document.getElementsByTagName("BODY")[0].style.cursor = "default"
		data = data.split('¤');
		if( data[action] == null || data[action] == '' )
		{
		        alert('Kontaktný údaj nie je uvedený');		        
		        return;
		}
		if( action == 0 )				    		 
		        window.location='callto:' + data[action]
		else if (action == 1) 
		        window.location='mailto:' + data[action]
		
	}		
	if (!myConn) 
		alert("XMLHTTP not available. Try a newer/better browser.");
	else 
	    document.getElementsByTagName("BODY")[0].style.cursor = "wait"	    
	    
	myConn.connect('Common.ashx?action=getcol&col=ip_phone&ridv=' + rid + '&idCis=' + idCis, 'POST', '', fnWhenDone);

}

