
var IE6 = false /*@cc_on || @_jscript_version < 5.7 @*/;

	var Pri=new Number("1.5")
	var Sep
	var NonSep
	if (isNaN(Pri))
	{
		Sep=","
		NonSep="."
	}
	else
	{
		Sep="."
		NonSep=","
	}

var finestraAperta





	function toggle(d, t){
		if(d){
			if(d.style.display!="block"){
				var cor = findPos(t)
			        d.style.top = "" + (cor[1] + 14) + "px";
			        d.style.left = "" + (cor[0] - 169)  + "px";
				d.style.display="block";
				t.src="img/up.gif";
			}
			else{
				d.style.display="none";
				t.src="img/down.gif";
			}
		}
	}

	function toggleRichiesta(d, t){
		if(d){
			if(d.style.display!="block"){
				if(t){
					var cor = findPos(t);
				        d.style.top = "" + (cor[1] - 220) + "px";
				        d.style.left = "" + (cor[0] - 220)  + "px";
				}else{
				  d.style.marginLeft = "-100px";
				  d.style.marginTop = "-100px";
					d.style.top="50%";
					d.style.left="50%";
				}
				d.style.display="block";
			}
			else{
				d.style.display="none";
			}
		}
	}



function checkPrice(Pr)
{
	if (Pr!="")
	{
		var Prezzo=new Number(Pr.replace(NonSep,Sep))
		if (!isNaN(Prezzo))
		{
			if (Prezzo==Math.round(Prezzo))
			{
				return (Math.round(Prezzo*1000)/1000).toString() + Sep + "000"
			}
			else
			{
				if (Prezzo==Math.round(Prezzo*10)/10)
				{

					return (Math.round(Prezzo*1000)/1000).toString() + "00" 
				}
				else
				{
					if (Prezzo==Math.round(Prezzo*100)/100)
					{
						return (Math.round(Prezzo*1000)/1000).toString() + "0" 
					}
					else
					{
						return Math.round(Prezzo*1000)/1000
					}
				}
			}
		}
		else
		{
			return ""
		}
	}
	else
	{
		return ""
	}
}


function checkNumber(Pr)
{
	if (Pr!="")
	{
		var Prezzo=new Number(Pr.replace(NonSep,Sep))
		if (!isNaN(Prezzo))
		{
			return Math.round(Prezzo)
		}
		else
		{
			return ""
		}
	}
	else
	{
		return ""
	}
}

function controlla(oggetto,valore)
{
	if (oggetto.value != "")
	{
		var giovanni
		giovanni=checkPrice(oggetto.value)
		if (giovanni=="")
			oggetto.value=valore
		else
			oggetto.value=giovanni
	}
}

function CheckDate(obj)
{
var Data,a,b,D1,D2,D3, Data1,Data2,Data3
  	  Data=new String(obj)
          Data=Data.replace(/-/g,"/")
	  a=Data.indexOf("/",1)
      b=Data.indexOf("/",a+1)
	if ((b!=-1) && (a!=-1))
	{
		D1=new Number(Data.substring(0,a))
		D2=new Number(Data.substring(a+1,b))
		D3=new Number(Data.substring(b+1,Data.length))
		if (D1>31 || D2>12 || D3<1000 || isNaN(D1) || isNaN(D2) || isNaN(D3))
		{
   			return ""
		}
    		else
		{
			Data1="00" + D1.toString(10)
			Data1=Data1.substr((Data1.length)-2,2)
			Data2="00" + D2.toString(10)
			Data2=Data2.substr(Data2.length-2,2)
			Data3=D3.toString(10)
			Data3=Data3.substring(Data3.length-4,4)
			return Data1 + "/" + Data2 + "/" + Data3 
		}
	}
	else
	{
		return ""
	}
}




function CheckDate2(obj)
{
var Data,a,b,D1,D2,D3, Data1,Data2,Data3
  	  Data=new String(obj)
          Data=Data.replace(/-/g,"/")
	  a=Data.indexOf("/",1)
      b=Data.indexOf("/",a+1)
	if (a!=-1)
	{
		if (b!=-1)
		{
			D1=new Number(Data.substring(0,a))
			D2=new Number(Data.substring(a+1,b))
			D3=new Number(Data.substring(b+1,Data.length))
		}
		else
		{
			D2=new Number(Data.substring(0,a))
			D3=new Number(Data.substring(a+1,Data.length))
		}
		if (D2>12 || D3<1000 || isNaN(D2) || isNaN(D3))
		{
	   		return ""
		}
	    	else
		{
			Data2="00" + D2.toString(10)
			Data2=Data2.substr(Data2.length-2,2)
			Data3=D3.toString(10)
			Data3=Data3.substring(Data3.length-4,4)
			return Data2 + "/" + Data3 
		}
	}
	else
	{
		return ""
	}
}

