/* popup image/flash/video megjelenito */
function showImage(img, w, h) {
	var scrollbars = 1;
	if(w == null) w = 200;
	if(h == null) h = 200;
	ww = w;
	wh = h;
	if (img.toLowerCase().substr(img.length - 4, 4) == '.flv') {
		h = h + 45;
		scrollbars = 0;
	} else {
		scrollbars = 1;
		if (is.ie) {
			w = w + 20;
		}
	}
	var win = window.open("about:blank", "_blank", "width=" + w + ",height=" + h + ",status=0,resizable=1,scrollbars=" + scrollbars);
	var doc = win.document;

	doc.write('<html xmlns="http://www.w3.org/1999/xhtml"><head><title></title></head>');
	doc.write('<body style="margin: 0px;">');
	if (img.toLowerCase().substr(img.length - 4, 4) == '.swf') {
		doc.write('<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,28,0" width="' + w + '" height="' + h + '" title="">  <param name="movie" value="' + img + '" />  <param name="quality" value="high" />  <embed src="' + img + '" quality="high" pluginspage="http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash" type="application/x-shockwave-flash" width="' + w + '" height="' + h + '"></embed>  </object>');
	} else if (img.toLowerCase().substr(img.length - 4, 4) == '.flv') {
		//url = '/video/player.swf?videoURL=' + img + '&amp;_w=' + w + '&amp;_h=' + (h + 40);
		url = '/video/playerx.swf?videoURL=' + img + '&amp;skinURL=/video/SkinDeepskeye.swf';
		doc.write('<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,28,0" width="' + w + '" height="' + h + '">  <param name="allowScriptAccess" value="sameDomain" />  <param name="allowFullScreen" value="true" />  <param name="movie" value="' + url + '" />  <param name="quality" value="high" />  <param name="bgcolor" value="#ffffff" />  <param name="scale" value="noscale" />  <param name="salign" value="lt" />  <embed src="' + url + '" quality="high" bgcolor="#ffffff" width="' + w + '" height="' + h + '" scale="noscale" salign="lt" name="playerx" align="middle" allowScriptAccess="sameDomain" allowFullScreen="true" type="application/x-shockwave-flash" pluginspage="http://www.adobe.com/go/getflashplayer" />  </object>');
	} else {
		doc.write('<img src="' + img + '" alt="" onclick="window.close();" style="cursor: pointer;">');
	}
	doc.write('</body></html>');
	doc.close();
	return false;
}




/* raklikkre eltunos input/textarea tartalmak */
jgtc.captureEvent(window, "load", function() {
	function makeAutoInput(es) {
		for(var i = 0; i < es.length; i++) {
			var attr = es[i].getAttribute('ht:value');
			if(attr != null) {
				es[i].onfocus = function() { if (this.value == this.getAttribute('ht:value')) { this.value = ''; } };
				es[i].onblur = function() { if (this.value == '') { this.value = this.getAttribute('ht:value') } };
			}
		}
	}

	makeAutoInput(document.getElementsByTagName('INPUT'));
	makeAutoInput(document.getElementsByTagName('TEXTAREA'));
}, true);





/* alapvetoen admin funkciok, de egyszerubb kezelni, ha kozos helyen van minden funkcio */
/* admin funkciok START */

/* confirmations */
function confirmDelete() {
	return window.confirm("Biztosan törölni akarod ezt az elemet?\nEzt a műveletet nem lehet visszavonni.");
}

function chkDel() {
	return window.confirm("Biztosan törölni akarod ezt az elemet?\nEzt a műveletet nem lehet visszavonni.");
}

function confDel() {
	return window.confirm("Biztosan törölni akarod ezt az elemet?\nEzt a műveletet nem lehet visszavonni.");
}

function confirmCopy() {
	return window.confirm("Biztosan másolni akarod ezt az elemet?");
}




