var debug = 0;

var checkUser = function() {
	CleanDiv('username_alert');
	CleanDiv('password_alert');
	CleanDiv('realname_alert');
	CleanDiv('email_alert');

	if (!$('username').value) {
		FillDiv('username_alert', '<img src="images/warning_small.png" alt="" border="0" />');
		alert('A felhasználónév mező kitöltése kötelező!');
		$('username').focus();

	} else if (!$('password').value) {
		FillDiv('password_alert', '<img src="images/warning_small.png" alt="" border="0" />');
		alert('A jelszo mező kitöltése kötelező!');
		$('password').focus();

	} else if (!$('realname').value) {
		FillDiv('realname_alert', '<img src="images/warning_small.png" alt="" border="0" />');
		alert('A név mező kitöltése kötelező!');
		$('realname').focus();

	} else if (!$('email').value) {
		FillDiv('email_alert', '<img src="images/warning_small.png" alt="" border="0" />');
		alert('Az e-mail cím mező kitöltése kötelező!');
		$('email').focus();

	} else { $('user_form').submit(); }
}

var FillDiv = function (div, text) {
	$(div).innerHTML = text;
}

var CleanDiv = function (div, text) {
	$(div).innerHTML = "";
}

var HideDiv = function (div) {
	$(div).style.display = "none";
}

var preDelete = function (link) {
	Modalbox.show('include/delete.php?link=' + link, {title: this.title, width: 300});
}
var preDelete2 = function (link, parameters) {
	Modalbox.show('include/delete_ajax.php?link=' + link + parameters, {title: this.title, width: 300});
}

var LoadData2 = function (object, page) {
	if (debug) {
		$('jsdebug').style.width = "97%";
		$('jsdebug').style.height = "200px";
		$('jsdebug').style.border = "1px solid";
		$('jsdebug').style.borderColor = "#666666";
		$('jsdebug').style.display = "block";

		$('jsdebug').innerHTML += 'Oldal betöltése: ' + page + '<br />';
	}

	$(object).innerHTML = '<div align="center"><img src="images/loading.gif" alt="Betöltés" border="0" /></div>';

	new Ajax.Updater(object, page, {
		method: 'get',
		evalScripts: true,
		onSuccess: function(t) {
			$(object).innerHTML = t.responseText;
		},
		onFailure: function(t) {
			return false;

		}
	});
	return true;

}

var setActiveTab = function (tabname, tab, tabcount, editorname) {
	for (x=1;x<=tabcount;x++) {
		$(tabname + x).className = "none";
	}

	for (x=1;x<=tabcount;x++) {
		$(editorname+x).className = "none";
	}
	
	$(tabname + tab).className = "active";
}

var OpenCloseTab = function (name , show , count) {
	for( i=1 ; i<=count ; i++) {
		hely = document.getElementById(name+i);
		if(i==show){
			hely.style.display='block';
		}else{
			hely.style.display='none';
		}
	}
}

var ResizeToGallery = function(aid, dir) {
	OpenCloseTab('editor', 3, 5); 
	LoadData2('right_settings', 'include/cms_gallery_dir.php?articleid=' + aid);
	LoadData2('editor3', 'include/cms_gallery_images.php?articleid=' + aid + '&dir=' + dir);
}

/*var swfu;
var uploadComplete_dawid = function() { LoadData2('editor3', 'include/cms_gallery_images.php'); Modalbox.hide(); } */

var GalleryImageEdit = function(tool, file) {
	if (tool == "tools") minusz = 3;
	else if (tool == "tools2") minusz = 1;

	$(tool + '_' + file).style.height = ($(tool + '_image_' + file).height-minusz);
	$(tool + '_' + file).style.display = "block";
}

var GalleryImageEditHide = function(tool, file) {
	$(tool + '_' + file).style.display = "none";
}

var GalleryCreateDir = function() {
	newdir_dir =$('newdir_dir').value;
	newdir = base64_encode($('newdir').value);
	
	LoadData2('right_settings', 'modules.php?module=cms_gallery&action=createdir&newdir_dir='+ newdir_dir + '&newdir=' + newdir + '&articleid=' + $('articleid').value);
}


var ResizeToFilemanager = function(aid, dir) {
	OpenCloseTab('editor', 4, 5); 
	LoadData2('right_settings', 'include/cms_fmanager_dir.php?articleid=' + aid);
	LoadData2('editor4', 'include/cms_fmanager_files.php?articleid=' + aid + '&dir=' + dir);
}

