



   
    

/*
$(document).ready(function() {
   

    $('#subscribe-button').click(function(){
           
           checkForm();
       
    })
    
    function checkForm(){
 
        return $.validate({
        	fieldset: "#subscribePanel",
        	usedefault: true,
        	onerror: function(err){
            		alert("message: " + err[0].msg + " \n type: " + err[0].type + " \n id: " + err[0].id);
            		//$("body").css({background: "#ff0000"});
        		}
			})
			
		}
		




    function addToSubscription(){
        var fn = $('#txtFirstName').val();
        var ln = $('#txtLastName').val();
        var e = $('#txtEmail').val();

        $.ajax({
            url: '<%= SiteConfig.VirtualDirectory %>/services/MailChimpHandler.ashx',
            type: 'POST',
            data: 'fn=' + fn + '&ln=' + ln + '&e=' +e,

            success:function(xml){
                var jData = $(xml);
                var result = jData.find("success").text();

                if(result == "true"){
                    $('#subscribe-thanks').fadeIn("fast");
                }
            }
        });
    }


});

*/


/**
 * @author Michael.Howlett
 */

/*
* 

	<xml>
		<index>
	 	<txtFriendsName>dasd</txtFriendsName>
	 	<txtFriendsEmail>sdsa</txtFriendsEmail>
		</index>
	<index>
		<txtFriendsName>sad</txtFriendsName>
		<txtFriendsEmail>asds</txtFriendsEmail>
	</index>
	</xml>


* 
*/


var ListCreator = Base.extend(
{
	
	/**
	* 
	*
	*/
	constructor : function(container){
	    	
		var outer = this;
		this.container = container;
		this.xmlList = "";
		this.xmlReturn = "";
        this.index = 0;
        this.comments = "";
	},
	
 
	add : function (form, lineheight) {
		
		var htmlString = "<ul class=\"list-entry\" id=\""+ this.index +"\">";
		this.xmlList += "<index id=\""+ this.index +"\">";
		this.index ++;
		var outer = this;
	    
		
		$(form).find("input").each(function(i){
			
			// update the display
			htmlString += "<li class=\"list-item-text " + $(this).attr("id") + "\" title=\"" + $(this).attr("id") + "\">" + $(this).val() + "</li>"
			
			// update the xml
			outer.xmlList += "<" + $(this).attr("id") + ">" + $(this).val() + "</" +  $(this).attr("id") + ">";
			
			// clear the form
			$(this).val("")
			
		}); 
		
		// tidy
		htmlString += "<li class=\"list-item-close\"><a href=\"javascript:void(0)\">x</a></li></ul>";
		this.xmlList += "</index>";
		
		
		// displau
		var item = $("<li class=\"list-item\" id=\""+ this.index +"\">" + htmlString + "</li>");

		
		$(this.container).prepend(item);
		$(this.container).animate({height: ($(this.container).height() + lineheight) + "px"}, 200, "linear", function(){
			item.fadeIn("fast")
		})

        
		 // remove item
		 currentObj = this;
		 
		$(".list-item-close").click(function(e) {

			$(outer.container).animate({height: ($(outer.container).height() - lineheight) + "px"}, 200);
			currentObj.removeXMLitem($(this).parent().attr("id"));
			$(this).parent().fadeOut(200, function(){
				$(this).remove();
			});
		});  
        
	},
	buildXML : function(){
	  this.xmlReturn = "<xml>" + this.xmlList + "<comment>"+ this.comments +"</comment></xml>";

	},
	
	getList : function (){
	    this.buildXML();
		return this.xmlReturn;
	},
	
	removeXMLitem : function (indexId){
	    this.buildXML();
	   	   
	    var replaceHTML = "<index id=\""+indexId+"\">" + $(this.xmlReturn).find("index[id=\""+ indexId +"\"]").html() + "</index>";
	    this.xmlList = $(this.xmlReturn).html().replace(replaceHTML,"");
	   
	}


	
});