﻿var pWindow = null;
function oWindow( url, width, height )
{
	  if( pWindow && !pWindow.closed ) 
      {
 	      pWindow.close();
	  }  
	  pWindow = window.open( url, "displayWindow", 'width=' + width + ',height=' + height + ',resizable=0,scrollbars=1,menubar=0,left=10,top=10');
      pWindow.focus();
}

function picWindow( url, width, height )
{
	  if( pWindow && !pWindow.closed ) 
      {
 	      pWindow.close();
	  }  
	  pWindow = window.open( url, "displayWindow", 'width=' + width + ',height=' + height + ',resizable=0,scrollbars=0,menubar=0,left=10,top=10');
      pWindow.focus();
}
function ask(URL)
{
    if(confirm("Czy na pewno" )) window.location.href=URL
}
function ask2()
{
    if(confirm("Czy na pewno" )) document.multiselect.submit()
}
function checkAll( frm, arr, mark )
{
	for (i = 0; i <= frm.elements.length; i++)
	{
		try
		{
			if(frm.elements[i].name == arr)
			{
				frm.elements[i].checked = mark;
			}
		}
		catch(er)
		{}
	}	
}
function mark( id )
{
	for (i = 0; i <= document.multiselect.elements.length; i++)
	{
		try
		{
			if( document.multiselect.elements[i].value == id )
			{
				if( document.multiselect.elements[i].checked == true )
				{
					document.multiselect.elements[i].checked = false;
				}
				else
				{
					document.multiselect.elements[i].checked = true;
				}	
			}
		}
		catch(er)
		{}
	}
} 
function ExpandTable()
{
	var oTable, oRow, oCell;
	nr = document.forms[0].length;
    if( nr > 450 )
	{
        alert ( 'Maksymalnie można dodać 20 składników.' );
	}
	else
	{
 		oTable = document.getElementById("oTable");
        index = oTable.rows.length;
        oRow = oTable.insertRow(index);
        oCell1 = oRow.insertCell(0);
    	oCell2 = oRow.insertCell(1);
        oCell3 = oRow.insertCell(2);
        oCell2.colSpan = 3;
        oCell1.innerHTML = 'Ilość:<input type="text" size="3" name="ilosc_' + nr + '" id="ilosc_' + nr + '" />';
        oCell2.innerHTML = 'Miara:' + ' ' + '<select name="jedn_' + nr + '" id="jedn_' + nr + '"></select>';
        oCell3.innerHTML = 'Produkt:<input type="text" size="30" name="skladnik_' + nr + '"  />';
        oCell1.align = "center";
        oCell2.align = "center";
        oCell2.align = "center";
        var c = eval( "document.forms[0].jedn_" + nr );
	    nr++;
    	var j = 0;
        for( i = 1; i<miary.length; i += 2)
		{
            opt = new Option( miary[i], miary[i-1], false, false);
        	c.options[j++] = opt;
	    }
	}
}
function ShrinkTable( row )
{
	var oRow, oTable;
	oRow = document.getElementById( row );
	oTable = document.getElementById( "oTable" )
	oTable.deleteRow( oRow.rowIndex );
}

function swapOptions(frm, grpName, eleIndex, nbElements, arName)
{
    var n = "";
    var ctl;

    for (var i = 0; i < nbElements; i++) {
        ctl = frm.form[grpName+'['+i+']'];
        if (!ctl) {
            ctl = frm.form[grpName+'['+i+'][]'];
        }
        if (i <= eleIndex) {
            n += "_"+ctl.value;
        } else {
            ctl.length = 0;
        }
    }

    var t = eval("typeof("+arName + n +")");
    if (t != 'undefined') {
        var the_array = eval(arName+n);
        var j = 0;
        n = eleIndex + 1;
        ctl = frm.form[grpName+'['+ n +']'];
        if (!ctl) {
            ctl = frm.form[grpName+'['+ n +'][]'];
        }
        for (var i in the_array) {
            opt = new Option(the_array[i], i, false, false);
            ctl.options[j++] = opt;
        }
    }
    if (eleIndex+1 < nbElements) {
        swapOptions(frm, grpName, eleIndex+1, nbElements, arName);
    }
}
// Compare two options within a list by VALUES
function compareOptionValues(a, b) 

{ 
  // Radix 10: for numeric values
  // Radix 36: for alphanumeric values
  var sA = parseInt( a.value, 36 );  
  var sB = parseInt( b.value, 36 );  
  return sA - sB;
}
// Compare two options within a list by TEXT
function compareOptionText(a, b) 
{ 
  // Radix 10: for numeric values
  // Radix 36: for alphanumeric values
  var sA = parseInt( a.text, 36 );  
  var sB = parseInt( b.text, 36 );  
  return sA - sB;
}
// Dual list move function
function moveDualList( srcList, destList, moveAll ) 
{
  // Do nothing if nothing is selected
  if (  ( srcList.selectedIndex == -1 ) && ( moveAll == false )   )
  {
    return;
  }
  newDestList = new Array( destList.options.length );
  var len = 0;
  for( len = 0; len < destList.options.length; len++ ) 
  {
    if ( destList.options[ len ] != null )
    {
      newDestList[ len ] = new Option( destList.options[ len ].text, destList.options[ len ].value, destList.options[ len ].defaultSelected, destList.options[ len ].selected );
    }
  }
  for( var i = 0; i < srcList.options.length; i++ ) 
  { 
    if ( srcList.options[i] != null && ( srcList.options[i].selected == true || moveAll ) )
    {
       // Statements to perform if option is selected
       // Incorporate into new list
       newDestList[ len ] = new Option( srcList.options[i].text, srcList.options[i].value, srcList.options[i].defaultSelected, srcList.options[i].selected );
       len++;
    }
  }
  // Sort out the new destination list
  newDestList.sort( compareOptionValues );   // BY VALUES
  // Populate the destination with the items from the new array
  for ( var j = 0; j < newDestList.length; j++ ) 
  {
    if ( newDestList[ j ] != null )
    {
      destList.options[ j ] = newDestList[ j ];
      destList.options[ j ].selected = false;
    }
  }
  // Erase source list selected elements
  for( var i = srcList.options.length - 1; i >= 0; i-- ) 
  { 
    if ( srcList.options[i] != null && ( srcList.options[i].selected == true || moveAll ) )
    {
       // Erase Source
       srcList.options[i]       = null;
    }
  }
}
function selectAll( select )
{
  for( var i = select.options.length - 1; i >= 0; i-- ) 
  { 
    if ( select.options[i] != null  )
    {
       select.options[i].selected = true;
    }
  }
}
function over(num)
{     
    for(i=1; i <= num; i++)
    {
        namediv = 't'+i;
        obj=document.getElementById(namediv);
        obj.src='images/star.gif';        
    }
}
function clear_all()
{     
    for(i=1; i < 6; i++)
    {
        namediv = 't'+i;
        obj=document.getElementById(namediv);
        obj.src='images/star2.gif';        
    }
}
function vote( grade, item )
{   
    var basehref = "http://aktywnisingle.pl/"
    document.location = basehref + "przepis.php?ocena=" + grade +"&id=" + item
}

