var addthis_config = {
	ui_language : "DEU"
}

var wT;
var hT;
var xT;
var navElement;
var navStatus = false;

var dseperator = ",";
var tseperator = "";
var currency = "€";

var total_national = 0;
var total_international = 0;
var total_logo = 0;
var total_top10 = 0;
var total_pr = 0;
var total_calced = 0;

var total_rabatt = 0;

var each_national = 0;
var each_international = 0;
var each_logo = 0;
var each_top10 = 0;
var each_pr = 0;
var basis_init = parseFloat(89.00);

var intoninit = false;

/* Error Messages */
var international_placement = "Wenn Sie eine internationale Platzierung wünschen, müssen Sie mindestens eine bundesweite Platzierung auswählen.";
var pickacat = "Bitte wählen Sie mindestens eine Kategorie aus - Dieses Feld wird dann automatisch aktiviert.";
var deleteConfirmMessage = "Möchten Sie diesen Eintrag wirklich löschen?";
var deleteNoMessage = 'Um Ihren Brancheneintrag zu entfernen, kontaktieren Sie bitte die\nKundenbetreuung per E-Mail unter info@solarserver.de Betreff\n"Brancheneintrag". Vielen Dank!';
var deleteNoMessageUser = 'Um Ihr Benutzerkonto zu löschen, kontaktieren Sie bitte die\nKundenbetreuung per E-Mail unter info@solarserver.de Betreff\n"Benutzerkonto". Vielen Dank!';
var filetypeerror = "Bitte prüfen Sie Ihr Dateiformat.";
var plzerrorMessage = "Bitte geben Sie eine gültige Postleitzahl an.";
var phoneerrorMessage = "Bitte geben Sie eine reguläre Telefonnummer an.";
var checkerrorsplease = "Bitte füllen Sie alle Felder vollständig aus."
var emtpy = "Bitte füllen Sie mindestens eines der beiden rot markierten Felder aus.";
var passwordLength = "Ihr Passwort muss mindestens 5 Zeichen lang sein!";

