function calltoaction_show_form(){
	$.ajax({
		type: "POST",
		url: WEB_PATH + "app/ajax/calltoaction_get_form.php",
		data:'',
		success: function(response){
			$('#div_message').html(response);
			msgbox_show('div_message');
		}
	});
}

function calltoaction_show_form_consultar(){
	$.ajax({
		type: "POST",
		url: WEB_PATH + "app/ajax/calltoaction_get_form_consulta.php",
		data:'',
		success: function(response){
			$('#div_message').html(response);
			msgbox_show('div_message');
		}
	});
}

function calltoaction_hide_form(){
	msgbox_hide('div_message');
}

function deletecivalue(){

    document.getElementById("consultasaldo_cedula").value = "";

}

function deletetargetvalue(){

    document.getElementById("consultasaldo_tarjeta").value = "";

}




function calltoaction_consulta_puntos()
{
	if (!document.sending && calltoaction_consulta_puntos_valid()) {
		document.sending = true;
		calltoaction_consulta_puntos_show_msg('ok', 'Enviando...');
		$.ajax({
			type: "POST",
			url: WEB_PATH + "app/ajax/calltoaction_consulta_puntos.php",
			data: {cedula: $('#consultasaldo_cedula').val()},
			success: function(response){
				document.sending = false;
				var v_result = response.split("|");
				if(v_result[0]=='0'){
					calltoaction_consulta_puntos_show_msg('error', v_result[1]);
				} else {
			//	switch (response) {
			//		case '1':
			//			calltoaction_consulta_puntos_show_msg('error', 'Datos incorrectos.');
			//			break;
			//		case '2':
			//		case '':
			//			calltoaction_consulta_puntos_show_msg('error', response);
			//			break;
			//		default:
						calltoaction_consulta_puntos_show_msg('', '');
						$('#div_message').html(response);
						msgbox_show('div_message');
				//		break;
				}
			}
		});
	}
}
function calltoaction_consulta_puntos_valid()
{
	var valid = true;
	var cedula = $('#consultasaldo_cedula').val();
	//var tarjeta = $('#consultasaldo_tarjeta').val();
	if (cedula.length != 8 || isNaN(cedula)) {
		valid = false;
		calltoaction_consulta_puntos_show_msg('error', 'Ingrese su c&eacute;dula sin puntos ni guiones.');
	} /*else if (tarjeta == '') {
		valid = false;
		calltoaction_consulta_puntos_show_msg('error', 'Ingrese su numero de tarjeta.');
	} else if (isNaN(tarjeta)) {
		valid = false;
		calltoaction_consulta_puntos_show_msg('error', 'Numero de tarjeta no v&aacute;lido.');
	}*/
	return valid;
}
function calltoaction_consulta_puntos_show_msg(type, text) //type: 'error', 'ok'
{
	$('#consultasaldo_msg').removeClass('error-text');
	$('#consultasaldo_msg').removeClass('good-text');
	if (type == 'error')
		$('#consultasaldo_msg').addClass('error-text');
	else if (type == 'ok')
		$('#consultasaldo_msg').addClass('good-text');
	$('#consultasaldo_msg').html(text);
}

