
lvtexte = new Array();
savePos = -1;
zweitfenster = null;

function openlvwindow(einheit, preis, kurztext, langtext) {
	openlvwindowkomplett("0", "", "", einheit, preis, "", kurztext, langtext);
}


function addToLV (id) {
	var myVar = lvtexte[id];
	openlvwindowkomplett(myVar[0], myVar[1], myVar[2], myVar[3], myVar[4], myVar[5], myVar[6], myVar[7]);
}

function addAllToLV() {
	openLV();
}

function openEditor() {
	if (typeof lvwindow == 'undefined') {
		lvwindow = window.open("", "cmslv", "width=1000,location=no,toolbar=no,resizable=yes");
	}
	if(typeof lvwindow == 'undefined'){
		lvwindow = window.open("typo3conf/ext/cdt_spectext/pi1/ats/index.htm", "cmslv", "width=1000,location=no,toolbar=no,resizable=yes");
	}
	if(lvwindow.closed == true){
		lvwindow = window.open("typo3conf/ext/cdt_spectext/pi1/ats/index.htm", "cmslv", "width=1000,location=no,toolbar=no,resizable=yes");
	}
	if (lvwindow.location.href == "about:blank"){
		lvwindow.location.href = "typo3conf/ext/cdt_spectext/pi1/ats/index.htm";
	}
	lvwindow.focus();
}

function openLV() {

	if (typeof lvwindow == 'undefined') {
		lvwindow = window.open("", "cmslv", "width=1000,location=no,toolbar=no,resizable=yes");
	}
	if(typeof lvwindow == 'undefined'){
		lvwindow = window.open("typo3conf/ext/cdt_spectext/pi1/ats/index.htm", "cmslv", "width=1000,location=no,toolbar=no,resizable=yes");
	}
	if(lvwindow.closed == true){
		lvwindow = window.open("typo3conf/ext/cdt_spectext/pi1/ats/index.htm", "cmslv", "width=1000,location=no,toolbar=no,resizable=yes");
	}
	if (lvwindow.location.href == "about:blank"){
		lvwindow.location.href = "typo3conf/ext/cdt_spectext/pi1/ats/index.htm";
	}
	lvwindow.focus();
	if(typeof aktiv == 'undefined') {
		aktiv = window.setInterval("sendAllData()", 2000);
		zaehler = 1;
	} else {
		if (aktiv == 0) {
			aktiv = window.setInterval("sendAllData()", 2000);
		}
	}
}

function sendAllData() {
	for (a=0; a < lvtexte.length; a++) {
		if (lvwindow.frames["unten"].insertPositionAt != -1){
			savePos = lvwindow.frames["unten"].insertPositionAt-1;
		}
		/*if (lvwindow.frames["unten"].insertPositionAt == -1){
			if (savePos < 0)
				savePos = 0;
			savePos++;
			lvwindow.frames["unten"].insertPositionAt = savePos;
		}*/
		if (savePos > -1) {
			savePos++;
			lvwindow.frames["unten"].insertPositionAt = savePos;
		}
		var xRows = lvwindow.frames["unten"].uniqueID;
		insertAT(lvtexte[a][0], lvtexte[a][1], lvtexte[a][6], lvtexte[a][7], lvtexte[a][2], lvtexte[a][3], lvtexte[a][4], lvtexte[a][5]);
		xRows = lvwindow.frames["unten"].uniqueID - xRows;
		if (savePos > -1) {
			if (xRows > 1)
				savePos = savePos + xRows -1;
		}
		if (a == lvtexte.length-1) {
				savePos = -1;
		}
	}
}

function openlvwindowkomplett(typ, titel, menge, einheit, preis, gpreis, kurztext, langtext) {
   	if (typeof lvwindow == 'undefined') {
		lvwindow = window.open("", "cmslv", "width=1000,location=no,toolbar=no,resizable=yes");
	}
	if(typeof lvwindow == 'undefined'){
		lvwindow = window.open("typo3conf/ext/cdt_spectext/pi1/ats/index.htm", "cmslv", "width=1000,location=no,toolbar=no,resizable=yes");
	}
	if(lvwindow.closed == true){
		lvwindow = window.open("typo3conf/ext/cdt_spectext/pi1/ats/index.htm", "cmslv", "width=1000,location=no,toolbar=no,resizable=yes");
	}
	if (lvwindow.location.href == "about:blank"){
		lvwindow.location.href = "typo3conf/ext/cdt_spectext/pi1/ats/index.htm";
	}
	lvwindow.focus();
	if(typeof aktiv == 'undefined') {
		aktiv = window.setInterval("insertAT('" + typ + "', '" + titel + "', '" + kurztext + "', '" + langtext + "', '" + menge + "', '" + einheit + "', '" + preis + "', '" + gpreis + "')", 2000);
		zaehler = 1;
	} else {
		if (aktiv == 0) {
			aktiv = window.setInterval("insertAT('" + typ + "', '" + titel + "', '" + kurztext + "', '" + langtext + "', '" + menge + "', '" + einheit + "', '" + preis + "', '" + gpreis + "')", 2000);
		}
	}
}

