// JavaScript Document

function limpaCampo(idCampo, msg) {
	if(document.getElementById(idCampo).value == msg) {
		document.getElementById(idCampo).value = "";
	}
}

function voltaCampo(idCampo, msg) {
	if(document.getElementById(idCampo).value == "") {
		document.getElementById(idCampo).value = msg;
	}
}

function limpaCampoMsg(idCampo, msg) {

	if(document.getElementById(idCampo).innerHTML == msg) {
		document.getElementById(idCampo).innerHTML = "";
	}
	
}

function voltaCampoMsg(idCampo, msg) {
	if(document.getElementById(idCampo).value.length == 0) {
		document.getElementById(idCampo).innerHTML = msg;
	}
}

function AreaRestrita(Username, Password) {
    if (Username.value == '' || Username.value == 'Login') {
        alert('Insira seu Login.')
        Username.focus()
        Username.value = ''
        return false;
    }
    else if ('' == Password.value || Password.value == '******') {
        alert('Insira sua Senha.')
        Password.focus()
        Password.value = ''
        return false;
    }
    else {

        document.getElementById('aspnetForm').action = "http://www.kpconsulting.com.br/aspupdown/Confirm.asp";
        document.getElementById('aspnetForm').submit();
        return true;
    }
}


function EnviarContato() {
    
    
    var emailRegex = /^([a-zA-Z0-9_.-])+@(([a-zA-Z0-9-])+.)+([a-zA-Z0-9]{2,4})+$/;
    
    if ($("#nomeContato").val() == '' || $("#nomeContato").val() == 'Seu nome') {
        alert('Insira seu Nome.');
        $("#nomeContato").focus();
        $("#nomeContato").val('');
        return false;
    }
    else if ($("#emailContato").val() == '' || $("#emailContato").val() == 'Seu e-mail') {
        alert('Insira seu Email.');
        $("#emailContato").focus();
        $("#emailContato").val('');
        return false;
    }
    else if ($("#telefoneContato").val() == '' || $("#telefoneContato").val() == 'Seu telefone') {
        alert('Insira seu telefone.');
        $("#telefoneContato").focus();
        $("#telefoneContato").val('');
        return false;
    }
    else if (!emailRegex.test($("#emailContato").val())) {
        alert("Email invalido");
        $("#emailContato").focus();
        $("#emailContato").val('');
        return false;
    }
    else if ($("#msgContato").val() == '' || $("#msgContato").val() == 'Sua mensagem') {
        alert('Insira sua Mensagem.');
        $("#msgContato").focus();
        $("#msgContato").val('');
        return false;
    }
    else {
        var data = { name: $("#nomeContato").val(), email: $("#emailContato").val(), telefone: $("#telefoneContato").val(), message: $("#msgContato").val() };
        $.post("../includes/Contato.ashx", data, function(data) {
            if (data == 'ok') {
                alert('Mensagem enviada com sucesso');
                $("#nomeContato").val('Seu nome');
                $("#emailContato").val('Seu e-mail');
                $("#telefoneContato").val('Seu telefone');
                $("#msgContato").val('');
            }
        });
    }
}

function SalvarEmail() {


    var emailRegex = /^([a-zA-Z0-9_.-])+@(([a-zA-Z0-9-])+.)+([a-zA-Z0-9]{2,4})+$/;

    if ($("#newsNome").val() == '' || $("#newsNome").val() == 'Seu nome') {
        alert('Insira seu Nome.');
        $("#newsNome").focus();
        $("#newsNome").val('');
        return false;
    }
    else if ($("#newsEmail").val() == '' || $("#newsEmail").val() == 'Seu e-mail') {
        alert('Insira seu Email.');
        $("#newsEmail").focus();
        $("#newsEmail").val('');
        return false;
    }
    else if (!emailRegex.test($("#newsEmail").val())) {
        alert("Email invalido");
        $("#newsEmail").focus();
        return false;
    }
    else {
        var data = { name: $("#newsNome").val(), email: $("#newsEmail").val() };
        $.post("../includes/Newsletter.ashx", data, function(data) {
            if (data == 'ok') {
                alert('Email cadastrado com sucesso');
                $("#newsNome").val('Seu nome');
                $("#newsEmail").val('Seu e-mail');
            }
            else
                alert(data);
        });
    }
}


$(document).ready(function() {
    $(".interna img").each(function(item) {
        if ($(this).attr("alt") != '') {
            $(this).wrap("<div class='img-content'><div />" + $(this).attr("alt") + "</div>")
            $(this).attr("style", "float:none;");
            $(this).closest(".img-content").attr("style", "float: right; margin: 5px;")
        }

    });
});

//banner home
var banner = {
    _init: function () {
        $('#slider').nivoSlider({
            effect: 'random', // Specify sets like: 'fold,fade,sliceDown'
            slices: 15, // For slice animations
            boxCols: 8, // For box animations
            boxRows: 4, // For box animations
            animSpeed: 500, // Slide transition speed
            pauseTime: 6000, // How long each slide will show
            startSlide: 0, // Set starting Slide (0 index)
            directionNav: true, // Next &amp; Prev navigation
            directionNavHide: true, // Only show on hover
            controlNav: true, // 1,2,3... navigation
            controlNavThumbs: false, // Use thumbnails for Control Nav
            controlNavThumbsFromRel: false, // Use image rel for thumbs
            controlNavThumbsSearch: '.jpg', // Replace this with...
            controlNavThumbsReplace: '_thumb.jpg', // ...this in thumb Image src
            keyboardNav: true, // Use left &amp; right arrows
            pauseOnHover: true, // Stop animation while hovering
            manualAdvance: false, // Force manual transitions
            captionOpacity: 0.8, // Universal caption opacity
            prevText: '<', // Prev directionNav text
            nextText: '>', // Next directionNav text
            beforeChange: function () { }, // Triggers before a slide transition
            afterChange: function () { }, // Triggers after a slide transition
            slideshowEnd: function () { }, // Triggers after all slides have been shown
            lastSlide: function () { }, // Triggers when last slide is shown
            afterLoad: function () { } // Triggers when slider has loaded
        });

    }
}

