function flash(movie, flashvars, width, height, retorna, swfid){
	if(!swfid)
	{
		swfid = movie.split("/");
		swfid = swfid[swfid.length-1].replace(".swf", "");
	}
	strSWF= '<object id="' + swfid + '" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" width="' + width + '" height="' + height + '">'+
			'<param name="movie" value="' + movie + '">'+
			'<param name="quality" value="high">'+
			'<param name="menu" value="false">'+
			'<param name="wmode" value="transparent">'+
			'<param name="salign" value="LT">'+
			'<param name="FlashVars" value="' + flashvars + '">'+
			'<embed name="' + swfid + '" src="' + movie + '" width="' + width + '" height="' + height + '" salign="LT" flashvars="' + flashvars + '" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" wmode="transparent"></embed>'+
			'</object>';
	if(!retorna) this.document.write(strSWF);
	else return(strSWF);
}

function MostraApaga(objeto, display){
	if(document.getElementById(objeto)) document.getElementById(objeto).style.display = display;
}
function EstadoDisplay(objeto){
	return document.getElementById(objeto).style.display;
}

function janela(url, W, H){
	jan = window.open(url, "", "width=" + W + ",height=" + H + ",left=" + ((screen.availWidth - W) / 2) + ",top=" + ((screen.availHeight - H) / 2));
	jan.focus();
}

var estados = new Array();
	estados["AC"]="Acre";
	estados["AL"]="Alagoas";
	estados["AM"]="Amazonas";
	estados["AP"]="Amapá";
	estados["BA"]="Bahia";
	estados["CE"]="Ceará";
	estados["DF"]="Distrito Federal";
	estados["ES"]="Espírito Santo";
	estados["GO"]="Goiás";
	estados["MA"]="Maranhão";
	estados["MG"]="Minas Gerais";
	estados["MT"]="Mato Grosso";
	estados["MS"]="Mato Grosso do Sul";
	estados["PA"]="Pará";
	estados["PB"]="Paraíba";
	estados["PE"]="Pernambuco";
	estados["PI"]="Piauí";
	estados["PR"]="Paraná";
	estados["RJ"]="Rio de Janeiro";
	estados["RN"]="Rio Grande do Norte";
	estados["RO"]="Rondônia";
	estados["RR"]="Roraima";
	estados["RS"]="Rio Grande do Sul";
	estados["SC"]="Santa Catarina";
	estados["SE"]="Sergipe";
	estados["SP"]="São Paulo";
	estados["TO"]="Tocantins";
	estados["GM"]="Gaspar (Matriz)";

function addEvent(obj, evType, fn, useCapture){
  if (obj.addEventListener){
    obj.addEventListener(evType, fn, useCapture);
    return true;
  } else if (obj.attachEvent){
    var r = obj.attachEvent("on"+evType, fn);
    return r;
  }
} 

function busca(oque){
	if(oque=="") alert("Por favor digite algo para poder buscar.");
	else top.location = "../home/busca.asp?busca=" + oque;
}

function cepa(qual){
	qual = "00000000" + qual;
	return qual.substr(qual.length-8);
}

function soNumeros() {

	if(document.all) tecla = event.keyCode;
	else if(document.layers) tecla = event.which;

	if(tecla == 8 || tecla == 9 || tecla == 46 || (tecla >= 48 && tecla <= 57) || (tecla >= 96 && tecla <= 105)){
		return true;
	}
	else return false;

}

function $(oque){
	return document.all? document.all[oque] : document.getElementById(oque);
}

function validaData(dia, mes, ano){
	if(parseInt(mes, 10)==2&&parseInt(dia, 10)==29) return (parseInt(ano, 10) % 4)? 0 : 1;
	else return (/^((0?[1-9]|[12]\d)\/(0?[1-9]|1[0-2])|30\/(0?[13-9]|1[0-2])|31\/(0?[13578]|1[02]))\/(19|20)?\d{2}$/.test(dia + "/" + mes + "/" + ano));
}

function validaEmail(email){
	return (/\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*/.test(email));
}

function getexpirydate(nodays){
	var UTCstring;
	Today = new Date();
	nomilli=Date.parse(Today);
	Today.setTime(nomilli+nodays*24*60*60*1000);
	UTCstring = Today.toUTCString();
	return UTCstring;
}

function setCookie(name, value, expires, path, domain, secure){
    document.cookie = name + "=" + escape(value) + "; expires=" + getexpirydate(365) + "; path=/; domain=www.bungealimentos.com.br;";
}

function getCookie(name) {
    var dc = document.cookie;
    var prefix = name + "=";
    var begin = dc.indexOf("; " + prefix);
    if (begin == -1) {
        begin = dc.indexOf(prefix);
        if (begin != 0) return null;
    } else {
        begin += 2;
    }
    var end = document.cookie.indexOf(";", begin);
    if (end == -1) {
        end = dc.length;
    }
    return unescape(dc.substring(begin + prefix.length, end));
}

function deleteCookie(name, path, domain) {
    if (getCookie(name)) {
        document.cookie = name + "=" +
            ((path) ? "; path=" + path : "") +
            ((domain) ? "; domain=" + domain : "") +
            "; expires=Thu, 01-Jan-70 00:00:01 GMT";
    }
}

function form(campo){
	return document.all? document.formulario.item(campo) : document.formulario[campo];
}

function ValorRadio(radio){
	radio = form(radio);
	tempValorRadio = false;
	for(VR_x = 0; VR_x < radio.length; VR_x++){
		if(radio[VR_x].checked){ tempValorRadio = radio[VR_x].value; break; }
	}
	return tempValorRadio;
}

function validaForm(campo, frase){

	type = form(campo).type;
	if(typeof(type)=="undefined") type = form(campo)[0].type;

	switch(type){
		case "text" :
		case "textarea" :
			if(form(campo).value!=""&&campo.substring(0,5)=="email"&&!validaEmail(form(campo).value)){
				alert("E-mail inválido!");
				form(campo).focus();
				form(campo).style.borderColor = "#ff0000";
				return;
			}
			else if(form(campo).value==""){
				if(frase) alert(frase);
				form(campo).focus();
				try { form(campo).style.borderColor = "#ff0000"; }
				catch(e){}
				return;
			}
			else {
				try { form(campo).style.borderColor = "#e8e8e8"; }
				catch(e){}
				return true;
			}
			break;
		case "select" :
		case "select-one" :
		case "select-list" :
			if(form(campo).options[form(campo).selectedIndex].value==""){
				if(frase) alert(frase);
				form(campo).focus();
				return false;
			}
			else return true;
			break;
		case "radio" :
		case "checkbox" :
			if(typeof(form(campo).length)=="undefined"){
				if(!form(campo).checked){
					if(frase) alert(frase);
					return false;
				}
				else return true;
			}
			else {
				temp = false;
				for(x = 0; x < form(campo).length; x++){
					if(form(campo)[x].checked){ temp = form(campo)[x].value; break; }
				}		
				if(!temp){
					if(frase) alert(frase);
					return false;
				}
				else return true;
			}
			break;
	}
}