/* ++++++++++++++++++++++ jQuery ++++++++++++++++*/

jQuery(function($) {

	/* all link-tags add this attribut */
	//$("a").attr("onfocus","this.blur();");

	/* input-tags add this attribut */
	$('input[type=submit]').attr("onfocus","this.blur();");
	$('input[type=button]').attr("onfocus","this.blur();");
}); 

/* +++++++++++++ set the focus on the pages ++++++++++++++++++ */
function setfocus() {
	if (document.getElementById("kennzeichen1")!=null){
		document.getElementById("kennzeichen1").focus();
	}
	if (document.getElementById("noneurokennzeichen1")!=null){
		document.getElementById("noneurokennzeichen1").focus();
	}
}

/* +++++++++++++ merging individual kennzeichen inputs ++++++++++++++++++ */
function mergeinputs() {
	if( document.getElementById('kennzeichen1')!= null){
		var a = document.getElementById('kennzeichen1').value;
		var b = document.getElementById('kennzeichen2').value;
		var c = document.getElementById('kennzeichen3').value;
		document.getElementById('kennzeichen').value = a+" "+b+" "+c;
		document.getElementById('kennzeichen').value = document.getElementById('kennzeichen').value.toUpperCase(); 
		oxid.popup.load();
	}
	if( document.getElementById('noneurokennzeichen1')!= null){
		var a = document.getElementById('noneurokennzeichen1').value;
		var b = document.getElementById('noneurokennzeichen2').value;
		var c = document.getElementById('noneurokennzeichen3').value;
		document.getElementById('kennzeichen').value = a+" - "+b+" "+c;
		document.getElementById('kennzeichen').value = document.getElementById('kennzeichen').value.toUpperCase(); 
		oxid.popup.load();
	}
}

/* +++++++ Transforming inputs to uppercase +++++++ */
function UpperCase(x){
 document.getElementById(x).value = document.getElementById(x).value.toUpperCase();
}

/* +++++++ Leftside navigation search expanding +++++++ */
function expandsearch(){
  document.getElementById("f.search").style.height = "79px";
}

/* +++++++++++++ Header Fadings ++++++++++++++++++ */
// sets the fadings on/off
var isoff = 0;
function makeonoff() {
		isoff = 1;
	}		
	
var timerID = null;
var h = null;
var imove = null;		
function StartCounter() {
	if (document.getElementById ("newproductsouter")!=null){
		h = document.getElementById ("newproductsouter").offsetHeight;
		imove = h;
			if (timerID === null) { // to avoid multiple registration
				timerID = setInterval ("move()", 16000);
			}
		}
	}
	
var ifade = 0;
var i = 1;			
function move() {
		if (isoff == 0) {
			ifade = 0;		
			document.getElementById ("newproductsinner").style.opacity = "0";
			StartCounterFade();
			var containerheight = document.getElementById ("newproductsinner").offsetHeight;
			var imax = (containerheight/h);
			if (i < imax) {
				
				document.getElementById ("newproductsinner").style.top = "-"+imove+"px";
				imove = imove + h;
				i = i + 1;
			}else{
				document.getElementById ("newproductsinner").style.top = "0px";
				i = 1;
				imove = h; 
			}
		}
	}
	
var timerIDfade = null;
function StartCounterFade() {
	if (timerIDfade === null) { // to avoid multiple registration
		timerIDfade = setInterval ("fade ()", 85);
	}
}

function fade() {			
	if (ifade < 1.05){
		document.getElementById ("newproductsinner").style.opacity = ifade;
		ifade = ifade + 0.05;
	}
}

var timerID3 = null;
function StartCounter3() {
	if (timerID3 === null) { // to avoid multiple registration
		timerID3 = setInterval ("StartCounter2()", 225);
	}
}

var timerID2 = null;
var h2 = null;
var imove2 = null;		
function StartCounter2() {
	if (document.getElementById ("offerproductsouter")!=null){
		clearInterval (timerID3);
		h2 = document.getElementById ("offerproductsouter").offsetHeight;
		imove2 = h2;
		if (timerID2 === null) { // to avoid multiple registration
			timerID2 = setInterval ("move2()", 16000);
		}
	}
}

