d = document;

try{xmlhttp=new XMLHttpRequest();}catch(ee){try{xmlhttp=new ActiveXObject("Msxml2.XMLHTTP");}catch(e){try{xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");}catch(E){xmlhttp=false;}}}

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_validateForm() { //v4.0
  var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
  for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=MM_findObj(args[i]);
    if (val) { nm=val.name; if ((val=val.value)!="") {
      if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
        if (p<1 || p==(val.length-1)) errors+='- '+nm+' deve ser preenchido corretamente.\n';
      } else if (test!='R') { num = parseFloat(val);
        if (isNaN(val)) errors+='- '+nm+' deve conter somente nmeros.\n';
        if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
          min=test.substring(8,p); max=test.substring(p+1);
          if (num<min || max<num) errors+='- '+nm+' deve conter nmeros entre '+min+' e '+max+'.\n';
    } } } else if (test.charAt(0) == 'R') errors += '- '+nm+'  obrigatrio.\n'; }
  } if (errors) alert('OPS! Ocorreram erros:\n\n'+errors);
  document.MM_returnValue = (errors == '');
}


function poeData(){
	var mydate=new Date()
	var year=mydate.getYear()
	if (year < 1000)
	year+=1900
	var day=mydate.getDay()
	var month=mydate.getMonth()
	var daym=mydate.getDate()
	if (daym<10)
	daym="0"+daym
	var dayarray=new Array("Domingo","Segunda-feira","Ter&ccedil;a-feira","Quarta-feira","Quinta-feira","Sexta-feira","S&aacute;bado")
	var montharray=new
	Array("01","02","03","04","05","06","07","08","09","10","11","12")
	document.write(""+dayarray[day]+", "+daym+"/"+montharray[month]+"/"+year+"")
}

function verFoto(novafoto,destino){
	document.getElementById(destino).src = novafoto;		
	}
	
function Centralizar(largura,altura){
	window.moveTo((window.screen.width/2)-(largura/2),(window.screen.height/2)-(altura/2))
	} 

function corLinha(objeto,novacor){
	objeto.style.backgroundColor = novacor
	objeto.style.cursor = 'hand'
	}
	
function verCarro(idCarro){
	window.open('/comercial/carro.asp?id='+idCarro,'carroDetalhes','top='+((window.screen.height/2)-(450/2))+',left='+((window.screen.width/2)-(720/2))+',width=720px,height=450px,scrollbars=yes')
	}
	
function editarCarro(idCarro){
	window.open('/comercial/adm/carro.asp?id='+idCarro,'carroEdicao','top='+((window.screen.height/2)-(340/2))+',left='+((window.screen.width/2)-(720/2))+',width=720px,height=340px,scrollbars=yes')
	}
function deletarCarro(idCarro){
	if (confirm("Tem certeza que deseja deletar o carro " + idCarro +" ?")) {
	window.open('/comercial/adm/actions.asp?action=delete&id='+idCarro,'carroDeletar','top='+((window.screen.height/2)-(340/2))+',left='+((window.screen.width/2)-(720/2))+',width=720px,height=340px,scrollbars=yes')
		}
	}

function passaLista(objeto){
	window.alert('foi trocado o '+objeto)
	}
	
function atualizaLista(keep,pegarCampo,fromCampo,filtroCampo,valorEnviado,antigo,proximoValor,proximoNome){
 if(valorEnviado.value==""){
	return;
 }else{
	 if(keep=="sim"){
	xmlhttp.open("GET", "/comercial/includes/cboBoxes.asp?select="+pegarCampo+"&from="+fromCampo+"&where="+filtroCampo+"&valor="+valorEnviado.value+"&antigo="+antigo+"&proximovalor="+proximoValor+"&proximoNome="+proximoNome,true);
	xmlhttp.onreadystatechange=function(){
		if(xmlhttp.readyState==4){
			d.getElementById(antigo+"Ajax").innerHTML = xmlhttp.responseText;
			//document.write(xmlhttp.responseText)
		}
	}
	xmlhttp.send(null)
	 }
 }
}

function atualizaSubLista(keep,pegarCampo,fromCampo,filtroCampo,valorEnviado,antigo,proximoValor,proximoNome){
 if(valorEnviado.value==""){
	return;
 }else{
	 if(keep=="sim"){
	xmlhttp.open("GET", "/comercial/includes/cboBoxes1.asp?select="+pegarCampo+"&from="+fromCampo+"&where="+filtroCampo+"&valor="+valorEnviado.value+"&antigo="+antigo+"&proximovalor="+proximoValor+"&proximoNome="+proximoNome,true);
	xmlhttp.onreadystatechange=function(){
		if(xmlhttp.readyState==4){
			d.getElementById(antigo+"Ajax").innerHTML = xmlhttp.responseText;
			//document.write(xmlhttp.responseText)
		}
	}
	xmlhttp.send(null)
	 }
 }
}

function buscaSend(value1,value2,value3){
	var1 = document.getElementById(value1).value;
	var2 = document.getElementById(value2).value;
	var3 = document.getElementById(value3).value;
		
	if(var1==""){
		alert('Escolha uma marca!');
		return;	
		}else{
			if(var2==""){
			alert('Escolha um modelo!');
			return;	
			}else{
				if(var3==""){
				alert('Escolha um ano!');
				return;	
				}else{
					document.getElementById("BuscaDeCarros").submit();
			}
		}
	}
}