var corBorda = "FFFFFF";
var corCamiseta = "FFFFFF";

function findPosX(obj)
  {
    var curleft = 0;
    if(obj.offsetParent)
        while(1) 
        {
          curleft += obj.offsetLeft;
          if(!obj.offsetParent)
            break;
          obj = obj.offsetParent;
        }
    else if(obj.x)
        curleft += obj.x;
    return curleft;
  }

  function findPosY(obj)
  {
    var curtop = 0;
    if(obj.offsetParent)
        while(1)
        {
          curtop += obj.offsetTop;
          if(!obj.offsetParent)
            break;
          obj = obj.offsetParent;
        }
    else if(obj.y)
        curtop += obj.y;
    return curtop;
  }


function trocaCor(id, cor){
	if(id == "camiseta"){
		   var Html = '<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" width="300" height="200" id="camisa" align="middle">';
		Html = Html + '<param name="allowScriptAccess" value="sameDomain" />';
		Html = Html + '<param name="movie" value="swfs/camisa_frente.swf?camisetaCor='+cor+'&bordaCor='+corBorda+'&textoCoracao=&textoCentro=" />';
		Html = Html + '<param name="quality" value="high" />';
		Html = Html + '<embed src="swfs/camisa_frente.swf?camisetaCor='+cor+'&bordaCor='+corBorda+'&textoCoracao=&textoCentro=" quality="high" bgcolor="#ffffff" width="300" height="200" name="camisa" align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />';
		Html = Html + '</object>';
		corCamiseta = cor;
	}else{
		   var Html = '<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" width="300" height="200" id="camisa" align="middle">';
		Html = Html + '<param name="allowScriptAccess" value="sameDomain" />';
		Html = Html + '<param name="movie" value="swfs/camisa_frente.swf?camisetaCor='+corCamiseta+'&bordaCor='+cor+'&textoCoracao=&textoCentro=" />';
		Html = Html + '<param name="quality" value="high" />';
		Html = Html + '<embed src="swfs/camisa_frente.swf?camisetaCor='+corCamiseta+'&bordaCor='+cor+'&textoCoracao=&textoCentro=" quality="high" bgcolor="#ffffff" width="300" height="200" name="camisa" align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />';
		Html = Html + '</object>';
		corBorda = cor;
	}
	eval('document.getElementById(\'cor'+id+'\').value = \''+cor+'\'');
	document.getElementById("camiseta").innerHTML = Html;
	document.getElementById("paletacores_"+id).style.display = "none";
	document.getElementById("corSel"+id).style.backgroundColor = "#"+cor;
}

