

var standardColor;
var rootDivId;
var checkOptions;

function getScrollXY() {
	var scrOfX = 0, scrOfY = 0;

	if( typeof( window.pageYOffset ) == 'number' ) {
		//Netscape compliant
		scrOfY = window.pageYOffset;
		scrOfX = window.pageXOffset;
	} else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
		//DOM compliant
		scrOfY = document.body.scrollTop;
		scrOfX = document.body.scrollLeft;
	} else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
		//IE6 standards compliant mode
		scrOfY = document.documentElement.scrollTop;
		scrOfX = document.documentElement.scrollLeft;
	}
	return [ scrOfX, scrOfY ];
}

function showDebugIn(id, value, name){

  var scrollCheck = getScrollXY();
  scrollCheck = scrollCheck.toString();
  scrollLT =  scrollCheck.split(",");

  var left = window.document.getElementById(id).offsetLeft;
  var top =  window.document.getElementById(id).offsetTop;

  if(left < 1){left = 0;}
  if(top < 1){top = 0;}
  if(!rootDivId){rootDivId = id;}

  //alert(window.document.getElementById('content').offsetWidth);

  var text = "Name: " + name + "<br />ID: " + id + "<br />Value: " + value;

  window.document.getElementById('debugShowDiv').style.left = 10;
  standardColor = window.document.getElementById(id).style.backgroundColor;
  window.document.getElementById(id).style.backgroundColor = '#33FF33';
  window.document.getElementById('debugShowDiv').style.top =  10 + eval(scrollLT[1]);
  window.document.getElementById('debugShowDiv').innerHTML = text;
  }


function showSelectIn(id, value, name){
  var left = window.document.getElementById(id).offsetLeft;
  var top =  window.document.getElementById(id).offsetTop;

  //alert(left);
  //alert(window.document.getElementById('content').offsetWidth);

  var text = "Name: " + name + "<br />ID: " + id + "<br />Value: " + value;
  window.document.getElementById('debugShowDiv').style.left = 10;
  standardColor = window.document.getElementById(id).style.backgroundColor;
  window.document.getElementById('debugShowDiv').style.top =  10;
  window.document.getElementById('debugShowDiv').innerHTML = text;
  }


function showDebugOut(id, value, name){
  window.document.getElementById('debugShowDiv').style.left =  -1000;
  window.document.getElementById('debugShowDiv').style.top =  -1000;
  window.document.getElementById(id).style.backgroundColor = standardColor;
  }

function setRootDivId(id){
  rootDivId = id;
}

function showDivFile(id, show){
  if(show == 1){
      window.document.getElementById(id).style.display = 'inline';
      }else{
           window.document.getElementById(id).style.display = 'none';
          }
}

var catOld = 0;
function showName(id,name,field)
  {
          //alert(id + " - " + name + " - " + field) ;
	  var temp = window.document.getElementById("valuationID").value;

		if(window.document.getElementById(temp) && temp > 0 ){window.document.getElementById(temp).className = "white";}

		if(window.document.getElementById(catOld) && catOld != 0 ){window.document.getElementById(catOld).className = "white";}

	catOld = id;

	window.document.getElementById(field).value = name;
	window.document.getElementById("menueIDHauptmenue").value = id;

	if(window.document.getElementById(id).className == "white")
	  {
		window.document.getElementById(id).className = "blue";
		}else
		   {
				window.document.getElementById(id).className = "white";
			 }
	window.document.getElementById("valuationID").value = id;
	}

