/* Add event handler to display pop up list for selecting folders */
function SaveToScrapbook( )
{
   /* Bind click events for displaying and hiding folder list. */
   $('div.stsb div.stsbClosedLinktitle').bind('click', function(){showList( $(this).parent('div.stsb'));});
   $('div.stsb div.stsbOpenLinktitle').bind('click', function(){hideList( $(this).parent('div.stsb'));});
   
   /*Change the background color to white when mouse over.*/
  // $('div.stsb div.stsbFolderList ul li').hover(
      //  function(){ $(this).css('background', '#FFFFFF'); },
      //  function(){ $(this).css('background','#F8EEF9');  });

    $('div.stsbFolderList ul li').bind('click', function(event){	saveArticleToScrapbook(this);} );        


}


/* Display the list of scrapbook folders */
function showList(sender)
{
     /*CLICK TO HIDE*/
     $('div.stsbClosedLinktitle', sender).hide();     
     $('div.stsbOpenLinktitle', sender).show();
     $('div.stsbFolderList', sender).show();
     $('div.span', sender).show();        
}

/* Hide the list of scarpbook folders.*/
function hideList(sender)
{        
        /*CLICK TO SHOW*/
        $('div.stsbClosedLinktitle', sender).show();
        $('div.stsbOpenLinktitle',sender).hide();
        $('div.stsbFolderList',sender).hide();  
}     
 
/* Save the article to the scrapbook.*/
function saveArticleToScrapbook( sender )
{
    var selection = $('input:hidden', sender );
    var value = $(selection[0]).attr('value');
    
    hideList( $('div.stsb') );
    
    var hiddenFlds =  $('div.stsb>input:hidden');
    var url = $(hiddenFlds[0]).attr('value');
    var title = $(hiddenFlds[1]).attr('value');
    var action = $(hiddenFlds[2]).attr('value');
   
    var querystring = "sb_add=true&sb_folder_uid=" + value;
    querystring = querystring + "&sb_url=" + url;
    querystring = querystring + "&sb_desc=WeddingChannel.com&sb_title=" + title;
    querystring = querystring + "&location=" + url;
    var strRedirect = action + querystring;

    window.location = strRedirect;    

    return false; 
}

/* Display the article save status bar. */
function onArticleSavedToScrapbook(msg)
{
    if($('div.articlesaved').length > 0 )
    {
       $('div.articlesaved span').html(msg);
       $('div.articlesaved').show();
    }
}

/* Move any controls marked with class introsectionwidget to the introsection div. */
function BuildIntroSection()
{
   $introwidgets = $('div.subchannel div.introsectionwidget').add('div.channel div.introsectionwidget' );
   $breadcrumbs  = $('div.channel div.breadcrumbs').add('div.subchannel div.breadcrumbs');
   $introsection = $('div.introsection'); 
   if( $introwidgets.length > 0 )
   {
      $breadcrumbs.remove().appendTo($introsection);
      $introwidgets.remove().appendTo($introsection);
      $introsection.show();  
   }
}

function SearchCouples()
{
    /* Define what happens when the textbox comes under focus
    / Remove the watermark class and clear the box*/
    $("#findcouplesregistry_first,#findcouplesregistry_last").focus(function() {

        $("#findcouplesregistry_first,#findcouplesregistry_last").filter(function() {

            // We only want this to apply if there's not
            // something actually entered
            return $(this).val() == "" ||  $(this).val() == "First Name" ||  $(this).val() == "Last Name"

        }).val("").addClass("error");

    });
   
    
    
//    $.validator.setDefaults({
//        submitHandler: function() { alert("submitted!"); }
//    }); 
    
    
   /* validate signup form on keyup and submit*/
    $("#aspnetForm").validate({
	    rules: {
			
		    findcouplesregistry_first: {
			    required: true,
			    minlength: 2
		    },
		    findcouplesregistry_last: {
			    required: true,
			    minlength: 2
		    }
	    },
	    messages:{
	        findcouplesregistry_first: "",
	        findcouplesregistry_last: ""
	    }
		
    });
    $("#findcouplesregistry_submit").click(
        function() 
        {
            $("#findcouplesregistry_first").focus(); 
            var fname = $("#findcouplesregistry_first").val();
            var lname = $("#findcouplesregistry_last").val();
		    /*	Last name must be 2 characters or more */
		    var lastNameValue = new String(lname);
		    var firstNameValue = new String(fname);
		    if(lastNameValue.length < 2 || firstNameValue.length < 1)
		    {
		 	    return false;	/*	last name field does not have enough characters. */
		    }
		    else{
                document.location.href='http://registry.weddingchannel.com/cs/search.action?auid=950&ainfo=search_box&cr=registry_search&sec=HP&fu=http://registry.weddingchannel.com/cs/searchresults.action&et=10&pageoverride=guest&incoming_div=1&rfn=' + fname + '&rln=' + lname;return false;         
            }
        });
    
}

function SetUniqueRadioButton(current)
{
   $('#AnswerChoices input:radio').attr('checked','');    
   $('div.quizquestion input:hidden').val(current.value);
   current.checked = true;
      alert(current.value);
   alert($('div.quizquestion input:hidden').val);
}

/* Process the following functions when the document is ready. */
$(document).ready(function(){   
     
    SaveToScrapbook();   
    BuildIntroSection();        
    SearchCouples();

}); 

