$(document).ready(function(){ 
    // $("#disabilityform").formToWizard({submitButton:"SendEval"});
    $("#upperright").flashembed("flaghead2.swf"); 
    $("ul.sf-menu").superfish({ 
        animation: {height:'show'},   // slide-down effect without fade-in 
        delay:     1200               // 1.2 second delay on mouseout 
    }); 
    $('#coda-slider-1').codaSlider({
        dynamicTabs:false,
        dynamicArrowLeftText: "&#171; Previous",
        dynamicArrowRightText: "Next &#187;",
        autoHeight:false,
        autoSlide:false
    });
    
    $('#example1').bxSlider({
            mode: 'slide',
            speed: 250,
            wrapper_class: 'example1_container'
    });
    
    if($.browser.msie){
        $("div.example1_container").css("width", "658px");
        $("div.panes div").css({"width":"588px"})
       // $("ul.tabs").css({"width":"590px"})
        
        
    }else{
        $("div.example1_container").css("width", "651px");
    }
    
    $("input[name=working]").click(function(){
        if ($("input[name=working]:checked").val() == 'Yes')
        {
            //$("#sub1").show();
            $("#sub1").css("display", "block");
        
        }
        else 
        {
             //$("#sub1").hide();
             $("#sub1").css("display", "none");
        }

    });   
    $("input[name=applied]").click(function(){
        if ($("input[name=applied]:checked").val() == 'Yes')
        {
            $("#sub2").show();
        
        }
        else 
        {
             $("#sub2").hide();
        }

    });   
    $("input[name=denied]").click(function(){
        if ($("input[name=denied]:checked").val() == 'Yes')
        {
            $("#sub3").css("display", "block");
        
        }
        else 
        {
             $("#sub3").css("display", "none");
        }

    });
    
    $('.prev, .next, .send').hover(function() {
          $(this).addClass('hover');
        }, function() {
          $(this).removeClass('hover');
    });
    
    $("input[name=zip]").change(function(){
    
            var zip = $(this).val();
            //alert(zip);
            if(zip.length == 5)
            {
                //alert("5 chars");
            
             $.get("getcity.php", { postalcode: zip},
               function(data){               
                 var state = data.postalCodes[0].adminCode1;
                 var city = data.postalCodes[0].placeName;
                 $("#city").val(city);
               }, "json");
          }
    });
    
    $("#state, #city").attr("readonly", "true");
    // get container for the wizard and initialize its exposing
    var wizard = $("#wizard").expose({color: '#789', lazy: true});
 
    // enable exposing on the wizard
    wizard.click(function() {
        //$(this).expose().load();
    });
    
    // select the overlay element - and "make it an overlay"
      var overlay =  $("#facebox").overlay({
         
            // custom top position
            top: 272,
         
            // some expose tweaks suitable for facebox-looking dialogs
            expose: {
         
                // you might also consider a "transparent" color for the mask
                color: '#999999',
         
                // load mask a little faster
                loadSpeed: 200,
         
                // highly transparent
                opacity: 0.5
            },
         
            // disable this for modal dialog-type of overlays
            closeOnClick: false,
         
            // we want to use the programming API
            api: true
         
        // load it immediately after the construction
        });
 
    $("form[name=evalwizard]").submit(function(){
    
        // var errors = new Array();
        // var requiredvals = new Array("FName","LName","Email","zip","Phone");
        
        // for(req in requiredvals)
        // {
            // var val = "input[name="+req+"]"
            // var tmp = $(val);
            // var tmpval = tmp.val();
            // //alert(zipval.length);
            // if(tmpval.length == 0)
            // {
                // tmp.addClass("required");
                // //return false;
                // errors.push(req);
            // }
        
        
        // }
        // // // // everything is ok. remove possible red highlight from the terms
        // zipcode.removeClass("required");
        
         var errortext = "";
         $("input.input").removeClass("required");
         $("input.input").each(function(){
            // alert($(this).val());
             var req = $(this).val();
             var reqtitle = $(this).attr("title");
             if(req.length == 0)
             {
                 errortext += "Missing Field:<b>"+ reqtitle + "</b><br />";
                 $(this).addClass("required");
                
             }
            
        
         });
        
         if(errortext.length > 0)
         {
             $("#missing").html("Please review the list below and fill in the missing fields before submitting<br /><br />" + errortext);
             overlay.load();
             return false;
         }

        return true;

    
    });
 
    // enable tabs that are contained within the wizard
    $("ul.tabs", wizard).tabs("div.panes > div", function(event, index) {
 
        /* now we are inside the onBeforeClick event */
 
        // // ensure that the "terms" checkbox is checked.
        // var terms = $("#terms");
        // if (index > 0 && !terms.get(0).checked)  {
            // terms.parent().addClass("error");
 
            // // when false is returned, the user cannot advance to the next tab
            // return false;
        // }
    });
 
    
    //$("button").attr("type", "button");
    // get handle to the tabs API
    var api = $("ul.tabs", wizard).tabs(0);
 
    // "next tab" button
    $("button.next", wizard).click(function() {
        api.next();
    });
 
    // "previous tab" button
    $("button.prev", wizard).click(function() {
        api.prev();
    });
       
}); 
