function SubmitForm(Formname, Formaction, Action) {

	if (Formaction) {
		document.forms[Formname].formaction.value = Formaction;
	}
	
	if (Action) {
		document.forms[Formname].action = Action;
	}
	
	document.forms[Formname].submit();

}

function DisableLaenderauswahl() {

    // die Auswahlliste deaktivieren
	if (document.forms["form_land"].elements["laender[]"].disabled) {
	    document.forms["form_land"].elements["laender[]"].disabled = false;
	} else {
        document.forms["form_land"].elements["laender[]"].disabled = true;
    }

}

function DisableKundengruppenVersandarten() {

    // die Auswahlliste deaktivieren
	if (document.forms["edit_form"].elements["versandarten[]"].disabled) {
	    document.forms["edit_form"].elements["versandarten[]"].disabled = false;
	} else {
        document.forms["edit_form"].elements["versandarten[]"].disabled = true;
    }

}

function SetReadOnly(FormName, InputName, Readonly) {
	document.forms[FormName].elements[InputName].readOnly = Readonly;
	
}

function SetRadioButton(FormName, RadioButtonName, RadioButtonValue) {
	if (document.forms[FormName].elements[RadioButtonName][0].checked) {
		document.forms[FormName].elements[RadioButtonName][RadioButtonValue].checked = true;
		SetReadOnly(FormName, 'artikel_nr', 'true');
	}
	
}

function ReloadDetailPage(FormName, FormAction, FormNextSite) {

	if (document.forms[FormName].elements["schemamenue"]) {
		document.forms[FormName].elements["variante1"].value = document.forms[FormName].elements["schemamenue"].value;
	}
	
	if (document.forms[FormName].elements["schemamenue1"]) {
		document.forms[FormName].elements["variante2"].value = document.forms[FormName].elements["schemamenue1"].value;
	}

	if (document.forms[FormName].elements["schemamenue2"]) {
		document.forms[FormName].elements["variante3"].value = document.forms[FormName].elements["schemamenue2"].value;
	}

	if (document.forms[FormName].elements["schemamenue3"]) {
		document.forms[FormName].elements["variante4"].value = document.forms[FormName].elements["schemamenue3"].value;
	}
	
	document.forms[FormName].elements["formaction"].value = FormAction;
	document.forms[FormName].action = FormNextSite;
	document.forms[FormName].submit();
	
}

function GoToDetailPage(FormName, FormAction, FormNextSite) {

	if (document.forms[FormName].elements["schemamenue"]) {
		document.forms[FormName].elements["variante1"].value = document.forms[FormName].elements["schemamenue"].value;
	}

	if (document.forms[FormName].elements["schemamenue1"]) {
		document.forms[FormName].elements["variante2"].value = document.forms[FormName].elements["schemamenue1"].value;
	}

	if (document.forms[FormName].elements["schemamenue2"]) {
		document.forms[FormName].elements["variante3"].value = document.forms[FormName].elements["schemamenue2"].value;
	}

	if (document.forms[FormName].elements["schemamenue3"]) {
		document.forms[FormName].elements["variante4"].value = document.forms[FormName].elements["schemamenue3"].value;
	}

	document.forms[FormName].elements["formaction"].value = FormAction;
	document.forms[FormName].action = FormNextSite;
	document.forms[FormName].submit();

}

function SaveFormAndOpenPreisPopup(FormName, FormAction, RadiobuttonName, RadiobuttonValue1, RadiobuttonValue2, PopupFile1, PopupFile2, PopupWidth, PopupHeight) {

	if (document.forms[FormName].elements[RadiobuttonName][RadiobuttonValue1].checked) {
		SaveFormAndOpenPopup(FormName, FormAction, PopupFile1, PopupWidth, PopupHeight);
	}

	if (document.forms[FormName].elements[RadiobuttonName][RadiobuttonValue2].checked) {
		SaveFormAndOpenPopup(FormName, FormAction, PopupFile2, PopupWidth, PopupHeight);
	}

}