function DateDiff(interval, start, end)
{
  var iOut = 0, rounding=true;
  var bufferA = Date.parse(start);
  var bufferB = Date.parse(end );

  // check that the start parameter is a valid Date.
  if ( isNaN (bufferA) || isNaN (bufferB) )
  {
      return 0;
  }
  // check that an interval parameter was not numeric.
  if ( interval.charAt == 'undefined' )
  {
    // the user specified an incorrect interval, handle the error.
    return 0;
  }
  var number = bufferB-bufferA;

  // what kind of add to do?
  switch (interval.charAt(0))
  {
    case 'd': case 'D':
      iOut = parseInt(number / 86400000)+parseInt((number % 86400000)/43200001);
      break ;
    case 'h': case 'H':
      iOut = parseInt(number / 3600000 )+parseInt((number % 3600000)/1800001);
      break ;
    case 'm': case 'M':
      iOut = parseInt(number / 60000 )+parseInt((number % 60000)/30001);
      break ;
    case 's': case 'S':
      iOut = parseInt(number / 1000 )+parseInt((number % 1000)/501);
      break ;
    default:
    // If we get to here then the interval parameter
    // didn't meet the d,h,m,s criteria.  Handle
    // the error.
    return 0;
  } return iOut ;
}


function checkMail(x){
	var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9])+$/;
	if (filter.test(x)) 
		return x
	else 
		return ""
}

function trim(s){
    return s.replace(/(^\s*)|(\s*$)/g, '')
}

function findPos(obj) {
	var curleft = curtop = 0;
	if (obj.offsetParent) {
		do {
			curleft += obj.offsetLeft;
			curtop += obj.offsetTop;
		} while (obj = obj.offsetParent);
	}
	curleft -= 20;
	return [curleft,curtop];
}


	function compare(d, t){
		t.style.backgroundColor='#EEEEEE';
		if(d){
			var cor = findPos(t)
		        d.style.top = "" + (cor[1] + 6) + "px";
		        d.style.left = "" + (cor[0] + t.offsetWidth)  + "px";
			d.style.display="block";
		}
		if(t){
			t.style.backgroundColor = "#ffffff";
		}

	}
	function scompare(d, t){
		t.style.backgroundColor='';
		if(d){
			d.style.display="none";
		}
		t.style.backgroundColor = "";
	}

function getWindowHeight() {
	var windowHeight = 0;
	if (typeof(window.innerHeight) == 'number') {
		windowHeight = window.innerHeight;
	}
	else {
		if (document.documentElement && document.documentElement.clientHeight) {
			windowHeight = document.documentElement.clientHeight;
		}
		else {
			if (document.body && document.body.clientHeight) {
				windowHeight = document.body.clientHeight;
			}
		}
	}
	return windowHeight;
}

function getWindowWidth() {
	var windowWidth = 0;
	if (typeof(window.innerWidth) == 'number') {
		windowWidth = window.innerWidth;
	}
	else {
		if (document.documentElement && document.documentElement.clientWidth) {
			windowWidth = document.documentElement.clientWidth;
		}
		else {
			if (document.body && document.body.clientWidth) {
				windowWidth = document.body.clientWidth;
			}
		}
	}
	return windowWidth;
}

var d;

function posF() {
	posForm(d);
}

function posF2() {
	posForm2(d);
}

function posForm(pName) {
	if (document.getElementById) {
	    var contentElement = document.getElementById(pName);
	    if(contentElement){
	        var windowHeight = getWindowHeight();
	        var windowWidth = getWindowWidth();
	        if (windowHeight > 0 && windowWidth>0) {
		        var contentHeight = 400;
		        var contentWidth = 500;
		        if (windowHeight - contentHeight > 0) {
		            var t = (((windowHeight / 2) - (contentHeight / 2)) + getScrollTop());
		            var l = ((windowWidth / 2) - (contentWidth / 2));
		            if (t<0){
		                t=0;
		            }
		            if (l<0){
		                l=0;
		            }
			        contentElement.style.top = t + 'px';
			        contentElement.style.left = l + 'px';
		        }
	        }
	    }
	}
}

function posForm2(pName) {
	if (document.getElementById) {
	    var contentElement = document.getElementById(pName);
	    if(contentElement){
		var t = getScrollTop();
		var l = getScrollLeft();
		if (t<0){
			t=0;
		}
		if (l<0){
			l=0;
		}
		contentElement.style.top = t + 'px';
		contentElement.style.left = l + 'px';
	    }
	}
}


function showForm(pName, show) {
	if (document.getElementById) {
		var contentElement = document.getElementById(pName);
	        if(show){
			if(!isSomethingOpen(pName)){
			        posForm(pName)
			        contentElement.style.display='block';
				d=pName;
				window.onscroll = posF;
			}
		}else{
			contentElement.style.display='none';
			window.onscroll = null;
		}
	}
}