var ifade2 = 0;
var i2 = 1;			
function move2() {
	if (isoff == 0) {
		ifade2 = 0;		
		document.getElementById ("offerproductsinner").style.opacity = "0";
		StartCounterFade2();
		var containerheight2 = document.getElementById ("offerproductsinner").offsetHeight;
		var imax2 = (containerheight2/h2);
		if (i2 < imax2) {
			
			document.getElementById ("offerproductsinner").style.top = "-"+imove2+"px";
			imove2 = imove2 + h2;
			i2 = i2 + 1;
		}else{
			document.getElementById ("offerproductsinner").style.top = "0px";
			i2 = 1;
			imove2 = h2; 
		}
	}
}

var timerIDfade2 = null;
function StartCounterFade2() {
	if (timerIDfade2 === null) { // to avoid multiple registration
		timerIDfade2 = setInterval ("fade2 ()", 85);
	}
}

function fade2() {			
	if (ifade2 < 1.05){
		document.getElementById ("offerproductsinner").style.opacity = ifade2;
		ifade2 = ifade2 + 0.05;
	}
}

/* +++++++++++++ Header Popup ++++++++++++++++++ */
function openPopupTopNav()
{
	document.getElementById("topnavpopup").style.visibility="visible";
}
function closePopupTopNav()
{
	document.getElementById("topnavpopup").style.visibility="hidden";
}

/* +++++++++++++ Wallpaper previews; Park Profi++++++++++++++++++ */
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_showHideLayers() { //v6.0
  var i,p,v,obj,args=MM_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v=='hide')?'hidden':v; }
    obj.visibility=v; }
}

function MM_controlShockwave(objStr,x,cmdName,frameNum) { //v3.0
	var obj=MM_findObj(objStr);
	if (obj) eval('obj.'+cmdName+'('+((cmdName=='GotoFrame')?frameNum:'')+')');
}
/* +++++++++++++ Free Delivery ++++++++++++++++++ */
var freedelivery = 0;

/* +++++++++++++ Sets the active Link in the zoom image popup ++++++++++++++++++ */	
var isactive = "pic1";
var c1 = "#000000";
var c2 = "#1c587e";
var c3 = "#ededed";
function zoomImageActiveSLK(pic){
	if (document.getElementById("pic1")!=null){
		isactive = pic;
		x = document.getElementById("zoom");
		a = x.getElementsByTagName("a");
		for (i = 0; i < a.length; i++) {
			a[i].style.color = c3;
			a[i].style.backgroundColor = c1;
		}
		if (pic != null){
			document.getElementById(pic).style.backgroundColor = c2;
			document.getElementById(pic).style.color = c3;
		}else{
			document.getElementById("pic1").style.backgroundColor = c2;
			document.getElementById("pic1").style.color = c3;
		}
	}
}

/* +++++++++++++ Sets the Link hover in the zoom image popup ++++++++++++++++++ */
function zoomImageHoverInSLK(pic){
	if (document.getElementById("pic1")!=null){
		if (pic != isactive){
			if (isactive != null){
				isactive2 = isactive;
			}else{
				isactive2 = "pic1";
			}
			if (pic != "closepopup"){
				document.getElementById(isactive2).style.backgroundColor = c1;
				document.getElementById(isactive2).style.color = c3;
				document.getElementById(pic).style.backgroundColor = c2;
				document.getElementById(pic).style.color = c3;
			}else{
				document.getElementById(pic).style.backgroundColor = "#830000";
			}
		}
	}
}
function zoomImageHoverOutSLK(pic){
	if (document.getElementById("pic1")!=null){
		if (pic != isactive){
			if (isactive != null){
				isactive2 = isactive;
			}else{
				isactive2 = "pic1";
			}
			document.getElementById(pic).style.backgroundColor = c1;
			document.getElementById(pic).style.color = c3;
			document.getElementById(isactive2).style.backgroundColor = c2;
			document.getElementById(isactive2).style.color = c3;
		}
	}
}

/* +++++++++++++ changes values in saison text inputs ++++++++++++++++++ */
function startmonth (){
	document.getElementById("anfangsmonat").value = document.getElementById("datum1").value;
}
function endmonth (){
	document.getElementById("endmonat").value = document.getElementById("datum2").value;
}

/* +++++++++++++ changes values in saison text inputs ++++++++++++++++++ */
function showmoreinfo (){
	document.getElementById("wunschkenzeichenmoreinfo").className = "wunschkenzeichenmoreinfoisopen";
}
function closemoreinfo (){
	document.getElementById("wunschkenzeichenmoreinfo").className = "wunschkenzeichenmoreinfoisclosed";
}

