
var ViewSpeed = 10;
var ViewStep = 5;

function objShow(obj, s)
{
	obj = document.getElementById(obj);
	if (s==1)
	{
		obj.style.display = '';
	}
	else
	{
		obj.style.display = 'none';
	}
}

function Rollover (MyName, MyImage) {
	if (navigator.userAgent.indexOf ('MSIE') != -1 || navigator.userAgent.indexOf ('Gecko') != -1) {
	  obj = document.getElementById(MyName);
	  obj.src = '' + MyImage;
  } else {
      eval ('document.' + MyName + '.src = \'' + MyImage + '\'');
  }
}

function OpenPopup (MyPage, MyWidth, MyHeight, MyResizable, MyScrolling) {
	xPos = (screen.width) ? (screen.width-MyWidth)/2 : 0; 
	yPos = (screen.height) ? (screen.height-MyHeight)/2 : 0; 
	settings = 'width=' + MyWidth + ', height=' + MyHeight + ",top=" + yPos + ",left=" + xPos + ', resizable=' + MyResizable + ', scrollbars=' + MyScrolling + ', location=0, menubar=0, status=0, titlebar=0, toolbar=0';
	window.open ('' + MyPage, '_blank', settings);	
}

function ViewObj (MyObj, MyObjWidth, xCenter, yCenter, StartHeight, EndHeight) {
	obj=document.getElementById(MyObj);
	wPos = window.screenLeft;
	//xPos = ((screen.availWidth) ? (screen.width-21-320)/2 : 0)-wPos;
	xPos = ((document.body.clientWidth) ? (document.body.clientWidth-MyObjWidth)/2 : 0) + xCenter;
	yPos = ((document.body.clientHeight) ? (document.body.clientHeight)/2 : 0) + yCenter;
	obj.style.left=xPos;
	obj.style.top=yPos;
	obj.style.visibility='visible';
	if (StartHeight < EndHeight) {
		obj.style.clip='rect(0px 320px ' + StartHeight + 'px 0px)';
		NewHeight = StartHeight + ViewStep;
		setParameters = "'" + MyObj + "', " +  MyObjWidth + ", " +  xCenter + ", " +  yCenter + ", " +  NewHeight + ", " + EndHeight;
		setTimeout ('ViewObj (' + setParameters + ');', ViewSpeed);
	}
}

function OpenObj (MyObj, MyObjWidth, xCenter, yCenter, StartHeight, EndHeight) {
	if (navigator.userAgent.indexOf ('MSIE') != -1 || navigator.userAgent.indexOf ('Gecko') != -1) {
		obj=document.getElementById(MyObj);
		obj.style.zIndex=10;
		if (obj.style.visibility=='visible') {
			obj.style.visibility='hidden';
		} else {
			setParameters = "'" + MyObj + "', " +  MyObjWidth + ", " +  xCenter + ", " +  yCenter + ", " +  StartHeight + ", " + EndHeight;
			setTimeout ('ViewObj (' + setParameters + ');', 0);
		}
	  } else {
      eval ('document.layers.Menu' + MyObj + '.visibility = \'show\'');
  }
}

function winPopup(imgPath, imgCode, imgDim, imgDscr) {
	x = imgDim.split('x');
	imgWidth = Number(x[0]);
	imgHight = Number(x[1]);
	winTitle = "Iveco Service Club - Prize: " + imgCode;
//	winImg = imgPath + imgCode +'.jpg';
	winImg = imgPath;
	winnButton = '<input name="viewmember" type="button" class="mainbutton" value="Ok" onClick="window.close()">';
	winHtml = '<html><head><meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"><title>';
	winHtml += winTitle;
	winHtml += '</title><link rel="stylesheet" type="text/css" href="/grafiche/isc_designblu/css/isc.css"><script language="JavaScript" src="/grafiche/isc_designblu/scripts/functions.js" type="text/javascript"></script></head>';
	winHtml += '<body><div align="center">';
	winHtml += '<table height="100%" width="100%" border="0" cellspacing="0" cellpadding="0" bgcolor="#FFFFFF"><tr>'
	winHtml += '<td align="center" valign="middle"><img src="/grafiche/isc_designblu/images/isc00ghost.gif" alt="" width="9" height="9"></td>'
	winHtml += '<td align="center" valign="middle"><table border="0" cellspacing="0" cellpadding="0">'
	winHtml += '<tr><td align="center" valign="middle"><img src="/grafiche/isc_designblu/images/isc00ghost.gif" alt="" width="9" height="9"></td></tr>'
	winHtml += '<tr><td align="center" valign="middle"><table border="0" cellspacing="0" cellpadding="0"><tr>'
	winHtml += '<td align="center" valign="middle">'
	winHtml += '<table border="0" cellspacing="0" cellpadding="0">'
	winHtml += '<tr><td align="center" valign="middle" bgcolor="#999999"><table width="100%" border="0" cellspacing="1" cellpadding="0">'
	winHtml += '<tr><td align="center" valign="middle" bgcolor="#FFFFFF">';
	winHtml += '<img src="';
	winHtml += winImg;
	winHtml += '" alt="" width="' + imgWidth + '" height="' + imgHight + '">';
	winHtml += '</td></tr></table></td></tr>';
	winHtml += '<tr><td align="center" valign="middle" bgcolor="#999999" class="formlable" style="text-align:center; height:20px; vertical-align: middle; color: #FFFFFF; padding: 5px 5px 5px 5px">';
	winHtml += imgDscr;
	winHtml += '</td></tr>';
	winHtml += '<tr><td align="center" valign="middle"><img src="/grafiche/isc_designblu/images/isc00ghost.gif" alt="" width="10" height="10"></td></tr>';
	winHtml += '<tr><td align="center" valign="middle">'
	winHtml += '<table width="30" border="0" cellspacing="1" cellpadding="0" class="formlable"><tr><td '
//	winHtml += "onMouseOver=Rollover('btnok','/grafiche/isc_designblu/images/isc00btnok02.gif') onMouseOut=Rollover('btnok','/grafiche/isc_designblu/images/isc00btnok01.gif')>";
	winHtml += ">";
	winHtml += winnButton;
	winHtml += '</td></tr></table>';
	winHtml += '</td></tr></table></td></tr></table></td></tr>';
	winHtml += '<tr><td align="center" valign="middle"><img src="/grafiche/isc_designblu/images/isc00ghost.gif" alt="" width="9" height="9"></td></tr>';
	winHtml += '</table></td><td align="center" valign="middle"><img src="/grafiche/isc_designblu/images/isc00ghost.gif" alt="" width="9" height="9"></td></tr>';
	winHtml += '</table></div></body></html>';	

	winWidth = imgWidth+50;
	winHight = imgHight+100;
	
	winxPos = (screen.width) ? (screen.width-winWidth)/2 : 0; 
	winyPos = (screen.height) ? (screen.height-winHight)/2 : 0; 
	settings ='height=' + winHight +' , width=' + winWidth +', top=' + winyPos + ', left=' + winxPos + ', scrollbars=0, location=0, menubar=0, status=0, titlebar=0, toolbar=0, resizable=0';
	
	if (window.resizeTo&&navigator.userAgent.indexOf("Microsoft")==-1) {
		var win = window.open('', 'win', settings);
			with (win.document) {
			  open('text/html', 'replace');
			  write(winHtml);
			  close();
			}
			win.name = imgCode;
			//for (winSize = 1; winSize <= winHight; winSize +=5) {
					//win.resizeTo(winWidth , winSize);
			//}
	} else {
		window.open(winImg);
	}
}

