function emailValidate(str) {
	var at="@"
	var dot="."
	var lat=str.indexOf(at)
	var lstr=str.length
	var ldot=str.indexOf(dot)
	if (str.indexOf(at)==-1){
	   return false;
	}
	if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
	   return false;
	}
	if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
	    return false;
	}
	 if (str.indexOf(at,(lat+1))!=-1){
	    return false;
	 }
	 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
	    return false;
	 }
	 if (str.indexOf(dot,(lat+2))==-1){
	    return false;
	 }
	
	 if (str.indexOf(" ")!=-1){
	    return false;
	 }
	 return true;
}

function wddxGetElement(str,elementName) {
	var re = new RegExp('<'+elementName+'>([\\s\\S]*?)<\/'+elementName+'>','i');
	var arrFound = re.exec(str);
	if (arrFound && (arrFound.length>1)) return arrFound[1];
	else return "error";
}

function carregando()  {
	frasei++;
	document.getElementById("mensagemerro").innerHTML = eval("frase" + frasei);
	if(frasei<7)
		setTimeout("carregando()",1000);
}

function IsNumeric(sText)  {
	var ValidChars = "0123456789-/.";
	var IsNumber=true;
	var Char;

	for (i = 0; i < sText.length && IsNumber == true; i++)  {
		Char = sText.charAt(i); 
		if (ValidChars.indexOf(Char) == -1)  {
			IsNumber = false;
		}
	}
	return IsNumber;
}

function validaCPF(cpf) {
	valor = true;
	verro = new String;
	if (cpf.length < 11) verro += "Sao necessarios 11 digitos para verificacao do CPF! \n\n"; 
	var nonNumbers = /\D/;
	if (nonNumbers.test(cpf)) verro += "A verificacao de CPF suporta apenas numeros! \n\n";	
	if (cpf == "00000000000" || cpf == "11111111111" || cpf == "22222222222" || cpf == "33333333333" || cpf == "44444444444" || cpf == "55555555555" || cpf == "66666666666" || cpf == "77777777777" || cpf == "88888888888" || cpf == "99999999999"){
		  verro += "Numero de CPF invalido!"
	}
	var a = [];
	var b = new Number;
	var c = 11;
	for (i=0; i<11; i++){
		a[i] = cpf.charAt(i);
		if (i < 9) b += (a[i] *  --c);
	}
	if ((x = b % 11) < 2) { a[9] = 0 } else { a[9] = 11-x }
	b = 0;
	c = 11;
	for (y=0; y<10; y++) b += (a[y] *  c--); 
	if ((x = b % 11) < 2) { a[10] = 0; } else { a[10] = 11-x; }
	if ((cpf.charAt(9) != a[9]) || (cpf.charAt(10) != a[10])){
		verro +="Digito verificador com problema!";
	}
	if (erro.length > 0){
		return false;
	}
	return true;
}

function valida_cnpj(cnpj)
      {
      var numeros, digitos, soma, i, resultado, pos, tamanho, digitos_iguais;
      digitos_iguais = 1;
      if (cnpj.length < 14 && cnpj.length < 15)
            return false;
      for (i = 0; i < cnpj.length - 1; i++)
            if (cnpj.charAt(i) != cnpj.charAt(i + 1))
                  {
                  digitos_iguais = 0;
                  break;
                  }
      if (!digitos_iguais)
            {
            tamanho = cnpj.length - 2
            numeros = cnpj.substring(0,tamanho);
            digitos = cnpj.substring(tamanho);
            soma = 0;
            pos = tamanho - 7;
            for (i = tamanho; i >= 1; i--)
                  {
                  soma += numeros.charAt(tamanho - i) * pos--;
                  if (pos < 2)
                        pos = 9;
                  }
            resultado = soma % 11 < 2 ? 0 : 11 - soma % 11;
            if (resultado != digitos.charAt(0))
                  return false;
            tamanho = tamanho + 1;
            numeros = cnpj.substring(0,tamanho);
            soma = 0;
            pos = tamanho - 7;
            for (i = tamanho; i >= 1; i--)
                  {
                  soma += numeros.charAt(tamanho - i) * pos--;
                  if (pos < 2)
                        pos = 9;
                  }
            resultado = soma % 11 < 2 ? 0 : 11 - soma % 11;
            if (resultado != digitos.charAt(1))
                  return false;
            return true;
            }
      else
			return false;
}

function OnlyNumeric() {
	e = event;
	if(window.event) {
	// for IE, e.keyCode or window.event.keyCode can be used
	key = e.keyCode;
	}
	else if(e.which) {
	// netscape
	key = e.which;
	}
	if (key!=8 || key < 48 || key > 57) return (((key > 47) && (key < 58)) || (key==8));
	{
		return true;
	  }
}

function janela(url,nome,propriedades)  {
	x = propriedades.indexOf('width=');
	x = propriedades.substr(x+6,3)
	y = propriedades.indexOf('height=');
	y = propriedades.substr(y+7,3)
	x = (screen.width-parseInt(x))/2 + '';
	y = (screen.height-parseInt(y))/2 + '';
	window.open(url,nome,propriedades + ',left=' + x + ',top=' + y);
}

function getCookieVal (offset) {
  var endstr = document.cookie.indexOf (";", offset);
  if (endstr == -1)
    endstr = document.cookie.length;
  return unescape(document.cookie.substring(offset, endstr));
}

function GetCookie (name) {
  var arg = name + "=";
  var alen = arg.length;
  var clen = document.cookie.length;
  var i = 0;
  while (i < clen) {
    var j = i + alen;
    if (document.cookie.substring(i, j) == arg)
      return getCookieVal (j);
    i = document.cookie.indexOf(" ", i) + 1;
    if (i == 0) break; 
  }
  return null;
}

function SetCookie (name,value,expires,path,domain,secure) {
  document.cookie = name + "=" + escape (value) +
    ((expires) ? "; expires=" + expires.toGMTString() : "") +
    ((path) ? "; path=" + path : "") +
    ((domain) ? "; domain=" + domain : "") +
    ((secure) ? "; secure" : "");
}

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 gerarAjax()  {
	try{
		xmlhttp = new XMLHttpRequest();
	}catch(ee){
		try{
			xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
		}catch(e){
			try{
				xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
			}catch(E){
				xmlhttp = false;
			}
		}
	}
	return xmlhttp;
}

function verData(obj)  {
	var partes = obj.value.split( '/' );
	var str    = '';

	if ( ( partes[ 0 ] != null ) && ( partes[ 0 ].length == 2 ) )
		if ( parseInt( partes[ 0 ] ) > 31 ) partes[ 0 ] = '31';
	
	if ( ( partes[ 1 ] != null ) && ( partes[ 1 ].length == 2 ) )
		if ( parseInt( partes[ 1 ] ) > 12 ) partes[ 1 ] = '12';
	
	str = partes.join( '' ).substr( 0 , 5 );
	
	if ( str.length >= 2 ) str = str.substr( 0 , 2 ) + '/' + str.substr( 2 , 5 );
	if ( str.length >= 5 ) str = str.substr( 0 , 5 );
	
	obj.value = str;
}

function validaLogin(valor)  {
	valor = valor.toLowerCase();
	caract_aceitos = "abcdefghijklmnopqrstuvwxyz0123456789._";
	for(i=0;i<valor.length;i++)
		if(caract_aceitos.indexOf(valor.substr(i,1))==-1)
			return false;
	return true;
}