
/**********************************************************************************
* Controllo Menu scroll
***********************************************************************************/
var iniSlideMenuX ,iniSlideMenuY;

function Inizializza_Menu(Pos_X ,Pos_Y)
{
    iniSlideMenuX = Pos_X
    iniSlideMenuY = Pos_Y
      
    positionMenu(iniSlideMenuX ,iniSlideMenuY);
  
    window.onscroll = controlSlideMenu;
  
}

function controlSlideMenu()
{
  var topOfClientArea;

  // Get current value of top of client area
    topOfClientArea = document.body.scrollTop;
  
  slideElementTo('slideMenu', topOfClientArea + iniSlideMenuY);

  
}
        
function positionMenu(iniSlideMenuX ,iniSlideMenuY)
{
  if (document.getElementById) {
    var mnu = document.getElementById('slideMenu');
    mnu.style.left = iniSlideMenuX +"px";
    mnu.style.top = iniSlideMenuY + "px";
    mnu.style.visibility = 'visible';
  }
  else { document.all.slideMenu.style.pixelLeft = 12;
    document.all.slideMenu.style.pixelTop = iniSlideMenuY;
    document.all.slideMenu.style.visibility = 'visible';
 } 
}
var slideTarget=0, elementSliding=false;

function slideElementTo(elementId, yPosition)
{
  slideTarget = yPosition;
  if (!elementSliding) {
    slideElement(elementId);
  }
}
 function slideElement(elementId)
{
  var delta, elementY;

  // Get the element's current y position
  if (document.getElementById) {
    var ele = document.getElementById(elementId);
    elementY = parseInt(ele.style.top);
  }
  
  else {
    return;
  }
  // Set the busy-bit
  elementSliding = true;
  // Move slower as the element gets
  // closer to the target position
  delta = Math.abs(elementY - slideTarget) / 2;
  if (delta < 1) delta = 1;
  // Determine the direction to move,
  // up or down, and move one delta
  if (elementY < slideTarget) {
    moveElementTo(elementId, elementY + delta);
  }  
  else if (elementY > slideTarget) {
    moveElementTo(elementId, elementY - delta);
  }
  else {
    // When the element reaches its target position
    // turn busy-bit off and return
    elementSliding = false;
    return;
  }
  // Until the element reaches its target,
  // continue to reschedule a call to this function
  setTimeout("slideElement('"+elementId+"')",50);
}

function moveElementTo(elementId, yPosition)
{
  if (document.getElementById) {
    var ele = document.getElementById(elementId);
    ele.style.top = yPosition + "px";
  }
  
}

/***********************************************************************************
* Funzione varie di redirezione documenti
***********************************************************************************/

function gopage(Pagina){
//parent.main.location = Pagina
location = Pagina
}

function gopageblank(url,title,options){
//alert (url)
//alert (title)
//alert (options)
//parent.window.open(Pagina)
window.open(url,title,options)
}


function gomail(Pagina){
//alert (Pagina)
//parent.location='mailto:'+Pagina+'?subject=Richiesta di Informazioni&cc=webmaster@ghs.it'
location='mailto:'+Pagina+'?subject=Richiesta di Informazioni&cc=webmaster@ghs.it'

}


function movein(which,html){
which.style.background='coral'
//if (document.getElementById)
//document.getElementById("boxdescription").innerHTML=html
//else
//boxdescription.innerHTML=html
window.status = html
}

function moveout(which,stile){
which.style.background=stile
//if (document.getElementById)
//document.getElementById("boxdescription").innerHTML='&nbsp;'
//else
//boxdescription.innerHTML='&nbsp;'
window.status = ''
}

/****************************************************/	
/* Seleziona il testo                               */
/****************************************************/
function selectAll(theField) {
var tempval=eval(theField)
tempval.focus()
tempval.select()
}

/****************************************************/	
/* Controlla il numero di caratteri inseriti        */
/****************************************************/

function checkmlenght(thisone,len){
var Aux = 'Please insert max ' + len + ' chars'
	if (thisone.value != "") {
		if (thisone.value.length>len) {
		alert (Aux)
		thisone.focus()
		thisone.select()
		}
	}	
}
/****************************************************/	
/* Controlla se il campo è numerico                 */
/****************************************************/

function checknum(thisone){
var Aux = thisone.value
if (Aux == "")
	return

/** alert (Aux) **/

var anum=/(^\d+$)|(^\d+\.\d+$)/
	if (!anum.test(Aux)) {
	alert ("Please insert a number")
	thisone.focus()
	thisone.select()
	}

}
/****************************************************/	
/* Controlla se la stringa è un numero              */
/****************************************************/
function isnum(aux){

if (aux == "") return true
var anum=/(^\d+$)|(^\d+\.\d+$)/
	if (!anum.test(aux)) return false
	else return true
}