function MostraPaleta(id, tipo, idPaleta){
	html = '<div id="paletacores_'+tipo+'" style="position:absolute; left:'+(findPosX(id)-140)+'px; top:'+(findPosY(id))+'px; width:31px; height:41px; z-index:1">';
	html = html +  '  <table width="262" height="15" border="0" cellpadding="1" cellspacing="1" bgcolor="#000000">';
	html = html +  '    <tr>';
	html = html +  '      <td style="background-color:#303F2C; cursor:pointer" onclick="trocaCor(\''+tipo+'\', \'303F2C\');">&nbsp;</td>';
	html = html +  '      <td style="background-color:#37CCE4; cursor:pointer" onclick="trocaCor(\''+tipo+'\', \'37CCE4\');">&nbsp;</td>';
	html = html +  '      <td style="background-color:#3AC0A8; cursor:pointer" onclick="trocaCor(\''+tipo+'\', \'3AC0A8\');">&nbsp;</td>';
	html = html +  '      <td style="background-color:#000000; cursor:pointer" onclick="trocaCor(\''+tipo+'\', \'000000\');">&nbsp;</td>';
	html = html +  '      <td style="background-color:#3D538F; cursor:pointer" onclick="trocaCor(\''+tipo+'\', \'3D538F\');">&nbsp;</td>';
	html = html +  '      <td style="background-color:#3F4045; cursor:pointer" onclick="trocaCor(\''+tipo+'\', \'3F4045\');">&nbsp;</td>';
	html = html +  '      <td style="background-color:#435362; cursor:pointer" onclick="trocaCor(\''+tipo+'\', \'435362\');">&nbsp;</td>';
	html = html +  '      <td style="background-color:#44978F; cursor:pointer" onclick="trocaCor(\''+tipo+'\', \'44978F\');">&nbsp;</td>';
	html = html +  '      <td style="background-color:#4865A9; cursor:pointer" onclick="trocaCor(\''+tipo+'\', \'4865A9\');">&nbsp;</td>';
	html = html +  '      <td style="background-color:#4D9B50; cursor:pointer" onclick="trocaCor(\''+tipo+'\', \'4D9B50\');">&nbsp;</td>';
	html = html +  '    </tr>';
	html = html +  '    <tr>';
	html = html +  '      <td style="background-color:#56522C; cursor:pointer" onclick="trocaCor(\''+tipo+'\', \'56522C\');">&nbsp;</td>';
	html = html +  '      <td style="background-color:#582D65; cursor:pointer" onclick="trocaCor(\''+tipo+'\', \'582D65\');">&nbsp;</td>';
	html = html +  '      <td style="background-color:#7EC63E; cursor:pointer" onclick="trocaCor(\''+tipo+'\', \'7EC63E\');">&nbsp;</td>';
	html = html +  '      <td style="background-color:#85F6E4; cursor:pointer" onclick="trocaCor(\''+tipo+'\', \'85F6E4\');">&nbsp;</td>';
	html = html +  '      <td style="background-color:#8C9465; cursor:pointer" onclick="trocaCor(\''+tipo+'\', \'8C9465\');">&nbsp;</td>';
	html = html +  '      <td style="background-color:#8D404A; cursor:pointer" onclick="trocaCor(\''+tipo+'\', \'8D404A\');">&nbsp;</td>';
	html = html +  '      <td style="background-color:#94BBE2; cursor:pointer" onclick="trocaCor(\''+tipo+'\', \'94BBE2\');">&nbsp;</td>';
	html = html +  '      <td style="background-color:#9C8E81; cursor:pointer" onclick="trocaCor(\''+tipo+'\', \'9C8E81\');">&nbsp;</td>';
	html = html +  '      <td style="background-color:#9DB0BF; cursor:pointer" onclick="trocaCor(\''+tipo+'\', \'9DB0BF\');">&nbsp;</td>';
	html = html +  '      <td style="background-color:#B5B6A8; cursor:pointer" onclick="trocaCor(\''+tipo+'\', \'B5B6A8\');">&nbsp;</td>';
	html = html +  '    </tr>';
	html = html +  '    <tr>';
	html = html +  '     <td style="background-color:#CBEBE6; cursor:pointer" onclick="trocaCor(\''+tipo+'\', \'CBEBE6\');">&nbsp;</td>';
	html = html +  '      <td style="background-color:#CE4147; cursor:pointer" onclick="trocaCor(\''+tipo+'\', \'CE4147\');">&nbsp;</td>';
	html = html +  '      <td style="background-color:#D52F3B; cursor:pointer" onclick="trocaCor(\''+tipo+'\', \'D52F3B\');">&nbsp;</td>';
	html = html +  '      <td style="background-color:#D6D9EA; cursor:pointer" onclick="trocaCor(\''+tipo+'\', \'D6D9EA\');">&nbsp;</td>';
	html = html +  '      <td style="background-color:#DC4041; cursor:pointer" onclick="trocaCor(\''+tipo+'\', \'DC4041\');">&nbsp;</td>';
	html = html +  '      <td style="background-color:#DF4D72; cursor:pointer" onclick="trocaCor(\''+tipo+'\', \'DF4D72\');">&nbsp;</td>';
	html = html +  '      <td style="background-color:#E1CF9D; cursor:pointer" onclick="trocaCor(\''+tipo+'\', \'E1CF9D\');">&nbsp;</td>';
	html = html +  '      <td style="background-color:#E35934; cursor:pointer" onclick="trocaCor(\''+tipo+'\', \'E35934\');">&nbsp;</td>';
	html = html +  '      <td style="background-color:#E4EF62; cursor:pointer" onclick="trocaCor(\''+tipo+'\', \'E4EF62\');">&nbsp;</td>';
	html = html +  '      <td style="background-color:#FEF6C7; cursor:pointer" onclick="trocaCor(\''+tipo+'\', \'FEF6C7\');">&nbsp;</td>';
	html = html +  '    </tr>';
	html = html +  '    <tr>';
	html = html +  '      <td style="background-color:#FFBA52; cursor:pointer" onclick="trocaCor(\''+tipo+'\', \'FFBA52\');">&nbsp;</td>';
	html = html +  '      <td style="background-color:#FFE25A; cursor:pointer" onclick="trocaCor(\''+tipo+'\', \'FFE25A\');">&nbsp;</td>';
	html = html +  '      <td style="background-color:#FFE3BB; cursor:pointer" onclick="trocaCor(\''+tipo+'\', \'FFE3BB\');">&nbsp;</td>';
	html = html +  '      <td style="background-color:#FFE7F4; cursor:pointer" onclick="trocaCor(\''+tipo+'\', \'FFE7F4\');">&nbsp;</td>';
	html = html +  '      <td style="background-color:#FFFF51; cursor:pointer" onclick="trocaCor(\''+tipo+'\', \'FFFF51\');">&nbsp;</td>';
	html = html +  '      <td style="background-color:#FFFFC3; cursor:pointer" onclick="trocaCor(\''+tipo+'\', \'FFFFC3\');">&nbsp;</td>';
	html = html +  '      <td style="background-color:#FFFFF3; cursor:pointer" onclick="trocaCor(\''+tipo+'\', \'FFFFF3\');">&nbsp;</td>';
	html = html +  '      <td style="background-color:#FFFFFF; cursor:pointer" onclick="trocaCor(\''+tipo+'\', \'FFFFFF\');">&nbsp;</td>';
	html = html +  '      <td style="background-color:#CBE0F5; cursor:pointer" onclick="trocaCor(\''+tipo+'\', \'CBE0F5\');">&nbsp;</td>';
	html = html +  '      <td style="background-color:#C3BCA0; cursor:pointer" onclick="trocaCor(\''+tipo+'\', \'C3BCA0\');">&nbsp;</td>';
	html = html +  '    </tr>';
	html = html +  '  </table>';
	html = html +  '</div>';
	document.getElementById(idPaleta).innerHTML = html;
}

