//-----------------------------------------------------------------------------------------------------------------------
// Removes all whitespace characters from s.
// Global variable whitespace (see above)
// defines which characters are considered whitespace.

var whitespace = " \t\n\r";

function stripWhitespace (s)

{   return stripCharsInBag (s, whitespace)
}

//-----------------------------------------------------------------------------------------------------------------------
function isEmail (s)
{   if (isEmpty(s)) 
       if (isEmail.arguments.length == 1) return defaultEmptyOK;
       else return (isEmail.arguments[1] == true);
   
    // is s whitespace?
    if (isWhitespace(s)) return false;
    
    // there must be >= 1 character before @, so we
    // start looking at character position 1 
    // (i.e. second character)
    var i = 1;
    var slength = s.length;

    // look for @
    while ((i < slength) && (s.charAt(i) != "@"))
    { i++
    }

    if ((i >= slength) || (s.charAt(i) != "@")) return false;
    else i += 2;

    // look for .
    while ((i < slength) && (s.charAt(i) != "."))
    { i++
    }

    // there must be at least one character after the .
    if ((i >= slength - 1) || (s.charAt(i) != ".")) return false;
    else return true;
}

//-----------------------------------------------------------------------------------------------------------------------
function isWhitespace (s)

{   var i;

    // Is s empty?
    if (isEmpty(s)) return true;

    // Search through string's characters one by one
    // until we find a non-whitespace character.
    // When we do, return false; if we don't, return true.

    for (i = 0; i < s.length; i++)
    {   
        // Check that current character isn't whitespace.
        var c = s.charAt(i);

        if (whitespace.indexOf(c) == -1) return false;
    }

    // All characters are whitespace.
    return true;
}

//-----------------------------------------------------------------------------------------------------------------------
function stripCharsInBag (s, bag)

{   var i;
    var returnString = "";

    // Search through string's characters one by one.
    // If character is not in bag, append to returnString.

    for (i = 0; i < s.length; i++)
    {   
        // Check that current character isn't whitespace.
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }

    return returnString;
}

//-----------------------------------------------------------------------------------------------------------------------

// isDigit (c) Check whether character c is a digit

function isDigit (c)
{   return ((c >= "0") && (c <= "9"))
}

//-----------------------------------------------------------------------------------------------------------------------

function isEmpty(s)
{   return ((s == null) || (s.length == 0))
}

//-----------------------------------------------------------------------------------------------------------------------

// isInteger (s [,eok]) True if all characters in string s are numbers.

function isInteger (s)

{   var i;

    if (isEmpty(s)) 
       if (isInteger.arguments.length == 1) return defaultEmptyOK;
       else return (isInteger.arguments[1] == true);

    // Search through string's characters one by one
    // until we find a non-numeric character.
    // When we do, return false; if we don't, return true.

    for (i = 0; i < s.length; i++)
    {   
        // Check that current character is number.
        var c = s.charAt(i);

        if (!isDigit(c)) return false;
    }

    // All characters are numbers.
    return true;
}

//-----------------------------------------------------------------------------------------------------------------------

function verifica_tel(obj_campo, quant)
{
	for(array=0; array < quant; array++)
	{
		var int_total = obj_campo[array].value.length;
		if(int_total!=0)
		{
			if (int_total>=8)
			{
				if(!isInteger(obj_campo[array].value))
				{
					for (i=0, j=1; i < int_total; i++, j++)
					{
						caracter = obj_campo[array].value.substring(i,j);
						if (int_total==8)
						{
							if(i!=3)
							{
								if (!isInteger(caracter))
								{
									alert('O número de telefone informado está incorreto. Favor corrigir !');
									obj_campo[array].focus();
									obj_campo[array].select();
									return
								}	
							}
							else
							{
								if(caracter!="-")
								{
									alert('O caracter separador deve ser representado por - hífen. Favor corrigir !');
									obj_campo[array].focus();
									obj_campo[array].select();
									return
								}
							}
						}			
						if (int_total==9)
						{
							if(i!=4)
							{
								if (!isInteger(caracter))
								{
									alert('O número de telefone informado está incorreto. Favor corrigir !');
									obj_campo[array].focus();
									obj_campo[array].select();
									return
								}	
							}
							else
							{
								if(caracter!="-")
								{
									alert('O caracter separador deve ser representado por - hífen. Favor corrigir !');
									obj_campo[array].focus();
									obj_campo[array].select();
									return
								}	
							}	
						}
					}
				}
			}
			else
			{
				alert('O telefone informado está incorreto. Favor corrigir!');
				obj_campo[array].focus();
				obj_campo[array].select();
				return
			}		
		}
	}
	return true
}

VerifiqueTAB=true;
function Mostra(quem, tammax) {
	if ( (quem.value.length == tammax) && (VerifiqueTAB) ) {
		var i=0,j=0, indice=-1;
		for (i=0; i<document.forms.length; i++) {
			for (j=0; j<document.forms[i].elements.length; j++) {
				if (document.forms[i].elements[j].name == quem.name) {
					indice=i;
					break;
				}
			}
			if (indice != -1)
		         break;
		}
		for (i=0; i<=document.forms[indice].elements.length; i++) {
			if (document.forms[indice].elements[i].name == quem.name) {
				while ( (document.forms[indice].elements[(i+1)].type == "hidden") &&
						(i < document.forms[indice].elements.length) ) {
							i++;
				}
				document.forms[indice].elements[(i+1)].focus();
				VerifiqueTAB=false;
				break;
			}
		}
	}
}

function PararTAB(quem) 
{ 
   VerifiqueTAB=false; 
} 

function ChecarTAB() 
{ 
   VerifiqueTAB=true; 
} 

//----------------------------------------------------------------------------------------------------------------------

function checkLength(form,name,charLimit){
        var count = countChars(form,name);
        var rc = true;
        if( count > charLimit ){
                alert("Sua mensagem possui "+count+" e excede "+charLimit+" caracteres.  \nRevise sua mensagem.");
                left_vb(form,name,charLimit);
                rc = false;               
        }
        return rc;
}

function countChars(form,name){
        if( blegal ){
				var count = form.item(name).value.length;
                return count;
        } else {
                return 0;
        }
}

//----------------------------------------------------------------------------------------------------------------------

bname = navigator.appName;
bver = parseInt(navigator.appVersion);
blegal = ((bname == "Netscape" && bver >= 3) || (bname == "Microsoft Internet Explorer" && bver >= 4));

//----------------------------------------------------------------------------------------------------------------------

