function getPosX(obj) {
		var curleft = 0;
		if (obj.offsetParent) {
		while (obj.offsetParent) {
		curleft += obj.offsetLeft
		obj = obj.offsetParent;
		}
		}
		else if (obj.x)
		curleft += obj.x;
		return curleft;
}

function getPosY(obj) {
		var curtop = 0;
		if (obj.offsetParent) {
		while (obj.offsetParent) {
		curtop += obj.offsetTop
		obj = obj.offsetParent;
		}
		}
		else if (obj.y)
		curtop += obj.y;
		return curtop;
}

function showDiv(div){

			theDiv=div+"_DIV";
			sfondoDiv=div+"_sfondo";
			posX=getPosX(document.getElementById(div));
			posY=getPosY(document.getElementById(div));

		if (theChoice=='centeredOnProduct'){

						W=parseFloat(document.getElementById(div).style.width);
						theW=parseFloat(document.getElementById(theDiv).style.width);
						sfondoW=parseFloat(document.getElementById(sfondoDiv).style.width);
						x=posX-((theW-W)/2);
						x_sfondo=posX-((sfondoW-W)/2);

						H=parseFloat(document.getElementById(div).style.height);
						theH=parseFloat(document.getElementById(theDiv).style.height);
						sfondoH=parseFloat(document.getElementById(sfondoDiv).style.height);
						y=posY-((theH-H)/2);
						y_sfondo=posY-((sfondoH-H)/2);


						document.getElementById(sfondoDiv).style.visibility='visible';
						document.getElementById(sfondoDiv).style.left = x_sfondo;
						document.getElementById(sfondoDiv).style.top = y_sfondo;
						document.getElementById(theDiv).style.zIndex = 1000;

						document.getElementById(theDiv).style.visibility='visible';
						document.getElementById(theDiv).style.left = x;
						document.getElementById(theDiv).style.top = y;
						document.getElementById(theDiv).style.zIndex = 1001;

		} else if (theChoice=='onTheSide'){
						//alert('leftbusy: ' + leftBusy + ' - rightbusy:' + rightBusy)
						if (posX < pageSizeX/2){
							if(leftBusy){
								if(rightBusy){
									return false;
								}else{
									x=(pageSizeX-divSizeX);
									rightBusy=true;
									//alert('1 - ' + x)
								}
							}else{
								x=0;
								leftBusy=true;
								//alert('2 - ' + x)
							}
						}else{
							if(rightBusy){
								if(leftBusy){
									return false;
								}else{
									x=0;
									leftBusy=true;
									//alert('3 - ' + x)
								}
							}else{
								x=(pageSizeX-divSizeX);
								rightBusy=true;
								//alert('4 - ' + x)
							}
						}
						document.getElementById(theDiv).style.visibility='visible';
						document.getElementById(theDiv).style.left = x;
						document.getElementById(theDiv).style.top = 160;
						document.getElementById(theDiv).style.zIndex = 1001;
		}


}

function hideDiv(div){

	theDiv=div+"_DIV";

	if (theChoice=='onTheSide'){
			if(parseFloat(document.getElementById(theDiv).style.left) < 1){
				leftBusy=false;
			}else{
				rightBusy=false;
			}
	}

	document.getElementById(theDiv).style.visibility='hidden';
	document.getElementById(theDiv).style.left = -1000;
	document.getElementById(theDiv).style.top = -1000;

	if (theChoice=='centeredOnProduct'){
			sfondoDiv=div+"_sfondo";
			document.getElementById(sfondoDiv).style.visibility='hidden';
			document.getElementById(sfondoDiv).style.left = -2000;
			document.getElementById(sfondoDiv).style.top = -2000;
	}


}


function highlightText(searchString, tagId){
			
			arrSearchString=searchString.split(" ");
			inH=document.getElementById(tagId).innerHTML;

			for(i=0; i<arrSearchString.length; i++)
			{
					theWord=arrSearchString[i].toLowerCase();
					inHtemp=inH.toLowerCase();
					n=71; // numero di caratteri aggiunti dalla parte "<span style='background-color:#FFFF00';font-weight:bold;></span>"
					len=theWord.length;
					pos=-(n+len); // inizializzo la posizione nella inH
					posTemp=0;	 // inizializzo la posizione nella inHtemp
					while (inHtemp.indexOf(theWord)>-1)
					{
							posTemp=inHtemp.indexOf(theWord)
							pos=pos+(n+len)+posTemp;

							theWrittenWord=inH.substr(pos,len);

							inHtemp=inHtemp.substring(posTemp+len);

							if (!(inHtemp.indexOf(">") < inHtemp.indexOf("<")))
							{ // sostituisce solo se non siamo all'interno di un tag
								pre=inH.substr(0,pos);
								
								post=inH.substring(pos+len);
								//alert(pre)
								//alert(theWrittenWord)
								//alert(post)
								inH = pre + "<span style='background-color:#FFFF00';font-weight:bold;><b>"+theWrittenWord+"</b></span>" + post;

							}
							else
							{
								pos=pos-n; // poiché non ha sostituito, scalo incremento n
							}

					}
			}
			document.getElementById(tagId).innerHTML=inH;
	}




