﻿$(document).ready(formLoaded);

function formLoaded() {
        
    RequiredValid = new Validate("Required", ".Required", Required);
    EmailValid = new Validate("Email", ".Email", Email);
    Password = new Validate("Password", ".password", ValidPassword);
    $('.offertype').find('input[type=checkbox]').bind("click", chkOfferType);
    var offerType = $('.offertype')
    for (var i = 0; i < offerType.length; i++) {
        var Chkcnt = 0;
        var chkbox = $(offerType[i]).find('input[type=checkbox]')
        Chkcnt = chkbox.filter(':checked').length;
        if (Chkcnt >= 1) {
            chkbox.not(':checked').attr("disabled", true);
        }
        else {
            chkbox.not(':checked').removeAttr("disabled");
        }
    }
    if ($('#ctl00_ContentPlaceHolder1_gvBenefits').length > 0) {
        $('#ctl00_ContentPlaceHolder1_gvBenefits').FreezePanes(1,1);
    }
    //for back end pages
    $("a[id*=lnkSave]").bind("click", Fromvalidation)
    //for frontend pages
    $("input[id*=btnSubmit]").bind("click", Fromvalidation)
    
    //For send password link
    $("input[id*=btnsend]").bind("click", Fromvalidation)
     if($('.Eventfeesdetail').length > 0){
        $('.Eventfeesdetail').FreezePanes(1, 1);
    }
    
	$("ul.subnav").parent().wrapInner("<span></span>"); //Only shows drop down trigger when js is enabled (Adds empty span tag after ul.subnav*)

	$("ul.topnav li span").hover(NavMenu).hover(function() {
		$(this).addClass("subhover"); //On hover over, add class "subhover"
	}, function(){	//On Hover Out
		$(this).removeClass("subhover"); //On hover out, remove class "subhover"
    });
}
function Fromvalidation() {    
    if (RequiredValid.Validation() == false) {
        RequiredValid.msg();
        return false;
    }
    if (EmailValid.Validation() == false) {
        EmailValid.msg();
        return false;
    }
    if (Password.Validation() == false) {
        Password.msg();
        return false;
    }
}

function NavMenu(){
    //Following events are applied to the subnav itself (moving subnav up and down)
	$(this).parent().find("ul.subnav").slideDown('fast').show(); //Drop down the subnav on click

	$(this).parent().hover(function() {
	}, function(){
		$(this).parent().find("ul.subnav").slideUp('slow'); //When the mouse hovers out of the subnav, move it back up
	});
}

function chkOfferType() {
    var Chkcnt = 0;
    // used to get all Chkbox inside the ChkboxList
    var chkboxlist = $(this).parents('.offertype').find('input[type=checkbox]');

    Chkcnt = chkboxlist.filter(':checked').length;

    if (Chkcnt >= 1) {
        chkboxlist.not(':checked').attr("disabled", true);
    }
    else {
        chkboxlist.not(':checked').removeAttr("disabled");
    }
}


