isNS4 = (document.layers) ? true : false;
isIE4 = (document.all && !document.getElementById) ? true : false;
isIE5 = (document.all && document.getElementById) ? true : false;
isNS6 = (!document.all && document.getElementById) ? true : false;


var PopupArray = new Array();
var myWin = null;
var ReloadMe = false;


function popup(url,w,h,sb)
	{
	var d = new Date();
	myWin=window.open(url,'popupwindow'+escape(d.getTime()),'left='+((screen.width/2)-(w/2))+',top='+((screen.height/2)-(h/2)-40)+',screenX='+((screen.width/2)-(w/2))+',screenY='+((screen.height/2)-(h/2)-40)+',Width='+w+',height='+h+',alwaysRaised=yes,history=no,resizable=no,status=no,scrollbars=' + sb +',menubar=no')	
	myWin.opener=self;	
	PopupArray[PopupArray.length] = myWin;
	myWin.focus();
	}


function CheckPopUp()
{
   setTimeout("TestPopUp()", 50);
}

function TestPopUp()
{
   var PopupArrayTemp = new Array();
		
	if (PopupArray.length >0)
	{   
	   for (var i=0; i<PopupArray.length; i++)
	   {
	      myWin = PopupArray[i];	      
	      if (!myWin.closed)
	      {
            myWin.focus();
	         PopupArrayTemp[PopupArrayTemp.length]=myWin;	         
	      }
	   }   
	   PopupArray = PopupArrayTemp;
	}
	
	if (PopupArray.length == 0)
	{
	   if (ReloadMe == true)
	   {
	      ReloadMe = false;
	      self.location.reload();	      
	   }	
	}
	else
	{		   
		return false;		
	}
}


function ClosePopUp()
{
	if (PopupArray.length >0)
	{   
	   for (var i=0; i<PopupArray.length; i++)
	   {
	      myWin = PopupArray[i];
	      if (myWin && !myWin.closed)
	      {	
	         myWin.close(); 
	      }
	   }   
		return true;					
	}
}

function ReloadOpener()
{
   if (self.opener != null)
   {
      self.opener.ReloadMe=true;    
   }   
}



function SetVisibility(strDivName,bolVisible)
{
	if (isNS4)
	{
	 objElement = document.layers[strDivName];
	}
	else if (isIE4)
	{
	 objElement = document.all[strDivName];
	}
	else if (isIE5 || isNS6)
	{
	 objElement = document.getElementById(strDivName);
	}
	if(isNS4){
	   if(!bolVisible) {
		 objElement.visibility ="hidden"
	   } else {
		 objElement.visibility ="visible"
	   }     
	 }else{
	   if(!bolVisible) {    
		 objElement.style.visibility = "hidden";
	   } else {
		 objElement.style.visibility = "visible";
	   }
	}
	
}

function IsInteger(sText)
{
   var ValidChars = "0123456789";
   var IsNumber=true;
   var Char;

   for (i = 0; i < sText.length && IsNumber == true; i++) 
      { 
      Char = sText.charAt(i); 
      if (ValidChars.indexOf(Char) == -1) 
         {
         IsNumber = false;
         }
      }
   return IsNumber;   
}

function IsNumeric(sText)
{
   var ValidChars = "0123456789.";
   var IsNumber=true;
   var Char;

   for (i = 0; i < sText.length && IsNumber == true; i++) 
      { 
      Char = sText.charAt(i); 
      if (ValidChars.indexOf(Char) == -1) 
         {
         IsNumber = false;
         }
      }
   return IsNumber;   
}

 
var day=''; 
var month=''; 
var yea=''; 
var datefield=''; 

function y2k(number)
{
   return (number < 1000) ? number + 1900 : number;
} 
   
function SetToday() 
{ 
   var today = new Date(); 
   day   = today.getDate(); 
   month = today.getMonth(); 
   year  = y2k(today.getYear()); 
} 
 
function padout(number)
{
   return (number < 10) ? '0' + number : number;
} 

function restart() 
{ 
  setfield=eval(datefield) ; 
  setfield.value= '' + padout(day) + '/' + padout(month - 0 + 1) + '/' + year; 
  mywindow.close(); 
}
 
function DateSelector(x) 
{ 
  datefield=x; 
  var w=350; 
  var h=250; 
  setfield=eval(datefield) ; 
  if ( setfield.value!='') 
  { 
   day=setfield.value.substr(0,2); 
   month=setfield.value.substr(3,2)-1; 
   year=setfield.value.substr(6,4); 
   if (year.indexOf(" ")>0)
   {
      year=year.substr(0,2);
   }
  
  } 
  else 
  { 
  	SetToday(); 
  }
  mywindow=open('dateselector.htm','myname','left='+((screen.width/2)-(w/2))+',top='+((screen.height/2)-(h/2))+',screenX='+((screen.width/2)-(w/2))+',screenY='+((screen.height/2)-(h/2))+',Width='+w+',height='+h+',alwaysRaised=yes,history=no,resizable=no,status=no,scrollbars=no,menubar=no'); 
  mywindow.location.href = 'dateselector.htm'; 
  if (mywindow.opener == null) mywindow.opener = self; 
}
 
 
 
