//aggiunte da fd e prelevate da main.js products.js etc inizio
	 // fatto nel body window.onload=setFormat;
excludeID=5;

function vaiA(page){
    document.location=page + '?k=' + document.getElementById('k').value;	
}

function setFormat(){
	var targetDiv;
	if(targetDiv=document.getElementById('topLinks')){
		if(smartBreak('topLinks', '<!--break-->|<!--/break-->', 420, true, 38, 31, 15)) 
			targetDiv.style.visibility="visible";
		else
			targetDiv.style.visibility="visible";
//FD illumino il link di primaryNav
        var fd;
        if (fd=document.getElementById(cihTopLinkSelected)){
            fd.className= "topLinksSelected";
        }

	}
	
}

var targetDrop;
var numberOfMainLinks=0;
var numberOfProductLinks=0;
var lineURL="/_layouts/images/CIH_AG/customLine.jpg";
function setPage(){
	setLines();
}

//below function automatically extends lines in the drops downs
function setLines(){
	var targetDiv;
	for(i=0; i<numberOfTopLinks; i++){
		if(targetDiv=document.getElementById("link_"+i+"_content")){
			for(j in targetDiv.childNodes){
				if(targetDiv.childNodes[j] && targetDiv.childNodes[j].tagName && 
				targetDiv.childNodes[j].tagName=="IMG" && targetDiv.childNodes[j].src.indexOf(lineURL)!=-1){
					//June 12 Update
					targetDiv.style.display = "block";
					targetDiv.childNodes[j].style.width=(targetDiv.offsetWidth-17)+"px";
					targetDiv.style.display = "none";
				}
			}
		}
	}
	for(i=0; i<numberOfMainLinks; i++){
		if(targetDiv=document.getElementById("main_"+i+"_content")){
			for(j in targetDiv.childNodes){
				if(targetDiv.childNodes[j] && targetDiv.childNodes[j].tagName && 
				targetDiv.childNodes[j].tagName=="IMG" && targetDiv.childNodes[j].src.indexOf(lineURL)!=-1){
					//June 12 Update
					targetDiv.style.display = "block";
					targetDiv.childNodes[j].style.width=(targetDiv.offsetWidth-17)+"px";
					targetDiv.style.display = "none";
				}
			}
		}
	}
	for(i=0; i<numberOfProductLinks; i++){
		if(targetDiv=document.getElementById("productLinks_"+i+"_content")){
			for(j in targetDiv.childNodes){
				if(targetDiv.childNodes[j] && targetDiv.childNodes[j].tagName && 
				targetDiv.childNodes[j].tagName=="IMG" && targetDiv.childNodes[j].src.indexOf(lineURL)!=-1){
					//June 12 Update
					targetDiv.style.display = "block";
					targetDiv.childNodes[j].style.width=(targetDiv.offsetWidth-17)+"px";
					targetDiv.style.display = "none";
				}
			}
		}
	}
}

//include in common.js
var bw = new lib_bwcheck();

function lib_bwcheck(){
	this.ver=navigator.appVersion;
	//this.vender = navigator.vender;
	this.product=navigator.product;
	this.moz= navigator.product == 'Gecko';
	this.agent=navigator.userAgent;
	this.dom=document.getElementById?1:0;
	this.mac=this.agent.indexOf("Mac")>-1;
	this.opera5=window.opera?1:0;
	this.ie5=(this.ver.indexOf("MSIE 5")>-1 && this.dom && !this.opera5)?1:0;
	this.ie6=(this.ver.indexOf("MSIE 6")>-1 && this.dom && !this.opera5)?1:0;
	this.ie7=(this.ver.indexOf("MSIE 7")>-1 && this.dom && !this.opera5)?1:0;
	this.ie5mac=(this.ver.indexOf("MSIE 5.23")>-1 && !this.opera5 && this.mac)?1:0;
	this.ie4=(document.all && !this.dom && !this.opera5)?1:0;
//	this.ie=this.ie4||this.ie5||this.ie6||this.ie7;
	this.ie=(this.ver.indexOf("MSIE")>-1 && this.dom && !this.opera5)?1:0;
	this.saf=this.agent.indexOf("Safari")>-1;
	this.ns6=(this.dom && parseInt(this.ver) >= 5) ?1:0;
	this.ns4=(document.layers && !this.dom)?1:0;
	this.bw=(this.moz||this.ie5mac||this.saf||this.ie7||this.ie6||this.ie5||this.ie4||this.ns4||this.ns6 ||this.opera5);
	return this;
}

var selectBlock0;
var selectBlock1;