function openlvwindowInsertArtID(ID) {
   	if(typeof lvwindow == 'undefined') {
		lvwindow = window.open("", "cmslv", "width=1000,location=no,toolbar=no,resizable=yes");
	}
	if(typeof lvwindow == 'undefined'){
		lvwindow = window.open("typo3conf/ext/cdt_spectext/pi1/ats/index.htm", "cmslv", "width=1000,location=no,toolbar=no,resizable=yes");
	}
	if(lvwindow.closed == true){
		lvwindow = window.open("typo3conf/ext/cdt_spectext/pi1/ats/index.htm", "cmslv", "width=1000,location=no,toolbar=no,resizable=yes");
	}
	if (lvwindow.location.href == "about:blank"){
		lvwindow.location.href = "typo3conf/ext/cdt_spectext/pi1/ats/index.htm";
	}
	lvwindow.focus();
	if(typeof aktiv == 'undefined') {
		aktiv = window.setInterval("insertArtID('" + ID + "')", 2000);
		zaehler = 1;
	} else {
		if (aktiv == 0) {
			aktiv = window.setInterval("insertArtID('" + ID + "')", 2000);
		}
	}
}
function openlvwindowInsertSysIDs(IDs) {
   	if(typeof lvwindow == 'undefined') {
		lvwindow = window.open("", "cmslv", "width=1000,location=no,toolbar=no,resizable=yes");
	}
	if(typeof lvwindow == 'undefined'){
		lvwindow = window.open("typo3conf/ext/cdt_spectext/pi1/ats/index.htm", "cmslv", "width=1000,location=no,toolbar=no,resizable=yes");
	}
	if(lvwindow.closed == true){
		lvwindow = window.open("typo3conf/ext/cdt_spectext/pi1/ats/index.htm", "cmslv", "width=1000,location=no,toolbar=no,resizable=yes");
	}
	if (lvwindow.location.href == "about:blank"){
		lvwindow.location.href = "typo3conf/ext/cdt_spectext/pi1/ats/index.htm";
	}
	lvwindow.focus();
	if(typeof aktiv == 'undefined') {
		aktiv = window.setInterval("insertSysIDs('" + IDs + "')", 2000);
		zaehler = 1;
	} else {
		if (aktiv == 0) {
			aktiv = window.setInterval("insertSysIDs('" + IDs + "')", 2000);
		}
	}
}

function openlvwindowInsertSysID(ID) {
   	if(typeof lvwindow == 'undefined') {
		lvwindow = window.open("", "cmslv", "width=1000,location=no,toolbar=no,resizable=yes");
	}
	if(typeof lvwindow == 'undefined'){
		lvwindow = window.open("typo3conf/ext/cdt_spectext/pi1/ats/index.htm", "cmslv", "width=1000,location=no,toolbar=no,resizable=yes");
	}
	if(lvwindow.closed == true){
		lvwindow = window.open("typo3conf/ext/cdt_spectext/pi1/ats/index.htm", "cmslv", "width=1000,location=no,toolbar=no,resizable=yes");
	}
	if (lvwindow.location.href == "about:blank"){
		lvwindow.location.href = "typo3conf/ext/cdt_spectext/pi1/ats/index.htm";
	}
	lvwindow.focus();
	if(typeof aktiv == 'undefined') {
		aktiv = window.setInterval("insertSysID('" + ID + "')", 2000);
		zaehler = 1;
	} else {
		if (aktiv == 0) {
			aktiv = window.setInterval("insertSysID('" + ID + "')", 2000);
		}
	}
}
function openlvwindowInsertID(ID) {
   	if(typeof lvwindow == 'undefined') {
		lvwindow = window.open("", "cmslv", "width=1000,location=no,toolbar=no,resizable=yes");
	}
	if(typeof lvwindow == 'undefined'){
		lvwindow = window.open("typo3conf/ext/cdt_spectext/pi1/ats/index.htm", "cmslv", "width=1000,location=no,toolbar=no,resizable=yes");
	}
	if(lvwindow.closed == true){
		lvwindow = window.open("typo3conf/ext/cdt_spectext/pi1/ats/index.htm", "cmslv", "width=1000,location=no,toolbar=no,resizable=yes");
	}
	if (lvwindow.location.href == "about:blank"){
		lvwindow.location.href = "typo3conf/ext/cdt_spectext/pi1/ats/index.htm";
	}
	lvwindow.focus();
	if(typeof aktiv == 'undefined') {
		aktiv = window.setInterval("insertID('" + ID + "', '')", 2000);
		zaehler = 1;
	} else {
		if (aktiv == 0) {
			aktiv = window.setInterval("insertID('" + ID + "', '')", 2000);
		}
	}
}

