﻿// File JScript
// <!--
var myimages=new Array();
var loaded = false;

function InterceptFireBeforeFormSubmit(){
    while(!loaded){
        alert('Attendere che la pagina venga caricata interamente...')
    }
}

function preloadimages(){
    for (i=0;i<preloadimages.arguments.length;i++){
        myimages[i]=new Image();
        myimages[i].src=preloadimages.arguments[i];
    }
}
function preloadPickImages(){
    preloadimages("../images/Home/Eventi.jpg","../images/Home/Librerie.jpg","../images/Home/racconti.jpg","../images/Home/Circoli.jpg","../images/Home/Home.jpg");
}
function Hide(arg){
    if(document.getElementById(arg)!=null) document.getElementById(arg).style.display = 'none';
}
function Show(arg){
    if(document.getElementById(arg)!=null) document.getElementById(arg).style.display = 'block';
}
function clickButton(obj, e, buttonid)
{ 
  var evt = e ? e : window.event;
  var bt = document.getElementById(buttonid);

  if (bt)
  { 
    if (evt.keyCode == 13)
    { 
      clearPasswordField(obj);
      bt.click(); 
      return false; 
    } 
  } 
}

function clearPasswordField(obj){    
    if(obj!=null)
    {
        var input = document.getElementsByTagName("input");
        for (var i = 0; i < input.length; i++)
        {
            type = input[i].getAttribute("type");
            if(type=='password') input[i].value = '';
            
        }
    }
    return;
}

function pageX(element) {
  if(!element) return 0;
  var curleft = 0;
  if (document.getElementById || document.all) {
	while (element.offsetParent) {
	  curleft += element.offsetLeft;
	  element = element.offsetParent;
    }
  }
  
  return curleft;
}

function pageY(element) {
  var curTop = 0;
  if (document.getElementById || document.all) {
    while (element.offsetParent) {
      curTop += element.offsetTop;
      element = element.offsetParent;
    }
  }
  return curTop;
}

    function swapImage(obj, ImgPath){             
        document.getElementById(obj).src = ImgPath;
    }
    
    function rollImage(obj, ImgPath){    
        document.getElementById(obj).firstChild.src = ImgPath;
    }
    function ShowItem(target,item,show){
        if(!loaded) return;
        //alert( document.getElementById(target).width );
        //iconX = pageX( document.getElementById(target));
        if(show){
            document.getElementById(item).style.display = 'block';
            document.getElementById(item).style.width = document.getElementById(target).style.width;
            document.getElementById(item).style.height = document.getElementById(target).width;
        }
        else
            document.getElementById(item).style.display = 'none'
        //alert(icon);
    }
    
    var map = null;
    var geocoder = null;
    function load(placeholdername) {  
        if (GBrowserIsCompatible()) {	
            map = new GMap2(document.getElementById( placeholdername ));	
            map.addControl(new GSmallMapControl());	
            map.addControl(new GMapTypeControl());	
            map.setCenter(new GLatLng(41.91633, 12.482185), 5);	
            geocoder = new GClientGeocoder();  }
    }
    function showAddress(address) {  
        if (geocoder) {	
            geocoder.getLatLng(	  
                address,	  
                function(point) {		
                    if (!point) {		  
                        alert(address + " not found");		
                    } else {		  
                        map.setCenter(point, 16);		  
                        var marker = new GMarker(point);		  
                        map.addOverlay(marker);		  
                        marker.openInfoWindowHtml(address);		
                    }	  
                });  
        }
    }
    
    /* *************
    *** SEARCH *****
    ****************/
   
		function trim(inputString) {
		// Removes leading and trailing spaces from the passed string. Also removes
		// consecutive spaces and replaces it with one space. If something besides
		// a string is passed in (null, custom object, etc.) then return the input.
		if (typeof inputString != "string") { return inputString; }
		var retValue = inputString;
		var ch = retValue.substring(0, 1);
		while (ch == " ") { // Check for spaces at the beginning of the string
			retValue = retValue.substring(1, retValue.length);
			ch = retValue.substring(0, 1);
		}
		ch = retValue.substring(retValue.length-1, retValue.length);
		while (ch == " ") { // Check for spaces at the end of the string
			retValue = retValue.substring(0, retValue.length-1);
			ch = retValue.substring(retValue.length-1, retValue.length);
		}
		while (retValue.indexOf("  ") != -1) { // Note that there are two spaces in the string - look for multiple spaces within the string
			retValue = retValue.substring(0, retValue.indexOf("  ")) + retValue.substring(retValue.indexOf("  ")+1, retValue.length); // Again, there are two spaces in each of the strings
		}
		return retValue; // Return the trimmed string back to the user
		}
		function openAlert(x,y,w){
			x = 10;
			y = 10;
			sBalert = document.getElementById(boxAlert);
			sBalert.style.left = x ;
			sBalert.style.top = y + 18;
			sBalert.style.display = 'block';
		}
		function verifyData(sBoxId, boxAlert){
			document.getElementById(sBoxId).value = trim(document.getElementById(sBoxId).value);
			if( document.getElementById(sBoxId).value=="" )
			{
				openAlert(pageX(document.getElementById(sBoxId)),pageY(document.getElementById(sBoxId)));
				return false;
			}
			return true;
		}

function verifyInit(){
    return false;
}
function Init(){
    loaded = true;
}
function SetEventListener(){
    if (typeof window.addEventListener != 'undefined')
    {
        window.addEventListener("load", Init, false);
    }
    else if (typeof document.addEventListener != 'undefined')
    {
        document.addEventListener("load", Init, false);
    }
    else if (typeof window.attachEvent != 'undefined')
    {
        window.attachEvent("onload", Init);
    }
    else
        window.alert('Failed to attach an Event Listener\n\n Please Report');
}
SetEventListener();    
// -->
