$(document).ready(function() {
    $("#twitter").getTwitter({
        userName: "dimasrepasse",
        numTweets: 4,
        loaderText: "Carregando tweets...",
        slideIn: true,
        showHeading: true
    });
});

function modelos(valor,tp) {
  http.open("GET", "/usados/xml/modelos?id="+valor+"&tipo="+tp, true);
  http.onreadystatechange = handleHttpResponse;
  http.send(null);
}
function handleHttpResponse() {
  campo_select = document.busca.modelo;
  //campo_select = document.forms[0].bairro;
  if (http.readyState == 4) {
    campo_select.options.length = 0;
    campo_select.options[0] = new Option('Carregando...','');
    results = http.responseText.split(",");
	for( i = 0; i < results.length; i++ )
    {
      string = results[i].split( "|" );
      campo_select.options[i] = new Option( string[0], string[1] );
    }
  }
}
function getHTTPObject() {
  var xmlhttp;
  /*@cc_on
  @if (@_jscript_version >= 5)
    try {
      xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
    } catch (e) {
      try {
        xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
      } catch (e) {
        xmlhttp = false;
      }
    }
  @else
  xmlhttp = false;
  @end @*/
  if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
    try {
      xmlhttp = new XMLHttpRequest();
    } catch (e) {
      xmlhttp = false;
    }
  }
  return xmlhttp;
}
var http = getHTTPObject();


function verificarCPF(c){
	var i; 
	s = c;
	var c = s.substr(0,9); 
	var dv = s.substr(9,2); 
	var d1 = 0; 
	var v = false;
	for (i = 0; i < 9; i++) 
	{ 
		d1 += c.charAt(i)*(10-i); 
	} 
	if (d1 == 0){ 
		v = true; 
		return false;
	} 
	d1 = 11 - (d1 % 11); 
	if (d1 > 9) d1 = 0; 
	if (dv.charAt(0) != d1) 
	{
		v = true;
		return false; 
	} 
	
	d1 *= 2; 
	for (i = 0; i < 9; i++) 
	{ 
		d1 += c.charAt(i)*(11-i); 
	} 
	d1 = 11 - (d1 % 11); 
	if (d1 > 9) d1 = 0; 
	if (dv.charAt(1) != d1) 
	{ 
		v = true;
		return false; 
	} 
	if (!v) {
		return true;
	}
}

function verificarCNPJ(c) { 
	_tam = c.length;
	
    if (_tam < 14) {
		return 0;
	}
	
    _soma1 = (c[_tam-14] * 5) //18 - 14
	_soma1 += (c[_tam-13] * 4) //17 - 13
	_soma1 += (c[_tam-12] * 3) //15 - 12
	_soma1 += (c[_tam-11] * 2) //14 - 11
	_soma1 += (c[_tam-10] * 9) //13 - 10
	_soma1 += (c[_tam-9] * 8) //11 - 9
	_soma1 += (c[_tam-8] * 7) //10 - 8
	_soma1 += (c[_tam-7] * 6) //9 - 7
	_soma1 += (c[_tam-6] * 5) //7 - 6
	_soma1 += (c[_tam-5] * 4) //6 - 5
	_soma1 += (c[_tam-4] * 3) //5 - 4
	_soma1 += (c[_tam-3] * 2); //4 - 3
	
    _resto = _soma1 % 11;
	
    if(_resto < 2) {
		_digito1 = 0
	} else {
		_digito1 = 11 - _resto;
	}
	
    _soma2 = (c[_tam-14] * 6)
	_soma2 += (c[_tam-13] * 5)
	_soma2 += (c[_tam-12] * 4)
	_soma2 += (c[_tam-11] * 3)
	_soma2 += (c[_tam-10] * 2)
	_soma2 += (c[_tam-9] * 9)
	_soma2 += (c[_tam-8] * 8)
	_soma2 += (c[_tam-7] * 7)
	_soma2 += (c[_tam-6] * 6)
	_soma2 += (c[_tam-5] * 5)
	_soma2 += (c[_tam-4] * 4)
	_soma2 += (c[_tam-3] * 3)
	_soma2 += (c[_tam-2] * 2);
	
    _resto = _soma2 % 11; 
	
    _digito2 = _resto < 2 ? 0 : 11 - _resto;
	
    return ((c[_tam-2] == _digito1) && (c[_tam-1] == _digito2)); 
}