function add(){
	var html = "";
	var n 	 = parseInt(document.getElementById("n").value);
	if(n != 9){
		n = n + 1;
		for(var i = 0; i < n; i++){
			html = html + '<table width="488" border="0" cellpadding="0" cellspacing="0">';
			html = html + '         <tr>';
			html = html + '           <td align="center" nowrap="nowrap">  Quantidade: </td>';
			html = html + '           <td nowrap="nowrap"><input name="quantidade[]" type="text" id="quantidade[]" onkeyup="return Num(this);"  size="1" maxlength="2" value="1"></td>';
			html = html + '           <td align="center" nowrap="nowrap">  Modelo: </td>';
			html = html + '           <td nowrap="nowrap"><select name="modelo[]" id="modelo[]">';
			html = html + '               <option value="basico_masc" selected>Camiseta Básica (Masculina)</option>';
			html = html + '               <option value="baby_look">Baby Look (Feminina)</option>';
			html = html + '               <option value="regata_masc">Regata (Masculina)</option>';
			html = html + '               <option value="inf">Camiseta Infantil</option>';
			html = html + '               <option value="regata_fem">Regata (Feminina)</option>';
			html = html + '           </select></td>';
			html = html + '           <td align="center" nowrap="nowrap">  Tamanho: </td>';
			html = html + '           <td nowrap="nowrap"><select name="tamanho[]" id="tamanho[]">';
			html = html + '             <option value="p" selected>P</option>';
			html = html + '             <option value="m">M</option>';
			html = html + '             <option value="g">G</option>';
			html = html + '             <option value="gg">GG</option>';
			html = html + '           </select></td>';
			html = html + '           </tr>';
			html = html + '</table>';
		}	
			document.getElementById("n").value = n;
			document.getElementById("qm").innerHTML = html;
		}
	if(n == 9){
		document.getElementById("bt_add").disabled = true;
	}else{
		document.getElementById("bt_add").disabled = false;
		document.getElementById("bt_del").disabled = false;
	}
}

