// #### MESSAGGIO SULLA BARRA DI STATO
//
  window.defaultStatus='GIACO: Gruppo Italiano per l\'Accesso alle Cure Orali';


function InStr(strSearch, charSearchFor)
/***

Returns the position of the character charSearchFor in strSearch

InStr(str, SearchForStr) : Returns the location a character (charSearchFor)
                           was found in the string str
========================================================================
InStr(strSearch, charSearchFor) : Returns the first location a substring (SearchForStr)
                           was found in the string str.  (If the character is not
                           found, -1 is returned.)
                           
Requires use of:
	Mid function
*/
{
	for (i=0; i < strSearch.length; i++)
	{
	    if (charSearchFor == Mid(strSearch, i, 1))
	    {
			return i;
	    }
	}
	return -1;
}

function Mid(str, start, len)
/***

Returns a specified number of characters from a string.

Mid(string, start, length): Returns a specified number of characters from a
                            string
============================================================================
  IN: str - the string we are LEFTing
      start - our string's starting position (0 based!!)
      len - how many characters from start we want to get

  RETVAL: The substring from start to start+len
// Keep in mind that strings in JavaScript are zero-based, so if you ask
// for Mid("Hello",1,1), you will get "e", not "H".  To get "H", you would
// simply type in Mid("Hello",0,1)

// You can alter the above function so that the string is one-based.  Just
// check to make sure start is not <= 0, alter the iEnd = start + len to
// iEnd = (start - 1) + len, and in your final return statement, just
// return ...substring(start-1,iEnd)
***/
{
  // Make sure start and len are within proper bounds
  if (start < 0 || len < 0) return "";

  var iEnd, iLen = String(str).length;
  if (start + len > iLen)
          iEnd = iLen;
  else
          iEnd = start + len;

  return String(str).substring(start,iEnd);
}


function Right(str, n)
/***

Returns a specified number of characters from the right side of a string.

Right(string, length): Returns a specified number of characters from the
                       right side of a string
========================================================================
  IN: str - the string we are RIGHTing
      n - the number of characters we want to return

  RETVAL: n characters from the right side of the string
***/
{
  if (n <= 0)     // Invalid bound, return blank string
     return "";
  else if (n > String(str).length)   // Invalid bound, return
     return str;                     // entire string
  else { // Valid bound, return appropriate substring
     var iLen = String(str).length;
     return String(str).substring(iLen, iLen - n);
  }
}
        
function Left(str, n)
/***

Returns a specified number of characters from the left side of a string.

Left(string, length): Returns a specified number of characters from the
                      left side of a string
========================================================================
  IN: str - the string we are LEFTing
      n - the number of characters we want to return

  RETVAL: n characters from the left side of the string
***/
{
  if (n <= 0)     // Invalid bound, return blank string
          return "";
  else if (n > String(str).length)   // Invalid bound, return
          return str;                // entire string
  else // Valid bound, return appropriate substring
          return String(str).substring(0,n);
}
        
function Trim(str)
/***

Returns a string without leading and trailing spaces

Trim(string) : Returns a copy of a string without leading or
               trailing spaces
        PURPOSE: Remove trailing and leading blanks from our string.
        IN: str - the string we want to Trim

        RETVAL: A Trimmed string!
***/
{
        return RTrim(LTrim(str));
}
        
function RTrim(str)
/***

Returns a string without trailing spaces

RTrim(string) : Returns a copy of a string without trailing spaces.
        PURPOSE: Remove trailing blanks from our string.
        IN: str - the string we want to RTrim

        RETVAL: An RTrimmed string!
***/
{
  // We don't want to trip JUST spaces, but also tabs,
  // line feeds, etc.  Add anything else you want to
  // "trim" here in Whitespace
  var whitespace = new String(" \t\n\r");

  var s = new String(str);

  if (whitespace.indexOf(s.charAt(s.length-1)) != -1) {
      // We have a string with trailing blank(s)...

      var i = s.length - 1;       // Get length of string

      // Iterate from the far right of string until we
      // don't have any more whitespace...
      while (i >= 0 && whitespace.indexOf(s.charAt(i)) != -1)
          i--;


      // Get the substring from the front of the string to
      // where the last non-whitespace character is...
      s = s.substring(0, i+1);
  }

        return s;
}