function Get_Cookie(name)
{
    var start = document.cookie.indexOf(name+"=");
    var len = start+name.length+1;
    if ((!start) && (name != document.cookie.substring(0,name.length))) return null;
    if (start == -1) return null;
    var end = document.cookie.indexOf(";",len);
    if (end == -1) end = document.cookie.length;
    return unescape(document.cookie.substring(len,end));
}

function Set_Cookie(name,value,expires,path,domain,secure)
{
    document.cookie = name + "=" +escape(value) +
        ( (expires) ? ";expires=" + expires.toGMTString() : "") +
        ( (path) ? ";path=" + path : "") + 
        ( (domain) ? ";domain=" + domain : "") +
        ( (secure) ? ";secure" : "");
}


function addOption(field,text,value,selected)
{
	var NS4 = (navigator.appName == "Netscape" && parseInt(navigator.appVersion) < 5);
	var NSX = (navigator.appName == "Netscape");
	var IE4 = (document.all) ? true : false;
	
	var obj=eval("document." + field);
	var newOpt  = new Option(text, value, false, selected);
			
	if (NSX)
	{	
		obj.options[obj.length] = newOpt;		
	}
	else if (IE4)
	{
		if(obj!=null && obj.options!=null)
		{
			obj.options[obj.options.length] = newOpt;
		}
	}
}


function trim(s) {
  while (s.substring(0,1) == ' ') {
    s = s.substring(1,s.length);
  }
  while (s.substring(s.length-1,s.length) == ' ') {
    s = s.substring(0,s.length-1);
  }
  return s;
}


function ExpandCollapse(hideThis)
{
	if(document.getElementById(hideThis).style.display == '')
  {
		document.getElementById(hideThis).style.display = 'none';
    document.getElementById(hideThis + '_img').src='img/folderclose.gif';
	}
  else
  {
		document.getElementById(hideThis).style.display = '';
    document.getElementById(hideThis + '_img').src='img/folderopen.gif';
  }
}



function OpenClose(hideThis)
{
	if(document.getElementById(hideThis).style.display == '')
  {
		document.getElementById(hideThis).style.display = 'none';
    document.getElementById(hideThis + '_img').src='img/boxclose.gif';
	}
  else
  {
		document.getElementById(hideThis).style.display = '';
    document.getElementById(hideThis + '_img').src='img/boxopen.gif';
  }
}


function placeFocus()
{
	if (document.forms.length > 0)
  {
	  var field = document.forms[0];
	  for (i = 0; i < field.length; i++)
    {
	    if ((field.elements[i].type == "text") || (field.elements[i].type == "textarea"))
      {
        var testo = document.forms[0].elements[i].value;
        var posizione = testo.length;  
    	  document.forms[0].elements[i].focus();
        oInput = document.forms[0].elements[i];
        if( oInput.createTextRange )
        {
          var range = oInput.createTextRange();
          range.moveEnd('character',posizione);
          range.moveStart('character',posizione);
          range.select();
        }
  	    break;
      }
    }
  }
}

function hideWait()
{
   elem = document.getElementById('WaitBase');
   if (elem != null) elem.style.display = 'none';
   elem = document.getElementById('WaitBox1');
   if (elem != null) elem.style.display = 'none';
   elem = document.getElementById('WaitBox2');
   if (elem != null) elem.style.display = 'none';
}

function showWait(i)
{


    hideThis = "WaitBase";
    var arrayPageSize = getPageSize();
    var objWaitBase = document.getElementById("WaitBase");
    objWaitBase.style.height = (arrayPageSize[1] + 'px');
    document.getElementById(hideThis).style.display = '';

    hideThis = "WaitBox"+i;
    document.getElementById(hideThis).style.display = '';

   
}

// getPageSize()
// Returns array with page width, height and window width, height
// Core code from - quirksmode.org
// Edit for Firefox by pHaez
//
function getPageSize(){
	
	var xScroll, yScroll;
	
	if (window.innerHeight && window.scrollMaxY) {	
		xScroll = document.body.scrollWidth;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	
	var windowWidth, windowHeight;
	if (self.innerHeight) {	// all except Explorer
		windowWidth = self.innerWidth;
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}	
	
	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else { 
		pageHeight = yScroll;
	}

	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){	
		pageWidth = windowWidth;
	} else {
		pageWidth = xScroll;
	}


	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight) 
	return arrayPageSize;
}



//    var objBody = document.getElementsByTagName("body");
//
//    alert(objBody);
//    objBody.onunload = function() {hideWait();};