function showMedia(aP,XF) {
  togglePLinks(true, true, true);
  var mediaDiv;
  
  	var bNavigation;
  	if(bNavigation=returnFlashObject('BottomNavigation')){
		bNavigation.SetVariable("disableAll", "true");
//		alert("bottom nav disabled");
	}
	
  	var mMenu;
  	if(mMenu=returnFlashObject('MainMenu')){
		mMenu.SetVariable("disableAll", "true");
//		alert("main menu disabled");
	}
	
  	var sBarSource;
  	if(sBarSource=returnFlashObject('scollBarSource')){
		sBarSource.SetVariable("disableAll", "true");
//		alert("scroll bar disabled");
	}
	
  	var sShow;
  	if(sShow=returnFlashObject('SlideShow')){
		sShow.SetVariable("disableAll", "true");
//		alert("slide show disabled");
	}
	
  	var gSWF;
  	if(gSWF=returnFlashObject('gallerySWF')){
		gSWF.SetVariable("gotoPage", aP);
		gSWF.SetVariable("XMLFile", XF);
	}
	
  	if (mediaDiv=document.getElementById('galleryBox')) {
		mediaDiv.style.visibility="visible";
//		alert("Pause");
  	}

  // This fun little part checks for iFrames and then reveals them
  // For IE 6 only
  	if ( (selectBlock0 = document.getElementById("SB_0")) && bw.ie && !bw.ie7) {
		selectBlock0.style.visibility = "visible";	
	}
	if ( (selectBlock1 = document.getElementById("SB_1")) && bw.ie && !bw.ie7) {
		selectBlock1.style.visibility = "visible";	
	}
     
  return false;
}

// call function from media gallery flash to close media gallery and hide black background
function hideMedia() {
  var mediaDiv;
  if (mediaDiv=document.getElementById('galleryBox')) {
    	mediaDiv.style.visibility="hidden";
  }
  
  	var gSWF;
  	if(gSWF=returnFlashObject('gallerySWF'))
		gSWF.SetVariable("showLoader", "yes");
	
  	var bNavigation;
  	if(bNavigation=returnFlashObject('BottomNavigation'))
		bNavigation.SetVariable("disableAll", "false");
	
  	var sBarSource;
  	if(sBarSource=returnFlashObject('scollBarSource'))
		sBarSource.SetVariable("disableAll", "false");
	
  	var mMenu;
  	if(mMenu=returnFlashObject('MainMenu'))
		mMenu.SetVariable("disableAll", "false");
	
  	var sShow;
  	if(sShow=returnFlashObject('SlideShow'))
		sShow.SetVariable("disableAll", "false");
	

	// This fun little part checks for iFrames and then hides them
	// for IE 6 only
  	if ( (selectBlock0 = document.getElementById("SB_0")) && bw.ie && !bw.ie7) {
		selectBlock0.style.visibility = "hidden";
			
	}
	if ( (selectBlock1 = document.getElementById("SB_1")) && bw.ie && !bw.ie7) {
		selectBlock1.style.visibility = "hidden";
			
	}
	
}


	var pageIndex=0;
	var numberOfLinks;

	var tOff=-9;
	function toggleOptions(i){
		var holderDiv;
		if(scrollDiv && (holderDiv=document.getElementById("option_"+i))){
			pageIndex=i;
			scrollDiv.style.top="0px";
//			scrollDiv.style.top="-22px";
			scrollDiv.innerHTML=holderDiv.innerHTML;
			//set captions if applicable
			var caption;
			var image;
			if( (caption=document.getElementById('caption_'+i)) && (image=document.getElementById('image_'+i)) ){
				caption.style.width=(image.offsetWidth-18)+"px";
				caption.style.top=(image.offsetTop+image.offsetHeight+tOff) + "px";
				caption.style.left=image.offsetLeft+"px";
				image.style.paddingBottom=caption.offsetHeight+"px";
				caption.style.visibility="visible";
			}
			var li;
			var j;
			for(j=0; li=document.getElementById('td_'+j); j++){
				li.className=(j==i)? "NAV5A":"NAV5";
			}
			numberOfLinks=j-1;
			var next;
			var nextArrow;
			var back;
			var backArrow;
			if( (next=document.getElementById('next')) && (nextArrow=document.getElementById('nextArrow')) &&
				(back=document.getElementById('back')) && (backArrow=document.getElementById('backArrow')) ){
				if(numberOfLinks==pageIndex){
					next.className="disabled";
					nextArrow.src="/_layouts/images/CIH_AG/red_triangle_disabled_small.gif";
				}
				else{
					next.className=null;
					nextArrow.src="/_layouts/images/CIH_AG/red_triangle_small.gif";
				}
				if(0==pageIndex){
					back.className="disabled";
					backArrow.src="/_layouts/images/CIH_AG/red_triangle_flip_disabled_small.gif";
				}
				else{
					back.className=null;
					backArrow.src="/_layouts/images/CIH_AG/red_triangle_flip_small.gif";
				}
			}
			scrollDiv.style.width="486px";

//FD inizio: risettato il dimensionamento per la caption per mozilla
			if( (caption=document.getElementById('caption_'+i)) && (image=document.getElementById('image_'+i)) ){
				caption.style.width=(image.offsetWidth-18)+"px";
				caption.style.top=(image.offsetTop+image.offsetHeight+tOff) + "px";
				caption.style.left=image.offsetLeft+"px";
				image.style.paddingBottom=caption.offsetHeight+"px";
				caption.style.visibility="visible";
			}
//FD fine
		}
		setScrollBar();
		return false;
	}

	var numberOfProductLinks=0;
	var firstSet=true;
	function productsSetPage(){
		if(firstSet){
			firstSet=false;
			var targetPLink;
			var i;
			for(i=0; targetPLink=document.getElementById('td_'+i); i++){}
			var backNext;
			if(i > 1 && (backNext=document.getElementById('backNext'))){
				backNext.style.display="block";
				backNext.style.visibility="visible";
			}
		}
		
		scrollDiv=document.getElementById('rightInnerContent');
		scrollBar=document.getElementById('scrollBar');
		setPage();
		/*for(i=0; i<numberOfProductLinks; i++){
			if(targetDiv=document.getElementById("productLinks_"+i+"_content")){
				for(j in targetDiv.childNodes){
					if(targetDiv.childNodes[j] && targetDiv.childNodes[j].tagName && 
					targetDiv.childNodes[j].tagName=="IMG" && targetDiv.childNodes[j].src.indexOf(lineURL)!=-1){
						targetDiv.childNodes[j].style.width=(targetDiv.offsetWidth-17)+"px";
					}
				}
			}
		}*/

		toggleOptions(0);
		
	}
	