function SaveFormAndOpenPopup(FormName, FormAction, PopupFile, PopupWidth, PopupHeight) {
	document.forms[FormName].action = FormAction;
	document.forms[FormName].elements["popupfile"].value = PopupFile;
	document.forms[FormName].elements["popupwidth"].value = PopupWidth;
	document.forms[FormName].elements["popupheight"].value = PopupHeight;
	document.forms[FormName].submit();

}

function openFenster(datei,breite,hoehe)
{
	fenster = open(datei,"send","width="+breite+",height="+hoehe+",locationbar=no,menubar=no,scrollbars=yes");
	fenster.focus();
}

function openFenster2(datei,breite,hoehe)
{
	fenster = open(datei,"big","width="+breite+",height="+hoehe+",locationbar=no,menubar=no,scrollbars=yes");
	fenster.focus();
}

function fenster_auf(file)
{ 
	fs=window.open(file,"Fenstername","location=no,height=300px,width=250px");
	fs.moveTo(230,100); /*  Positionierung des Fensters */
	fs.focus();
}

/* Für den Backgroundchange in der Navi */
function chgBg(obj,color)
{
	if (document.all || document.getElementById)
		obj.style.backgroundColor=color;
	else if (document.layers)
 		obj.bgColor=color;
}


/****************************************************************************
*												Editor fuer Formulardaten														*
****************************************************************************/
function Fett()
{
  Markierung = document.selection.createRange().text ;
          
  if(Markierung=="")
  {
  document.getElementById('formular').beschreibung.value = document.getElementById('formular').beschreibung.value + '<b>text</b>';
  }
  else
  {
	 Markierung = '<b>'+Markierung+'</b>';
	document.selection.createRange().text = Markierung;
  }      
}

function Kursiv()
{
  Markierung = document.selection.createRange().text;
          
  if(Markierung=="")
  {
  document.getElementById('formular').beschreibung.value = document.getElementById('formular').beschreibung.value + '<i>text</i>';
  }
  else
  {
	 Markierung = '<i>'+Markierung+'</i>';
	document.selection.createRange().text = Markierung;
  }       
}

function Unterstreichen()
{
  Markierung = document.selection.createRange().text;
          
  if(Markierung=="")
  {
  document.getElementById('formular').beschreibung.value = document.getElementById('formular').beschreibung.value + '<u>text</u>';
  }
  else
  {
	 Markierung = '<u>'+Markierung+'</u>';
	document.selection.createRange().text = Markierung;
  }      
}

function Pfad()
{
  Markierung = document.selection.createRange().text;
          
  if(Markierung=="")
  {
  document.getElementById('formular').beschreibung.value = document.getElementById('formular').beschreibung.value + "<a href='HTTP://URL\' target='blank'>text</a>";
  }
  else
  {
	Markierung = "<a href='HTTP://URL' target='blank'>"+Markierung+"</a>";
	document.selection.createRange().text = Markierung;
  }  
}

function getHTTPObject() {
	/*Usage
	 * var request = getHTTPObject();
	 * if(request){
	 * AJAX CODE HERE
	 * }
	 * 
	 * If getHTTPObject returns false, the browser isn't Ajax compatible. The if 
	 * statement checks to see if it exists, then runs the code.
	 */
	var xhr = false;//set to false, so if it fails, do nothing
	if(window.XMLHttpRequest) {//detect to see if browser allows this method
		var xhr = new XMLHttpRequest();//set var the new request
	} else if(window.ActiveXObject) {//detect to see if browser allows this method
		try {
			var xhr = new ActiveXObject("Msxml2.XMLHTTP");//try this method first
		} catch(e) {//if it fails move onto the next
			try {
				var xhr = new ActiveXObject("Microsoft.XMLHTTP");//try this method next
			} catch(e) {//if that also fails return false.
				xhr = false;
			}
		}
	}
	return xhr;//return the value of xhr
}
