
	
function isUrl(s) {
    var regexp = /(ftp|http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?/
    return regexp.test(s);
}
	
		
		$(function(){
			 window['container'] = $("#links");
			 window['globalIterator'] = 0;
		
			$("#slidetxt").bind("click",function(){
				var cnt = $("#txtcontainer");
				cnt.slideToggle('slow',function(){
	
					if((cnt).is(":visible"))
					{
							
							$("#txtcnt").focus().select();
					}
			
				});
				
				
				return false;		
			});
			$(".td2").live('click',function(){
				$(".htmlval",$(this)).hide();
				$("input",$(this)).show().focus().select();
                                return false;
			});
			
			$(".td2 .strval").live('blur',function(){
				$(this).hide();
				$('.htmlval',$(this).parent()).show();
                                 return false;
			
			});
			
			$("#go").bind('click',function(){
                            var globalIterator = 0;
                                $(".result,#text").hide();
                                $("#tmpind").show();
                             
				$("#attr_href").removeClass('err');
				$(".inputfield li:hidden").remove();

					if(isUrl($("#attr_href").val()))
					{

                                                var strform_vars = $('#mainform').serialize();
                                                $.post('req.php',strform_vars,function(data){
                                                    container.empty();
                                                   $.each( data.result, function(i, n){
                                                             $('<div class="row"><div class="td1">'+(++globalIterator)+'</div><div class="td2"><span class="htmlval">'+n+'</span><input type="text" value=""  class="strval" style="display:none;" /></div></div>').appendTo(container);
                                                                var input = $('.strval:last',container);
                                                                input.val(n);
                                                            });
                                                            $("#txtcnt").val(jQuery.trim(data.result.join("\n")));

                                                            $("#tmpind").hide();
                                                             $(".result").show();

                                                });
                                                  return false;

					}
					else
					{
						$("#attr_href").addClass('err');
						alert('Not valid href ');

					}
				return false;
			});
			$(".inputfield input").live("keypress",function(e){
					if ((e.which && e.which == 13) || (e.keyCode && e.keyCode == 13) ) {  
						self = $(this); count_sel = "input[name='"+self.attr('name')+"']";
						if( $.trim(self.val()) != '' && $(count_sel).length<=10){
						
						
							var  newItem = $('<input />').attr('type','text').attr('name',self.attr('name'));
							self.parents('ul:first').append(newItem);
							newItem.wrap('<li />');
							newItem.focus();
							
							newItem.bind('blur',function(e){
					
							var self = $(this);
							if($.trim(self.val())=='')
							{
								if(self.parents('ul:first').children().size() > 1)
								{
									self.parent().hide();
								}
							}
								
								
							}).bind('focus',function(){
								$(".inputfield li:hidden").remove();	
							});
						}
                                                 return false;
					}
                                       
			}).bind('blur',function(e){
					
							var self = $(this);
							if($.trim(self.val())=='')
							{
								if(self.parents('ul:first').children().size() > 1)
								{
									self.parent().hide();
								}
							}
								
								
							}).bind('focus',function(){
								$(".inputfield li:hidden").remove();	
							});
			
		});