function noBNSetPage() {    
	scrollDiv=document.getElementById('rightInnerContent');
	scrollBar=document.getElementById('scrollBar');
	//scrollDiv.style.width="486px"; //era commentato e funzionavano le pagine sitemap ecc
	setScrollBarTall();
	return false;
}

var activeProduct;
	var scrollDiv;
	var scrollBar;
	
	function setScrollBar(){
		if(scrollDiv){
			if(scrollDiv.offsetHeight > 265){
				var sBSource;
				if(sBSource=returnFlashObject('scollBarSource')){
					sBSource.SetVariable("targetHeight", scrollDiv.offsetHeight+25);
					sBSource.SetVariable("chChanges", 1);
					scrollBar.style.visibility="visible";
				}
				else {
					setTimeout("setScrollBar()",100);
				}
			}
			else scrollBar.style.visibility="hidden";
		}
	}
	
	function setScrollBarTall(){
		if(scrollDiv){
			if(scrollDiv.offsetHeight > 290){
				var sBSource;
				if(sBSource=returnFlashObject('scollBarSource')){
					sBSource.SetVariable("targetHeight", scrollDiv.offsetHeight+25);
					sBSource.SetVariable("chChanges", 1);
					scrollBar.style.visibility="visible";
				}
				else {
					setTimeout("setScrollBarTall()",100);
				}
			}
			else scrollBar.style.visibility="hidden";
		}
	}
	
	// SWEET FUNCTION ADDED RIGHT HERE.
	//1/21/09 to try and correct clicking
	
	function scollBarSource_DoFSCommand(command, args) {
		if (command == "scroll") {
//			alert("hey there");
			scroll(args);
		}
	}	
	
	function scroll(y){
		if(scrollDiv)
			scrollDiv.style.top=y+"px";
//		document.getElementById('y').innerHTML=y;
	}
	
	function prevOption(){
		if(pageIndex>0) toggleOptions(pageIndex-1);
		return false;
	}
	
	function nextOption(){
		if(pageIndex<numberOfLinks) toggleOptions(pageIndex+1);
		return false;
	}



