// JavaScript Document


// Get the HTTP Object
function getHTTPObject()
{
	if (window.ActiveXObject) return new ActiveXObject("Microsoft.XMLHTTP");
	else if (window.XMLHttpRequest) return new XMLHttpRequest();
	else 
	{
		alert("Your browser does not support AJAX.");
		return null;
	}
}

// Change the value of the outputText field
function setOutput()
{
	if(httpObject.readyState == 4)
	{
		document.getElementById('txtarea_zahlungsart').innerHTML = httpObject.responseText;
	}
}

// Implement business logic
function get_Zahlungsart_txt()
{
	httpObject = getHTTPObject();
	if (httpObject != null) 
	{
		//var selObj = document.getElementById('sel_Zahlungsart');
		zahlartid = $('#sel_Zahlungsart').val();
		httpObject.open("GET", "ace_ajax.php?sel_Zahlungsart="
		+zahlartid, true);
		httpObject.send(null);
		httpObject.onreadystatechange = setOutput;
		
		if (zahlartid == 2)
		{
			$('.kkForm').slideDown(1000);
		}
		else
		{
			$('.kkForm').slideUp(1000);
		}
		
		update_prices();
	}
}

function update_prices()
{
	if ($('#cb_Lieferadresse').attr('checked') == "checked")
	{
		land = "&daten[liefer_landIsoAlpha]="+$('#liefer_land').val();
	}
	else
	{
		land = "&daten[landIsoAlpha]="+$('#land').val();
	}
	zahlartid = $('#sel_Zahlungsart').val();
	$.ajax({
	   type: "POST",
	   url: "mm_kasse.php",
	   data: "zahlart_submit=1&zahlungsweise="+zahlartid+land,
	   success: function(response){
	     //alert( "Data Saved: " + msg );
	     $('#price_infos').html(response);
	   }
	 });
}

