$(document).ready(function() {

    $(".pointer").mouseover( function() {
	$(this).css("cursor", "pointer");
    });
        

    $('#amplFotoDiv').scrollFollow( {
	speed :1000,
	offset :60
    });
	
    $(".pointer").mouseover( function() {
	$(this).css("cursor", "pointer");
    });
        
//    $("#cpf").mask("999.999.999-99");
//    $("#rg").mask("9999.999");
//    $("#cep").mask("99.999-999");
//    $(".telefone").mask("(99) 9999-999");
//
//    $("input").border = "none";



});


function amplFoto(foto , legenda) {
    $("#cobreTudo").css("width", $(document).width());
    $("#cobreTudo").css("height", $(document).height());
    $("#cobreTudo").css("opacity", "0");
    $("#cobreTudo").css("display", "block");
    $("#cobreTudo").animate( {
	opacity :0.5,
	borderWidth :1
    }, 600);

    $("#amplFotoDiv").slideDown(1500);
    $("#amplFoto").html("<img src='../img-"+foto+"-600-500' alt='"+legenda+"' /> <br> <span class='ampl-legenda'>" + legenda + "</span>");
// $("#superConteudo").html(conteudoPagina);
}

function fecharFoto() {
    $("#cobreTudo").animate( {
	opacity :0,
	borderWidth :1
    }, 1000, function() {
	$("#cobreTudo").hide();
    });

    $("#amplFotoDiv").slideUp(1000);

}



function validarInscricao() {
    campos = new Array("nome" , "email" , "telefone" , "endereco" , "numero" , "bairro"
	, "cidade" , "cpf" , "rg");
    if(validarFormulario(campos)) {

	if(!validarEmail(document.getElementById("email"))) {
	    document.getElementById("email").style.border = "1px solid #C75F4E";
	    document.getElementById("email").focus();
	    alert("Email Inválido");
	    return false;
	}

	return true;
    } else {
	return false;
    }
}
function validarTrabalhos() {
    campos = new Array("nome" , "email" , "fax" , "profissao" , "crm" , "especialidade" , "cpf");
    if(validarFormulario(campos)) {

	if(!validarEmail(document.getElementById("email"))) {
	    document.getElementById("email").style.border = "1px solid #C75F4E";
	    document.getElementById("email").focus();
	    alert("Email Inválido");
	    return false;
	}

	return true;
    } else {
	return false;
    }
}


function carregarFoto(foto) {
    $("#"+amplFoto).html("<< ");
}


function getURL(href) {
    document.location.href= href;
}

function getUrl(href) {
    getURL(href);
}

function hide(element) {
    $(element.id).hide("slow");
}




function limparSelect(selectId) {
    $("#" + selectId).html("");
}

function addListValue(inputComValor, targetSelect) {
    var valor = $("#" + inputComValor).attr("value");
    $("#" + targetSelect).append(
	"<option value='" + valor + "' selected='selected'>" + valor
	+ "</option>");
    $("#" + inputComValor).attr("value", "");
}

function carregarCidades(estado) {

    $("#cidade").attr("disabled", "disabled");
    $("#cidade").html(
	"<option style='color: silver'>Carregando as cidades....</option>");

    $.post("carregar_cidades.ajax.php", {
	estado :estado
    }, function(data) {
	var valores = data.split(",");
	$("#cidade").html("");
	$("#cidade").attr("disabled", "");

	$("#cidade").append(
	    "<option value=''>..:: Selecione uma Cidade ::..</option>");

	for (i = 0; i < valores.length; ++i) {

	    nome = valores[i];
	    i++;
	    id = valores[i];

	    $("#cidade").append(
		"<option value='" + id + "'>" + nome + "</option>");
	}
    ;

    });
}


function carregarCategorias(departamentoId , valorInicialArray) {
    $("#categoriaDeProduto").attr("disabled", "disabled");
    $("#categoriaDeProduto").html(
	"<option style='color: silver'>Carregando categorias....</option>");

    $.post("carregar_categorias.ajax.php", {
	departamento : departamentoId
    }, function(data) {
	var valores = data.split(",");
	$("#categoriaDeProduto").html("");
	$("#categoriaDeProduto").attr("disabled", "");

	$("#categoriaDeProduto").append(
	    "<option value='"+valorInicialArray[0]+"'>"+valorInicialArray[1]+"</option>");

	for (i = 0; i < valores.length; ++i) {

	    nome = valores[i];
	    i++;
	    id = valores[i];

	    $("#categoriaDeProduto").append(
		"<option value='" + id + "'>" + nome + "</option>");
	}
    ;

    });
}





function validarContato() {
    var retorno = false;
    retorno =  validarFormulario( new Array('nome' , 'email' , 'mensagem'));
    return retorno;
}


function  validarFormulario (campo) { //campo tem as IDs dos campos obrigatorios
    tamanho =  campo.length;
    var camp = campo;

    for(i=0;i<camp.length ; i++) {
	if(document.getElementById(camp[i]).value=='' || document.getElementById(camp[i]).value==null) {
	    window.alert("Preencha o campo "+ camp[i].toUpperCase() );
	    document.getElementById(camp[i]).style.border = "1px solid #C75F4E";
	    document.getElementById(camp[i]).focus();

	    return false;
	}
    }

    return true;
}


function validarEmail(mail){
    var er = new RegExp(/^[A-Za-z0-9_\-\.]+@[A-Za-z0-9_\-\.]{2,}\.[A-Za-z0-9]{2,}(\.[A-Za-z0-9])?/);
    if(typeof(mail) == "string"){
	if(er.test(mail)){
	    return true;
	}
    }else if(typeof(mail) == "object"){
	if(er.test(mail.value)){
	    return true;
	}
    }else{
	return false;
    }
}