// below three functions are for dropdowns
var excludeID=-1;
var origin;
var targetDrop=false;
var onDiv=false;
var onLink=false;
var closeDiv=0;
var delay=100;
var timeOutCommand="";
function toggleTopLink(o, i, holdClass){
    //alert(document.getElementById("link_"+i+"_content").style.display);
	clearTimeout(closeDiv);
	onLink=!onLink;
	//check if is open div that is not owned
	if((targetDrop && targetDrop.id) && targetDrop.id!="link_"+i+"_content"){
		targetDrop.style.visibility="hidden";
		targetDrop.style.display="none";
		if( (!origin.id || origin.id.indexOf("active_") ===false) && !origin.holdClass)
			origin.parentNode.className=null;
	}
	origin=o;
	origin.holdClass=holdClass;
	targetDrop=document.getElementById("link_"+i+"_content");
	if(targetDrop){
		timeOutCommand='if(!onLink && !onDiv) {' +
							'targetDrop.style.visibility="hidden";';
		timeOutCommand='if(!onLink && !onDiv) {' +
							'targetDrop.style.display="none";';
		if(!holdClass) timeOutCommand+='origin.parentNode.className=null;';
		timeOutCommand+='}';
		if(targetDrop.style.visibility=="visible"){
			if(!onLink){
				closeDiv=setTimeout(timeOutCommand, delay);
			}
		}
		if(targetDrop.style.display=="block"){
			if(!onLink){
				closeDiv=setTimeout(timeOutCommand, delay);
			}
		}
		else{
			targetDrop.style.left=(origin.offsetLeft+378) + "px";
			if(!holdClass)
				origin.parentNode.className="topLinksOver";
			targetDrop.style.top=(origin.offsetTop+origin.parentNode.parentNode.offsetTop+origin.offsetHeight+2)+"px";
			targetDrop.style.visibility="visible";
			targetDrop.style.display="block";
		}
	}
}

function divSense() {
    
	clearTimeout(closeDiv);
	onDiv=!onDiv;
	if(!onDiv){
		closeDiv=setTimeout(timeOutCommand, delay);
	}
}

function showArrow(i){
	clearTimeout(closeDiv);
	onLink=!onLink;
	var targetArrow;
	if(targetArrow=document.getElementById('arrow_'+i)){
		if(targetArrow.style.visibility=="visible"){
			targetArrow.style.visibility="hidden";
		}
		else{
			targetArrow.style.visibility="visible";
		}
	}	
}

var oldImage="";
var maxWidth=970;
function toggleButtons(o, img, i){
	img="/_layouts/images/CIH_AG/"+img;
	o.src=(o.src.indexOf("Over.jpg")!=-1)? img+".jpg":img+"Over.jpg";
}

var oldIndex;
	var targetDrop;

var nextIndex=0;
var pageIndex=0;
var pagePointers = new Array();
var maxHeight;

