function JustSoPicWindow(imageName,imageWidth,imageHeight,alt,bgcolor,hugger,hugMargin) {
// by E Michael Brandt of ValleyWebDesigns.com - Please leave these comments intact.
// version 3.0.4  

	if (bgcolor=="") {
		bgcolor="#FFFFFF";
	}
	var adj=10
	var w = screen.width;
	var h = screen.height;
	var byFactor=1;

	if(w<740){
	  var lift=0.90;
	}
	if(w>=740 & w<835){
	  var lift=0.91;
	}
	if(w>=835){
	  var lift=0.93;
	}
	if (imageWidth>w){	
	  byFactor = w / imageWidth;			
	  imageWidth = w;
	  imageHeight = imageHeight * byFactor;
	}
	if (imageHeight>h-adj){
	  byFactor = h / imageHeight;
	  imageWidth = (imageWidth * byFactor);
	  imageHeight = h; 
	}
	   
	var scrWidth = w-adj;
	var scrHeight = (h*lift)-adj;

	if (imageHeight>scrHeight){
  	  imageHeight=imageHeight*lift;
	  imageWidth=imageWidth*lift;
	}

	var posLeft=0;
	var posTop=0;

	if (hugger == "hug image"){
	  if (hugMargin == ""){
	    hugMargin = 0;
	  }
	  var scrHeightTemp = imageHeight - 0 + 2*hugMargin;
	  if (scrHeightTemp < scrHeight) {
		scrHeight = scrHeightTemp;
	  } 
	  var scrWidthTemp = imageWidth - 0 + 2*hugMargin;
	  if (scrWidthTemp < scrWidth) {
		scrWidth = scrWidthTemp;
	  }
	  
	  if (scrHeight<100){scrHeight=100;}
	  if (scrWidth<100){scrWidth=100;}

	  posTop =  ((h-(scrHeight/lift)-adj)/2);
	  posLeft = ((w-(scrWidth)-adj)/2);
 	}

	if (imageHeight > (h*lift)-adj || imageWidth > w-adj){
		imageHeight=imageHeight-adj;
		imageWidth=imageWidth-adj;
	}
	posTop = parseInt(posTop);
	posLeft = parseInt(posLeft);		
	scrWidth = parseInt(scrWidth); 
	scrHeight = parseInt(scrHeight);
	
	var agt=navigator.userAgent.toLowerCase();
	if (agt.indexOf("opera") != -1){
	  var args= new Array();
	  args[0]='parent';
	  args[1]=imageName;
	  var i ; document.MM_returnValue = false;
	  for (i=0; i<(args.length-1); i+=2) eval(args[i]+".location='"+args[i+1]+"'");
	} else {
	newWindow = window.open("vwd_justso.htm","newWindow","width="+scrWidth+",height="+scrHeight+",left="+posLeft+",top="+posTop);
	newWindow.document.open();
	newWindow.document.write('<html><title>'+alt+'</title><body leftmargin="0" topmargin="0" marginheight="0" marginwidth="0" bgcolor='+bgcolor+' onBlur="self.close()" onClick="self.close()">');  
	newWindow.document.write('<table width='+imageWidth+' border="0" cellspacing="0" cellpadding="0" align="center" height='+scrHeight+' ><tr><td>');
	newWindow.document.write('<img src="'+imageName+'" width='+imageWidth+' height='+imageHeight+' alt="Clique na janela para fechar" >'); 
	newWindow.document.write('</td></tr></table></body></html>');
	newWindow.document.close();
	newWindow.focus();
	}
}

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

function setImagem(i) {

	for(j=1;j<=3;j++) {
		objDiv = document.getElementById("foto"+j);
		if(j==i)
			objDiv.style.display='';
		else
			objDiv.style.display='none';
	}
	
}
function aviso(InCdProduto)
{
window.open("cadastroaviso.asp?cod=" + InCdProduto + "&email=" + document.registro1.email.value,"aviso","width=250,height=150,left=150,top=150")
}
function indique(InCdProduto)
{
window.open("indique_produto.asp?cod=" + InCdProduto,"aviso","width=300,height=225,left=150,top=150")
}
function setImagem(i) {
	for(j=1;j<=3;j++) {
		objDiv = document.getElementById("foto"+j);
		if(objDiv) {
			if(j==i)
				objDiv.style.display='';
			else
				objDiv.style.display='none';
		}
	}
	
}
function setImagemMulti(i,InCdProduto) {
	for(j=1;j<=3;j++) {
		objDiv = document.getElementById("foto"+j+"_"+InCdProduto);
		if(objDiv) {
			if(j==i)
				objDiv.style.display='';
			else
				objDiv.style.display='none';
		}
	}
	
}
function getDivProduto(InCdProduto,acao) {
	if(!acao) acao = 'abrir';
	objDivProduto = document.getElementById('divDetalheProduto'+InCdProduto);
	if(acao=='abrir')
		objDivProduto.style.display='';
	else
		objDivProduto.style.display='none';
}

