function openTemplateDetail(path)
{
	detail = window.open(path,"templatedetail","width=820,height=620"); 	
	detail.focus();
}

function showFilePreview(path)
{
	if (document.formular.page_fileexists.value != "")	
	{
		preview = window.open(path + "/" + document.formular.page_fileexists.value,"preview","width=600,height=500,resizable=yes,scrollbars=yes"); 
		preview.focus();
	}
}

function startPreview()
{
	preview = window.open("","Ansicht","width=700,height=550,resizable=yes,scrollbars=yes");
	preview.document.open();
	with(preview.document)
	{
		writeln(document.formular.nl_html.value);
	}
    preview.document.close();
}

function openBig2Dialog(path,dialogname)
{
	dialog = window.open("website.php?id=" + path + "&admin=" + dialogname,"dialog2","width=900,height=700,top=20,left=20,scrollbars=no,resizable=no");
	dialog.focus();
}

function showSelector(path,field)
{
	dialog = window.open("website.php?id=" + path + "&admin=filepool&selector=1&filter=all","Selector","width=900,height=700,resizable=yes,scrollbars=yes");
	dialog.moveTo(((screen.width / 2) - 450),((screen.height / 2) - 350));
	dialog.focus();
}

/***********************************************
* Form Field Progress Bar- By Ron Jonk- http://www.euronet.nl/~jonkr/
* Modified by Dynamic Drive for minor changes
* Script featured/ available at Dynamic Drive- http://www.dynamicdrive.com
* Please keep this notice intact
***********************************************/

function textCounter(field,counter,maxlimit,linecounter) 
{
	// text width//
	var fieldWidth = parseInt(field.offsetWidth);
	var charcnt = field.value.length;        

	// trim the extra text
	if (charcnt > maxlimit) { 
		field.value = field.value.substring(0, maxlimit);
	}

	else { 
	// progress bar percentage
	var percentage = parseInt(100 - (( maxlimit - charcnt) * 100)/maxlimit) ;
	document.getElementById(counter).style.width =  parseInt((fieldWidth*percentage)/100 - 5) +"px";
	document.getElementById("oe_progresstext").innerHTML= charcnt + "/" + maxlimit + " = " + percentage+"%"
	// color correction on style from CCFFF -> CC0000
	setcolor(document.getElementById(counter),percentage,"background-color");
	}
}

function setcolor(obj,percentage,prop){
	obj.style[prop] = "rgb(80%,"+(100-percentage)+"%,"+(100-percentage)+"%)";
}

function insertAtCursor(myField, myValue) 
{
	//IE support
	if (document.selection) 
	{
		myField.focus();
		sel = document.selection.createRange();
		sel.text = myValue;
	}

	//MOZILLA/NETSCAPE support
	else if (myField.selectionStart || myField.selectionStart == "0") 
	{
		var startPos = myField.selectionStart;
		var endPos = myField.selectionEnd;
		myField.value = myField.value.substring(0, startPos)
		+ myValue
		+ myField.value.substring(endPos, myField.value.length);
	} 
	else 
	{
		myField.value += myValue;
	}
}

function selectOnChange(selObject) 
{
	var selWert = selObject.options[selObject.selectedIndex].value;
	window.location.href = selWert;
}

function insertTab(event,obj) {
    var tabKeyCode = 9;
    if (event.which) // mozilla
        var keycode = event.which;
    else // ie
        var keycode = event.keyCode;
    if (keycode == tabKeyCode) {
        if (event.type == "keydown") {
            if (obj.setSelectionRange) {
                // mozilla
                var s = obj.selectionStart;
                var e = obj.selectionEnd;
                obj.value = obj.value.substring(0, s) + 
                    "\t" + obj.value.substr(e);
                obj.setSelectionRange(s + 1, s + 1);
                obj.focus();
            } else if (obj.createTextRange) {
                // ie
                document.selection.createRange().text="\t"
                obj.onblur = function() { this.focus(); this.onblur = null; };
            } else {
                // unsupported browsers
            }
        }
        if (event.returnValue) // ie ?
            event.returnValue = false;
        if (event.preventDefault) // dom
            event.preventDefault();
        return false; // should work in all browsers
    }
    return true;
}