function switchArticles(bck, mH) {
        //FD workaround 
        if (bck==false){ 
            if (nextBut=document.getElementById("next")) {
                if (nextBut.className=="disabled2")
                {
                //alert('cuzzato');
		        return false;
                }
            }
        }
    
		var articlesTable;
		var articlesList;
		var backBut;
		var nextBut;
			
		if ( (articlesTable=document.getElementById("articlesTable")) && (articlesList=document.getElementById("articlesList")) ) {
	
			if(articlesTable.rows.length>0) {
				while (articlesTable.childNodes.length>0)
					articlesTable.removeChild(articlesTable.firstChild);
			}
			
		
		//	event_0.innerHTML="";
		//	event_1.innerHTML="";
			
			
			articlesTable.style.height="0px";
		//	maxHeight = 170;
			maxHeight = mH;
			var targetTable = articlesTable;
			var originCell;
			
			var tbody = document.createElement("tbody");
			targetTable.appendChild(tbody);
			if (bck==true) {
				if (pageIndex>1) {
					pageIndex--;
					nextIndex=pagePointers[pageIndex-1];
				}
				else
					nextIndex=0;
			}
			
			else {
			    
				if (nextIndex < (articlesList.rows.length) ) {
				//alert('nextIndex' + nextIndex + 'lengh' + articlesList.rows.length);
				//if (nextIndex < (articlesList.rows.length-1) ) { //FD
				
					pageIndex++;
					// if the command is to move forward, and this is the last page of the list, make a note of the top index
					if (pagePointers.length == pageIndex-1) {
						pagePointers.push(nextIndex);	
					}
				}
				else
					nextIndex=pagePointers[pageIndex-1];
			}
			
			if (backBut=document.getElementById("back")) {
				if(pageIndex==1){
					//hide back
					backBut.className="disabled2";
					document.getElementById('backArrow').src="/_layouts/images/CIH_AG/red_triangle_flip_disabled2_small.gif";
				}
				else {
					//reveal back
					backBut.className=null;
					document.getElementById('backArrow').src="/_layouts/images/CIH_AG/red_triangle_flip_small.gif";
				}
			}
			
			var bAbilitaNext=false; //FD
			
			for (i=nextIndex; i< articlesList.rows.length; i++) {
			if (articlesList.rows[i].cells) {
				originCell = articlesList.rows[i].cells[0];
				var row=document.createElement("tr");
				var cell=document.createElement("td");
				cell.innerHTML = originCell.innerHTML;
				row.appendChild(cell);
				tbody.appendChild(row);
				nextIndex = i;
				if(targetTable.offsetHeight > maxHeight) {
					// reveal back next buttons
					document.getElementById("backNextLeft").style.display="block";
					document.getElementById("backNextLeft").style.visibility="visible";
					tbody.removeChild(row);
					i--;
					bAbilitaNext=true; //FD
					break;
				}
			}
			}				
		}
		
		if (nextBut=document.getElementById("next")) {
			//if (nextIndex < (articlesList.rows.length-1) ) { //FD
			if (bAbilitaNext ) {
			//alert('abilito il next');
				//show the next div
				nextBut.className=null;
				document.getElementById('nextArrow').src="/_layouts/images/CIH_AG/red_triangle_small.gif";
			}	
			else {
				//hide next div	
				nextBut.className="disabled2";
				document.getElementById('nextArrow').src="/_layouts/images/CIH_AG/red_triangle_disabled2_small.gif";
			}
		}
		return false;
	}		
	
	function smartBreak(targetID, breakString, targetWidth, includeBreaks, maxHeight, initial, moveUp, padding){
		var target;
		if(target=document.getElementById(targetID)){
			//set up defaults
			if(arguments.length < 8) padding=20;
			if(arguments.length < 4) includeBreaks=false;
			if(arguments.length < 3){
				if(target.style.width) targetWidth=parseInt(target.style.width);
				else return false;	
			}
			if(arguments.length < 2) breakString='<!--break-->';
			var segment=target.innerHTML.split(breakString);
			target.innerHTML="";
			var lastLoop;
			//create an empty table
			var virtualTable=document.createElement('table');
			virtualTable.style.padding="0px !important";
			virtualTable.style.width=null;
			var tbody=document.createElement('tbody');
			var tr=document.createElement('tr');
			var targetCell=document.createElement('td');
			tr.appendChild(targetCell);
			tbody.appendChild(tr);
			virtualTable.appendChild(tbody);
			target.appendChild(virtualTable);
			virtualTable.style.visibility="hidden";
			var regularHeight;
			for(i in segment){
				lastLoop=targetCell.innerHTML;
				if(includeBreaks && (i < segment.length-1) && (i!=0) ) targetCell.innerHTML+=breakString;
				targetCell.innerHTML+=segment[i];
				if(i==0) regularHeight=targetCell.offsetHeight;
				//if gets too large
				if(arguments.length >= 7 && regularHeight>maxHeight) {
					target.style.top=(initial-moveUp)+"px";
					maxHeight=regularHeight;
				}
				if((targetCell.offsetWidth > targetWidth) || (regularHeight<targetCell.offsetHeight) ){
					regularHeight=targetCell.offsetHeight;
					targetCell.innerHTML=lastLoop;
					if(i!=0) targetCell.innerHTML+="<br />";
					targetCell.innerHTML+=segment[i];
				}
			}
			target.innerHTML=targetCell.innerHTML;
			target.style.width=targetWidth+"px";
		}
		//alert(target.style.width);
		return true;
	}

	function smartTable(targetID, breakString, targetWidth, minItems){
		var target;
		if(target=document.getElementById(targetID)){
			//set up defaults
			if(bw.saf) var segment=target.innerHTML.split("<!--/break-->");
			else var segment=target.innerHTML.split(breakString);
			target.innerHTML="";
			var lastLoop;
			//create an empty table
			var virtualTable=document.createElement('table');
			virtualTable.style.padding="0px !important";
			virtualTable.cellPadding="0";
			virtualTable.cellSpacing="0";
			virtualTable.style.width=null;
			var tbody=document.createElement('tbody');
			var tr=document.createElement('tr');
			tr.className="firstRow";
			var targetCell=document.createElement("td");
			tbody.appendChild(tr);
			virtualTable.appendChild(tbody);
			target.appendChild(virtualTable);
			var maxCols=-1;
			var rowCount=1;
			var colCount=0;
			for(i=0; i < segment.length -1; i++){
				//populate cell
				targetCell.innerHTML=segment[i];
				//set padding
				targetCell.style.padding=(colCount==0)?"3px 0px 3px 0px": "3px 0px 3px 24px";
				//place cell in row
				colCount++;
				tr.appendChild(targetCell);
				//check if maxcols has been reached before targetWidth or targetWidth has been reached on the first row
			//alert(' poi i:' + i + ' segment.length:' + segment.length + ' maxCols:' + maxCols + ' rowCount:' + rowCount + 'colCount: '+ colCount + ' targetWidth:' + targetWidth + ' virtualTable.offsetWidth:' + virtualTable.offsetWidth);
				if(colCount > 1) { //allow a minimum of one item to each row regardless of width (prevent recursion)
					//alert(targetWidth+" < "+virtualTable.offsetWidth);
					//alert(maxCols > -1);
					//alert(maxCols <= colCount);
					if(maxCols > -1 && maxCols < colCount){
						//create a new row
						tr.removeChild(targetCell); //remove the last column
						var tr=document.createElement('tr'); //create new row
						//FD var tr=document.createElement('tr'); //create new row
						rowCount++;
						tbody.appendChild(tr);
						//alert(' FD rowCount++' + rowCount);
						//reset col count //FD aggiunto per vedere di mettere a posto le righe
						colCount=0;
					}
					else if(maxCols==-1 && targetWidth < virtualTable.offsetWidth){
						//set maxcols at one less than colCount
						maxCols=colCount-2;
						tr.removeChild(targetCell); //remove the last column
						var tr=document.createElement('tr'); //create new row
						rowCount++;
						tbody.appendChild(tr);
						targetCell.style.padding="3px 0px 3px 0px";
						
						tr.appendChild(targetCell); //attach column to new row
						//reset col count
						colCount=0;
						//alert(' FD2 rowCount++' + rowCount);
						
					}
					else if(maxCols > -1 && targetWidth < virtualTable.offsetWidth && maxCols < colCount){
						//decrement maxCols
						maxCols--;
						//reset all variables including 1
						colCount=0;
						rowCount=1;
						i=-1;
						//reset table variables
						//alert("restarting");
						virtualTable.removeChild(tbody);  
						var tbody=document.createElement('tbody');
						virtualTable.appendChild(tbody);
						tbody.appendChild(tr);
					}
				}
				var targetCell=document.createElement("td");
			}
			//determine number of columns per row
			//FD mCols=Math.ceil((segment.length-1)/rowCount); //FD in quanto crea un elemento in pi� di tabella
			mCols=Math.floor((segment.length-1)/rowCount); //FD in quanto crea un elemento in pi� di tabella

            ////FD modifica del 07/01/09 inizio
        	maximumColumns=6;
			if((maxCols > maximumColumns)||(maxCols==-1)) maxCols=maximumColumns; 
            ////FD modifica del 07/01/09 fine

			mCols=maxCols; //FD
			//mCols=Math.ceil(segment.length/rowCount);
			//alert('segment.length' + segment.length + 'rowCount' + rowCount);
			//alert('mCols' + mCols);
			maxCols=( (mCols<minItems) && (minItems<=maxCols) )?minItems:mCols;
			//FD 
			rowCount=Math.ceil((segment.length-1)/mCols);
			//alert('rowCount' + rowCount);
			//alert('virtualTable.offsetWidth' + virtualTable.offsetWidth);
			//FD inizio
			var fdLeft=24;
			//alert ('virtualTable.offsetWidth' + virtualTable.offsetWidth + 'targetWidth' + targetWidth + 'calcolo' + (targetWidth + 80 + (24 * (mCols - 1) - virtualTable.offsetWidth) ) );
			if (virtualTable.offsetWidth > targetWidth)
			{
			    if ((targetWidth  + 80 + (24 * (mCols - 1) - virtualTable.offsetWidth) ) > 0)
			        {
			            fdLeft = Math.ceil((targetWidth + 80 + (24 * (mCols - 1) - virtualTable.offsetWidth)) / mCols);
			            if (fdLeft>24)
			                fdLeft=24;
			            if (fdLeft<4)
			                fdLeft=4;
			        }
			    else
			        {
			            fdLeft = 4;
			        }
			}
			
			//FD fine
			//once done start over and do again
			
			virtualTable.removeChild(tbody);  
			var tbody=document.createElement('tbody');
			virtualTable.appendChild(tbody);  
			var tr=document.createElement('tr');
			tr.className="firstRow";
			tbody.appendChild(tr);  
			colCount=0;
			rC=1;
			for(i in segment){
				var targetCell=document.createElement('td');
				if(colCount==maxCols){
					colCount=0;
					var tr=document.createElement('tr');
					rC++;
					if( rC==1 || rC < rowCount)
						tr.className="firstRow";
					tbody.appendChild(tr);
				}
				targetCell.innerHTML=segment[i];
				//FD targetCell.style.padding=(colCount==0)?"3px 0px 3px 0px": "3px 0px 3px 24px";
				targetCell.style.padding=(colCount==0)?"3px 0px 3px 0px": "3px 0px 3px " + fdLeft + "px";
				tr.appendChild(targetCell);
				colCount++;
			}
			if(rowCount>2) target.style.top="0px";
			//alert ('target.offsetWidth' + target.offsetWidth);
			
		}
		return true;
	}




	function convertFlashVars(str){
		return str.replace("&", "%26").replace("?", "%3F");
	}


