$(document).ready (function() 
{
	$('#inp1').val('');
});

function ClearSearch(){
	$('#inp1').val('');
	$('#sel1').empty();
	$('#result_place').empty();
	$('#inp1').focus();
}

function labor_seek () 
{
	$('#sel1').empty();
	var pm = $('.kind').val();
	$('#result').empty();
	
	$.getJSON("directing.php",
	{ kparam:pm },
	function(json)
	{
		$('#sel1').empty();
		$.each(json.all, function(id, entry) 
		{
	   		var x = $('#inp1').val();
		 	var re = new RegExp(x, "i");
			var matches = entry.cikkek.match (re);
		 	if (matches != null)
		 	{
				$('#sel1').remove('#'+entry.mutatok);
		 		$('<option id="'+entry.mutatok+'" value="'+entry.mutatok+'" onclick="labor_submit();">'+entry.cikkek+'</option>').appendTo('#sel1');
		 	}
		});
	});
}

function SendExpression(kind) 
{
 var word = $('#title').val();
 var name = $('#name').val();
 var email = $('#email').val();
 var send_to_sender = (($('#copy').attr('checked'))?('send'):('nosend'));

 if(!name.length){ alert('Kérem adja meg nevét'); return; }
 if(!email.length){ alert('Kérem adja meg e-mail címét'); return; }
 if (!(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(email))){ alert('Hibás e-mail címet adott meg'); return; }

 if (word.length) 
 {
  $.get("sendmail.php",
  {expression:word, sender_name:escape(name), sender_email:escape(email), comment:escape($('#comment').val()), copy:escape(send_to_sender), type:kind},
  function(html) 
  {
	var res = html.split(';');
	if(res[0] == 'done'){
		alert('Kérését az alkalmazás további bővítésénél figyelembe vesszük, segítségét köszönjük, a bővítésről e-mailben értesítjük.');
		document.location.href='index.php';
	}else{
		alert(res[1]);
	}
  }
  )
 } 
 else 
 {
  alert('Kérem adja meg a kifejezést.');
 }
}

function labor_all_list () 
{
 var pm = $('.kind').val();
 $('#inp1').val('');
 $('#sel1').empty();
 $('#result_place').empty();
 
 $.getJSON("directing.php",
	{ kparam:pm },
 	function(json)
  {
   $.each(json.all, function(id, entry) 
   {   
    $('<option value="'+entry.mutatok+'" onclick="labor_submit();">'+entry.cikkek+'</option>').appendTo('#sel1');
 		});	  
	 });	
}

function labor_submit_all (id) 
{
 $('#result_place').empty();
 var pm = $('.kind').val();

	$.post("directing.php",
	 { mt:id, jparam:'submit',kparam:pm },
		function(html)
		{
			$('#result_place').html(html);
		}
	);
}

function labor_submit ()
{
 var pm = $('.kind').val();
 var gen = $('.generic').val();
 $('#result_place').empty();
 var selectedArray = new Array();
 var select = document.getElementById('sel1');
 var i;
 var count = 0;
 for (i=0; i<select.options.length; i++) 
 {
 	if (select.options[i].selected)
 	{
 	 selectedArray[count] = select.options[i].value;
 	 count++;
 	}
 }
 $('#result_place').html('');
	$.post("directing.php",
	 { mt:selectedArray, jparam:'submit',kparam:pm,genvalue:gen },
		function(html)
		{
			$('#result_place').html(html);
		}
	);
}