function LTrim(str)
/***

Returns a string without leading spaces

LTrim(string) : Returns a copy of a string without leading spaces.
        PURPOSE: Remove leading blanks from our string.
        IN: str - the string we want to LTrim

        RETVAL: An LTrimmed string!
***/
{
  var whitespace = new String(" \t\n\r");

  var s = new String(str);

  if (whitespace.indexOf(s.charAt(0)) != -1) {
      // We have a string with leading blank(s)...

      var j=0, i = s.length;

      // Iterate from the far left of string until we
      // don't have any more whitespace...
      while (j < i && whitespace.indexOf(s.charAt(j)) != -1)
          j++;


      // Get the substring from the first non-whitespace
      // character to the end of the string...
      s = s.substring(j, i);
  }

  return s;
}

function FormatDateTime(datetime, FormatType)
/***

Returns an expression formatted as a date or time.

FormatDateTime(datetime, FormatType) : Returns an expression formatted
                                       as a date or time
	 FomatType takes the following values
		1 - General Date = Friday, October 30, 1998
		2 - Typical Date = 10/30/98
		3 - Standard Time = 6:31 PM
		4 - Military Time = 18:31
***/
{
	var strDate = new String(datetime);

	if (strDate.toUpperCase() == "NOW") {
		var myDate = new Date();
		strDate = String(myDate);
	} else {
		var myDate = new Date(datetime);
		strDate = String(myDate);
	}


	// Get the date variable parts
	var Day = new String(strDate.substring(0,3));
	if (Day == "Sun") Day = "Sunday";
	if (Day == "Mon") Day = "Monday";
	if (Day == "Tue") Day = "Tuesday";
	if (Day == "Wed") Day = "Wednesday";
	if (Day == "Thu") Day = "Thursday";
	if (Day == "Fri") Day = "Friday";
	if (Day == "Sat") Day = "Saturday";	
	
	var Month = new String(strDate.substring(4,7)), MonthNumber = 0;
	if (Month == "Jan") { Month = "January"; MonthNumber = 1; }
	if (Month == "Feb") { Month = "February"; MonthNumber = 2; }
	if (Month == "Mar") { Month = "March"; MonthNumber = 3; }
	if (Month == "Apr") { Month = "April"; MonthNumber = 4; }
	if (Month == "May") { Month = "May"; MonthNumber = 5; }
	if (Month == "Jun") { Month = "June"; MonthNumber = 6; }
	if (Month == "Jul") { Month = "July"; MonthNumber = 7; }
	if (Month == "Aug") { Month = "August"; MonthNumber = 8; }
	if (Month == "Sep") { Month = "September"; MonthNumber = 9; }
	if (Month == "Oct") { Month = "October"; MonthNumber = 10; }
	if (Month == "Nov") { Month = "November"; MonthNumber = 11; }
	if (Month == "Dec") { Month = "December"; MonthNumber = 12; }
	
	var curPos = 11;
	var MonthDay = new String(strDate.substring(8,10));
	if (MonthDay.charAt(1) == " ") {
		MonthDay = "0" + MonthDay.charAt(0);
		curPos--;
	}	
	
	var MilitaryTime = new String(strDate.substring(curPos,curPos + 5));
	
	var Year = new String(strDate.substring(strDate.length - 4, strDate.length));	
	
	document.write(strDate + "");	

	// Format Type decision time!
	if (FormatType == 1)
		strDate = Day + ", " + Month + " " + MonthDay + ", " + Year;
	else if (FormatType == 2)
		strDate = MonthNumber + "/" + MonthDay + "/" + Year.substring(2,4);
	else if (FormatType == 3) {
		var AMPM = MilitaryTime.substring(0,2) >= 12 && MilitaryTime.substring(0,2) != "24" ? " PM" : " AM";
		if (MilitaryTime.substring(0,2) > 12)
			strDate = (MilitaryTime.substring(0,2) - 12) + ":" + MilitaryTime.substring(3,MilitaryTime.length) + AMPM;
		else {
			if (MilitaryTime.substring(0,2) < 10)
				strDate = MilitaryTime.substring(1,MilitaryTime.length) + AMPM;
			else
				strDate = MilitaryTime + AMPM;
		}
	}	
	else if (FormatType == 4)
		strDate = MilitaryTime;


	return strDate;
}

