function setVid(vid) {
	if (vid.length) {
		$('#vid_id').attr('innerHTML',vid);
		startCommentApp();
	}
}

function startCommentApp() {
	ajaxSubmit('index.php?vid='+$('#vid_id').attr('innerHTML')+'&act=','container');
	$('#content').show();
	$('#content').fadeTo('slow',0.75,function(){
		$('#container').show();
	});
}

function closeCommentApp() {
	$('#container').hide();
	$('#content').fadeTo('slow',0.0,function() {
		$('#content').hide();
		$('#content').attr('innerHTML','');
	});
	
}

function ajaxSubmit(url, celdiv, form, button) {
	post = '';

	if (typeof(form) !== 'undefined') {
		inputok = form.getElementsByTagName('input');
		for (i = 0; i < inputok.length; i++) {
			
			if (inputok[i].type=='text' || inputok[i].type=='hidden' || inputok[i].type=='password') {
				if (post.length == 0) {
					post += inputok[i].name + "=" + inputok[i].value;
				} else {
					post += "&" + inputok[i].name + "=" + inputok[i].value;
				}
			}
			
			if (inputok[i].type=='checkbox' && inputok[i].checked) {
				if (post.length == 0) {
					post += inputok[i].name + "=" + inputok[i].value;
				} else {
					post += "&" + inputok[i].name + "=" + inputok[i].value;
				}
			}
			
			if (inputok[i].type=='radio' && inputok[i].checked) {
				if (post.length == 0) {
					post += inputok[i].name + "=" + inputok[i].value;
				} else {
					post += "&" + inputok[i].name + "=" + inputok[i].value;
				}
			}
		}
		
		textareak = form.getElementsByTagName('textarea');
		for (i = 0; i < textareak.length; i++) {
			if (post.length == 0) {
				post += textareak[i].name + "=" + textareak[i].value;
			} else {
				post += "&" + textareak[i].name + "=" + textareak[i].value;
			}
		}
		
		selectek = form.getElementsByTagName('select');
		for (i = 0; i < selectek.length; i++) {
			if (post.length == 0) {
				post += selectek[i].name + "=" + selectek[i].value;
			} else {
				post += "&" + selectek[i].name + "=" + selectek[i].value;
			}
		}
		
		if (post.length == 0) {
			post += button+"=feltolt";
		} else {
			post += "&"+button+"=feltolt";
		}
	}
	$.post(url, post, function (data) {
		if (data != 'posted') {
			document.getElementById(celdiv).innerHTML = data;
		} else {
			document.getElementById('n_comment').innerHTML = '';
			document.getElementById('login').innerHTML = '';
		}
		if (celdiv != 'comments' && $('#vid_id').attr('innerHTML') != '') {
			if ($('#n_comment').attr('innerHTML') == '' && $('#login').attr('innerHTML') == '') {
				ajaxSubmit('index.php?act=comment_list&vid='+$('#vid_id').attr('innerHTML'),'comments');
			} else {
				$('#comments').hide();
			}
		}
		$('#'+celdiv).show(); 
	});
}