function question(value)
	{

  //alert("this " + value);
	var text = "";
		if(value == "linkAdmin") {
			text = "Wollen Sie die Inndizierung wirklich starten?";
			text = text + "\nDieser Vorgang kann mehrere Minuten dauern.";
		 	}
    if(value == "deleteMenu") {
			text = "Wollen Sie den Menüeintrag wirklich löschen? Es wird nur der Menüeintrag entfernt. Die dazugehörigen Seiten ";
      text = text + "und Scripte bleiben erhalten. Sie müssen diese manuell entfernen!";
		 	}
    if(value == "deleteAttrSatz") {
			text = "Wollen Sie den Attribut Satz wirklich löschen?";
		 	}
    if(value == "deleteAttribut") {
			text = "Wollen Sie das Attribut wirklich löschen?\nEs wird nur das Attribut für den gewählten Attributsatz gelöscht.\nDiese Action kann nicht rückgängig gemacht werden!";
		 	}
    if(value == "deleteAttributAll") {
			text = "Wollen Sie das Attribut wirklich löschen?\nEs wird das Attribut bei allen Attributsätzen gelöscht!\nDiese Action kann nicht rückgängig gemacht werden!";
		 	}
    if(value == "changeCron") {
			text = "Wollen Sie den Cronjob wirklich ändern?";
		 	}
    if(value == "deleteCron") {
			text = "Wollen Sie den Cronjob wirklich löschen?";
		 	}
    if(value == "startCron") {
			text = "Wollen Sie den Cronjob wirklich starten?";
		 	}
    if(value == "deleteUser") {
			text = "Wollen Sie den User wirklich löschen?";
		 	}
    if(value == "allocation") {
			text = "Wollen Sie die Zuordnungen wirklich löschen?\nDiese Action kann nicht rückgängig gemacht werden!";
		 	}
    if(value == "textCat") {
			text = "Sie lesen jetzt die gesamten Ebay Kategorien aus der Textdatei neu in die Datenbank ein. Das kann einge Minuten dauern.\n";
      text = text + "Bitte brechen Sie die Aktion nicht ab.\nDas könnte die Datenbank zerstören! \nWollen Sie diese Aktion wirklich ausführen? ";
		 	}
    if(value == "reclaNo") {
			text = "Die Datenbank wird zurück gesetzt. Alle folgenden Aktionen\n(auch schon begonnene) werden gestoppt.\nBitte prüfen Sie eventuelle Zahlungen und Warenrücksendungen!\n";
		 	}
    if(value == "changeLiefer") {
			text = "Wollen Sie den Lieferanten wirklich ändern?";
		 	}
    if(value == "deleteLiefer") {
			text = "Wollen Sie den Lieferanten wirklich löschen?";
		 	}
    if(value == "newProject") {
			text = "Wenn Sie ein neues Projekt anlegen, werden alle benötigten Grundlagendateien automatisch erstellt und in die jeweiligen Ordner integriert. ";
      text = text + "Für die eigenen Klassen wird ein Ordner aber noch keine Standarddatei erstellt. Die Klassendatei müssen Sie selbst erstellen und über Ihre ";
      text = text + "Scriptdateien einbinden. Bitte benutzen Sie nur diese Ordner für Ihre Klassen, Scripte und Styles. Es existiert momentan noch keine ";
      text = text + "Löschroutine. Wenn Sie ein Projekt falsch oder versehentlich erstellt haben, löschen Sie bitte nicht die Ordner!";
		 	}
    if(value == "endProject") {
			text = "Wollen Sie das Projekt wirklich beenden? Sie sehen das Projekt dann noch in dem Menüpunkt \"beendete Projekte\". ";
      text = text + "Es sind keine Gebote und Kommentare mehr möglich.";
		 	}
    if(value == "reactivate") {
			text = "Sie stellen damit das gewählte Projekt mit den gleichen Daten ein, die dafür hinterlegt sind. Nur der Startzeitraum wird auf ";
      text = text + "heute festgelegt. Das Projekt ist sofort sichtbar und aktiv. Wenn Sie danach Änderungen vornehmen wird es wieder bis zur ";
      text = text + "Überprüfung inaktiv.";
		 	}




		var agree = confirm(text);
					if (agree)
						{
						 return true;
						}
						else
							{
							return false;
							}
	}

function adminCheckShow(hidden,id,unique1,unique2,unique3)
  {

  var hiddenID = hidden + id;
  var adminstatus = hiddenID + "_1";
  var superadminstatus = hiddenID + "_2";
  var permission = hiddenID + "_3";

  var adminstatusID = "ID" + unique1 + "_0";
  var superadminstatusID = "ID" + unique2 + "_0";
  var permissionID = "ID" + unique3 + "_0";

  //alert(adminstatus);
  if(window.document.getElementsByName(adminstatus)[0].value == 1)
    {window.document.getElementById(adminstatusID).checked = true;}else{window.document.getElementById(adminstatusID).checked = false;}
  //alert(superadminstatusID);
  if(window.document.getElementsByName(superadminstatus)[0].value == 1)
    {window.document.getElementById(superadminstatusID).checked = true;}else{window.document.getElementById(superadminstatusID).checked = false;}
  //alert(permissionID);
  if(window.document.getElementsByName(permission)[0].value == 1)
    {window.document.getElementById(permissionID).checked = true;}else{window.document.getElementById(permissionID).checked = false;}

  }