function FormatCurrency(num,decimalNum,bolLeadingZero,bolParens,bolCommas)
/**********************************************************************

Returns an expression formatted as a currency value.

FormatCurrency(Expression, NumDigitsAfterDecimal, IncludeLeadingDigit,
               UseParensForNegativeNumbers, GroupDigits)

(NOTE!! This function MUST have FormatNumber
also provided.)
	IN:
		NUM - the number to format
		decimalNum - the number of decimal places to format the number to
		bolLeadingZero - true / false - display a leading zero for
										numbers between -1 and 1
		bolParens - true / false - use parenthesis around negative numbers
		bolCommas - put commas as number separators.										
 
	RETVAL:
		The formatted number!		
 **********************************************************************/
{
	var tmpStr = new String(FormatNumber(num,decimalNum,bolLeadingZero,bolParens,bolCommas));

	if (tmpStr.indexOf("(") != -1 || tmpStr.indexOf("-") != -1) {
		// We know we have a negative number, so place '$' inside of '(' / after '-'
		if (tmpStr.charAt(0) == "(")
			tmpStr = "($"  + tmpStr.substring(1,tmpStr.length);
		else if (tmpStr.charAt(0) == "-")
			tmpStr = "-$" + tmpStr.substring(1,tmpStr.length);
			
		return tmpStr;
	}
	else
		return "$" + tmpStr;		// Return formatted string!
}

function FormatPercent(num,decimalNum,bolLeadingZero,bolParens,bolCommas)
/**********************************************************************

Returns an expression formatted as a percentage (multiplied by 100) with a trailing % character.
 
 FormatPercent(Expression, NumDigitsAfterDecimal, IncludeLeadingDigit,
               UseParensForNegativeNumbers, GroupDigits)
 - Returns an expression formatted as a percentage (multiplied by 100)
   with a trailing % character.

(NOTE!! This function MUST have FormatNumber
also provided.)
	IN:
		NUM - the number to format
		decimalNum - the number of decimal places to format the number to
		bolLeadingZero - true / false - display a leading zero for
										numbers between -1 and 1
		bolParens - true / false - use parenthesis around negative numbers
		bolCommas - put commas as number separators.										
 
	RETVAL:
		The formatted number!		
 **********************************************************************/
{
	var tmpStr = new String(FormatNumber(num*100,decimalNum,bolLeadingZero,bolParens,bolCommas));

	if (tmpStr.indexOf(")") != -1) {
		// We know we have a negative number, so place '%' inside of ')'
		tmpStr = tmpStr.substring(0,tmpStr.length - 1) + "%)";
		return tmpStr;
	}
	else
		return tmpStr + "%";			// Return formatted string!
}

function my_FormatNumber(num,decimalNum,bolLeadingZero,bolParens,bolCommas)
/**********************************************************************
 
 Returns an expression formatted as a number.
 
 FormatNumber(Expression, NumDigitsAfterDecimal, IncludeLeadingDigit, UseParensForNegativeNumbers, GroupDigits)
	IN:
		NUM - the number to format
		decimalNum - the number of decimal places to format the number to
		bolLeadingZero - true / false - display a leading zero for
										numbers between -1 and 1
		bolParens - true / false - use parenthesis around negative numbers
		bolCommas - put commas as number separators.
 
	RETVAL:
		The formatted number!
 **********************************************************************/
{ 
if (isNaN(parseInt(num))) return "NaN";

var tmpNum = num;
var iSign = num < 0 ? -1 : 1;		// Get sign of number

// Adjust number so only the specified number of numbers after
// the decimal point are shown.
tmpNum *= Math.pow(10,decimalNum);
tmpNum = Math.round(Math.abs(tmpNum))
tmpNum /= Math.pow(10,decimalNum);
tmpNum *= iSign;					// Readjust for sign


// Create a string object to do our formatting on
var tmpNumStr = new String(tmpNum);

// See if we need to strip out the leading zero or not.
if (!bolLeadingZero && num < 1 && num > -1 && num != 0)
if (num > 0)
tmpNumStr = tmpNumStr.substring(1,tmpNumStr.length);
else
tmpNumStr = "-" + tmpNumStr.substring(2,tmpNumStr.length);

// See if we need to put in the commas
if (bolCommas && (num >= 1000 || num <= -1000)) {
var iStart = tmpNumStr.indexOf(".");
if (iStart < 0)
iStart = tmpNumStr.length;

iStart -= 3;
while (iStart >= 1) {
tmpNumStr = tmpNumStr.substring(0,iStart) + "," + tmpNumStr.substring(iStart,tmpNumStr.length)
iStart -= 3;
}		
}

	// See if we need to use parenthesis
	if (bolParens && num < 0)
		tmpNumStr = "(" + tmpNumStr.substring(1,tmpNumStr.length) + ")";

	return tmpNumStr;		// Return our formatted string!
}  

