var echo = '';

function getSessionID() {
	return document.cookie.replace("PHPSESSID=", "");
}

/* POPUP */
function popup(element, width, height) {
	if (element.getAttribute) {
		url = element.getAttribute('href');
	} else {
		url = element;
	}
	new_window = window.open(url, '_blank', 'width=' + width + ', height=' + height + ', left=' + Math.round((screen.width - width)/2) + ', top=' + Math.round((screen.height - height)/4) + ', location=0, statusbar=1, menubar=0, toolbar=0, scrollbars=0, name=info_popup');
	return false;
}

function popup_2(element, width, height) {
	if (element.getAttribute) {
		url = element.getAttribute('href');
	} else {
		url = element;
	}
	new_window = window.open(url, '_blank', 'width=' + width + ', height=' + height + ', left=' + Math.round((screen.width - width)/2) + ', top=' + Math.round((screen.height - height)/4) + ', location=0, statusbar=1, menubar=0, toolbar=0, scrollbars=1, name=info_popup');
	return false;
}

function click_kollektion(nr,count) {
	for (var i=0; i<count; i++) {
		if (i!=nr) {
			$('#sub_'+i).hide();
		}
	}
	
	$('#sub_'+nr).toggle();
}

function formcheck_geburtstagserinnerung() {
	var temp = document.formular.input_mail.value;
	if (temp == "") {
		alert('Bitte geben Sie Ihre E-Mail-Adresse an!');
		return false;
	} else {
		var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
		if (filter.test(temp)) {
			//document.formular.submit();
		} else {
			alert('Die eingegebene E-mail-Adresse ist nicht korrekt!');
			return false;
		}
	}
	
	var check_anyinput = 0;
	for (var i=1; i<=5; i++) {
		var temp_name_kind = document.formular['input_name_' + i].value.length;
		if (temp_name_kind != 0) {
			check_anyinput = 1;
			var temp_datum_1 = document.formular['input_datum_tag_' + i].value.length;
			var temp_datum_2 = document.formular['input_datum_monat_' + i].value.length;
			var temp_datum_3 = document.formular['input_datum_jahr_' + i].value.length;
			var temp_geschlecht = document.formular['input_geschlecht_' + i].value.length;
			if (temp_datum_1 == 0 || temp_datum_2 == 0 || temp_datum_3 == 0 || temp_geschlecht == 0) {
				alert('Bitte zu den eingebenen Namen auch Geburtsdaten und Geschlecht komplett angeben!');
				return false;
			}
		}
	}
	
	if (check_anyinput == 0) {
		alert('Bitte geben Sie mindestens 1 Geburtstag ein!');
		return false;
	} else {
		return true;
	}
}

/* KONTAKT */
function adressformular_pruefen() {
	if(document.adressformular.vorname.value.length < 1 || document.adressformular.nachname.value.length < 1 || document.adressformular.email.value.length < 1 || document.adressformular.betreff.value.length < 1 || document.adressformular.nachricht.value.length < 1) {
		alert("Bitte füllen Sie das Kontaktformular vollständig aus!");
		return;
	}
	
	document.adressformular.submit();
}

function adressformular_loeschen() {
	document.adressformular.vorname.value = "";
	document.adressformular.nachname.value = "";
	document.adressformular.email.value = "";
	document.adressformular.betreff.value = "";
	document.adressformular.nachricht.value = "";
}

function empfehlung_pruefen() {
	if(document.adressformular.email_empfaenger.value.length < 1) {
		alert("Sie m&uuml;ssen die Email-Adresse des Empf&auml;ngers angeben!");
		return;
	}
	
	document.adressformular.submit();
}


/* NAVIGATION */
function mitsubnav(sub_id,menge_navpunkte) {
	for (i=0; i<menge_navpunkte; i++) {
		var sub_schliessen = 'sub_' + i;
		document.getElementById(sub_schliessen).style.display = "none";
	}
	document.getElementById(sub_id).style.display = "block";
}



