//////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////
// start ----------- controllo browser per foglio di stile
//////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////

// net.css  = netscape on win
// mac.css  = ie on mac 
// macn.css = netscape on mac
// ex.css   = ie, netscape 6 on win and everything else
if ((navigator.appName == "Netscape") && (navigator.appVersion.indexOf("Mac")==-1) && (navigator.appVersion.substring(0,1) < 5)) {
    document.write('<link rel="stylesheet" href="/style/net.css" type="text/css">');
  }
else if ((navigator.appName == "Microsoft Internet Explorer") && (navigator.appVersion.indexOf("Mac")!=-1)){
	document.write('<link rel="stylesheet" href="/style/mac.css" type="text/css">');
}

else if ((navigator.appName == "Netscape") && (navigator.appVersion.indexOf("Mac")!=-1)) {
	document.write('<link rel="stylesheet" href="/style/macn.css" type="text/css">');
}
  else {
    document.write('<link rel="stylesheet" href="/style/ex.css" type="text/css">');
  }
  
// reloads page if resized in netscape 4x to keep style
NS4 = document.layers;
if (NS4) {
	origWidth = innerWidth;
	origHeight = innerHeight;
		}
function reDo() {
if (innerWidth != origWidth || innerHeight != origHeight)
location.reload();
	}
if (NS4) onresize = reDo;
// stop ----------- controllo browser


//////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////
// start ----------- fadein-fadeout nei link
//////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////
fadeColor = "#FF8400";  // color to fade to
//fadeColor = "#0";
stepIn = 17; // delay when fading in
stepOut = 25; // delay when fading out

/* set to true or false; true will
** cause all links to fade automatically
** (you won't need to add )
***/
autoFade = true;  

/* set to true or false; true will cause all CSS
** classes with "fade" in them to fade onmouseover
***/
sloppyClass = true;

/* set to true or false; true will make the script
** work for Macs (IE 5+), but you will have to give
** a name (name="blah") to each link that you want
** to fade.
***/
macCompat = false;


/*************
**** <install>
**

Now, once you have customized your fading colors,
you need to include your customized .js file on
every page that you want to use it in. You can
include javascript files using this syntax (in
the head of a document):

<script src="fade.js" language="Javascript"></script>

Now that you have the file included, you need to
setup your links a small bit.  Each link that you
want to fade needs to use the fade class.

Example:

<a href="blah.html" >click here</a>

Also, the link must be plain text.  This means
that you can't have <b>'s, <i>'s, <font>'s, etc.
inside of the link.

Example of what not to do:

<a href="blah.html" ><b>click</b> here</a>

Have fun!
-Anarchos-

** 
**** </install>
**************/

hexa = new makearray(16);
for(var i = 0; i < 10; i++)
    hexa[i] = i;
hexa[10]="a"; hexa[11]="b"; hexa[12]="c";
hexa[13]="d"; hexa[14]="e"; hexa[15]="f";

document.onmouseover = domouseover;
document.onmouseout = domouseout;

fadeColor = dehexize(fadeColor.toLowerCase());

var fadeId = new Array();

function dehexize(Color){
	var colorArr = new makearray(3);
	for (i=1; i<7; i++){
		for (j=0; j<16; j++){
			if (Color.charAt(i) == hexa[j]){
				if (i%2 !=0)
					colorArr[Math.floor((i-1)/2)]=eval(j)*16;
				else
					colorArr[Math.floor((i-1)/2)]+=eval(j);
			}
		}
	}
	return colorArr;
}

function domouseover() {
	if(document.all){
		var srcElement = event.srcElement;
		if ((srcElement.tagName == "A" && autoFade && srcElement.className != "nofade") || srcElement.className == "fade" || (sloppyClass && srcElement.className.indexOf("fade") != -1)) {
				if (!srcElement.startColor) {
					srcElement.startColor = (srcElement.style.color)? srcElement.style.color: srcElement.currentStyle.color;
					srcElement.startColor = dehexize(srcElement.startColor.toLowerCase());
				}
				var link = (macCompat? srcElement.name: srcElement.uniqueID);
				if (link) fade(srcElement.startColor,fadeColor,link,stepIn);				
				else if (macCompat) alert("Error: Mac Compatility mode enabled, but link has no name.");
		}
	}
}

function domouseout() {
	if (document.all){
		var srcElement = event.srcElement;
		if ((srcElement.tagName == "A" && autoFade && srcElement.className != "nofade") || srcElement.className == "fade" || (sloppyClass && srcElement.className.indexOf("fade") != -1)) {
			var link = (macCompat? srcElement.name: srcElement.uniqueID);
			if (link) fade(fadeColor,srcElement.startColor,link,stepIn);
		}
	}
}

function makearray(n) {
    this.length = n;
    for(var i = 1; i <= n; i++)
        this[i] = 0;
    return this;
}

function hex(i) {
    if (i < 0)
        return "00";
    else if (i > 255)
        return "ff";
    else
       return "" + hexa[Math.floor(i/16)] + hexa[i%16];
}

