/* BrowserChecks */
var w3c = (typeof(document.getElementById) != 'undefined') ? 1 : 0;
var ie5plus = ((typeof(document.getElementById) != 'undefined') && (document.all)) ? 1 : 0;
var ns6 = ((navigator.userAgent.indexOf('Netscape6') != -1) && (typeof(document.getElementById) != 'undefined')) ? 1 : 0;
var ns7 = ((navigator.userAgent.indexOf('Netscape7') != -1) && (typeof(document.getElementById) != 'undefined')) ? 1 : 0;
var moz = ((navigator.userAgent.indexOf('Gecko') != -1) && (typeof(document.getElementById) != 'undefined')) ? 1 : 0;
var ie4plus = (document.all) ? 1 : 0;
var ns4 = (document.layers) ? 1 : 0;


function CheckEingabe(IDStrings, Form)
{
	ElementsValid = true;
	
	for (i=0; i<IDStrings.length; i++)
	{
		if (Form.elements[IDStrings[i]])	
		{
			Value = Form.elements[IDStrings[i]].value.replace(',', '.');

			if (isNaN(Value) || Value == "" || Value < 0)
			{
				Form.elements[IDStrings[i]].focus();
				ElementsValid = false;
				break;
			}
			Form.elements[IDStrings[i]].value = Form.elements[IDStrings[i]].value.replace('.', ',');		
		}
	}

	return ElementsValid;
}

function SimClick_Reset(Obj)
{
	if (ie4plus) ParentObj.style.paddingTop = '0px';
	ParentObj.style.paddingLeft = '0px';
}

function SimClick(Obj)
{
	ie4plus ? ParentObj = Obj.parentElement : ParentObj = Obj.parentNode; 
	
	if (ie4plus) ParentObj.style.paddingTop = '2px';
   ParentObj.style.paddingLeft = '2px';
	
	window.setTimeout(function () { SimClick_Reset(Obj) }, 140);
	return true;
}

function ResetSuchButtons(BezName, NumName)
{
	var Button
	
	if (!(moz || ns6 || ns7) && (parent.frames['suchenach']))
	{
		if (parent.frames['suchenach'].frm_Bezeichnung) {
			Button = GetElemRefFromBase(parent.frames['suchenach'].document, 'ButtonSucheBez');
			if (Button != null && Button.value) Button.value = BezName;
		}
		
		if (parent.frames['suchenach'].frm_Nummer) {
			Button = GetElemRefFromBase(parent.frames['suchenach'].document, 'ButtonSucheNummer');
			if (Button != null && Button.value) Button.value = NumName;
		}
	}
	return true;
}

function SetSuchButtons(SuchTyp, SuchName)
{
	switch (SuchTyp)
	{
		case 1:
			if (!isNaN(document.getElementById('suchbegr').value) && (document.getElementById('suchbegr_nummer') != null))
			{
				TargetFormID = 'suchbegr_nummer';
				TargetButtonID = 'ButtonSucheNummer';
				SubmitForm = document.frm_Nummer;
			}
			else
			{
				TargetFormID = 'suchbegr_bez';
				TargetButtonID = 'ButtonSucheBez';
				SubmitForm = document.frm_Bezeichnung;
			}
			break;
		case 2:
			TargetFormID = 'suchbegr_bez';
			TargetButtonID = 'ButtonSucheBez';
			break;
		case 3:
			TargetFormID = 'suchbegr_nummer';
			TargetButtonID = 'ButtonSucheNummer';
			break;
	}

	if (document.getElementById(TargetFormID)) {
		document.getElementById(TargetFormID).value = document.getElementById('suchbegr').value;
		if (!(moz || ns6 || ns7) && SuchName != '') document.getElementById(TargetButtonID).value = SuchName;
	}

	if (SuchTyp == 1)
	{
		SubmitForm.submit();
		return false;
	}	
}

function FocusBestellMenge()
{
 	if (document.frm_Bestellung.item("cart.add.menge")) 
	{
		document.frm_Bestellung.item("cart.add.menge").focus();
	}
	else
	{
		if (document.frm_Bestellung.item("cart.add.1.menge")) document.frm_Bestellung.item("cart.add.1.menge").focus();
	}
}

