﻿    
    // NOTE!! : This code is for ask the experts carousel//
    $(function() {
	    $(".ask_the_experts_move").jCarouselLite({
		    visible: 4,
		    start: 0,
		    mouseWheel: true,
		    btnNext: ".asknext",
		    btnPrev: ".askprev",
		    speed: 400,
		    vertical: true
	    });
    });
    // end of NOTE!! : This code is for ask the experts carousel//
    
    var calendar = new CalendarPopup("calendar");
    calendar.setCssPrefix("Preg");
    
    var myDate=new Date();
    myDate.setDate(myDate.getDate()-1);
    var dates = myDate.toDateString().split(' ');
    var newdate = dates[1] + " " + dates[2] + ", " + dates[3];
    
    calendar.addDisabledDates(null,newdate);
    
    myDate=new Date();
    myDate.setMonth(myDate.getMonth() + 9);
    dates = myDate.toDateString().split(' ');
    newdate = dates[1] + " " + dates[2] + ", " + dates[3];
    
    calendar.addDisabledDates(newdate,null);
    
    function defaultAlertMsg(box, message)
    {
        $(box).modal({
		    close:false,
		    position: ["20%",],
		    overlayId:'modalPopupOverlay',
		    containerId:'modalPopup',
		    onShow: function (dialog) {
			    dialog.data.find('.message').append(message);
		    }
	    });
    }
    
    function validateDueDate(sender, args)
    {
        var ptrn = /^(([1-9]|0[1-9])|[12][0-9]|3[01])\/(([1-9]|0[1-9])|1[012])\/(19|20)\d\d$/;
        
        if(ptrn.test(args.Value))
        {
            var today = new Date();
            var othermonth = new Date();
            var otherday = new Date();
            
            var i = args.Value.lastIndexOf('/');
            var year = args.Value.substr(i+1);
            var j = args.Value.indexOf('/');
            var month = args.Value.substring(j+1,i) - 1;
            var day = args.Value.substring(0,j);
            otherday.setFullYear(year,month,day);
            
            othermonth.setMonth(othermonth.getMonth() + 9)
            
            if(otherday < today || otherday > othermonth)
            {
                defaultAlertMsg("#alert","Sorry, your pregnancy due date cannot be before today or after 9 months starting from today.<br /><br />Please check it and try again.");
                args.IsValid = false;
            }
            else
                args.IsValid = true;
        }
        else
        {
            defaultAlertMsg("#alert","The date you entered is not valid. Please check it and try again.");        
            args.IsValid = false;
        }
    }
    
    var theInt = null;
		var $crosslink, $navthumb;
		var curclicked = 0;

		theInterval = function(cur) {
		    clearInterval(theInt);

		    if (typeof cur != 'undefined')
		        curclicked = cur;

		    $(".stripNav ul li a").eq(curclicked).trigger('click');

		    theInt = setInterval(function() {

		        $navthumb.eq(curclicked).attr('src', 'images/main_page/active_but.png');
		        for (i = 0; i < 5; i++) {
		            if (i == curclicked)
		                continue;
		            $navthumb.eq(i).attr('src', 'images/main_page/but.png');
		        }

		        $(".stripNav ul li a").eq(curclicked).trigger('click');
		        curclicked++;
		        if (document.getElementById("ctl00_PageContentPlaceHolder_CarouselCount").value == curclicked)
		            curclicked = 0;

		    }, 6800);
		};

		$(function() {

		    $("#main-photo-slider").codaSlider();

		    $navthumb = $(".nav-thumb");
		    $crosslink = $(".cross-link");

		    $navthumb
			.click(function() {
			    var $this = $(this);
			    var index = $this.parent().attr('href').slice(1) - 1;

			    theInterval(index);

			    $this.attr('src', 'images/main_page/active_but.png');

			    var carcount = document.getElementById("ctl00_PageContentPlaceHolder_CarouselCount").value;
			    for (i = 0; i < carcount; i++) {
			        if (i == index)
			            continue;

			        $navthumb.eq(i).attr('src', 'images/main_page/but.png');
			    }

			    return false;
			});

		    theInterval();
		});
        