//var strX="         <--trimAll-->        "
//var strY="         <--trimLeft          "
//var strZ="         trimRight-->         "

function trimAll(x)
{
  var xLen=x.length;
  var xLenM1=xLen-1;
  for(i=0;i<xLen,x.charAt(i)==" ";i++){};
  for(n=xLenM1;n>i,x.charAt(n)==" ";n--){};
  return x.substring(i,n+1);
}

function trimLeft(x)
{
  var xLen=x.length;
  for(i=0;i<xLen,x.charAt(i)==" ";i++){};
  return x.substring(i)
}

function trimRight(x)
{
  var xLenM1=x.length-1;
  for(n=xLenM1;n>0,x.charAt(n)==" ";n--){};
  return x.substring(0,n+1);
}


function VerificaNome(tbox) 	//formato minimo: aaa aaa
{
	tbox.value = trimAll(tbox.value);

	comprimento = tbox.value.length;
	espaco = ((tbox.value).indexOf(" "));
	
	if ( (comprimento < 7) || (espaco < 3) || (espaco > (comprimento - 4)))
	{
		tbox.focus();
		return false;
	}

	return true;
}


function VerificaEMail(tbox) 	//formato minimo: a@aa.aa
{
	tbox.value = trimAll(tbox.value);

	comprimento = tbox.value.length;
	arroba = ((tbox.value).indexOf("@"));
	espaco = ((tbox.value).indexOf(" "));
	ponto = (tbox.value).lastIndexOf(".");	//index de traz prá frente
	
	if ((espaco != -1) || (comprimento < 7) || (arroba == -1) || (ponto < arroba +3) || (ponto > comprimento - 3))
	{
		tbox.focus();
		return false;
	}

	return true;
}

function VerificaTelefone(tbox) 	//formato minimo: XXXXXXXXX
{
	tbox.value = trimAll(tbox.value);

	comprimento = tbox.value.length;
	espaco = ((tbox.value).indexOf(" "));
	

	var validchars = "+0123456789";
	
	for (var i=0; i < comprimento; i++) 
	{
		if (validchars.indexOf(tbox.value.charAt(i)) != -1)
      			continue;
   	
		comprimento = 0;
  	}


	if ( (comprimento < 9) || (espaco != -1))
	{
		tbox.focus();
		return false;
	}

	return true;
}

function GetBrowserVersion()
{
	str = "AppVersion=" + navigator.appVersion + "; UserAgent=" + navigator.userAgent;
	return str;
}