var NO_MENU = 0;

function ConfirmDelete(url, str)
{
  str = typeof(str) != 'undefined' ? str : "Czy na pewno chcesz, aby usunąć?";

  ndot_alert(url, 'Potwierdzenie', 'Czy na pewno chcesz, aby usunąć?');
}

function validateServiceAddForm(theForm)
{
    if (!validRequired(theForm.name, "Nazwa"))            return false;
    if (!validNum(theForm.time_duration, "Czas", true))    return false;
    if (!validNum(theForm.price, "Cena", true))            return false;

    return true;
} 
function validateServiceEditForm(theForm)
{

    if (!validRequired(theForm.name, "Nazwa"))            return false;
    if (!validNum(theForm.time_duration, "Czas", true))    return false;
    if (!validNum(theForm.price, "Cena", true))            return false;
    if (!validNum(theForm.time_duration, "Czas", true))            return false;
    if (!validNum(theForm.min_time_interval, "Przedziały czasowe", true))            return false;
    if (!validNum(theForm.price_per_unit, "Cena za minutę", true))            return false;
    if (!validNum(theForm.applet_width, "Szerokość appletu", true))            return false;

    return true;
} 

function validateWorkersEditForm(theForm)
{
    if (!validRequired(theForm.name, "Imię"))            return false;
    if (!validRequired(theForm.surname, "Nazwisko"))            return false;

    return true;
} 
function validateDevicesEditForm(theForm)
{
    if (!validRequired(theForm.name, "Nazwa"))            return false;
    return true;
} 


function maximizedPopupWndw(url)
{
   var w = 800, h = 600;
   w = screen.width;
   h = screen.height;

   var newwindow = null;

   if (NO_MENU==0)
	   newwindow=window.open(url,'name','height='+h+',width='+w+',top=0,left=0,resizable=yes,scrollbars=yes,menubar=yes,statusbar=no');
   else
     newwindow=window.open(url,'name','');

	 if (window.focus) {newwindow.focus()}

}

function centerPopupWndwN(name, url, wwidth, wheight, forceparams)
{
   var w = 1024, h = 768;
   w = screen.width;
   h = screen.height;

   var ww = typeof(wwidth) != 'undefined' ? wwidth : 950;
   var wh = typeof(wwidth) != 'undefined' ? wheight : 650;
   var nm = typeof(forceparams) != 'undefined' ? forceparams : false;

   var popY = ww, popX = wh;

   var leftPos = (w-popY)/2, topPos = (h-popX)/2;

   var newwindow = null;

   if (NO_MENU==0 || nm==true)
	   newwindow=window.open(url,name,'height='+popX+',width='+popY+',top='+topPos+',left='+leftPos+',resizable=yes,scrollbars=yes,menubar=no,statusbar=no,toolbar=no');
   else
 	   newwindow=window.open(url,name,'');


	 if (window.focus) {newwindow.focus()}

}

function centerPopupWndw(url)
{
  centerPopupWndwN('name', url);
}

function reportTM(theForm)
{
  if (theForm.reptype.value == 15)
  {
    theForm.timeFrom.disabled = false;
    theForm.timeTo.disabled = false;
  }
  else
  {
    theForm.timeFrom.value = '';
    theForm.timeFrom.disabled = true;
    theForm.timeTo.value = '';
    theForm.timeTo.disabled = true;
  }

  theForm.submit();

  return true;
} 

function reportTMPickerCal(theForm, elem)
{
  if (theForm.reptype.value == 15)
  {
    theForm.timeFrom.disabled = false;
    theForm.timeTo.disabled = false;
    NewCal(elem,'yyyymmdd',true,24,'arrow',true);
  }
  else
  {
    ndot_info('Wybierz czas', 'Ustaw "wybrany przedział czasu" jeśli chcesz określić datę');  }
  
} 
function discountTMPickerCal(elem)
{
    NewCal(elem,'yyyymmdd',true,24,'arrow',true);
} 

function TMPickerCal(elem)
{
    NewCal(elem,'yyyymmdd',true,24,'arrow',true);
} 

