
$(document).ready( function(){ addEvents()});


function  addEvents()
{
	$('#listName').blur( function(){ checkListName(this); } );
	$('#numbersList').blur(function(){ checnumbersList(this); } );
}

function checkListName(elem)
{
	if(elem.value == '')
	{
		alert("List Name can't be  empty\n"+elem.value);
		elem.focus();
		
		return ;
	}
	
	$.post('/create/check-list-name',{'listName':elem.value},function(result){ 
		
		if(result.qty > 0)
		{
			$('#listName').parent().append('<p>'+result.msg+'</p>')
		} 
		
	},'json');
	
	
}
function checnumbersList(elem)
{
	if(elem.value == '')
	{
		alert("Numbers Name can't be  empty");
		elem.focus();
		
		return ;
	}
}

function addNewList()
{
	
	
	var listName=$('#listName');
	var numbersList=$('#numbersList');
	
	
	
	if(listName.val() == '')
	{
		alert("List Name can't be  empty");
		$('#listName').trigger('focus');
		
		return;
	}
	if(numbersList.val() == '')
	{
		alert("numbers List can't be  empty");
		$('#numbersList').trigger('focus');
		
		return;
	}
	
	var data={ 
			
			"listName":listName.val(),
			"numbersList":numbersList.val()	
	}; 
	
	$.ajax(
			{
				url: "/create/add-numbers-list.html", 
				data: data,
				dataType: "json",
				type:'POST',
				success: function( response )
				{
					
					/*
					 *
					 * 
					 * MARTIROS CODE MODIFIED 05.03.2011
					   listName.val("") ;
					 
					numbersList.val("");
					var dialog=$("#message_dialog");
					dialog.html(response);
					dialog.dialog({ 
				        modal: true, 
				 
				        overlay: { 
				            opacity: 1,     
				            background: "black" 
				        } 
				    });*/
				
						viewNotice(response);
					
				}
			}
	);
	
 
	 
}


function viewNotice(response)
{
	var _dialog = document.createElement('div');
	var _nDialog = document.createElement('div');
	
	var _noticeHTML = '<ul><li> ERORS :'+response.warning+'<li>';
	
	if(response.notice.length > 0)
	{
		_notice = response.notice.join('</li><li>');

		_noticeHTML += '<li>'+_notice+'</li>';
		
	}
	
	_noticeHTML += '<li> ADED :'+response.added+'<li>';
	
	if(response.notice.result > 0)
	{
		_result = response.result.join('</li><li>');
		_noticeHTML += '<li>'+_notice+'</li>';
		
	}
	
	_noticeHTML += '</ul>';
	_dialog.title =' List '+response.name +' done';
	
	   
	_noticeHTML = '<p>'+ response.added_text+'</p>';
	 
	$(_dialog).append(_noticeHTML);
	
	$(_dialog).dialog(	
				{ 
					title:response.added_title  , 
					close:function(){ $(this).remove() },
					buttons: {
						Ok: function() {
							$( this ).dialog( "close" );
						}
					}
				
				}
				
	);
	
	
}
function deleteList(id,Dom,msg)
{
	
	
	if(confirm(msg))
	{
		$(Dom).animate({'opacity':0.8}).addClass('loading_ajax');
		
			$.post("/create/deleteList",{listId:id,DomeElement:Dom},
			function(result)
			{ 
				
			$(result.DomeElement).animate({'opacity':0.}, function(){ $(this).remove();})
		},'json');
	}
	
	
}

var cancelQueue=function(QueueId,path,Dom,message)
{
	
	if(confirm(message))
	{
		$(Dom).animate({opacity:0.8}).addClass('loading_ajax');
		$.post(path,{QueueId:QueueId,DomeElement:Dom},function(data){ window.location.href =  path});
	}
	
}
var allowQueue=function(QueueId,path,Dom,message)
{
	if(confirm(message))
	{
		$(Dom).animate({opacity:0.8}).addClass('loading_ajax');
		$.post(path,{QueueId:QueueId,DomeElement:Dom},function(data){ window.location.href =  path});
	}
	
}

	 