var curplzl = 5;
var checkplznum = true;
var haserror = false;
$().ready(function() {
	/* Check for required fields before submit */
	if ($(".reqField").length > 0) {
		$(formtocheck + " form").submit(function() {
			var error = true;
			$(".reqField input").each(function() {
				if ($(this).val() == "" && error != false) {
					error = true;
				} else {
					error = false;
				}
			});
			if (error == true) {
				$(".reqField input").parent().prev().addClass("errormessage");
				alert(emtpy);
				return false;
			}
		});
	}
	
	/* Fehlercheck der Postleitzahl */
	if ($("#zipchecker").length > 0) {
		$("#zipchecker, #countrypicker").change(function() {
			checkforplz();
		});
	}
	if($(".phonechecker").length > 0){
		$(".phonechecker").change(function() {
			if($(this).val()!=""){
				if (!checkphone($(this).val())) {
					if ($(this).parent().find(".perror").length < 1) {
						$(this).parent().prepend('<p class="errormessage perror">' + phoneerrorMessage + '</p>');
						haserror = true;
					}
				} else {
					if ($(this).parent().find(".perror").length > 0) {
						$(this).parent().find(".perror").remove();
						haserror = false;
					}
				}
			} else {
				if ($(this).parent().find(".perror").length > 0) {
					$(this).parent().find(".perror").remove();
					haserror = false;
				}
			}
		});
		$("input[type=image]").click(function(){
			if(!haserror){
				return true;
			}else{
				alert(checkerrorsplease);
				return false;
			}
		});
	}
	/* Printfunktion */
	$(".link_print").click(function() {
		print();
		return false;
	});

	/* PayPal Trick... */
	if ($(".p_paypal").length > 0) {
		$("#paypal,#kreditkarte,#rechnung,#lastschrift").change(function() {
			if ($("#paypal").attr("checked") == true) {
				$(".submitbezahlen").hide();
				$(".p_paypal").show();
			} else {
				$(".submitbezahlen").show();
				$(".p_paypal").hide();
			}
		});
		$(".p_paypal").click(function() {
			$("form.bvz").submit();
		});
	}

	if ($("#tx-srfeuserregister-pi1-password").length > 0) {
		$("#tx-srfeuserregister-pi1-fe_users_form").submit(function() {
			if (($("#tx-srfeuserregister-pi1-password").val()).length < 5 && ($("#tx-srfeuserregister-pi1-password").val()).length > 0) {
				if ($("#passworderror").length < 1 && $(".tx-srfeuserregister-pi1-trash").length < 1) {
					$(".csc-bulletlist:first").append('<li class="errormessage" id="passworderror">' + passwordLength + '</li>');
				} else {
					if ($("#passworderror").length < 1) {
						$(".tx-srfeuserregister-pi1-trash").parent().append('<p class="errormessage" id="passworderror">' + passwordLength + '</p>');
					}
				}
				return false;
			}
			return true;
		});
	}

	/* Filter Funktionen */
	if ($("#filtermethod").length > 0) {
		$(".selectMonth").change(function() {
			if ($(".selectYear option:selected").val() == "") {
				$(".selectYear option:selected").next().attr("selected", true);
			}
		});
		$(".selectYear").change(function() {
			if ($(".selectMonth option:selected").val() == "") {
				$(".selectMonth option:selected").next().attr("selected", true);
			}
		});
		$("#filtermethod").submit(function() {
			var cat = "";
			if ($(".leftsub .orange").length > 0) {
				cat = "." + $(".leftsub .orange").attr("rel");
			}
			$("#filter_hash").val(filterhash[$(".selectYear option:selected").val() + "." + $(".selectMonth option:selected").val() + cat]);
		});
	}

	if ($("#filtermethodPr").length > 0) {
		$(".selectMonth").change(function() {
			if ($(".selectYear option:selected").val() == "") {
				$(".selectYear option:selected").next().attr("selected", true);
			}
		});
		$(".selectYear").change(function() {
			if ($(".selectMonth option:selected").val() == "") {
				$(".selectMonth option:selected").next().attr("selected", true);
			}
		});
	}

	/* Navigation */
	if ($(".nav").length > 0) {
		$("li.nav").mouseover(function() {
			window.clearTimeout(xT);
			window.clearTimeout(wT);
			navElement = $(this);

			if (navStatus == true) {
				hideNavi();
				$(this).find("a").addClass("hover");
				if ($(this).find(".subs").length > 0) {
					$(this).find(".subs").removeClass("hide");
				}
			} else {
				hT = setTimeout("showNavi()", 500);
			}
		});
		$(".nav").mouseleave(function() {
			window.clearTimeout(hT);
			xT = setTimeout("resetNavi()", 500);
			if (navStatus == true) {
				wT = setTimeout("hideNavi()", 500);
			}
		});
	}

	/* Topicpage Header Images */
	if ($(".t_cols").length > 0) {
		$(".t_cols").css("opacity", 0.6);
	}

	if ($(".t_area").length > 0) {
		$(".t_area").css("opacity", 0.7);
	}

	/* Table Highlighting */
	if (($(".cel1").length > 0) || ($(".cel2").length > 0)) {
		$(".cel1, .cel2, .cel3").hover(function() {
			$("." + $(this).attr("rel")).addClass("celHover");
			$(this).parent().parent().find(".pricecell").parent().addClass("rowHover");
		}, function() {
			$("." + $(this).attr("rel")).removeClass("celHover");
			$(this).parent().parent().find(".pricecell").parent().removeClass("rowHover");
		});
	}

	/* Topic Container */
	if ($(".rela").length > 0) {
		if ($(".rela").text() == "") {
			$(".rela").remove();
		}
	}

	/* Price Calculation And Requirements */
	if ($(".require_national").length > 0) {
		var cktest = document.cookie;
		var curpage = window.location.href;

		var gg = new Date();
		var gend = gg.getTime() + (360 * 24 * 60 * 60);
		gg.setTime(gend);

		if ($("#nocalc").length > 0) {
			if (cktest.match("intoninit=false") != null) {
				intoninit = false;
			} else {
				if (cktest.match("intoninit=true") != null) {
					intoninit = true;
				} else {
					if ($(".require_international").attr("disabled") == true) {
						intoninit = true;
						document.cookie = "intoninit=true; expires=" + gg.toGMTString();
					} else {
						document.cookie = "intoninit=false; expires=" + gg.toGMTString();
					}
				}
			}
		}

		/* Init Values */
		each_national = parseFloat($(".price_national").text());
		each_international = parseFloat($(".price_international").text());
		each_logo = parseFloat($(".price_logoplacement").text());
		each_top10 = parseFloat($(".price_top10placement").text());
		each_pr = parseFloat($(".price_press").text());

		initPrice();

		/* Placement Germany */
		$(".count_national").change(function() {
			if ($(".count_national:checked").length > 0) {
				if ($(".require_national:checked").length < 1) {
					$(".require_national").attr("disabled", false);
					$(".require_national").attr("checked", true);
				}
				total_national = each_national * $(".count_national:checked").not(".itsfree").length;
			} else {
				if ($(".require_national:checked").length > 0) {
					$(".require_national").attr("checked", false);
				} else {
					$(".count_national").attr("disabled", false);
				}
				total_national = 0;
			}
			checkInternational();
			sumPrice();
		});

		/* Logo Upload */
		if ($("#nocalc").length < 1) {
			$(".require_logo").attr("disabled", false);
		}
		$(".require_logo").change(function() {
			if ($(".require_logo").attr("checked") == true) {
				total_logo = each_logo;
				$(".count_logoplacement").attr("disabled", false);
			} else {
				total_logo = 0;
				$(".count_logoplacement").attr("disabled", true);
			}

			sumPrice();
		});

		/* Top 10 Placement */
		$(".count_top10placement").change(function() {
			if ($(".count_top10placement:checked").length > 0) {
				total_top10 = each_top10;
			} else {
				total_top10 = 0;
			}

			sumPrice();
		});

		/* Press Releases */
		$(".count_press").change(function() {
			if ($(".count_press:checked").length > 0) {
				total_pr = each_pr;
			} else {
				total_pr = 0;
			}

			sumPrice();
		});

		/* Off the record .. */
		$(".require_national").change(function() {
			if ($(".require_national:checked").length < 1) {
				$(".count_national").attr("checked", false);
				checkInternational();
			}
			checkInternational();
			sumPrice();
		});

		$(".require_international").change(function() {
			if ($(".count_international:checked").length < 1) {
				$(".require_international").attr("checked", false);
				alert(pickacat);
				return false;
			} else {
				checkInternational();
			}
			checkInternational();
			sumPrice();
		});
	}

	/* Anordnung Boxen BVZ Detailansicht */
	if ($(".tx-essollocationdetail-pi1").length > 0) {
		$(".main .box").not(".rightCol .box, .w560 .box, .main .box .box").each(function() {
			$(this).appendTo(".rightCol");
		});
	}
	$(".i_search").focus(function() {
		if (($(this).val() == "Suchbegriff") || ($(this).val() == "Keyword")) {
			$(this).val("");
		}
	});

	if ($("#top").height() < $(window).height()) {
		$("#top").height($(window).height());
	}

	/* Width for Maincol */
	if ($(".tx-essollocationdetail-pi1").length < 1) {
		$(".main").width(870 - $(".leftCol").width() - $(".rightCol").width());
	}

	/* Solaranlage Online Berechnen ... */
	if ($("#blackpearl").length > 0) {
		$(".rightCol").remove();
		$(".main").width("715px");
	}

	/* Delete?! */
	if ($(".delete").length > 0) {
		if ($(".nodelete").length > 0) {
			$(".delete").attr("href", "#false");
			$(".delete").click(function() {
				alert(deleteNoMessage);
				return false;
			});
		} else {
			$(".delete").click(function() {
				if (confirm(deleteConfirmMessage)) {
					return true;
				} else {
					return false;
				}
			});
		}
	}
	
	if($(".tx-srfeuserregister-pi1-trash").length > 0) {
		$(".tx-srfeuserregister-pi1-trash a").attr("href", "#false")
		$(".tx-srfeuserregister-pi1-trash a").click(function() {
			alert(deleteNoMessageUser);
			return false;
		});
	}

	/* HTTP Val checken bei Form submit */
	if ($(".httpval").length > 0) {
		$("form").submit(function() {
			$(".httpval").each(function() {
				if ($(this).val() == "http://") {
					$(this).val("");
				}
			});
		});
	}

	/* Filecheck bei Submit form */
	if ($(".filecheck").length > 0) {
		$("form").submit(function() {
			var imageerror = false;
			var texterror = false;
			$(".filecheck").each(function() {
				if ($(this).val() != "") {
					var string = $(this).val();
					var filetocheck = string.split(".");
					if ($(this).attr("accept") == "text/*") {
						if ((!filetocheck[filetocheck.length - 1].toLowerCase() == "pdf") || (!filetocheck[filetocheck.length - 1].toLowerCase() == "doc")) {
							texterror = true;
							$(this).parent().prev().addClass("errormessage");
						}
					} else {
						if ((filetocheck[filetocheck.length - 1].toLowerCase() != "jpg") && (filetocheck[filetocheck.length - 1].toLowerCase() != "jpeg") && (filetocheck[filetocheck.length - 1].toLowerCase() != "gif") && (filetocheck[filetocheck.length - 1].toLowerCase() != "png")) {
							imageerror = true;
							$(this).parent().prev().addClass("errormessage");
						}
					}
				}
			});
			if (imageerror == true || texterror == true) {
				alert(filetypeerror);
				return false;
			}
		});
	}
	if($(".tx-felogin-pi1").length > 0) {
		if($(".tx-felogin-pi1 h3").text() == ""){
			$(".tx-felogin-pi1 h3").remove()
		}
	}
	/*
	 * Stop country from changing if readonly
	if($("select.readonly").length > 0) {
		$("select.readonly").click(function(event){
			event.preventDefault();
			return false;
		});
		$("select.readonly").change(function(event){
			event.preventDefault();
			return false;
		});
	}
	*/
});