function TMPickerCalDateOnly(elem)
{
    NewCal(elem,'yyyymmdd',false,12,'arrow');
} 

	var arrayOfRolloverClasses = new Array();
	var arrayOfClickClasses = new Array();
	var activeRow = false;
	var activeRowClickArray = new Array();
	
	function highlightTableRow()
	{
		var tableObj = this.parentNode;
		if(tableObj.tagName!='TABLE')tableObj = tableObj.parentNode;

		if(this!=activeRow){
			this.setAttribute('origCl',this.className);
			this.origCl = this.className;
		}
		this.className = arrayOfRolloverClasses[tableObj.id];
		
		activeRow = this;
		
	}
	
	function clickOnTableRow()
	{
		var tableObj = this.parentNode;
		if(tableObj.tagName!='TABLE')tableObj = tableObj.parentNode;		
		
		if(activeRowClickArray[tableObj.id] && this!=activeRowClickArray[tableObj.id]){
			activeRowClickArray[tableObj.id].className='';
		}
		this.className = arrayOfClickClasses[tableObj.id];
		
		activeRowClickArray[tableObj.id] = this;
				
	}
	
	function resetRowStyle()
	{
		var tableObj = this.parentNode;
		if(tableObj.tagName!='TABLE')tableObj = tableObj.parentNode;

		if(activeRowClickArray[tableObj.id] && this==activeRowClickArray[tableObj.id]){
			this.className = arrayOfClickClasses[tableObj.id];
			return;	
		}
		
		var origCl = this.getAttribute('origCl');
		if(!origCl)origCl = this.origCl;
		this.className=origCl;
		
	}

	function addTableRolloverEffect(tableId,whichClass,whichClassOnClick)
	{
		arrayOfRolloverClasses[tableId] = whichClass;
		arrayOfClickClasses[tableId] = whichClassOnClick;
		
		var tableObj = document.getElementById(tableId);
		var tBody = tableObj.getElementsByTagName('TBODY');
		if(tBody){
			var rows = tBody[0].getElementsByTagName('TR');
		}else{
			var rows = tableObj.getElementsByTagName('TR');
		}
		for(var no=0;no<rows.length;no++){

      if (rows[no].className!='noeffect')
      {
        rows[no].onmouseover = highlightTableRow;
        rows[no].onmouseout = resetRowStyle;
        
        //if(whichClassOnClick){
        //  rows[no].onclick = clickOnTableRow;	
        //}
      }
		}
		
	}

  var originalCellBackground = null;
  var originalHCellBackground = null;
  var originalRCellBackground = null;

	function resetCellStyle()
	{
    if (this.id==null || this.id=='') return;

    var str = this.id;

    var arr = new Array();
    arr = str.split('_');
    
    row_no = arr[0];
    col_no = arr[1];

		var HCell = document.getElementById('0_'+col_no);
		var RCell = document.getElementById(row_no+'_0');

    if (HCell != null && HCell != this)
    {
      HCell.style.backgroundColor=originalHCellBackground;
    }
    if (RCell != null && RCell != this)
    {
      RCell.style.backgroundColor=originalRCellBackground;
    }
    
    this.style.backgroundColor=originalCellBackground;
	}

	function highlightTableCell()
	{
    if (this.id==null || this.id=='') return;

    var str = this.id;

    var arr = new Array();
    arr = str.split('_');
    
    row_no = arr[0];
    col_no = arr[1];

		var HCell = document.getElementById('0_'+col_no);
		var RCell = document.getElementById(row_no+'_0');

    if (HCell != null && HCell != this)
    {
      originalHCellBackground = HCell.style.backgroundColor;
      HCell.style.backgroundColor='#00FF00';
    }
    if (RCell != null && RCell != this)
    {
      originalRCellBackground = RCell.style.backgroundColor;
      RCell.style.backgroundColor='#00FF00';
    }

    originalCellBackground = this.style.backgroundColor;
    this.style.backgroundColor='#00FF00';
  }

	function addTableCREffect(tableId)
	{
		
		var tableObj = document.getElementById(tableId);
		var tBody = tableObj.getElementsByTagName('TBODY');
		if(tBody){
			var cells = tBody[0].getElementsByTagName('TD');
		}else{
			var cells = tableObj.getElementsByTagName('TD');
		}
		for(var no=0;no<cells.length;no++){
			cells[no].onmouseover = highlightTableCell;
			cells[no].onmouseout = resetCellStyle;
			
		}
		
	}

  function ndot_alert(url, title, msg) {

    var w = 1024, h = 768;
    w = screen.width;
    h = screen.height;

    var popW = 350, popH = 120;

    var leftPos = (w-popW)/2, topPos = (h-popH)/2;

    var alertWin = null;

    alertWin=window.open('','ndot_prompt','height='+popH+',width='+popW+',top='+topPos+',left='+leftPos+',resizable=yes,scrollbars=no,menubar=no,statusbar=no');

    alertWin.document.write('<HTML><HEAD><TITLE>' + title + '</TITLE>');	
    alertWin.document.write('<STYLE type="text/css">');
    alertWin.document.write('* { font-family : Helvetica, sans-serif; font-size : 9pt; color : #000000; font-weight : bold;}');
    alertWin.document.write('.button { font-family : Helvetica, sans-serif; font-size : 9pt; color : #000000; width:70px;}');
    alertWin.document.write('.inputtext { font-family : Helvetica, sans-serif; font-size : 9pt; color : #000000; width:70px; text-align:right;}');
    alertWin.document.write('BODY { background-color: #D6D3CE;}');
    alertWin.document.write('</STYLE>');
    alertWin.document.write('</HEAD>');
    alertWin.document.write('<BODY BGCOLOR=#D6D3CE TEXT=#000000 LINK=#000000 VLINK=#000000>');
    alertWin.document.write('<CENTER>');
    alertWin.document.write('<FORM ACTION="#" METHOD="GET" NAME="promptfrm" ONSUBMIT="opener.location=\''+url+'\';window.close();">');

    alertWin.document.write('<TABLE BORDER="0" CELLSPACING="0" CELLPADDING="8">');

    alertWin.document.write('<TR>');
    alertWin.document.write('<TD ALIGN="center" VALIGN="top"><IMG SRC="templates/default/graphics/alert.png"></TD>');
    alertWin.document.write('<TD ALIGN="center" VALIGN="middle">');
    alertWin.document.write(msg);
    alertWin.document.write('</TD>');
    alertWin.document.write('</TR>');

    alertWin.document.write('<TR>');
    alertWin.document.write('<TD COLSPAN="2" ALIGN="center" VALIGN="middle">');
    alertWin.document.write('<input type="submit" value="OK" class="button" name="btn_ok">&nbsp;&nbsp;');
    alertWin.document.write('<input type="button" value="Anuluj" class="button" name="btn_cancel" onclick="window.close();">');
    alertWin.document.write('</TD>');
    alertWin.document.write('</TR>');

    alertWin.document.writeln('</TABLE>');
    alertWin.document.writeln('</FORM>');
    alertWin.document.writeln('<script language="JavaScript" type="text/javascript">');
    alertWin.document.writeln('<!-- ');
    alertWin.document.writeln('setTimeout("document.forms.promptfrm.btn_ok.focus()",100);');
    alertWin.document.writeln('// -->');
    alertWin.document.writeln('</script>');
    alertWin.document.writeln('</CENTER></BODY></HTML>');
    alertWin.document.close();	
    
    if (window.focus) {alertWin.focus()}

  }



  function ndot_info(title, msg) {

    var w = 1024, h = 768;
    w = screen.width;
    h = screen.height;

    var popW = 350, popH = 120;

    var leftPos = (w-popW)/2, topPos = (h-popH)/2;

    var alertWin = null;

    alertWin=window.open('','ndot_prompt','height='+popH+',width='+popW+',top='+topPos+',left='+leftPos+',resizable=yes,scrollbars=no,menubar=no,statusbar=no');

    alertWin.document.write('<HTML><HEAD><TITLE>' + title + '</TITLE>');	
    alertWin.document.write('<STYLE type="text/css">');
    alertWin.document.write('* { font-family : Helvetica, sans-serif; font-size : 9pt; color : #000000; font-weight : bold;}');
    alertWin.document.write('.button { font-family : Helvetica, sans-serif; font-size : 9pt; color : #000000; width:70px;}');
    alertWin.document.write('.inputtext { font-family : Helvetica, sans-serif; font-size : 9pt; color : #000000; width:70px; text-align:right;}');
    alertWin.document.write('BODY { background-color: #D6D3CE;}');
    alertWin.document.write('</STYLE>');
    alertWin.document.write('</HEAD>');
    alertWin.document.write('<BODY BGCOLOR=#D6D3CE TEXT=#000000 LINK=#000000 VLINK=#000000>');
    alertWin.document.write('<CENTER>');
    alertWin.document.write('<FORM ACTION="#" METHOD="GET" NAME="promptfrm" ONSUBMIT="window.close();">');

    alertWin.document.write('<TABLE BORDER="0" CELLSPACING="0" CELLPADDING="8">');

    alertWin.document.write('<TR>');
    alertWin.document.write('<TD ALIGN="center" VALIGN="top"><IMG SRC="templates/default/graphics/info.png"></TD>');
    alertWin.document.write('<TD ALIGN="center" VALIGN="middle">');
    alertWin.document.write(msg);
    alertWin.document.write('</TD>');
    alertWin.document.write('</TR>');

    alertWin.document.write('<TR>');
    alertWin.document.write('<TD COLSPAN="2" ALIGN="center" VALIGN="middle">');
    alertWin.document.write('<input type="submit" value="OK" class="button" name="btn_ok">&nbsp;&nbsp;');
    alertWin.document.write('</TD>');
    alertWin.document.write('</TR>');

    alertWin.document.writeln('</TABLE>');
    alertWin.document.writeln('</FORM>');
    alertWin.document.writeln('<script language="JavaScript" type="text/javascript">');
    alertWin.document.writeln('<!-- ');
    alertWin.document.writeln('setTimeout("document.forms.promptfrm.btn_ok.focus()",100);');
    alertWin.document.writeln('// -->');
    alertWin.document.writeln('</script>');
    alertWin.document.writeln('</CENTER></BODY></HTML>');
    alertWin.document.close();	
    
    if (window.focus) {alertWin.focus()}

  }



  function ndot_prompt(url, title, msg, defval, unit) {

    var w = 1024, h = 768;
    w = screen.width;
    h = screen.height;

    var popW = 400, popH = 140;

    var leftPos = (w-popW)/2, topPos = (h-popH)/2;

    var promptWin = null;

    promptWin=window.open('','ndot_prompt','height='+popH+',width='+popW+',top='+topPos+',left='+leftPos+',resizable=yes,scrollbars=no,menubar=no,statusbar=no');

    promptWin.document.write('<HTML><HEAD><TITLE>' + title + '</TITLE>');	
    promptWin.document.write('<STYLE type="text/css">');
    promptWin.document.write('* { font-family : Helvetica, sans-serif; font-size : 9pt; color : #000000; font-weight : bold;}');
    promptWin.document.write('.button { font-family : Helvetica, sans-serif; font-size : 9pt; color : #000000; width:70px;}');
    promptWin.document.write('.inputtext { font-family : Helvetica, sans-serif; font-size : 9pt; color : #000000; width:70px; text-align:right;}');
    promptWin.document.write('BODY { background-color: #D6D3CE;}');
    promptWin.document.write('</STYLE>');
    promptWin.document.write('</HEAD>');
    promptWin.document.write('<BODY BGCOLOR=#D6D3CE TEXT=#000000 LINK=#000000 VLINK=#000000>');
    promptWin.document.write('<CENTER>');
    promptWin.document.write('<FORM ACTION="#" METHOD="GET" NAME="promptfrm" ONSUBMIT="opener.location=\''+url+'\'+document.promptfrm.val.value;window.close();">');

    promptWin.document.write('<TABLE BORDER="0" CELLSPACING="0" CELLPADDING="8">');

    promptWin.document.write('<TR>');
    promptWin.document.write('<TD ALIGN="center" VALIGN="top"><IMG SRC="templates/default/graphics/question.png"></TD>');
    promptWin.document.write('<TD ALIGN="center" VALIGN="middle">');
    promptWin.document.write(msg);
    promptWin.document.write('&nbsp;<INPUT TYPE="text" class="inputtext" NAME="val" SIZE="15" MAXLENGTH="15" VALUE="'+defval+'">&nbsp;');
    promptWin.document.write(unit);
    promptWin.document.write('</TD>');
    promptWin.document.write('</TR>');

    promptWin.document.write('<TR>');
    promptWin.document.write('<TD COLSPAN="2" ALIGN="center" VALIGN="middle">');
    promptWin.document.write('<input type="submit" value="OK" class="button" name="btn_ok">&nbsp;&nbsp;');
    promptWin.document.write('<input type="button" value="Anuluj" class="button" name="btn_cancel" onclick="window.close();">');
    promptWin.document.write('</TD>');
    promptWin.document.write('</TR>');

    promptWin.document.write('</TABLE>');
    
    promptWin.document.writeln('</FORM>');
    promptWin.document.writeln('<script language="JavaScript" type="text/javascript">');
    promptWin.document.writeln('<!-- ');
    promptWin.document.writeln('setTimeout("document.forms.promptfrm.inputtext.focus()",100);');
    promptWin.document.writeln('// -->');
    promptWin.document.writeln('</script>');
    promptWin.document.write('</CENTER></BODY></HTML>');
    promptWin.document.close();	
    
    if (window.focus) {promptWin.focus()}

  }






  var rowClickEffect_prev_row = null;
  var rowClickEffect_prev_class = null;
  
	function rowClickEffect(row_ob, classname, url)
	{
    if (rowClickEffect_prev_row != null)
      rowClickEffect_prev_row.className=rowClickEffect_prev_class;

    rowClickEffect_prev_row = row_ob;

    rowClickEffect_prev_class = row_ob.className;
    row_ob.className=classname;

    if (url!=null && url!='')
      window.location=url;

  }

	function rowClickEffectInputNum(row_ob, classname, url, msg, defval, unit)
	{
    if (url!=null && url!='')
    {
      ndot_prompt(url, 'N.S New Image', msg, defval, unit);
    }
  }

	function rowClickEffectConfirm(row_ob, classname, url, msg)
	{
    if (rowClickEffect_prev_row != null)
      rowClickEffect_prev_row.className=rowClickEffect_prev_class;

    rowClickEffect_prev_row = row_ob;

    rowClickEffect_prev_class = row_ob.className;
    row_ob.className=classname;

    if (url!=null && url!='')
    {
      var value = confirm(msg);

      if (value)
      {
        window.location = url;
      }
    }
  }


  function togglechange(id, newClass)
  {
    identity=document.getElementById(id);
    identity.className=newClass;
  } 


  function tmsgs(msg, obname, classname) 
  {
    var m = document.getElementById(obname);
    m.className=classname;
    m.appendChild(document.createTextNode(msg));
  }

  function SetAllCheckBoxes(FormName, FieldNamePart, CheckValue)
  {
    if(!document.forms[FormName])
      return;
    var objCheckBoxes = document.forms[FormName].elements;
    if(!objCheckBoxes)
      return;

    var countCheckBoxes = objCheckBoxes.length;

    if(!countCheckBoxes)
      objCheckBoxes.checked = CheckValue;
    else
      for(var i = 0; i < countCheckBoxes; i++)
      {
        if (objCheckBoxes[i].name.search(FieldNamePart)!=-1)
        {
          objCheckBoxes[i].checked = CheckValue;
        }
      }
  }

  function goToLocation(url)
  {
    window.location = url;
  }

  function parseFloatX(str)
  {
    var newstr = str.replace(',', '.');
    return parseFloat(newstr)
  }

  function floatToCurrency(val)
  {
    var newval = Math.round(val*100)/100;
    var str = newval.toString();
    var newstr = str.replace('.', ',');
    return newstr
  }

function submitenter(myfield,e)
{
  var keycode;
  if (window.event) keycode = window.event.keyCode;
  else if (e) keycode = e.which;
  else return true;

  if (keycode == 13)
  {
  myfield.form.submit();
  return false;
  }
  else
  return true;
}

function closeWindow()
{
  self.close();
}