function change_Firma_txt()
{
	if(document.getElementById('sel_Zahlungsart').selectedIndex == 5 && document.getElementById('frm_firma').value == '')
	{
		httpObject = getHTTPObject();
		if (httpObject != null) 
		{
			var selObj = document.getElementById('sel_Zahlungsart');
			httpObject.open("GET", "ace_ajax.php?sel_Zahlungsart="
			+0, true);
			httpObject.send(null);
			httpObject.onreadystatechange = setOutput;
		}
		
		document.getElementById('sel_Zahlungsart').selectedIndex = 0;
		
		
	}

}
$(document).ready(function(){
	$('#add_art_button').click(function(){
		artnr = $('#frm_artikelnummer').val();
		$.ajax({
		   type: "POST",
		   url: "mm_kasse.php",
		   data: "add_artikel=1&ajax=true&add_new_artnr="+artnr,
		   success: function(response){
			data = jQuery.parseJSON(response);
		     //alert( "Data Saved: " + response );
		     $('#article_listing').html(data[0]);
		     $('#price_infos').html(data[1]);
		     
		     if (data[2] != 1)
		     {
		     	$('#adding_product_failed').html('Der Artikel konnte nicht gefunden bzw. hinzugefügt werden.');
		     }
		     else
		     {
		     	$('#adding_product_failed').html(' ');
		     }
		   }
		 });
		 $('#frm_artikelnummer').val('Artikelnummer')
		return false;
	});
	$('#save_adress').click(function(){
		daten = '';
		prefix = '';
		i = 0;
		$('#adressForm input').each(function() {
			name = $(this).attr('name');
			if (name == 'daten[vorname]' || name == 'daten[nachname]' || name == 'daten[strasse]' || name == 'daten[hausnr]' || name == 'daten[plz]' || name == 'daten[ort]')
			{
				if (i != 0)
				{
					prefix = "&";
				}
				daten += prefix + name + '=' + $(this).val();
				i++;
			}
		});
		daten += '&daten[anrede]='+$('#adressForm select[name="daten[anrede]"] option:selected').val();
		daten += '&daten[landIsoAlpha]='+$('#adressForm select[name="daten[landIsoAlpha]"] option:selected').val();
		$.ajax({
		   type: "POST",
		   url: "myshop.php?ajax=true&option=saveAdress",
		   data: daten,
		   success: function(response){
			//data = jQuery.parseJSON(response);
		     var offset = $('#save_adress').offset();
			 $('#backgroundLayer').height($('body').height());
		     $('#adressbuchLayer').css({marginTop:offset.top-2+'px',marginLeft:offset.left+$('#save_adress').width()+6+'px'});
		     $('#adressbuchLayer').html(response);
		     $('#backgroundLayer').slideDown(1000);
		   }
		 });
		return false;
	});
	$('#save_delivery_adress').click(function(){
		daten = '';
		prefix = '';
		i = 0;
		$('#adressForm input').each(function() {
			name = $(this).attr('name');
			if (name == 'daten[liefer_vorname]' || name == 'daten[liefer_nachname]' || name == 'daten[liefer_strasse]' || name == 'daten[liefer_hausnr]' || name == 'daten[liefer_plz]' || name == 'daten[liefer_ort]')
			{
				if (i != 0)
				{
					prefix = "&";
				}
				daten += prefix + name + '=' + $(this).val();
				i++;
			}
		});
		daten += '&daten[liefer_anrede]='+$('#adressForm select[name="daten[liefer_anrede]"] option:selected').val();
		daten += '&daten[liefer_landIsoAlpha]='+$('#adressForm select[name="daten[liefer_landIsoAlpha]"] option:selected').val();
		$.ajax({
		   type: "POST",
		   url: "myshop.php?ajax=true&option=saveAdress",
		   data: daten,
		   success: function(response){
			//data = jQuery.parseJSON(response);
		     var offset = $('#save_delivery_adress').offset();
			 $('#backgroundLayer').height($('body').height());
		     $('#adressbuchLayer').css({marginTop:offset.top-2+'px',marginLeft:offset.left+$('#save_adress').width()+6+'px'});
		     $('#adressbuchLayer').html(response);
		     $('#backgroundLayer').slideDown(1000);
		   }
		 });
		return false;
	});
	$('#getAdressenLink').click(function() {
		$.ajax({
		   type: "POST",
		   url: "myshop.php",
		   data: "ajax=1&option=getAdressen",
		   success: function(response){
			//data = jQuery.parseJSON(response);
		     //alert( "Data Saved: " + response );
		     var offset = $('#getAdressenLink').offset();
			 $('#backgroundLayer').height($('body').height());
		     $('#adressbuchLayer').css({marginTop:offset.top+'px',marginLeft:offset.left+$('#getAdressenLink').width()+'px'});
		     $('#adressbuchLayer').html(response);
		     $('#backgroundLayer').slideDown(1000);
		   }
		 });
		 return (false);
	});
	$('#getLieferAdressenLink').click(function() {
		$.ajax({
		   type: "POST",
		   url: "myshop.php",
		   data: "ajax=1&option=getLieferAdressen",
		   success: function(response){
			//data = jQuery.parseJSON(response);
		     //alert( "Data Saved: " + response );
		     var offset = $('#getLieferAdressenLink').offset();
			 $('#backgroundLayer').height($('body').height());
		     $('#adressbuchLayer').css({marginTop:offset.top+'px',marginLeft:offset.left+$('#getLieferAdressenLink').width()+'px'});
		     $('#adressbuchLayer').html(response);
		     $('#backgroundLayer').slideDown(1000);
		   }
		 });
		 return (false);
	});
	$('#adressbuchLayer').click(function() {
		 return (false);
	});
	$('#backgroundLayer').click(function() {
		 $('#backgroundLayer').slideUp(1000);
	});
});

function closeWindow()
{
	$('#backgroundLayer').slideUp(1000);
	return (false);
}