function startCronjobNow(id,name,session,choice){

  text = "Wollen Sie den Cronjob wirklich starten?";
  var agree = confirm(text);
  	if (agree)
  		{
       name = name.replace(/-/g,"_");
       name = name.replace(" ","_");
       //alert(name) ;
  		 var path = "execution/cronjobs/startCronjobShow.php?session=" + session + "&cronID=" + id + "&serverChoice=" + choice + "&name=" + name;
       //alert(path);
       var win = window.open(path,name,"width=800px,height=500px,left=50px,top=50px,resizable=yes,menubars=yes,scrollbars=yes");
  		 return true;
  		}
  		else
  			{
  			return false;
  			}

  }


function startCronjobRequest(id,name,session,choice){

  text = "Wollen Sie den Cronjob-Request wirklich starten?";
  var agree = confirm(text);
  	if (agree)
  		{
  		 var path = "execution/cronjobs/startCronjobRequest.php?session=" + session + "&cronID=" + id + "&serverChoice=" + choice + "&name=" + name;
       name = name.replace(/-/g,"_");
       name = name.replace(" ","_");
       //alert(path);
       var win = window.open(path,name,"width=1400px,height=600px,left=50px,top=50px,resizable=yes,menubars=yes,scrollbars=yes");
  		 return true;
  		}
  		else
  			{
  			return false;
  			}

  }


function showInfo(infoValue,session){

 if(infoValue == 'cronjob'){
    var path = "execution/cronjobs/showCronTab.php?session=" + session;
    }

 var win = window.open(path,name,"width=800px,height=500px,left=50px,top=50px,rezizable=yes,menubars=yes");
 }

function createCronjobNow(session,unique,index,serverChoice){
  var idNew = unique + "_" + index;
  var path = "execution/cronjobs/createCronjobShow.php?session=" + session + "&cronID=" + idNew + "&serverChoice=" + serverChoice;
  //alert(path);
  var win = window.open(path,name,"width=850px,height=500px,left=50px,top=50px,resizable=yes,menubars=yes");
  }

function setStandardServerpath(uniqueIDTo,indexTo,uniqueIDFrom,indexFrom){

  var indexToNew = "ID" + uniqueIDTo + "_" + indexTo;
  var indexFromNew = "ID" + uniqueIDFrom + "_" + indexFrom;

  var valueEnd = window.document.getElementById(indexToNew).value;
  var valueStart = window.document.getElementById(indexFromNew).value;

  if(valueEnd.indexOf(valueStart) != -1){
    var startString = eval(valueEnd.indexOf(valueStart) + valueStart.length);
    var newStringLen = eval(valueEnd.length - startString);
    var newSringPart2 = valueEnd.substr(startString,newStringLen);
    var newStringExport = valueStart + newSringPart2;
    window.document.getElementById(indexToNew).value = newStringExport;
    }else{
        var newStringExport = valueStart + valueEnd;
        window.document.getElementById(indexToNew).value = newStringExport;
        }

  }

function setStandardDirectory(uniqueIDTo,indexTo,uniqueIDFrom,indexFrom,uniqueIDFrom1,indexFrom1){

  var indexToNew = "ID" + uniqueIDTo + "_" + indexTo;
  var indexFromNew = "ID" + uniqueIDFrom + "_" + indexFrom;
  var indexFromNew1 = "ID" + uniqueIDFrom1 + "_" + indexFrom1;

  var valueEnd = window.document.getElementById(indexToNew).value;
  var valueStart = window.document.getElementById(indexFromNew).value;
  var valueStart1 = window.document.getElementById(indexFromNew1).value;

  if(valueEnd.indexOf(valueStart) != -1){
  //Directory wurde eingetragen
    //suchen, ob bereits der Serverpfad eingegeben wurde
    if(valueEnd.indexOf(valueStart1) != -1){
      var startString = valueEnd.indexOf(valueStart1);
      var newStringLen = valueStart1.length;
      var newSringPart1 = valueEnd.substr(startString,newStringLen);
      }else{var newSringPart1 = "";}

    var startString2 = eval(valueEnd.indexOf(valueStart) + valueStart.length);
    var newStringLen = eval(valueEnd.length - startString2);
    var newSringPart3 = valueEnd.substr(startString2,newStringLen);
    var newSringPart2 = valueStart;
    }else{
        //Directory noch nicht eingetragen
        var newSringPart2 = valueStart;

        if(valueEnd.indexOf(valueStart1) != -1){
          var startString = valueEnd.indexOf(valueStart1);
          var newStringLen = valueStart1.length;
          var newSringPart1 = valueEnd.substr(startString,newStringLen);

           var startString2 = eval(valueEnd.indexOf(valueStart1) + valueStart1.length);
           var newStringLen = eval(valueEnd.length - startString2);
           var newSringPart3 = valueEnd.substr(startString2,newStringLen);

          }else{var newSringPart1 = "";var newSringPart3 = valueEnd;}

        }

  var newStringExport = newSringPart1 + newSringPart2 + newSringPart3;
  window.document.getElementById(indexToNew).value = newStringExport;

  }

