
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 openLV() {

	if (typeof lvwindow_e == 'undefined') {
		lvwindow_e = window.open("", "cmslv_e", "");
	}
	if(typeof lvwindow_e == 'undefined'){
		lvwindow_e = window.open("typo3conf/ext/cdt_spectext/pi1/ats_e/index.htm", "cmslv_e", "");
	}
	if(lvwindow_e.closed == true){
		lvwindow_e = window.open("typo3conf/ext/cdt_spectext/pi1/ats_e/index.htm", "cmslv_e", "");
	}
	if (lvwindow_e.location.href == "about:blank"){
		lvwindow_e.location.href = "typo3conf/ext/cdt_spectext/pi1/ats_e/index.htm";
	}
	lvwindow_e.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_e.frames["unten"].insertPositionAt != -1){
			savePos = lvwindow_e.frames["unten"].insertPositionAt-1;
		}
		/*if (lvwindow_e.frames["unten"].insertPositionAt == -1){
			if (savePos < 0)
				savePos = 0;
			savePos++;
			lvwindow_e.frames["unten"].insertPositionAt = savePos;
		}*/
		if (savePos > -1) {
			savePos++;
			lvwindow_e.frames["unten"].insertPositionAt = savePos;
		}
		var xRows = lvwindow_e.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_e.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_e == 'undefined') {
		lvwindow_e = window.open("", "cmslv_e", "");
	}
	if(typeof lvwindow_e == 'undefined'){
		lvwindow_e = window.open("typo3conf/ext/cdt_spectext/pi1/ats_e/index.htm", "cmslv_e", "");
	}
	if(lvwindow_e.closed == true){
		lvwindow_e = window.open("typo3conf/ext/cdt_spectext/pi1/ats_e/index.htm", "cmslv_e", "");
	}
	if (lvwindow_e.location.href == "about:blank"){
		lvwindow_e.location.href = "typo3conf/ext/cdt_spectext/pi1/ats_e/index.htm";
	}
	lvwindow_e.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_e == 'undefined') {
		lvwindow_e = window.open("", "cmslv_e", "");
	}
	if(typeof lvwindow_e == 'undefined'){
		lvwindow_e = window.open("typo3conf/ext/cdt_spectext/pi1/ats_e/index.htm", "cmslv_e", "");
	}
	if(lvwindow_e.closed == true){
		lvwindow_e = window.open("typo3conf/ext/cdt_spectext/pi1/ats_e/index.htm", "cmslv_e", "");
	}
	if (lvwindow_e.location.href == "about:blank"){
		lvwindow_e.location.href = "typo3conf/ext/cdt_spectext/pi1/ats_e/index.htm";
	}
	lvwindow_e.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_e == 'undefined') {
		lvwindow_e = window.open("", "cmslv_e", "");
	}
	if(typeof lvwindow_e == 'undefined'){
		lvwindow_e = window.open("typo3conf/ext/cdt_spectext/pi1/ats_e/index.htm", "cmslv_e", "");
	}
	if(lvwindow_e.closed == true){
		lvwindow_e = window.open("typo3conf/ext/cdt_spectext/pi1/ats_e/index.htm", "cmslv_e", "");
	}
	if (lvwindow_e.location.href == "about:blank"){
		lvwindow_e.location.href = "typo3conf/ext/cdt_spectext/pi1/ats_e/index.htm";
	}
	lvwindow_e.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_e == 'undefined') {
		lvwindow_e = window.open("", "cmslv_e", "");
	}
	if(typeof lvwindow_e == 'undefined'){
		lvwindow_e = window.open("typo3conf/ext/cdt_spectext/pi1/ats_e/index.htm", "cmslv_e", "");
	}
	if(lvwindow_e.closed == true){
		lvwindow_e = window.open("typo3conf/ext/cdt_spectext/pi1/ats_e/index.htm", "cmslv_e", "");
	}
	if (lvwindow_e.location.href == "about:blank"){
		lvwindow_e.location.href = "typo3conf/ext/cdt_spectext/pi1/ats_e/index.htm";
	}
	lvwindow_e.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_e == 'undefined') {
		lvwindow_e = window.open("", "cmslv_e", "");
	}
	if(typeof lvwindow_e == 'undefined'){
		lvwindow_e = window.open("typo3conf/ext/cdt_spectext/pi1/ats_e/index.htm", "cmslv_e", "");
	}
	if(lvwindow_e.closed == true){
		lvwindow_e = window.open("typo3conf/ext/cdt_spectext/pi1/ats_e/index.htm", "cmslv_e", "");
	}
	if (lvwindow_e.location.href == "about:blank"){
		lvwindow_e.location.href = "typo3conf/ext/cdt_spectext/pi1/ats_e/index.htm";
	}
	lvwindow_e.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_e.document.frames["strg"]!= 'undefined') {
		if (typeof lvwindow_e.insertID != 'undefined') {
			lvwindow_e.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_e.frames["strg"]!== 'undefined') {
		if ((typeof lvwindow_e.insertSysID !== 'undefined') &&
			(typeof lvwindow_e.frames["strg"].document !== 'undefined') &&
			(typeof lvwindow_e.frames["strg"].document.forms["form1"] !== 'undefined')) {
			window.clearInterval(aktiv);
			aktiv = 0;
			lvwindow_e.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_e.frames["strg"]!== 'undefined') {
		if ((typeof lvwindow_e.insertSysID !== 'undefined') &&
			(typeof lvwindow_e.frames["strg"].document !== 'undefined') &&
			(typeof lvwindow_e.frames["strg"].document.forms["form1"] !== 'undefined')) {
			window.clearInterval(aktiv);
			aktiv = 0;
			lvwindow_e.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_e.frames["strg"]!= 'undefined') {
		if (typeof lvwindow_e.insertArtID != 'undefined') {
			lvwindow_e.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_e.frames["unten"]!= 'undefined') {
		if (typeof lvwindow_e.frames["unten"].insertProdukt != 'undefined') {
			if ((savePos != -1) || (lvwindow_e.frames["unten"].insertPositionAt != -1)){
				if  (lvwindow_e.frames["unten"].insertPositionAt != -1){
					savePos = lvwindow_e.frames["unten"].insertPositionAt;
				}
				if (lvwindow_e.frames["unten"].insertPositionAt == -1){
					savePos++;
					lvwindow_e.frames["unten"].insertPositionAt = savePos;
				}
			}
			lvwindow_e.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_e.frames["unten"]!= 'undefined') {
		if (typeof lvwindow_e.frames["unten"].insertProdukt != 'undefined') {
			lvwindow_e.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!");
	}
}