/* Price Calculator */
function initPrice() {

	total_national = each_national * $(".count_national:checked").not(".itsfree").length;
	total_international = each_international * $(".count_international:checked").not(".itsfree").length;

	if ($(".require_logo").attr("checked") == true) {
		total_logo = each_logo;
		$(".count_logoplacement").attr("disabled", false);
	} else {
		total_logo = 0;
		$(".count_logoplacement").attr("disabled", true);
	}

	if ($(".count_top10placement:checked").length > 0) {
		total_top10 = each_top10;
	} else {
		total_top10 = 0;
	}

	if ($(".require_logo:checked").length > 0) {
		total_logo = each_logo;
	}

	if ($(".count_press:checked").length > 0) {
		total_pr = each_pr;
	} else {
		total_pr = 0;
	}
	checkInternational();
	sumPrice();
}

function sumPrice() {
	//alert(total_logo);
		
	if ($(".require_national:checked").length < 1) {
		total_national = 0;
	}
	
	if (($(".require_national:checked").length > 0) && ($(".require_logo:checked").length)) {
		var logoint = total_logo * $(".count_international:checked").length;
	} else {
		var logoint = 0;
	}

	if (($(".require_international:checked").length > 0) && ($(".require_logo:checked").length)) {
		var logonat = total_logo * $(".count_national:checked").length;
	} else {
		var logonat = 0;
	}

	total_calced = (total_national + total_international + total_logo + total_top10 + total_pr + basis_init + parseFloat(logoint) + parseFloat(logonat));

	if (( ($(".require_national:checked").length > 0) && ($(".count_national:checked").not(".itsfree").length > 1) && ($(".require_logo:checked").length > 0) ) || ( ($(".require_national:checked").length > 0) && ($(".count_national:checked").not(".itsfree").length > 0) && ($(".require_international:checked").length > 0) && ($(".require_logo:checked").length > 0) )){
		total_rabatt = total_calced * 0.2;
		total_calced = total_calced * 0.8;
	} else {
		total_rabatt = "0.00";
	}
	$(".total_price").text(plocale(total_calced));
	$(".total_rabatt").text(plocale(total_rabatt));
}

