function print_produkt_info(){
    var printWin = window.open('','printSpecial','width=700,height=700,location=yes,scrollbars=yes,resizable=yes');
    printWin.document.open();
    printWin.document.write('<html><head>');
    printWin.document.write('<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><LINK href="../template/css/style.css" type="text/css" rel="stylesheet" /></head><body style="background-image:none;background-color:white;text-align:left;padding:25px;">');
    printWin.document.write(document.getElementById('produkt_info').innerHTML);
    printWin.document.getElementById('pop_zam').style.display='none';
    printWin.document.getElementById('pop_print').style.display='none';
    printWin.document.write('</body></html>');
    printWin.document.close();
    printWin.print();
}




function open_alert(text, close_time){
  var ob1=document.getElementById('alert_global');
  ob1.innerHTML= text;      
      var offY;    
   if (document.all){
      offY= truebody().scrollTop;
      //document.getElementById('produkt_info').style.left= (truebody().clientWidth /2 - 500 );
   }else{
      offY= window.pageYOffset;
   }
   
   document.getElementById('alert_global').style.top= (offY+(parseInt(truebody().clientHeight) /2)) +'px';
   document.getElementById('alert_global').style.left= (parseInt(truebody().clientWidth) /2) +'px';
   ob1.style.visibility='visible';
   
   if( arguments.length==2 ){
      setTimeout("close_alert()", close_time);
   } 
}


function close_alert(){  
  var ob=document.getElementById('alert_global') 
  ob.style.visibility='hidden' ;
}



function toogle_alert(id){
  var ob=document.getElementById(id).style; 
  if (ob.visibility =="hidden" ){
    ob.visibility= 'visible';
  }else{
    ob.visibility='hidden' ;
  }    
}



/* W mozilli nie moze zakończyć się ładowanie strony w tej funkcji*/
function truebody(){


   return (document.compatMode && 
    document.compatMode!="BackCompat")? document.documentElement : document.body
}


//type czy produkty czy zestaw
function load_image1(name,prod_nr, prod_name, id, width, type){
  if (type!=undefined){
    load_image_base(name,prod_nr, prod_name, id, 1);
  }else{
    load_image_base(name,prod_nr, prod_name, id, 0);
  }
}

function load_image(name,prod_nr, prod_name, id,rys_width, type){
   prod_id=id // zmienna w szablonie drukuj.tpl.html
   document.images['produkt_image'].src= name
   
   //var width_ob= document.images['produkt_image'].width;
   
   document.getElementById('produkt_info').style.display='none';
   //alert(rys_width);   
   if (rys_width<400) rys_width=400;
   document.getElementById('produkt_info').style.width=rys_width+'px';
   
   
   
   //alert(document.getElementById('produkt_info').style.top);   
   //alert(document.body.scrollTop);
    //alert(window.pageYOffset);
   var cells= document.getElementById('prodpop_'+id).cells;
   
   //alert(document.getElementById('prodpop_'+id).cells[9].innerHTML);    
   var ind= 0;
   if (arguments.length==6){
     ind=1;
   }
      
   if (document.all){
      document.getElementById('produkt_info').style.top= truebody().scrollTop+20+'px';
      //document.getElementById('produkt_info').style.left= (truebody().clientWidth /2 - 500 );
   }else{
      document.getElementById('produkt_info').style.top= window.pageYOffset+20+'px';
   }
   document.getElementById('produkt_info').style.left= (parseInt(truebody().clientWidth) /2-500) +'px';
   
   document.getElementById('produkt_info_nr_kat').innerHTML=prod_nr;
   document.getElementById('produkt_info_name').innerHTML=prod_name;
   document.getElementById('produkt_info_symbol').innerHTML=cells[1+ind ].innerHTML;
   document.getElementById('produkt_info_jm').innerHTML=cells[3+ind ].innerHTML;
   document.getElementById('produkt_info_jm2').innerHTML=cells[3+ind ].innerHTML;
   document.getElementById('produkt_info_waga').innerHTML=cells[4+ind].innerHTML;
   document.getElementById('produkt_info_ilosc').innerHTML=cells[2+ind].innerHTML;
   
   
     for(var i=5+ind; i<cells.length ; i++){
       if (document.getElementById('produkt_info_wymiar_'+(i-5)) ){
          document.getElementById('produkt_info_wymiar_'+(i-5)).innerHTML=cells[i].innerHTML;
       }
     }
   
   
   
   //alert(document.images['produkt_image'].width);
   
   //document.images['produkt_image'].width
   
   if (document.images['produkt_image'].width>0){
      //document.getElementById('produkt_info').style.width= document.images['produkt_image'].width+'px';
   }
   //document.getElementById('produkt_info').style.display='block'
   //document.getElementById('produkt_info').style.display='none'
   document.getElementById('produkt_info').style.display='block'
   
        
   //alert(window.pageYOffset)
   
   //document.getElementById('produkt_info').style.width=width_ob+'px';

}



