var MODALSUBMIT = true;

// ----------------------------------------------------------------------------------------------------------------------------
// (Dialog Aufufe)
// ----------------------------------------------------------------------------------------------------------------------------
function openHelp(alias) 
{
    window.open("http://www.fsm-werkstatt.net/cms-help/" + (alias.replace("/", "-")), "help", "scrollbars=yes,resizable=yes,width=" + 600 + ",height=" + 600 + ",left=0,top=0");

    if (false)
    {
        // funktioniert noch nicht.
        
        return makeFalse(
                domTT_activate(event.srcElement, event, 'caption', 'CMS Hilfe', 'content', '&lt;iframe src=&quot;http://www.fsm-werkstatt.net/cms-help/' + (alias.replace("/", "-")) + '&quot; style=&quot;width: 600px; height: 400px;&quot;&gt;&lt;/iframe&gt;', 'statusText', 'Loading Hilfe...', 'type', 'sticky', 'styleClass', 'domTTWin', 'closeLink', 'x', 'draggable', true, 'closeAction', 'destroy')
        );
    }
}

// ----------------------------------------------------------------------------------------------------------------------------
// Objekt Administration (Submit Funktionen)
// ----------------------------------------------------------------------------------------------------------------------------

function doObjektRelease() 
{
	var formName = doSaveImpl();
	if (!formName) return false;

	doSubmit("tdo", "release", "", "", "", "");
}

function doObjektBlock() 
{
	var formName = doSaveImpl();
	if (!formName) return false;

	doSubmit("tdo", "block", "", "", "", "");
}

function doSave() 
{
	var formName = doSaveImpl();
	if (!formName) return false;

	doSubmit("tdo", "save", "", "", "", "");
}

function doExit() 
{
	var formName = doExitImpl();
	if (!formName) return false;

	doSubmit("tdo", "exit", "", "", "", "");
}

//function abstract doSaveImpl();

//function abstract doExitImpl();

//function abstract doSubmitImpl();


function doSubmit(f1, f1Value, f2, f2Value, f3, f3Value, f4, f4Value, f5, f5Value) 
{
	var formName = doSubmitImpl();
	if (!formName) return false;
	
	try {
		initRelationsVarForSave(formName);
	} catch (e) { /*ignore*/ }
	
	try {
		initRechteVarForSave(formName);
	} catch (e) { /*ignore*/ }
	
	try {
	    initPropertyViewerType(formName);
	} catch (e) { /*ignore*/ }
	  
	try {
	
		document.forms[formName].elements[f1].value = f1Value;
		if (f2 && f2!="") {
			document.forms[formName].elements[f2].value = f2Value;
		}
		if (f3 && f3!="") {
			document.forms[formName].elements[f3].value = f3Value;
		}
		if (f4 && f4!="") {
			document.forms[formName].elements[f4].value = f4Value;
		}
		if (f5 && f5!="") {
			document.forms[formName].elements[f5].value = f5Value;
		}
	
	} catch (e) { /*ignore*/ }
	  
	setModal();
	document.forms[formName].submit();
}

function initPropertyViewerType(formName) 
{
	if (document.getElementById("btnPropView1")) {
		document.forms[formName].elements["propView1"].value = document.getElementById("btnPropView1").vistype;
	}
	if (document.getElementById("btnPropView2")) {
		document.forms[formName].elements["propView2"].value = document.getElementById("btnPropView2").vistype;
	}
	if (document.getElementById("btnPropView3")) {
		document.forms[formName].elements["propView3"].value = document.getElementById("btnPropView3").vistype;
	}
	if (document.getElementById("btnPropView4")) {
		document.forms[formName].elements["propView4"].value = document.getElementById("btnPropView4").vistype;
	}
	if (document.getElementById("btnPropView5")) {
		document.forms[formName].elements["propView5"].value = document.getElementById("btnPropView5").vistype;
	}
	if (document.getElementById("btnPropView6")) {
		document.forms[formName].elements["propView6"].value = document.getElementById("btnPropView6").vistype;
	}
	if (document.getElementById("btnPropView7")) {
		document.forms[formName].elements["propView7"].value = document.getElementById("btnPropView7").vistype;
	}
}

