function GetRootPathN()
{
 var url = window.location.href.toLowerCase();
 var bploc = GetRootPath().toLowerCase();
 return window.location.href.substr(0,url.indexOf(bploc)+bploc.length);
}


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(GetRootPathN() + '/Admin/Forms/Colorer.html','Colorer',300,400,false,false);
}

function CisRecordEdit(layout,pk1,pk2)
{
	MyWindowOpen(GetRootPathN() + '/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 = GetRootPathN() + '/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 = GetRootPathN() + '/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( GetRootPathN() + '/Controls/AccessLevel/AccessLevel.aspx?control=' + controlId + '&ar='+ currentAR + addOn ,'AL',300,400,true,true);
}
 
 function Attachments(doklrid,mediarid)
 {
//	GetRootPathN();
	height = 300;
	if(doklrid == null)
		return;		
	url = GetRootPathN() + '/Controls/Attachments/Attachments.aspx?ridd=' + doklrid;
	if( mediarid != null && mediarid != '')
	{
		url = url + '&ridm=' + mediarid;
		height = height + 150;
	}	
	MyWindowOpen(url,'Attachments',400,height,true,true); 
 }
 
 
var popUp; 

function OpenCalendar(idname, postBack,time)
{
	var addOn;
	if( time == null || time == 'no' || time == 'false' || time == false)
		addOn = '';
	else
		addOn = '&time=True';
		
	popUp = window.open(GetRootPathN() + '/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 OldKoder(type,controlId,submit,quickselect,extrapar)
{
	//alert('Startujem koder [Type:' + type + ' ControlId:' + controlId + ' Submit:' + submit + ' QuickSelect:' + quickselect + ' ] ');
	// type:
	url =  GetRootPathN() + '/Controls/Selectors/Selector.aspx?textbox=' + controlId + '&case=' + type;

	if( submit != null && ( submit == 'True' || submit == true))
		url = url + '&submit=1';

	if( quickselect != null && ( quickselect == 'True' || quickselect == true) )
		url = url + '&quickselect=true';
		
	if(extrapar != null )
		url = url + '&par=' + extrapar;

	MyWindowOpen(url,'selector',450,200,true,true);
}

function Koder(id_cis,clientId,submit,quickselect,extrapar,mode)
{
	/*if( extrapar != null )
	 alert("Sql podm:" + extrapar);
	 */
	 if( mode == null )
		mode = 0;
	MyWindowOpen(GetRootPathN() + "/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)
{
	/*if( extrapar != null )
	 alert("Sql podm:" + extrapar);
	 */
	var url = "/Moduly/Common/Forms/PopUpKoder.aspx?id_cis=" + id_cis + "&id=" + clientId + "&submit=" + submit  + "&quick=" + quickselect + '&ep=' +  extrapar;
	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( GetRootPathN() + '/Moduly/Shop/Schemy/TovarInsert.aspx' ,'TovarInsert',450,400,true,true);
}


function UsersSelector(controlId,textId,currentVal,submit)
{
	text = '';
	if( textId != null && textId != '' )
		text = '&text=' + textId;
	MyWindowOpen(GetRootPathN() + '/Controls/UsersSelector/UsersSelector.aspx?control=' + controlId + text + '&current=' + currentVal + '&submit=' + submit,'UserSelect',270,250,true,true); 
}


function CisProp(primarykey,idcis)
{
	//alert('Vlastnosti zaznamu s primarny klucom:' + primarykey +' a vzhladom ' + layout);
	//MyWindowOpen(GetRootPathN() + '/Moduly/Common/Forms/CisRecordInfo.aspx?pk=' + primarykey + '&layout=' + layout ,'Prop' + primarykey ,400,450,true,true); 
	if( idcis == 263 )
	{
		DetailOP(primarykey);	
	}
	else
		MyWindowOpen(GetRootPathN() + '/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(GetRootPathN() + '/Moduly/Common/Forms/CisRecordEdit.aspx?pk=' + primarykey + '&layout=' + layout ,'Prop' + primarykey ,400,450,true,true); 		
	MyWindowOpen(GetRootPathN() + '/Moduly/Common/Forms/CisProperties.aspx?pk=' + primarykey + '&idcis=' + idcis,'cisp' + primarykey ,650,450,true,true); 		
}

function AddSysField()
{
	MyWindowOpen(GetRootPathN() + '/Moduly/Common/Forms/AddSysField.aspx' ,'ASF' ,600,450,true,true); 			
}

function CisEngine(id)
{
	//alert('Vlastnosti pre zaznam '  + id);	
	MyWindowOpen(GetRootPathN() + '/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 = GetRootPathN() + 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 = 300;
	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)
{

	var loc = '';	
	if(nid == null || nid == '')
		return;
	if(!inline) 
		loc = 'detail.aspx';
	else
		loc = 'http://' + window.location.host + location.pathname; 
		
	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 = 300; }
		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");
		return MyWindowOpen(url,'NID' + nid,sirka,vyska,'yes','auto');
	}
}


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;	
	if(window.opener == null)
	{
		window.location = url;
	}
	else
	{
		window.opener.location = url;
		self.close();
	}
}

function AutoResize(width, height)
{
	//alert('(' + Form1.windowEnd.clientWidth + ',' +  Form1.windowEnd.clientHeight + ')');							
	//alert('(' + Form1.windowEndB.offsetLeft + ',' +  Form1.windowEndB.offsetTop + ')');
	if(!width || width == null) width = document.getElementById("t1").offsetWidth+document.getElementById("t1").offsetLeft*2+8
	if(!height || height == null) height = document.getElementById("t1").offsetHeight+document.getElementById("t1").offsetTop*2+50
	heightavail = screen.availHeight
	if(width > screen.width) width = screen.availWidth
	if(height > heightavail) height = heightavail
    if(parent.name)
    {
		xpos = (screen.width - width)/2
		ypos = (heightavail - height)/2
		window.moveTo(xpos, ypos)
	}
	window.resizeTo(width,height);
}

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('Moduly/System/Forms/NewSerZak.aspx?in=1' + query,'NSZ' ,510,550,"no","no"); 		
}


function NewSerZakO(rid,id_r,step)
{
	var addOn = '';
		if( id_r != null )
				addOn = '&idr=' + id_r;
	MyWindowOpen('Moduly/System/Forms/NewSerZakO.aspx?rid=' + rid + addOn +'&step=' + step ,'NSZO' + rid ,460,200,"no","no"); 
	
}


function EditSerZar(id)
{
	MyWindowOpen('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('Moduly/System/Forms/NewSerZar.aspx?skid=' + skid + addOn,'NEWSZ' ,510,550,"no","no"); 		
}

function NewFD(typ,rid_p,rid_m)
{
	MyWindowOpen(GetRootPathN() + '/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(GetRootPathN() + "/Controls/DetailPic/detailpic.aspx?img=" + image,"imgwin",300,300,'yes','auto');		
}

function NahradaSK(kod_id)
{
	MyWindowOpen(GetRootPathN() + "/Controls/Selectors/nahradask.aspx?kodid=" + kod_id,"nahrada",380,200,false,false);		
}

function CRView(rid,prn,nparams)
{
	MyWindowOpen("Moduly/Common/Forms/ReportViewer.aspx?rid=" + rid +'&prn=' + prn + '&nparams=' + nparams,"RV" + rid,800,600,'yes','yes');		
}	

function FormShow(rid,inbox)
{
	MyWindowOpen(GetRootPathN() + "/Moduly/Manager/Forms/FormShow.aspx?idm=" + rid + "&inbox=1",'FormShow',700,550,'no','no');
}

function Favorit(idcis,ridv,iduser)
{
	if( idcis == null || ridv== null )
								return;
	var url = GetRootPathN() + "/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,mode)
{
	if( ridorcis== null )
				return;
	var url = GetRootPathN() + "/Moduly/Common/Forms/ChangeTree.aspx?ridv=" + ridorcis;	
	if(mode != null)	
		url = url + '&mode=' + mode;
	if( ctrl != null)
		url = url + '&ctrl=' +  ctrl;
	if( selected != null)
		url = url + '&sel=' +  selected;
	MyWindowOpen(url,'CT',320,500,'yes','yes');

}


function KontaktEdit(idk)
{
 //alert('edit');
 if( idk == null || idk == '' )
 {
		alert('Nie je zadane id kontaktu');
		return;
 }
 MyWindowOpen(GetRootPathN() +  '/Moduly/Manager/Forms/FormContact.aspx?idk=' + idk ,'NewKon',300,400,false,false);
}

function ObchPartEdit(id)
{
 MyWindowOpen(GetRootPathN() +  '/Moduly/Manager/Forms/FormObchPart.aspx?id=' + id ,'EditObchPart',300,400,false,false);
}

function KontaktNew()
{
 MyWindowOpen(GetRootPathN() +  '/Moduly/Manager/Forms/FormContact.aspx','NewKon',450,480,false,false);
}

function ContactEvent(idcontact)
{
	MyWindowOpen(GetRootPathN() + '/Moduly/Manager/Forms/FormChoose.aspx?blank=1&idcontact=' + idcontact ,'pridaj',300,250,'no','no');	
}


function FormChoose(date,hour,blank,idcontact)
{	
	MyWindowOpen(GetRootPathN() + '/Moduly/Manager/Forms/FormChoose.aspx?date='+date+'&hour=' + hour + '&blank=' + blank ,'pridaj',300,250,'no','no');	

}

function Scheduler(mode,date,user)
{
//&show=week&date=10.05.2005&uid=52
MyWindowOpen(GetRootPathN() + '/Moduly/Manager/Forms/FormScheduler.aspx?show=' + mode + '&date=' + date + '&uid=' + user + '&printver=true','Scheduler',800,600,'no','yes');
}


function DetailOP(rid)
{
	MyWindowOpen(GetRootPathN() + '/Moduly/Manager/Forms/FormDetailOP.aspx?idop=' + rid,'detail_op' + rid,700,540,false,false);
}

function QV(rid)
{
	Detail(20,'rid;' + rid ,false,910,500);
}

function NewOP()
{
	MyWindowOpen(GetRootPathN() + '/Moduly/Manager/Forms/FormOP.aspx?refresh=true','FormOP',650,320,false,false)
}


function EditOP(rid,idtree)
{
	url = GetRootPathN() + '/Moduly/Manager/Forms/FormOP.aspx?refresh=true&idop=' + rid ;
	if( idtree != null )
		url = url + '&idtree=' + idtree;
	MyWindowOpen(url,'FormOP' + rid ,650,320,false,false);
}


// 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

function EnableMouseCapturing()
{
	// 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;  
}
}

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)
		{
			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";
			PopUpOff()
		}
		else
		{
			clearTimeout(popupTimerID); 
			popupTimerID=null;
		}
	}
	
	function PopUpOff()
	{
	   popupTimerID=setTimeout("popupOff()",popup_delay_msec);
	}

	function PopUpItemOn(popUpItem)
	{	
		clearTimeout(popupTimerID);	
		popupTimerID=null;
		selectedPopUpItem=popUpItem;
		popUpItem.className='PopUpItemOn';
	}
	
	function PopUpItemOff(popUpItem)
	{
		popUpItem.className='PopUpItemOff';
		selectedPopUpItem=null;
		PopUpOff();
	}


	function Menu(zalId,nparams)
	{		
		//EnableMouseCapturing();
		UniMenu("/Moduly/Common/Forms/WwwMenu.aspx",zalId,nparams);	  	
	}
	
	function UniMenu(source,zalId,nparams)
	{
		xMousePos = window.event.x+document.body.scrollLeft;
        yMousePos = window.event.y+document.body.scrollTop;     
		var myConn = new XHConn();
		var fnWhenDone = function (oXML) 
		{
			InLinePopUp(oXML.responseText,	'prop' + zalId,xMousePos,yMousePos);
		}
			
		if (!myConn) 
			alert("XMLHTTP not available. Try a newer/better browser.");
		myConn.connect(GetRootPathN() + source, "POST", "id=" + zalId + "&nparams=" + nparams, fnWhenDone);
	}
	
	
function InLinePopUp(obsah,popUpId,x,y)
{			
	var inData = document.getElementById("inlineData"); 
	inData.innerHTML = obsah;
	inData.style.visibility=''; 		

	if(xMousePos + inData.offsetWidth > document.body.clientWidth) inData.style.left = x - inData.offsetWidth + 8 + "px";
	else inData.style.left = x - 8 + "px";
/*
	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";
	}
*/
	inData.style.top = y - 8 + "px";
	PopUpOn(document.getElementById(popUpId),0,0);		
}
	
function BArchive()
{
	alert( 'Barchive aktivny...');
}

function DocNew()
{
// alert('Doc New');
 MyWindowOpen(GetRootPathN() +  '/Moduly/BArchive/Forms/DocEdit.aspx','NewDoc',450,450,false,false);
}

function DocEdit(rid)
{
// alert('Doc New');
 MyWindowOpen(GetRootPathN() +  '/Moduly/BArchive/Forms/DocEdit.aspx?rid=' + rid,'EditDoc',450,450,false,false);
}


function SanonNew()
{
// alert('Sanon New');
 MyWindowOpen(GetRootPathN() +  '/Moduly/BArchive/Forms/SanonEdit.aspx','NewSan',450,310,false,false);
}


function SanonProp(rid)
{
 //alert('sanon prop pre RID:' + rid);
  
  if( rid != 0 && (rid == null || rid == ''  ))
  {
	alert('Nie je vybrany sanon.' + rid);
	return;
   }
  MyWindowOpen(GetRootPathN() +  '/Moduly/BArchive/Forms/SanonProp.aspx?rid=' + rid ,'SanProp' +  rid,900,520);
}

function DocProp(rid)
{
 if( rid == null || rid == '' )
  {
	alert('Nie je vybrany dokument.');
	return;
   }
 MyWindowOpen(GetRootPathN() + '/Moduly/BArchive/Forms/DocProperties.aspx?rid=' + rid +'&enable=P','PropDoc' + rid,900,510,false,false);
}


function DocMoveTo(rid,retControl,submit)
{	
   if( rid == null || rid == '' )
  {
	alert('Nie je vybrany dokument.');
	return;
   }
   MyWindowOpen(GetRootPathN() +  '/Moduly/BArchive/Forms/DocMoveTo.aspx?rid=' + rid + '&control=' + retControl + '&submit=' +  submit ,'MoveDocTo',450,200);
   // blokovanie postbacku
   return false;
}

function DocMoveFrom(rid,retControl,submit)
{	
   if( rid == null || rid == '' )
  {
	alert('Nie je vybrany dokument.');
	return;
   }
   MyWindowOpen(GetRootPathN() +  '/Moduly/BArchive/Forms/DocMoveFrom.aspx?rid=' + rid +  '&control=' + retControl + '&submit=' +  submit ,'MoveDocFrom',450,250);
   // blokovanie postbacku
   return false;
}
  
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(GetRootPathN() +  '/Moduly/BArchive/Forms/DmsAction.aspx?aid=' + action + '&rid=' + rid +  '&control=' + retControl + '&submit=' +  submit ,'MoveAction',450,250);   
   return false;
}

function Pohyby(rid)
{
 window.location = 'http://' + window.location.host + GetRootPathN() + '?content=DMS_PHB&rid=' + rid + '&enable=P';
}

function PohybInfo(id)
{
//	alert('Pohyb:' + id);
	MyWindowOpen(GetRootPathN() +  '/Moduly/BArchive/Forms/PohybInfo.aspx?id=' + id,'PohybInfo' + id,450,200);
}

function SanonContent(rid)
{
	alert('Nie je k dispozicii ['+rid+']' );
}

function hideItem(item)
{
	//if(Items[item]["visible"])
	if(document.getElementById(item).style.visibility == 'visible')
	{
		document.getElementById(item).style.visibility='hidden'
//		Items[item]["visible"] = false
	}
	else
	{
		document.getElementById(item).style.visibility='visible'
//		Items[item]["visible"] = true
	}
}

function PLSQL(id,nparams)
{		
	var url = GetRootPathN() + "/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("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") obj.readOnly = true
	else obj.readOnly = false
}

var validMode = true;
function validate(objIn, typ, notNull)
{
	var obj = objIn;
	if( typeof(objIn) == 'string' )
	{
		obj = document.getElementById(objIn);				
	}
	if(validMode == true) return true

	var emailfilter=/^\w+[\+\.\w-]*@([\w-]+\.)*\w+[\w-]*\.([a-z]{2,4}|\d+)$/i
	var ok = true

	if(obj.value == "")
	{
		if(!notNull) return true
		else
		{
			changeClass(obj, "ERR")
//			alert('Pole nesmie ostať prázdne!')
			return false
		}
	}

	switch(typ)
	{
		case 'Num':
		case 0:
			if(isNaN(obj.value.replace(/,/,".").replace(/ /,""))) ok = false
			break;
		case 'Date':
		case 1:
			udaje = obj.value.split(".")
			if(isNaN(udaje[0])) { ok = false; break }
			if(udaje[0] < 1 || udaje[0] > 31) { ok = false; break }
			if(isNaN(udaje[1])) { ok = false; break }
			if(udaje[1] < 1 || udaje[1] > 12) { ok = false; break }
			if(isNaN(udaje[2])) { ok = false; break }
			if(udaje[2] < 1900 || udaje[2] > 2300) { ok = false; break }
			break;
		case 'Email':
		case 3:		
			ok = emailfilter.test(obj.value); break
	}

	if(ok)
	{
		changeClass(obj, "")
		return true
	}
	else
	{
		changeClass(obj, "ERR")
		//alert('Nesprávna hodnota!')
		return false
	}
}

function DatumOdDo(obj1, obj2)
{
	var popis = new Array("dnes", "akt. t&#253;&#382;de&#328;", "akt. mesiac", "akt. 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")
	var temp = '<TABLE class="PopUp" id="menuDatum" style="POSITION: absolute;LEFT:0px;TOP:0px; WIDTH:100px" CELLSPACING="0">'
	
	for(n in popis)
		temp += '<TR><TD onmouseover="PopUpItemOn(this)"  onmouseout="PopUpItemOff(this)" onclick="popupOff();putDates(\''+ obj1 +'\',\''+ obj2 +'\','+ n +')">'+ popis[n] +'</TD></TR>'

	temp += '</TABLE>'	
	InLinePopUp( temp,'menuDatum',window.event.x+document.body.scrollLeft,window.event.y+document.body.scrollTop);
}

function putDates(obj1Id, obj2Id, n)
{
	obj1 = document.getElementById(obj1Id)
	obj2 = document.getElementById(obj2Id)

	var date = new Date()
	den = date.getDate()
	mesiac = date.getMonth() + 1
	rok = date.getFullYear()
	PocetDni = pocetDni()

	switch(n)
	{
		case 0:
			obj1.value = obj2.value = den +"."+ mesiac +"."+ rok
			break
		case 1:
			obj1.value = (den - date.getDay() + 1) +"."+ mesiac +"."+ rok
			date.setDate(den - date.getDay() + 7)
			obj2.value = date.getDate() +"."+ (date.getMonth()+1) +"."+ date.getFullYear()
			break
		case 2:
			obj1.value = "1."+ mesiac +"."+ rok
			obj2.value = PocetDni +"."+ mesiac +"."+ rok
			break
		case 3:
			obj1.value = "1.1."+ rok
			obj2.value = "31.12."+ rok
			break
		default:
			obj1.value = "1."+ (n-3) +"."+ rok
			obj2.value = pocetDni(n-3) +"."+ (n-3) +"."+ 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)
	document.getElementById(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 = location.search.substr(1)
	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 DoklExport(rid,typdokl)
{
	window.location =  GetRootPathN() + '/DataExport.ashx?td=' + typdokl + '&nparams=rid;' + rid;
}

function myAlert(typ,obsah)
{
	tempDiv = document.getElementById("inlineData")
	if(tempDiv == null) { alert('Nie je in' + obsah); return }

	switch(typ)
	{
		case 'alert': head = 'Upozornenie'; obr = 'Alert.gif'; break
		case 'info': head = 'Inform&#225;cia'; obr = 'Info.gif'; break
		default: head = 'Upozornenie'; obr = 'Alert.gif'; break
	}
	var temp = '<DIV id="ma" class="myAlert"><DIV class="myAlertHead">' + head + '</DIV><TABLE class="myAlertObsah"><TR><TD width="60"><IMG SRC="Images/System/' + obr + '" ALT=""></TD><TD>' + obsah + '</TD></TR></TABLE><BUTTON onClick="tempDiv.innerHTML=\'\'">OK</BUTTON></DIV>'

	tempDiv.innerHTML = temp
	var obj = document.getElementById("ma")
	width = obj.offsetWidth
	height = obj.offsetHeight
	tempDiv.style.left = (document.body.offsetWidth - width)/2;
	tempDiv.style.top = (document.body.offsetHeight - height)/2;
	tempDiv.style.visibility = "visible"
}


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(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()
{
	tags = document.getElementById("tdTabs").getElementsByTagName("TD")
	for(i=0;i<tags.length;i++)
	{
		if(tags[i].children[0] == null || tags[i].className == "tabOn") continue
		tags[i].children[0].style.filter = "gray"
		tags[i].onmouseover = tabColor
		tags[i].onmouseout = tabBW
		tags[i].unselectable = "on"
	}
}
function tabColor()
{
	this.children[0].style.filter=""
}

function tabBW()
{
	this.children[0].style.filter="gray"
}

function stool(id)
{
	var tooltip = document.getElementById("inlineData")
	if(id == 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(window.event) e = window.event

	tooltip.innerHTML = obsah
	tooltip.style.left = e.clientX + document.body.scrollLeft
	tooltip.style.top = e.clientY + document.body.scrollTop + 16
	tooltip.style.visibility = "visible"
}

function sTool(id)
{
	if(id == null)
	{
		tooltip.style.visibility = "hidden"
		return
	}
	tooltip = document.getElementById(id)

	if(window.event) 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 itemOver()
{
	this.className = "tblSlideMenuOn"
}

function itemOut()
{
	this.className = "tblSlideMenuOff"
}

function slideMenu(obj)
{
	tags = document.getElementById(obj).getElementsByTagName("TD")
	for(i=0;i<tags.length;i++)
	{
		tags[i].onmouseover = itemOver
		tags[i].onmouseout = itemOut
		tags[i].unselectable = "on"
	}
}

function validateForm(zoznam)
{
	var OK = true

	for(n = 0; n < zoznam.length; n+=3)
	{		
		if(validate(zoznam[n], zoznam[n+1], zoznam[n+2]) == false) OK = false
	}

	return OK
}

function validating(zoznam)
{
	for(n = 0; n < zoznam.length-1; n+=3)
	{
		document.getElementById(zoznam[n]).onblur= validateThis		
	}
}

function validateOverArray(ar,what)
{
	var n = existInArray( ar, what.id)
    validate(what,  ar[n+1],  ar[n+2]);
}
