/*

vjustify function

This is a plug-in for jQuery that can equalize the heights
of a set of columns based on standard jQuery selectors.

http://michael.futreal.com/jquery/vjustifym

 */

jQuery.fn.vjustify=function() {
    var maxHeight=0;
    this.each(function(){
        if (this.offsetHeight>maxHeight) {maxHeight=this.offsetHeight;}
    });
    this.each(function(){
        jQuery(this).height(maxHeight + "px");
        if (this.offsetHeight>maxHeight) {
            jQuery(this).height((maxHeight-(this.offsetHeight-maxHeight))+"px");
        }
    });
};





//	jQuery BEHAVIORS

jQuery(document).ready(function() {

    /*
	Because IE6 doesn't suppor the :hover pseudo-selector on any element other than links,
	we're using JavaScript to make a proxy's list of accounts show up when they hover over
	the "Health Records" tab by changing a class name.
     */
    jQuery("#records-tab").hover(
    function(){
        jQuery(this).toggleClass("iehover");
    },
    function(){
        jQuery(this).toggleClass("iehover");
    }
);
    /*
	These are the various places that we're adding rounded corners.
     */
    jQuery(".side-module").append("<div class=\"tl-corner\"></div><div class=\"tr-corner\"></div><div class=\"br-corner\"></div><div class=\"bl-corner\"></div>");
    jQuery(".all-corners").append("<span class=\"tl-corner\"></span><span class=\"tr-corner\"></span><span class=\"br-corner\"></span><span class=\"bl-corner\"></span>");
    jQuery(".paging-control li a").append("<span class=\"tl-corner\"></span><span class=\"tr-corner\"></span><span class=\"br-corner\"></span><span class=\"bl-corner\"></span>");
    jQuery(".top-right-corner").append("<span class=\"tr-corner\"></span>");
    jQuery(".downloads").append("<div class=\"br-corner\"></div><div class=\"bl-corner\"></div>");

    /*
	This adds the "Print this list" link to the medications page. Because that link
	requires javascript to print, we only want it to show up for JS-enabled browsers.
     */
    jQuery("#print-meds p").html("<a href=\"#\" onclick=\"window.print();return false;\">Print this list.</a>");

    /*
	Page tools menu.
	The first function adds the "Print" link, which requires JavaScript to work.
	The second adds the necessary HTML for modal "E-mail this page" window and the
	triggers for the jqModal script.
     */
    if(jQuery("#page-tools")){
        jQuery("#page-tools li").append("<div id=\"email-form\" class=\"jqmWindow\" title=\""+document.title+"\"></div>");
        jQuery("#page-tools").prepend("<li><a href=\"#\" onclick=\"window.print();return false;\" id=\"print-link\">print</a></li>");
    }

    if(jQuery("#page-tools1")){
        jQuery("#page-tools1").append("<div id=\"refer-form\" class=\"jqmWindow\" title=\""+document.title+"\"></div>");
    }
    /*
	Various instances of showing and hiding things
     */
    // These are all in the medications/reminders/etc. pages
    jQuery(".edit-link a").click(function(){

            jQuery(this).parents(".single-item").toggleClass("edit");
            jQuery(this).parents(".single-med").toggleClass("edit");
            jQuery(this).parents(".med-wrapper").toggleClass("edit-child");
            jQuery(this).parents(".phr-items-wrapper").toggleClass("edit-child");

        return false;
    });
    jQuery(".cancel-edit").click(function(){
        jQuery(this).parents(".single-item").toggleClass("edit");
        jQuery(this).parents(".single-med").toggleClass("edit");
        jQuery(this).parents(".med-wrapper").toggleClass("edit-child");
        jQuery(this).parents(".phr-items-wrapper").toggleClass("edit-child");


        return false;
    });
    jQuery(".single-med .expand-link").click(function(){
        jQuery(this).parents(".single-med").toggleClass("open");
        var thisText = jQuery(this).text();
        if(thisText == "see more"){
            jQuery(this).text("see less");
        } else {
            jQuery(this).text("see more");
        }
        return false;
    });
    jQuery(".single-item .expand-link").click(function(){
        jQuery(this).parents(".single-item").toggleClass("open");
        var thisText = jQuery(this).text();
        if(thisText == "read more"){
            jQuery(this).text("close details");
        } else {
            jQuery(this).text("read more");
        }
        return false;
    });
    jQuery(".single-item .show-details").click(function(){
        jQuery(this).parents(".single-item").toggleClass("open");
        return false;
    });
    jQuery(".add-med a").click(function(){

            jQuery(this).parents(".med-wrapper").toggleClass("add-new-med");
            multipleClickCount=1;
        return false;
    });
    jQuery(".add-item a").click(function(){
        jQuery(this).parents(".phr-items-wrapper").toggleClass("add-new-item");
        return false;
    });
    jQuery(".cancel-add").click(function(){
        jQuery(this).parents(".med-wrapper").toggleClass("add-new-med");
        jQuery(this).parents(".phr-items-wrapper").toggleClass("add-new-item");
        multipleClickCount=0;

    });

    // Special engraving request field
    jQuery("#special-engraving-toggle").click(function(){
        jQuery("#special-engraving-request").toggle();
        return false;
    })

    // The size guide for the shop
    jQuery(".size-guide-toggle").click(function(){
        jQuery("#size-guide").toggle();
        return false;
    });

    // This opens and closes the MSA window
    jQuery("#msa-name a").click(function(){
        jQuery(this).parents("#msa").toggleClass("open");
    });

    // This shows the answers in the "Common Questions"
    if(jQuery("a.cq")){
        jQuery("a.cq").click(function(){
            var answer = "p#answer-"+this.id;
            jQuery(answer).toggle();
            return false;
        });
    }

    var alertBox = jQuery(".single-med .alert.fancy");
    if(alertBox != null){
        var alertHeight = jQuery(alertBox).height();
        var parentPadding = alertHeight + 10;
        jQuery(alertBox).parents(".single-med-header").css("position","relative");
        jQuery(alertBox).parents(".single-med-header").css("padding-top",parentPadding);
    }


    // Pop-up calendar windows in PHR
    popUpCal.setDefaults({
        autoPopUp: 'both', buttonImageOnly: true, buttonImage: '/images/static/calendar-fixed.png',
        dateFormat: 'MDY/', changeMonth: false, changeYear: false, closeAtTop: false,
        dayNames: ['S', 'M', 'T', 'W', 'T', 'F', 'S'],
        prevText: '<img src="/images/static/calendar_prev.png" alt="Go back" />',
        nextText: '<img src="/images/static/calendar_next.png" alt="Go back" />',
        yearRange: '-5:+5'
    });
    jQuery(".arrows-only").calendar();
    jQuery(".selects-only").calendar({changeMonth: true, changeYear: true, prevText: '', nextText: ''})
    jQuery(".invokeBoth").calendar({changeMonth: true, changeYear: true, prevText: '', nextText: ''})

    /* SHOPPING */

    /* set the correct state of the shopping home page for visitors with JavaScript */

    jQuery("#shop-banner-nav").css("display","block");
    var shopbanners = jQuery(".shop-home #right-banner").children(".right-banner-image");
    var shopmenuitems = jQuery("#shop-banner-nav").children("li");
    jQuery(shopbanners).css({ display:"none",marginBottom:"0" });
    if (shopbanners.length != 0) {
        jQuery(shopbanners[0]).css("display","block");
    }
    jQuery(shopmenuitems[0]).attr("class","active");

    jQuery("#shop-banner-nav li a").click(function(){
        jQuery(shopbanners).css({ display:"none" });
        jQuery(shopmenuitems).removeClass("active");
        var showBanner = jQuery(this).attr("href");
        jQuery(showBanner).css("display","block");
        jQuery(this).parent("li").addClass("active");
        return false;
    })

    if(jQuery(".product-gallery")){
        jQuery(".product-gallery ul").jqGalViewII();
    }


    if(jQuery("body.build-id")) {

        var radios = jQuery("#shopBuild :radio");
        var xr;
        for (xr in radios) {
            if (radios[xr].checked){
                var radioParentFieldset = jQuery(radios[xr]).parents("fieldset")[0];
                var radioParentLabel = jQuery(radios[xr]).parents("label")[0];
                jQuery(radioParentFieldset).addClass("completed").next().addClass("current");
                var radioName = jQuery(radioParentFieldset).children(".option-name")[0];
                if(radioParentFieldset.id == "style-options" || radioParentFieldset.id == "size-options"){
                    jQuery(radioParentLabel).css("border","1px solid #9ab6ce");
                }
                jQuery(radioParentLabel).css("color","#00447f");
            }
        }


        jQuery("#shopBuild label").click(function(){
            var optParent = jQuery(this).parents("fieldset")[0];
            jQuery(optParent).addClass("completed").removeClass("current").next().addClass("current");
            var optName = jQuery(optParent).children(".option-name")[0];
            if(optParent.id == "style-options" || optParent.id == "size-options"){
                jQuery(this).siblings().css("border-color","#eff8ff");
                jQuery(this).css("border-color","#9ab6ce");
            }
            if(optParent.id == "size-options") {
                jQuery("#shopBuild .buttons").toggle();
            }
            jQuery(this).css("color","#00447f");
        });

    }

    // Equalizing various columns

    jQuery(".change-log-options fieldset").vjustify();
    jQuery(".print-download-options fieldset").vjustify();
    jQuery(".home-left-sub").vjustify();
    jQuery(".msa-dash-sub").vjustify();

    // E-mail a friend modal window

    if(jQuery("#email-form")){
        var contextPath = location.protocol + '//' + location.host;
        var path = contextPath + '/common/emailFriendModal.htm';
        jQuery("#email-form").jqm({ajax: path, trigger: 'a#email-link', toTop:true});
    }
    jQuery(".email-friend-title").append("Email ");

    if(jQuery("#refer-form")){
        var contextPath = location.protocol + '//' + location.host;
        var path = contextPath + '/common/referFriendModal.htm';
        jQuery("#refer-form").jqm({ajax: path, trigger: 'a#refer-link', toTop:true});
    }
    jQuery(".refer-friend-title").append("Refer ");
    // 	Contact form
    //	Populating various form fields based on the content of other fields.
    jQuery(".shipping-choice").click(function(){
        var whichAdd = this.value;
        if(whichAdd != "new"){
            jQuery("#shipping-street").val(jQuery("#" + whichAdd + "-street").val());
            jQuery("#shipping-city").val(jQuery("#" + whichAdd + "-city").val());
            jQuery("#shipping-state").val(jQuery("#" + whichAdd + "-state").val());
            jQuery("#shipping-zipcode").val(jQuery("#" + whichAdd + "-zipcode").val());
        } else {
            jQuery("#shipping-street").val("");
            jQuery("#shipping-city").val("");
            jQuery("#shipping-state").val("");
            jQuery("#shipping-zipcode").val("");
        }
    });

    jQuery(".billing-choice").click(function(){
        var whichAdd = this.value;
        if(whichAdd != "new"){
            jQuery("#billing-street").val(jQuery("#" + whichAdd + "-street").val());
            jQuery("#billing-city").val(jQuery("#" + whichAdd + "-city").val());
            jQuery("#billing-state").val(jQuery("#" + whichAdd + "-state").val());
            jQuery("#billing-zipcode").val(jQuery("#" + whichAdd + "-zipcode").val());
        } else {
            jQuery("#billing-street").val("");
            jQuery("#billing-city").val("");
            jQuery("#billing-state").val("");
            jQuery("#billing-zipcode").val("");
        }
    });
});


