// JavaScript Document zur Steuerung der Navigation
// bei Deaktivierung von Javascript ist die Navigation voll funktionsfaehig

/* --allgemeine Funktion zum oeffnen von externen Fenstern -- */
/* -------------------------------------------------------------------------------------------------------------- */
function openPopup(theUrl, theWindowName, theWidth, theHeight){    
    lWindowLook = "height="+theHeight+",width="+theWidth+",status=yes,toolbar=no,menubar=yes,scrollbars=yes,location=no,resizable=yes,top=1,left=1";
    var lWin = window.open(theUrl, theWindowName , lWindowLook);
}



/* --Funktion zur Steuerung der verteilten Katalog Administration -- */
/* -------------------------------------------------------------------------------------------------------------- */

function controlFedCatalogues(theTargetId){

    if(theTargetId == '1'){
        document.getElementById('distrCatalogForm').target='contentFrame';
        document.getElementById('distrCatalogForm').submit();
    }
    if(theTargetId == '2'){
        window.open('about:blank' ,'verifyWindow', "height=200,width=300,status=yes,toolbar=no,menubar=no,location=no,resizable=yes,dependent=yes,top=1,left=1");
        document.getElementById('distrCatalogForm').target='verifyWindow';
        document.getElementById('distrCatalogForm').submit();
    }


}

function controlQuerySettings(theAction){
    document.getElementById('modifyActionType').value=theAction;
    document.getElementById('querySettingsForm').submit();

}

/* --Funktion zur Steuerung der Auswahl der verteilten Katalog -- */
/* -------------------------------------------------------------------------------------------------------------- */
function openDetailWindow(theContext, theMessage){
    var counter = 0;
    var theFildID='';
    for (i = 0; i < document.getElementById('catalogList').length; ++i){
        if (document.getElementById('catalogList').options[i].selected == true){
          theFileID=document.getElementById('catalogList').options[i].value;
          counter++;
        }
    }

    if((counter==0) || (counter  > 1)){
        alert(theMessage);
    }else{
        theUrl=theContext + '?fileIdentifier=' + encodeURIComponent(theFileID);
        window.open(theUrl ,'detailWindow', "height=534,width=710,status=yes,toolbar=no,menubar=no,scrollbars=yes,location=no,resizable=yes,dependent=yes,top=1,left=1");
    }
}

/* ----------------------Funktion zur Steuerung des einstellen und loeschen von Templates  ---------------------- */
/* -------------------------------------------------------------------------------------------------------------- */
function controlTemplateQueries(theAction){
    document.getElementById('executeType').value = theAction
    var lTemplateFormArray = document.getElementsByTagName("form");
    //lTemplateFormArray.submit();
    for (var i = 0; i < lTemplateFormArray.length; i++) {
        if(lTemplateFormArray[i].className == "templateFormElement"){
            lTemplateFormArray[i].submit();
            break;
        }
    }
    //document.getElementById('templateForm').submit();
}

/* --Extended Search ----------------------------------------------------------------------------------------------*/
/* --Funktion zur Steuerung der Formularelemete beim Abschicken der Erweiterten Suche  ----------------------------*/
/* --------------------------------------------------------------------------------------------------------------- */
function controlExtendedQuery(theAction){
    /*if(theAction == '3'){
        if(!controlSelectedFields('multiBoxValue(queryType)', 'extendedQueryForm', theHlvMissing)){
            return false;
        }
    } */

    //Auslesen der DivElemente
    //wenn Element vorhanden und style= nix dann = show
    //wenn Element vorhanden und style = block dann show
    //wenn Element vorhanden und style =  none dann hide
    
    //wenn Element nicht vorhanden dann = hide

    document.getElementById('categoryElementMap(cCategory)').value='show';

    /*f(document.getElementById('cCategory')){
        if(document.getElementById('cCategory').style == undefined || document.getElementById('cCategory').style.display == 'block'){
             document.getElementById('categoryElementMap(cCategory)').value='show';    
        }else{
            document.getElementById('categoryElementMap(cCategory)').value='hide';
        }
    }else{
        document.getElementById('categoryElementMap(cCategory)').value='hide';
    } */

    if(document.getElementById('cDescription')){
        if(document.getElementById('cDescription').style.display == 'none'){
             document.getElementById('categoryElementMap(cDescription)').value='hide';
        }else{
            document.getElementById('categoryElementMap(cDescription)').value='show';
        }
    }else{
        document.getElementById('categoryElementMap(cDescription)').value='hide';
    }

    if(document.getElementById('cMetadata')){
        if(document.getElementById('cMetadata').style.display == 'none'){
             document.getElementById('categoryElementMap(cMetadata)').value='hide';
        }else{
            document.getElementById('categoryElementMap(cMetadata)').value='show';
        }
    }else{
        document.getElementById('categoryElementMap(cMetadata)').value='hide';
    }

    if(document.getElementById('cKonformitaet')){
        if(document.getElementById('cKonformitaet').style.display == 'none'){
             document.getElementById('categoryElementMap(cKonformitaet)').value='hide';
        }else{
            document.getElementById('categoryElementMap(cKonformitaet)').value='show';
        }
    }else{
        document.getElementById('categoryElementMap(cKonformitaet)').value='hide';
    }


    if (document.getElementById('selectedStoredQuery')){
            var theSelList = document.getElementById('selectedStoredQuery');
            document.getElementById('executeType').value=theAction;
            if (!theSelList.options[0].selected){
                document.getElementById('extendedQueryForm').submit();
            }
    }else{
        document.getElementById('executeType').value=theAction;
        document.getElementById('extendedQueryForm').submit();
    }
 }

