
function openBrWindow(theURL,winName,features) { 
  window.open(theURL,winName,features);
}

function closeBrWindow() { 
  window.close();;
}


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_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];}
}

function changeDiv(the_div,the_change) {
	if ((document.getElementById) || (document.all)) {
		var the_style = getStyleObject(the_div);
		if (the_style != false) {
			the_style.display = the_change;
		}
	}
}

function changeDiv2(the_div) {
	if ((document.getElementById) || (document.all)) {
		var the_style = getStyleObject(the_div);
		if (the_style != false) {
		    if (the_style.display=="block"){
			    the_style.display = "none";
			}else{
			    the_style.display = "block";
			}
			
		}
	}
}

function changeDiv3(the_div) {
   Effect.toggle(the_div,'slide');
}




function getStyleObject(objectId) {
	if (document.getElementById && document.getElementById(objectId)) {
		return document.getElementById(objectId).style;
	} else if (document.all && document.all(objectId)) {
		return document.all(objectId).style;
	} else {
		return false;
	}
}

function limpacobranca() {

	document.forms['Form1'].TextboxCobrancaNome.value='';
	document.forms['Form1'].TextboxCobrancaEndereco.value='';
	//document.forms['Form1'].TextboxCobrancaNumero.value='';
	document.forms['Form1'].TextboxCobrancaComplemento.value='';
	document.forms['Form1'].TextboxCobrancaDDD.value='';
	document.forms['Form1'].TextboxCobrancaTelefone.value='';
	document.forms['Form1'].TextboxCobrancaCidade.value='';
	document.forms['Form1'].TextboxCobrancaBairro.value='';
	document.forms['Form1'].TextboxCobrancaCep.value='';
}
function preenchecobranca() {

	document.forms['Form1'].TextboxCobrancaNome.value='não preenchido';
	document.forms['Form1'].TextboxCobrancaEndereco.value='não preenchido';
	//document.forms['Form1'].TextboxCobrancaNumero.value='não preenchido';
	document.forms['Form1'].TextboxCobrancaComplemento.value='não preenchido';
	document.forms['Form1'].TextboxCobrancaDDD.value='não preenchido';
	document.forms['Form1'].TextboxCobrancaTelefone.value='não preenchido';
	document.forms['Form1'].TextboxCobrancaCidade.value='não preenchido';
	document.forms['Form1'].TextboxCobrancaBairro.value='não preenchido';
	document.forms['Form1'].TextboxCobrancaCep.value='não preenchido';
}


function mudaimagem(id) {
	document['ImageProduto'].src='images/products/camisetas/' + id + '_tam3.jpg';
	
}

function DefaultButton(e, buttonid){ 
	var bt = document.getElementById(buttonid); 
	if (typeof bt == 'object'){ 
		if(navigator.appName.indexOf('Netscape')>(-1)){ 
			if (e.keyCode == 13){ 
				bt.click(); 
				return false; 
			} 
		} 
		if (navigator.appName.indexOf('Microsoft Internet Explorer')>(-1)){ 
			if (event.keyCode == 13){ 
				bt.click(); 
				return false; 
			} 
		} 
	} 
} 

function pedecep(){
	var doc = document.forms[0];
	if (doc.TextBoxCep1 != undefined) {
		if (doc.TextBoxCep1.value == '' || doc.TextBoxCep2.value == ''){
			alert("Por favor, preencha o cep de destino");
			return false;
		}
	}
}

function submitItau(){
	document.itaushopline.submit();
}

function VerificaCPF(source, arguments) { 

      var cpf, numeros, digitos, soma, i, resultado, digitos_iguais; 
      //cpf = arguments.Value;
      cpf = arguments;
     
      digitos_iguais = 1; 
      
      cpf = cpf.replace(/\D/g, '');            

      if (cpf.length < 11) {
        arguments.IsValid = false;
        return;    // valid ccn

      }
      
      if (cpf.length ==0) {
        arguments.IsValid = false;
        return;    // valid ccn

      }

      for (i = 0; i < cpf.length - 1; i++) {
            if (cpf.charAt(i) != cpf.charAt(i + 1)){ 
                  digitos_iguais = 0; 
                  break; 
            } 
		}
      if (!digitos_iguais) { 
            numeros = cpf.substring(0,9); 
            digitos = cpf.substring(9); 
            soma = 0; 
            for (i = 10; i > 1; i--) 
                  soma += numeros.charAt(10 - i) * i; 
            resultado = soma % 11 < 2 ? 0 : 11 - soma % 11; 
            if (resultado != digitos.charAt(0)){ 
		        arguments.IsValid = false;
				return;    // valid ccn

            }
            numeros = cpf.substring(0,10); 
            soma = 0; 
            for (i = 11; i > 1; i--){ 
                  soma += numeros.charAt(11 - i) * i; 
            }
            resultado = soma % 11 < 2 ? 0 : 11 - soma % 11; 
            if (resultado != digitos.charAt(1)){ 
                 arguments.IsValid = false;
			     return;    // valid ccn

            }
            arguments.IsValid = true;
	        return;    // valid ccn

      }else{ 
            arguments.IsValid = false;
			return;    // valid ccn
      }

} 


