/* ###### general.js for conamic 4   ###### **
----------------------------------------------
$id: index.php v0.9 tobiaska 2006-10-28
----------------------------------------------
Tobias Kazmierczak <info@toak.de>
http://www.conamic.de
(c) 2006 TOAK
** ######################################## */

function del(id) {
	q = confirm('Wirklich löschen?');
	if(q == true) self.location.href = 'del_' + id + '.html';
}

function sure_del(url) {
	q = confirm('Wirklich löschen?');
	if(q == true) self.location.href = url;
}

function wait(field) {
	field.value = 'Bitte warten...';
	field.disabled = true;
return true;
}

function getFileName(file) {
	var result, pathDiv, fileNameExt, extPos;
	pathDiv=(file.value.indexOf("/")>=0)?"/":"\\"
	fileNameExt=file.value.substring(file.value.lastIndexOf(pathDiv)+1);
	extPos=fileNameExt.lastIndexOf('.');
	result=(extPos>1)?fileNameExt.substring(0,extPos):fileNameExt;
	return result;
}

function check_image(file) {
	if (file.value != "") {
		var ext1 = file.value;
		ext1 = ext1.substring(ext1.length-3,ext1.length);
		ext1 = ext1.toLowerCase();
		if(ext1 != 'jpg' && ext1 != 'peg' && ext1 != 'gif' && ext1 != 'png') {
			document.forms[0].reset();
			alert('Sie haben eine .'+ext1+' Datei gewählt, bitte wählen Sie nur Bilddateien (jpg, png, gif)!');
			return false; 
		}
	}
}

function openWin (url, options) {
	win = window.open(url, "win", "dependent=no,resizable=yes,scrollbars=yes,"+options);
	win.focus();	
}

function checkBox(id) {
	document.getElementById('box_'+id).checked = true;
	if(currentBox!="") {
		document.getElementById('box_'+currentBox).checked = false; 
	}
	currentBox = id;
}

function show_hide( targetId, img ){
	if (document.getElementById){
		target = document.getElementById( targetId );
		if (target.style.display == "none"){
			target.style.display = "";
			if (img!='') document.images[img].src="/system/images/hide.gif";
			document.getElementById( img ).value = "1";
		} else {
			target.style.display = "none";
			if (img!='') document.images[img].src="/system/images/show.gif";
			document.getElementById( img ).value = "";
		}
	}
}

var count = 0;

function mark(id) {
	if (document.getElementById('movemenu').style.display=='none' && count > 0)
		document.getElementById('movemenu').style.display='inline';
	if (document.getElementById('chkd'+id).value==0) {
		document.getElementById('chkd'+id).value='1';
		document.getElementById('imgb'+id).style.backgroundColor = '#eee';
	} else {
		document.getElementById('chkd'+id).value='';
		document.getElementById('imgb'+id).style.backgroundColor = '#fff';
	}
	count++;
}

var xmlhttp;

function showdir(module,id,inside) {
	if (id=='')
		id = 0;
	xmlhttp=GetXmlHttpObject();
	if (xmlhttp==null) {
		alert ("Browser does not support HTTP Request");
		return;
	}
	xmlhttp.onreadystatechange=stateChanged;
	xmlhttp.open("GET","/modules/"+module+"/getdirs.html?id="+id+"&inside="+inside,true);
	xmlhttp.send(null);
}

function stateChanged() {
	if (xmlhttp.readyState==4) {
		document.getElementById("dirlist").innerHTML=xmlhttp.responseText;
		document.getElementById("dirlist").disabled = false;
	}
}

function GetXmlHttpObject() {
	if (window.XMLHttpRequest) {
		return new XMLHttpRequest();
	}
	if (window.ActiveXObject) {
		return new ActiveXObject("Microsoft.XMLHTTP");
	}
	return null;
}
