// JavaScript Document

var numb = '0123456789';
var lwr = 'abcdefghijklmnopqrstuvwxyz';
var upr = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
var adviseVisible = false;
var advisePosition = new Array(48, 80, 110, 140, 170, 200, 230, 260, 295, 326, 360, 390, 410);
var canProcessAdvise = true;

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;
}

function isAlphabetic(sText) 
{
	return isValid(sText,lwr+upr);
}

function isValid(parm,val) 
{
	if (parm == "") return true;
	for (i=0; i<parm.length; i++)
	{
		if (val.indexOf(parm.charAt(i),0) == -1) return false;
	}
	return true;
}

function createAdvise(id, txt, num)
{
	var obj = document.getElementById("baloon");
	var advise = document.getElementById("advise");
	var top = advisePosition[num] + "px";
	if(document.all)
		obj.style.top = top;
	else
	{
		//obj.setStyle("top", top);
		obj.style.top = top;
	}
	
	advise.innerHTML = txt;
	if(!adviseVisible && canProcessAdvise)
	{
		if(document.all)
			obj.style.visibility = "visible";
		else
		{
			//obj.setStyle("visibility", "visible");
			obj.style.visibility = "visible";
		}
		
		if(!adviseVisible && canProcessAdvise)
			fadeIn("baloon", 1);
		canProcessAdvise = false;
	}
	selectField(id);
	
	return false;
}

function hideBaloon()
{
	if(adviseVisible && canProcessAdvise)
	{
		canProcessAdvise = false;
		fadeOut("baloon",100);
	}
}

function fadeOut(objId,opacity) 
{
  if (document.getElementById) {
    obj = document.getElementById(objId);
    if (opacity >= 0) {
      setOpacity(obj, opacity);
      opacity -= 10;
      window.setTimeout("fadeOut('"+objId+"',"+opacity+")", 100);
    }
	else
	{		
		if(objId == "baloon")
		{
			if(document.all)
				obj.style.visibility = "hidden";
			else
			{
				//obj.setStyle("visibility", "visible");
				obj.style.visibility = "hidden";
			}
		}
		canProcessAdvise = true;
		adviseVisible = false;
	}
  }
}

function fadeIn(objId,opacity) 
{
	
  if (document.getElementById) {
    obj = document.getElementById(objId);
    if (opacity <= 100){
      setOpacity(obj, opacity);
      opacity += 10;
      window.setTimeout("fadeIn('"+objId+"',"+opacity+")", 100);
    }
	else
	{
		canProcessAdvise = true;
		adviseVisible = true;
	}
  }
}

function fadeInMax(objId,opacity, maxv) 
{
  if (document.getElementById)
  {
    obj = document.getElementById(objId);
    if (opacity <= maxv){
      setOpacity(obj, opacity);
      opacity += 10;
      window.setTimeout("fadeInMax('"+objId+"',"+opacity+","+ maxv+")", 100);
    }
	else
	{
		canProcessAdvise = true;
		adviseVisible = true;
	}
  }
}

function fadeInMaxContainer(objId, objInside, opacity, maxv) 
{
  if (document.getElementById)
  {
    obj = document.getElementById(objId);
    if (opacity <= maxv){
      setOpacity(obj, opacity);
      opacity += 10;
      window.setTimeout("fadeInMaxContainer('"+objId+"','" + objInside +"'," +opacity+","+ maxv+")", 100);
    }
	else
	{
		var obj2 = document.getElementById(objInside);
		setOpacity(obj2, 100);
		canProcessAdvise = true;
		adviseVisible = true;
	}
  }
}

function setOpacity(obj, opacity) 
{
	if(opacity > 90) opacity = 100;
	
	opacity = (opacity == 100)?99.999:opacity;
	
	// IE/Win
	obj.style.filter = "alpha(opacity:"+opacity+")";
	
	// Safari<1.2, Konqueror
	obj.style.KHTMLOpacity = opacity/100;
	
	// Older Mozilla and Firefox
	obj.style.MozOpacity = opacity/100;
	
	// Safari 1.2, newer Firefox and Mozilla, CSS3
	obj.style.opacity = opacity/100;
}