/* --Funktion zur Steuerung der Extended Query bei Auswahl der 'Selektionsliste' Typ und beim Aufbau der Seite  ------------------- */

function controlSearchFields(theObj) {

    if (controlSearchFields.arguments.length == 1){
        var theTypObj = document.getElementById(theObj.id);
        var theObjValue = theObj.value;
    }  else{
        var theTypObj = document.getElementById('selectedQueryType');
    }

    var counter = 0;
    var hits = 0
    var checkedFields = 0;
    var theFieldArray = new Array();

    while (counter < theTypObj.options.length) {
        if (theTypObj.options[counter].selected) {
            checkedFields = checkedFields + 1;
            theFieldArray[checkedFields] = theTypObj.options[counter].value//
        }
        counter++;
    }

    var lISO19115ExtQueryable = false;
    var lISO19119ExtQueryable = false;



    for (var k = 1; k < checkedFields + 1; k++) {
        if (theFieldArray[k] == "dataset" || (theFieldArray[k] == "datasetCollection") || (theFieldArray[k] == "application")) {
            lISO19115ExtQueryable = true;
        }

        else if ((theFieldArray[k] == "service")) {
            lISO19119ExtQueryable = true;
        }
    }

    if (lISO19115ExtQueryable && lISO19119ExtQueryable) {
        setSelectionListDisabled(false, 'selectedServiceType', "");
        setSelectionListDisabled(false, 'selectedTopicCategoryType', "");
        setSelectionListDisabled(false, 'selectedResourceLanguage', "");
    }

    if (!lISO19115ExtQueryable && !lISO19119ExtQueryable) {
        setSelectionListDisabled(false, 'selectedServiceType', "");
        setSelectionListDisabled(false, 'selectedTopicCategoryType', "");
        setSelectionListDisabled(false, 'selectedResourceLanguage', "");

    }

    if (!lISO19115ExtQueryable && lISO19119ExtQueryable) {
        setSelectionListDisabled(false, 'selectedServiceType', "");
        setSelectionListDisabled(true, 'selectedTopicCategoryType', "");
        setSelectionListDisabled(true, 'selectedResourceLanguage', "");

    }

    if (!lISO19119ExtQueryable && lISO19115ExtQueryable) {
        setSelectionListDisabled(true, 'selectedServiceType', "");
        setSelectionListDisabled(false, 'selectedTopicCategoryType', "");
        setSelectionListDisabled(false, 'selectedResourceLanguage', "");

    }

    lISO19119ExtQueryable = false;
    lISO19115ExtQueryable = false;
    checkedFields = null;

}

var theArray = new Array();

function setSelectionListDisabled(theStatus, theElementId, theDefaultValue){

    var theOptionArray = new Array();

    var theSelectTag;
    var theOptionTag;

    theSelectTag = document.getElementById(theElementId);
    theOptionTag = theSelectTag.options;
    theSelectTag.disabled = theStatus;

    if (theOptionArray.length == 0){
        theOptionArray = storeElementTypeList(theElementId);
    }

    for (var i=0; i < theOptionTag.length; i++ ){
            if (theOptionTag[i].selected){
                theOptionTag[i].value = theOptionArray[i];
                }
    }

    if (theStatus){
            for (var i=0; i < theOptionTag.length; i++ ){
                 theOptionTag[i].setAttribute("disabled","disabled")
                    if(theOptionTag[i].value == theDefaultValue){                         
                        theOptionTag[i].selected = true;                      
                    }


                    if (theOptionTag[i].selected){
                        theOptionTag[i].selected = false;
                    }

            }

        }

    if (!theStatus){
          for (var k=0; k < theOptionTag.length; k++ ){
                theOptionTag[k].removeAttribute("disabled");                   
            }
        }

}

/* --  Funktion Speichert die Werte aus der Selektionsliste der theElementId   -- */
/* ------------------------------------------------------------------------------ */
function storeElementTypeList(theElementId){

	var theSelectTag = document.getElementById(theElementId);
	var theOptionTag = theSelectTag.options
	var theOptionValues = new Array();

	for (var i=0; i < theOptionTag.length; i++ ){
			theOptionValues[i] = theOptionTag[i].value;					}

	return theOptionValues;
}