function fieldCheck(aTextField) {
   return (!(aTextField.value.length==0) &&
           (aTextField.value!=null) && 
           !whiteCheck(aTextField.value) );
}	

//returns true if string is whitespace only
function whiteCheck(str){
    return /^( |\n|\r\s)+$/.test(str);
}


//takes an array and checks if fields are empty
var originalLabelColor="#333333";
function verifySubmit(checkFields, checkFieldNames, formIndex){
    var verified=true;
    var focusSwitched=false;
    //default form index
    if(arguments.length < 3)
        formIndex=0;
    for(i in checkFields){
        if(document.forms[formIndex][checkFields[i]]){
            if( ((document.forms[formIndex][checkFields[i]].tagName=="SELECT") && document.forms[formIndex][checkFields[i]].selectedIndex==0)
                   || !fieldCheck(document.forms[formIndex][checkFields[i]])){
                verified=false;
                var checkFieldName=checkFields[i];
                if(arguments.length>1 && checkFieldNames[i])
                    checkFieldName=checkFieldNames[i];
	                alert("Please enter '"+checkFieldName+"'");
                if(!focusSwitched){
                    document.forms[formIndex][checkFields[i]].focus();
                    focusSwitched=true;
                }
                var targetLabel;
                if(targetLabel=document.getElementById(checkFields[i]+'Label')){
					targetLabel.innerHTML=targetLabel.innerHTML.replace(/^\*/, "");
                    targetLabel.style.color="#993333";
                    targetLabel.innerHTML="*"+targetLabel.innerHTML;
                }
            }
            else if( ((document.forms[formIndex][checkFields[i]].tagName=="SELECT") && document.forms[formIndex][checkFields[i]].selectedIndex!=0)
                   || fieldCheck(document.forms[formIndex][checkFields[i]])){
                var targetLabel;
                if(targetLabel=document.getElementById(checkFields[i]+'Label')){
					targetLabel.style.color=originalLabelColor;
					targetLabel.innerHTML=targetLabel.innerHTML.replace(/^\*/, "");
                }
            }
        }
	}
	return verified;
}

	

