function gv4_savePeriAdminForm(leave)
{
	if ($('form_periVorlage'))
	{
		showInfoDivContainer('', 'ajax');
		var url = 'ajax/srv/gv_v4.php?t=savePeriAdminForm';
		new Ajax.Request(url,
			{
				postBody: $('form_periVorlage').serialize(),
				onComplete: function (t)
				{
					var json = t.responseText.evalJSON();
					if (json.error)
					{
						showInfoDivContainer(getLang("all", "saveError"), 'fehler');
					}
					else
					{
						showInfoDivContainer(getLang("all", "edit_successfully"));
						if (leave == true)
						{
							location.href = 'index.php?section=admin&sub=vorlage_peri';
						}
						else
						{
							if ($('peri_ID') && (json.id != $('peri_ID').value))
							{
								location.href = 'index.php?section=admin&sub=vorlage_peri&action=edit&id='+encodeURIComponent(json.id);
							}
						}
					}
				}
			}
		);
	}
}

function gv4_savePeriAsVorlage()
{
	if ($('peri_form'))
	{
		if ($('peri_artID') && (parseInt($('peri_artID').value, 10) == 0))
		{
			showInfoDivContainer(getLang("all", "haveToChooseAKind"), 'fehler');
		}
		else
		{
			showInfoDivContainer('', 'ajax');
			var url = 'ajax/srv/gv_v4.php?t=savePeriAsVorlage';
			new Ajax.Request(url,
				{
					postBody: $('peri_form').serialize(),
					onComplete: function (t)
					{
						var json = t.responseText.evalJSON();
						if (json.error)
						{
							showInfoDivContainer(getLang("all", "saveError"), 'fehler');
						}
						else
						{
							showInfoDivContainer(getLang("all", "edit_successfully"));
						}
					}
				}
			);
		}
	}
}

function gv4_getVServerMoveSelect(firmenID)
{
	if ($('move_vserver_select_td') && $('move_vserver_select_tr') && $('garantie_vserver_firmenauswahl'))
	{
		$('move_vserver_select_tr').show();
		$('move_vserver_select_td').innerHTML = show_load();
		var url = 'ajax/srv/gv_v4.php?t=getVServerMoveSelect&firmenID='+encodeURIComponent($('garantie_vserver_firmenauswahl').value);
		new Ajax.Request(url,
			{
				method: 'get',
				onComplete: function (t)
				{
					$('move_vserver_select_td').innerHTML = t.responseText;
				}
			}
		);
	}
}

function gv4_checkServerSelect()
{
	if ($('move_vserver_submit_tr') && $('move_server_select'))
	{
		if (parseInt($('move_server_select').value, 10) > 0)
		{
			$('move_vserver_submit_tr').show();
		}
		else
		{
			$('move_vserver_submit_tr').hide();
		}
	}
}

function gv4_moveVServerFormSubmitCheck()
{
	if ($('move_vserver_form'))
	{
		showInfoDivContainer('', 'ajax');
		var url = 'ajax/srv/gv_v4.php?t=move_vserver';
		new Ajax.Request(url,
			{
				method: 'post',
				postBody: $('move_vserver_form').serialize(),
				onComplete: function (t)
				{
					var json = t.responseText.evalJSON();
					if (json.fehler == true)
					{
						showInfoDivContainer(json.msg, 'fehler');
					}
					else
					{
						showInfoDivContainer(json.msg);
						if ($('move_backstring'))
						{
							location.href = $('move_backstring').value;
						}
					}
				}
			}
		);
	}
}

function gv4_periSearch(typ, event)
{
	($('periSearchDiv')) ? $('periSearchDiv').remove() : true;
	var theElement = Event.element(event);
	var theDiv = document.createElement('div');
	var theInput = document.createElement('input');
	theInput.id = 'periSearchInput';
	theInput.onkeydown = function (e)
	{
		var keyNum = (event.keyCode) ? event.keyCode : e.which;
		if (keyNum == 13)
		{
			showInfoDivContainer('', 'ajax');
			var theValue = theInput.value;
			var maID = ($('peri_hidden_maID')) ? $('peri_hidden_maID').value : 0;
			var kundenID = ($('peri_hidden_kundenID')) ? $('peri_hidden_kundenID').value : 0;
			var geraetID = ($('peri_hidden_geraetID')) ? $('peri_hidden_geraetID').value : 0;
			var url = 'ajax/srv/gv_v4.php?t=periSearch'+
								'&value='+encodeURIComponent(theValue)+
								'&typ='+encodeURIComponent(typ)+
								'&maID='+encodeURIComponent(maID)+
								'&kundenID='+encodeURIComponent(kundenID)+
								'&geraetID='+encodeURIComponent(geraetID);
			new Ajax.Request(url,
				{
					method: 'get',
					onComplete: function (t)
					{
						if ($(typ+'_container'))
						{
							$(typ+'_container').innerHTML = t.responseText;
						}
						hideShowInfoDivContainer();
					}
				}
			);
			($('periSearchDiv')) ? $('periSearchDiv').remove() : true;
		}
	};
	theDiv.id = 'periSearchDiv';
	theDiv.appendChild(theInput);
	theDiv.style.left = (theElement.cumulativeOffset()[0] + theElement.getWidth()) + 'px';
	theDiv.style.top = (theElement.cumulativeOffset()[1] + theElement.getHeight()) + 'px';
	document.body.appendChild(theDiv);
	window.setTimeout(function(){($('periSearchInput'))?$('periSearchInput').focus():true},1);
	Event.observe(document, 'click', function(event){if ((Event.element(event).id != 'periSearchDiv') && (Event.element(event).id != 'periSearchInput') && (Event.element(event).id != 'peri_maID_img') && (Event.element(event).id != 'peri_pcID_img') && (Event.element(event).id != 'periZuweisenSelect_img')){($('periSearchDiv')) ? $('periSearchDiv').remove() : true;}});
}