function selectAdress(id,deliveryAdressFlag)
{
	i = 0;
	prefix = '';
	
	if (deliveryAdressFlag == 1)
	{
		prefix = 'liefer_';
	}
	
	if (prefix == '')
	{
		$('#billingForm input').each(function() {
			if ($(this).attr('id') != 'save_adress')
			{
				$(this).val('');
			}
		});
		$('#billingForm select').each(function() {
			$(this).val('');
		});
	}
	else
	{
		$('#deliveryForm input').each(function() {
			if ($(this).attr('id') != 'save_delivery_adress' && $(this).attr('id') != 'coupon_button' && $(this).attr('id') != 'cb_Lieferadresse')
			{
				$(this).val('');
			}
		});
		$('#deliveryForm select').each(function() {
			$(this).val('');
		});
	}
	
	$('.Adresse'+id).each(function() {
		if (i == 0)
		{
			feld = "daten["+prefix+"anrede]";
		}
		else if (i == 1)
		{
			feld = "daten["+prefix+"vorname]";
		}
		else if (i == 2)
		{
			feld = "daten["+prefix+"nachname]";
		}
		else if (i == 3)
		{
			feld = "daten["+prefix+"strasse]";
		}
		else if (i == 4)
		{
			feld = "daten["+prefix+"hausnr]";
		}
		else if (i == 5)
		{
			feld = "daten["+prefix+"plz]";
		}
		else if (i == 6)
		{
			feld = "daten["+prefix+"ort]";
		}
		else if (i == 7)
		{
			feld = "daten["+prefix+"land]";
		}
		wert = $(this).html();
		if (i != 0 && i != 7)
		{
			$('input[name="'+feld+'"]').val(wert);
		}
		else
		{
			if (i == 7 && wert == '')
			{
				wert = 'Deutschland';
			}
			if (i == 0)
			{
				$('select[name="'+feld+'"] option').each(function (){
					if($(this).val() == wert)
					{
						$(this).attr('selected', 'true')
					}
				});
			}
			else
			{
				$('select[name="daten[landIsoAlpha]"] option').each(function (){
					if($(this).html() == wert)
					{
						$(this).attr('selected', 'true')
					}
				});
			}
		}
		i++;
	})
	closeWindow()
	return (false);
}

var httpObject = null;


function setVisibility_Lieferadresse()
{
	if(document.getElementById('cb_Lieferadresse').checked == true)
	{
		//document.getElementById('show_Lieferadresse').style.visibility='visible';
		//document.getElementById('show_Lieferadresse').style.height='auto';
		$('#show_Lieferadresse').slideDown(1000);
	}
	else
	{
		//document.getElementById('show_Lieferadresse').style.visibility='hidden';
		//document.getElementById('show_Lieferadresse').style.height='1px';
		$('#show_Lieferadresse').slideUp(1000);
	}
}

function check_Firma()
{
	
	if(document.getElementById('frm_firma').value == '')
	{
		//document.getElementById("sel_Zahlungsart").options[5].style.visibility='hidden';
		document.getElementById("zahlungsweise6").disabled = true;
	}
	else
	{
		//document.getElementById("sel_Zahlungsart").options[5].style.visibility='visible';
		//document.getElementById("sel_Zahlungsart").getElementsByTagName("option")[5].disabled = false;
		document.getElementById("zahlungsweise6").disabled = false;
	}
}








// NAV CONTENT 

/*function navContent ()
	{
		//window.open("tab_unternehmen.php", "TELOTEC", target="Fensterlein");
		
		if (document.getElementById)
           alert(document.getElementById};
		//document.getElementById("menu_top_sub").background = "../img/nav_content/nav_tab_on.jpg";
		alert(document.getElementById);
		//document.getElementById("menu_top_sub").backgroundImage = "url(../img/nav_content/nav_tab_on.jpg)";
		//document.getElementById("contents").aline = 'right';
		document.all.menu_top_sub.style.backgroundImage = "url(../img/nav_content/nav_tab_on.jpg)";
	}*/
	

function pop_Statisch () 
	{
  		 pop_Statisch = window.open("pop_statisch.php", "Versand", width=750,height=550,scrollbars='yes');
  		 pop_Statisch.focus();
	}

	
function schritteAusdruck_Export () 
	{
  		schritteAusdruckExport = window.open("ausdruck_export.php", "TELOTEC", width=800,height=1200,scrollbars='yes');
  		schritteAusdruckExport.focus();
	}