function FocusLogin ()
{
	if (document.frm_Login)
	{
		if (document.frm_Login.passw.value == "") document.frm_Login.passw.focus();
		if (document.frm_Login.kunde.value == "") document.frm_Login.kunde.focus();
	}
}

function FocusSchnellauswahl()
{
	if (document.getElementById("Schnell_artikel")) document.getElementById("Schnell_artikel").focus();
}

function FocusZahlungsart()
{
	if (document.getElementById('Kreditkartennummer') && !(document.getElementById('Kreditkartennummer').disabled)) document.getElementById('Kreditkartennummer').focus();
	if (document.getElementById('Kontonummer') && !(document.getElementById('Kontonummer').disabled)) document.getElementById('Kontonummer').focus();
}

function SubmitZahlungsart()
{
	if (document.frm_Zahlungsart)
	{
		document.frm_Zahlungsart.action="bestellen_zahlungsart.asp";
		document.frm_Zahlungsart.submit();
	}
}

function SubmitZahlungsartWK()
{
	if (document.frm_Zahlungsart)
	{
		document.frm_Zahlungsart.action="warenkorb.asp";
		document.frm_Zahlungsart.submit();
	}
}

function SubmitLieferanschriften()
{
	if (document.frm_Lieferanschriften)
	{
		document.frm_Lieferanschriften.action="bestellen_lieferanschriften.asp";
		document.frm_Lieferanschriften.submit();
	}
}

function LoadAuftragsbestaetigung()
{
	var parameter = "";	
	
	parameter += "width=" + screen.width - 40;
	parameter += ",height=" + screen.height - 100;
	parameter += ",resizable=yes";
	parameter += ",scrollbars=yes";
	parameter += ",menubar=yes";
	parameter += ",toolbar=no";
	parameter += ",location=no";
	parameter += ",status=yes";		
	
	return window.open("auftragsbestaetigung.asp","",parameter);
}

function CS()
{
	ClearStatusZeile();
}

function ClearStatusZeile()
{
	window.status = ' ';
	window.defaultStatus = ' ';
	return true;
}

function GetElemRefFromBase(ParentDoc, ElemString)
{
	if (w3c)
	{
		return ParentDoc.getElementById(ElemString);
	}
	else 
	{
		if (ie4plus) { return ParentDoc.all[ElemString]; }
	}
}

function SetUeberschrift(HtmlID, Text)
{
	var AllFrames = parent.frames;
	
	if (HtmlID == null || Text == null) return;
	if (AllFrames)
	{
		for (var i=0; i < AllFrames.length; i++)
		{
			if (GetElemRefFromBase(AllFrames[i].document, HtmlID) != null)
			{
				GetElemRefFromBase(AllFrames[i].document, HtmlID).innerHTML = Text;
			}
		  	if (GetElemRefFromBase(AllFrames[i].document,'KatalogUeberschrift') != null)
			{
				GetElemRefFromBase(AllFrames[i].document, 'KatalogUeberschrift').innerHTML = '';
			}
			
		}
		
	}
}

function SetArtikelProSeite(HtmlID, Anzahl, MacroName)
{
	var AllFrames = parent.frames;
	var Elem;
	var BisTemp1, BisTemp2;
	if (HtmlID == null || Anzahl == null || MacroName == null) return;
	
	if (AllFrames)
	{
		for (var i=0; i < AllFrames.length; i++)
		{
			if (GetElemRefFromBase(AllFrames[i].document, HtmlID) != null)
			{
				Elem = GetElemRefFromBase(AllFrames[i].document, HtmlID);

				BisTemp1 = Elem.action.indexOf('?') > 0 ? Elem.action.indexOf('?') : Elem.action.length;
				BisTemp2 = window.location.href.indexOf('?') > 0 ? window.location.href.indexOf('?') : window.location.href.length;
				Elem.action = Elem.action.substring(0, BisTemp1) + window.location.href.substring(BisTemp2, window.location.href.length);
				
				if (Elem.macroname) Elem.macroname.value = MacroName;
				if (Elem.blocksize) Elem.blocksize.value = Anzahl;
			}
		}
	}
}