var winRys =null;

function popup(url, wdt, hgh){
	var params = "width="+wdt+", height="+hgh+", toolbar=0, location=0, directories=0, status=0, border=0, scrollbars=0, menubar=0, resizable=0";
	if (winRys!=null){
		winRys.close();
	}
	winRys = window.open('' , 'popRys', params);
	winRys.resizeTo(wdt+40,hgh+80); //+40+80 nie rozumiem ale skrole sie nie pojawiają
	winRys.document.innerHTML='';

	
	winRys.document.write("<html>");		
	winRys.document.write("<head>");		
	winRys.document.write("<title>TKREM - Trasy Kablowe </title>");
	winRys.document.write("</head><body onblur='self.close()'>");		
	//winRys.document.write(url);
	winRys.document.write("<IMG src=\""+url+"\" width=\""+wdt+"\" height=\""+hgh+"\" border=\"0\"  style=\"cursor:hand;\" onclick=\"javascript:parent.focus();self.close();winRys=null;return void(0);\" alt=\"kliknij aby zamkn±ć\" />");
	winRys.document.write("</body></html>");
	//winRys.onclick=self.close();
	if(winRys.focus){ winRys.focus();}
	return false;			
}

function md5(){
	var str=new String('abcdefghijklmnopqrstuvxyz0123456789');
	//ABCDEFGHIJKLMNOPQRSTUVXYZ;
	//alert(str);
	var key='';
	var len= str.length;
	for (var i=0; i<32; i++){
		var ind= Math.floor(len*Math.random());
		key+= str.charAt(ind);
	}
	return key;
}



var Url = {

	// public method for url encoding
	encode : function (string) {
		return escape(this._utf8_encode(string));
	},

	// public method for url decoding
	decode : function (string) {
		return this._utf8_decode(unescape(string));
	},

	// private method for UTF-8 encoding
	_utf8_encode : function (string) {
		string = string.replace(/\r\n/g,"\n");
		var utftext = "";

		for (var n = 0; n < string.length; n++) {

			var c = string.charCodeAt(n);

			if (c < 128) {
				utftext += String.fromCharCode(c);
			}
			else if((c > 127) && (c < 2048)) {
				utftext += String.fromCharCode((c >> 6) | 192);
				utftext += String.fromCharCode((c & 63) | 128);
			}
			else {
				utftext += String.fromCharCode((c >> 12) | 224);
				utftext += String.fromCharCode(((c >> 6) & 63) | 128);
				utftext += String.fromCharCode((c & 63) | 128);
			}

		}

		return utftext;
	},

	// private method for UTF-8 decoding
	_utf8_decode : function (utftext) {
		var string = "";
		var i = 0;
		var c = c1 = c2 = 0;

		while ( i < utftext.length ) {

			c = utftext.charCodeAt(i);

			if (c < 128) {
				string += String.fromCharCode(c);
				i++;
			}
			else if((c > 191) && (c < 224)) {
				c2 = utftext.charCodeAt(i+1);
				string += String.fromCharCode(((c & 31) << 6) | (c2 & 63));
				i += 2;
			}
			else {
				c2 = utftext.charCodeAt(i+1);
				c3 = utftext.charCodeAt(i+2);
				string += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));
				i += 3;
			}

		}

		return string;
	}

}

//-----------------------------------------------------------------------------
//
// Skrypt sortujący brainjar.com
//
//-----------------------------------------------------------------------------
// sortTable(id, col, rev)
//
//  id  - ID of the TABLE, TBODY, THEAD or TFOOT element to be sorted.
//  col - Index of the column to sort, 0 = first column, 1 = second column,
//        etc.
//  rev - If true, the column is sorted in reverse (descending) order
//        initially.
//
// Note: the team name column (index 1) is used as a secondary sort column and
// always sorted in ascending order.
//-----------------------------------------------------------------------------

