function setMsgDefault(data)
{
	var divMessage = getElementById('divMessage');
	divMessage.innerHTML = '<strong>' + data + '</strong>';
}

function validateLogin(login)
{
		var proibitedChars = "\n =-!@#$%¨&*()_+?:><,.;/\\|\"";
		var cont=0;
		 
			  
    	if(login.length < 3 || login.length > 20) {
			return 72;		
		}
		
		for (cont = 0 ; cont <  proibitedChars.length ; cont++)
		{
			if(login.indexOf(proibitedChars.charAt(cont))!=-1)
			{
				return 73;
			}
		}
		return -1;
}


function passwordValidate(senha)
{
		var proibitedChars = "\n =-!@#$%¨&*()_+?:><,.;/\\|\"";
		var cont=0;
		
    	if(senha.length < 4 || senha.length > 20) {
			return 72;		
		}
		
		for (cont = 0 ; cont <  proibitedChars.length ; cont++)
		{
			if(senha.indexOf(proibitedChars.charAt(cont))!=-1)
			{
				return 73;
			}
		}
		return -1;
}
    

function hideElement(elementID)
{
	//alert(elementID);
	var element = getElement(elementID); 
	//alert(element);
	element.style.visibility= 'hidden';
}


function showElement(elementID)
{
	var element = getElement(elementID); 
	element.style.visibility= 'visible';
}

function sendError(text)
{
	var divMessage = getElement('divMessage');
	divMessage.innerHTML = text;
	Effect.Appear('divMessage');
	Effect.Pulsate('divMessage', {duration: 3});
	Effect.Fade('divMessage', {delay: 6});
}

function isEmail(campo) 
{ 
	  return (campo.indexOf(".") > 2) && (campo.indexOf("@") > 0);
}

function isIE(){
	return (navigator.appName == 'Microsoft Internet Explorer');
}


function isOpera(){
	return (navigator.appName == 'Opera');
}

function trim(str)
{
  		return str.replace(/^\s*|\s*$/g,"");
}
			
/*Em JavaScript, uma expresso regular  delimitada por uma barra / inicial 
e outra final. Cada expresso de validao sempre comea com ^ (incio de linha) 
e termina com $ (fim de linha), para garantir que abrange o contedo inteiro do 
texto (parmetro) a ser validado.
Existe uma seqncia de expresso regular que significa um dgito (0 a 9): \d.
Adicionando um + aps essa seqncia, significa "uma ou mais ocorrncias da seqncia precedente". 
Isto , um ou mais dgitos. Note que isso implica o preenchimento obrigatrio; 
 melhor que o caso do campo no preenchido (vazio) seja tratado  parte. 
 Assim, temos a expresso regular completa para validar um nmero apenas composto por dgitos:
*/
function isInteger(pVal)
{
	var valN = pVal;
	if(pVal.indexOf("-")!=-1)
	{
		valN = pVal.substring(1);
	}
	var reTipo = /^\d+$/;
	return reTipo.test(valN);
}


/*
 Padawan's JavaScript-Mega-Validator 3000+
 Todos os direitos reservados para Diego Pires Plentz
 Voc pode usar esse cdigo nas suas pginas desde que mantenha os crditos ;-)
 */
 function isDate(data,ano,mes,dia, opcional)
 {
	//Se o parmetro obrigatrio for igual  zero, significa que elepode estar vazio, caso contrrio, no
	if(dia+mes+ano != "")
	{
		//Verifica o ms
		if (!isInteger(mes) || mes > 12 || mes < 1)
		{
			if(isInteger(mes)  && opcional==1 && mes==0)
			{
				ano=0;
				dia=0;
				return true;
			}
			
			alert("Formato do mes invalido.");
			data.focus();
			return false
		}
		
		//converte para numero
		mes=parseInt(mes);
		
							
		//Verifica o dia
		if (!isInteger(dia) || dia > 31 || dia < 1)
		{
			if(isInteger(dia)  && opcional==1 && dia==0)
			{
				ano=0;
				mes=0;
				return true;
			}
			alert("Formato do dia nao valido.");
			data.focus();
			return false
		}
		
		//converte para numero
		dia=parseInt(dia);
		
		if (mes == 4 || mes == 6 || mes == 9 || mes == 11)
		{
			if (dia == 31)
			{
				alert("O mes informado nao possui 31 dias.");
				data.focus();
				return false
			}
		}
		if (mes == 2)
		{
			bissexto = ano % 4;
			if (bissexto == 0)
			{
				if (dia > 29)
				{
					alert("O mes informado possui somente 29 dias.");
					data.focus();
					return false
				}
			}
			else
			{
				if (dia > 28)
				{
					alert("O mes informado possui somente 28 dias.");
					data.focus();
					return false
				}
			}
		}

		//Verifica o ano
		if (!isInteger(ano))
		{
			alert("Formato do ano no  invalido.");
			data.focus();
			return false
		}
		else if(ano==0 && opcional==1)
		{
				dia=0;
				mes=0;
				return true;
		}
	}
	
	return true;
 }
 

 function showMessage(msg)
 {
	var element = getElement('msgBox'); 
	element.innerHTML = "<input align='right' id='button' type='button' value='X' onclick='closeMessage()'/><BR/><BR/>"+msg +"<BR/>";
	centeralize('msgBox',200,200);
	element.style.visibility= 'visible';
 }
 
 function closeMessage()
 {
	hideElement('msgBox');
 }


function hideElement(elementID)
{
	//alert(elementID);
	var element = getElement(elementID); 
	//alert(element);
	element.style.visibility= 'hidden';
}


function showElement(elementID)
{
	var element = getElement(elementID); 
	element.style.visibility= 'visible';
}

function centeralize(elementID,diffW,diffH)
{
	var div = getElement(elementID);
	var nw = (screen.width /2 ) - diffW;
	var nh = (screen.height /2) - diffH;
	div.style.left = nw+ "px";
	div.style.top = nh + "px";
}


function getElement(id)
{
	if(window.document.getElementById)
	{
		// test the most common method first.  Most browsers won't get past this test
		return window.document.getElementById(id);
	}else if(window.document.all){         // test older versions of IE
		return window.document.all[id];
	}else if(window.document.layers){      // test older versions of Netscape
		return window.document.layers[id];
	}else{                          // not sure what to do...return null
		return null;
	}
}

function getElementById(elementID)
{
	return getElement(elementID);
}

function replaceAll(string, token, newtoken) 
{
	return string.split(token).join(newtoken);
}
 