function setColor(r, g, b, element) {
      var hr = hex(r); var hg = hex(g); var hb = hex(b);
      element.style.color = "#"+hr+hg+hb;
}

function fade(s,e,element,step) {
	var sr = s[0]; var sg = s[1]; var sb = s[2];
	var er = e[0]; var eg = e[1]; var eb = e[2];
	
	if (fadeId[0] != null && fade[0] != element && eval(fadeId[0])) {
		var orig = eval(fadeId[0]);
		setColor(orig.startColor[0],orig.startColor[1],orig.startColor[2],orig);
		var i = 1;
		while(i < fadeId.length) {
			clearTimeout(fadeId[i]);
			i++;
		}
	}
		
	for(var i = 0; i <= step; i++) {
		fadeId[i+1] = setTimeout("setColor(Math.floor(" +sr+ " *(( " +step+ " - " +i+ " )/ " +step+ " ) + " +er+ " * (" +i+ "/" +
			step+ ")),Math.floor(" +sg+ " * (( " +step+ " - " +i+ " )/ " +step+ " ) + " +eg+ " * (" +i+ "/" +step+
			")),Math.floor(" +sb+ " * ((" +step+ "-" +i+ ")/" +step+ ") + " +eb+ " * (" +i+ "/" +step+ ")),"+element+");",i*step);
	}
	fadeId[0] = element;
}

// stop ----------- fadein-fadeout nei link



//////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////
// start ----------- gestione data all'interno della ricera
//////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////

//Current date in form script
//By Lee Hinder (lee.hinder@ntlworld.com)
//Visit http://wsabstract.com for this script and more

//set todays date

var Now = new Date();
var NowDay = Now.getDate();
var NowMonth = Now.getMonth();
var NowYear = Now.getYear();
if (NowYear < 2000) NowYear += 1900; //for Netscape


//function for returning how many days there are in a month including leap years

function DaysInMonth(WhichMonth, WhichYear)
{
	var DaysInMonth = 31;

	if (WhichMonth == "Apr" || WhichMonth == "Jun" || WhichMonth == "Sep" || WhichMonth == "Nov") DaysInMonth = 30;

	if (WhichMonth == "Feb" && (WhichYear/4) != Math.floor(WhichYear/4))	DaysInMonth = 28;

	if (WhichMonth == "Feb" && (WhichYear/4) == Math.floor(WhichYear/4))	DaysInMonth = 29;

	return DaysInMonth;
}


//function to change the available days in a months

function ChangeOptionDays(DaysObject, MonthObject, YearObject)
{
	
	Month = MonthObject[MonthObject.selectedIndex].text;
	Year = YearObject[YearObject.selectedIndex].text;

	DaysForThisSelection = DaysInMonth(Month, Year);

	CurrentDaysInSelection = DaysObject.length;

	if (CurrentDaysInSelection > DaysForThisSelection)
	{
		for (i=0; i<(CurrentDaysInSelection-DaysForThisSelection); i++)
		{
			DaysObject.options[DaysObject.options.length - 1] = null
		}
	}

	if (DaysForThisSelection > CurrentDaysInSelection)
	{
		var length;
		var d, vd;
		for (i=0; i<(DaysForThisSelection-CurrentDaysInSelection); i++)
		{   
			d = DaysObject.options.length + 1;
			if (d<10) {
				vd = "0" + d;
			} else {
				vd = d;	
			}
			NewOption = new Option(d,vd);
			//DaysObject.add(NewOption);
			DaysObject.options[DaysObject.options.length] = NewOption;

		}
	}

	if (DaysObject.selectedIndex < 0) DaysObject.selectedIndex = 0;
}


//function to set options to today

function SetToToday(DaysObject, MonthObject, YearObject)
{


	YearObject[0].selected = true;
	MonthObject[NowMonth].selected = true;

	ChangeOptionDays(DaysObject, MonthObject, YearObject);

	DaysObject[NowDay-1].selected = true;
}


//function to write option years plus x

function WriteYearOptionsAhead(YearsAhead)
{
	line = "";

	for (i=0; i<YearsAhead; i++)
	{
		line += ("<OPTION VALUE=\"" + (NowYear + i) +"\">");
		line += NowYear + i;
	}

	return line;
}

//function to write option years minus x

function WriteYearOptionsBehind(YearsBehind)
{
	line = "";

	for (i=0; i<YearsBehind; i++)
	{
		//line += "<OPTION>";
		line += ("<OPTION VALUE=\"" + (NowYear - i) +"\">");
		
		line += NowYear - i;
	}

	return line;
}



// stop ----------- gestione data


//////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////
// start ----------- funzione openWindow
//////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////
var win= null;
function NewWindow(mypage,myname,w,h,scroll){

  var winl = (screen.width-w)/2;
  var wint = (screen.height-h)/2;
  var settings  ='height='+h+',';
      settings +='width='+w+',';
      settings +='top='+wint+',';
      settings +='left='+winl+',';
      settings +='scrollbars='+scroll+',';
      settings +='resizable=yes';
  win=window.open(mypage,myname,settings);
  win.creator=self;
  if(parseInt(navigator.appVersion) >= 4){win.window.focus();}
}

