var pag = location.href;



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_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 PopUp(url,jan,w,h) {



	newWindow = window.open(url, jan, 'width='+w+',height='+h+',left=0,top=0,toolbar=0,location=0,directories=0,status=1,menuBar=0,scrollBars=1,resizable=0' ); newWindow.focus();



}



function MM_jumpMenu(targ,selObj,restore){ //v3.0

  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");

  if (restore) selObj.selectedIndex=0;

}



function MM_jumpMenuGo(selName,targ,restore){ //v3.0

  var selObj = MM_findObj(selName); if (selObj) MM_jumpMenu(targ,selObj,restore);

}





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_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 currencyFormat(fld, milSep, decSep, e) {

var sep = 0;

var key = '';

var i = j = 0;

var len = len2 = 0;

var strCheck = '0123456789';

var aux = aux2 = '';

var whichCode = (window.Event) ? e.which : e.keyCode;

if (whichCode == 13) return true;  // Enter

key = String.fromCharCode(whichCode);  // Get key value from key code

if (strCheck.indexOf(key) == -1) return false;  // Not a valid key

len = fld.value.length;

for(i = 0; i < len; i++)

if ((fld.value.charAt(i) != '0') && (fld.value.charAt(i) != decSep)) break;

aux = '';

for(; i < len; i++)

if (strCheck.indexOf(fld.value.charAt(i))!=-1) aux += fld.value.charAt(i);

aux += key;

len = aux.length;

if (len == 0) fld.value = '';

if (len == 1) fld.value = '0'+ decSep + '0' + aux;

if (len == 2) fld.value = '0'+ decSep + aux;

if (len > 2) {

aux2 = '';

for (j = 0, i = len - 3; i >= 0; i--) {

if (j == 3) {

aux2 += milSep;

j = 0;

}

aux2 += aux.charAt(i);

j++;

}

fld.value = '';

len2 = aux2.length;

for (i = len2 - 1; i >= 0; i--)

fld.value += aux2.charAt(i);

fld.value += decSep + aux.substr(len - 2, len);

}

return false;

}



function Carrinho(id) {

	f = document.forms.shop;

	g = document.forms['qt'].elements['qtde[]'];

	h = document.forms['qt'].elements['produto_codigo_preco_id[]'];

	l = g.length;

	//alert(l);

	if(l != undefined) {

		for(i=0;i<l;i++) {



			if(g[i].value != '' || g[i].value != 0) {

				document.forms['shop'].elements['qtde[]'][i].value = g[i].value;

				document.forms['shop'].elements['produto_codigo_preco_id[]'][i].value = h[i].value;

			}

		}

	} else {

		//alert(g[0].value);

		document.forms['shop'].elements['qtde[]'].value = g.value;

		document.forms['shop'].elements['produto_codigo_preco_id[]'].value = h.value;

	}

	f.sku.value = id;

	f.action.value = 'add';

	f.submit();

}



function Indique(pagina) {

	ajanela = window.open('/enviar_amigo/'+pagina,'email_amigo','status=yes,width=550,height=350,left=0,top=0');

	}



function Favoritos(id) {

	ajanela = window.open('grava_favoritos.php?id='+id,'favoritos','status=no,width=100,height=100,left=0,top=0');

	}



function EsqueceuSenha() {

	ajanela = window.open('/esqueceu_senha','favoritos','status=yes,width=400,height=180,left=0,top=0');

	}



function Comentarios(tema,gid) {

	w = screen.width - 100;

	PopUp('/comentarios/'+tema,'comentarios',w,250);

}



function RemoveComentarios(id) {

	if(confirm('Tem certeza que deseja excluir este comentário?')) {

		ajanela = window.open('remove_comentarios.php?id='+id,'rcomentarios','status=no,width=100,height=100,left=0,top=0');

	}

}



 /* Generate a random string. */

function RandomString()

{

var alphaNum = "abcdefghijklmnopqrstuwxyz0123456789";

var strLen = 8;

var randomStr = "";

for ( count = 0; count < strLen; count++ )

randomStr += alphaNum.charAt( parseInt( alphaNum.length * Math.random() ) );

return randomStr;

}





function Moeda(num) {

num = num.toString().replace(/\$|\,/g,'');

if(isNaN(num))

num = "0";

sign = (num == (num = Math.abs(num)));

num = Math.floor(num*100+0.50000000001);

cents = num%100;

num = Math.floor(num/100).toString();

if(cents<10)

cents = "0" + cents;

for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)

num = num.substring(0,num.length-(4*i+3))+'.'+

num.substring(num.length-(4*i+3));

return (((sign)?'':'-') + 'R$ ' + num + ',' + cents);

}



function RemoveItem(id) {

	if(confirm('Tem certeza que deseja remover este item de seu carrinho?')) {

		f = document.forms.shop;

		f.sku.value = id;

		f.action.value = 'remove';

		f.submit();

	}

}

function EditaItem(id,qtde) {

	var qt = window.prompt("Informe a nova quantidade:",qtde);
	alert(qt);

	if(qt != null) {

		f = document.forms.shop;

		f.sku.value = id;

		//document.forms['shop'].elements['qtde[]'][0].value = qt;

		f.qtde.value = qt;

		f.action.value = 'edita';

		f.submit();

	}

}

function Preview(img) {

	var im = new Image;

	im.src = img;

	w = im.width + 30;

	h = im.height + 30;

	newWindow = window.open('/site/img.php?img='+img, 'preview', 'width='+w+',height='+h+',left=0,top=0,toolbar=0,location=0,directories=0,status=0,menuBar=0,scrollBars=0,resizable=0' );

	newWindow.focus();

	//newWindow.close();



	//newWindow.onblur = newWindow.close();

	/*

	if(x != 'undefined') {

		newWindow.close();

	}*/

}



function AbreFrete() {

PopUp('/frete', 'cep',250,100);

}



function Frete(f) {



	f = parseFloat(f);

	//alert(f);

	if(f == 'NaN' || f == 0) {

		document.write('<form method="post" action="/frete" target="iframe_frete" name="frm_calc_frete"><input type="text" class="botaoinsc" size="9" name="cep"><input type="submit" class="formpeq" value="Calcular Frete"> </form>');

	} else {

		document.write(Moeda(f));

	}

}



function ConfirmaRemover(categoria_id) {



	if(confirm('Tem certeza que você deseja excluir esta categoria? \r\nVocê somente poderá excluí-la se não houver nenhum produto associado a ela. Deseja prosseguir?')) {

		location.href='categoria.php?excluir=1&categoria_id=' + categoria_id;



	}

}



function AbreBoleto(no_pedido) {



 PopUp('/abrir_boleto/'+no_pedido,'boleto',700,480);



}

