function addFav(){
    var url      = "http://www.padaria2000.com.br/";
    var title    = "PADARIA 2000";
    if (window.sidebar) window.sidebar.addPanel(title, url,"");
    else if(window.opera && window.print){
        var mbm = document.createElement('a');
        mbm.setAttribute('rel','sidebar');
        mbm.setAttribute('href',url);
        mbm.setAttribute('title',title);
        mbm.click();
    }
    else if(document.all){window.external.AddFavorite(url, title);}
}

function Divs2(ObjBlock,ObjNone){

	window.document.getElementById(ObjBlock).style.display		= "block";
	window.document.getElementById(ObjNone).style.display		= "none";

	window.document.getElementById('DIV_'+ObjBlock).className	= "div_aberta";
	window.document.getElementById('DIV_'+ObjNone).className	= "div_fechada";

}


function limpa(f){
	f.value = '';
}

function Colorir(objParam){
	
	objParam.style.backgroundColor = '#FFFFCC';
	return false;	
}


/* FUNCTION VALIDA BRANCO */
function ValidaBranco(objParam){

	if(objParam.value == ''){
		return false;
	}
	else{
		return true;
	}

}

/* FUNCTION VALIDA NÚMERO */
function ValidaNum(objParam){

	if(!ValidaBranco(objParam)){
		return false;
	}
	else if(isNaN(objParam.value)){
		return false;
	}
	else{
		return true;
	}

}

/* FUNCTION VALIDA INPUT TYPE="RADIO" */
function ValidaRadio(objParam){

	total = objParam.length - 1;
//	alert('O número de radios é ' + total);

	for(x=0; x<=total; x++){

		if(objParam(x).checked){
			return true;
			break;
		}

	 }

	 if(x > total){
		return false;
	 }

}

/* FUNCTION VALIDA INPUT TYPE="CHECKBOX" */
function ValidaCheck(objParam){

	total = objParam.length - 1;
//	alert('O número de checkbox é '	+ total);
	
	var i = 0;
	var cont = 0;

	while (i <= total){
		
		if(objParam[i].checked==true){
			cont=1;
		}

	i++;
	}

	if (cont == 0){
		return false;
	}
	else{
		return true;
	}

}

/* FUNCTION VALIDA CPF */
function valida_CPF(s){

	var i;
	s 		= limpa_string(s);
	var c 	= s.substr(0,9);
	var dv 	= s.substr(9,2);
	var d1 	= 0;

	for (i 	= 0; i < 9; i++){
		d1 += c.charAt(i)*(10-i);
	}

	if (d1 == 0) 
		return false;
	d1 = 11 - (d1 % 11);
	if (d1 > 9) d1 = 0;

	if (dv.charAt(0) != d1){
		return false;
	}

	d1 *= 2;
	for (i = 0; i < 9; i++){
		d1 += c.charAt(i)*(11-i);
	}

	d1 = 11 - (d1 % 11);
	if (d1 > 9) d1 = 0;
	
	if (dv.charAt(1) != d1){
		return false;
	}

	return true;

}

function limpa_string(S){
	// Deixa so' os digitos no numero
	var Digitos = "0123456789";
	var temp = "";
	var digito = "";

	for (var i=0; i<S.length; i++)	{
		digito = S.charAt(i);
		if (Digitos.indexOf(digito)>=0)	{
			temp=temp+digito	}
	} //for

	return temp
}

/* FUNCTION VALIDA E-MAIL */
function ValidaEmail(objParam){

	var invalid, s;
	invalid = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,4})+$/;

	var s;

	if(!ValidaBranco(objParam)){
		return false;
	}
	else if (invalid.test(objParam.value) == false){
		return false;
	}
	else{
		return true;
	}

}

/* FUNCTION VALIDA E-MAIL */