/****************************************************/	
/* Controlla se il campo è una data                 */
/****************************************************/

function checkdate(thisone){
var Sdata = thisone.value

if (Sdata == "")
	return true

if (!spasec(Sdata)) {
	alert ("Please insert a valid date")
	thisone.focus()
	thisone.select()
	return false
	}
else	{
	thisone.value = StrData
	return true
	}
}


function spasec(Sdata) {
	
	var serdat = Sdata.split("/")
	if ( serdat[0] != null && serdat [1] != null && serdat[2] != null ) {
		switch (serdat[0].length) {
			case 1: serdat[0]="0"+serdat[0]
				break
			case 2: break
			default: return false
		}
		switch (serdat[1].length) {
			case 1: serdat[1]="0"+serdat[1]
				break
			case 2: break
			default: return false
		}
		switch (serdat[2].length) {
			case 4: break
			case 2: break
			default: return false
		}
	Sdata = serdat[0]+serdat[1]+serdat[2]
	}

	//alert (Sdata)	


	/* Controllo per vedere se e' un numero */
	var anum=/(^\d+$)|(^\d+\.\d+$)/
	if (!anum.test(Sdata))
	return false
	else {
		if (Sdata.charAt(8) != "")
		return false
		else {
		if (Sdata.charAt(7) != "") {
			if(data8(Sdata))
			return true
			}
			else {
			if (Sdata.charAt(6) != "") {
			if (data7(Sdata))
			return true
			}
			else {
			if (Sdata.charAt(5) != "") {
			if (data6(Sdata))
			return true
			}
			else {
			if (Sdata.charAt(4) != "") {
			if (data5(Sdata))
			return true
			}
			else
			return false
}
}
}
}
}
}

function data5(Sdata) {

var gg
var mm
var yy
var aa

	gg = Sdata.substring(0,1)
	mm = Sdata.substring(1,3)
	aa = Sdata.substring(3,5)
	yy = 19
	if (aa < 70 )
		yy = 20
	yy = yy + aa
	if (spadat(gg,mm,aa,yy))
	return true
	else
	return false
}
function data6(Sdata) {

var gg    
var mm
var yy
var aa

	gg = Sdata.substring(0,2)
	mm = Sdata.substring(2,4)
	aa = Sdata.substring(4,6)
	yy = 19
	if (aa < 70 )
		yy = 20
	yy = yy + aa
	if (spadat(gg,mm,aa,yy))
	return true
	else
	return false

}		
function data7(Sdata) {

var gg
var mm
var yy
var aa

	gg = Sdata.substring(0,1)
	mm = Sdata.substring(1,3)
	yy = Sdata.substring(3,5)
	aa = Sdata.substring(5,7)

	yy = yy + aa
	
	if (spadat(gg,mm,aa,yy))
	return true
	else
	return false

}
function data8(Sdata) {

var gg
var mm
var yy
var aa

	gg = Sdata.substring(0,2)
	mm = Sdata.substring(2,4)
	yy = Sdata.substring(4,6)
	aa = Sdata.substring(6,8)

	yy = yy + aa
	
	if (spadat(gg,mm,aa,yy))
	return true
	else
	return false

}

function spadat (gg,mm,aa,yy) {

/* alert (gg + "/" + mm + "/" + aa + "-" + yy ) */
//alert (typeof(gg)+typeof(mm)+typeof(yy))
//var s = mm.length
//alert (s+'-'+mm)

if ( yy < 1753 )
	return false
if (gg < 1 )
	return false
	
	switch (mm)
	{
		case "01":
			if (gg > 31)
			return false
			else {
				StrData = gg + "/" + mm + "/" + yy
				return true
			}
					
		case "02":
			anno = yy / 4
			anno4 = anno.toString()
			serann = anno4.split(".")
			giorni = 28
			if (serann[1] == null)
				giorni = 29
				if ( gg > giorni )
				return false
				else {
				StrData = gg + "/" + mm + "/" + yy
				return true
				}
				
		case "03":
		if (gg > 31)
			return false
			else {
				StrData = gg + "/" + mm + "/" + yy
				return true
				}
					
		case "04":
		if (gg > 30)
			return false
			else {
				StrData = gg + "/" + mm + "/" + yy
				return true
				}
					
		case "05":
		if (gg > 31)
			return false
			else {
				StrData = gg + "/" + mm + "/" + yy
				return true
				}
					
		case "06":
		if (gg > 30)
			return false
			else {
				StrData = gg + "/" + mm + "/" + yy
				return true
				}
					
		case "07":
		if (gg > 31)
			return false
			else {
				StrData = gg + "/" + mm + "/" + yy
				return true
				}
					
		case "08":
		if (gg > 31)
			return false
			else {
				StrData = gg + "/" + mm + "/" + yy
				return true
				}
					
		case "09":
		if (gg > 30)
			return false
			else {
				StrData = gg + "/" + mm + "/" + yy
				return true
				}
					
		case "10":
		if (gg > 31)
			return false
			else {
				StrData = gg + "/" + mm + "/" + yy
				return true
				}
					
		case "11":
		if (gg > 30)
			return false
			else {
				StrData = gg + "/" + mm + "/" + yy
				return true
				}
					
		case "12":
		if (gg > 31)
			return false
			else {
				StrData = gg + "/" + mm + "/" + yy
				return true
				}
					
		default:
			StrData = ""
			return false
	}
}

