// Projektspezifische JS-Funktionen
function openPopup(url, ID, mediaID){
	//der array 'IstrListboxTargetPopupstyle' wird in der methode
	//MainOutputClass.GetClientJSPopupTargets() gefuellt...

	if ((mediaID > 0) && (ID == 197)) {
		url = "/main.aspx/G/" + GroupID + "/L/" + LangID + "/A/" + AreaID + "/ID/" + mediaID + "/V/media";
		window.open(url, "ePilotPopup"+ID, IstrListboxTargetPopupstyle[ID]);
	} else {
		//url += "/V/popup/PM/1";
		window.open(url, "ePilotPopup"+ID, IstrListboxTargetPopupstyle[ID]);
	}
}

function openContent(url,ID){
	switch(ID){
		case 4:
			parent.location.href = url;
			break;
		case 5:
			parent.window.opener.location.href = url;
			break;
	}
}

function RunSearch(lngPopupMode) {

  var queryval = encodeURI(document.forms["suche"].elements["Z"].value);
  
  // Die Auswahl des Suchbereiches erfolgt über die Radiobuttons
  var ID = -1;
  
    if(document.forms["suche"].elements["ID"][0].checked == true)
        ID = document.forms["suche"].elements["ID"][0].value;
    else
        ID = document.forms["suche"].elements["ID"][1].value;
  
  if (lngPopupMode > 0) {
    var strLink = IstrPopupLink;
	  strLink += "/ID/" + ID + "/Z/" + queryval;
    openPopup(strLink, lngPopupMode);
  }
  else {
    var strLink = IstrBaseLink;
	  strLink += "/ID/" + ID + "/Z/" + queryval;
	  
    document.location.href = strLink;
  }
}


/* Sensorenuebersicht Anfang */
var produktvergleich = new Array('', '', '');
var productcount = 0;

function CommitValue(objectID, submit) {
    if (!objectID || objectID == "") {
        return;
    }
        
    var removed = false;
    
    // wenn element vorhanden, dann entfernen
    var done = false;
    for (var i = 0; i < 3; i++) {
        if (produktvergleich[i] == objectID) {
            produktvergleich[i] = "";
            productcount--;
            removed = true;
            DisableCheckBox("chk_" + objectID);
            done = true;
        }
        
        if (done) {
            break;
        }
    }

    done = false;
    if (!removed && (productcount < 3)) {
        // wenn bis hier gekommen, dann hinzufuegen
        for(i = 0; i < 3; i++) {
            //alert("inh: " + produktvergleich.length);
            if (produktvergleich[i] == "") {
                produktvergleich[i] = objectID;
                productcount++;
                EnableCheckBox("chk_" + objectID);
                done = true;
            } 
            
            if (done)
                break;
        }
    }
    
    if (productcount == 3) {
        // Feierabend
        DisableAllCheckboxes();
    } else {
        EnableAllCheckboxes();
    }
    
    if (submit) {
        // Parameter Z2 setzen und Seite für Warenkorb neu laden
        document.forms["productselection"].elements["z2"].value = GetZValue();
        document.productselection.submit();
    }
}

function GetZValue() {
    var zvalue = "";
    for (i = 0; i < 3; i++) {
        if (i > 0)
            zvalue += ";";
        zvalue += produktvergleich[i];
    }
    
    return zvalue;
}

function GoCompareProducts() {
    document.forms["productselection"].elements["z2"].value = GetZValue();
    document.forms["productselection"].elements["id"].value = FixID_produktvergleich;
    document.productselection.submit();
}

function DisableAllCheckboxes() {
    var elements = document.getElementsByTagName("input");

    for (i = 0; i < elements.length; i++) {
        if (elements[i].id) {
            if (elements[i].id && elements[i].id.indexOf("chk_") >= 0) {
                if (!IsCheckedElement(elements[i].id)) {
                    elements[i].disabled = true;
                }
            }
        }
    }
}

function EnableAllCheckboxes() {
    var elements = document.getElementsByTagName("input");

    for (i = 0; i < elements.length; i++) {
        if (elements[i].id && elements[i].id.indexOf("chk_") >= 0) {
            if (elements[i].disabled) {
                elements[i].disabled = false;
            }
        }
    }
}

function IsCheckedElement(controlID) {
    for(j = 0; j < 3; j++) {
        if (controlID == "chk_" + produktvergleich[j]) {
            return true;
        }
    }
    return false;
}