function plocale(value) {
	value = Math.round(value * 100) / 100;

	value = "" + value;
	var valarr = value.split(".");

	if (valarr.length < 2) {
		valarr[1] = "00";
	}
	if (valarr[1].length < 2) {
		valarr[1] = valarr[1] + "0";
	}

	val = '' + valarr[0];
	if (val.length > 3) {
		var mod = val.length % 3;
		var output = (mod > 0 ? (val.substring(0, mod)) : '');
		for (i = 0; i < Math.floor(val.length / 3); i++) {
			if ((mod == 0) && (i == 0))
				output += val.substring(mod + 3 * i, mod + 3 * i + 3);
			else
				output += tseperator + val.substring(mod + 3 * i, mod + 3 * i + 3);
		}
		return output + dseperator + valarr[1];
	} else {
		return val + dseperator + valarr[1];
	}
}

function checkInternational() {

	$(".count_international").attr("disabled", true);

	if ($(".count_national:checked").length > 0) {

		if ($(".require_national:checked").length > 0 && intoninit == false) {
			$(".require_international").attr("disabled", false);
		}

		$(".count_national").each(function() {
			if ($(this).attr("checked") == true) {
				$("." + $(this).attr("rel")).attr("checked", true);
			} else {
				$("." + $(this).attr("rel")).attr("checked", false);
			}
		});
	} else {
		$(".count_international").attr("checked", false);
		$(".require_international").attr("checked", false);
		$(".require_international").attr("disabled", true);
	}

	if ($(".require_international:checked").length > 0) {
		total_international = each_international * $(".count_national:checked").not(".itsfree").length;
	} else {
		total_international = 0.00;
	}
}

