//______________________________________________________________________________________
function changeInc(so,inc,cod,pag,ope,psq){
	document.main.so.value=so;
	document.main.inc.value=inc;
	document.main.cod.value=cod;
	document.main.pag.value=pag;
	document.main.ope.value=ope;
	document.main.psq.value=psq;
	document.main.submit();
}

//______________________________________________________________________________________
function alignDivs(input,target){
	var hSize = 0;
	var aInput = input.split("/");

	if (target == '')
	var aTarget = aInput;
	else
	var aTarget = target.split("/");

	for (var i=0; i<aInput.length; i++){
		if (document.getElementById(aInput[i]).scrollHeight > hSize)
		hSize = document.getElementById(aInput[i]).scrollHeight;
	}
	for (var i=0; i<aTarget.length; i++)
	document.getElementById(aTarget[i]).style.height = hSize+'px';
}

//______________________________________________________________________________________
function bloqEnter(objEvent)
{
	var iKeyCode;
	iKeyCode = objEvent.keyCode;
	if(iKeyCode == 13) return false;
	return true;
}

//______________________________________________________________________________________
function abrir(URL,TITLE) {
	var imgPath = URL;
	var imgSrc = new Image();
	imgSrc.src = imgPath;
	var picWidth=imgSrc.width + 30;
	var picHeight=imgSrc.height + 30;

	window.open(URL,TITLE, 'width='+picWidth+', height='+picHeight+', scrollbars=no, status=no, toolbar=no, location=no, directories=no, menubar=no, resizable=no, fullscreen=no');
}

//______________________________________________________________________________________
function MM_CheckFlashVersion(reqVerStr,msg){
	with(navigator){
		var isIE  = (appVersion.indexOf("MSIE") != -1 && userAgent.indexOf("Opera") == -1);
		var isWin = (appVersion.toLowerCase().indexOf("win") != -1);
		if (!isIE || !isWin){
			var flashVer = -1;
			if (plugins && plugins.length > 0){
				var desc = plugins["Shockwave Flash"] ? plugins["Shockwave Flash"].description : "";
				desc = plugins["Shockwave Flash 2.0"] ? plugins["Shockwave Flash 2.0"].description : desc;
				if (desc == "") flashVer = -1;
				else{
					var descArr = desc.split(" ");
					var tempArrMajor = descArr[2].split(".");
					var verMajor = tempArrMajor[0];
					var tempArrMinor = (descArr[3] != "") ? descArr[3].split("r") : descArr[4].split("r");
					var verMinor = (tempArrMinor[1] > 0) ? tempArrMinor[1] : 0;
					flashVer =  parseFloat(verMajor + "." + verMinor);
				}
			}
			// WebTV has Flash Player 4 or lower -- too low for video
			else if (userAgent.toLowerCase().indexOf("webtv") != -1) flashVer = 4.0;

			var verArr = reqVerStr.split(",");
			var reqVer = parseFloat(verArr[0] + "." + verArr[2]);

			if (flashVer < reqVer){
				if (confirm(msg))
				window.location = "http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash";
			}
		}
	}
}

//______________________________________________________________________________________
function MM_CheckFlashVersion(reqVerStr,msg){
	with(navigator){
		var isIE  = (appVersion.indexOf("MSIE") != -1 && userAgent.indexOf("Opera") == -1);
		var isWin = (appVersion.toLowerCase().indexOf("win") != -1);
		if (!isIE || !isWin){
			var flashVer = -1;
			if (plugins && plugins.length > 0){
				var desc = plugins["Shockwave Flash"] ? plugins["Shockwave Flash"].description : "";
				desc = plugins["Shockwave Flash 2.0"] ? plugins["Shockwave Flash 2.0"].description : desc;
				if (desc == "") flashVer = -1;
				else{
					var descArr = desc.split(" ");
					var tempArrMajor = descArr[2].split(".");
					var verMajor = tempArrMajor[0];
					var tempArrMinor = (descArr[3] != "") ? descArr[3].split("r") : descArr[4].split("r");
					var verMinor = (tempArrMinor[1] > 0) ? tempArrMinor[1] : 0;
					flashVer =  parseFloat(verMajor + "." + verMinor);
				}
			}
			// WebTV has Flash Player 4 or lower -- too low for video
			else if (userAgent.toLowerCase().indexOf("webtv") != -1) flashVer = 4.0;

			var verArr = reqVerStr.split(",");
			var reqVer = parseFloat(verArr[0] + "." + verArr[2]);

			if (flashVer < reqVer){
				if (confirm(msg))
				window.location = "http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash";
			}
		}
	}
}

//______________________________________________________________________________________
function download(local, arquivo){
	window.location.href = 'down.php?local=' + local + '&arquivo=' + arquivo;
}

//______________________________________________________________________________________
function redimImagem(imgPath,imgName,imgSize){
	var imgPath = imgPath;
	var imgSrc = new Image();
	imgSrc.src = imgPath;
	var picWidth=imgSrc.width;
	var picHeight=imgSrc.height;

	try{
		if ((picWidth != imgSize) || (picHeight != imgSize)){
			if (picWidth > picHeight){
				picHeight = parseInt(imgSize*picHeight/picWidth);
				picWidth = imgSize;
			}
			else{
				picWidth = parseInt(imgSize*picWidth/picHeight);
				picHeight = imgSize;
			}
			imgName.style.width = picWidth+'px';
			imgName.style.height = picHeight+'px';
		}
	}
	catch(e){}
}

