function removeSpace(field)
{
	field.value = (field.value).replace(/^\s*|\s*$/g,'');
}

function isValidEmail(str) 
{
   return (str.indexOf(".") > 1) && (str.indexOf("@") > 0);
}

function trim(val)
{
	re=/\s+$|^\s+/g;
	with (val)
	{
		val=val.replace(re,"");
	}
	return val;
}

function ltrim(val)
{
	re=/^\s+/g;
	with (val)
	{
		val=val.replace(re,"");
	}
	return val;
}

function rtrim(val)
{
	re=/\s+$/g;
	with (val)
	{
		val=val.replace(re,"");
	}
	return val;
}

function Show_Img(img, w, h) 
{
	if(w<400){w=400;}

	if(img=="")
	{
		return; // set the options as you like
	}
	winleft = (screen.width - w - 22)/2; 
	wintop = (screen.height - h)/2 - 50; 
	if(typeof(SmallWin)!="undefined")
	{
		SmallWin.close();
	}
	SmallWin = window.open('./viewimg.php?img='+img, 'ImgWindow','scrollbars,resizable=no,height=' +(h+24)+ ',width=' +(w+24)+',top=' +wintop+ ',left=' +winleft+ ', margin=0');
	SmallWin.focus() 
	SmallWin.width=w;
	SmallWin.height=h;
}

function SWFDelegate(url,caption,gallery) {
   var objLink = document.createElement('a');
   objLink.setAttribute('href',url);
   
   if(gallery==1)
   {
   	objLink.setAttribute('rel','lightbox[gallery]');
   } else 
   {
   	objLink.setAttribute('rel','lightbox[images]');
   }
   
   objLink.setAttribute('title',unescape(unescape(caption)));
   Lightbox.prototype.start(objLink);
}

function setcenterframe()
{
	var arrayPageSize = getPageSizeWH();
	//Element.setWidth('bg_hideTP', arrayPageSize[0]);
	//Element.setHeight('bg_hideTP', arrayPageSize[1]);
	
	if(arrayPageSize[1]>del_height+min_height)
	{
		var newheight=arrayPageSize[1]-del_height;
		document.getElementById('centerframe').height=newheight;
	} else
	{
		document.getElementById('centerframe').height=min_height;
	}
}

function get_radio_value(radiusname)
{
	var rad_val=0;
	var rname=eval(radiusname);

	for (var i=0; i < rname.length; i++)
	{
		if (rname[i].checked)
		{
			rad_val = rname[i].value;
		}
	}
	return rad_val;
}

function numcalc(numview)
{
	if(numview=="")
	{
		numview="0,00";
	}

	numview=numview.replace(".","");
	numview=parseFloat(numview.replace(",","."), 10);
	numview=Math.round(numview*100, 10);
	
	return numview; 
}

function numview(numcalc) 
{
	numcalc=(numcalc/100).toString();
	index = numcalc.indexOf(".");
	decalc="";
	if (index < 0) 
	{
		decalc=".00";
	} else 
	{
		decalc = numcalc.substring(index, index + 3);
		numcalc = numcalc.substring(0, index);
		if (decalc.length < 3)
		{
			decalc+="0";
		}
	}

	numcalc=numcalc.replace(",",".");
	numcalc=numcalc.replace(".",",");

	decalc=decalc.replace(",",".");
	decalc=decalc.replace(".",",");
	negative=0;

	if(numcalc == '' | numcalc == 0)
	{
		numcalc_int = 0;
	} else 
	{
		numcalc_int = numcalc;

		//alert(numcalc_int);

		if(numcalc_int<0)
		{
			numcalc_int=Math.abs(numcalc_int);
			negative=1;
		}

		l = numcalc_int.length;
		if(l > 3) 
		{
			i = l % 3;
			if(i == 0) i = 3;
			a = numcalc_int.substr(0, i);
			while(i < l) 
			{
				a += '.' + numcalc_int.substr(i, 3);
				i += 3;
			}
			numcalc_int = a;
		}
	}

	if(negative==1)
	{
		numcalc_int="-" +numcalc_int;
	}

	return numcalc_int+decalc;
}

function getPageSizeWH(){
	
	var xScroll, yScroll;
	
	if (window.innerHeight && window.scrollMaxY) {	
		xScroll = window.innerWidth + window.scrollMaxX;
		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;
	
//	console.log(self.innerWidth);
//	console.log(document.documentElement.clientWidth);

	if (self.innerHeight) {	// all except Explorer
		if(document.documentElement.clientWidth){
			windowWidth = document.documentElement.clientWidth; 
		} else {
			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;
	}

//	console.log("xScroll " + xScroll)
//	console.log("windowWidth " + windowWidth)

	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){	
		pageWidth = xScroll;		
	} else {
		pageWidth = windowWidth;
	}
//	console.log("pageWidth " + pageWidth)

	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight) 
	return arrayPageSize;
}

function expand(target)
{
	document.getElementById(target+ "_label").innerHTML="<a href=\"javascript:contract('" +target+ "')\">Riduci <img src=\"../images/minus.gif\" border=\"0\"></a>";
	document.getElementById(target+ "_body").style.display="block";
}

function contract(target)
{
	document.getElementById(target+ "_label").innerHTML="<a href=\"javascript:expand('" +target+ "')\">Espandi <img src=\"../images/plus.gif\" border=\"0\"></a>";
	document.getElementById(target+ "_body").style.display="none";
}


