﻿$(function(){

omniCallout();
    //top navigation highlights
    LATISSE.topNav();
    
    //page specific js
    switch (globalVar.mainclass()) {
        case "home":
            LATISSE.initHome();
            break;
        case "subpage":
            LATISSE.initSubpage();
            break;
    }    
       
   //image swap for DOCTALK
   $(".hoverswap a img").hover(
		function () {
			$(this).attr("src", $(this).attr("src").replace("Static", "Hover"));
		},
		function () {
			$(this).attr("src", $(this).attr("src").replace("Hover", "Static"));
		}
	);
	
	
}); //  End Document Ready

//global variables in a closure
var globalVar = {
    mainclass: function() {
        return $("#main_content").attr("class").split(' ').slice(0, 1).toString();
    },
    pagecategory: function() {
        return $("#main_content").attr("class").split(' ').slice(1, -1).toString();
    },    
    subpage: function() {
        return $("#main_content").attr("class").split(' ').slice(-1).toString();
    }
};

var LATISSE = {
    topNav: function() {
        //highlight top nav        
        $('#main_nav ul li#' + globalVar.pagecategory()).addClass('active');
        $('#main_nav ul li#' + globalVar.pagecategory() + ' a').click(function() {
            return false;
        });
    },
    initHome: function() {
        //add home specific js here

    },
    initSubpage: function() {

        //qa page specific call
        if (globalVar.subpage() == 'qa') {
            RealQuest_FaqDL(); General_FaqDL();
        }

        //alert(globalVar.subpage());

        //highlight left nav
        $('ul#left_nav li#' + globalVar.subpage()).addClass('on_State');
        $('ul#left_nav li#' + globalVar.subpage() + ' a').click(function() {
            return false;
        });

        switch (globalVar.subpage()) {
            case "apply":
                $('.col_left #DownloadPdf').show(); //how to apply pages - left nav manipulation
                break;
            case "trial":
                $('.col_left #trial-thumbs').show();
                break;
            case "realwomen":
                $('.col_left #realwomen-thumbs').show();
                break;
            case "realwomenvideo":
                $('.col_left #realwoman-video-thumbs').show();
                break;
            case "qa":
                $('.col_left .BDP_callout').hide();
                $('.col_left #physician-thumbs').show();
                break;
        }

    }
}

//  Omniture calls
var omniCallout = function() {
    $('#home_callouts a').click(function() {
        var text = $(this).attr('name');
        s.linkTrackVars = 'eVar36';
        s.linkTrackEvents = 'None';
        s.eVar36 = text;
        s.tl(this, 'o', s.pageName);
    });
    $('#social_media a.youtube').click(function() {
        s.linkTrackVars = 'eVar36';
        s.linkTrackEvents = 'None';
        s.eVar36 = 'YouTube';
        s.tl(this, 'o', s.pageName);
        //alert('asdf');
    });
    $('#social_media a.facebook').click(function() {
        s.linkTrackVars = 'eVar35';
        s.linkTrackEvents = 'None';
        s.eVar35 = 'Facebook';
        s.tl(this, 'o', s.pageName);
    });
    $('.BDP_callout a').click(function() {
        s.linkTrackVars = 'eVar37';
        s.linkTrackEvents = 'None';
        s.eVar37 = 'Brilliant Distinctions';
        s.tl(this, 'o', s.pageName);
        return false;
    });
    $('.Pdf_callout a').click(function() {
        s.linkTrackVars = 'eVar37';
        s.linkTrackEvents = 'None';
        s.eVar37 = 'Download Now';
        s.tl(this, 'o', s.pageName);
    });
    $('#Submit_photo a').click(function() {
        s.linkTrackVars = 'eVar37';
        s.linkTrackEvents = 'None';
        s.eVar37 = 'Submit Photo';
        s.tl(this, 'o', s.pageName);
        return false;
    });
};
var fadCallourOmni = function() {
    s.linkTrackVars = 'eVar37';
    s.linkTrackEvents = 'None';
    s.eVar37 = 'Find a Doctor';
    s.tl(this, 'o', s.pageName);
};  
//     /Omniture calls 
  
function validateZIP(field) {
    var valid = "0123456789-";
    var hyphencount = 0;

    if (field.length!=5 && field.length!=10) {
    alert("Please enter your 5 digit or 5 digit+4 zip code.");
    return false;
    }
    for (var i=0; i < field.length; i++) {
    temp = "" + field.substring(i, i+1);
    if (temp == "-") hyphencount++;
    if (valid.indexOf(temp) == "-1") {
    alert("Invalid characters in your zip code.  Please try again.");
    return false;
    }
    if ((hyphencount > 1) || ((field.length==10) && ""+field.charAt(5)!="-")) {
    alert("The hyphen character should be used with a properly formatted 5 digit+four zip code, like '12345-6789'.   Please try again.");
    return false;
    }
    }
    fadCallourOmni();
    return true;
    }

    $(document).ready(function() {

        if ($("#joint_the_challenge")) {
            $('#joint_the_challenge').click(function() {
                location.href = 'https://www.latissewisheschallenge.com';
                return false;
            });
        };

        if ($("#sign_up_now")) {
            $('#sign_up_now').click(function() {
                location.href = 'SignUp.aspx';
                return false;
            });
        };


        //the following code is used to check the input box value and removes any html tags
        if ($(".check_input_value")) {
            $('.check_input_value').blur(function() {
                var temp_text_info = $(this).val();
                temp_text_info = $('<div/>').html(temp_text_info).text();
                $(this).val(temp_text_info);
                return true;
            });
        };

        if ($("#FaD_go")) {
            $('#FaD_go').click(function() {

                if (validateZIP($("#FaDSearch").val())) {
                    location.href = 'FindaDoctor.aspx?radius=1&zip=' + $("#FaDSearch").val();
                    return false;
                }
                else {
                    $("#FaDSearch").focus();
                    return false;
                }
            });
        }

        if ($("#FaDSearch")) {
            $("#FaDSearch").keypress(function(e) {
                if (e.which == 13) {
                    $("#FaD_go").click();
                    e.preventDefault();     
                    }
                });
        }

    });
