
  var windowsInternetExplorer = false;
  var browserVersion = 0;
	
	/*
		fix browser ie 6 (png-transparency)
	*/
	
	function png_load() {
		
		detectBrowser();
		
		if (!windowsInternetExplorer)
			return;
		
		if (browserVersion == 7)
			return;
		imgs = document.getElementsByTagName('img');
		
		for (var c = 0; c < imgs.length; c++) {
			
			var png = imgs[c].src.match(/\.png/);
      if (!png)
				continue;
			
  		imgs[c].style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + imgs[c].src + "')";
      imgs[c].src = '../customfactory/web/pictures/spacer.gif';
			
		}
	}
	
  function detectBrowser() {

    var appVersion = navigator.appVersion;
		
    if ((appVersion.indexOf("MSIE") != -1) &&
        (appVersion.indexOf("Macintosh") == -1)) {
      var temp = appVersion.split("MSIE");
      browserVersion = parseFloat(temp[1]);
			
      windowsInternetExplorer = true;
    }
  }	
	
	
  function validator(theForm){  	

    var alerts = $('alerts').innerHTML.replace(new RegExp("\n","g"), "");
    alerts = alerts.replace(new RegExp("\t","g"), "");
    alerts = alerts.replace(new RegExp("\r","g"), "");
    alerts = alerts.evalJSON(true);		    
    
		if(theForm.name == "payment") {
		
			if(theForm.payment_type[2].checked == true) {

				if(theForm.kartennr.value == "") {
					alert("Bitte geben Sie Ihre Kreditkartennummer an!!");
					theForm.kartennr.focus();
					return (false);
				}
				
				if(theForm.pruefnr.value == "") {
					alert("Bitte geben sie Ihre Kreditkartenprüfnummer an!");
					theForm.pruefnr.focus();
					return (false);
				}
				
			}
			
			if(theForm.payment_type[3].checked == true) {
				
				if(theForm.kontoinhaber.value == "") {
					alert("Bitte geben Sie den Kontoinhaber an!");
					theForm.kontoinhaber.focus();
					return (false);
				}
				
				if(theForm.kontonr.value == "") {
					alert("Bitte geben Sie die Kontonummer an!");
					theForm.kontonr.focus();
					return (false);
				}
				
				if(theForm.blz.value == "") {
					alert("Bitte geben sie die BLZ an!");
					theForm.blz.focus();
					return (false);
				}
				
				if(theForm.bank.value == "") {
					alert("Bitte geben Sie den Namen der Bank an!");
					theForm.bank.focus();
					return (false);
				}
				
			}
		
		}
		
    if(theForm.name == "order") {

    	var cart_members = $$('tr.cart_member');
      if(cart_members.length == 0) {
      	alert(alerts['cart']);
        return (false);
      }

    }

    if(theForm.Anrede) {

    	if(theForm.Anrede[0].checked == false && theForm.Anrede[1].checked == false) {
      	alert(alerts['Anrede']);
        return (false);      
      }

    }

    if(theForm.delivery_type) {

    	if(theForm.delivery_type[0].checked == false && theForm.delivery_type[1].checked == false) {
      	alert(alerts['Versand']);
        return (false);      
      }

    }

    if(theForm.agb) {

    	if(theForm.agb.checked == false) {
      	alert(alerts['agb']);
        return (false);      
      }

    }
    
    if(theForm.dse) {

    	if(theForm.dse.checked == false) {
      	alert(alerts['dse']);
        return (false);      
      }

    }

    if(theForm.user) {
      if (theForm.user.value == ""){
          alert(alerts['user']);
          theForm.user.focus();
          return (false);
      }
    }

    if(theForm.Benutzername) {
      if (theForm.Benutzername.value == ""){
          alert(alerts['Benutzername']);
          theForm.Benutzername.focus();
          return (false);
      }
    }
    
    if(theForm.Passwort) {
      if (theForm.Passwort.value == ""){
          alert(alerts['password']);
          theForm.Passwort.focus();
          return (false);
      }
    }
    
    if(theForm.password) {
      if (theForm.password.value == ""){
          alert(alerts['password']);
          theForm.password.focus();
          return (false);
      }
    }
    
    if(theForm.Vorname) {
    	if (theForm.Vorname.value == ""){
          alert(alerts['Vorname']);
          theForm.Vorname.focus();
          return (false);
      }
    }
		
    if(theForm.Nachname) {
    	if (theForm.Nachname.value == ""){
          alert(alerts['Nachname']);
          theForm.Nachname.focus();
          return (false);
      }
    }
		
    if(theForm.Strasse) {
    	if (theForm.Strasse.value == ""){
          alert(alerts['Strasse']);
          theForm.Strasse.focus();
          return (false);
      }
    }
		
    if(theForm.PLZ_Ort) {
    	if (theForm.PLZ_Ort.value == ""){
          alert(alerts['PLZ_Ort']);
          theForm.PLZ_Ort.focus();
          return (false);
      }
    }

    if(theForm.Ort) {
    	if (theForm.Ort.value == ""){
          alert(alerts['Ort']);
          theForm.Stadt.focus();
          return (false);
      }
    }

    if(theForm.EMail) {
    	if (theForm.EMail.value == ""){
          alert(alerts['EMail']);
          theForm.EMail.focus();
          return (false);
      }
    }

    if(theForm.coupon_betrag) {
      if (theForm.coupon_betrag.value == ""){
          alert(alerts['coupon_betrag']);
          theForm.coupon_betrag.focus();
          return (false);
      }
      if (theForm.coupon_betrag.value < 20){
          alert(alerts['coupon_betrag_min']);
          theForm.coupon_betrag.focus();
          return (false);
      }
    }

    if(theForm.coupon_von) {
      if (theForm.coupon_von.value == ""){
          alert(alerts['coupon_von']);
          theForm.coupon_von.focus();
          return (false);
      }
    }
    
    if(theForm.coupon_an) {
      if (theForm.coupon_an.value == ""){
          alert(alerts['coupon_an']);
          theForm.coupon_an.focus();
          return (false);
      }
    }
            
    if(theForm.coupon_email) {
      if(theForm.coupon_typ[0].checked) {
	      if (theForm.coupon_email.value == ""){
          alert(alerts['coupon_email']);
          theForm.coupon_email.focus();
          return (false);
  	    }
      }
    }

    if(theForm.coupon_nachricht) {
      if (theForm.coupon_nachricht.value == ""){
          alert(alerts['coupon_nachricht']);
          theForm.coupon_nachricht.focus();
          return (false);
      }
    }

    if(theForm.Sender_Name) {
      if (theForm.Sender_Name.value == ""){
          alert(alerts['Sender_Name']);
          theForm.Sender_Name.focus();
          return (false);
      }
    }

    if(theForm.coupon_typ) {
	    if(theForm.coupon_typ[1].checked) {
      	if (theForm.coupon_street.value == ""){
          alert(alerts['coupon_street']);
          theForm.coupon_street.focus();
          return (false);
      	}
        if (theForm.coupon_plz.value == ""){
          alert(alerts['coupon_plz']);
          theForm.coupon_plz.focus();
          return (false);
      	}
        if (theForm.coupon_city.value == ""){
          alert(alerts['coupon_city']);
          theForm.coupon_city.focus();
          return (false);
      	}
        if (theForm.coupon_country.value == ""){
          alert(alerts['coupon_country']);
          theForm.coupon_country.focus();
          return (false);
      	}
      }
    }
      	
    
    if(theForm.Receiver_EMail) {
      if (theForm.Receiver_EMail.value == ""){
          alert(alerts['Receiver_EMail']);
          theForm.Receiver_EMail.focus();
          return (false);
      }
    }

    if(theForm.df_31) {

      if (!theForm.df_31.checked &&
      		!theForm.df_32.checked &&
          !theForm.df_33.checked &&
          !theForm.df_34.checked &&
          !theForm.df_35.checked &&
          !theForm.df_36.checked &&
          theForm.df_37.value == ""
      		){
          alert(alerts['present_finder']);
          return (false);
      }
    }

    return (true);

  }

  function check_form(theForm) {

  	if(validator(theForm))
    	theForm.submit();
 
  }
  
  function fill (URL, ARTICLE_ID, DB_ID) {

		var quantity = document.getElementById('qua' + ARTICLE_ID).value;
    if(quantity == "")
    	quantity = 1;
    var color = document.getElementById('colors_' + ARTICLE_ID) ? document.getElementById('colors_' + ARTICLE_ID).value : "";
    var size = document.getElementById('sizes_' + ARTICLE_ID) ? document.getElementById('sizes_' + ARTICLE_ID).value : "";

		document.location.href = URL + '&addarticle=' + ARTICLE_ID + '&db_id=' + DB_ID + '&quantity=' + quantity + '&color=' + color + '&size=' + size;

	}
  
  function check_search_field() {

  	if(document.getElementById('search').value.length < 3) {
    	alert("Das Suchwort muss mindestens 3 Zeichen lang sein!");
      return false;
    } else return true;
  
  }
  
  function check_coupon_type() {

  	document.getElementById('coupon_headline').style.display = document.gutschein.coupon_typ[1].checked ? 'inline' : 'none';
    document.getElementById('coupon_street1').style.display = document.gutschein.coupon_typ[1].checked ? 'inline' : 'none';
    document.getElementById('coupon_street2').style.display = document.gutschein.coupon_typ[1].checked ? 'inline' : 'none';
    document.getElementById('coupon_plz1').style.display = document.gutschein.coupon_typ[1].checked ? 'inline' : 'none';
    document.getElementById('coupon_plz2').style.display = document.gutschein.coupon_typ[1].checked ? 'inline' : 'none';
    document.getElementById('coupon_country1').style.display = document.gutschein.coupon_typ[1].checked ? 'inline' : 'none';
    document.getElementById('coupon_country2').style.display = document.gutschein.coupon_typ[1].checked ? 'inline' : 'none';

  }