var filesCreateDir = function() {
	newdir_dir =$('newdir_dir').value;
	newdir = base64_encode($('newdir').value);
	
	LoadData2('right_settings', 'modules.php?module=cms_files&action=createdir&newdir_dir='+ newdir_dir + '&newdir=' + newdir + '&articleid=' + $('articleid').value);
}

/* forms */
var FormAddField = function (form, type) {

	var _data = $(form).serialize(true);

	new Ajax.Updater('debug', 'modules.php?module=forms&action=addfield&type='+type, {
		method: 'post',
		parameters: _data,
		evalScripts: true,
		onSuccess: function(t) {
			alert(t.responseText);
			LoadData2('newform_content', 'include/new_formfield.php?formid=' + $('formid').value);
			//$(object).innerHTML = t.responseText;
		},
		onFailure: function(t) {
			return false;

		}
	});
	return true;
}

var FormsCreateSelect = function () {
	$('select_content').innerHTML = "";

	if ($('select_num').value > 35) {
		alert('Maximum 35 opció lehet!');
		return;
	}

	for (x=1;x<=$('select_num').value;x++) {
		$('select_content').innerHTML += '<div style="float: left; padding-left: 5px">Opció ' + x + ': <input type="text" name="select_field[' + x + ']" value="" id="select_field[' + x + ']" tabindex="' + x + '" /></div>';
	}
	Modalbox.resizeToContent();
}

var FormsCreateSelectR = function () {
	$('select_content_radio').innerHTML = "";

	if ($('select_num').value > 35) {
		alert('Maximum 35 opció lehet!');
		return;
	}

	for (x=1;x<=$('select_num_radio').value;x++) {
		$('select_content_radio').innerHTML += '<div style="float: left; padding-left: 5px">Rádió ' + x + ': <input type="text" name="select_field_radio[' + x + ']" value="" id="select_field_radio[' + x + ']" tabindex="' + x + '" /></div>';
	}
	Modalbox.resizeToContent();
}


var KeepAlive = function() {
	//alert('e');

	new Ajax.Updater('debug', 'modules/keepalive.php', {
		method: 'get',
		evalScripts: true,
		onSuccess: function(t) {
			setTimeout("KeepAlive()", 50000);
		},
		onFailure: function(t) {
			return false;

		}
	});
	return true;

	//setTimeout("KeepAlive()", 1000);
}



var getSelectionId = function(text, li) { 
	$('selected_cityes_id').value += ";" + li.id + ";"; 
	loadCity();
	$('city_search').value = "";
}

var deleteCityItem = function(id, city) { 
	$('selected_cityes_id').value = str_replace(";" + id + ";", "", $('selected_cityes_id').value ); 
	
	/* alert($('selected_cityes_id').value);
	alert($('city_list').innerHTML);
	alert(city + ' (<A href="javascript:deleteCityItem(' + id + ', \'' + city+ '\')">törlés</A>)<BR>'); */

	$('city_list').innerHTML = str_replace(city + ' (<A href="javascript:deleteCityItem(' + id + ', \'' + city + '\')">törlés</A>)<BR>', '', $('city_list').innerHTML);
	
}

var loadCity = function() {
	new Ajax.Updater('city_list', '/admin/modules/hirdetesek/modules/cityes_load.php?city=' + $('selected_cityes_id').value, {
		method: 'get',
		evalScripts: true,
		onSuccess: function(t) {
			$(object).innerHTML = t.responseText;
		},
		onFailure: function(t) {
			return false;
		}
	});
}

var StartTraceVideoWatch = function(pid, adid) {

	//alert(pid + ' + ' + adid);

}

var TraceVideoWatch = function(pid, adid) {
	//alert(pid + ' + ' + adid);

	new Ajax.Request('/modules/nyeremenyjatek/module/trace.php?pid=' + pid + '&ad_id=' + adid, {
		method: 'get',
		evalScripts: true,
		onSuccess: function(t) {
			//alert(t.responseText);
		},
		onFailure: function(t) {
			return false;
		}
	});
}

var LoadNaptar = function(object, url) {
	jQuery.get(url, function(data){
		$("#naptar").html(data);
	});

}


function login() {
	document.forms['login_form'].submit();
}