function gv4_toggleKompContainerGeraet(rowID)
{
	($('editKompContainer_'+rowID)) ? $('editKompContainer_'+rowID).toggle() : true;
	($('showKompContainer_'+rowID)) ? $('showKompContainer_'+rowID).toggle() : true;
}

function gv4_changeArtPeriZusatzLoad()
{
	if (confirm(getLang("all", "changePeriKindSwitch")))
	{
		var theID = ($('peri_id')) ? parseInt($('peri_id').value, 10) : 0;
		var refreshPage = (theID) ? true : false;
		gv4_save_periForm(theID, false, refreshPage);
	}
}

function gv4_save_kompForm(theID, leave, geraeteAnsicht)
{
	if ($('komp_form'))
	{
		showInfoDivContainer('', 'ajax');
		var url = 'ajax/srv/gv_v4.php?t=save_komp';
		new Ajax.Request(url,
			{
				method: 'post',
				postBody: $('komp_form').serialize(),
				onComplete: function (t)
				{
					var res = t.responseText;
					var saveID = (parseInt(theID, 10) == 0) ? parseInt(res, 10) : parseInt(theID, 10);
					gv4_saveGarantie(5, saveID, 'komp_form');
					showInfoDivContainer(getLang("all", "edit_successfully"));
					if (leave == true)
					{
						if ($('hidden_backlink'))
						{
							location.href = $('hidden_backlink').value;
						}
					}
					else
					{
						if (geraeteAnsicht == true)
						{
							gv4_kompAdmin_removeDiv();
							gv4_refreshKompAdminDiv();
						}
						else
						{
							if (parseInt(theID, 10) == 0)
							{
								location.href = 'index.php?section=garantie&sub=komponenten_edit&ID='+parseInt(res, 10);
							}							
						}
					}
				}
			}
		);
	}
	else
	{
		showInfoDivContainer(getLang("all", "saveError"), 'fehler');
	}
}

function gv4_save_periFormZusatz()
{
	if ($('peri_form_zusatz'))
	{
		var url = 'ajax/srv/gv_v4.php?t=save_peri_zusatz';
		new Ajax.Request(url,
			{
				method: 'post',
				asynchronous: false,
				postBody: $('peri_form_zusatz').serialize()
			}
		);
	}
}

function gv4_delete_geraet(typ, id)
{
	if (confirm(getLang("all", "reallyDeleteDevice").replace('#1#', id)))
	{
		var komp_exists = false;
		var url = 'ajax/srv/gv_v4.php?t=check_komp_exists&typ='+encodeURIComponent(typ)+
                                                    '&id='+encodeURIComponent(id);
		new Ajax.Request(url, {
      asynchronous: false,
      onComplete: function (t) {
        var json = t.responseText.evalJSON();
        if (json.anzahl) komp_exists = true;
      }
    });
		var deleteKomp = false;
		if (komp_exists) {
			if (confirm(getLang("all", "reallyDeleteKompFromDevice"))) {
				deleteKomp = true;
			}
		}
		showInfoDivContainer('', 'ajax');
		url = 'ajax/srv/gv_v4.php?t=delete_geraet'+
      		'&typ='+encodeURIComponent(typ)+
					'&id='+encodeURIComponent(id)+
					'&deleteKomp='+encodeURIComponent(deleteKomp);
		new Ajax.Request(url, {
      onComplete: function (t) {
        var json = t.responseText.evalJSON();
        if (json.content) {
          showInfoDivContainer(getLang("all", "delete_successfully"));
          if ($('gv4_backlink')) {
            location.href = $('gv4_backlink').href;
          }
        } else {
          hideShowInfoDivContainer();
        }
      }
    });
	}
}

function gv4_delete_periZusatzFeld(theID, geraete_artID)
{
	if (confirm(getLang("admin", "generalDeleteQuestion")))
	{
		showInfoDivContainer('', 'ajax');
		var url = 'ajax/srv/gv_v4.php?t=delete_peri_zusatz&id='+encodeURIComponent(theID);
		new Ajax.Request(url,
			{
				method: 'get',
				onComplete: function (t)
				{
					if (t.responseText == 'ok')
					{
						showInfoDivContainer(getLang("all", "delete_successfully"));
						gv4_periGeraeteShowAuflistung(geraete_artID);
						gv4_showPeriTypSelect(geraete_artID);
					}
					else
					{
						hideShowInfoDivContainer();
					}
				}
			}
		);
	}
}

function gv4_check_newPeriZusatzFeld(formID, geraete_artID)
{
	var save = true;
	($('bezeichnung') && trimString($('bezeichnung').value).length == 0) ? save = false : true;
	($('typ') && $('typ').value == '') ? save = false : true;
	if (save)
	{
		gv4_periFeld_save(formID, geraete_artID);
	}
	else
	{
		showInfoDivContainer(getLang("all", "checkInputs"), 'fehler');
	}
}

function gv4_removeMessageBox()
{
	if ($('messageBox'))
	{
		$('messageBox').remove();
	}
}