function calltoaction_ofertacorreo_submit()
{
	if (!document.sending && calltoaction_ofertacorreo_valid()) {
		document.sending = true;
		$('#div_calltoaction_ofertas_msg').removeClass('error');
		$('#div_calltoaction_ofertas_msg').removeClass('success');
		$('#div_calltoaction_ofertas_msg').html('Enviando...');
		$.ajax({
			type: "POST",
			url: WEB_PATH + "app/ajax/calltoaction_ofertacorreo_submit.php",
			data: {name: $('#inp_calltoaction_ofertas_name').val().trim(), email: $('#inp_calltoaction_ofertas_email').val().trim()},
			success: function(response) {
				document.sending = false;
				switch (response) {

					case '0':						
						$('#inp_calltoaction_ofertas_name').val('');
						$('#inp_calltoaction_ofertas_email').val('');
						$('#div_calltoaction_ofertas_msg').html('El registro se ha realizado correctamente');
						$('#div_calltoaction_ofertas_msg').removeClass('error');
						$('#div_calltoaction_ofertas_msg').addClass('success');
						break;
					case '1':
						$('#div_calltoaction_ofertas_msg').html('Este email ya se encuentra registrado');
						$('#div_calltoaction_ofertas_msg').removeClass('success');
						$('#div_calltoaction_ofertas_msg').addClass('error');
						break;
					default:
						$('#div_calltoaction_ofertas_msg').html('Error al registrar datos. Vuelva a intentarlo en unos minutos');
						$('#div_calltoaction_ofertas_msg').removeClass('success');
						$('#div_calltoaction_ofertas_msg').addClass('error');
						break;
				}
			},
			error: function(obj, what_happen, other_obj) {
				document.sending = false;
			}
		});
	}
}
function calltoaction_ofertacorreo_valid()
{
	var name = $('#inp_calltoaction_ofertas_name').val().trim();
	var email = $('#inp_calltoaction_ofertas_email').val().trim();
	var valid = true;
	if (name == '' || name == 'Nombre') {
		valid = false;
		$('#div_calltoaction_ofertas_msg').html('Debe ingresar su nombre');
		$('#div_calltoaction_ofertas_msg').removeClass('success');
		$('#div_calltoaction_ofertas_msg').addClass('error');
	} else if (email == '' || email == 'E-mail') {
		valid = false;
		$('#div_calltoaction_ofertas_msg').html('Debe ingresar su email');
		$('#div_calltoaction_ofertas_msg').removeClass('success');
		$('#div_calltoaction_ofertas_msg').addClass('error');
	} else if (!is_email(email)) {
		valid = false;
		$('#div_calltoaction_ofertas_msg').html('El email ingresado no es v&aacute;lido');
		$('#div_calltoaction_ofertas_msg').removeClass('success');
		$('#div_calltoaction_ofertas_msg').addClass('error');
	} 
	return valid;
}