/* WARENKORB */
function change_warenkorb(warenkorb_id) {
	var neue_anzahl = document['warenkorb'+warenkorb_id].anzahl.value;
	var neue_groesse = document['warenkorb'+warenkorb_id].groesse.value;
	var neue_farbe = document['warenkorb'+warenkorb_id].farbe.value;
	
	/* alert (neue_anzahl + "______" + neue_groesse + "______" + neue_farbe); */
	document.location.href = 'warenkorb_aendern_' + warenkorb_id + '___' + neue_anzahl + '___' + escape(neue_groesse) + '___' + escape(neue_farbe);
}

function change_land(target_php) {
	neues_land = document['form_land'].land.value;
	document.location.href = 'landaendern_' + target_php + '_' + neues_land;
}


/* KASSE */
function datenformular_pruefen() {
	if(document.datenformular.vorname_l.value.length < 1 || document.datenformular.nachname_l.value.length < 1 || document.datenformular.strasse_l.value.length < 1 || document.datenformular.plz_l.value.length < 1 || document.datenformular.stadt_l.value.length < 1) {
		alert("Die Angaben der Versandadresse sind nicht vollstaendig.\nBitte ueberpruefen Sie nochmals Ihre Angaben.");
		return;
	}
	
	if(document.datenformular.vorname_r.value.length < 1 || document.datenformular.nachname_r.value.length < 1 || document.datenformular.strasse_r.value.length < 1 || document.datenformular.plz_r.value.length < 1 || document.datenformular.stadt_r.value.length < 1) {
		alert("Die Angaben der Rechnungsadresse sind nicht vollstaendig.\nBitte ueberpruefen Sie nochmals Ihre Angaben.");
		return;
	}
	
	if(document.datenformular.email.value.length < 1) {
		alert("Sie muessen eine gueltige Email-Adresse angeben.");
		return;
	}
	
	document.datenformular.submit();
	/*parent.mainframe.document.location.href = 'zusammenfassung.php?vorname_l=' + document.datenformular.vorname_l.value + '&nachname_l=' + document.datenformular.nachname_l.value + '&strasse_l=' + document.datenformular.strasse_l.value + '&plz_l=' + document.datenformular.plz_l.value + '&stadt_l=' + document.datenformular.stadt_l.value + '&land_l=' + document.datenformular.land_l.value + '&email=' + document.datenformular.email.value + '&telefon=' + document.datenformular.telefon.value + '&vorname_r=' + document.datenformular.vorname_r.value + '&nachname_r=' + document.datenformular.nachname_r.value + '&strasse_r=' + document.datenformular.strasse_r.value + '&plz_r=' + document.datenformular.plz_r.value + '&stadt_r=' + document.datenformular.stadt_r.value + '&land_r=' + document.datenformular.land_r.value + '&checked=' + document.datenformular.adress_check.checked + '&zahlmethode=' + document.datenformular.zahlmethode.value + '&geschenkverpackung=' + document.datenformular.geschenkverpackung.checked;*/
}

function adressengleich() {
	if (document.datenformular.adress_check.checked == true) {
		document.datenformular.vorname_r.value = document.datenformular.vorname_l.value;
		document.datenformular.nachname_r.value = document.datenformular.nachname_l.value;
		document.datenformular.strasse_r.value = document.datenformular.strasse_l.value;
		document.datenformular.plz_r.value = document.datenformular.plz_l.value;
		document.datenformular.stadt_r.value = document.datenformular.stadt_l.value;
		document.datenformular.land_r.value = document.datenformular.land_l.value;
	} else {
		document.datenformular.vorname_r.value = '';
		document.datenformular.nachname_r.value = '';
		document.datenformular.strasse_r.value = '';
		document.datenformular.plz_r.value = '';
		document.datenformular.stadt_r.value = '';
	}
}

function moveshippingaddress() {
	var array = new Array('firma', 'vorname', 'nachname', 'strasse', 'strasse_2', 'plz', 'stadt', 'land');
	
	var test = 2;
	for (var string in array) {
  		/* test += $('#' + array[string] + '_l').val(); */
  		
  		$('#' + array[string] + '_r').val($('#' + array[string] + '_l').val());
	}
	
	/* alert (test); */
}

