function getStyleClass (className) {

	for (var s = 0; s < document.styleSheets.length; s++)
	{
		if(document.styleSheets[s].rules)
		{
			for (var r = 0; r < document.styleSheets[s].rules.length; r++)
			{
				if (document.styleSheets[s].rules[r].selectorText.toUpperCase() == className.toUpperCase())
				{
					return document.styleSheets[s].rules[r];
				}
			}
		}
		else if(document.styleSheets[s].cssRules)
		{
			for (var r = 0; r < document.styleSheets[s].cssRules.length; r++)
			{
				if (document.styleSheets[s].cssRules[r].selectorText.toUpperCase() == className.toUpperCase())
					return document.styleSheets[s].cssRules[r];
			}
		}
	}
	
	return null;
}

function validaEmail(email) {

        var achou_ponto=false;
        var achou_arroba=false;
        var achou_caracter=false;

        if (email.length < 8)
        {
           return false;
        }	

        for (var i=0; i<email.length; i++) {
                if (email.charAt(i)=="@")
                { 
                  if (email.charAt(i+1)==".")
                  	achou_arroba=false;
                  else
                    achou_arroba=true;
                }
                else if (email.charAt(i)==".") achou_ponto=true;
                else if (email.charAt(i)!=" ") achou_caracter=true;
        }

        if((email.charAt(0)=="W" || email.charAt(0)=="w") &&
           (email.charAt(1)=="W" || email.charAt(1)=="w") &&
           (email.charAt(2)=="W" || email.charAt(2)=="w") &&
           (email.charAt(3)=="."))
        {
            achou_ponto=false;
            achou_caracter=false;
        }
        if(email.charAt(email.length-1)==".")
        {
            achou_ponto=false;
        }	
        return (achou_ponto && achou_arroba && achou_caracter);
}

function validaCPF(cpf) {

	var erro = "";

	if (cpf.length < 11) erro += "Sao necessarios 11 digitos para verificacao do CPF! "; 

	var nonNumbers = /\D/;
	if (nonNumbers.test(cpf)) erro += "Digite apenas os numeros do CPF, sem pontuação! "; 

	if (cpf == "00000000000" || cpf == "11111111111" || cpf == "22222222222" || cpf == "33333333333" || cpf == "44444444444" || cpf == "55555555555" || cpf == "66666666666" || cpf == "77777777777" || cpf == "88888888888" || cpf == "99999999999")
	{
	    erro += "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]))
	{
		erro +="Digito verificador com problema!";
	}

	if (erro.length > 0)
	{
		alert(erro);
		return false;
	}

	return true;
}


var dtCh= "/";
var minYear=1900;
var maxYear=2100;

function isInteger(s)
{
	var i;
	for (i = 0; i < s.length; i++){   

		var c = s.charAt(i);
		if (((c < "0") || (c > "9"))) return false;
	}

	return true;
}

function stripCharsInBag(s, bag)
{
	var i;
	var returnString = "";

	for (i = 0; i < s.length; i++)
	{
		var c = s.charAt(i);
		if (bag.indexOf(c) == -1) returnString += c;
	}

	return returnString;
}

function daysInFebruary (year)
{
	return (((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0))) ? 29 : 28 );
}

function DaysArray(n) {

	for (var i = 1; i <= n; i++) 
	{
		this[i] = 31;
		if (i==4 || i==6 || i==9 || i==11) { this[i] = 30; }
		if (i==2) { this[i] = 29; }
	}

	return this;
}

function isDate(dtStr){

	var daysInMonth = DaysArray(12);
	var pos1=dtStr.indexOf(dtCh);
	var pos2=dtStr.indexOf(dtCh,pos1+1);
	var strDay=dtStr.substring(0,pos1);
	var strMonth=dtStr.substring(pos1+1,pos2);
	var strYear=dtStr.substring(pos2+1);
	strYr=strYear;

	if (strDay.charAt(0)=="0" && strDay.length>1) { strDay=strDay.substring(1); }

	if (strMonth.charAt(0)=="0" && strMonth.length>1) { strMonth = strMonth.substring(1); }

	for (var i = 1; i <= 3; i++) {
		if (strYr.charAt(0)=="0" && strYr.length>1) { strYr = strYr.substring(1); }
	}

	month=parseInt(strMonth);
	day=parseInt(strDay);
	year=parseInt(strYr);

	if (pos1==-1 || pos2==-1) { return false; }

	if (strMonth.length<1 || month<1 || month>12) {	return false; }

	if (strDay.length<1 || day<1 || day>31 || (month==2 && day>daysInFebruary(year)) || day > daysInMonth[month]){ return false; }

	if (strYear.length != 4 || year==0 || year<minYear || year>maxYear) { return false; }

	if (dtStr.indexOf(dtCh,pos2+1)!=-1 || isInteger(stripCharsInBag(dtStr, dtCh))==false){ return false; }

	return true;
}