function gv4_createCopy(linkID, linkTypID, aTag, theType, zuwTypID, zuwID)
{
	if (typeof theType == 'undefined') theType = '';
	if (typeof zuwTypID == 'undefined') zuwTypID = '';
	if (typeof zuwID == 'undefined') zuwID = '';
	Element.extend(aTag);
	($('messageBox')) ? $('messageBox').remove() : true;
	var _div = document.createElement('div');
	_div.className = 'messageBox';
	_div.id = 'messageBox';
	_div.style.left = aTag.cumulativeOffset()[0] + 'px';
	_div.style.top = aTag.cumulativeOffset()[1] + aTag.getHeight() + 'px';
	_div.innerHTML = show_load(true);
	document.body.appendChild(_div);
	var url = 'ajax/srv/gv_v4.php?t=showEnterNumberOfCopies'+
						'&linkTypID='+encodeURIComponent(linkTypID)+
						'&linkID='+encodeURIComponent(linkID)+
						'&type='+encodeURIComponent(theType)+
						'&zuwTypID='+encodeURIComponent(zuwTypID)+
						'&zuwID='+encodeURIComponent(zuwID);
	new Ajax.Request(url,
		{
			method: 'get',
			onComplete: function (t)
			{
				_div.innerHTML = t.responseText;
				($('kopieren_anzahl')) ? $('kopieren_anzahl').focus() : true;
			}
		}
	);
}

function gv4_kompCopy(linkID, linkTypID, zuwTypID, zuwID)
{
	gv4_executeCopy(linkID, linkTypID);
	if ($('kompCon_selectArt'))
	{
		gv4_showKompAdministration(zuwTypID, zuwID, 'kompCon_selectArt');
	}
}

function gv4_executeCopy(linkID, linkTypID)
{
	var kopieren_anzahl = ($('kopieren_anzahl')) ? parseInt($('kopieren_anzahl').value, 10) : 0;
	var kopieren_sn = ($('kopieren_sn')) ? $('kopieren_sn').value : '';
	if (kopieren_anzahl > 0 && kopieren_anzahl < 100)
	{
		($('messageBox')) ? $('messageBox').remove() : true;
		showInfoDivContainer('', 'ajax');
		var url = 'ajax/srv/gv_v4.php?linkID='+encodeURIComponent(linkID)+
							'&anzahl='+encodeURIComponent(kopieren_anzahl)+
							'&sn='+encodeURIComponent(kopieren_sn);
		var execute = false;
		switch (parseInt(linkTypID, 10))
		{
			case 1:
				url += '&t=pc_copy';
				execute = true;
				break;
			case 2:
				url += '&t=peri_copy';
				execute = true;
				break;
			case 3:
				url += '&t=komp_copy';
				execute = true;
				break;
		}
		if (execute)
		{
			new Ajax.Request(url,
				{
					method: 'get',
					asynchronous: false,
					onComplete: function (t)
					{
						if (t.responseText == 'ok')
						{
							showInfoDivContainer(getLang("all", "edit_successfully"));
							gv4_refreshKompAdminDiv();
							gv4_refreshPeriAdminDiv();
						}
						else
						{
							showInfoDivContainer(getLang("admin", "import_err_1"), 'fehler');
						}
					}
				}
			);
		}
	}
	else
	{
		($('messageBox')) ? $('messageBox').focus() : true;
		showInfoDivContainer(getLang("all", "copyInfoText"), 'fehler');
	}
}

function gv4_save_periForm(theID, leave, refreshPage)
{
	if ($('peri_form'))
	{
		var peri_save = true;
		if ($('peri_artID') && (parseInt($('peri_artID').value, 10) == 0))
		{
			showInfoDivContainer(getLang("all", "haveToChooseAKind"), 'fehler');
			peri_save = false;
		}
		if ($('peri_sn') && $('peri_id'))
		{
			var _sn = trimString($('peri_sn').value);
			if (_sn.length > 0)
			{
				var url = 'ajax/srv/gv_v4.php?t=checkSNExists'+
									'&from=peri'+
									'&id='+encodeURIComponent($('peri_id').value)+
									'&sn='+encodeURIComponent(_sn);
				new Ajax.Request(url,
					{
						method: 'get',
						asynchronous: false,
						onComplete: function (t)
						{
							var json = t.responseText.evalJSON();
							if (json.exists == true)
							{
                var frage = getLang("all", "serialAlreadyExists");
								frage = frage.replace("#1#", json.info);
                if (!confirm(frage))
								{
									peri_save = false;
								}
							}
						}
					}
				);
			}
		}
		if (peri_save)
		{
			showInfoDivContainer('', 'ajax');
			var url = 'ajax/srv/gv_v4.php?t=save_peri';
			new Ajax.Request(url,
				{
					method: 'post',
					postBody: $('peri_form').serialize(),
					onComplete: function (t)
					{
						var res = t.responseText;
						var saveID = (parseInt(theID, 10) == 0) ? parseInt(res, 10) : parseInt(theID, 10);
						gv4_save_periFormZusatz();
						gv4_saveGarantie(4, saveID, 'form_periChangeForm_garantie');
						showInfoDivContainer(getLang("all", "edit_successfully"));
						var refreshDienste = false;
						if (leave == true)
						{
							if ($('hidden_backlink'))
							{
								location.href = $('hidden_backlink').value;
							}
							else
							{
								refreshDienste = true;
							}
						}
						else
						{
							if (parseInt(theID, 10) == 0)
							{
								location.href = 'index.php?section=geraete&sub=edit&id='+parseInt(res, 10);
							}
							else
							{
								refreshDienste = true;
							}
						}
						if (refreshPage)
						{
							location.reload();
						}
						else
						{
							if (refreshDienste)
							{
								gv4_showServiceSymbole(theID, 2, true);
							}						
						}
					}
				}
			);
		}
	}
	else
	{
		showInfoDivContainer(getLang("all", "saveError"), 'fehler');
	}
}

