//========================================================================================
//Show or Hide table with images
function showHideTableWithImage(theTable,theImg)
{
if (document.getElementById(theTable).style.display == 'none')
   {
   document.getElementById(theTable).style.display = 'block';
   document.getElementById(theImg).src='../img/collapse.gif';
   }
   else
   {
   document.getElementById(theTable).style.display = 'none';
   document.getElementById(theImg).src='../img/expand.gif';
   }
}
//========================================================================================
function resetfield(obj)
{
	obj.value = '';
}



//===========================================================
function showFurther(theTable)
{
     if (document.getElementById(theTable).style.display == 'none')
     {
          document.getElementById(theTable).style.display = 'block';
     }
}



function hideFurther(theTable)
{
     if (document.getElementById(theTable).style.display == 'none')
     {
          document.getElementById(theTable).style.display = 'none';
     }
     else
     {
          document.getElementById(theTable).style.display = 'none';
     }
}



function showhide (id) 
{ 
var style = document.getElementById(id).style 
if (style.visibility == "hidden") 
style.visibility = "visible"; 
else 
style.visibility = "hidden"; 
} 



/**
 * resize.js 0.3 970811
 * by gary smith
 * js component for "reloading page onResize"
 */

if(!window.saveInnerWidth) {
  window.onresize = resizeIt;
  window.saveInnerWidth = window.innerWidth;
  window.saveInnerHeight = window.innerHeight;
}

function resizeIt() {
    if (saveInnerWidth < window.innerWidth || 
        saveInnerWidth > window.innerWidth || 
        saveInnerHeight > window.innerHeight || 
        saveInnerHeight < window.innerHeight ) 
    {
        window.history.go(0);
    }
}

function toggle(f){
  if(f.elements['mycheckbox'].checked == true){
    f.item1.style.display = 'block';
    f.item2.style.display = 'block';
    f.item3.style.display = 'block';
  } else {
    f.item1.style.display = 'none';
    f.item2.style.display = 'none';
    f.item3.style.display = 'none';
  }
}


//========================================================================================
//Show or Hide Div with a click of a checkbox
function showHideChkBox(chkBox,objName) 
{
if (chkBox.checked) {
     document.getElementById(objName).style.display="block";
     } 
     else 
     {
      document.getElementById(objName).style.display="none";
     }
}
//========================================================================================

//========================================================================================

<!-- Begin
function setDataType(cValue)
  {
    // THIS FUNCTION CONVERTS DATES AND NUMBERS FOR PROPER ARRAY
    // SORTING WHEN IN THE SORT FUNCTION
    var isDate = new Date(cValue);
    if (isDate == "NaN")
      {
        if (isNaN(cValue))
          {
            // THE VALUE IS A STRING, MAKE ALL CHARACTERS IN
            // STRING UPPER CASE TO ASSURE PROPER A-Z SORT
            cValue = cValue.toUpperCase();
            return cValue;
          }
        else
          {
            // VALUE IS A NUMBER, TO PREVENT STRING SORTING OF A NUMBER
            // ADD AN ADDITIONAL DIGIT THAT IS THE + TO THE LENGTH OF
            // THE NUMBER WHEN IT IS A STRING
            var myNum;
            myNum = String.fromCharCode(48 + cValue.length) + cValue;
            return myNum;
          }
        }
  else
      {
        // VALUE TO SORT IS A DATE, REMOVE ALL OF THE PUNCTUATION AND
        // AND RETURN THE STRING NUMBER
        //BUG - STRING AND NOT NUMERICAL SORT .....
        // ( 1 - 10 - 11 - 2 - 3 - 4 - 41 - 5  etc.)
        var myDate = new String();
        myDate = isDate.getFullYear() + " " ;
        myDate = myDate + isDate.getMonth() + " ";
        myDate = myDate + isDate.getDate(); + " ";
        myDate = myDate + isDate.getHours(); + " ";
        myDate = myDate + isDate.getMinutes(); + " ";
        myDate = myDate + isDate.getSeconds();
        //myDate = String.fromCharCode(48 + myDate.length) + myDate;
        return myDate ;
      }
  }