function ChecaTab(VemDe, IrPara, tammax) {

	if (VemDe.value.length == tammax)  {
		document.getElementById(IrPara).focus();
	}
}


function ismaxlength(obj, mlength){
	//var mlength=obj.getAttribute? parseInt(obj.getAttribute("maxlength")) : ""
	if (obj.getAttribute && obj.value.length>mlength)
	obj.value=obj.value.substring(0,mlength)
}

function showvisa(){
	//frames['mpg_popup'].location.href='paymentvisa2.aspx';
}



function AddFavoritoAjax(user_id)	{

	
	MM_swapImage('imgFav1','','images/favorito_adding.gif',1);
	camiseteria.profile.AddFavorito(user_id, AddFavoritoAjax_CallBack)
	}		

function AddFavoritoAjax_CallBack(response)
{
    if (response.value > 0){
		//document.getElementById('div1Fav').innerHTML = '<a href="javascript:void(0);" onclick="RemFavoritoAjax(' + response.value + ')"><img src="images/favorito_added.gif" width="130" height="32" id="imgFav1" border="0"></a></div>';
		changeInnerHTML('div1Fav', '<a href="javascript:void(0);" onclick="RemFavoritoAjax(' + response.value + ')"><img src="images/favorito_added.gif" width="130" height="32" id="imgFav1" border="0"></a></div>');
    }else{
		if (response.value == -1){
			MM_swapImage('imgFav1','','images/favorito_add.gif',1);
			alert('Ops! Você não pode adicionar mais do que 1000 favoritos.');
			}
		else{

			MM_swapImage('imgFav1','','images/favorito_add.gif',1);
			alert('Ops! Ocorreu um erro.');
		}
    }
}

function RemFavoritoAjax(user_id)	{

	MM_swapImage('imgFav1','','images/favorito_removing.gif',1);
	camiseteria.profile.RemFavorito(user_id, RemFavoritoAjax_CallBack);
}		
			
function RemFavoritoAjax_CallBack(response)
{
    if (response.value!=0){
    changeInnerHTML('div1Fav', '<a href="javascript:void(0);" onclick="AddFavoritoAjax(' + response.value + ')"><img src="images/favorito_add.gif" width="130" height="32" id="imgFav1" border="0"></a></div>');
//		document.getElementById('div1Fav').innerHTML = '<a href="javascript:void(0);" onclick="AddFavoritoAjax(' + response.value + ')"><img src="images/favorito_add.gif" width="130" height="32" id="imgFav1" border="0"></a></div>';
    }else{
		MM_swapImage('imgFav1','','images/favorito_added.gif',1);
		alert('Ops! Ocoreru um erro.');
    }
}

function changeInnerHTML(divId,html){
 if (document.getElementById) {
       document.getElementById(divId).innerHTML= html;
 }else{
     document.layers[divId].document.open();
     document.layers[divId].document.write(html);
     document.layers[divId].document.close();
 }
}

function MostraMsgBoleto(show){
 if (show==1) {
	changeDiv('PanelMsgBoleto','block');
 }else{
    changeDiv('PanelMsgBoleto','none');
 }
}

function overlay( img ) {
	//alert(img)
	document['imagemoverlay'].src = img;
	el = document.getElementById("overlay");
	el.style.visibility = (el.style.visibility == "visible") ? "hidden" : "visible";
}

function ShowHideReplyComent(obj, coment_id){
    //changeDiv3('divcomentario'+coment_id);
    Effect.toggle('divcomentario' + coment_id,'slide');
    
    if (obj.innerHTML=='Responder') {
    
        obj.innerHTML='Cancelar';
    }else{
    
        obj.innerHTML='Responder';
    }
}

function TrocaFoto(id, pid, caminho, vflagalbum) {
    
    flagalbum = vflagalbum;

    var i;

    for (i = 1; i <= qtdfotos; i++) {
        if (id == i) {
            MM_swapImage('nav'+i, '', 'images/nav_fotos_on.gif', 1);
        } else {
            MM_swapImage('nav'+i, '', 'images/nav_fotos_off.gif', 1);
        }
        
    }

 
    Effect.Fade('divAlbum', 0.2);
    
    setTimeout("eval('TrocaFoto2(" + id + ", " + pid + ", \"" + caminho + "\")')", 1000);

    
    }
    
function TrocaFoto2(id, pid, caminho){
    MM_swapImage('album', '', 'images/products/' + caminho + '/album/foto_' + pid + '_' + id + '.jpg', 1)
    //alert('images/products/' + caminho + '/album/foto_' + pid + '_' + id + '.jpg');

      Effect.Appear('divAlbum', 0.2);
}

function AutoTrocaFoto(qtd, pid, caminho){

    if (flagalbum){
        if (idfoto == qtd) {
            idfoto = 1;    
        }
        else {
            idfoto = idfoto +1;
        }
        
        TrocaFoto(idfoto, pid, caminho, true);
       setTimeout("eval('AutoTrocaFoto(" + qtd + ", " + pid + ", \"" + caminho + "\")')", 5000); 
        
    }
}