function del(){

	var html  = "";
	var n 	  = parseInt(document.getElementById("n").value);
	var ativo = 0;
		n = (n - 1);
		for(var i = 0; i < n; i++){
				html = html + '<table width="488" border="0" cellpadding="0" cellspacing="0">';
				html = html + '         <tr>';
				html = html + '           <td align="center" nowrap="nowrap">  Quantidade: </td>';
				html = html + '           <td nowrap="nowrap"><input name="quantidade[]" type="text" id="quantidade[]" onkeyup="return Num(this);" size="1" maxlength="2" value="1"></td>';
				html = html + '           <td align="center" nowrap="nowrap">  Modelo: </td>';
				html = html + '           <td nowrap="nowrap"><select name="modelo[]" id="modelo[]">';
				html = html + '               <option value="basico_masc" selected>Camiseta Básica (Masculina)</option>';
				html = html + '               <option value="baby_look">Baby Look (Feminina)</option>';
				html = html + '               <option value="regata_masc">Regata (Masculina)</option>';
				html = html + '               <option value="inf">Camiseta Infantil</option>';
				html = html + '               <option value="regata_fem">Regata (Feminina)</option>';
				html = html + '           </select></td>';
				html = html + '           <td align="center" nowrap="nowrap">  Tamanho: </td>';
				html = html + '           <td nowrap="nowrap"><select name="tamanho[]" id="tamanho[]">';
				html = html + '             <option value="p" selected>P</option>';
				html = html + '             <option value="m">M</option>';
				html = html + '             <option value="g">G</option>';
				html = html + '             <option value="gg">GG</option>';
				html = html + '           </select></td>';
				html = html + '           </tr>';
				html = html + '</table>';				
				ativo = 1;
		}
		if(ativo){
			document.getElementById("n").value 		= n;
			document.getElementById("qm").innerHTML = html;
		}
	if(n == 1){
		document.getElementById("bt_del").disabled = true;
	}else{
		document.getElementById("bt_del").disabled = false;
		document.getElementById("bt_add").disabled = false;
	}
}

function Num(v){  
	 v.value = v.value.replace(/\D/g,"");
	 if(v.value == ""){
	 	v.value = 1;
	 }
}

function validarEstampa(){
	var f = document.estampas;
	if(f.frente_sem.checked == true && f.verso_sem.checked == true){
		alert("Selecione ao menos uma estampa");
	}else{
		if(f.frente_sem.checked == true && f.verso_sem.checked != true){
			f.action = "?p=monta_camiseta_4";
		}else if(f.frente_sem.checked != true && f.verso_sem.checked == true){
			f.action = "?p=monta_camiseta_3";
		}else{
			f.action = "?p=monta_camiseta_3";
		}
		f.submit();
	}
}

function habilitaVer(){
	document.getElementById("ver").disabled = false;
}