// #### PRECARICA LE IMMAGINI
//
  function my_PreloadIMG()
  {
    var d=top.document;
    if (d.images)
    {
      if (!d.AR_imgs)
      {
        d.AR_imgs=new Array();
      }
      var i,j=d.AR_imgs.length,a=preloadimg.arguments;
      for (i=0; i<a.length; i++)
      {
        if (a[i].indexOf("#")!=0)
        {
          d.AR_imgs[j]=new Image;
          d.AR_imgs[j++].src=a[i];
        }
      }
    }
  }

// #### RITORNA TRUE SE LA STRINGA CONTIENE SOLO SPAZI BIANCHI
//
  function my_IsBlank(s)
  {
    for(var i = 0; i < s.length; i++)
    {
        var c = s.charAt(i);
        if ((c != ' ') && (c != '\n') && (c != '\t')) return false;
    }
    return true;
  }

// #### TOGLIE TUTTI GLI SPAZI BIANCHI
//
function my_Trim(s)
{
  // Remove leading spaces and carriage returns

  while ((s.substring(0,1) == ' ') || (s.substring(0,1) == '\n') || (s.substring(0,1) == '\r'))
  {
    s = s.substring(1,s.length);
  }

  // Remove trailing spaces and carriage returns

  while ((s.substring(s.length-1,s.length) == ' ') || (s.substring(s.length-1,s.length) == '\n') || (s.substring(s.length-1,s.length) == '\r'))
  {
    s = s.substring(0,s.length-1);
  }
  return s;
}


function my_AddZero(int_number)
{
  var str_number= '' + int_number;
  str_number= (str_number.length == 2) ? str_number : '0' + str_number;
  return str_number;
}

function my_Int2Month(iMonth)
{
  // pass in an month as an integer
  // return the month string
  var monthArray = new Array("January","Febuary","March","April","May","June","July","August","September","October","November","December");
  return monthArray[iMonth];
}

function my_DisplayDate(passedDate, what, view)
{

  // uses getDisplayMonth()
  // returns passed Date formatted nicely
  // Month day, Year  mmmm dd, yyyy

  theDate = new Date(passedDate);

  // split into day, month, year
  var iDay = theDate.getDate();
  var iMonth = theDate.getMonth();
  var iYear = theDate.getFullYear();
  var iHours = theDate.getHours();
  var iMinutes = theDate.getMinutes();
  var iSeconds = theDate.getSeconds();

  if (what == 0)
  {
    switch(view)
    {
      case 0:
        var sDisplayDate = my_AddZero(iDay) + "/" + my_AddZero((iMonth-0+1)) + "/" + iYear;
        break;
      case 1:
        var sDisplayDate = my_AddZero(iDay) + " " + getDisplayMonth(iMonth) + ", " + iYear;
        break;
    }
  return sDisplayDate;
  }
  else
  {
    switch(view)
    {
      case 0:
        var sDisplayTime = my_AddZero(iHours) + ":" + my_AddZero(iMinutes);
        break;
      case 1:
        var sDisplayTime = my_AddZero(iHours) + ":" + my_AddZero(iMinutes) + ":" + my_AddZero(iSeconds);
        break;
    }
  return sDisplayTime;
  }
}

// #### VERIFY IP
//
function my_verifyIP (IPvalue) {
errorString = "";
theName = "IPaddress";

var ipArray=IPvalue.split(".");

if (IPvalue == "0.0.0.0")
  errorString = errorString + theName + ': '+IPvalue+' is a special IP address and cannot be used here.(4)';
else if (IPvalue == "255.255.255.255")
  errorString = errorString + theName + ': '+IPvalue+' is a special IP address and cannot be used here.(5)';
if (!ipArray||!ipArray[0]||!ipArray[1]||!ipArray[2]||!ipArray[3]||ipArray.length>4)
  errorString = errorString + theName + ': '+IPvalue+' is not a valid IP address.(1)';
else {
  for (i = 0; i < 4; i++) {
    thisSegment = ipArray[i];
    if (thisSegment > 255) {
      errorString = errorString + theName + ': '+IPvalue+' is not a valid IP address.(2)';
      i = 4;
    }
    if ((i == 0) && (thisSegment > 255)) {
      errorString = errorString + theName + ': '+IPvalue+' is a special IP address and cannot be used here.(3)';
      i = 4;
    }
  }
}
extensionLength = 3;
if (errorString == "")
  alert ("That is a valid IP address.(0)");
else {
  alert (errorString);
  return false;
}
  return false;
}

function OpenWindow(url,name)
{
  var newwindow;
	newwindow=window.open(url,name,'height=480,width=640,scrollbars=yes');
	if (window.focus) {newwindow.focus()}
}
