// -- Initializations --
$(document).ready(function() {
if($('#contactform').length || $('#vetparticipationform').length || $('#applicationform').length){
$('#contactform, #vetparticipationform, #applicationform').submit(function(e) {
e.preventDefault();
$('.required-field-alert').removeClass('required-field-alert');
$('.required-field-alert-highlight').removeClass('required-field-alert-highlight');
if (!$('input[name="citycode"]', this).length)
$(this).append('');
$('input[type="submit"]', this).hide();
$('.-spin', this).removeClass('hide');
var jFrmD = $(this).attr('id');
var jFrmCtn = $(this).attr('action');
jslocal_AjaxPost(jFrmD, jFrmCtn);
return false;
});
}
if($('#section-vetparticipation #vetparticipationform').length){
jslocal_Url = window.location.search;
if(jslocal_Url.indexOf('?') >= 0){
jslocal_Url = jslocal_Trim(jslocal_Url.replace('?', ''));
if (jslocal_Url != '' && jslocal_IsInteger(jslocal_Url, false)){
$('#section-vetparticipation #vetparticipationform').slideUp();
$('#section-vetparticipation .-0').slideUp();
$('#section-vetparticipation .-' + jslocal_Url).slideDown();
}
}
}
if($('#section-application #applicationform').length){
$('#section-application #applicationform input[type="text"]').val('');
$('#section-application #applicationform textarea').val('');
$('#section-application #applicationform select#hospitalname').val('');
$('#section-application #applicationform input[type="checkbox"]').prop('checked', false);
}
});
$(window).load(function(){
var parentNode = document.body;
jslocal_LinkEmails(parentNode);
jslocal_LinkUrls(parentNode);
});
// -- Special functions --
function jlocal_Contact_After(jSccss, jRqrdFldsLmntsLst){
if (!jSccss){
jslocal_SetFormFieldsHighlight(jRqrdFldsLmntsLst);
$('#myModal').modal({show:true});
jslocal_ResetSubmitButton('contactform');
return;
}
$('#section-contact form').slideUp();
$('#section-thankyou').slideDown();
return;
}
function jlocal_VetParticipation_After(jSccss, jRqrdFldsLmntsLst){
if (!jSccss){
jslocal_SetFormFieldsHighlight(jRqrdFldsLmntsLst);
$('#myModal').modal({show:true});
jslocal_ResetSubmitButton('vetparticipationform');
return;
}
$('#section-vetparticipation form').slideUp();
$('#section-thankyou').slideDown();
$('#section-thankyou h4').slideDown();
return;
}
function jlocal_Application_After(jSccss, jRqrdFldsLmntsLst){
if (!jSccss){
jslocal_SetFormFieldsHighlight(jRqrdFldsLmntsLst);
if (jRqrdFldsLmntsLst.indexOf('#declinedbycarecredit') >= 0)
$('#applicationform .-declinedbycarecredit').addClass('required-field-alert-highlight'); // Checkbox required
if (jRqrdFldsLmntsLst.indexOf('#countyofresidence') >= 0)
$('#applicationform .-countyofresidence').addClass('required-field-alert-highlight'); // Checkbox required
if (jRqrdFldsLmntsLst.indexOf('#zip') >= 0)
$('#applicationform .-zip').show(); // Zip must be valid
$('#myModal .modal-body .-msg1, #myModal .modal-body .-msg2, #myModal .modal-body .-msg3, #myModal .modal-body .-msg4, #myModal .modal-body .-msg5').hide();
if (jRqrdFldsLmntsLst.indexOf('#numofpets') >= 0)
$('#myModal .modal-body .-msg1').show();
if (jRqrdFldsLmntsLst.indexOf('#estimatedamountneeded') >= 0)
$('#myModal .modal-body .-msg2').show();
if (jRqrdFldsLmntsLst.indexOf('#amountabletocontribute') >= 0)
$('#myModal .modal-body .-msg3').show();
if (jRqrdFldsLmntsLst.indexOf('#zip') >= 0 || jRqrdFldsLmntsLst.indexOf('#countyofresidence') >= 0)
$('#myModal .modal-body .-msg4').show();
if (jRqrdFldsLmntsLst.indexOf('#toomanypets') >= 0){
jslocal_SetFormFieldsHighlight('#numofpets');
$('#myModal .modal-body .-msg5').show();
}
$('#myModal').modal({show:true});
jslocal_ResetSubmitButton('applicationform');
return;
}
$('#section-application').slideUp();
$('#section-thankyou').slideDown();
jslocal_Scroll2Element('#page-title');
return;
}
function jslocal_SetFormFieldsHighlight(jSlctrs){ // jSlctrs = selectors
if (jslocal_Trim(jSlctrs) != '')
$(jSlctrs).addClass('required-field-alert');
return;
}
function jslocal_ResetSubmitButton(jFrmSlctr){
$(('#' + jFrmSlctr + ' .-spin')).addClass('hide');
$(('#' + jFrmSlctr + ' input[type="submit"]')).show();
return;
}
function jslocal_Scroll2Element(jLmnt){ // jLmnt = element
jslocal_Offset = 100;
$('html, body').animate({
scrollTop: $(jLmnt).offset().top - jslocal_Offset
}, 900, 'swing');
return;
}
// -- Standard functions --
var re = /[\w\.\-]+\@([\w\-]+\.)+[\w]{2,4}(?![^<]*>)/ig;
function jslocal_LinkEmails(parentNode){
var nodes = parentNode.childNodes;
for (var i=0; i < nodes.length; i++){
if (nodes[i].nodeType == 1 && nodes[i].tagName != "A") {
jslocal_LinkEmails(nodes[i]);
} else if (nodes[i].nodeType == 3 && re.test(nodes[i].nodeValue)){
parentNode.innerHTML = parentNode.innerHTML.replace(re,"$&");
}
}
}
var rl = /https?:\/\/([-\w\.]+)+(:\d+)?(\/([\w\_\.]*(\?\S+)?)?)?/ig;
function jslocal_LinkUrls(parentNode){
var nodes = parentNode.childNodes;
for (var i=0; i < nodes.length; i++){
if (nodes[i].nodeType == 1 && nodes[i].tagName != "A") {
jslocal_LinkUrls(nodes[i]);
} else if (nodes[i].nodeType == 3 && rl.test(nodes[i].nodeValue)){
parentNode.innerHTML = parentNode.innerHTML.replace(rl,"$&");
}
}
}
function jslocal_Trim(jVl){ // jVl = value to 'trim'
return jVl.replace(/(?:(?:^|\n)\s+|\s+(?:$|\n))/g, "");
}
function jslocal_Set(jLmntID, jVl){ // jLmntID = element id | jVl = value
// Set the 'innerHTML' of an element
if (document.all)
document.all[jLmntID].innerHTML = jVl;
else
document.getElementById(jLmntID).innerHTML = jVl;
}
function jslocal_SetValue(jLmntID, jVl){ // jLmntID = element id | jVl = value
// Set the 'value' of an element
if (document.all)
document.all[jLmntID].value = jVl;
else
document.getElementById(jLmntID).value = jVl;
}
function jslocal_SetSelectOption(jFrmFldBjct, jVl){ // jFrmFldBjct = form field object | jVl = value to set with
// Set the 'selected' option of a select input list
for (i=0; i < jFrmFldBjct.options.length; i++){
if (jFrmFldBjct.options[i].value == jVl)
jFrmFldBjct.options[i].selected = true;
}
}
function jslocal_GetElement(jLmntID){ // jLmntID = element id
if (document.all)
return document.all[jLmntID];
else
return document.getElementById(jLmntID);
}
function jslocal_GetElementValue(jLmntID){ // jLmntID = element id
if (document.all)
return document.all[jLmntID].value;
else
return document.getElementById(jLmntID).value;
}
function jslocal_SetValue(jLmntID, jVl){ // jLmntID = element id | jVl = value
// Set the 'value' of an element
if (document.all)
document.all[jLmntID].value = jVl;
else
document.getElementById(jLmntID).value = jVl;
}
function jslocal_IsEmpty(jStrng){ // jStrng = string to check if empty
var jStrng2 = jslocal_Trim(jStrng);
return ((jStrng2 == null) || (jStrng2.length == 0));
}
function jslocal_IsEmptyRadio(jFrmFldNm, jFrmNmbr){ // jFrmFldNm = radio form field name | jFrmNmbr = form number
for (i=document.forms[jFrmNmbr][jFrmFldNm].length-1; i > -1; i--)
if(document.forms[jFrmNmbr][jFrmFldNm][i].checked)
return false;
return true;
}
var reEmail = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/i;
function jslocal_IsEmail(jMls){ // jMls = email to validate (empty is Ok)
return reEmail.test(jMls);
}
var reFloat = /^-?((\d+(\.\d*)?)|((\d*\.)?\d+))$/;
function jslocal_IsNumber(jNmbr) { // jNmbr = number to check
return reFloat.test(jNmbr);
}
function jslocal_IsInteger(jNmbr, jSgndNtgr) { // jNmbr = number to check | jSgndNtgr = allow signed integer (true/false)
if (jSgndNtgr)
return (jNmbr.toString().search(/^-?[0-9]+$/) == 0); // allows negative sign
else
return (jNmbr.toString().search(/^[0-9]+$/) == 0); // does not allow negative sign
}
uc = Date.parse(new Date()) + '_' + Math.round(100*Math.random()) + '_';
var ucIncrement = 0; // a value to be incremented
function jslocal_UC(){ // return the unique value
++ucIncrement;
return (uc + (ucIncrement+''));
}
function jslocal_AjaxPost(jFrmD, jRl) { // jNmbr = form id | jRl = url
var jFormData = $('#' + jFrmD).serialize();
var jAjaxUrl = jRl;
$.ajax({type:'POST',
url:(jAjaxUrl + '?uc=' + jslocal_UC()),
data:jFormData, async:true, dataType:'script'
});
return;
}
function jslocal_AjaxPost2(jFrmDt, jRl) { // jFrmDt = form data | jRl = url
var jFormData = jFrmDt;
var jAjaxUrl = jRl;
$.ajax({type:'POST',
url:(jAjaxUrl + '?uc=' + jslocal_UC()),
data:jFormData, async:true, dataType:'script'
});
return;
}