function sortTable(id, col, rev) {

  // Get the table or table section to sort.
  var tblEl = document.getElementById(id);

  // The first time this function is called for a given table, set up an
  // array of reverse sort flags.
  if (tblEl.reverseSort == null) {
    tblEl.reverseSort = new Array();
    // Also, assume the team name column is initially sorted.
    tblEl.lastColumn = 1;
  }

  // If this column has not been sorted before, set the initial sort direction.
  if (tblEl.reverseSort[col] == null)
    tblEl.reverseSort[col] = rev;

  // If this column was the last one sorted, reverse its sort direction.
  if (col == tblEl.lastColumn)
    tblEl.reverseSort[col] = !tblEl.reverseSort[col];

  // Remember this column as the last one sorted.
  tblEl.lastColumn = col;

  // Set the table display style to "none" - necessary for Netscape 6 
  // browsers.
  var oldDsply = tblEl.style.display;
  tblEl.style.display = "none";

  // Sort the rows based on the content of the specified column using a
  // selection sort.

  var tmpEl;
  var i, j;
  var minVal, minIdx;
  var testVal;
  var cmp;

  for (i = 0; i < tblEl.rows.length - 1; i++) {

    // Assume the current row has the minimum value.
    minIdx = i;
    minVal = getTextValue(tblEl.rows[i].cells[col]);

    // Search the rows that follow the current one for a smaller value.
    for (j = i + 1; j < tblEl.rows.length; j++) {
      testVal = getTextValue(tblEl.rows[j].cells[col]);
      cmp = compareValues(minVal, testVal);
      // Negate the comparison result if the reverse sort flag is set.
      if (tblEl.reverseSort[col])
        cmp = -cmp;
      // Sort by the second column (team name) if those values are equal.
      if (cmp == 0 && col != 1)
        cmp = compareValues(getTextValue(tblEl.rows[minIdx].cells[1]),
                            getTextValue(tblEl.rows[j].cells[1]));
      // If this row has a smaller value than the current minimum, remember its
      // position and update the current minimum value.
      if (cmp > 0) {
        minIdx = j;
        minVal = testVal;
      }
    }

    // By now, we have the row with the smallest value. Remove it from the
    // table and insert it before the current row.
    if (minIdx > i) {
      tmpEl = tblEl.removeChild(tblEl.rows[minIdx]);
      tblEl.insertBefore(tmpEl, tblEl.rows[i]);
    }
  }

  // Make it look pretty.
  //makePretty(tblEl, col);

  // Set team rankings.
  //setRanks(tblEl, col, rev);

  // Restore the table's display style.
  tblEl.style.display = oldDsply;
  
  return false;
}

//-----------------------------------------------------------------------------
// Functions to get and compare values during a sort.
//-----------------------------------------------------------------------------

// This code is necessary for browsers that don't reflect the DOM constants
// (like IE).
if (document.ELEMENT_NODE == null) {
  document.ELEMENT_NODE = 1;
  document.TEXT_NODE = 3;
}

function getTextValue(el) {
  var i;
  var s;
  // Find and concatenate the values of all text nodes contained within the
  // element.
  s = "";
  for (i = 0; i < el.childNodes.length; i++)
    if (el.childNodes[i].nodeType == document.TEXT_NODE)
      s += el.childNodes[i].nodeValue;
    else if (el.childNodes[i].nodeType == document.ELEMENT_NODE &&
             el.childNodes[i].tagName == "BR")
      s += " ";
    else
      // Use recursion to get text within sub-elements.
      s += getTextValue(el.childNodes[i]);
  return normalizeString(s);
}

function compareValues(v1, v2) {

  var f1, f2;

  // If the values are numeric, convert them to floats.

  f1 = parseFloat(v1);
  f2 = parseFloat(v2);
  if (!isNaN(f1) && !isNaN(f2)) {
    v1 = f1;
    v2 = f2;
  }

  // Compare the two values.
  if (v1 == v2)
    return 0;
  if (v1 > v2)
    return 1
  return -1;
}