function verifyEmail(formIndex, firstField, matchField){
	if(arguments.length==0) formIndex=0;
	var status = false;     
	var emailRegEx = /^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$/i;
     if (document.forms[formIndex][firstField].value.search(emailRegEx) == -1) {
          alert("Please enter a valid email address.");
     }
     else if (document.forms[formIndex][firstField].value != document.forms[formIndex][matchField].value) {
          alert("Email addresses do not match.  Please retype them to make sure they are the same.");
     }
     else status = true;
     return status;
}

function addCSSRule(selector, attributes){
var ss = document.styleSheets[0];
if(ss.insertRule) ss.insertRule(selector + '{' + attributes + '}', ss.cssRules.length);
else if(ss.addRule) ss.addRule(selector, attributes);
}

	function setActivePLink(){
 		if(bw.ie) addCSSRule("#productLinks img", "padding-top: 2px;");
		var activeParent;
		if( (document.getElementById('active_PLink')) && (activeParent=document.getElementById('active_PLink').parentNode) ){
			activeParent.className="productLinksDropped";
			for(i in activeParent.childNodes){
				if(activeParent.childNodes[i].tagName=="IMG" && activeParent.childNodes[i].id){
					activeParent.childNodes[i].src="/_layouts/images/CIH_AG/products/pArrowOver.jpg";
					break;
				}
			}
		}
		if(activeParent=document.getElementById('productLinks')){
			activeParent.style.visibility="visible";
		}
	}


	var oldIndex;
	var targetDrop;
	var oldArrow;
	var pArrow;
	
	function togglePLinks(o, i, closeAll){
		if(arguments.length==3){
			if(targetDrop && origin && origin.parentNode){
				targetDrop.style.visibility="hidden";
				if(pArrow) pArrow.style.visibility="visible";
				if(!origin.id || origin.id.indexOf("active_") ===false)
					origin.parentNode.className=null;
			}
		}
		else {
			clearTimeout(closeDiv);
			onLink=!onLink;
			//check if is open div that is not owned
			if((targetDrop && targetDrop.id) && targetDrop.id!="productLinks_"+i+"_content"){
				targetDrop.style.visibility="hidden";
				pArrow.style.visibility="visible";
				if(!origin.id || origin.id.indexOf("active_") ===false)
					origin.parentNode.className=null;
			}
			origin=o;
			targetDrop=document.getElementById("productLinks_"+i+"_content");
			pArrow=document.getElementById('pArrow_'+i);
			if(targetDrop){
				timeOutCommand='if(!onLink && !onDiv) {' +
								'targetDrop.style.visibility="hidden";';
				if(!origin.id || origin.id.indexOf("active_") ===false) {
					timeOutCommand+='origin.parentNode.className=null;'+
										'document.getElementById("pArrow_"+oldIndex).style.visibility="visible";';
				}
				
				timeOutCommand+='}';
				if(targetDrop.style.visibility=="visible"){
					if(!onLink){
						closeDiv=setTimeout(timeOutCommand, delay);
	
					}
				}
				else{
					oldIndex=i;
					document.getElementById('pArrow_'+i).style.visibility="hidden";
					var parentDiv=origin.parentNode.parentNode.parentNode.parentNode.parentNode;
					var parentDivParent=origin.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode;
					var parentTable=origin.parentNode.parentNode.parentNode.parentNode;
					var parentCell=origin.parentNode;
					//check that there is room between it and end of screen
					var leftOffset=origin.offsetLeft+parentDiv.offsetLeft+ parentCell.offsetLeft;
					var topOffset=parentCell.offsetTop+parentDivParent.offsetTop+parentCell.offsetHeight+
								parentTable.offsetTop+parentDiv.offsetTop-54;
					topOffset=parentCell.offsetTop + parentCell.offsetHeight + parentDiv.offsetTop; //FD cos� funziona
					

					if(leftOffset > (maxWidth-targetDrop.offsetWidth))
						targetDrop.style.left=(maxWidth-targetDrop.offsetWidth)+"px";
					else targetDrop.style.left=leftOffset + "px";
					origin.parentNode.className="productLinksDropped";
					
					targetDrop.style.top=topOffset+"px";
					targetDrop.style.visibility="visible";
					
					
					// LINE ADDED 6_05_09 to fix internal product menu glitch
					targetDrop.style.display="block";
				}
			}
			else{
				if(origin.parentNode.className && origin.parentNode.className=="productLinksDropped"){
					if(!origin.id || origin.id.indexOf("active_") ===false) {
						origin.parentNode.className=null;
						document.getElementById('pArrow_'+i).style.visibility="visible";
					}
				}
				else{
					origin.parentNode.className="productLinksDropped";
					document.getElementById('pArrow_'+i).style.visibility="hidden";
				}
			}
		}
	}