/* kapcsolodo-formok tartalmanak kiegeszito funkcioi, elemek cserelgetese */
function jformRead(form, prefix, excludes) {
	if(typeof form == 'string') form = document.forms[form];
	if(typeof excludes != 'object' || !(excludes instanceof Array)) excludes = new Array();

	var jform = null;
	for(var i = 0; i < form.elements.length; i++) {
		var input = form.elements.item(i);
		var id = input.id;

		if(id != null && id.indexOf(prefix) == 0) {
			id = id.substr(prefix.length);
			if(excludes.indexOf(id) != -1) continue;

			var v = null;
			if(input.tagName == 'INPUT') {
				if(input.type == 'text' || input.type == 'hidden') {
					v = input.value;
				} else if(input.type == 'checkbox' || input.type == 'radio') {
					v = input.checked;
				} else {
					alert("FIXME!");
				}
			} else if(input.tagName == 'TEXTAREA') {
				v = input.value;
			} else if(input.tagName == 'SELECT') {
				v = input.value;
			}

			if(jform == null) jform = new Object();
			jform[id] = v;
		}
	}

	return jform;
}

function jformWrite(form, prefix, jform, excludes) {
	if(typeof form == 'string') form = document.forms[form];
	if(typeof excludes != 'object' || !(excludes instanceof Array)) excludes = new Array();

	if(prefix == null) prefix = "";
	for(var i = 0; i < form.elements.length; i++) {
		var input = form.elements.item(i);
		var id = input.id;
		if(id != null && id.indexOf(prefix) == 0) {
			id = id.substr(prefix.length);
			if(excludes.indexOf(id) != -1) continue;

			var v = jform[id];
			if(typeof v == 'function' || typeof v == 'undefined') continue;

			if(input.tagName == 'INPUT') {
				if(input.type == 'text' || input.type == 'hidden') {
					input.value = v == null ? "" : v;
				} else if(input.type == 'checkbox' || input.type == 'radio') {
					input.checked = (new Boolean(v) == true);
				} else {
					alert("FIXME!");
				}
			} else if(input.tagName == 'TEXTAREA') {
				input.value = v;
			} else if(input.tagName == 'SELECT') {
				if(v != null) {
					input.value = v;
				} else {
					input.selectedIndex = -1;
				}
			}
		}
	}
}

function jformXchg(form0, prefix0, form1, prefix1, excludes) {
	var jform0 = jformRead(form0, prefix0, excludes);
	var jform1 = jformRead(form1, prefix1, excludes);

	//console.log("jform: %s %s %s %s", form0, prefix0, form1, prefix1);
	//console.dir(jform0);
	//console.dir(jform1);

	if(jform0 != null && jform1 != null) {
		jformWrite(form1, prefix1, jform0);
		jformWrite(form0, prefix0, jform1);
	}
}

function xchgProperty(form, xchgpropPrefix, idx, delta) {
	var prefix0 = xchgpropPrefix + idx;
	var prefix1 = xchgpropPrefix + (idx + delta);

	jformXchg(form, prefix0, form, prefix1);
}




/* tagcloud tipusu inputmezok kezelese */
function NormalizeTagCloud(tag) {
	return tag.replace(/^\s+/, "").replace(/\s+$/, "").replace(/ *, */g, ",").replace(/,,+/g, ",").replace(/(,$|^,)/g, "").replace(/,/g, ", ");
}

function UpdateTagCloud(id, tag) {
	var e = document.getElementById(id);
	e.value = NormalizeTagCloud(e.value);
	var tmp = e.value.replace(/^|$/g , ", ");
	if (tmp.search(", " + tag + ", ") != -1) {
		tmp = tmp.replace(", " + tag + ", ", ", ");
	} else {
		tmp = tmp + tag + ", ";
	}
	e.value = NormalizeTagCloud(tmp);
}

/* preview */
function openPopupO(htmname, winname) {
	var w = window.open(htmname, winname, "screenX=1,screenY=1,resizable=1,scrollbars=1");
	w.focus();
}

function setPreview(form, e) {
	if(typeof form == 'string') form = document.forms[form];
	form.elements[e].value = 1;
}

/* admin funkciok END */