function gv4_kompForm_geraet_neu(zuwTypID, zuwID, selectElement, formID)
{
	if ($(formID))
	{
		showInfoDivContainer('', 'ajax');
		var url = 'ajax/srv/gv_v4.php?t=save_komp';
		new Ajax.Request(url, 
			{
				method: 'post',
				postBody: $(formID).serialize(),
				onComplete: function (t)
				{
					var res = t.responseText;
					gv4_showKompAdministration(zuwTypID, zuwID, selectElement);
				}
			}
		);
	}
}

function gv4_kompForm_geraet_ausbauen(kompID)
{
	if (confirm(getLang("all", "removeKompQuestion").replace(/#1#/, kompID)))
	{
		showInfoDivContainer('', 'ajax');
		var url = 'ajax/srv/gv_v4.php?t=komp_ausbauen&kompID='+encodeURIComponent(kompID);
		new Ajax.Request(url, 
			{
				method: 'get',
				onComplete: function (t)
				{
					gv4_refreshKompAdminDiv();
				}
			}
		);
	}
}

function gv4_periForm_geraet_ausbauen(periID)
{
	if (confirm(getLang("all", "removePeriQuestion").replace(/#1#/, periID)))
	{
		showInfoDivContainer('', 'ajax');
		var url = 'ajax/srv/gv_v4.php?t=peri_ausbauen&periID='+encodeURIComponent(periID);
		new Ajax.Request(url, 
			{
				method: 'get',
				onComplete: function (t)
				{
					gv4_refreshPeriAdminDiv();
				}
			}
		);
	}
}

function gv4_kompForm_geraet_einbauen(zuwTypID, zuwID, theID)
{
	if (confirm(getLang("all", "reallyAssignThisComp").replace(/#1#/, theID)))
	{
		showInfoDivContainer('', 'ajax');
		var url = 'ajax/srv/gv_v4.php?t=komp_einbauen'+
							'&zuwID='+encodeURIComponent(zuwID)+
							'&zuwTypID='+encodeURIComponent(zuwTypID)+
							'&kompID='+encodeURIComponent(theID);
		new Ajax.Request(url, 
			{
				method: 'get',
				onComplete: function (t)
				{
					gv4_refreshKompAdminDiv();
				}
			}
		);		
	}
}

function gv4_periForm_geraet_einbauen(zuwTypID, zuwID, theID)
{
	if (confirm(getLang("all", "reallyAssignThisPeri").replace(/#1#/, theID)))
	{
		showInfoDivContainer('', 'ajax');
		var url = 'ajax/srv/gv_v4.php?t=peri_einbauen'+
							'&zuwID='+encodeURIComponent(zuwID)+
							'&zuwTypID='+encodeURIComponent(zuwTypID)+
							'&periID='+encodeURIComponent(theID);
		new Ajax.Request(url, 
			{
				method: 'get',
				onComplete: function (t)
				{
					gv4_refreshPeriAdminDiv();
				}
			}
		);		
	}
}

function gv4_kompForm_geraet_loeschen(kompID)
{
	ajax_delete_item('komp', kompID, '', false);
	gv4_refreshKompAdminDiv();
}

function gv4_periForm_geraet_loeschen(periID)
{
	ajax_delete_item('peri', periID, '', false);
	gv4_refreshPeriAdminDiv();
}

function gv4_saveGarantie(linkTypID, linkID, formID)
{
	if ($(formID))
	{
		var url = 'ajax/srv/gv_v4.php?t=saveGarantie'+
							'&linkTypID='+encodeURIComponent(linkTypID)+
							'&linkID='+encodeURIComponent(linkID);
		new Ajax.Request(url,
			{
				method: 'post',
				asynchronous: false,
				postBody: $(formID).serialize(),
				onComplete: function (t) {}
			}
		);
	}
}

function gv4_save_pcForm(theID, leave, vorlage)
{
	if ($('form_pcChangeForm_oben') && $('form_pcChangeForm_unten'))
	{
		var pcSave = true;
		if ($('pc_modell') && $('pc_hostID'))
		{
			if ((trimString($('pc_modell').value).length == 0) && ($('pc_hostID').value == 0))
			{
				pcSave = false;
				showInfoDivContainer(getLang("pc", "chkFormValues_noType"), 'fehler');
			}
		}
		if ($('pc_sn') && $('pc_id') && (pcSave == true))
		{
			var _sn = trimString($('pc_sn').value);
			if (_sn.length > 0)
			{
				var url = 'ajax/srv/gv_v4.php?t=checkSNExists'+
									'&from=pc'+
									'&id='+encodeURIComponent($('pc_id').value)+
									'&sn='+encodeURIComponent(_sn);
				new Ajax.Request(url,
					{
						method: 'get',
						asynchronous: false,
						onComplete: function (t)
						{
							var json = t.responseText.evalJSON();
							if (json.exists == true)
							{
                var frage = getLang("all", "serialAlreadyExists");
								frage = frage.replace("#1#", json.info);
								if (!confirm(frage))
								{
									pcSave = false;
								}
							}
						}
					}
				);
			}
		}
		if (pcSave)
		{
			var postStr = $('form_pcChangeForm_oben').serialize();
			(postStr.length) ? postStr += '&' : true;
			postStr += $('form_pcChangeForm_unten').serialize();
			showInfoDivContainer('', 'ajax');
			var url = 'ajax/srv/gv_v4.php?t='+((vorlage == true)?'save_pcVorlage':'save_pc');
			new Ajax.Request(url,
				{
					method: 'post',
					postBody: postStr,
					onComplete: function (t)
					{
						var res = t.responseText;
						var saveID = (parseInt(theID, 10) == 0) ? parseInt(res, 10) : parseInt(theID, 10);
						(vorlage != true) ? gv4_saveGarantie(1, saveID, 'form_pcChangeForm_garantie') : gv4_saveGarantie(-1, saveID, 'form_pcChangeForm_garantie');
						showInfoDivContainer(getLang("all", "edit_successfully"));
						var refreshDienste = false;
						if (leave == true)
						{
							if ($('hidden_backlink'))
							{
								location.href = $('hidden_backlink').value;
							}
							else
							{
								refreshDienste = true;
							}
						}
						else
						{
							if ((parseInt(theID, 10) == 0) && (vorlage != true))
							{
								location.href = 'index.php?section=garantie&sub=edit&id='+parseInt(res, 10);
							}
							else
							{
								refreshDienste = true;
							}
						}
						if (refreshDienste)
						{
							gv4_showServiceSymbole(theID, 1, true);
						}
					}
				}
			);
		}
	}
	else
	{
		showInfoDivContainer(getLang("all", "saveError"), 'fehler');
	}
}

function gv4_checkSelectKompTyp()
{
	if ($('kapazitaet_select') && $('komp_typID') && $('komp_MB'))
	{
		if (parseInt($('komp_typID').options[$('komp_typID').selectedIndex].value, 10) == 3)
		{
			if (trimString($('komp_MB').value).length == 0)
			{
				for (var i = 0; i < $('kapazitaet_select').length; i++)
				{
					($('kapazitaet_select').options[i].value == 'gb') ? $('kapazitaet_select').selectedIndex = i : true;
				}
			}
		}
	}
	if ($('komp_typID'))
	{
		var url = 'ajax/srv/gv_v4.php?t=checkKompTypFields&kompTypID='+encodeURIComponent($('komp_typID').value);
		new Ajax.Request(url,
			{
				method: 'get',
				onComplete: function (t)
				{
					var jsonObj = t.responseText.evalJSON();
					($('kompTR_hersteller')) ? (jsonObj.hersteller) ? $('kompTR_hersteller').show() : $('kompTR_hersteller').hide() : true;
					($('kompTR_typ')) ? (jsonObj.typ) ? $('kompTR_typ').show() : $('kompTR_typ').hide() : true;
					($('kompTR_hddtyp')) ? (jsonObj.hddtyp) ? $('kompTR_hddtyp').show() : $('kompTR_hddtyp').hide() : true;
					($('kompTR_scsiID')) ? (jsonObj.scsiID) ? $('kompTR_scsiID').show() : $('kompTR_scsiID').hide() : true;
					($('kompTR_invNr')) ? (jsonObj.invNr) ? $('kompTR_invNr').show() : $('kompTR_invNr').hide() : true;
					($('kompTR_kapazitaet')) ? (jsonObj.kapazitaet) ? $('kompTR_kapazitaet').show() : $('kompTR_kapazitaet').hide() : true;
					($('kompTR_sn')) ? (jsonObj.sn) ? $('kompTR_sn').show() : $('kompTR_sn').hide() : true;
					($('kompTR_mac')) ? (jsonObj.mac) ? $('kompTR_mac').show() : $('kompTR_mac').hide() : true;
					($('kompTR_onboard')) ? (jsonObj.onboard) ? $('kompTR_onboard').show() : $('kompTR_onboard').hide() : true;
					($('kompTR_datum')) ? (jsonObj.datum) ? $('kompTR_datum').show() : $('kompTR_datum').hide() : true;
					($('kompTR_rechnNr')) ? (jsonObj.rechnNr) ? $('kompTR_rechnNr').show() : $('kompTR_rechnNr').hide() : true;
				}
			}
		);
	}
}

function gv4_kompEinbauen(_pcID)
{
	var kompID = ($('kompID')) ? parseInt($('kompID').value, 10) : 0;
	var pcID = parseInt(_pcID, 10);
	if ((kompID > 0) && (pcID > 0))
	{
		if (confirm(getLang("all", "reallyInsertKompToPC").replace("#1#", pcID)))
		{
			showInfoDivContainer('', 'ajax');
			var url = 'ajax/srv/gv_v4.php?t=komp_einbauen'+
								'&zuwID='+encodeURIComponent(pcID)+
								'&zuwTypID=1'+
								'&kompID='+encodeURIComponent(kompID);
			new Ajax.Request(url,
				{
					method: 'get',
					onComplete: function (t)
					{
						var res = t.responseText;
						if (res == 'ok')
						{
							showInfoDivContainer(getLang("all", "edit_successfully"));
							location.reload();
						}
						else
						{
							showInfoDivContainer(getLang("all", "saveError"), 'fehler');
						}
					}
				}
			);			
		}
	}
}

function gv4_showServiceSymbole(theID, theTyp, editMode)
{
	if ($('serviceSymboleDiv'))
	{
		var url = 'ajax/srv/gv_v4.php?t=showServiceSymbole'+
							'&id='+encodeURIComponent(theID)+
							'&typ='+encodeURIComponent(theTyp)+
							'&editMode='+encodeURIComponent(editMode);
		new Ajax.Request(url,
			{
				method: 'get',
				onComplete: function (t)
				{
					$('serviceSymboleDiv').innerHTML = t.responseText;
					gv4_showServiceSymboleOnly(theID, theTyp);
				}
			}
		);
	}
}

function gv4_showServiceSymboleOnly(theID, theTyp)
{
	if ($('serviceSymboleShowForm'))
	{
		var url = 'ajax/srv/gv_v4.php?t=showServiceSymboleOnly'+
							'&id='+encodeURIComponent(theID)+
							'&typ='+encodeURIComponent(theTyp);
		new Ajax.Request(url,
			{
				method: 'get',
				onComplete: function (t)
				{
					$('serviceSymboleShowForm').innerHTML = t.responseText;
				}
			}
		);
	}
}

function gv4_showIPContainer(zuwID, zuwTypID)
{
	if ($('ipContainer'))
	{
		var url = 'ajax/srv/gv_v4.php?t=showIPContainer'+
							'&zuwID='+encodeURIComponent(zuwID)+
							'&zuwTypID='+encodeURIComponent(zuwTypID);
		new Ajax.Request(url,
			{
				method: 'get',
				onComplete: function (t)
				{
					$('ipContainer').innerHTML = t.responseText;
				}
			}
		);
	}
}

function gv4_showKompContainer(zuwID, zuwTypID)
{
	alert($('kompContainer'));
	if ($('kompContainer'))
	{
		var url = 'ajax/srv/gv_v4.php?t=showKompContainer'+
							'&zuwID='+encodeURIComponent(zuwID)+
							'&zuwTypID='+encodeURIComponent(zuwTypID);
		new Ajax.Request(url,
			{
				method: 'get',
				onComplete: function (t)
				{
					$('kompContainer').innerHTML = t.responseText;
				}
			}
		);
	}
}

function gv4_showPeriContainer(zuwID, zuwTypID)
{
	if ($('periContainer'))
	{
		var url = 'ajax/srv/gv_v4.php?t=showPeriContainer'+
							'&zuwID='+encodeURIComponent(zuwID)+
							'&zuwTypID='+encodeURIComponent(zuwTypID);
		new Ajax.Request(url,
			{
				method: 'get',
				onComplete: function (t)
				{
					$('periContainer').innerHTML = t.responseText;
				}
			}
		);
	}
}

function gv4_ipToggleRow(theID)
{
	($('ipShowTable_row_'+theID)) ? $('ipShowTable_row_'+theID).toggle() : true;
	($('ipFormTable_row_'+theID)) ? $('ipFormTable_row_'+theID).toggle() : true;
}

function gv4_ipSaveRow(theID, zuwID, zuwTypID)
{
	showInfoDivContainer('', 'ajax');
	var url = 'ajax/srv/gv_v4.php?t=saveIP';
	var postStr = '';
	if (theID)
	{
		($('ipEditForm_'+theID)) ? postStr = $('ipEditForm_'+theID).serialize() : true;
	}
	else
	{
		($('ipCreateForm')) ? postStr = $('ipCreateForm').serialize() : true;
	}
	new Ajax.Request(url,
		{
			method: 'post',
			postBody: postStr,
			onComplete: function (t)
			{
				var res = t.responseText;
        var json = res.evalJSON();
        if (json.ok == false) {
          alert(json.meldung);
        }
				hideShowInfoDivContainer();
				gv4_showIPContainer(zuwID, zuwTypID);
				gv4_showServiceSymbole(zuwID, zuwTypID, true);
			}
		}
	);
}

function gv4_ipDelete(theID, zuwID, zuwTypID)
{
	if (confirm(getLang("all", "ipReallyDelete")))
	{
		var url = 'ajax/srv/gv_v4.php?t=deleteIP&id='+encodeURIComponent(theID);
		new Ajax.Request(url,
			{
				method: 'get',
				onComplete: function (t)
				{
					var res = t.responseText;
					gv4_showIPContainer(zuwID, zuwTypID);
					gv4_showServiceSymbole(zuwID, zuwTypID, true);
				}
			}
		);
	}
}

function gv4_showKompAdministration(zuwTypID, zuwID, selectElement)
{
	var typID = 0;
	if ($(selectElement))
	{
		($(selectElement).options[$(selectElement).selectedIndex].value) ? typID = parseInt($(selectElement).options[$(selectElement).selectedIndex].value, 10) : true;
	}
	if ($('kompCon_resultContainer'))
	{
		if (typID > 0)
		{
			var url = 'ajax/srv/gv_v4.php?t=showKompAdministration'+
								'&zuwTypID='+encodeURIComponent(zuwTypID)+
								'&zuwID='+encodeURIComponent(zuwID)+
								'&typID='+encodeURIComponent(typID);
			new Ajax.Request(url,
				{
					method: 'get',
					onComplete: function (t)
					{
						var res = t.responseText;
						$('kompCon_resultContainer').innerHTML = res;
						location.href = '#komp_ank';
					}
				}
			);
		}
		else
		{
			$('kompCon_resultContainer').innerHTML = '';
		}
	}
	if ($('kompCon_SelectContainer'))
	{
		var url = 'ajax/srv/gv_v4.php?t=showKompSelect'+
							'&zuwTypID='+encodeURIComponent(zuwTypID)+
							'&zuwID='+encodeURIComponent(zuwID)+
							'&typID='+encodeURIComponent(typID);
		new Ajax.Request(url,
			{
				method: 'get',
				onComplete: function (t)
				{
					var res = t.responseText;
					$('kompCon_SelectContainer').innerHTML = res;
				}
			}
		);
	}
	hideShowInfoDivContainer();
}

function gv4_changeColor(elementID)
{
	if ($(elementID))
	{
		$(elementID).className = ($(elementID).className == 'pwHidden') ? 'pwVisible' : 'pwHidden';
	}
}

function gv4_changeColorInput(elementID, imageElementID)
{
	if ($(elementID))
	{
		$(elementID).className = ($(elementID).className == 'pwHiddenInput') ? 'pwVisibleInput' : 'pwHiddenInput';
	}
	if ($(imageElementID))
	{
		$(imageElementID).src = ($(elementID).className == 'pwHiddenInput') ? 'media/hp/versteckt.gif' : 'media/hp/tickets.gif';
	}
}

function gv4_periGeraeteArtChange(geraete_artID)
{
	if ($('resultDivPeriArt'))
	{
		var url = 'ajax/srv/gv_v4.php?t=getPeriGeraeteArtChangeform&geraete_artID='+encodeURIComponent(geraete_artID);
		new Ajax.Request(url,
			{
				method: 'get',
				onComplete: function (t)
				{
					var res = t.responseText;
					$('resultDivPeriArt').innerHTML = res;
					gv4_periGeraeteShowAuflistung(geraete_artID);
				}
			}
		);
	}
}

function gv4_periGeraeteShowAuflistung(geraete_artID)
{
	if ($('resultDivPeriAuflistung'))
	{
		var url = 'ajax/srv/gv_v4.php?t=getPeriFeldAuflistung&geraete_artID='+encodeURIComponent(geraete_artID);
		new Ajax.Request(url,
			{
				method: 'get',
				onComplete: function (t)
				{
					var res = t.responseText;
					$('resultDivPeriAuflistung').innerHTML = res;
				}
			}
		);
	}
}

function gv4_showPeriTypSelect(selectedID)
{
	if ($('periTypSelectTD'))
	{
		var url = 'ajax/srv/gv_v4.php?t=showPeriTypSelect&selectedID='+encodeURIComponent(selectedID);
		new Ajax.Request(url,
			{
				method: 'get',
				onComplete: function (t)
				{
					$('periTypSelectTD').innerHTML = t.responseText;
				}
			}
		);
	}
}

function gv4_togglePeriAuflistung(theID)
{
	($('auflistung_show_'+theID)) ? $('auflistung_show_'+theID).toggle() : true;
	($('auflistung_edit_'+theID)) ? $('auflistung_edit_'+theID).toggle() : true;
}

function gv4_periFeld_save(formID, geraete_artID)
{
	if ($(formID))
	{
		showInfoDivContainer('', 'ajax');
		var url = 'ajax/srv/gv_v4.php?t=savePeriFeldChangeform';
		new Ajax.Request(url,
			{
				method: 'post',
				postBody: $(formID).serialize(),
				onComplete: function (t)
				{
					gv4_periGeraeteShowAuflistung(geraete_artID);
					gv4_showPeriTypSelect(geraete_artID)
					hideShowInfoDivContainer();
				}
			}
		);
	}
}

function gv4_periZuweisungAuflistung(geraetID)
{
	if ($('periZuweisungAuflistungDiv')) {
		var url = 'ajax/srv/gv_v4.php?t=periZuweisungAuflistung'+
							'&geraetID='+encodeURIComponent(geraetID);
		new Ajax.Request(url, {
      onComplete: function (t) {
        $('periZuweisungAuflistungDiv').innerHTML = t.responseText;
      }
    });
	}
}

function gv4_pcServerZuweisungAuflistung(geraetID)
{
	if ($('pcServerZuweisungAuflistungDiv')) {
		var url = 'ajax/srv/gv_v4.php?t=pcServerZuweisungAuflistung'+
							'&geraetID='+encodeURIComponent(geraetID);
		new Ajax.Request(url, {
      onComplete: function (t) {
        $('pcServerZuweisungAuflistungDiv').innerHTML = t.responseText;
      }
    });
	}
}

function gv4_refreshZuweisungSelection(geraetID, typ)
{
  var selectionContainer = '';
  switch (typ)
  {
    case 'pc':
      selectionContainer = 'pcServerZuweisenSelect_container';
      break;
    case 'peri':
      selectionContainer = 'periZuweisenSelect_container';
      break;
  }
	if ($(selectionContainer) && selectionContainer != '') {
		var url = 'ajax/srv/gv_v4.php?t=refreshZuweisungSelection'+
							'&geraetID='+encodeURIComponent(geraetID)+
							'&typ='+encodeURIComponent(typ);
		new Ajax.Request(url, {
      onComplete: function (t) {
        var json = t.responseText.evalJSON();
        $(selectionContainer).innerHTML = json.content;
      }
    });
	}
}

function gv4_periZuweisungHinzufuegen(geraetID, zuwID)
{
  if ($('periZuweisenSelect')) $('periZuweisenSelect').disabled = true;
	showInfoDivContainer('', 'ajax');
	var url = 'ajax/srv/gv_v4.php?t=periZuweisungHinzufuegen'+
						'&geraetID='+encodeURIComponent(geraetID)+
						'&zuwID='+encodeURIComponent(zuwID);
	new Ajax.Request(url, {
    onComplete: function (t) {
      gv4_refreshZuweisungSelection(geraetID, 'peri');
      gv4_periZuweisungAuflistung(geraetID);
      hideShowInfoDivContainer();
    }
  });
}

function gv4_pcServerZuweisungHinzufuegen(geraetID, zuwID)
{
  if ($('pcServerZuweisenSelect')) $('pcServerZuweisenSelect').disabled = true;
	showInfoDivContainer('', 'ajax');
	var url = 'ajax/srv/gv_v4.php?t=pcServerZuweisungHinzufuegen'+
						'&geraetID='+encodeURIComponent(geraetID)+
						'&zuwID='+encodeURIComponent(zuwID);
	new Ajax.Request(url, {
    onComplete: function (t) {
      gv4_refreshZuweisungSelection(geraetID, 'pc');
      gv4_pcServerZuweisungAuflistung(geraetID);
      hideShowInfoDivContainer();
    }
  });
}

function gv4_periZuweisungEntfernen(geraetID, zuwID)
{
	if (confirm(getLang("admin", "generalDeleteQuestion"))) {
		showInfoDivContainer('', 'ajax');
		var url = 'ajax/srv/gv_v4.php?t=periZuweisungEntfernen'+
							'&geraetID='+encodeURIComponent(geraetID)+
							'&zuwID='+encodeURIComponent(zuwID);
		new Ajax.Request(url, {
      onComplete: function (t) {
        gv4_refreshZuweisungSelection(geraetID, 'peri');
        gv4_periZuweisungAuflistung(geraetID);
        hideShowInfoDivContainer();
      }
    });
	}
}

function gv4_pcServerZuweisungEntfernen(geraetID, zuwID)
{
	if (confirm(getLang("admin", "generalDeleteQuestion"))) {
		showInfoDivContainer('', 'ajax');
		var url = 'ajax/srv/gv_v4.php?t=pcServerZuweisungEntfernen'+
							'&geraetID='+encodeURIComponent(geraetID)+
							'&zuwID='+encodeURIComponent(zuwID);
		new Ajax.Request(url, {
      onComplete: function (t) {
        gv4_refreshZuweisungSelection(geraetID, 'pc');
        gv4_pcServerZuweisungAuflistung(geraetID);
        hideShowInfoDivContainer();
      }
    });
	}
}

function gv4_refreshKompAdminDiv()
{
	if ($('kompAdminDiv') && $('kompAdminDiv_linkTypID') && $('kompAdminDiv_linkID'))
	{
		var openDiv = ($('kompAdmin_nz_div') && ($('kompAdmin_nz_div').style.display == 'none')) ? false : true;
		var url = 'ajax/srv/gv_v4.php?t=kompAdminRefreshList'+
							'&linkTypID='+encodeURIComponent($('kompAdminDiv_linkTypID').value)+
							'&linkID='+encodeURIComponent($('kompAdminDiv_linkID').value);
		new Ajax.Request(url,
			{
				method: 'get',
				onComplete: function (t)
				{
					$('kompAdminDiv').innerHTML = t.responseText;
					hideShowInfoDivContainer();
					if (openDiv) toggleDivById('kompAdmin_nz_div', 'kompAdmin_nz_img', true);
				}
			}
		);
	}
}

function gv4_refreshPeriAdminDiv()
{
	if ($('periAdminDiv') && $('periAdminDiv_linkTypID') && $('periAdminDiv_linkID'))
	{
		var openDiv = ($('periAdmin_nz_div') && ($('periAdmin_nz_div').style.display == 'none')) ? false : true;
		var url = 'ajax/srv/gv_v4.php?t=periAdminRefreshList'+
							'&linkTypID='+encodeURIComponent($('periAdminDiv_linkTypID').value)+
							'&linkID='+encodeURIComponent($('periAdminDiv_linkID').value);
		new Ajax.Request(url,
			{
				method: 'get',
				onComplete: function (t)
				{
					$('periAdminDiv').innerHTML = t.responseText;
					hideShowInfoDivContainer();
					if (openDiv) toggleDivById('periAdmin_nz_div', 'periAdmin_nz_img', true);
				}
			}
		);
	}
}

function gv4_kompAdmin_removeDiv()
{
	if ($('kompAdminChangeformDiv'))
	{
		$('kompAdminChangeformDiv').remove();
	}
}

function gv4_kompAdmin_editKomp(kompID, linkTypID, linkID)
{
	showInfoDivContainer('', 'ajax');
	var url = 'ajax/srv/gv_v4.php?t=kompAdminChangeform'+
						'&kompID='+encodeURIComponent(kompID)+
						'&linkTypID='+encodeURIComponent(linkTypID)+
						'&linkID='+encodeURIComponent(linkID);
	new Ajax.Request(url,
		{
			method: 'get',
			onComplete: function (t)
			{
				($('kompAdminChangeformDiv')) ? $('kompAdminChangeformDiv').remove() : true;
				hideShowInfoDivContainer();
				var theDiv = document.createElement('div');
				theDiv.id = 'kompAdminChangeformDiv';
				document.body.appendChild(theDiv);
				theDiv.innerHTML = t.responseText;
				var theCloseHref = document.createElement('a');
				theCloseHref.id = 'kompAdminChangeformCloseHref';
				theCloseHref.href = '#';
				theCloseHref.onclick = function ()
				{
					Element.extend(theDiv);
					theDiv.remove();
					return false;
				}
				theDiv.appendChild(theCloseHref);
				var theCloseImg = document.createElement('img');
				theCloseImg.src = 'media/hp/schliessen.gif';
				theCloseHref.appendChild(theCloseImg);
				gv4_checkSelectKompTyp();
			}
		}
	);
}

function gv4_generateTeamviewerStart(theID)
{
  location.href = 'module/dynamic_teamviewer.php?ID='+encodeURIComponent(theID);
  //window.open('module/dynamic_teamviewer.php?ID='+encodeURIComponent(theID), '_blank', 'width=500,height=300,resizable=yes,scrollbars=yes,top=50,left=50');
}

function gv4_delPC(id)
{
  if (confirm(getLang('pc', 'pcDelQ'))) {
    new Ajax.Request('ajax/srv/delete_ajax.php?t=pc&id=' + id + '&s=do', {
      onSuccess: function(t) {
        window.location.href = "index.php?section=garantie&sub=nliste";
      }
    });
  }
}

function gv4_delPeri(id)
{
  if (confirm(getLang('pc', 'delPeriQ'))) {
    new Ajax.Request('ajax/srv/delete_ajax.php?t=peri&id=' + id + '&s=do', {
      onSuccess: function(t) {
        window.location.href = "index.php?section=geraete&sub=list&init=1";
      }
    });
  }
}