function returnFlashObject(objectName){
	if(window.document[objectName])
		return window.document[objectName];
	if(navigator.appName.indexOf("Microsoft Internet")==-1){
		if (document.embeds && document.embeds[objectName])
			return document.embeds[objectName]; 
	}
	else // if (navigator.appName.indexOf("Microsoft Internet")!=-1)
		return document.getElementById(objectName);
	return false;
}

function GetRequest(Url_, Word_)
{
    var Out_="0";
	var Pos_ = -1;
	var Index_ = "";
	var toParse_ = "";
    toParse_ = Index_ = "" + Url_;
	
	Index_ = Index_.toUpperCase();
	Word_ = Word_.toUpperCase();
	
	if ((Pos_ = Index_.indexOf("?")) > -1)
	{
		Index_ = Index_.substring(Pos_ + 1, Index_.length);
		toParse_ = toParse_.substring(Pos_ + 1, toParse_.length);
		if ((Pos_ = Index_.indexOf(Word_)) > -1)
		{
			Out_ = toParse_.substring(Pos_ + Word_.length + 1, toParse_.length);
			if ((Pos_ = Out_.indexOf("&")) > 0)
			{
				Out_ = Out_.substring(0, Pos_);
			}
			if ((Pos_ = Out_.indexOf("#")) > 0)
			{
				Out_ = Out_.substring(0, Pos_);
			}
			
			Out_ = unescape(Out_);
			
		}
	}
	return Out_;
}

//<pier>
	function getCookieVal (offset) {
	    var endstr = document.cookie.indexOf (";", offset);
	    if (endstr == -1) endstr = document.cookie.length;
	    return unescape(document.cookie.substring(offset, endstr));
    }

    function getCookie (name) {
	    var arg = name + "=";
	    var alen = arg.length;
	    var clen = document.cookie.length;
	    var i = 0;
	    while (i < clen) {
		    var j = i + alen;
		    if (document.cookie.substring(i, j) == arg){
		        return getCookieVal (j);
		    }
		    i = document.cookie.indexOf(" ", i) + 1;
		    if (i == 0) break;
	    }
	    return null;
    }
    
    function setCookie (name, value) {
        var argv = setCookie.arguments;
	    var argc = setCookie.arguments.length;
	    var expires = (argc > 2) ? argv[2] : null;
	    var path = (argc > 3) ? argv[3] : null;
	    var domain = (argc > 4) ? argv[4] : null;
	    var secure = (argc > 5) ? argv[5] : false;
	    document.cookie = name + "=" + escape (value) +
	    ((expires == null) ? "" : ("; expires=" + expires.toGMTString())) +
	    ((path == null) ? "" : ("; path=" + path)) +
	    ((domain == null) ? "" : ("; domain=" + domain)) +
	    ((secure == true) ? "; secure" : "");
    }
    
    function deleteCookie (name) {
        var exp = new Date();
	    exp.setTime (exp.getTime() - 1);
	    var cval = getCookie (name);
	    document.cookie = name + "=" + cval + "; expires=" + exp.toGMTString();
    }
//</pier>