/****************************************************/	
/* Controlla valori nulli                           */
/****************************************************/

function checkNULL(thisone){
if (thisone.value != "")
	return true
else	{
	alert ('Inserire Valore')
	thisone.focus()
	return false
	}	
}
/***************************************************
* Message Box                                      *
***************************************************/
function msgbox(S_msgbox) {


alert (S_msgbox)

}

/****************************************
* Controllo campi vuoti                 *
****************************************/
function CtrCampiVuoti(which) 
{
   
   var pass=true;
   if (document.images) 
   {
      for (i=0;i<which.length;i++) 
      {
          var tempobj=which.elements[i];
          if (tempobj.id.substring(0,8)=="required") 
          {
             if (tempobj.value == "") 
             {
		pass=false;
		break;
             }
          }
      }
   }
   if (!pass) 
   {
      alert ('Field Empty')
      tempobj.focus();
//      tempobj.select(); 
      return false;
   }
   else
      return true;
}

/****************************************
* Controllo date form                   *
****************************************/
function ctrdate(which) {   
   var pass=true;
   if (document.images) {
      for (i=0;i<which.length;i++) {
          var tempobj=which.elements[i];
          if (tempobj.id.substring(0,8)=="ctrdates") {
             if (! checkdate(tempobj)) { 
             	pass=false
             	break;
             	}
      
	  }
      }
   }
   return pass
}

/***************************************************
* Funzioni di Stampa                               *
***************************************************/
window.onbeforeprint=removeelements
window.onafterprint=reloadelements

function removeelements(){
//store all elements with id=remove to "remove_el"
var remove_el=document.all.remove
if (typeof(remove_el)!='undefined'){
//if there is only one element with id=remove
if (remove_el!=''&&remove_el.length==null)
remove_el.style.display='none'
else	{
//for each element with id=remove
for (i=0;i<remove_el.length;i++)
remove_el[i].style.display='none'
}
}
}

function reloadelements(){
//setTimeout("window.location.reload()",50)
//store all elements with id=remove to "remove_el"

var remove_el=document.all.remove
if (typeof(remove_el)!='undefined'){
//if there is only one element with id=remove
if (remove_el!=''&&remove_el.length==null)
remove_el.style.display=''
else	{
//for each element with id=remove
for (i=0;i<remove_el.length;i++)
remove_el[i].style.display=''
	}
    }
}


/* ********************************************************
FUNZIONI PER IL CALCOLO DEL NUMERO CARATTERI NELLA FORM SMS
*********************************************************** */
var supportsKeys = false


function favChange(rnum) {
	f = document.newMsg;
	
	if (f.favs.selectedIndex >=0) {
		f.msgTo.value = f.favs.options[f.favs.selectedIndex].value
	}

	if (f.favs.selectedIndex > 0 && f.favs.selectedIndex <= rnum + 1) {
		f.SMStext.focus();
	} else {
		f.msgTo.focus();
	}
}
function calcCharLeft(f) {
		lenUSig = f.lenSSig.value
		maxLength = 160 - f.lenSysSig.value - lenUSig
        if (f.SMStext.value.length > maxLength) {
	        f.SMStext.value = f.SMStext.value.substring(0,maxLength)
		    charleft = 0
        } else {
			charleft = maxLength - f.SMStext.value.length
		}

        f.msgCL.value = charleft
}

function textKey(f) {
	supportsKeys = true
	calcCharLeft(f)
}
/* ********************************************************* */



