/**
* Arquivo com scripts 
*
* Feito para painel de controle
* @link http://www.
*
* @author Thiago Marini <marinithiago@gmail.com>
* @version 3.0
* @package 
*/
$(document).ready(function(){
    // mascara de telefone
    $(".phone").mask("(99) 9999-9999");
    $(".cep").mask("99999-999");
	
	// Calendario
    $("#data").datepicker({
        //showButtonPanel: true,
        changeMonth: true,
        changeYear: true,
        //showOn: 'button',
        showOn: 'both',
        //buttonImage: 'imagens/calendar.gif',
        buttonImageOnly: true
    });
    $("#data").css({
        'margin-right':'3px',
        'width':'56px'
    });//espaço entre o input e a buttonImage
});
//////////////////////////////
// CHANGE ANY URL PARAMETER
// troca qualquer parametro e acrescenta se não tiver
function caup(key, value, page) {
	var wlh = page.split("?");
	var param = wlh[1].split("&");
	var tmp;
	var url   = wlh[0];
	var KEY   = new Array();
	var VALUE = new Array();
	// passa params para KEY & VALUE
	for(var i=0;i<param.length;i++) {
		tmp      = param[i].split("=");
		KEY[i]   = tmp[0];
		VALUE[i] = tmp[1];
	}
	var cont = 0;
	// muda o parametro desejado e monda a URL
	for(var i=0;i<KEY.length;i++) {
		if(key == KEY[i]){
			VALUE[i] = value;
			cont++;
		}
		if(i==0){
			url += '?' + KEY[i] + '=' + VALUE[i];
		}else{
			url += '&' + KEY[i] + '=' + VALUE[i];
		}
	}
	if(cont == 0){
		url += '&' + key + '=' + value;
	}
	return url;
}
//////////////////////////////
// GET URL PARAMETERS
function gup( name ) {
	name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
	var regexS = "[\\?&]"+name+"=([^&#]*)";
	var regex = new RegExp(regexS);
	var results = regex.exec(window.location.href);
	if( results == null )
		return false;
	else
		return results[1];
}
//////////////////////////////
function isValidEmail(email) {
    var regex = /^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*$/i;
    return regex.test(email);
}
///////////////////////////////////
function checkIndicar(f) {
	var erro   = false;
	var notice = 'Por favor corrija os campos abaixo:\n\n';
	if(f.nome.value == '') {
		notice += 'Seu nome\n';
		erro   = true;
	}
	if(!isValidEmail(f.email.value)) {
		notice += 'Email destinatário\n';
		erro   = true;
	}
	if(erro==true) {
		alert(notice);
		return false;
	} else {
		return true;
	}
}
///////////////////////////////////
function checkContato(f) {
	var erro   = false;
	var notice = 'Por favor corrija os campos abaixo:\n\n';
	if(f.nome.value == '') {
		notice += 'Seu nome\n';
		erro   = true;
	}
	if(!isValidEmail(f.email.value)) {
		notice += 'Seu e-mail\n';
		erro   = true;
	}
	
	if(f.msg.value == '') {
		notice += 'Mensagem vazia\n';
		erro   = true;
	}
	if(erro==true) {
		alert(notice);
	} else {
		document.getElementById('ff').submit()
	}
}
///////////////////////////////////
function checkFaca() {
	var f = document.getElementById('ff');
	var erro   = false;
	var notice = 'Por favor corrija os campos abaixo:\n\n';
	if(f.nome.value == '') {
		notice += 'Seu nome\n';
		erro   = true;
	}
	if(!isValidEmail(f.email.value)) {
		notice += 'Seu e-mail\n';
		erro   = true;
	}
	
	if(f.data.value == '') {
		notice += 'Data\n';
		erro   = true;
	}
	if(erro==true) {
		alert(notice);
	} else {
		document.getElementById('ff').submit()
	}
}
///////////////////////////////////
function checkCadastro(f) {
	var erro   = false;
	var notice = 'Por favor corrija os campos abaixo:\n\n';
	if(f.nome.value == '') {
		notice += 'Seu nome\n';
		erro   = true;
	}
	if(!isValidEmail(f.email.value)) {
		notice += 'Seu e-mail\n';
		erro   = true;
	}
	
	if(f.tel.value == '') {
		notice += 'Seu telefone\n';
		erro   = true;
	}
	if(erro==true) {
		alert(notice);
	} else {
		document.getElementById('ff').submit()
	}
}
/////////////////////////////////// RESERVE
var Ag="ativa"; 
function NoLogin() {var Ag="ativa";  var URL="http://www.reserve.com.br/nologin.asp?A="+Ag;  window.open(URL,'noLogin','width=400,height=300,resizable=no,toolbar=no,status=no,menubar=no,scrollbars=no'); } function validarsenhaempresa() { var Ag="ativa";    if (document.b2bempresa.Login.value == "")         {         alert("Digite Seu Login");         document.b2bempresa.Login.focus();         return (false);         }              if (document.b2bempresa.Senha.value == "")         {         alert("Digite Sua Senha");         document.b2bempresa.Senha.focus();         return (false);         }         document.b2bempresa.Agencia.value=Ag; }
///////////////////////////////////////////