function HideArtikelProSeite(HtmlID)
{
	var AllFrames = parent.frames;
	var Elem;
	
	if (HtmlID == null) return;
	
	if (AllFrames)
	{
		for (var i=0; i < AllFrames.length; i++)
		{
			if (GetElemRefFromBase(AllFrames[i].document, HtmlID) != null)
			{
				GetElemRefFromBase(AllFrames[i].document, HtmlID).style.visibility = 'hidden';
			}
		}
	
		for (var i=0; i < AllFrames.length; i++)
		{
			if (GetElemRefFromBase(AllFrames[i].document, 'ArtikelTabellenKopf') != null)
			{
				GetElemRefFromBase(AllFrames[i].document, 'ArtikelTabellenKopf').style.visibility = 'hidden';
			}
		}
	}
}

function ShowArtikelProSeite(HtmlID)
{
	var AllFrames = parent.frames;
	var Elem;
	
	if (HtmlID == null) return;
	if (AllFrames)
	{
		for (var i=0; i < AllFrames.length; i++)
		{
			if (GetElemRefFromBase(AllFrames[i].document, HtmlID) != null)
			{
				GetElemRefFromBase(AllFrames[i].document, HtmlID).style.visibility = 'visible';
			}
		}
		for (var i=0; i < AllFrames.length; i++)
		{
			if (GetElemRefFromBase(AllFrames[i].document, 'ArtikelTabellenKopf') != null)
			{
				GetElemRefFromBase(AllFrames[i].document, 'ArtikelTabellenKopf').style.visibility = 'visible';
			}
		}
	}
}

String.prototype.RTrim = function() { return this.replace(/\s+$/, ""); }
String.prototype.LTrim = function() { return this.replace(/^\s+/, ""); }
String.prototype.Trim = function() { return this.RTrim().LTrim(); }

function CheckBestDaten(IDStrings, BaseForm) 
{
	var NoError = true;
	
	for (var i=0; i< IDStrings.length; i++) {
		if (BaseForm.elements[IDStrings[i]]) {
			if (BaseForm.elements[IDStrings[i]].value.Trim() == '') {
				SetBestDatenInput(BaseForm.elements[IDStrings[i]], 3);
				NoError = false;
			}
			else
				SetBestDatenInput(BaseForm.elements[IDStrings[i]], 1);
		}
	}

	return NoError;
}


function SetBestDatenInput (Obj, Modus)
{
	if (Obj == null) return;

	switch (Modus) {
		case 1:
			Obj.className = 'BestDaten-Normal';
			break;
		case 2:
			Obj.className = 'BestDaten-Focused';
			break;
		case 3:
			Obj.className = 'BestDaten-Error';
			break;
	}
}


function GetElemRef(ElemString)
{
	if (w3c)
	{
		return document.getElementById(ElemString);
	}
	else 
	{
		if (ie4plus) { return document.all[ElemString]; }
	}
}

function GetVariantenDataFav(Line, IsVariante) {
	if (IsVariante == false) return;
	
	if (Line.toUpperCase() == 'OL' && document.forms.frm_Bestellung != null) {
		i = 1;
		NewHersteller = '';
		
		while (1 == 1) {
			if (GetElemRef("cart.add." + i + ".menge") != null) {
				if (GetElemRef("cart.add." + i + ".menge").value > 0 && GetElemRef("cart.add." + i + ".auspraegungID") != null) {
					NewHersteller += ";" + GetElemRef("cart.add." + i + ".auspraegungID").value;
				}
				i++;
			}
			else {
				break;
			}
		}
		
		if (document.forms.Favoriten != null) {
			document.forms.Favoriten.elements['cart.add.hersteller'].value = NewHersteller;
		}
	}
}

function SetStatusHidden(HtmlID)
{
	var AllFrames = parent.frames;
	
	if (HtmlID == null) return;
	if (AllFrames)
	{
		for (var i=0; i < AllFrames.length; i++)
		{
			if (GetElemRefFromBase(AllFrames[i].document, HtmlID) != null)
			{
				GetElemRefFromBase(AllFrames[i].document, HtmlID).style.visibility = 'hidden';
			}
		}
	}
}

function OnlyNumbers(value){
	return value.replace(/[A-Za-z\W%_]+/, "");
};