function compareReverse(a, b) {
  if ( a < b ) return 1;
  if ( a > b ) return -1;
  return 0;
}
function sortTable(col, tableToSort, order)
  {
    var iCurCell = col + tableToSort.cols;
    var totalRows = tableToSort.rows.length;
    var bSort = 0;
    var colArray = new Array();
    var oldIndex = new Array();
    var indexArray = new Array();
    var bArray = new Array();
    var newRow;
    var newCell;
    var i;
    var c;
    var j;
    // ** POPULATE THE ARRAY colArray WITH CONTENTS OF THE COLUMN SELECTED
    for (i=1; i < tableToSort.rows.length; i++)
      {
        colArray[i - 1] = setDataType(tableToSort.cells(iCurCell).innerText);
        iCurCell = iCurCell + tableToSort.cols;
      }
    // ** COPY ARRAY FOR COMPARISON AFTER SORT
    for (i=0; i < colArray.length; i++)
      {
        bArray[i] = colArray[i];
      }
    // ** SORT THE COLUMN ITEMS
    //alert ( colArray );
	if (order == 'desc'){
    		colArray.sort(compareReverse);
	} else {
		colArray.sort()
	}
    //alert ( colArray );
    for (i=0; i < colArray.length; i++)
      { // LOOP THROUGH THE NEW SORTED ARRAY
        indexArray[i] = (i+1);
        for(j=0; j < bArray.length; j++)
          { // LOOP THROUGH THE OLD ARRAY
            if (colArray[i] == bArray[j])
              {  // WHEN THE ITEM IN THE OLD AND NEW MATCH, PLACE THE
                // CURRENT ROW NUMBER IN THE PROPER POSITION IN THE
                // NEW ORDER ARRAY SO ROWS CAN BE MOVED ....
                // MAKE SURE CURRENT ROW NUMBER IS NOT ALREADY IN THE
                // NEW ORDER ARRAY
                for (c=0; c<i; c++)
                  {
                    if ( oldIndex[c] == (j+1) )
                    {
                      bSort = 1;
                    }
                      }
                      if (bSort == 0)
                        {
                          oldIndex[i] = (j+1);
                        }
                          bSort = 0;
                        }
          }
    }
  // ** SORTING COMPLETE, ADD NEW ROWS TO BASE OF TABLE ....
  for (i=0; i<oldIndex.length; i++)
    {
      newRow = tableToSort.insertRow();
      for (c=0; c<tableToSort.cols; c++)
        {
          newCell = newRow.insertCell();
          newCell.innerHTML = tableToSort.rows(oldIndex[i]).cells(c).innerHTML;
        }
      }
  //MOVE NEW ROWS TO TOP OF TABLE ....
  for (i=1; i<totalRows; i++)
    {
      tableToSort.moveRow((tableToSort.rows.length -1),1);
    }
  //DELETE THE OLD ROWS FROM THE BOTTOM OF THE TABLE ....
  for (i=1; i<totalRows; i++)
    {
      tableToSort.deleteRow();
    }
  }
//  End -->

/*
USO:
1) definire una tabella; darle un nome e un id univoco.
es.: <TABLE WIDTH="75%" BORDER=1 CELLSPACING=1 CELLPADDING=1 name="tabellakit" id=tabellakit  cols=5>

2) nella definizione delle colonne della prima riga mettere questo codice:
<A href="javascript:sortTable(0, rsTable);"> .... </A>
es.:
	<TR bgcolor=mediumblue>
		<TD><A href="javascript:sortTable(0, tabellakit);"><FONT color=white><B>ID</FONT></B></A></TD>
		<TD><A href="javascript:sortTable(1, tabellakit);"><FONT color=white><B>NAME</FONT></B></A></TD>
		<TD><A href="javascript:sortTable(2, tabellakit);"><FONT color=white><B>DATE</FONT></B></A></TD>
		<TD><A href="javascript:sortTable(3, tabellakit);"><FONT color=white><B>PHONE</FONT></B></A></TD>
	</TR>
	<TR>
*/

//========================================================================================
			