function calltoaction_register(){


	if(calltoaction_register_valid() && !document.sending ){
		document.sending = true;
		$.ajax({
			type: "POST",
			dataType:"json",
			url: WEB_PATH + "app/ajax/calltoaction_register_submit.php",
			data: $('#form_calltoaction_reg').serialize(),
			success: function(response) {
				if(response.error=='1'){
					//location.href= WEB_PATH + "html/tpl/busqueda.html";
					document.sending = false;

					//alert(response.message);

					//show_div('reg_msg', response.message);
					/******************************/
					setTimeout(function() {
							calltoaction_hide_form();
						}, 50000);
						$('#div_message').html('<div id="msj_correcto" name="msj_correcto" style="width: 600px;background-color: #FFFFFF;padding:30px;color: #4D4D4D;display: block;left: 276px;top: 320px;z-index: 999999999;font: 15px/1.231 arial,helvetica,clean,sans-serif; font-style:italic; " ><img style="float: left;" alt="SiSi club" src="' + WEB_PATH + 'html/img/sisi-club.gif"><a class="cerrar-popup" href="javascript:void(calltoaction_hide_form());"></a><p style="display:block;clear: both;display: inline-block;margin-top: 10px;">' + response.message + '</p></div>' );
						msgbox_show('div_message');

						/******************************/
			} else if (response.error =='-1'){
					document.sending = false;
					show_div('reg_msg', response.message);
				} else {
					document.sending = false;
					show_div('reg_msg', response.message);
				}
			return (response)?true:false;
			}
		});
	}

}
function calltoaction_register_valid()
{
	
	var valid = false;
	var nacim_dia = $('#reg_nacim_dia').val().trim();
	var nacim_mes = $('#reg_nacim_mes').val().trim();
	var nacim_anio = $('#reg_nacim_anio').val().trim();
	$('input').removeClass('error');
	$('#reg_msg').removeClass('error');
	$('#reg_msg').removeClass('success');
	
	show_div('reg_msg', '');
	if ($('#reg_nombre').val().trim() == ''){
		show_div('reg_msg', MSG_INVALID_NAME);
		$('#reg_nombre').addClass('error');
		$('#reg_nombre').focus();
		$('#reg_msg').addClass('error');
	}else if ($('#reg_apellido').val().trim() == ''){
		show_div('reg_msg', MSG_INVALID_LASTNAME);
		$('#reg_apellido').addClass('error');
		$('#reg_apellido').focus();
		$('#reg_msg').addClass('error');
	}else if ($('#reg_documento').val().trim() == ''){
		show_div('reg_msg', 'Debe ingresar su documento');
		$('#reg_documento').addClass('error');
		$('#reg_msg').addClass('error');
	}else if (validate_cedula($('#reg_documento').val().trim()) == 1){
		show_div('reg_msg', 'El documento debe estar en formato 1.234.567-8');
		$('#reg_documento').addClass('error');
		$('#reg_msg').addClass('error');
	}else if (nacim_dia == '' || isNaN(nacim_dia) || nacim_dia.length != 2){
		show_div('reg_msg', 'La fecha de nacimiento no es v&aacute;lida');
		$('#reg_nacim_dia').addClass('error');
		$('#reg_msg').addClass('error');
	}else if (nacim_mes == '' || isNaN(nacim_mes) || nacim_mes.length != 2){
		show_div('reg_msg', 'La fecha de nacimiento no es v&aacute;lida');
		$('#reg_nacim_mes').addClass('error');
		$('#reg_msg').addClass('error');
	}else if (nacim_anio == '' || isNaN(nacim_anio) || nacim_anio.length != 4){
		show_div('reg_msg', 'La fecha de nacimiento no es v&aacute;lida');
		$('#reg_nacim_anio').addClass('error');
		$('#reg_msg').addClass('error');
	}else if (!is_date(nacim_dia + '/' + nacim_mes + '/' + nacim_anio)){
		show_div('reg_msg', 'La fecha de nacimiento no es v&aacute;lida');
		$('#reg_nacim_dia').addClass('error');
		$('#reg_nacim_mes').addClass('error');
		$('#reg_nacim_anio').addClass('error');
		$('#reg_msg').addClass('error');
	}else if ($('#reg_departamento').val().trim() == ''){
		show_div('reg_msg', 'Debe ingresar su departamento');
		$('#reg_departamento').addClass('error');
		$('#reg_msg').addClass('error');
	}/*else if ($('#reg_direccion').val().trim() == ''){
		show_div('reg_msg', 'Debe ingresar su direcci&oacute;n');
		$('#reg_direccion').addClass('error');
		$('#reg_msg').addClass('error');
	}*/else if ($('#reg_telefono').val().trim() == ''){
		show_div('reg_msg', 'Debe ingresar su tel&eacute;fono');
		$('#reg_telefono').addClass('error');
		$('#reg_msg').addClass('error');
	}else if ($('#reg_email').val().trim() == ''){
		show_div('reg_msg', 'Debe ingresar su email');
		$('#reg_email').addClass('error');
		$('#reg_msg').addClass('error');
	}else if (!is_email($('#reg_email').val())){
		show_div('reg_msg', 'El email no es v&aacute;lido');
		$('#reg_email').addClass('error');
		$('#reg_msg').addClass('error');
	}else if ($('#reg_departamento').val().trim() == ''){
		show_div('reg_msg', 'El email no es v&aacute;lido');
		$('#reg_email').addClass('error');
		$('#reg_msg').addClass('error');
	}else if ($('#reg_genero').val().trim() == ''){
		show_div('reg_msg', 'Debe seleccionar su sexo');
		$('#reg_genero').addClass('error');
		$('#reg_msg').addClass('error');
	}else if (document.getElementById('terminos').checked == false){
		show_div('reg_msg', 'Acepte los t&eacute;rminos y condiciones');
		$('#reg_genero').addClass('error');
		$('#reg_msg').addClass('error');
	}else{
		valid = true;
		$('#reg_msg').addClass('success');
		show_div('reg_msg', 'Enviando...');		
	}
	return valid;
}