function validaCNPJ(objParam) {
	
	CNPJ = document.frmDDl.cnpj.value;
	erro = new String;

	if (CNPJ == "00.000.000/0000-00") erro += "É necessarios preencher corretamente o numero do CNPJ! \n\n";
	
	if (CNPJ.length < 18) erro += "É necessarios preencher corretamente o numero do CNPJ! \n\n";
	
		if ((CNPJ.charAt(2) != ".") || (CNPJ.charAt(6) != ".") || (CNPJ.charAt(10) != "/") || (CNPJ.charAt(15) != "-")){
			
			if (erro.length == 0) erro += "É necessarios preencher corretamente o numero do CNPJ! \n\n";
		}
		
		//substituir os caracteres que nao sao numeros
		if(document.layers && parseInt(navigator.appVersion) == 4){
			x = CNPJ.substring(0,2);
			x += CNPJ.substring(3,6);
			x += CNPJ.substring(7,10);
			x += CNPJ.substring(11,15);
			x += CNPJ.substring(16,18);
			CNPJ = x;	
		} else {
			CNPJ = CNPJ.replace(".","");
			CNPJ = CNPJ.replace(".","");
			CNPJ = CNPJ.replace("-","");
			CNPJ = CNPJ.replace("/","");
		}
		var nonNumbers = /\D/;
		
		if (nonNumbers.test(CNPJ)) erro += "A verificacao de CNPJ suporta apenas numeros! \n\n";	
		
		var a = [];
		var b = new Number;
		var c = [6,5,4,3,2,9,8,7,6,5,4,3,2];
		
		for (i=0; i<12; i++){
			a[i] = CNPJ.charAt(i);
			b += a[i] * c[i+1];
		}
		
		if ((x = b % 11) < 2) { a[12] = 0 } else { a[12] = 11-x }
		
		b = 0;
		
		for (y=0; y<13; y++) {
			b += (a[y] * c[y]); 
		}
		
		if ((x = b % 11) < 2) { a[13] = 0; } else { a[13] = 11-x; }
		
		if ((CNPJ.charAt(12) != a[12]) || (CNPJ.charAt(13) != a[13])){
			erro +="Digito verificador com problema! \n\n";
		}
		
		if (erro.length > 0){
			//alert(erro);
			return false;
		} else {
			//alert("CNPJ valido!");
		}
		return true;
	}

	function janela(url,nome,atributos)
	{
		window.open(url,nome,atributos);
	}

/* FUNCTION NEWSLETTER */
function CadNews(f){

	var Email = f.newsletter.value;

	if(!ValidaEmail(f.newsletter)){
		alert("Informe o E-mail por favor.");
		f.newsletter.style.backgroundColor = '#FFFFCC'
		f.newsletter.focus();
		return false;
	}
	else{
		window.open("inc.newsletter_cadastro.php?email=" + Email, "CadEmail", "width=300, height=220");
		f.newsletter.value = '';
		return false;
	}

	return false;

}

function AbreDiv(ObjParam){

	document.getElementById(ObjParam).style.display = 'block';
	
}

function FechaDiv(ObjParam){

	document.getElementById(ObjParam).style.display = 'none';

}

function Divs(ObjBlock,ObjNone){

	window.document.getElementById(ObjBlock).style.display		= "block";
	window.document.getElementById(ObjNone).style.display		= "none";

	window.document.getElementById('TD_'+ObjBlock).className	= "box_aberto";
	window.document.getElementById('TD_'+ObjNone).className		= "box_fechado";

}

function changeFontSize() {
	var c = document.getElementById('conteudo');
	if(c.style.fontSize == '' || c.style.fontSize == 'small') {
		c.style.fontSize = 'medium';
		createCookie('fontSizeCursoImasters','medium',30);
	} else if(c.style.fontSize == 'medium') {
		c.style.fontSize = 'large';
		createCookie('fontSizeCursoImasters','large',30);
	} else if(c.style.fontSize == 'large') {
		c.style.fontSize = 'x-small';
		createCookie('fontSizeCursoImasters','x-small',30);
	} else {
		c.style.fontSize = 'small';
		createCookie('fontSizeCursoImasters','small',30);
	}
}

function verifyFontSize() {
	var cookie = readCookie('fontSizeCursoImasters')
	
	if(cookie) {
		document.getElementById('conteudo').style.fontSize = cookie;
	}
}