// Regular expressions for normalizing white space.
var whtSpEnds = new RegExp("^\\s*|\\s*$", "g");
var whtSpMult = new RegExp("\\s\\s+", "g");

function normalizeString(s) {

  s = s.replace(whtSpMult, " ");  // Collapse any multiple whites space.
  s = s.replace(whtSpEnds, "");   // Remove leading or trailing white space.

  return s;
}

//-----------------------------------------------------------------------------
// Functions to update the table appearance after a sort.
//-----------------------------------------------------------------------------

// Style class names.
var rowClsNm = "alternateRow";
var colClsNm = "sortedColumn";

// Regular expressions for setting class names.
var rowTest = new RegExp(rowClsNm, "gi");
var colTest = new RegExp(colClsNm, "gi");

function makePretty(tblEl, col) {

  var i, j;
  var rowEl, cellEl;

  // Set style classes on each row to alternate their appearance.
  for (i = 0; i < tblEl.rows.length; i++) {
   rowEl = tblEl.rows[i];
   rowEl.className = rowEl.className.replace(rowTest, "");
    if (i % 2 != 0)
      rowEl.className += " " + rowClsNm;
    rowEl.className = normalizeString(rowEl.className);
    // Set style classes on each column (other than the name column) to
    // highlight the one that was sorted.
    for (j = 2; j < tblEl.rows[i].cells.length; j++) {
      cellEl = rowEl.cells[j];
      cellEl.className = cellEl.className.replace(colTest, "");
      if (j == col)
        cellEl.className += " " + colClsNm;
      cellEl.className = normalizeString(cellEl.className);
    }
  }

  // Find the table header and highlight the column that was sorted.
  var el = tblEl.parentNode.tHead;
  rowEl = el.rows[el.rows.length - 1];
  // Set style classes for each column as above.
  for (i = 2; i < rowEl.cells.length; i++) {
    cellEl = rowEl.cells[i];
    cellEl.className = cellEl.className.replace(colTest, "");
    // Highlight the header of the sorted column.
    if (i == col)
      cellEl.className += " " + colClsNm;
      cellEl.className = normalizeString(cellEl.className);
  }
}

function setRanks(tblEl, col, rev) {

  // Determine whether to start at the top row of the table and go down or
  // at the bottom row and work up. This is based on the current sort
  // direction of the column and its reversed flag.

  var i    = 0;
  var incr = 1;
  if (tblEl.reverseSort[col])
    rev = !rev;
  if (rev) {
    incr = -1;
    i = tblEl.rows.length - 1;
  }

  // Now go through each row in that direction and assign it a rank by
  // counting 1, 2, 3...

  var count   = 1;
  var rank    = count;
  var curVal;
  var lastVal = null;

  // Note that this loop is skipped if the table was sorted on the name
  // column.
  while (col > 1 && i >= 0 && i < tblEl.rows.length) {

    // Get the value of the sort column in this row.
    curVal = getTextValue(tblEl.rows[i].cells[col]);

    // On rows after the first, compare the sort value of this row to the
    // previous one. If they differ, update the rank to match the current row
    // count. (If they are the same, this row will get the same rank as the
    // previous one.)
    if (lastVal != null && compareValues(curVal, lastVal) != 0)
        rank = count;
    // Set the rank for this row.
    tblEl.rows[i].rank = rank;

    // Save the sort value of the current row for the next time around and bump
    // the row counter and index.
    lastVal = curVal;
    count++;
    i += incr;
  }

  // Now go through each row (from top to bottom) and display its rank. Note
  // that when two or more rows are tied, the rank is shown on the first of
  // those rows only.

  var rowEl, cellEl;
  var lastRank = 0;

  // Go through the rows from top to bottom.
  for (i = 0; i < tblEl.rows.length; i++) {
    rowEl = tblEl.rows[i];
    cellEl = rowEl.cells[0];
    // Delete anything currently in the rank column.
    while (cellEl.lastChild != null)
      cellEl.removeChild(cellEl.lastChild);
    // If this row's rank is different from the previous one, Insert a new text
    // node with that rank.
    if (col > 1 && rowEl.rank != lastRank) {
      cellEl.appendChild(document.createTextNode(rowEl.rank));
      lastRank = rowEl.rank;
    }
  }
}