function isInteger(evt) 
{ 
    var charCode = (evt.which) ? evt.which : window.event.keyCode; 
 
    if (charCode <= 13) 
    { 
        return true; 
    } 
    else 
    { 
        var keyChar = String.fromCharCode(charCode); 
        var re = /[0-9]/ 
        return re.test(keyChar); 
    } 
}
function updValor(InCdProduto,InQuantidade,DbValor) {
	objValor = document.getElementById('tdSubTotal'+InCdProduto);
	objValor.innerHTML = 'R$ ' + formatanumero(parseFloat(DbValor)*parseInt(InQuantidade),2).replace(".",",");
}
//formatar nš com casas decimais
function formatanumero(numero,decimais)
{
  if (isNaN(numero)) { return 0};
  if (numero=='') { return 0};
 
  var IsNegative=(parseInt(numero)<0);
  if(IsNegative)numero=-numero;

  var snum = new String(numero);
  var sec = snum.split('.');
  var whole = parseInt(sec[0]);
  var result = '';
  if(sec.length > 1){
    var dec = new String(sec[1]);
    dec = parseInt(dec)/Math.pow(10,parseInt(dec.length-decimais-1));
Math.round(dec);
dec = parseInt(dec)/10;

if(IsNegative)
{
  var x = 0-dec;
      x = Math.round(x);
  dec = - x;
}
else
{
      dec = Math.round(dec);
}

/*
  * If the number was rounded up from 9 to 10, and it was for 1 'decimal'
  * then we need to add 1 to the 'whole' and set the dec to 0.
  */
if(decimais==1 && dec==10)
{
  whole+=1;
  dec="0";
}

    dec = String(whole) + "." + String(dec);
    var dot = dec.indexOf('.');
    if(dot == -1){
      dec += '.';
      dot = dec.indexOf('.');
    }
var l=parseInt(dot)+parseInt(decimais);
    while(dec.length <= l) { dec += '0'; }
    result = dec;
  } else{
    var dot;
    var dec = new String(whole);
    dec += '.';
    dot = dec.indexOf('.');
var l=parseInt(dot)+parseInt(decimais);
    while(dec.length <= l) { dec += '0'; }
    result = dec;
  }
  if(IsNegative)result="-"+result;
  return result;
}
function FormatNumber(num,decimalNum,bolLeadingZero,bolParens,bolCommas)
/**********************************************************************
	IN:
		NUM - the number to format
		decimalNum - the number of decimal places to format the number to
		bolLeadingZero - true / false - display a leading zero for
										numbers between -1 and 1
		bolParens - true / false - use parenthesis around negative numbers
		bolCommas - put commas as number separators.
 
	RETVAL:
		The formatted number!
 **********************************************************************/
{ 
        if (isNaN(parseInt(num))) return "NaN";

	var tmpNum = num;
	var iSign = num < 0 ? -1 : 1;		// Get sign of number
	
	// Adjust number so only the specified number of numbers after
	// the decimal point are shown.
	tmpNum *= Math.pow(10,decimalNum);
	tmpNum = Math.round(Math.abs(tmpNum))
	tmpNum /= Math.pow(10,decimalNum);
	tmpNum *= iSign;					// Readjust for sign
	
	
	// Create a string object to do our formatting on
	var tmpNumStr = new String(tmpNum);

	// See if we need to strip out the leading zero or not.
	if (!bolLeadingZero && num < 1 && num > -1 && num != 0)
		if (num > 0)
			tmpNumStr = tmpNumStr.substring(1,tmpNumStr.length);
		else
			tmpNumStr = "-" + tmpNumStr.substring(2,tmpNumStr.length);
		
	// See if we need to put in the commas
	if (bolCommas && (num >= 1000 || num <= -1000)) {
		var iStart = tmpNumStr.indexOf(".");
		if (iStart < 0)
			iStart = tmpNumStr.length;

		iStart -= 3;
		while (iStart >= 1) {
			tmpNumStr = tmpNumStr.substring(0,iStart) + "," + tmpNumStr.substring(iStart,tmpNumStr.length)
			iStart -= 3;
		}		
	}

	// See if we need to use parenthesis
	if (bolParens && num < 0)
		tmpNumStr = "(" + tmpNumStr.substring(1,tmpNumStr.length) + ")";

	return tmpNumStr;		// Return our formatted string!
}