function insertID(ID) {
    window.clearInterval(aktiv);
	aktiv = 0;
	if (typeof lvwindow.frames["strg"]!= 'undefined') {
		if (typeof lvwindow.insertID != 'undefined') {
			lvwindow.insertID(ID);
			window.clearInterval(aktiv);
			aktiv = 0;
		} else {
			zaehler = zaehler + 1;
		}
	} else {
		zaehler = zaehler + 1;
	}
	if (zaehler > 20) {
		window.clearInterval(aktiv);
		aktiv = 0;
		alert("Übernahme gescheitert!");
	}
}

function insertSysIDs(IDs) {
	if (typeof lvwindow.frames["strg"]!== 'undefined') {
		if ((typeof lvwindow.insertSysID !== 'undefined') &&
			(typeof lvwindow.frames["strg"].document !== 'undefined') &&
			(typeof lvwindow.frames["strg"].document.forms["form1"] !== 'undefined')) {
			window.clearInterval(aktiv);
			aktiv = 0;
			lvwindow.insertSysIDs(IDs);
		} else {
			zaehler = zaehler + 1;
		}
	} else {
		zaehler = zaehler + 1;
	}
	if (zaehler > 20) {
		window.clearInterval(aktiv);
		aktiv = 0;
	//	alert("Übernahme gescheitert!");
	}
}

function insertSysID(ID) {
    //window.clearInterval(aktiv);
	//aktiv = 0;

	if (typeof lvwindow.frames["strg"]!== 'undefined') {
		if ((typeof lvwindow.insertSysID !== 'undefined') &&
			(typeof lvwindow.frames["strg"].document !== 'undefined') &&
			(typeof lvwindow.frames["strg"].document.forms["form1"] !== 'undefined')) {
			window.clearInterval(aktiv);
			aktiv = 0;
			lvwindow.insertSysID(ID);
		} else {
			zaehler = zaehler + 1;
		}
	} else {
		zaehler = zaehler + 1;
	}
	if (zaehler > 20) {
		window.clearInterval(aktiv);
		aktiv = 0;
		alert("Übernahme gescheitert!");
	}
}

function insertArtID(ID) {
    window.clearInterval(aktiv);
	aktiv = 0;
	if (typeof lvwindow.frames["strg"]!= 'undefined') {
		if (typeof lvwindow.insertArtID != 'undefined') {
			lvwindow.insertArtID(ID);
			window.clearInterval(aktiv);
			aktiv = 0;
		} else {
			zaehler = zaehler + 1;
		}
	} else {
		zaehler = zaehler + 1;
	}
	if (zaehler > 20) {
		window.clearInterval(aktiv);
		aktiv = 0;
		alert("Übernahme gescheitert!");
	}
}

function insertMultipleAT(typ, titel, kurztext, langtext, menge, einheit, epreis, gpreis, reset) {
	if (typeof lvwindow.frames["unten"]!= 'undefined') {
		if (typeof lvwindow.frames["unten"].insertProdukt != 'undefined') {
			if ((savePos != -1) || (lvwindow.frames["unten"].insertPositionAt != -1)){
				if  (lvwindow.frames["unten"].insertPositionAt != -1){
					savePos = lvwindow.frames["unten"].insertPositionAt;
				}
				if (lvwindow.frames["unten"].insertPositionAt == -1){
					savePos++;
					lvwindow.frames["unten"].insertPositionAt = savePos;
				}
			}
			lvwindow.insertProdukt(typ, titel, kurztext, langtext, menge, einheit, epreis, gpreis);
			if (reset) {
				savePos = -1;
			}
			window.clearInterval(aktiv);
			aktiv = 0;
		} else {
			zaehler = zaehler + 1;
		}
	} else {
		zaehler = zaehler + 1;
	}
	if (zaehler > 20) {
		window.clearInterval(aktiv);
		aktiv = 0;
		alert("Übernahme gescheitert!");
	}
}

function insertAT(typ, titel, kurztext, langtext, menge, einheit, epreis, gpreis) {
	if (typeof lvwindow.frames["unten"]!= 'undefined') {
		if (typeof lvwindow.frames["unten"].insertProdukt != 'undefined') {
			lvwindow.insertProdukt(typ, titel, kurztext, langtext, menge, einheit, epreis, gpreis);
			window.clearInterval(aktiv);
			aktiv = 0;
		} else {
			zaehler = zaehler + 1;
		}
	} else {
		zaehler = zaehler + 1;
	}
	if (zaehler > 20) {
		window.clearInterval(aktiv);
		aktiv = 0;
		alert("Übernahme gescheitert!");
	}
}