$(document).ready(function(){
	$(".logo").click(function(){
            window.location="./index.php";
	});
    var $closed=1;
    var $logIn_div_closed=1;
    $(".looker_div").live('click',function(){
            if($closed)	{
                    $(".wrapperTop").slideDown(1000,"easeInQuad");
                    $closed=0;
            }else{
                    $(".wrapperTop").slideUp(1000,"easeInQuad");
                    $closed=1;
            }
    });
    $("#prospecter_div").click(function(){
            window.location="prospect.php#section2";
    });

    $("#panelister_div").click(function(){
        //alert("JUNK");
          $.growlUI('Processing','We are processing your request..',10000,'5%');
          window.location="panelist.php";
       
    });
    
    $(document).keydown(function(e){
        var code = (e.keyCode ? e.keyCode : e.which);
     if(code == 13) { //Enter keycode
       if($logged_in==0)  $("#login_button").trigger("click");
     }
    });
    
    
    $("#login").submit(function(){
         $("#login_button").trigger("click");
        return false;
    })
    $("#login_button").click(function(){
       var uname=$("#userName").val();
       var pword=$("#password").val();
       var msg='';
       if(uname=="") msg="Please enter a User ID <br>";
       //if(pword=="") msg+="Please enter a Password";
       $(".ui-dialog-titlebar").removeClass("ui-widget-header");
       $(".ui-dialog-titlebar").removeClass("ui-corner-all");
       $(".ui-dialog-titlebar").css("color","#FFFFFF");
       $(".ui-dialog-titlebar").css("background-color","#646567");
       if(msg==""){
           //Display Message to let them know that we are logging in.
           $.growlUI('Processing','We are processing your request..',10000,'5%');
           //POST THE LOGIN IF GOOD THEN NAVIGATE IF BAD THEN NO GO.
           $.post("./functions.php?action=login",{uname:uname,pword:pword},function(data){
              //console.log(data);
              //exit();
              if(data!="") window.location="panelist.php";
              else{

                  $( ".error_msg" ).html("The userid or password you entered was incorrect");
                  $( ".error_msg" ).dialog("open");
              } 
           });
       }else{
           $( ".error_msg" ).html(msg);
           $( ".error_msg" ).dialog("open");
       }

    });
    $("#old").click(function(){
       $(this).removeClass("error"); 
    });
    $("#new").click(function(){
       $(this).removeClass("error"); 
    });
    $("#confirm").click(function(){
       $(this).removeClass("error"); 
    });
    $("#chage_password").click(function(){
       var pword=$("#old").val();
       var new_pword=$("#new").val();
       var confirm=$("#confirm").val();
       var msg='';
       if(pword==""){
           msg="Please enter a Password.<br>";
           $("#old").addClass("error");
       } 
       if(new_pword=="") {
           msg+="Please enter a New Password. <br>";
           $("#new").addClass("error");
       }
       if(new_pword.length<7) {
           msg+="Your password must be at least 7 characters long. <br>";
           $("#new").addClass("error");
       }
       if(confirm==""){
           msg+="Please enter confirmation Password. <br>";
           $("#confirm").addClass("error");
       }
       if(new_pword!=confirm) {
           msg+="Passwords do not match. <br>"
           $("#new").addClass("error");
           $("#confirm").addClass("error");
       }
       if(pword==new_pword) {
           msg+="Your old password and new password are the same. <br>";
           $("#new").addClass("error");
           $("#confirm").addClass("error");
       }
       $(".ui-dialog-titlebar").removeClass("ui-widget-header");
       $(".ui-dialog-titlebar").removeClass("ui-corner-all");
       $(".ui-dialog-titlebar").css("color","#FFFFFF");
       $(".ui-dialog-titlebar").css("background-color","#646567");
       if(msg==""){
           //Display Message to let them know that something is happening.
            $.growlUI('Processing','We are processing your request..',3000,'5%');
           //POST THE LOGIN IF GOOD THEN NAVIGATE IF BAD THEN NO GO.
           $.post("./functions.php?action=change_password",{password:pword,newPassword:new_pword},function(data){
              //console.log(data);
              if(data=='Success'){
                  $( ".error_msg" ).html("Password successfully changed <input type=hidden id=err_action value='./panelist.php'/>");
                  $( ".error_msg" ).dialog( 'option', 'title', 'Success');
                  $( ".error_msg" ).dialog("open");
              }else{
                  $( ".error_msg" ).html(data);
                  $( ".error_msg" ).dialog("open");
              }

           });
       }else{
           $( ".error_msg" ).html(msg);
           $( ".error_msg" ).dialog("open");
       }

    });
     $("#lname").click(function(){
       $(this).removeClass("error"); 
    });
     $("#email").click(function(){
       $(this).removeClass("error"); 
    });
     $("#homePhone").click(function(){
       $(this).removeClass("error"); 
    });
     $("#cellPhone").click(function(){
       $(this).removeClass("error"); 
    });
     $("#street").click(function(){
       $(this).removeClass("error"); 
    });
     $("#city").click(function(){
       $(this).removeClass("error"); 
    });
     $("#state").click(function(){
       $(this).removeClass("error"); 
    });
     $("#zip").click(function(){
       $(this).removeClass("error"); 
    });

    $("#save_profile").click(function(){
        //var fname=$.trim($("#fname").val());
        var lname=$.trim($("#lname").val());
        var email=$.trim($("#email").val());
        var home=$.trim($("#homePhone").val());
        var cell=$.trim($("#cellPhone").val());
        var street=$.trim($("#street").val());
        var city=$.trim($("#city").val());
        var state=$.trim($("#state").val());
        var zip=$.trim($("#zip").val());
        var msg="";
        var emailReg = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/;

        if (lname=="") {
            msg="Plese enter a last name.<br>";
            $("#lname").addClass("error");
        }
        if(email=="") {
            msg+="Please enter an email.<br>";
            $("#email").addClass("error");
        }
        else if(!emailReg.test(email)) {
            msg+="Please enter a valid email.<br>";
            $("#email").addClass("error");
        }
        if(street=="") {
            msg+="Please enter a street.<br>";
            $("#street").addClass("error");
        }
        if(city=="") {
            msg+="Please enter a city.<br>";
            $("#city").addClass("error");
        }
        if(state=="") {
            msg+="Please enter a state.<br>";
            $("#state").addClass("error");
        }
        if(zip=="") {
            msg+="Please enter a zip.<br>";
            $("#zip").addClass("error");
        }

        if(msg==""){
            //Display Message to let them know that something is happening.
            $.growlUI('Processing','We are processing your request..',3000,'5%');
            $.post("./functions.php?action=change_profile",{lname:lname,email:email,home:home,cell:cell,street:street,city:city,state:state,zip:zip},function(data){
              //console.log(data);
              if(data=='Success'){
                  $( ".error_msg" ).html("Profile successfully changed <input type=hidden id=err_action value='./panelist.php'/>");
                  $( ".error_msg" ).dialog( 'option', 'title', 'Success');
                  $( ".error_msg" ).dialog("open");
              }else{
                  $( ".error_msg" ).html("An Error has occured. "+data+" Your profile has not been updated.");
                  $( ".error_msg" ).dialog("open");
              }

           });
        }else{
            $( ".error_msg" ).html(msg);
            $( ".error_msg" ).dialog("open");
        }


    });

    $(".contentWrap").height($(document).height());

    //SLIDER INFO
    $(".orangeBoxHover").hover(
      function () {
            $(".whiteBodyHover").css('color','#f06e27');
      }, 
      function () {
            $(".whiteBodyHover").css('color','#ffffff');
      }
    );



    /**
     * Most jQuery.localScroll's settings, actually belong to jQuery.ScrollTo, check it's demo for an example of each option.
     * @see http://flesler.demos.com/jquery/scrollTo/
     * You can use EVERY single setting of jQuery.ScrollTo, in the settings hash you send to jQuery.LocalScroll.
     */

    // The default axis is 'y', but in this demo, I want to scroll both
    // You can modify any default like this
    $.localScroll.defaults.axis = 'x';

    // Scroll initially if there's a hash (#something) in the url 
    $.localScroll.hash({
            target: '.slider', // Could be a selector or a jQuery object too.
            queue:true,
            //offset:-200,
            duration:500
    });

    /**
     * NOTE: I use $.localScroll instead of $('#navigation').localScroll() so I
     * also affect the >> and << links. I want every link in the page to scroll.
     */
    $.localScroll({
            target: '.slider', // could be a selector or a jQuery object too.
            //queue:true,
            //hash:true,
            easing:'easeInQuad',
            //offset:-200,
            duration:1000,
            onBefore:function( e, anchor, $target ){
                    // The 'this' is the settings object, can be modified
                    //$(".slider").height($target.height());
                    $('html, body').animate({scrollTop: 0}, 'slow');
            },
            onAfter:function( anchor, settings ){
                    // The 'this' contains the scrolled element (#content)

            }
    });
    $(".education").click(function(){
            $("#prospector_ed").show("slide",{direction: 'right'},1000);
            
            $("body").attr("style","background-image:none;");
            $(".slider").height("1700");
            $("object").remove();
             setTimeout( function() {
                            $("#prospector_V_edit").show("slide",{direction: 'down'},500);
                    }, 900 );
             setTimeout( function() {
                            $("#prospector_H_edit").show("slide",{direction: 'right'},500);
                    }, 1200 );
            
    });
    
    $(".link").click(function(){
            setTimeout( function() {
                            $("body").attr("style","");
                    }, 500 );
                    $(".slider").height("1700");
    });

    $(".survey_link").click(function(){
            setTimeout( function() {
                    $( "#survey_div" ).dialog("open");
            }, 800 );
            $('html, body').animate({scrollTop: 0}, 'slow');
            return false;
    });
    $( "#survey_div" ).dialog({
                    autoOpen:false,
                    title:"<a href='#' id='dialogBack'>Back to Prospect'er</a>",
                    modal: false,
                    width:'800',
                    draggable:false,
                    close: function(event, ui) {window.location="prospect.php#section2";}
            });
    $("#dialogBack").click(function(){
            $( "#survey_div" ).dialog("close");
            $('#section2').localScroll({
                    duration:1000
                    });
            window.location.reload();
            return false;
    });

    $( ".error_msg" ).dialog({
                    autoOpen:false,
                    title:"ERROR",
                    modal: true,
                    width:'auto',
                    height:'auto',
                    draggable:false,
                    resizable:false,
                    buttons:{
                        Ok: function(event, ui) {
                            if($("#err_action").length >0){
                                var action=$("#err_action").val();
                                $(this).dialog('close')
                                window.location=action;
                            }else $(this).dialog('close')
                        }
                    }

            });

     $("#whatIsPlugin").live('click',function(){
            $(".ui-dialog-titlebar").removeClass("ui-widget-header");
            $(".ui-dialog-titlebar").removeClass("ui-corner-all");
            $(".ui-dialog-titlebar").css("color","#FFFFFF");
            $(".ui-dialog-titlebar").css("background-color","#646567");
            $( "#whatIsDesc" ).dialog('open');
     });
     $( "#whatIsDesc" ).dialog({
                    autoOpen:false,
                    title:"what is the web activity add-on?",
                    modal: true,
                    width:'900',
                    height:'auto',
                    draggable:false,
                    resizable:false,
                    buttons:{
                        Ok: function(event, ui) {
                            $(this).dialog('close')
                        }
                    }

            });
            
    $("#privacy_agreement_link").live('click',function(){
            $(".ui-dialog-titlebar").removeClass("ui-widget-header");
            $(".ui-dialog-titlebar").removeClass("ui-corner-all");
            $(".ui-dialog-titlebar").css("color","#FFFFFF");
            $(".ui-dialog-titlebar").css("background-color","#646567");
            $( "#privacy_agreement" ).dialog('open');
            return false;
     });
    $( "#privacy_agreement" ).dialog({
                    autoOpen:false,
                    title:"privacy agreement",
                    modal: true,
                    width:'auto',
                    height:'auto',
                    draggable:false,
                    resizable:false,
                    position:'top',
                    buttons:{
                        Ok: function(event, ui) {
                             $(this).dialog('close')
                        }
                    }

   });
   $("#panelist_agreement_link").live('click',function(){
            $(".ui-dialog-titlebar").removeClass("ui-widget-header");
            $(".ui-dialog-titlebar").removeClass("ui-corner-all");
            $(".ui-dialog-titlebar").css("color","#FFFFFF");
            $(".ui-dialog-titlebar").css("background-color","#646567");
            $( "#panelist_agreement" ).dialog('open');
            return false;
     });
    $( "#panelist_agreement" ).dialog({
                    autoOpen:false,
                    title:"panelist agreement",
                    modal: true,
                    width:'auto',
                    height:'auto',
                    draggable:false,
                    resizable:false,
                    position:'top',
                    buttons:{
                        Ok: function(event, ui) {
                             $(this).dialog('close')
                        }
                    }

   });
   
    $(window).resize(function(){
      $('.container').css({
            position:'absolute',
            left: ($(window).width() - $('.container').outerWidth())/2
        });
    });
    
    $(window).resize();
    
    $("#logout").live('click',function(){
       window.location="functions.php?action=logout"; 
    });
    $("#edit_profile").live("click",function(){ 
      //  $("body").attr("style","background-image:none;");
       // $(".slider").height('1000');
       
       
        
        $("#edit_stripH").show('slide',1300);        
        setTimeout( function() {
            $("#edit_V_line").show("slide",{direction: 'up'},500);
            //alert($(document).height() + " X "+$(window).height());
            if($(window).height()<=768) var minusHeight=450;
            else var minusHeight=325;
            $('html, body').animate({ 
               scrollTop: ($(document).height()-minusHeight)-$(window).height()}, 
               1000, 
               "easeOutQuint"
            );
        }, 1200 );
        setTimeout( function() {
            $("#edit_H_line_top").show("slide",{direction: 'left'},500);
        }, 1700 );
        
    });
    $(".cancel").live('click',function(){
        
        $("#edit_H_line_top").hide("slide",{direction: 'left'},'fast');
        setTimeout( function() {
            $("#edit_V_line").hide("slide",{direction: 'up'},'fast');
          //  $(".slider").height('1700');
        }, 200 );
        setTimeout( function() {
           $("#edit_stripH").hide('slide',1000);
          // $("body").attr("style","background-image:url(./images/liquidBg.png); background-repeat:no-repeat; background-position:bottom;");
        }, 400 );
        
        
     //  $("#profile_info").show('slow');
    });
});
	
function answer_question(){
    alert("Answered");
    return false;
}