/* code edited by manoj */

/*
	jQuery("#home-banner-nav").css("display","block");
	var homebanners = jQuery(".home-standard #right-banner01").children(".right-banner-image01");
	var homemenuitems = jQuery("#home-banner-nav").children("li");
	jQuery(homebanners).css({ display:"none",marginBottom:"0" });
	if (homebanners.length != 0) {
		jQuery(homebanners[0]).css("display","block");
	}
	jQuery(homemenuitems[0]).attr("class","active");


	jQuery("#home-banner-nav li a").click(function(){
		jQuery(homebanners).css({ display:"none" });
		jQuery(homemenuitems).removeClass("active");
		var homeBanner = jQuery(this).attr("href");
		jQuery(homeBanner).css("display","block");
		jQuery(this).parent("li").addClass("active");
		return false;
	})

jQuery(" .magnify").click(function(){
alert("manoj");
	jQuery(this).parents(".join-select-type").toggleClass("open");
	});

	jQuery(" p").click(function(str){
	alert("manoj");
	jQuery("str").toggle();
	return false;
	});
 */

jQuery(" .questions").click(function(){
    jQuery("#answer").toggle();
    return false;
});
jQuery(" .questions1").click(function(){
    jQuery("#answer1").toggle();
    return false;
});
jQuery(" .questions2").click(function(){
    jQuery("#answer2").toggle();
    return false;
});
jQuery(" .questions3").click(function(){
    jQuery("#answer3").toggle();
    return false;
});

/* upto here */