function  mostraImporta(mod, text){
	if(mod == "txt"){
		if(text == ""){
			var html = '<textarea name="importar" id="importar" cols="40" rows="5" onclick="habilitaVer()"></textarea>';
		}else{
			var html = '<textarea name="importar" id="importar" cols="40" rows="5" onclick="habilitaVer()">'+text+'</textarea>';
		}
		document.getElementById("tipo").value = "texto";
	}else if(mod == "img"){
		if(text == ""){
			var html = '<input name="importar" id="importar" type="file" onchange="habilitaVer()">';
		}else{
			var html = 'Imagem já enviada ! <input name="imagem" type="hidden" value="'+text+'"> <a href="#" onclick="campoImportar();return false">Alterar</a>';
		}
		document.getElementById("tipo").value = "imagem";
	}
	document.getElementById('conteudo_importa').innerHTML = html;
}
function campoImportar(){
	document.getElementById('conteudo_importa').innerHTML = '<input name="importar" id="importar" type="file" onchange="habilitaVer()">';
	document.getElementById("tipo").value = "imagem";
}
function validarImportaVer(){
	var campo = document.getElementById("importar");
	var mod   = document.getElementById("tipo").value;
	var ativo = 1;
	var acao  = document.getElementById("proximo").value;
	
	if(mod == "imagem"){
		if(campo){
			if(campo.value == ""){
				alert("Selecione a imagem que queria colocar em sua camiseta");
				campo.focus();
				ativo = 0;
			}else{
				ativo = 1;
			}
		}else{
			ativo = 1;
		}
	}else if(mod == "texto"){
		if(campo){
			if(campo.value == ""){
				alert("Digite o texto você quer por na sua camiseta");
				campo.focus();
				ativo = 0;
			}else{
				ativo = 1;
			}
		}else{
			ativo = 1;
		}
	}
	
	if(ativo){
		document.importaf.submit();
	}
}
function validarImportaEnvia(){
	var campo = document.getElementById("importar");
	var mod   = document.getElementById("tipo").value;
	var ativo = 1;
	var acao  = document.getElementById("proximo").value;
	
	if(mod == "imagem"){
		if(campo){
			if(campo.value == ""){
				alert("Selecione a imagem que queria colocar em sua camiseta");
				campo.focus();
				ativo = 0;
			}else{
				ativo = 1;
			}
		}else{
			ativo = 1;
		}
	}else if(mod == "texto"){
		if(campo){
			if(campo.value == ""){
				alert("Digite o texto você quer por na sua camiseta");
				campo.focus();
				ativo = 0;
			}else{
				ativo = 1;
			}
		}else{
			ativo = 1;
		}
	}
	
	if(ativo){
		if(acao == "editar_costas"){
			document.importaf.action = "?p=monta_camiseta_4";
		}else{
			document.importaf.action = "?p=monta_camiseta_5";
		}
		document.importaf.submit();
	}
}
///////////////////////////// VERSO /////////////////////////////////////////////

function validarImportaVer2(){
	var campo = document.getElementById("importar");
	var mod   = document.getElementById("tipo").value;
	var ativo = 1;
	var acao  = document.getElementById("proximo").value;
	
	if(mod == "imagem"){
		if(campo){
			if(campo.value == ""){
				alert("Selecione a imagem que queria colocar em sua camiseta");
				campo.focus();
				ativo = 0;
			}else{
				ativo = 1;
			}
		}else{
			ativo = 1;
		}
	}else if(mod == "texto"){
		if(campo){
			if(campo.value == ""){
				alert("Digite o texto você quer por na sua camiseta");
				campo.focus();
				ativo = 0;
			}else{
				ativo = 1;
			}
		}else{
			ativo = 1;
		}
	}
	
	if(ativo){
		document.importaf.submit();
	}
}
function validarImportaEnvia2(){
	var campo = document.getElementById("importar");
	var mod   = document.getElementById("tipo").value;
	var ativo = 1;
	var acao  = document.getElementById("proximo").value;
	
	if(mod == "imagem"){
		if(campo){
			if(campo.value == ""){
				alert("Selecione a imagem que queria colocar em sua camiseta");
				campo.focus();
				ativo = 0;
			}else{
				ativo = 1;
			}
		}else{
			ativo = 1;
		}
	}else if(mod == "texto"){
		if(campo){
			if(campo.value == ""){
				alert("Digite o texto você quer por na sua camiseta");
				campo.focus();
				ativo = 0;
			}else{
				ativo = 1;
			}
		}else{
			ativo = 1;
		}
	}
	
	if(ativo){
		document.importaf.action = "?p=monta_camiseta_5";
		document.importaf.submit();
	}
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

window.onload = function(){
	MM_preloadImages('imagens/Menu/Menu_r2_c1_f2.jpg','imagens/Menu/Menu_r4_c1_f2.jpg','imagens/Menu/Menu_r6_c1_f2.jpg','imagens/Menu/Menu_r8_c1_f2.jpg','imagens/Menu/Menu_r10_c1_f2.jpg');
}