function imgShow(yPos,xPos) {
	obj = document.getElementById('imgTag');
	box = document.getElementById('imgBox');
	sel = document.getElementById('imgCtrl');

	if(obj!=null && box!=null && sel!=null)
	{
		obj.style.visibility='hidden';
	//	y = sel.options(sel.selectedIndex).value.split('|');
		y = sel.value.split('|');
		if (y!='') {
			imgCode = y[3];
			imgDim = y[1];
			x = imgDim.split('x');	
			imgWidth = Number(x[0]);
			imgHeight = Number(x[1]);	
			key = 'ximgTag';	
			obj.style.width = "150";
			obj.style.height = "183";
			imgBoxWidth = obj.width;
			imgBoxHeight = obj.height;	
			xPos += ((document.body.clientWidth) ? (document.body.clientWidth)/2 : 0);
			obj.style.left=Number(xPos);
			obj.style.top=Number(yPos);
			if (Number(imgHeight*imgBoxWidth/imgWidth)>=(imgBoxHeight)) {
				obj.style.width = imgBoxWidth;
				obj.style.height = imgHeight*imgBoxWidth/imgWidth;
				cutimgHeight = Math.floor(((imgHeight*imgBoxWidth/imgWidth)-imgBoxHeight)/2);
				if ((((imgHeight*imgBoxWidth/imgWidth)-imgBoxHeight)/2)-cutimgHeight>=0.5) {
					cutTop = cutimgHeight+1;
				} else {
					cutTop = cutimgHeight;
				}
				cutBottm = ((imgHeight*imgBoxWidth/imgWidth)-cutimgHeight);
				obj.style.clip = 'rect ('+cutTop+'px '+imgBoxWidth+'px '+cutBottm+'px 0px)';
				obj.style.top = Number(yPos)-cutTop;
			} else if (Number(imgWidth*imgBoxHeight/imgHeight)>=(imgBoxWidth)) {
				obj.style.height = imgBoxHeight;
				obj.style.width = imgWidth*imgBoxHeight/imgHeight;
				cutimgWidth = Math.floor(((imgWidth*imgBoxHeight/imgHeight)-imgBoxWidth)/2);
				cutLeft = ((imgWidth*imgBoxHeight/imgHeight)-cutimgWidth);
				if ((((imgWidth*imgBoxHeight/imgHeight)-imgBoxWidth)/2)-cutimgWidth>=0.5) {
					cutRight = cutimgWidth+1;
				} else {
					cutRight = cutimgWidth;
				}
				obj.style.clip = 'rect (0px '+cutLeft+'px '+imgBoxHeight+'px '+cutRight+'px)';
				obj.style.left = Number(xPos)-cutRight;
			}	

			document.images[key].src = '' + imgCode +'';
			box.style.backgroundColor = '#FFFFFF';
			obj.style.visibility='visible';
			oclick = "'/application/jpg/','"+imgCode+"','"+imgDim+"','CARICA CELLULARE DI EMERGENZA'";
			//document.viewform.viewprize.onclick = imgLink;
		} else {
			box.style.backgroundColor = '#E5E5E5';
		}
	}
}

function imgLink() {
	sel = document.getElementById('imgCtrl');
	y = sel.options(sel.selectedIndex).value.split('|');
	if (y!='') {
		imgCode = y[0];
		imgDim = y[1];
		imgDscr = y[2];
		winPopup('/application/jpg/', imgCode, imgDim, imgDscr);
	}
}