function fetchDateinameAsBezeichner(fileelement) 
{
	if (!fileelement || fileelement.value=="") return "";
    
	var rn = "";
	var ix = fileelement.value.lastIndexOf('/');

	if (ix>0) 
	{
		rn = fileelement.value.substring(++ix);
	} 
	else 
	{
		ix = fileelement.value.lastIndexOf('\\');
		if (ix>0) 
		{
			rn = fileelement.value.substring(++ix);
		}
	}

	return rn;    
}

// ----------------------------------------------------------------------------------------------------------------------------
// ----------------------------------------------------------------------------------------------------------------------------

// ----------------------------------------------------------------------------------------------------------------------------
// Modaler Submit
// ----------------------------------------------------------------------------------------------------------------------------
if (MODALSUBMIT) 
{
	document.write('<DIV id="modalSubm" style="LEFT: 5px; TOP: 5px; WIDTH: 1px; cursor: wait; HEIGHT: 1px; VISIBILITY: hidden; POSITION: absolute; z-index: 9000"></DIV>');
}

function setModal() 
{
    var ow = (window.document.body.offsetWidth *1)
    var oh = (window.document.body.offsetHeight *1);
    var sw = (window.document.body.scrollWidth *1)
    var sh = (window.document.body.scrollHeight *1);

	var modalWidth = Math.max(ow, sw);
	var modalHeight = Math.max(oh, sh);

	var waitPos = (window.document.body.scrollTop + 50) + "px";
    var imageRoot = "../";

	var webLoc = (window.location + "");
    if (webLoc.indexOf(".do")>0) 
    {
    	imageRoot = "web/";

	    modalWidth = (modalWidth-30)
    	modalHeight = (modalHeight-5);
    }
    else
    {
		var wi = webLoc.indexOf("web");
		if (wi > 0)
		{
			var relWl = webLoc.substring(wi, webLoc.length)
			var relLevels = relWl.split("/");
     	
			relWl = "";
			relLevels = relLevels.length-2; // 2 => 'web' + 'dateiname'
			for (var i=0; i<relLevels; i++)
			{
	     		relWl += "../";
     		}
	    	imageRoot = relWl;

	    	modalWidth = (modalWidth-10)
    		modalHeight = (modalHeight-5);
		} 
    }

	if (ActualIsIe)
	{
		var i1 = new Image; 
		var i2 = new Image; 
		i1.src = imageRoot + "images/sym/waitBack.gif";
		i2.src = imageRoot + "images/sym/waitCircle.gif";
   	}


    if (window.document.getElementById("modalSubm")) 
    {
  		var htmInner  = ""

		if (ActualIsIe)
		{
  			htmInner  = '<DIV style="position:absolute; top:0px; left:0px; width:"' + modalWidth + 'px; height:' + modalHeight + 'px; z-index: 1000;"><IMG height="' + modalHeight + '" width="'+ modalWidth +'" src="' + imageRoot + 'images/sym/waitBack.gif" border="1" style="cursor: wait; filter:alpha(opacity=50);" galleryimg="no"></DIV>'
            htmInner += '<DIV style="position:absolute; top:' + waitPos + '; left:0px; width:' + modalWidth + 'px; height:' + modalHeight + 'px; z-index: 1100; text-align: center; "><span class="descAdmin" style="border: 1px solid gray; height: 50px; width: 120px; background-color: white; vertical-align: middle; text-align: center"><br><i>bitte warten</i><IMG src="' + imageRoot + 'images/sym/waitCircle.gif" border="0" galleryimg="no" style="margin-left: 8px"></span></DIV>'
    	}
    	else
    	{
			htmInner = '<IMG height="' + modalHeight + '" width="' + modalWidth + '" src="' + imageRoot + 'images/leer.gif" border="0" style="cursor: wait;" galleryimg="no">';
    	}

		window.document.getElementById("modalSubm").style.width = modalWidth;
		window.document.getElementById("modalSubm").style.height = modalHeight;
		window.document.getElementById("modalSubm").innerHTML = htmInner;
		window.document.getElementById("modalSubm").style.visibility = 'visible';
	}
}

function clearModal() 
{
    if (window.document.getElementById("modalSubm")) 
    {
        window.document.getElementById("modalSubm").style.visibility = 'hidden';
    }
}