//______________________________________________________________________________________
function Resize(){
	if ((navigator.appName!="Microsoft Internet Explorer") && (screen.width >= 1024) && (screen.height >= 768)) {
		window.moveTo(0,0);
		//window.resizeTo(screen.width-225,screen.height-225);
		window.resizeTo(screen.width-1,screen.height-1);
	}
}

//______________________________________________________________________________________
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_changeProp(objName,x,theProp,theValue) { //v6.0
	var obj = MM_findObj(objName);
	if (obj && (theProp.indexOf("style.")==-1 || obj.style)){
		if (theValue == true || theValue == false)
		eval("obj."+theProp+"="+theValue);
		else eval("obj."+theProp+"='"+theValue+"'");
	}
}

//______________________________________________________________________________________
function MM_closeObj(objName) {
	try{MM_changeProp(objName,'','style.clip','rect(auto, 468, 60, auto)','DIV');}catch(e){}

}

//______________________________________________________________________________________
function MM_openObj(objName) {
	try{MM_changeProp(objName,'','style.clip','rect(auto auto auto auto)','DIV');}catch(e){}
}

//______________________________________________________________________________________
// monta camada no IE, por causa dos selects sobre os divs
function getPos(objName) {
	var IFrameName = 'div_'+objName.id;
	var IfrRef = document.getElementById(IFrameName);
	var x,w,y,h;
	var rect = objName.getBoundingClientRect();
	//x = rect.left - 2;
	x = rect.left;
	w = rect.right - rect.left;
	//y = rect.top - 2;
	y = rect.top;
	h = rect.bottom - rect.top;
	IfrRef.style.display = '';
	IfrRef.style.width = w;
	IfrRef.style.height = h;
	IfrRef.style.top = y;
	IfrRef.style.left = x;
}

//______________________________________________________________________________________
function createLayer(state){
	if (document.all && !navigator.userAgent.match(/opera/gi)){
		var objs = document.getElementsByTagName('select');
		for (i=0; i<objs.length; i++){
			if (state){createIframe(objs[i].id);getPos(objs[i]);}
			else{destroyIframe(objs[i].id);}
		}
	}
}

//______________________________________________________________________________________
function createIframe(myObj){
	var IFrameName = 'div_'+myObj;
	var objIframe=document.createElement('iframe');
	objIframe.setAttribute('id',IFrameName);
	objIframe.setAttribute('scrolling','no');
	objIframe.setAttribute('frameborder','1');
	objIframe.style.backgroundColor='##FFFFFF';
	objIframe.style.position='absolute';
	objIframe.style.top='0px';
	objIframe.style.left='0px';
	objIframe.style.display='none';
	var IFrameObj = document.body.appendChild(objIframe);
}

//______________________________________________________________________________________
function destroyIframe(myObj){
	var IFrameObj = document.getElementById('div_'+myObj);
	IFrameObj.removeNode(true);
}

//______________________________________________________________________________________
function validaBusca(theForm){
	if (!validaitem(theForm.txt_produto,'s','3','50','Palavra-chave')){return (false);}
	theForm.submit();
}

//______________________________________________________________________________________
function insereCarrinho(theForm, vQtde){
	var retorno = false;
	for (i=1;i<=vQtde;i++){if (document.getElementById('qt_'+i).value > 0){retorno = true;}}
	if (retorno == false){alert('Digite a quantidade desejada');	return (false);}
	else theForm.submit();
}

//______________________________________________________________________________________
function verifica_estoque(input,stock){
	var vQtde = eval(input.value);
	var vStok = eval(stock);

	if (vQtde > vStok){
		alert('A quantidade desejada ultrapassa o estoque');
		input.value = vStok;
	}
}

//______________________________________________________________________________________
function verifica_qtde(input,campo){
	var vChkd = input.checked;
	var vCmpo = document.getElementById(campo);
	if (vChkd == false){
		vCmpo.value = '';
	}
}

//______________________________________________________________________________________
function digita_num(evento){
	var tecla = (evento.keyCode ? evento.keyCode: evento.which ? evento.which : evento.charCode)
	if (((tecla < 48) || (tecla > 57)) && (tecla != 8)){
		evento.returnValue = false;
		return false;
	}
	return true;
}

//______________________________________________________________________________________
function show_img(cod){
	window.open('http://www.baristabrasil.com.br/so/loja/pop_img.php?LVID=19&cod='+cod,'imagem','toolbar=no,location=no,status=no,scrollbars=yes,resizable=yes,top=0,left=0,width=480,height=480');
}

//______________________________________________________________________________________
function set_cod(cod){
	codigo = cod;
}

//______________________________________________________________________________________
function Fn_Ins_LogPublicidades(publicidade, link){
	window.open('http://www.baristabrasil.com.br/front/inc/on/count_publicidade.php?pub=' + publicidade + '&lk=' + link);
}