﻿$(function() {
    var countdown = {
        init: function() {
            countdown.remaining = countdown.max - $(countdown.obj).val().length;
            if (countdown.remaining > countdown.max) {
                $(countdown.obj).val($(countdown.obj).val().substring(0, countdown.max));
            }
            $(countdown.obj).siblings(".remaining").html(countdown.remaining + " characters remaining.");
        },
        max: null,
        remaining: null,
        obj: null
    };
    $(".countdown").each(function() {
        $(this).focus(function() {
            var c = $(this).attr("class");
            countdown.max = parseInt(c.match(/limit_[0-9]{1,}_/)[0].match(/[0-9]{1,}/)[0]);
            countdown.obj = this;
            iCount = setInterval(countdown.init, 1000);
        }).blur(function() {
            countdown.init();
            clearInterval(iCount);
        });
    });
});

$(document).ready(function() {

    maxWidth = 180;
    minWidth = 80;

    $(".recipe_rating_popup").mouseenter(function(e) {
        if ($.browser.msie) {
        } else {
            $(this).addClass("recipe_rating_popup_rollover");
            $(this).stop().animate({ width: maxWidth + "px" }, { queue: false, duration: 400 });
        }
    }).mouseleave(function(e) {
        if ($.browser.msie) {
        } else {
            $(this).stop().animate({ width: minWidth + "px" }, { queue: false, duration: 100 });
            $(this).removeClass("recipe_rating_popup_rollover");
        }
    });

    $(".recipe_button").click(function(e) {
        if ($.browser.msie) {
            $(".recipe_rating_popup").fadeToggle(500);
        } else {
        }
    });

    jQuery.fn.fadeToggle = function(speed, easing, callback) {
        return this.animate({ opacity: 'toggle' }, speed, easing, callback);
    };

    // addition for the rollover effect on the arrows
    $("#recipesearch .search").hover(function() {
        $(this).attr("src", "../../images/search_btn_over.gif");
        }, function() {
        $(this).attr("src", "../../images/search_btn.gif");
    });

    $("#resultsnav .arrowright").hover(function() {
        $(this).attr("src", "../images/arrow_over.png");
    }, function() {
        $(this).attr("src", "../images/arrow.png");
    });

    $("#resultsnav .arrowleft").hover(function() {
        $(this).attr("src", "../images/arrow_left_over.png");
    }, function() {
        $(this).attr("src", "../images/arrow_left.png");
    });

    
    
});

$(document).ready(function () {
    $('.registerSubmit').unbind('click');
    $('.registerSubmit').click(function () {
        var validationGroup = 'joinNews';
        if ($(this).next().is('input[type=hidden]') == true)
            validationGroup = $(this).next().val();
        if (Page_ClientValidate(validationGroup) == true) {
        } else {
            /* display error message */
            alert('One or more fields is invalid, please check your information');
        }
    });
});

$(document).ready(function() {        
        $(".tipArea").hide();
        $(".tipShadow").hide();

        $(".tip").mouseenter(function (e) {
            $(this).children(".tipArea").stop(true,true).show('1000', function (e) {} );        
        });
        
         $(".tip").mouseleave(function(e) {
             $(".tipArea").stop(true, true).hide();            
        });
     });

     $(document).ready(function() {
         $('.registerSubmit').click(function() {
         if (Page_ClientValidate('joinNews') == true) {
             } else {
                 /* display error message */
                 alert('One or more fields is invalid, please check your information');
             }
         });
     });

     $(document).ready(function() {
         $('.registerSubmit2').click(function() {
         if (Page_ClientValidate('submitMember') == true) {
             } else {
                 /* display error message */
                 alert('One or more fields is invalid, please check your information');
             }
         });
     });     

//     function ValidateGender() {
//         if (getCheckedValue($('#<%= rbMale.ClientID %>')) == 'rbMale' || getCheckedValue($('#<%= rbFemale.ClientID %>')) == 'rbFemale')
//         {
//             window.alert("gender passed");
//             $('#spanGender').hide(); return true;
//         }
//         else {
//             window.alert("gender failed");
//             $('#spanGender').show(); return false;             
//         }                
//     }

// return the value of the radio button that is checked
// return an empty string if none are checked, or
// there are no radio buttons
function getCheckedValue(radioObj) {
	if (!radioObj)
		return "";
	var radioLength = radioObj.length;
	if (radioLength == undefined)
	if (radioObj.checked)
		return radioObj.value;
	else
		return "";
	for (var i = 0; i < radioLength; i++) {
		if (radioObj[i].checked) {
			return radioObj[i].value;
		}
	}
	return "";
}