function geschenkverpackung_aendern() {
	if (document.datenformular.geschenkverpackung.value == "nein") {
		document.datenformular.geschenkverpackung.value = "ja";
		document.getElementById('div_geschenkverpackung').style.display = "block";
	} else {
		document.datenformular.geschenkverpackung.value = "nein";
		document.getElementById('div_geschenkverpackung').style.display = "none";
	}
//	alert(document.datenformular.geschenkverpackung.value);
}

function newsletter_aendern() {
	if (document.datenformular.newsletter.value == "0") {
		document.datenformular.newsletter.value = "1";
	} else {
		document.datenformular.newsletter.value = "0";
	}
}

function div_einblenden(div_name) {
	if (document.getElementById(div_name).style.display == "block") {
		document.getElementById(div_name).style.display = "none";
	} else {
		document.getElementById(div_name).style.display = "block";
	}
}

function versand_pruefen() {
	if (document.datenformular.agb_check.checked == false) {
		alert("Sie muessen unsere AGB akzeptieren!");
		return;
	}
	
	document.datenformular.submit();
	/*parent.mainframe.document.location.href = 'bestellung_senden.php?fragen=' + document.datenformular.fragen.value + '&newsletter=' + document.datenformular.newsletter.value;*/
}

function toggle_object(id) {
	$("#" + id).toggle();
}

function showInfo(object, duration) {
	$('#' + object).css('top', $(window).height()/2-$('#' + object).height()/2); 
	$('#' + object).css('left', $(window).width()/2-$('#' + object).width()/2);
	
	$('#' + object).fadeIn('slow'); 
	setTimeout(function(){ 
		$('#' + object).fadeOut('slow'); 
	}, duration);
}

function show_hide_shopping_cart() {
	$('#warenkorb_short').slideToggle();
	$('#warenkorb_added').hide();
}


function add_to_shopping_cart(sid) {
	var article_id 			= $('#article_id').val();
	var article_quantity 	= $('#article_quantity').val();
	var article_size 			= $('#article_size').val();
	var article_color 		= $('#article_color').val();
	var article_sub 			= $('#article_sub').val();
	
	/* alert("article_id: " + article_id + "\narticle_quantity: " + article_quantity + "\narticle_size: " + article_size + "\narticle_color: " + article_color + "\nsid: " + sid); */
	
	$.ajax({
		url: "/_actions/add_to_shopping_cart.php",
		type: "POST",
		data: "ajax=1&sid=" + sid + "&id=" + article_id + "&anzahl=" + article_quantity + "&groesse=" + escape(article_size) + "&farbe=" + escape(article_color) + "&sub=" + escape(article_sub),
		evalScripts: true,
		
		success: function(response) {
		   var part = response.split("|||");
		   
		   /* alert (part[0]); */
		   $('#warenkorb_added_ajax').html(part[0]);
		   $('#warenkorb_navi').html(part[1]);
		   $('#warenkorb_short').html(part[2]);
		   /* alert(part[2]); */
		   
		   Cufon.replace('h3');
		},
		
		complete: function(){
			showInfo('warenkorb_added_ajax', 2500);
		}
	});
}

function setImagePreview_old(file_m, file_l, p_t, p_l, w, h) {
	$('#img_img_preview').attr("src", file_m);
	/* MagicZoom.refresh() */
	$('#zoom_img_preview').attr("href", file_l);
	$('#btn_zoomer').attr("href", file_l);
	$('#img_img_preview').css("width", w + 'px');
	$('#img_img_preview').css("height", h + 'px');
	$('#img_preview').css("padding-left", p_l + 'px');
	$('#img_preview').css("padding-top", p_t + 'px');
	$('#img_preview').css("width", Math.abs(250 - p_l) + 'px');
	$('#img_preview').css("height", Math.abs(250 - p_t) + 'px');
	
	Shadowbox.setup();
}

function setImagePreview(img_nr,count_images) {
	for (var i=0; i<count_images; i++) {
		if (i != img_nr) {
			$('#preview_' + i).fadeOut('fast');
		}
	}
	
	$('#preview_' + img_nr).fadeIn('slow');
	
}


function removeImagePreview() {
	
	/* $('#img_preview_canvas').html(""); */
	/* $('#img_preview_canvas').css("background", "none"); */
}