function readCurrentUrl()
{
	var str = new String(location);
	var index = str.lastIndexOf("www.bellora.it") + 14;
	var str = str.substring(index);
	if(str.lastIndexOf('#') > -1)
	{
		var rem = "";
		var ind = str.lastIndexOf('#');
		rem = str.substring(ind);
		str = str.replace(rem, "");
	}
	
	var links = str.split("/");
	
	
	for(var i=1; i<links.length; i++)
	{
		var temp = links[i].replace(".php", "");
		temp = temp.replace(/\_/g, " ");
		
		if(temp.lastIndexOf("?") > -1)
		{
			var cut = temp.lastIndexOf("?");
			temp = temp.substring(0, cut);
		}

		if(links[i].lastIndexOf(".php") == -1)
		{
			links[i] = links[i] + ".php";
		}
		
		if(i < links.length-1)
			document.write(" ><span> " +"<a href='" + links[i] + "' title='" + temp +"'>" + temp + "</a></span>");
		else
			document.write(" > <span class='lightBlueBold'>" + temp + "</span>");
	}
}

function redirectCurrentIndex()
{
	var str = new String(location);
	var index = str.lastIndexOf("www.bellora.it") + 14;
	var str = str.substring(index);
	var links = str.split("/");
	
	var temp = links[1] + ".php";

	location = temp;
}

function buttonOver()
{
	var obj = document.getElementById("buttonRegistrati");
	obj.src = root + "images/forms/registrati_button_over.png";
}

function buttonOut()
{
	var obj = document.getElementById("buttonRegistrati");
	obj.src = root + "images/forms/registrati_button.png";
}

function createGiorno()
{
	for(var i= 1; i<32; i++)
	{
		document.write("<option value='" + i + "'>" + i + "</option>");
	}
}

function createAnno()
{
	for(var i= 2008; i>=1900; i--)
	{
		document.write("<option value='" + i + "'>" + i + "</option>");
	}
}

function hidePiega()
{
	var obj = document.getElementById("piega");
	obj.style.display = "none";
}

function setSplash(val)
{
	/*var obj = document.getElementById("container");
	var obj2 = document.getElementById("splash");*/
	
	if(val)
	{
		/*obj2.style.display = "block";
		obj.style.display = "none";*/
		location.href= "splash.php";
	}
	else
	{
		/*obj2.style.display = "none";
		obj.style.display = "block";*/
		var indirizzo = document.location.toString();
		if(indirizzo.indexOf("splash.php") > -1)
			document.location.href = "index.php";
	}
}

function setCookie(c_name,value,expiredays)
{
	var exdate=new Date();exdate.setDate(exdate.getDate()+expiredays);
	document.cookie=c_name+ "=" +escape(value)+
	((expiredays==null) ? "" : ";expires="+exdate.toGMTString());
}

function getCookie(c_name)
{
	if (document.cookie.length>0)
	  {
	  c_start=document.cookie.indexOf(c_name + "=");
	  if (c_start!=-1)
		{ 
		c_start=c_start + c_name.length+1; 
		c_end=document.cookie.indexOf(";",c_start);
		if (c_end==-1) c_end=document.cookie.length;
		return unescape(document.cookie.substring(c_start,c_end));
		} 
	  }
	return "";
} 

function checkCookie()
{
	var splash=getCookie('splash');
	if (splash!=null && splash!="")
	{
		setSplash(false);
	}
	else 
	{
		splash = "visto";
		if (splash!=null && splash!="")
		{
			setCookie('splash',splash,null);
			setSplash(true);
		} 
	}
}

function setAllInputforIE6(form)
{
	if(is_ie5 || is_ie5_5 || is_ie6)
	{
		var ff = document.getElementById(form);
		for(var i=0; i< ff.elements.length; i++)
		{
			ff.elements[i].style.border = "1px #E3E3E3 solid";
		}
	}
}

function checkSQLSyntax(str)
{
	if(str.indexOf(' like ')>-1 || str.indexOf('%')>-1 || str.indexOf(';')>-1 || str.indexOf(',')>-1 || str.indexOf('drop ')>-1 || str.indexOf('select ')>-1)
		return true;
	
	return false;
}

function trim(stringToTrim) {
	return stringToTrim.replace(/^\s+|\s+$/g,"");
}
function ltrim(stringToTrim) {
	return stringToTrim.replace(/^\s+/,"");
}
function rtrim(stringToTrim) {
	return stringToTrim.replace(/\s+$/,"");
}

function getExtension(str)
{
	var dot = str.lastIndexOf("."); 
	if( dot == -1 ) return ""; 
	var extension = str.substr(dot+1,str.length); 
	return extension; 
}