function schritteAusdruck_Import () 
	{
		schritteAusdruckImport = window.open("ausdruck_import.php", "TELOTEC", width=800,height=1200,scrollbars='yes');
  		schritteAusdruckImport.focus();
	}	
	
function schritteExport () 
	{
  		schritteExport_w = window.open("3schritte_export.php", "TELOTEC", width=800,height=600,scrollbars='yes');
  		schritteExport_w.focus();
	}

function schritteImport () 
	{
  		schritteImport_w = window.open("3schritte_import.php", "TELOTEC", "menubar=1,resizable=1,width=350,height=250");
  		schritteImport_w.focus();
	}
	
function schImport()
{
	window.open("3schritte_import.php","TELOTEC","menubar=0,resizable=1,width=1000,height=700");
}

function schExport()
{
	window.open("3schritte_export.php","TELOTEC","menubar=0,resizable=1,width=1000,height=750");
}






function schrittClear () 
{
  if (document.getElementById)
     /*alert(document.getElementById};*/
     document.getElementById("Layer1").style.visibility = "hidden";
     document.getElementById("Layer2").style.visibility = "hidden";
	 document.getElementById("Layer3").style.visibility = "hidden";
}


function schritt1 () 
{
  if (document.getElementById)
     /*alert(document.getElementById};*/
     document.getElementById("Layer1").style.visibility = "visible";
     document.getElementById("Layer2").style.visibility = "hidden";
	 document.getElementById("Layer3").style.visibility = "hidden";
}

function schritt2 () 
{
  if (document.getElementById)
     /*alert(document.getElementById};*/
     document.getElementById("Layer1").style.visibility = "hidden";
     document.getElementById("Layer2").style.visibility = "visible";
	 document.getElementById("Layer3").style.visibility = "hidden";
}

function schritt3 () 
{
  if (document.getElementById)
     /*alert(document.getElementById};*/
     document.getElementById("Layer1").style.visibility = "hidden";
     document.getElementById("Layer2").style.visibility = "hidden";
	 document.getElementById("Layer3").style.visibility = "visible";
}


function expSchritt1 () 
{
  if (document.getElementById)
     /*alert(document.getElementById};*/
     document.getElementById("expLayer1").style.visibility = "visible";
     document.getElementById("expLayer2").style.visibility = "hidden";
	 document.getElementById("expLayer3").style.visibility = "hidden";
}

function expSchritt2 () 
{
  if (document.getElementById)
     /*alert(document.getElementById};*/
     document.getElementById("expLayer1").style.visibility = "hidden";
     document.getElementById("expLayer2").style.visibility = "visible";
	 document.getElementById("expLayer3").style.visibility = "hidden";
}

function expSchritt3 () 
{
  if (document.getElementById)
     /*alert(document.getElementById};*/
     document.getElementById("expLayer1").style.visibility = "hidden";
     document.getElementById("expLayer2").style.visibility = "hidden";
	 document.getElementById("expLayer3").style.visibility = "visible";
}

function expSchrittClear () 
{
  if (document.getElementById)
     /*alert(document.getElementById};*/
     document.getElementById("expLayer1").style.visibility = "hidden";
     document.getElementById("expLayer2").style.visibility = "hidden";
	 document.getElementById("expLayer3").style.visibility = "hidden";
}




function show () 
{
  if (document.getElementById)
     /*alert(document.getElementById};*/
     document.getElementById("box").style.visibility = "visible";
     document.getElementById("box1").style.visibility = "hidden";
}


function hide () 
{
  if (document.getElementById)
     document.getElementById("box").style.visibility = "hidden";
     document.getElementById("box1").style.visibility = "visible";
	 
}

function resize() {
  setHeightTo('MainArea', winHeight()-137);
  window.status=winHeight();
}

function scrollToPosition() {
	try{
		if(document.getElementById("scrollpos").value!="")
			document.getElementById("LM1").scrollTop=document.getElementById("scrollpos").value;
		else if(document.location.hash!="")
			document.location=document.location.hash;
		setInterval("document.getElementById(\"scrollpos\").value=document.getElementById(\"MainArea\").scrollTop", 1000);
	}catch(e){null;}
}


function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