function setCronTimeInField(idMinute,indexMinute,idHour,indexHour,idDay,indexDay,idMonth,indexMonth,idWeekday,indexWeekday,fieldID){

  var minuteID = "ID" + idMinute + "_" + indexMinute;
  var hourID = "ID" + idHour + "_" + indexHour;
  var dayID = "ID" + idDay + "_" + indexDay;
  var monthID = "ID" + idMonth + "_" + indexMonth;
  var weekdayID = "ID" + idWeekday + "_" + indexWeekday;

  var cronString = window.document.getElementById(minuteID).value + " ";
  cronString = cronString + window.document.getElementById(hourID).value + " ";
  cronString = cronString + window.document.getElementById(dayID).value + " ";
  cronString = cronString + window.document.getElementById(monthID).value + " ";
  cronString = cronString + window.document.getElementById(weekdayID).value;

  fieldID = "ID" + fieldID;
  opener.document.getElementById(fieldID).value = cronString;
  }

function CronjobShowComplete(id1,index1,id2,index2){

  var ID1 = "ID" + id1 + "_" + index1;
  var ID2 = "ID" + id2 + "_" + index2;

  var cronString = window.document.getElementById(ID1).value + " ";
  cronString = cronString + window.document.getElementById(ID2).value;

  var win = window.open("","Cronjob","width=850px,height=120px,left=50px,top=50px");
  win.document.open();
  win.document.write(cronString + "<br /><br /><br /><a href='javascript:self.close();'>Fenster schlie&szlig;en</a>");
  win.document.close();
  }

function showHelp(infoID,session){
 var path = "execution/cronjobs/showHelpCron.php?cronID=" + infoID + "&session=" + session;
 var win = window.open(path,'help',"width=800px,height=500px,left=50px,top=50px,rezizable=yes,menubars=yes");
 }


//globales array für check der textfelder, die einen Inhalt haben müssen
checkOptions = new Array();
//  id = id der checkbox zur Artikelauswahl
//  checkOptions[id][0] = counter
//  checkOptions[id][1] = check-Flag (ist die checkbox zur Artikelauswahl aktiviert oder nicht)
//  checkOptions[id][2] = required Flag (ist eine Texteingabe für reklamation erforderlich oder nicht)
//  checkOptions[id][3] = id des Feldes (div) für Stückzahl eingabe
//  checkOptions[id][4] = id des Feldes (div) für Reklamationstexteingabe
//  Bedeutung Flag: 0 = nicht aktiviert, 1 = aktiviert

function showReclaSetDiv(session,id,textCounter,index,divID,checkID){
      var newCheckID = "ID" + checkID + "_" + textCounter;
      var newID = id + textCounter;
      var newDivID = divID + textCounter;

  if(index == 0){
        window.document.getElementById(newID).style.display = "none";
        }else{

            window.document.getElementById(newDivID).innerHTML = jsReclaDesc[(index)][0];
            checkOptions[newCheckID][2] = jsReclaDesc[(index)][1];      //required Flag setzen
            window.document.getElementById(newID).style.display = "block";
            }
}