//per utilizzare cut&paste la seguente stringa <a href="nomepagina.html" onclick="NewWindow(this.href,'name','400','400','yes');return false">click to open new window</a>

function NewWindowPosition(mypage,myname,w,h,scroll,winl,wint){

 if (winl == '' && wint == '') {
  winl = (screen.width-w)/2;
  wint = (screen.height-h)/2;
  }  
  var settings  ='height='+h+',';
      settings +='width='+w+',';
      settings +='top='+wint+',';
      settings +='left='+winl+',';
      settings +='scrollbars='+scroll+',';
      settings +='resizable=yes';
  win=window.open(mypage,myname,settings);
  win.creator=self;
  if(parseInt(navigator.appVersion) >= 4){win.window.focus();}
}
//per utilizzare cut&paste la seguente stringa <a href="nomepagina.html" onclick="NewWindow(this.href,'name','400','400','yes','400','300');return false">click to open new window</a>
// stop ----------- funzione open-window

//////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////
// start ----------- funzione Form Checking
//////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////

var defaultEmptyOK = true

// CONSTANT STRING DECLARATIONS
// (grouped for ease of translation and localization)

// whitespace characters
var whitespace = " \t\n\r"

// m is an abbreviation for "missing"
var mPrefix = "You did not enter a value into the "
var mSuffix = " field. This is a required field. Please enter it now."

var iEmail = "This field must be a valid email address (like foo@bar.com).  Please reenter it now."


// Notify user that required field theField is empty.
// String s describes expected contents of theField.value.
// Put focus in theField and return false.
function warnEmpty (theField, s)
{   theField.focus()
    alert(mPrefix + s + mSuffix)
    return false
}


// Notify user that contents of field theField are invalid.
// String s describes expected contents of theField.value.
// Put select theField, pu focus in it, and return false.
function warnInvalid (theField, s)
{   theField.focus()
    theField.select()
    alert(s)
    return false
}


// Check whether string s is empty.
function isEmpty(s)
{   return ((s == null) || (s.length == 0))
}


// Returns true if string s is empty or 
// whitespace characters only.
function isWhitespace (s)

{   var i;

    // Is s empty?
    if (isEmpty(s)) return true;

    // Search through string's characters one by one
    // until we find a non-whitespace character.
    // When we do, return false; if we don't, return true.

    for (i = 0; i < s.length; i++)
    {   
        // Check that current character isn't whitespace.
        var c = s.charAt(i);

        if (whitespace.indexOf(c) == -1) return false;
    }

    // All characters are whitespace.
    return true;
}


// isEmail (STRING s [, BOOLEAN emptyOK])
// 
// Email address must be of form a@b.c -- in other words:
// * there must be at least one character before the @
// * there must be at least one character before and after the .
// * the characters @ and . are both required
function isEmail (s)
{   if (isEmpty(s)) 
       if (isEmail.arguments.length == 1) return defaultEmptyOK;
       else return (isEmail.arguments[1] == true);
   
    // is s whitespace?
    if (isWhitespace(s)) return false;
    
    // there must be >= 1 character before @, so we
    // start looking at character position 1 
    // (i.e. second character)
    var i = 1;
    var sLength = s.length;

    // look for @
    while ((i < sLength) && (s.charAt(i) != "@"))
    { i++
    }

    if ((i >= sLength) || (s.charAt(i) != "@")) return false;
    else i += 2;

    // look for .
    while ((i < sLength) && (s.charAt(i) != "."))
    { i++
    }

    // there must be at least one character after the .
    if ((i >= sLength - 1) || (s.charAt(i) != ".")) return false;
    else return true;
}


/* FUNCTIONS TO INTERACTIVELY CHECK VARIOUS FIELDS. */

// checkString (TEXTFIELD theField, STRING s, [, BOOLEAN emptyOK==false])
//
// Check that string theField.value is not all whitespace.
function checkString (theField, s, emptyOK)
{   // Next line is needed on NN3 to avoid "undefined is not a number" error
    // in equality comparison below.
    if (checkString.arguments.length == 2) emptyOK = defaultEmptyOK;
    if ((emptyOK == true) && (isEmpty(theField.value))) return true;
    if (isWhitespace(theField.value)) 
       return warnEmpty (theField, s);
    else return true;
}

// checkEmail (TEXTFIELD theField [, BOOLEAN emptyOK])
//
// Check that string theField.value is a valid Email.
function checkEmail (theField, emptyOK)
{   if (checkEmail.arguments.length == 1) emptyOK = defaultEmptyOK;
    if ((emptyOK == true) && (isEmpty(theField.value))) return true;
    else if (!isEmail(theField.value, false)) 
       return warnInvalid (theField, iEmail);
    else return true;
}


// stop ----------- funzione di Form Checking


//////////////////////////////////////////////////////////////////////
// start ----------- funzione apri finistra da popup su mainframe
//////////////////////////////////////////////////////////////////////

function remoteOpen(url){
creator.location=url
}

//////////////////////////////////////////////////////////////////////
// stop ----------- funzione apri finistra da popup su mainframe
//////////////////////////////////////////////////////////////////////


