// JavaScript Document

var persistmenu="yes"
var persisttype="sitewide"

if (document.getElementById){
document.write('<style type="text/css">\n')
document.write('.submenu{display: none;}\n')
document.write('</style>\n')
}

function SwitchMenu(obj){
	if(document.getElementById){
	var el = document.getElementById(obj);
	var ar = document.getElementById("masterdiv").getElementsByTagName("span");
		if(el.style.display != "block"){
			for (var i=0; i<ar.length; i++){
				if (ar[i].className=="submenu")
				ar[i].style.display = "none";
			}
			el.style.display = "block";
		}else{
			el.style.display = "none";
		}
	}
}

function get_cookie(Name) { 
var search = Name + "="
var returnvalue = "";
if (document.cookie.length > 0) {
offset = document.cookie.indexOf(search)
if (offset != -1) { 
offset += search.length
end = document.cookie.indexOf(";", offset);
if (end == -1) end = document.cookie.length;
returnvalue=unescape(document.cookie.substring(offset, end))
}
}
return returnvalue;
}

function onloadfunction(){
if (persistmenu=="yes"){
var cookiename=(persisttype=="sitewide")? "switchmenu" : window.location.pathname
var cookievalue=get_cookie(cookiename)
if (cookievalue!="")
document.getElementById(cookievalue).style.display="block"
}
}

function savemenustate(){
var inc=1, blockid=""
while (document.getElementById("sub"+inc)){
if (document.getElementById("sub"+inc).style.display=="block"){
blockid="sub"+inc
break
}
inc++
}
var cookiename=(persisttype=="sitewide")? "switchmenu" : window.location.pathname
var cookievalue=(persisttype=="sitewide")? blockid+";path=/" : blockid
document.cookie=cookiename+"="+cookievalue
}

if (window.addEventListener)
window.addEventListener("load", onloadfunction, false)
else if (window.attachEvent)
window.attachEvent("onload", onloadfunction)
else if (document.getElementById)
window.onload=onloadfunction

if (persistmenu=="yes" && document.getElementById)
window.onunload=savemenustate

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

function buscaEntrega(){
    var nasc = document.busca_entrega.data_nasc.value;
    var ficha = "&ficha=" + document.busca_entrega.ficha.value;

    if(document.busca_entrega.data_nasc.value == "") {window.alert("Entre com os dados corretamente!"); return;
    } else if((document.busca_entrega.data_nasc.value.length < 8) || (document.busca_entrega.data_nasc.value.length > 8)) {window.alert("Data de nascimento deve conter 8 dígitos! (Sem barras. Ex: 01021970)"); return;
    } else {
        MM_openBrWindow("entregalista.php?data_nasc="+nasc+ficha,'Entrega','menubar=yes,scrollbars=yes,width=500,height=492,top=0,left=0,screenx=0,screeny=0');
    }
}

function buscaOficina(){
    var placa = document.busca_oficina.placa;

    if(placa.value == "") {
		window.alert("Entre com a placa!"); return;
    } else if(placa.value.length < 7) {window.alert("A placa deve conter 7 Dígitos!"); return;
    } else {
        MM_openBrWindow("oficinalista.php?placa=" + placa.value,'Oficina','menubar=yes,scrollbars=yes,width=500,height=492,top=0,left=0,screenx=0,screeny=0');
    }
}

function buscaFrota(){
    var x = document.busca_frota.pedido;

    if(x.value == "") {
		window.alert("Entre com o pedido!"); return;
    } else if(x.value.length < 8) {window.alert("O pedido deve conter ao menos 8 caracteres!"); return;
    } else {
        MM_openBrWindow("frotalista.php?pedido=" + x.value,'Frotistas','menubar=yes,scrollbars=yes,width=500,height=492,top=0,left=0,screenx=0,screeny=0');
    }
}

function MM_openBrWindowToGet(x,theURL,winName,features) { //v2.0
  URL = theURL + "?ficha=" + x.ficha.value + "&data_nasc=" + x.data_nasc.value;
  window.open(URL,winName,features);
}

function abrir(URL) {

   var width = 710;
   var height = 480;

   var left = 99;
   var top = 99;

   window.open(URL,'teste1', 'width='+width+', height='+height+', top='+top+', left='+left+', scrollbars=no, status=no, toolbar=no, location=no, directories=no, menubar=no, resizable=no, fullscreen=no');

}

function abrir2(URL) {

   var width = 690;
   var height = 500;

   var left = 99;
   var top = 99;

   window.open(URL,'teste1', 'width='+width+', height='+height+', top='+top+', left='+left+', scrollbars=yes, status=no, toolbar=no, location=no, directories=no, menubar=no, resizable=yes, fullscreen=no');

}

function trocar2(ende) {
  document.busca.action = ende;
}

function trocar3(ende) {
  document.busca_estoque.action = ende;
}
