/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

if(typeof(PUREXSAVESGREEN) === 'undefined') {
    var PUREXSAVESGREEN = {};
}

/* Document Ready Function */
$(document).ready(function(){

    $("a#go-homepage").bind('click',function(){
        PUREXSAVESGREEN.closeOverlay();
        return false;
    });

    PUREXSAVESGREEN.SendToFriend();


    /*
    $("form#purexContestSendToFriend").validate(
        {
            messages: "Required"
        }
    );
    */

    //PUREXSAVESGREEN.validateShare();

   // $("form#purexContestEntryForm").validate()
   // PUREXSAVESGREEN.validateShare();

/*
    $("form#purexContestSendToFriend").bind('submit',function(){
        //$(this).ajaxSubmit();
        PUREXSAVESGREEN.closeOverlay();
        return false;
    });
  */

    /* http://code.google.com/p/jquery-dynamic-form/ */
    /* http://sroucheray.org/blog/demos/jquery-dynamic-form/ */
    $("#send-to-friend-share").dynamicForm(
        "#plus", "#minus", {
            limit:5
        }
        );
    /* Share friend with winner */
    $("#share-friend").dynamicForm(
        "#plus", "#minus", {
            limit:3
        }
        );

});

PUREXSAVESGREEN.closeOverlay = function(){
    
   
    
    $(".modal-overlay",window.parent.document).remove();
    $(".modal-window",window.parent.document).remove();
 
    
}

PUREXSAVESGREEN.SendToFriend = function(){
    // $("form#purexContestSendToFriend").bind('submit',function(){
     $("form#purexContestSendToFriend").validate( {
         submitHandler: function(form){
             $(form).ajaxSubmit();
             thankYouUrl = siteBaseUrl + 'pages/thankyou';
             parent.location.replace( thankYouUrl );
             PUREXSAVESGREEN.closeOverlay();
         }
        
        //PUREXSAVESGREEN.closeOverlay();

     }
    );

   // $("form#purexContestSendToFriend").validate();
   return false;
}


PUREXSAVESGREEN.validateShare = function(){

$("form#purexContestEntryForm").validate(
    {
        submitHandler: function(form){
            console.log( 'Form submitted ');
            jQuery(form).ajaxSubmit();
        }
    }
);

}