function showForm2(pName, show) {

	if (document.getElementById) {
		var contentElement = document.getElementById(pName);
	        if(show){
			if(!isSomethingOpen(pName)){
				var pi = document.getElementById('imgBig');
				var pb = document.getElementById('pBar');
				pb.style.display='block';
				pi.style.display='none';
			        posForm2(pName)
			        contentElement.style.display='block';
				d=pName;
				window.onscroll = posF2;
				initCheckLoad();
			}
		}else{
			contentElement.style.display='none';
			window.onscroll = null;
		}
	}
}

function isSomethingOpen(pName){
    var ret=false;
    var i;
    var contentElement = document.getElementById(pName);
    if (contentElement){
        for(i=0; i<document.getElementsByTagName("div").length; i++){
            if (document.getElementsByTagName("div")[i].className == contentElement.className){
                ret = ret || isOpen(document.getElementsByTagName("div")[i].id);
            }
        }
    }
    return ret;
}


function toggleForm(pName){
    fatto=false;
    var contentElement = document.getElementById(pName);
    if (contentElement.style.display != 'block'){
        showForm(pName, true) 
    }else{
        showForm(pName, false) 
    }
}

function isOpen(pName){
    var ret = false;
    var contentElement = document.getElementById(pName);
    if(contentElement){
        if (contentElement.style.display == 'block'){
            ret=true;
        }
    }
    return ret;
}

function getScrollTop(){
    if(typeof pageYOffset!= 'undefined'){
        //most browsers
        return pageYOffset;
    }
    else{
        var B= document.body; //IE 'quirks'
        var D= document.documentElement; //IE with doctype
        D= (D.clientHeight)? D: B;
        return D.scrollTop;
    }
}

function getScrollLeft(){
    if(typeof pageXOffset!= 'undefined'){
        //most browsers
        return pageXOffset;
    }
    else{
        var B= document.body; //IE 'quirks'
        var D= document.documentElement; //IE with doctype
        D= (D.clientWidth)? D: B;
        return D.scrollLeft;
    }
}


function setDivText(myDiv, testo){
    if (myDiv.innerText != null) { 
        myDiv.innerText = testo;
    }
    else{
        if (myDiv.textContent != null)
        {
            myDiv.textContent = testo;
        } 
    }
}

function getDivText(myDiv){
    ret = '';
    if (myDiv.innerText != null) { 
        ret = myDiv.innerText;
    }
    else{
        if (myDiv.textContent != null)
        {
		ret = myDiv.textContent;
        } 
    }
    return ret;
}


function imposeMaxLength(Object, MaxLen)
{
  return (Object.value.length <= MaxLen);
}

var toDrag = null;
var xPartenza = null;
var yPartenza = null;
var xMousePartenza = null;
var yMousePartenza = null;

function beginDrag(pName, e){
  if(!IE6){
    toDrag = document.getElementById(pName);
    if (toDrag){
        yPartenza = new Number(toDrag.style.top.toLowerCase().replace('px',''));
        xPartenza = new Number(toDrag.style.left.toLowerCase().replace('px',''));
        document.onmousemove = doDrag;
        document.onmouseup = endDrag;
    }
  }
}

function doDrag(e) {
    if(toDrag){
        if (!e) var e = window.event;
        
        if(!xMousePartenza){
            xMousePartenza  = e.clientX;
            yMousePartenza = e.clientY;
        }
        
        var xDiff = e.clientX - xMousePartenza ;
        var yDiff = e.clientY - yMousePartenza;
        
        xDiff = xPartenza + xDiff;
        yDiff = yPartenza + yDiff;

        toDrag.style.top = yDiff.toString() + 'px'
        toDrag.style.left = xDiff.toString() + 'px'

    }
}

function endDrag(){
    document.onmousemove = null;
    toDrag = null;
    xPartenza = null;
    yPartenza = null;
    xMousePartenza = null;
    yMousePartenza = null;
    document.onmouseup = null;
}
var imgz=null;
var imgName = "";

function initCheckLoad() {
	imgz = new Image 
	imgz.src = imgName
	checkLoad();
}


function checkLoad() {
	if(imgz){
		if(imgz.complete){
			var pb = document.getElementById('pBar');
			var pi=document.getElementById('imgBig');
			pi.src=imgz.src;
			pb.style.display='none';
			pi.style.display='block';
			if(detectIE()!=-1){
				posiziona(pi);
			}
			imgz=null;
			imgName='';
		}else{
			var timerID = setTimeout("checkLoad()",10) 
		}
	}
}



function posiziona(i){
	var top=0;
	if(imgz.height < 460){
		top = Math.round((460 - imgz.height) / 2)-10;
	}
	i.style.position="static";
	i.style.marginTop = top.toString();
}

function detectIE(){
	var ret = -1;
	if (/MSIE (\d+\.\d+);/.test(navigator.userAgent)){ //test for MSIE x.x;
		ret=new Number(RegExp.$1) // capture x.x portion and store as a number
	}
	return ret;
}