/* --  Content Admin ----------------------------------------------------------------------- */
/* --------------------------------------------------------------------------------------------- */
function checkUserInformation(theObj){
    var lExplicitUserInformationDiv = document.getElementById('explicitUserInformation');
    var lExplicitUserInformationFileDiv = document.getElementById('explicitUserInformationFile');
    var lImplicitUserInformationFileDiv = document.getElementById('implicitUserInformationFile');

    if((lExplicitUserInformationDiv)){
        if(theObj.checked){
            lExplicitUserInformationDiv.style.display='none';
            lExplicitUserInformationFileDiv.style.display='none';
            lImplicitUserInformationFileDiv.style.display='block';
        }else if(!theObj.checked){
            lExplicitUserInformationDiv.style.display='block';
            lExplicitUserInformationFileDiv.style.display='block';
            lImplicitUserInformationFileDiv.style.display='none';
        }
    }
}


/* --  Wait effect ----------------------------------------------------------------------- */
/* --------------------------------------------------------------------------------------------- */
 InformationInlineWindow = {
    windowWidth:null,
    windowHeight:null,
    navigationWidth:null,
    xCoord:null,yCoord:null,interval:null,
    lightBox:null,
    informationBox:null,
    clear:null,
     

    init: function(){// Initialisierung
        this.navigationWidth = document.getElementById('contentNavBox').clientWidth+1;
        this.lightBox = document.getElementById('lightBox');
        this.informationBox = document.getElementById('informationBox');
        this.calculateContentFrameExtension();        
        this.getStartCoordsForInlineWindow();
        this.clear = "../images/clear.gif" //path to clear.gif

        if(!document.getElementsByTagNameNS){// Browserweiche
            this.pngfix();
        }
        
        window.onresize = function(){                     
                     InformationInlineWindow.getStartCoordsForInlineWindow();
                }
/*        if (window.contentFrame && window.contentFrames.frames.length != 2){
        window.onresize = function(){
                     InformationInlineWindow.calculateContentFrameWidth();
                }
        }
*/        

    },
     
     calculateContentFrameExtension: function(){// Gesamthöhe/ breite des Fenster ermitteln
        if (document.documentElement){
                this.windowWidth = document.documentElement.clientWidth;
                this.windowHeight = document.documentElement.clientHeight;
            }   else{
                this.windowWidth = window.innerWidth;
                this.windowHeight = window.innerHeight;
            }                 
     },

       getStartCoordsForInlineWindow: function(){// x,y Position/ Höhe Info Box
           InformationInlineWindow.calculateContentFrameExtension();
           InformationInlineWindow.getStartCoordsForLightBox();
           this.xCoord = ((this.windowWidth - this.navigationWidth) / 2 + this.navigationWidth) - (parseFloat(this.informationBox.style.width) / 2)-30;
           this.informationBox.style.left = this.xCoord+"px";
     },

     getStartCoordsForLightBox:function(){ // x,y Position/ Höhe Light Box
         this.lightBox.style.left   =   this.navigationWidth+"px";
         this.lightBox.style.top    =   "101px";
         this.lightBox.style.width  =   this.windowWidth - this.navigationWidth+"px";
         this.lightBox.style.height =   this.windowHeight - 102+"px";
     },

     show: function(){ // Lighbox einschalten
         this.informationBox.style.display ="block"
         this.lightBox.style.height = this.windowHeight - 102+"px";
         this.lightBox.style.display ="block"
     },

     hide: function(){ // Lighbox ausschalten
         this.informationBox.style.display ="none";
         this.lightBox.style.display ="none"
     },

    pngfix:function(){// FIX für IE6
        // cc="http://creativecommons.org/ns#"
        // about="http://labs.unitinteractive.com/unitpngfix.php">
        // rel="cc:attributionURL" property="cc:attributionName" href="http://labs.unitinteractive.com/unitinteractive.com">Unit Interactive</a>
        // rel="license" href="http://creativecommons.org/licenses/by/3.0/"

            var els=document.getElementById('lightBox');
            var i_p=/\.png/i;var i=1;var el=els;var es=el.style;

                if(el.src&&el.src.match(i_p)&&es.filter==''){            
                        es.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='"+el.src+"',sizingMethod='crop')";
                        el.src = this.clear;
                }
                            else{
                            var elb=el.currentStyle.backgroundImage;
                            if(elb.match(i_p))
                                {var path=elb.split('"');
                                var rep=(el.currentStyle.backgroundRepeat=='no-repeat')?'crop':'scale';
                                es.filter="progid:DXImageTransform.Microsoft.AlphaImageLoader(src='"+path[1]+"',sizingMethod='"+rep+"')";
                                es.height=el.clientHeight+'px';
                                es.backgroundImage="none";
                            }
                        }
                        if (el.currentStyle.position!='absolute' && !es.filter && !el.tagName.match(/(body|html|script)/gi)) es.position="relative";
                        if (es.filter&&el.currentStyle.position=="relative") es.position="static";
                }
        }