function checkShowRecla(selectID,divID,counter,checkID,buttonID,setCounter,hideDiv,textDiv,countDiv){
    var newSelectID = "ID" + selectID + "_" + counter;
    var newCountDivID = "ID" + countDiv + "_" + counter;
    var newTextDivID = "ID" + textDiv + "_" + counter;
    var newDivID = divID + counter;
    var newHideDivID = hideDiv + counter;
    var newButtonID = "ID" + buttonID + "_" + counter;

    checkOptions[checkID] = new Array;
    checkOptions[checkID][3] = newCountDivID;        //id des Feldes (div) für Stückzahl eingabe
    checkOptions[checkID][4] = newTextDivID;         //id des Feldes (div) für Reklamationstexteingabe

    if(window.document.getElementById(checkID).checked == true){
      window.document.getElementById(newSelectID).disabled = false;
      if(buttonID > 0 && setCounter > 0){
        window.document.getElementById(newButtonID).disabled = false;
        }
      window.document.getElementById(newDivID).style.display = "block";
      checkOptions[checkID][1] = 1;   //Flag für die checkbox (an oder aus)
      }else{
          window.document.getElementById(newSelectID).disabled = true;
          if(buttonID > 0 && setCounter > 0){
           window.document.getElementById(newButtonID).disabled = true;
           }
          if(setCounter > 0 && hideDiv != 'no'){
            window.document.getElementById(newHideDivID).style.display = "none";
            }
          window.document.getElementById(newDivID).style.display = "none";
          checkOptions[checkID][1] = 0;    //Flag für die checkbox (an oder aus)
          }

}

function recleShowSetDetail(divID,counter,reclaCounter,reclaID){
    var newDivID = divID + counter;
     var newHildeID = "ID" + reclaID + "_" + counter;
    if(window.document.getElementById(newDivID).style.display == "block"){
      window.document.getElementById(newDivID).style.display = "none";
      window.document.getElementById(newHildeID).value = 0;
      }else{
          window.document.getElementById(newDivID).style.display = "block";
          window.document.getElementById(newHildeID).value = 1;
         }
}

function checkFields(){
    var error = 0; var checkError = 1;
    for (var index in checkOptions){
      if(checkOptions[index][1] == 1){
        checkError = 0;
        if(checkOptions[index][2] == 1){
          if(window.document.getElementById(checkOptions[index][4]).value == ""){
            alert("Bitte geben Sie einen Reklamationstext ein. \n(Feld ist rot gekennzeichnet)");
            window.document.getElementById(checkOptions[index][4]).style.backgroundColor = '#FF9980';
            error = 1;
            }else{
                 window.document.getElementById(checkOptions[index][4]).style.backgroundColor = '#FFFFFF';
                }
          }
        if(window.document.getElementById(checkOptions[index][3]).value < 1){
          alert("Bitte geben Sie eine Rücksendemenge ein. \n(Feld ist rot gekennzeichnet)");
          window.document.getElementById(checkOptions[index][3]).style.backgroundColor = '#FF9980';
          error = 1;
          }else{
                 window.document.getElementById(checkOptions[index][3]).style.backgroundColor = '#FFFFFF';
                }
         }
      }
 if(checkError == 1){alert("Bitte wählen Sie mindestens 1 Position aus!");}
 if(error == 1 || checkError == 1){return false;}else{return true;}
}

function menueHide(name1,name2,idButton,idFiled){
     if(window.document.getElementById('menue').className == 'showThis'){
      window.document.getElementById('menue').className = 'showNoThis';
      window.document.getElementById(idButton).value = name1;
      window.document.getElementById(idFiled).value = 1;
      }else{
          window.document.getElementById('menue').className = 'showThis';
          window.document.getElementById(idButton).value = name2;
          window.document.getElementById(idFiled).value = 0;
          }
}

function showOfferLink(id,ses){
  var path = "execution/cronjobs/showOfferLinkSite.php?id=" + id + "&session=" + ses;
  var win = window.open(path,"showOffer","width=1200px,height=800px,left=20px,top=20px,resizable=yes,scrollbars=yes");
  }

function setKeyword(id,fieldValue) {
  window.document.getElementById(id).value = fieldValue;
  }

function showReclaHideAddOn(id){
  //alert(window.document.getElementById(id).className);
        if(window.document.getElementById(id).className == 'showThis'){
            window.document.getElementById(id).className = 'showNoThis';
          }else{
              window.document.getElementById(id).className = 'showThis';
              }
}

function setCheckAll(unique,menge){
  var newID; var i = 0;
  for(i = 0; i < menge; i++){
    newID = "ID" + unique + "_" + i;
    window.document.getElementById(newID).checked = true;
    }
  }