/* +++++++++++++ More Infos Popup ++++++++++++++++++ */
var popupname = "";
function showmoreinfopopup (x){
	popupname = x;
	document.getElementById(x).style.display="block";
	document.getElementById("popupouter").style.display="block";
}
function closemoreinfopopup (){
	if (document.getElementById(popupname)!=null){
		document.getElementById(popupname).style.display="none";
		document.getElementById("popupouter").style.display="none";
	}
}
function printcontent(p){
	var WindowObject = window.open('', "printwindow", "toolbars=no,scrollbars=yes,status=no,resizable=no");
	WindowObject.document.writeln(document.getElementById(p).innerHTML);
	WindowObject.document.close();
	WindowObject.focus();
	WindowObject.print();
	WindowObject.close();
}

/* +++++++++++++ Changes Price when Variants are selected ++++++++++++++++++ */
var once = 0;
var pricehaschanged = 0;
function changeprice(x){
	if (once == 0){
		str1 = document.getElementById("priceinput").value;	
		str1 = str1.replace(",",".");
		num1 = parseFloat(str1);
		once = 1;
		
	}
	str2 = document.getElementById(x).value;
	i = str2.lastIndexOf("+");
	str2 = str2.slice(i+1);
	str2 = str2.replace(",",".");
	num2 = parseFloat(str2);
	if (num2 > 0){
		num2 = num1+num2;
		if (document.getElementById("texttoprint")!=null){					// displays the input for Wunschtext and color
			document.getElementById("texttoprint").style.display = "block";	//
			document.getElementById("texttoprintinput").focus();			//
			document.getElementById("printtext").value = document.getElementById("texttoprintinput").value;	// fils the printtext input		
			pricehaschanged = 1;
		}
	}else{
		num2 = num1;	
		if (document.getElementById("texttoprint")!=null){					// hides the input for Wunschtext and color						
			document.getElementById("texttoprint").style.display = "none";	//
			document.getElementById("printtext").value = "";				// clears the printtext	input		
			pricehaschanged = 0;
		}
	}
	num2 = num2.toFixed(2);
	num2 = num2.toString()
	num2 = num2.replace(".",",");
	document.getElementById("priceinput").value = num2;
}

function changeprice2 (x, y) {
	document.getElementById(x).value=y;
}

/* +++++++++++++ Kennzeichenhalter Aufdruck ++++++++++++++++++ */
function texttoprintonplate(x){
	document.getElementById("printtext").value = x;
	texttoprintinputvalue = x;
}
function changecolor(x){
	document.getElementById("printtext").className = x;
}
function setwithptint(){
	if (pricehaschanged == 1){
		for (var i=0; document.withoptions.farbe[i]!=null; i++) {
			if (document.withoptions.farbe[i].checked == true)	{
				printcolor = document.withoptions.farbe[i].value;
			} 
		}
		document.getElementById("printtext").value = "";
		document.forms["withoptions"].elements["persparam[Farbe]"].value = printcolor;
	}else{
		document.forms["withoptions"].elements["persparam[Farbe]"].value = "";
		document.forms["withoptions"].elements["persparam[mit Aufdruck]"].value = "";
	}
	document.forms["withoptions"].submit();
}

function dontshowtexttoprint(x){
	if (pricehaschanged == 1){	
		if (x=="test_MorePics_1"||x=="test_MorePics_3"||x=="test_MorePics_4"){								
			document.getElementById("printtext").style.display = "block";	// shows the input for Wunschtext and color	
		}else{
			document.getElementById("printtext").style.display = "none";  // hides the input for Wunschtext and color			
		}	
	}
}

/* +++++++++++++ Socialnetwork under left navigation  ++++++++++++++++++ */
var facebookleft = 0;
function setsocialnetworkleft(){
	if (facebookleft == 1){
		document.getElementById("socialnetworkleft").className  = "socialnetworkall";	// show bigger container
		document.getElementById("facebooklike").style.display = "block";				// show Facebook button
		document.getElementById("tweet").style.display = "block";						// show Tweet button
	}
}

/* +++++++++++++ Freedelivery on  ++++++++++++++++++ */
function freedeliveryon(){
	document.getElementById("freedelivery").style.display = "block";	// shows freedelivery
	document.getElementById("nonfreedelivery").style.display = "none";	// hides nonfreedelivery
}