/* Navigation */
function hideNavi() {
	$(".subs").addClass("hide");
	$(".nav a").removeClass("hover");
}

function showNavi() {
	navStatus = true;

	hideNavi();

	$(navElement).find("a").addClass("hover");
	if ($(navElement).find(".subs").length > 0) {
		$(navElement).find(".subs").removeClass("hide");
	}
}

function resetNavi() {
	window.clearTimeout(hT);
	navStatus = false;
}

sas_tmstp = Math.round(Math.random() * 10000000000);
sas_masterflag = 1;
function SmartAdServer(sas_pageid, sas_formatid, sas_target) {
	if (sas_masterflag == 1) {
		sas_masterflag = 0;
		sas_master = 'M';
	} else {
		sas_master = 'S';
	}
	;
	document.write('<scr' + 'ipt src="http://www3.smartadserver.com/call/pubj/' + sas_pageid + '/' + sas_formatid + '/' + sas_master + '/' + sas_tmstp + '/' + escape(sas_target) + '?"></scr' + 'ipt>');
}

function checkforplz() {
	if($("#countrypicker").val()==54){
		curplzl = 5;
		checkplznum = true;
	}else{
		if($("#countrypicker").val()==41 || $("#countrypicker").val()==13){
			curplzl = 4;
			checkplznum = true;
		}else{
			curplzl = 10;
			checkplznum = false;
			if ($("#plzerror").length > 0) {
				$("#plzerror").remove();
			}
		}
	}
	if(checkplznum == true) {
		var objRegExp  = /(^-?\d\d*$)/;
		
		if (!(objRegExp.test($("#zipchecker").val())) || ($("#zipchecker").val().length != curplzl)) {
			if ($("#plzerror").length < 1) {
				$("#zipchecker").parent().prepend('<p class="errormessage" id="plzerror">' + plzerrorMessage + '</p>');
				haserror = true;
			}
		} else {
			if ($("#plzerror").length > 0) {
				$("#plzerror").remove();
				haserror = false;
			}
		}
	}
}

function checkphone(val) {
	var phonechecker = true;
	
	//var objRegExp1 = /(\d\d*)(\-*)(\+*)(\/*)$/;
	//var objRegExp1 = /(^\+?)(\+?)(\d*)(\(*\d*\)*)(\d*\/*\d*\-*\d*)$/;
	var objRegExp1 = /(^[\-\+\(\)\/\+\s\d]*$)/;
	if(!objRegExp1.test(val)) {
		phonechecker = false;
	}
	
	return phonechecker;
}

