function DisableCheckBox(controlID) {
    if (document.getElementById(controlID))
        document.getElementById(controlID).checked = false;
}

function EnableCheckBox(controlID) {
    if (document.getElementById(controlID))
        document.getElementById(controlID).checked = true;
}

function InitProduktUebersicht(value) {
    //produktvergleich = value;
    
    // jetzt zerlegen und checken
    var values = value.split(";");
    
    // die values durchlaufen und prüfen, ob checkbox vorhanden, dann checken.
    for (m = 0; m < 3; m++) {
        CommitValue(values[m], false);
    }
    
    // wenn drei values erreicht sind, dann dürfen keine wieteren checkboxen klickbar sein.
    
}
/* Sensorenuebersicht Ende */

/* Sensorenvergleich Anfang */
//var produktvergleich = new Array('', '', '');
//var productcount = 0;
function AddCompareValue(objectID) {
    if (!objectID || objectID == "") {
        return;
    }
        
    var done = false;
    if (productcount < 3) {
        // wenn bis hier gekommen, dann hinzufuegen
        for(i = 0; i < 3; i++) {
            if (produktvergleich[i] == "") {
                produktvergleich[i] = objectID;
                productcount++;
                done = true;
            } 
            
            if (done)
                break;
        }
    }

}

function CompareProducts() {
    // Das Array löschen.
    produktvergleich = new Array('', '', '');

    // Die selektierten Sensoren der Liste hinzufügen.
    AddCompareValue(document.forms["productselection"].elements["productselectionone"].value);
    AddCompareValue(document.forms["productselection"].elements["productselectionsecond"].value);
    AddCompareValue(document.forms["productselection"].elements["productselectionthird"].value);
    
    // und ab
    GoCompareProducts();
}

function InitProduktVergleich(value) {
    //produktvergleich = value;
    
    // jetzt zerlegen und checken
    var values = value.split(";");
    
    // die values durchlaufen und prüfen, ob checkbox vorhanden, dann checken.
    for (m = 0; m < 3; m++) {
        CommitValue(values[m], false);
    }
    
    // wenn drei values erreicht sind, dann dürfen keine wieteren checkboxen klickbar sein.
    
}
/* Sensorenvergleich Ende */

// FlashScript
function ShowFlash(controlID, src, width, height, quality, bgcolor, align, params) {
	
    if (!align)
        align = "middle"
    if (!bgcolor)
        bgcolor = "#ffffff"
    if (!quality)
        quality = "high"

    var output = "";

    output += '<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0"';

		
    if (width != '')
        output += ' width="' + width + '"';
    if (height != '')
        output += ' height="' + height + '"';
		
    output += ' id="' + controlID + '" align="' + align + '">';

    output += '<param name="allowScriptAccess" value="sameDomain" />';
    output += '<param name="movie" value="' + src + '" />';
    output += '<param name="quality" value="' + quality + '" />';
    output += '<param name="bgcolor" value="' + bgcolor + '" />';

    var embedVars = "";
    if (params) {
        for(var i = 0; i < params.length; i++) {
            output += '<param name="' + params[i]['Key'] + '" value="' + params[i]['Value'] + '" />';
            embedVars += params[i]['Key'] + "=\"" + params[i]['Value'] + "\"";
        }
    }

    output += '<embed src="' + src + '" quality="' + quality + '"';
		
    if (width != '')
        output += ' width="' + width + '"';
    if (height != '')
        output += ' height="' + height + '"'
		
    //output += ' bgcolor="' + bgcolor + '" name="' + controlID + '" align="' + align + '" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" ' + embedVars + '></embed>';
    output += ' bgcolor="' + bgcolor + '" name="' + controlID + '" align="' + align + '" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" ' + embedVars + '></embed>';

    output += '</object>';
    document.write(output);
}


function runSiteSearch( folderPath, navID, langID, restrictedMode, zValue ) {
    if(zValue) {
        var path = folderPath + navID + ',' + langID + ',' + navID + ',' + restrictedMode + ',(' + zValue + '),0,0,0.aspx';
    }
    else {
        var path = folderPath + navID + ',' + langID + ',' + navID + ',' + restrictedMode + ',0,0,0,0.aspx';
    }
    
    window.location = path;
    return false;
}

function setFieldValue( zValue, fieldID ) {
    document.getElementById(fieldID).value = zValue;
}
