var SelectWindow;
var FilmWindow;
var uploading;

function FensterZu() {
	if(typeof SelectWindow != "undefined" && SelectWindow.closed != true) {
		SelectWindow.close();
	}
}

function FensterAuf(url) {
	var x = 200;
	var help = 'width=650,height=700,toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=yes,copyhistory=yes,resizable=no,left=' + x + ',top=5';
	SelectWindow = window.open(url, 'Auswahl', help);
}

function openFilmPopup(url, name, width, height) {
	var help = 'width=' + width + ',height=' + height + ',toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,copyhistory=no,resizable=yes';
	FilmWindow = window.open(url, name, help);
}

function openVotePopup(url, name, width, height) {
	var help = 'width=' + width + ',height=' + height + ',toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,copyhistory=no,resizable=no';
	VoteWindow = window.open(url, name, help);
}

function closeFilmPopup() {
	if(typeof FilmWindow != "undefined" && FilmWindow.closed != true) {
//		FilmWindow.close();
	}
}

function checkThings() {
	checkFocus();
	closeFilmPopup();
}

function changeOpener(url) {
	opener.document.location.href = url;
	self.close();
}

function clearInput(field, hiddenfield) {
	field.value = '';
	if(hiddenfield) {
		hiddenfield.value = '';
	}
}

function checkAll(checked, form) {
	var form_element;
	var form_elements	= form.elements;
	var element_count	= form_elements.length;
	if(element_count < 2) {
		return;
	}
	for(var i = 0; i < element_count; i++) {
		form_element = form_elements[i];
		if(form_element.type == 'checkbox') {
			form_element.checked = checked;
		}
	}
}

function checkFocus() {
	if(window.name == 'uploading') {
		if(typeof uploading != 'undefined') {
			uploading.focus();
		}
	}
}

function checkGroup(checked, form, group) {
	var form_element;
	var form_elements	= form.elements;
	var element_count	= form_elements.length;
	if(element_count < 2) {
		return;
	}
	for(var i = 0; i < element_count; i++) {
		form_element = form_elements[i];
		if(form_element.type == 'radio') {
			if(form_element.value.substr(0, group.length) == group) {
				form_element.checked = checked;
			}
		}
	}
}

var nl_focus_field;

function insertFieldName(form) {
	if(nl_focus_field == 'undefined') {
		return;
	}
    var myFocus = nl_focus_field;
    var myListBox = form.__fieldlist;

    if(myListBox.options.length > 0) {
        var chaineAj = "";
        var NbSelect = 0;
        for(var i=0; i<myListBox.options.length; i++) {
            if (myListBox.options[i].selected){
                NbSelect++;
                if (NbSelect > 1)
                    chaineAj += ", ";
                chaineAj += '<%' + myListBox.options[i].value + '%>';
            }
        }

        //IE support
        if (document.selection) {
            myFocus.focus();
            sel = document.selection.createRange();
            sel.text = chaineAj;
        }
        //MOZILLA/NETSCAPE support
        else if (myFocus.selectionStart || myFocus.selectionStart == "0") {
            var startPos = myFocus.selectionStart;
            var endPos = myFocus.selectionEnd;
            var chaineSql = myFocus.value;

            myFocus.value = chaineSql.substring(0, startPos) + chaineAj + chaineSql.substring(endPos, chaineSql.length);
        } else {
            myFocus.value += chaineAj;
        }
    }
}

function setSelectOptions(the_form, the_select, do_check)
{
    var selectObject = document.forms[the_form].elements[the_select];
    var selectCount  = selectObject.length;

    for (var i = 0; i < selectCount; i++) {
        selectObject.options[i].selected = do_check;
    } // end for

    return true;
} // end of the 'setSelectOptions()' function

function askDelete(name, url) {
	var confirmation = confirm("Wollen Sie den Datensatz '" + name + "' wirklich l�schen?");
	url += '&in=5';
	if(confirmation) {
		self.location.href = url;
	}
	return false;
}

function PrintNow() {
	for(i = 0; i < document.images.length; i++) {
		if(document.images[i].src == "http://img.map24.com/map24/portal/de-de/16_print.gif") {
			document.images[ i ].style.width=0;
		}
	}
	window.print();
}

function RegExpHelp() {
	RegExpHelpWindow = window.open('regexp.html','RegEx','width=650,height=700,toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=yes,copyhistory=yes,resizable=no,left=100,top=5');
}

function change_flag(name, path) {
	window.document.images[""+name+""].src=path+name+".gif";
}

function change_flag_back(name, path) {
	window.document.images[""+name+""].src=path+name+"_bw.gif";
}

function change_navi(name, path) {
	window.document.images[""+name+""].src=path+name+"_hi.gif";
}

function change_navi_back(name, path) {
	window.document.images[""+name+""].src=path+name+".gif";
}

function showMessage(form) {
	uploading = window.open("progress.php","msg","height=200,width=350,toolbar=no,scrollbars=no,resizable=0,status=no");
	form.submit();
	return true;
}

function changeSite(selection) {
	if(typeof selection.options != 'object') {
		return;
	}
	if(typeof selection.options[selection.options.selectedIndex].value == 'undefined') {
		return;
	}
	var url = selection.options[selection.options.selectedIndex].value;
	if(url.indexOf(".pdf") != -1) {
		PDFWindow = window.open(url, 'PDF', '');
	} else if(url.indexOf("http://") != -1) {
		NEWWindow = window.open(url, 'NEW', '');
	} else {
		document.location.href = selection.options[selection.options.selectedIndex].value;
	}
}

