$(document).ready(function()
{
$('.cc_modal').qtip(
{
content: { title: {
text: 'Alaska Sportfishing Newsletter',
button: 'Close'
},
url: 'constant-contact-ajax2.php' },
position: {
target: $(document.body), // Position it via the document body...
corner: 'center' // ...at the center of the viewport
},
show: {
when: 'click', // Show it on click
solo: true // And hide all other tooltips
},
hide: { when: { target: $('#cancel_btn') } },
style: {
width: 650,
height: 400,
padding: '14px',
border: {
width: 9,
radius: 9,
color: '#666666'
},
name: 'light'
},
api: {
beforeShow: function()
{
// Fade in the modal "blanket" using the defined show speed
$('#qtip-blanket').fadeIn(this.options.show.effect.length);
},
beforeHide: function()
{
// Fade out the modal "blanket" using the defined hide speed
$('#qtip-blanket').fadeOut(this.options.hide.effect.length);
},
onContentUpdate: function()
{
//alert('Loaded');
setup_errors();
$('#contant_contact_form').submit(function(){
form_loaded_handler();
return false;
});
$('#cancel_btn').click(function(){
$('a[rel="cc_modal"]').qtip("hide");
});
}
}
});
// Create the modal backdrop on document load so all modal tooltips can use it
$('
')
.css({
position: 'absolute',
top: $(document).scrollTop(), // Use document scrollTop so it's on-screen even if the window is scrolled
left: 0,
height: $(document).height(), // Span the full document height...
width: '100%', // ...and full width
opacity: 0.7, // Make it slightly transparent
backgroundColor: 'black',
zIndex: 5000 // Make sure the zIndex is below 6000 to keep it below tooltips!
})
.appendTo(document.body) // Append to the document body
.hide(); // Hide it initially
});
function form_loaded_handler(){
var api = 'http://www.cloverpassresort.com/ccapi.php?action=addcontact';
//alert('hello');
//Hide error message if needed.
$('.cc_response_container').slideUp('slow');
haserrors = false;
//Check Email Value
if(!validate_email($('#email_address').val())){
haserrors = true;
$('#email_address_error').removeClass('error_container_hide').addClass('error_container');
} else {
$('#email_address_error').removeClass('error_container').addClass('error_container_hide');
}
//Check List
var lists = $('.lists_con input').serializeArray();
if(lists.length == 0){
//alert("No Lists");
haserrors = true;
$('#list_error_1').removeClass('error_container_hide').addClass('error_container');
}else{
$('#list_error_1').removeClass('error_container').addClass('error_container_hide');
}
// $.each(lists, function(index, value) {
// alert(index + ': ' + value.value);
// });
//Submit Ajax
if(!haserrors){
//alert($('#contant_contact_form').serialize());
$.post(api, $("#contant_contact_form").serialize(),function(data) {
process_submission(data);
});
} else {
$('.cc_response_container').slideDown('slow');
$('.cc_response_container').html('Please fix errors in the form. (Mouse-over * for more info)');
}
}
function setup_errors(){
$('#email_address_error').qtip({
content: {
text: false // Use each elements title attribute
},
style: 'cream' // Give it some style
});
$('#list_error_1').qtip({
content: {
text: false // Use each elements title attribute
},
position: {
corner: {
tooltip: 'topRight', // Use the corner...
target: 'bottomLeft'// ...and opposite corner
}
},
style: 'cream' // Give it some style
});
}
function process_submission(data){
if(data.childNodes[0].childNodes[0].nodeName != 'error'){
//alert(data.childNodes[0].childNodes[0].childNodes[0].nodeValue);
} else {
//alert(data.childNodes[0].childNodes[0].childNodes[0].nodeValue);
}
$('.cc_response_container').slideDown('slow');
$('.cc_response_container').html(data.childNodes[0].childNodes[0].childNodes[0].nodeValue);
//alert("Data Loaded: " + data.childNodes[0].childNodes[0].nodeName);
}
function validate_email(email) {
var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
var address = email;
if(reg.test(address) == false) {
return false;
}else{
return true;
}
}