/* 

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(){
        $(this).height(maxHeight + "px");
        if (this.offsetHeight>maxHeight) {
            $(this).height((maxHeight-(this.offsetHeight-maxHeight))+"px");
        }
    });
};





//	jQuery BEHAVIORS

$(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.
     */
    $("#records-tab").hover(
    function(){
        $(this).toggleClass("iehover");
    },
    function(){
        $(this).toggleClass("iehover");
    }
);
    /*
	These are the various places that we're adding rounded corners.
     */
    $(".side-module").append("<div class=\"tl-corner\"></div><div class=\"tr-corner\"></div><div class=\"br-corner\"></div><div class=\"bl-corner\"></div>");
    $(".all-corners").append("<span class=\"tl-corner\"></span><span class=\"tr-corner\"></span><span class=\"br-corner\"></span><span class=\"bl-corner\"></span>");
    $(".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>");
    $(".top-right-corner").append("<span class=\"tr-corner\"></span>");
    $(".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.
     */
    $("#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($("#page-tools")){
        $("#page-tools li").append("<div id=\"email-form\" class=\"jqmWindow\" title=\""+document.title+"\"></div>");
        $("#page-tools").prepend("<li><a href=\"#\" onclick=\"window.print();return false;\" id=\"print-link\">print</a></li>");
    }

    if($("#page-tools1")){
        $("#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
    $(".edit-link a").click(function(){
       
            $(this).parents(".single-item").toggleClass("edit");
            $(this).parents(".single-med").toggleClass("edit");
            $(this).parents(".med-wrapper").toggleClass("edit-child");
            $(this).parents(".phr-items-wrapper").toggleClass("edit-child");
        
        return false;
    });
    $(".cancel-edit").click(function(){
        $(this).parents(".single-item").toggleClass("edit");
        $(this).parents(".single-med").toggleClass("edit");
        $(this).parents(".med-wrapper").toggleClass("edit-child");
        $(this).parents(".phr-items-wrapper").toggleClass("edit-child");
       

        return false;
    });
    $(".single-med .expand-link").click(function(){
        $(this).parents(".single-med").toggleClass("open");
        var thisText = $(this).text();
        if(thisText == "see more"){
            $(this).text("see less");
        } else {
            $(this).text("see more");
        }
        return false;
    });
    $(".single-item .expand-link").click(function(){
        $(this).parents(".single-item").toggleClass("open");
        var thisText = $(this).text();
        if(thisText == "read more"){
            $(this).text("close details");
        } else {
            $(this).text("read more");
        }
        return false;
    });
    $(".single-item .show-details").click(function(){
        $(this).parents(".single-item").toggleClass("open");
        return false;
    });
    $(".add-med a").click(function(){
        
            $(this).parents(".med-wrapper").toggleClass("add-new-med");
            multipleClickCount=1;
        return false;
    });
    $(".add-item a").click(function(){
        $(this).parents(".phr-items-wrapper").toggleClass("add-new-item");
        return false;
    });
    $(".cancel-add").click(function(){
        $(this).parents(".med-wrapper").toggleClass("add-new-med");
        $(this).parents(".phr-items-wrapper").toggleClass("add-new-item");
        multipleClickCount=0;

    });

    // Special engraving request field
    $("#special-engraving-toggle").click(function(){
        $("#special-engraving-request").toggle();
        return false;
    })

    // The size guide for the shop
    $(".size-guide-toggle").click(function(){
        $("#size-guide").toggle();
        return false;
    });

    // This opens and closes the MSA window
    $("#msa-name a").click(function(){
        $(this).parents("#msa").toggleClass("open");
    });
	
    // This shows the answers in the "Common Questions"
    if($("a.cq")){
        $("a.cq").click(function(){
            var answer = "p#answer-"+this.id;
            $(answer).toggle();
            return false;
        });
    }

    var alertBox = $(".single-med .alert.fancy");
    if(alertBox != null){
        var alertHeight = $(alertBox).height();
        var parentPadding = alertHeight + 10;
        $(alertBox).parents(".single-med-header").css("position","relative");
        $(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'
    });
    $(".arrows-only").calendar();
    $(".selects-only").calendar({changeMonth: true, changeYear: true, prevText: '', nextText: ''})
    $(".invokeBoth").calendar({changeMonth: true, changeYear: true, prevText: '', nextText: ''})
	
    /* SHOPPING */
	
    /* set the correct state of the shopping home page for visitors with JavaScript */

    $("#shop-banner-nav").css("display","block");
    var shopbanners = $(".shop-home #right-banner").children(".right-banner-image");
    var shopmenuitems = $("#shop-banner-nav").children("li");
    $(shopbanners).css({ display:"none",marginBottom:"0" });
    if (shopbanners.length != 0) {
        $(shopbanners[0]).css("display","block"); 
    }
    $(shopmenuitems[0]).attr("class","active");
	
    $("#shop-banner-nav li a").click(function(){
        $(shopbanners).css({ display:"none" });
        $(shopmenuitems).removeClass("active");
        var showBanner = $(this).attr("href");
        $(showBanner).css("display","block");
        $(this).parent("li").addClass("active");
        return false;
    })

    if($(".product-gallery")){
        $(".product-gallery ul").jqGalViewII();		
    }

	
    if($("body.build-id")) {

        var radios = $("#shopBuild :radio");
        var xr;
        for (xr in radios) {
            if (radios[xr].checked){
                var radioParentFieldset = $(radios[xr]).parents("fieldset")[0];
                var radioParentLabel = $(radios[xr]).parents("label")[0];
                $(radioParentFieldset).addClass("completed").next().addClass("current");
                var radioName = $(radioParentFieldset).children(".option-name")[0];
                if(radioParentFieldset.id == "style-options" || radioParentFieldset.id == "size-options"){
                    $(radioParentLabel).css("border","1px solid #9ab6ce");
                }
                $(radioParentLabel).css("color","#00447f");
            }
        }
		
	
        $("#shopBuild label").click(function(){
            var optParent = $(this).parents("fieldset")[0];
            $(optParent).addClass("completed").removeClass("current").next().addClass("current");
            var optName = $(optParent).children(".option-name")[0];
            if(optParent.id == "style-options" || optParent.id == "size-options"){
                $(this).siblings().css("border-color","#eff8ff");
                $(this).css("border-color","#9ab6ce");
            }
            if(optParent.id == "size-options") {
                $("#shopBuild .buttons").toggle();
            }
            $(this).css("color","#00447f");
        });
		
    }
	
    // Equalizing various columns
	
    $(".change-log-options fieldset").vjustify();
    $(".print-download-options fieldset").vjustify();
    $(".home-left-sub").vjustify();
    $(".msa-dash-sub").vjustify();
	
    // E-mail a friend modal window 
	
    if($("#email-form")){
        var contextPath = location.protocol + '//' + location.host;
        var path = contextPath + '/common/emailFriendModal.htm';
        $("#email-form").jqm({ajax: path, trigger: 'a#email-link', toTop:true});
    }
    $(".email-friend-title").append("Email "); 
	
    if($("#refer-form")){
        var contextPath = location.protocol + '//' + location.host;
        var path = contextPath + '/common/referFriendModal.htm';
        $("#refer-form").jqm({ajax: path, trigger: 'a#refer-link', toTop:true});
    }
    $(".refer-friend-title").append("Refer "); 
    // 	Contact form
    //	Populating various form fields based on the content of other fields.
    $(".shipping-choice").click(function(){
        var whichAdd = this.value;
        if(whichAdd != "new"){
            $("#shipping-street").val($("#" + whichAdd + "-street").val());
            $("#shipping-city").val($("#" + whichAdd + "-city").val());
            $("#shipping-state").val($("#" + whichAdd + "-state").val());
            $("#shipping-zipcode").val($("#" + whichAdd + "-zipcode").val());
        } else {
            $("#shipping-street").val("");
            $("#shipping-city").val("");
            $("#shipping-state").val("");
            $("#shipping-zipcode").val("");
        }
    });
	
    $(".billing-choice").click(function(){
        var whichAdd = this.value;
        if(whichAdd != "new"){
            $("#billing-street").val($("#" + whichAdd + "-street").val());
            $("#billing-city").val($("#" + whichAdd + "-city").val());
            $("#billing-state").val($("#" + whichAdd + "-state").val());
            $("#billing-zipcode").val($("#" + whichAdd + "-zipcode").val());
        } else {
            $("#billing-street").val("");
            $("#billing-city").val("");
            $("#billing-state").val("");
            $("#billing-zipcode").val("");
        }
    });
});


/* code edited by manoj */
	
/*
	$("#home-banner-nav").css("display","block");
	var homebanners = $(".home-standard #right-banner01").children(".right-banner-image01");
	var homemenuitems = $("#home-banner-nav").children("li");
	$(homebanners).css({ display:"none",marginBottom:"0" });
	if (homebanners.length != 0) {
		$(homebanners[0]).css("display","block"); 
	}
	$(homemenuitems[0]).attr("class","active");
	
	
	$("#home-banner-nav li a").click(function(){
		$(homebanners).css({ display:"none" });
		$(homemenuitems).removeClass("active");
		var homeBanner = $(this).attr("href");
		$(homeBanner).css("display","block");
		$(this).parent("li").addClass("active");
		return false;
	})
	
$(" .magnify").click(function(){
alert("manoj");
	$(this).parents(".join-select-type").toggleClass("open");		
	});
	
	$(" p").click(function(str){	
	alert("manoj");
	$("str").toggle();
	return false;
	});
 */

$(" .questions").click(function(){
    $("#answer").toggle();
    return false;
});
$(" .questions1").click(function(){
    $("#answer1").toggle();
    return false;
});
$(" .questions2").click(function(){
    $("#answer2").toggle();
    return false;
});
$(" .questions3").click(function(){
    $("#answer3").toggle();
    return false;
});
	
/* upto here */
	
