$(document).ready(function(){
	$(':checkbox').css('background', 'none');
	$(':checkbox').css('width', '14px');
	$('input[name=D54ghW43tGFD]').val('_BMvalideformBM_');
	$(document).pngFix();
	
	var list = $('#two :input');

	for( i=0; i<list.length; i++) {
		if ( $(list[i]).attr('type') == 'text' || $(list[i]).attr('type') == 'password' ) {
			$(list[i]).css('float', 'left');
			$(list[i]).before('<img src="/misc/pics/inputs/input_left.gif" class="input_left">');
			$(list[i]).after('<img src="/misc/pics/inputs/input_right.gif" class="input_right">');
		}
//		else if ( $(list[i]).attr('type') == 'textarea' ) {
//			$(list[i]).replaceWith('<div class="tarea"><textarea name="'+$(list[i]).attr('name')+'"></textarea></div>');
//		}
//		else
//			alert($(list[i]).attr('type'));
	}

	var list = $('#one :input');

	for( i=0; i<list.length; i++) {
		if ( $(list[i]).attr('type') == 'text' || $(list[i]).attr('type') == 'password' ) {
			$(list[i]).css('float', 'left');
			$(list[i]).before('<img src="/misc/pics/inputs/input_left.gif" class="input_left">');
			$(list[i]).after('<img src="/misc/pics/inputs/input_right.gif" class="input_right">');
		}
	}

})

function ismaxlength(obj){
	var mlength=obj.getAttribute? parseInt(obj.getAttribute("maxlength")) : ""
	if (obj.getAttribute && obj.value.length>mlength)
	obj.value=obj.value.substring(0,mlength)
}


function downloadCategory() {
	selectFirstRow = '-- Kérem válasszon --';
	ID = $('#selectFoKategoria').attr('value');

	if ( ID > 0 ) {
		$.post(document.URL, {ajaxFunction: 'downloadCategory', ajaxFile: 'hirdetes/ajax.php', ID: ID},
			function( data ) {
				s = document.getElementById('selectAlKategoria');
				$(s).empty();

				s.options[0] = new Option(selectFirstRow, '0');
				a = data.split('|');
				if ( a.length > 0 )
					for ( i=0; i<a.length; i++ ) {
						j = a[i].split('$');
						s.options[i+1] = new Option(j[1], j[0]);
					}
			}
		);
	}
	else {
		s = document.getElementById('selectAlKategoria');
		$(s).empty();
		s.options[0] = new Option(selectFirstRow, '0');
	}
}

function hirdetesMentese( id ) {
	$.post(document.URL, {ajaxFunction: 'hirdetesMentese', ajaxFile: 'ajax.php', ID: id},
		function( data ) {
			if ( data == 'not_auth' )
				bmAlert('Kérlek először jelentkezz be!', 'error');
			else if ( data == 'ok' )
				bmAlert('A hirdetés mentése sikerült!');
	});

}

function hirdetesfigyelo( id, type ) {
	$.post(document.URL, {ajaxFunction: 'hirdetesfigyelo', ajaxFile: 'ajax.php', ID: id, TYPE: type},
		function( data ) {
			if ( data == 'not_auth' )
				bmAlert('Kérlek először jelentkezz be!', 'error');
			else if ( data == 'ok' )
				bmAlert('A hirdetésfgyelő erre a kategóriára be lett állítva!');
	});

}

function hirdetesfigyeloTorlese( id, type ) {
	if ( confirm('Biztos benne, hogy törölni szeretné?') )
	$.post(document.URL, {ajaxFunction: 'hirdetesfigyeloTorlese', ajaxFile: 'ajax.php', ID: id, TYPE: type},
		function( data ) {
			bmAlert('Az adott kategóriához a hirdetésfigyelő törölve lett!');
			$('#hfigyeloLine'+type+'_'+id).hide();
	});
}

function mentettHirdetesTorlese( id ) {
if ( confirm('Biztos benne, hogy törölni szeretné?') )
	$.post(document.URL, {ajaxFunction: 'mentettHirdetesTorlese', ajaxFile: 'ajax.php', ID: id},
		function( data ) {
			$('#aprokID'+id).fadeOut();
			$('#aprokbuttonID'+id).hide();
			bmAlert('A hirdetés törlése sikerült!');
	});
}

function hirdetesTorlese( id ) {
if ( confirm('Biztos benne, hogy törölni szeretné a hirdetést? A műveletet visszavonni nem lehet, a hirdetéssel kapcsolatos minden adat törlődik!') )
	$.post(document.URL, {ajaxFunction: 'hirdetesTorlese', ajaxFile: 'ajax.php', ID: id},
		function( data ) {
			if ( data == 'ok' ) {
				$('#aprokID'+id).fadeOut();
				bmAlert('A hirdetés törlése sikerült!');
			}
			else if ( data == 'not_admin' ) {
				bmAlert('Hirdetést csak Adminisztrátor törölhet!');
			}
	});
}
