console.log("loading");
// added j20140423 // error notification
//(function(){
if (typeof jQuery == 'undefined'){
console.log("loading jQuery");
var nmxscript = document.createElement("script");
nmxscript.src = '//ws.nutramax.biz/js/jquery.js';
document.head.appendChild(nmxscript);
}
//})();
function showPostStoryThankyou(formSelector){
jQuery(formSelector).hide();
jQuery("#thankyou, .thankyou").show();
document.location = "/#thankyou";
jQuery('html, body').scrollTo(jQuery('#thankyou'), 300);
}
function showPostStoryForm(formSelector){
jQuery(formSelector).show();
jQuery("#thankyou, .thankyou").hide();
document.location = "/#yourstory";
jQuery('html, body').scrollTo(jQuery('#yourstory'), 300);
}
if (!jQuery(".success-stories-submit-form").length){
if(jQuery("#success-stories-submit-form-script[button='true']").length && !jQuery(".success-stories-submit-form-btn").length){
console.log("added success stories submit form button");
jQuery("#success-stories-submit-form-script").after('
Submit Your Success Story
');
} else{
console.log("added success stories submit form");
}
jQuery("#success-stories-submit-form-script").before('');
if (!jQuery("#success-stories-submit-form-script[button='true']").length){ jQuery(".success-stories-submit-form").removeAttr("style"); }
if (jQuery(".success-stories-submit-form-btn").length){
jQuery(".success-stories-submit-form-btn").removeAttr("target").removeAttr("href").find("*").removeAttr("target").removeAttr("href");
}
}
var product = "";
jQuery(document).ready(function(){
jQuery(".success-stories-submit-form").addClass("nmx-bs");
if (jQuery(".success-stories-submit-form-btn").length){
jQuery(".success-stories-submit-form").prependTo("body").addClass("popup");
jQuery(".success-stories-submit-form-btn").click(function(){
OpenSubmitFormPopup();
});
} else{
console.log("no button");
}
jQuery("head").append('');
jQuery("head").append('');
console.log("rating goes here");
}
//jQuery("head").append('');
}
function LoadSuccessStories(){
window.setInterval(function(){
//email optin animal selection
jQuery('#optin').click(function(){
if(this.checked){
jQuery('#animal-type').css("display","block");
jQuery("#zipcode").prop('required',true);
}
else
{
jQuery('#animal-type').css("display","none");
jQuery("#zipcode").prop('required',false);
}
});
//end email optin animal selection
jQuery("i").each(function() {
jQuery("i[data-value='1']").hover(function(){
jQuery("#rating-class").css("color","#b43034").text("Poor");
jQuery(".rating-input i.glyphicon").css("color","#b43034");
});
jQuery("i[data-value='2']").hover(function(){
jQuery("#rating-class").css("color","#de9500").text("Fair");
jQuery(".rating-input i.glyphicon").css("color","#de9500");
});
jQuery("i[data-value='3']").hover(function(){
jQuery("#rating-class").css("color","#ffbf00").text("Average");
jQuery(".rating-input i.glyphicon").css("color","#ffbf00");
});
jQuery("i[data-value='4']").hover(function(){
jQuery("#rating-class").css("color","#8ac100").text("Good");
jQuery(".rating-input i.glyphicon").css("color","#8ac100");
});
jQuery("i[data-value='5']").hover(function(){
jQuery("#rating-class").css("color","#005320").text("Excellent");
jQuery(".rating-input i.glyphicon").css("color","#005320");
});
});
jQuery(".rating-input").mouseout(function(){
if(jQuery("#rating1").val() == "")
{
jQuery("#rating-class").text("");
jQuery(".rating-input i.glyphicon").css("color","#9c680e");
}
if(jQuery("#rating1").val() == 1)
{
jQuery("#rating-class").css("color","#b43034").text("Poor");
jQuery(".rating-input i.glyphicon").css("color","#b43034");
}
if(jQuery("#rating1").val() == 2)
{
jQuery("#rating-class").css("color","#de9500").text("Fair");
jQuery(".rating-input i.glyphicon").css("color","#de9500");
}
if(jQuery("#rating1").val() == 3)
{
jQuery("#rating-class").css("color","#ffbf00").text("Average");
jQuery(".rating-input i.glyphicon").css("color","#ffbf00");
}
if(jQuery("#rating1").val() == 4)
{
jQuery("#rating-class").css("color","#8ac100").text("Good");
jQuery(".rating-input i.glyphicon").css("color","#8ac100");
}
if(jQuery("#rating1").val() == 5)
{
jQuery("#rating-class").css("color","#005320").text("Excellent");
jQuery(".rating-input i.glyphicon").css("color","#005320");
}
});
},500);
if (location.hash=="#thankyou"){
ShowSuccessThankyou();
}
window.scrollBy(0,0);
if(navigator.userAgent.indexOf("iPhone") == -1 && navigator.userAgent.indexOf("iPad") == -1){
jQuery(".legal-text").attr("scrolling","yes").attr("style","height:200px; width:100%; border:solid 1px #dddddd;").unwrap();
jQuery(".success-stories-submit-form iframe.legal-text-container").remove();
}
//jQuery('#gotop').click(function(){ window.scrollTo(0,0); });
jQuery("head").append('');
jQuery(".col-md-2 p strong:contains('Testimonal Affidavit')").closest("div").removeClass("col-md-2").addClass("col-md-12");
jQuery("#submit-story-form #email").focus(function(){ jQuery("#submit-story-form #email").prop("type","email"); });
jQuery("#submit-story-form #phone").focus(function(){ jQuery("#submit-story-form #phone").prop("type","tel"); });
if(jQuery("#submit-story-form select#product option").length<3){
jQuery("#submit-story-form select#product").closest("div").hide();
}
//jQuery(".scroll-to-view").prev("h4").css("margin-top","40px");
window.setInterval(function(){ checkUploadFileSelection(); },2000);
window.onresize= function(){ ResizeForm(); };
ResizeForm();
}
function ResizeForm(){
if (jQuery("#submit-story-form input[type='submit']").parent().width()<250){
jQuery("#submit-story-form input[type='submit']").val("Submit Story");
//jQuery("div.trigger").css("font-size","12px");
}
else {
jQuery("#submit-story-form input[type='submit']").val("Submit Your Story");
//jQuery("div.trigger").css("font-size","16px");
}
var winheight = jQuery(window).height()*.9;
var topmargin = jQuery(window).height()*.05;
winheight = (winheight-topmargin);
jQuery(".success-stories-submit-form.popup form").height(winheight).css("margin-top",topmargin+"px");
}
function CloseSuccessStoriesSubmitFormPopup(){
jQuery(".success-stories-submit-form.popup").removeClass("active").removeClass("done");
jQuery("body").removeClass("success-stories-submit-form-active");
submitAnotherStory();
}
function submitAnotherStory(){
jQuery('#submit-story-form').trigger('reset');
jQuery('#submit-story-form fieldset').fadeIn(500);
jQuery('#submit-story-form .form-notification').fadeOut(500);
jQuery('.custom-file-input').html(jQuery('.custom-file-input').html());
jQuery("#submit-story-form input[type='submit']").val("Submit Your Story");
jQuery('.custom-file-input').html(jQuery('.custom-file-input').html()).removeClass("upload-ready").removeClass("upload-invalid");
jQuery('.custom-file-input div').html('Click Here to Upload a Photo
');
}
var allowedUploadTypes = ",.gif,.jpeg,.jpg,.png,.xbmp,";
function checkUploadFileSelection(e){
jQuery('.custom-file-input input[type="file"]').blur();
if (jQuery('.custom-file-input input[type="file"]').val() != "") {
//if(!jQuery('.custom-file-input .select').length || jQuery('.custom-file-input .select').length){
//alert(jQuery('.custom-file-input input[type="file"]').val().substr(jQuery('.custom-file-input input[type="file"]').val().lastIndexOf("\\")+1));
if( allowedUploadTypes.indexOf(","+jQuery('.custom-file-input input[type="file"]').val().toLowerCase().substr(jQuery('.custom-file-input input[type="file"]').val().lastIndexOf("."))+",") == -1 ){
if(!jQuery('.custom-file-input').hasClass("upload-invalid")){
jQuery('.custom-file-input').addClass("upload-invalid").removeClass("upload-ready");
jQuery('.custom-file-input div').html("Invalid file type (click to select another)
");
}
} else if(!jQuery('.custom-file-input').hasClass("upload-ready")){
jQuery('.custom-file-input').addClass("upload-ready").removeClass("upload-invalid");
//jQuery('.custom-file-input div').html(""+jQuery('.custom-file-input input[type="file"]').val().substr(jQuery('.custom-file-input input[type="file"]').val().lastIndexOf("\\")+1)+"
X
");
jQuery('.custom-file-input div').html("Reset
Ready to upload (click to change)
");
}
jQuery('.custom-file-input div .remove').mousedown(function(){
jQuery('.custom-file-input').html(jQuery('.custom-file-input').html()).removeClass("upload-ready").removeClass("upload-invalid");
jQuery('.custom-file-input div').html("Click Here to Upload a Photo");
return false;
});
//}
}
}
jQuery(document).ready(function(){
window.setTimeout(function(){
jQuery(".success-stories-submit-form form#submit-story-form").submit(function(e){
e.preventDefault();
SubmitSuccessStory();
return false;
});
},1400);
});
function isValidEmail(emailAddress) {
var pattern = new RegExp(/^((([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+(\.([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+)*)|((\x22)((((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(([\x01-\x08\x0b\x0c\x0e-\x1f\x7f]|\x21|[\x23-\x5b]|[\x5d-\x7e]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(\\([\x01-\x09\x0b\x0c\x0d-\x7f]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))))*(((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(\x22)))@((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.?$/i);
return pattern.test(emailAddress);
}
function IsValidPhone(p){
var phoneRe = /^[(]{0,1}[0-9]{3}[)]{0,1}[-\s\.]{0,1}[0-9]{3}[-\s\.]{0,1}[0-9]{4}$/;
var digits = p.replace(/\D/g, "");
return phoneRe.test(digits);
}
function validateZipCode(zip) {
var isValid = /^[0-9]{5}(?:-[0-9]{4})?$/.test(zip);
if (!isValid) {
return false;
} else {
return true;
}
}
function SubmitSuccessStory(){
console.log("submit story");
var firstname = jQuery("#firstname").val(),lastname = jQuery("#lastname").val(),email = jQuery("#email").val(), yourstory = jQuery("#story").val(),testimonalrelease = jQuery("input#testimonalrelease").val(), product = jQuery("#product").val(), zipcode = jQuery("#zipcode").val(), phone = jQuery("#phone").val();
console.log(email+","+firstname+","+lastname+","+yourstory+","+testimonalrelease);
var validPhone=true;
if(!IsValidPhone(phone) && phone != "")
{
validPhone = false;
}
var validZipCode=true;
if(!validateZipCode(zipcode) && zipcode != "")
{
validZipCode = false;
}
// if optin is checked user must choose one animal type
var selected=true;
if(jQuery("#optin").is(':checked') && !jQuery('input#cat:checked').length && !jQuery('input#dog:checked').length && !jQuery('input#horse:checked').length){
selected=false;
}
if (isValidEmail(email) && (firstname.length > 1) && (lastname.length > 1) && (product != "") &&(yourstory.length > 1) && jQuery("input#testimonalrelease:checked").length && validPhone == true && validZipCode == true && selected == true && !jQuery('.non-us-email').length == 1) {
jQuery(".success-stories-submit-form").addClass("working");
window.scrollTo(0,0);
jQuery("#submit-story-form input[type='submit']").val("Please wait...").blur();
var env = "";
if(location.hostname.indexOf("test.")>-1){ env = "stg"; console.log("test stories site"); }
else if(location.hostname.indexOf("stg.")>-1){ env = "stg"; console.log("staging stories site"); }
// if they check Join Our Email List (Optional) checkbox
if(jQuery("#optin").is(':checked'))
{
if(!jQuery('input#cat:checked').length && !jQuery('input#dog:checked').length && !jQuery('input#horse:checked').length)
{
jQuery('#cat').focus();
jQuery("#desktop-error").css('display','block');
}
else
{
jQuery("#desktop-error").css('display','none');
}
var dog='&',cat='&',horse='&',small_animal='&';
if (jQuery('#submit-story-form #dog').is(':checked')) { var dog = '&group[3327][1]=1'; };
if (jQuery('#submit-story-form #cat').is(':checked')) { var cat= '&group[3327][2]=1'; };
if (jQuery('#submit-story-form #horse').is(':checked')) { var eqt = '&group[3327][4]=1'; };
if((jQuery('#submit-story-form #cat').is(':checked')) || (jQuery('#submit-story-form #dog').is(':checked'))) { small_animal +="small_animal=1"; }
var data = jQuery("form#submit-story-form").serializeArray().reduce(function(obj, item) {
obj[item.name] = item.value;
return obj;
}, {});
var formData = "FIRSTNAME=" + data["firstname"] + "&LASTNAME=" + data["lastname"] + "&EMAIL=" + data["email"] + "&ZIP=" + data["zipcode"] + "&STREETADD1=" + data["address1"] + "&CITY=" + data["city"] + "&STATE=" + data["state"] + "&PHONE=" + data["phone"] + "&COUNTRY=USA" + "&OPTINFRO=" + location.hostname + '&' + dog + cat + eqt;
jQuery.ajax({
type: "POST",
url: 'https://nutramaxlabs.us17.list-manage.com/subscribe/post-json?u=94b067d817727f5933c97d267&id=c3a400946b',
data: formData,
cache: false,
dataType: "jsonp",
jsonp: "c", // trigger MailChimp to return a JSONP response
contentType: "application/json; charset=utf-8",
error: function(error) {
// According to jquery docs, this is never called for cross-domain JSONP requests
// nmx added d20171511
/* ga('create', 'UA-741540-1', 'auto', {'name': 'nutramax'});
ga('nutramax.send', 'event', 'Conversion Popup', 'Join Our Mailing List', 'Subscribe failed');*/
},
success: function(data) {
console.log('going mailchimp');
console.log(data);
}
});
}
//end of join our email list
jQuery("#submit-story-form").attr("method","post").attr("action","//ws.nutramax.biz/stories/upload/index.php?site="+env+"&productpage="+encodeURIComponent(location.href)+"").attr("enctype","multipart/form-data");
jQuery("head").append('