var activeTab = 'tabCont1';
var animationWorking = true;


/////// show & hide layer ///////////////////////////////////////
var aktiveDrop = false;
var dropOpen = false;
var lastClick = false;

function  hideLayer(Layer){
    jQuery('#'+Layer).hide();
    jQuery('#'+Layer).css("display", "none");
}
function  showLayer(Layer){
    jQuery('#'+Layer).show();
    jQuery('#'+Layer).css("display", "block");
	jQuery('#'+Layer).css('position','relative').css('position','absolute');
}

function hideInfoRowLayer(Layer) {
    jQuery('#'+Layer).hide();
    jQuery('#'+Layer).css("display", "none");
    jQuery('#'+Layer).closest('.zusatzpaketeShopRow').removeClass('changeOrder');
}

function showInfoRowLayer(Layer) {
    jQuery('#'+Layer).show();
    jQuery('#'+Layer).css("display", "block");
    jQuery('#'+Layer).closest('.zusatzpaketeShopRow').addClass('changeOrder');
}


jQuery(document).ready(function() {

jQuery('.chkEMail').keyup(function () {
$parts = $(this).val().split('@');
if($parts.length > 2) {
alert('E-Mail Adresse nicht Korrekt!');
$(this).focus();
} 
});

jQuery('.chkEMail').blur(function () {
$parts = $(this).val().split('@');
if($parts[1].indexOf('.') == '-1') {
alert('E-Mail Adresse nicht Korrekt!');
$(this).focus();
}
});


if(jQuery(document).height() < jQuery(window).height()) {
jQuery('#page').height(jQuery(window).height())
}

var forms = ['loginLayerForm','loginLayerFormLayer'];


        jQuery('input','#loginLayerForm').keydown(function(e){
        if (e.keyCode == 13) {
            jQuery(this).parents('form').submit();
            return false;
        }
    });

jQuery('input','#loginLayerFormLayer').keydown(function(e){
        if (e.keyCode == 13) {
            jQuery(this).parents('form').submit();
            return false;
        }
    });




jQuery('#searchbuttonclick').click(function (){
	jQuery('#searchform').submit();
});

jQuery('.textSliders').click(function (){
	jQuery('.textSliderHidden', this).toggle('slow');
	jQuery('.sliderPlus', this).toggle('fast');
	jQuery('.sliderMinus', this).toggle('fast');	
});

jQuery("[csswidth]").each(function (i,e) {
		jQuery(e).css('width',jQuery(e).attr('csswidth')+'px');
	});
	
	jQuery('.tmalogin').click(function () {
		jQuery('#loginLayer').toggle();
	});

jQuery('.loginMenu').click(function () {
		jQuery('#loginLayer').toggle();
	});

jQuery('.megadrop').hide();
jQuery('.autohide').hide();
jQuery('.autoHide').hide();

/*Var def*/
	var loginAbdecker = jQuery('.loginLayerDecker');
    var loginLayerBox = jQuery('.loginLayerBox');
    var dH = jQuery(document).height();
    var dW = jQuery(document).width();
    var vpW = jQuery(window).width();
    var vpH = jQuery(window).height();
    var scrollpos = jQuery("html").scrollTop();

/*Var def ende*/

jQuery('.zusatzpaketeRow').each(function (i,e) {
	jQuery(e).click(function (ev) {
		ev.preventDefault();
		jQuery('a.innerLink',e).each(function (id,f) {
			if(id == 0)
				window.location.href = jQuery(f).attr('href');
		});
	});
});

var zusatzboxNames = [];


/*zusatzpakete funktionen*/
jQuery('.zusatzpaketebox').each(function (i,e) {
		var $name = jQuery(e).attr('groupname');
		if(jQuery.inArray($name, zusatzboxNames) == '-1' && $name != ''){
			jQuery('<input type="checkbox" checked="checked" value="'+$name+'" name="" class="filterCheckbox">'+$name+'<br />').appendTo('.filterRow');
			zusatzboxNames.push($name);
		}
	});	
	
	jQuery('#zusatzpaketeAnzeigenBtn').click(function() {
		$gocheck = false;
		
		jQuery('.filterRow input').each(function (i,e) {
			if(jQuery(e).is(':checked')) {
				$gocheck = true;
			} 	
		});
		
		if(!$gocheck) {
			jQuery(lastClick).checked = true;
		}
		
		jQuery('.filterRow input').each(function (i,e) {
			if($gocheck) {
				aktElm = jQuery('.zusatzpaketebox')[i];
				aktElmEnd = jQuery('.zusatzpaketebox_u')[i];
				$attrib = jQuery(e).val();
				if(jQuery(e).is(':checked')) {
					jQuery('div[groupname]').each(function (f,g) {
						if(jQuery(g).attr('groupname') == $attrib)
							jQuery(g).fadeIn('fast');
					});
				} else {
					jQuery('div[groupname]').each(function (f,g) {
						if(jQuery(g).attr('groupname') == $attrib)
							jQuery(g).fadeOut('fast');
						
					});
				}
			} 
		});
	});
	
	jQuery('.filterRow input').click(function () {
		jQuery('#zusatzpaketeAnzeigenBtn').trigger('click');
		lastClick = this;
	});

/*zusatzpakete funktionen ende*/

/*loginlayer*/
	loginAbdecker.hide();
    loginLayerBox.hide();
	
	jQuery('.loginLayerClick').click(function (e) {
        e.preventDefault();
		
		if(jQuery(this).attr('href') != '#'){
			$newUrl = jQuery(this).attr('href');
			if($newUrl.indexOf('http://') == -1) {
				$newUrl = 'https://passwort.t-mobile.at/ssomd/login.html?redirect_to='+escape('https://mein.t-mobile.at/myTNT/application.html?no_timeout=1&shortcut='+$newUrl);
			}
			jQuery('#loginLayerFormLayer').attr('action',$newUrl);
			jQuery('#loginRedirUrl').val($newUrl)
		}
        
        jQuery.post('/class/loginlayer.php', {'check':'1'}, function(d) {
            
            if(d == 'false') {
                loginAbdecker.show();
                loginLayerBox.show();

                jQuery(loginAbdecker).fadeTo(1,.3);
				scrollpos = jQuery(window).scrollTop();
                var bLeft = Math.floor((vpW-jQuery(loginLayerBox).width())/2);
                var bTop = Math.floor((vpH-jQuery(loginLayerBox).height())/2);

                jQuery(loginLayerBox).css({'left':bLeft+'px', 'top':(bTop+scrollpos)+'px'});        

                loginAbdecker.height(dH);
                loginAbdecker.width(dW); 
            } else {
				
				location.href = jQuery('#loginRedirUrl').val();
					
            }
        });
    });
    
    jQuery(loginAbdecker).click(function (e) {
        e.preventDefault();
        loginAbdecker.hide();
        loginLayerBox.hide();
    });
    
    jQuery('.loginLayerClose').click(function (e) {
        e.preventDefault();
        loginAbdecker.hide();
        loginLayerBox.hide();
    });
    
    jQuery('#loginLayerSubmit').click(function (e) {
        e.preventDefault();
        if(jQuery('#loginLayerRufNummer').val() != '' && jQuery('#loginLayerKennwort').val() != '') {
            jQuery('#loginLayerFormLayer').submit();
        }
    });
	
/*loginlayer ende*/

/*Google Tracking */

jQuery('a.gTTrigger').click(function(){
		_gaq.push(['_trackEvent', jQuery(this).attr('name'), jQuery(this).attr('alt'), jQuery(this).attr('title')]);
});


jQuery('ul.hauptnav li a').click(function (e) {
	e.preventDefault();
});

 jQuery('ul.hauptnav li').click(function (e) {
		e.stopPropagation();
		if(animationWorking) {
			animationWorking = false;
			
			var drop = jQuery(this).attr('drop');
			var liElm = jQuery(this);
			  
			jQuery('.megadrop').fadeOut('fast');
			
			jQuery('#'+drop).fadeIn('fast', function () { 
				animationWorking = true; 
				jQuery('ul.hauptnav li').removeClass('active');
				jQuery(liElm).addClass('active');
			});
			
			aktiveDrop = drop;
			dropOpen = true;

		}

	});
	
	jQuery(document).click(function() {
		if(animationWorking) {
			jQuery('.megadrop').fadeOut('fast', function () { 
				jQuery('ul.hauptnav li').removeClass('active');
			});
			
			dropOpen = false;
			aktiveDrop = false;
		}

	});
 
	 
	// TOGGLE //
	jQuery(".rechtstext_content").hide();

	jQuery(".rechtstext h5").click(function(){
		jQuery(this).toggleClass("active").next().slideToggle("slow");
	});

	
	jQuery('.tabContent').each(function (i,e) {
		if(i != 0) {
			jQuery(e).hide();	
		}
	});
	
	jQuery('.contentTabs > li > a').each(function (i,e) {
		jQuery(e).parents("li").click(function () {
			var tabclicked = jQuery(e).attr('tab');
			jQuery('#'+activeTab).hide();
			jQuery('#'+tabclicked).show();
			activeTab = tabclicked;
			jQuery('.contentTabs > li').removeClass('selected');
			jQuery(this).addClass('selected');
		});
	});
	
if(window.location.hash.indexOf('tab')) {
		var idx = window.location.hash.replace('#tab','');
	    if(idx != '') {
			jQuery('.contentTabs > li').each(function (i, e){
				if(i == (idx-1)) {
					jQuery(e).trigger('click');
				}
			});
	    }
		
	}
	
if (jQuery.browser.msie && jQuery.browser.version.substr(0,1)<7) {
	$altString = '<div class="supportIE6">Der von Ihnen verwendete Browser wird nicht mehr unterstützt. Für eine optimale Darstellung des Inhalts empfehlen wir ein Update auf einen der <a href="http://www.browserchoice.eu/BrowserChoice/browserchoice_de.htm" target="_blank">Folgenden Browser</a>.</div>';
	jQuery('body').prepend($altString);
}	

if(jQuery('#page').height() < jQuery(window).height()) {
	jQuery('#page').height(jQuery(window).height()-67)
}

});


var Globals={initialize:function(){Custom.init();}}
window.onload=Globals.initialize;var checkboxHeight="19";var radioHeight="19";var selectWidth="";document.write('<style type="text/css">input.styled { display: none; } select.styled { position: relative; width: '+selectWidth+'px; height:23px; margin-bottom:5px; opacity: 0; filter: alpha(opacity=0); z-index: 5; }</style>');var Custom={init:function(){var inputs=document.getElementsByTagName("input"),span=Array(),textnode,option,active;for(a=0;a<inputs.length;a++){if((inputs[a].type=="checkbox"||inputs[a].type=="radio")&&inputs[a].className=="styled"){span[a]=document.createElement("span");span[a].className=inputs[a].type;if(inputs[a].checked==true){if(inputs[a].type=="checkbox"){position="0 -"+(checkboxHeight*2)+"px";span[a].style.backgroundPosition=position;}else{position="0 -"+(radioHeight*2)+"px";span[a].style.backgroundPosition=position;}}
inputs[a].parentNode.insertBefore(span[a],inputs[a]);inputs[a].onchange=Custom.clear;span[a].onmousedown=Custom.pushed;span[a].onmouseup=Custom.check;document.onmouseup=Custom.clear;}}
inputs=document.getElementsByTagName("select");for(a=0;a<inputs.length;a++){if(inputs[a].className=="styled"){option=inputs[a].getElementsByTagName("option");active=option[0].childNodes[0].nodeValue;textnode=document.createTextNode(active);for(b=0;b<option.length;b++){if(option[b].selected==true){textnode=document.createTextNode(option[b].childNodes[0].nodeValue);}}
span[a]=document.createElement("span");span[a].className="select";span[a].id="select"+inputs[a].name;span[a].appendChild(textnode);inputs[a].parentNode.insertBefore(span[a],inputs[a]);inputs[a].onchange=Custom.choose;}}},pushed:function(){element=this.nextSibling;if(element.checked==true&&element.type=="checkbox"){this.style.backgroundPosition="0 -"+checkboxHeight*3+"px";}else if(element.checked==true&&element.type=="radio"){this.style.backgroundPosition="0 -"+radioHeight*3+"px";}else if(element.checked!=true&&element.type=="checkbox"){this.style.backgroundPosition="0 -"+checkboxHeight+"px";}else{this.style.backgroundPosition="0 -"+radioHeight+"px";}},check:function(){element=this.nextSibling;if(element.checked==true&&element.type=="checkbox"){this.style.backgroundPosition="0 0";element.checked=false;}else{if(element.type=="checkbox"){this.style.backgroundPosition="0 -"+checkboxHeight*2+"px";}else{this.style.backgroundPosition="0 -"+radioHeight*2+"px";group=this.nextSibling.name;inputs=document.getElementsByTagName("input");for(a=0;a<inputs.length;a++){if(inputs[a].name==group&&inputs[a]!=this.nextSibling){inputs[a].previousSibling.style.backgroundPosition="0 0";}}}
element.checked=true;}},clear:function(){inputs=document.getElementsByTagName("input");for(var b=0;b<inputs.length;b++){if(inputs[b].type=="checkbox"&&inputs[b].checked==true&&inputs[b].className=="styled"){inputs[b].previousSibling.style.backgroundPosition="0 -"+checkboxHeight*2+"px";}else if(inputs[b].type=="checkbox"&&inputs[b].className=="styled"){inputs[b].previousSibling.style.backgroundPosition="0 0";}else if(inputs[b].type=="radio"&&inputs[b].checked==true&&inputs[b].className=="styled"){inputs[b].previousSibling.style.backgroundPosition="0 -"+radioHeight*2+"px";}else if(inputs[b].type=="radio"&&inputs[b].className=="styled"){inputs[b].previousSibling.style.backgroundPosition="0 0";}}},choose:function(){option=this.getElementsByTagName("option");for(d=0;d<option.length;d++){if(option[d].selected==true){document.getElementById("select"+this.name).childNodes[0].nodeValue=option[d].childNodes[0].nodeValue;}}}}


/*dlc*/
var hersteller = -1;
var returnData = '';

jQuery(document).ready(function () {
	
	if(jQuery('#dlcSelectHersteller').size()) {
		//jQuery('#dlcSelectHersteller').attr('options').length = 1;
		jQuery.post('/webapps/dlc/getData.php', {'action':'getHersteller'}, function (data) {
			jQuery('#dlcSelectHersteller').append(data);
		});	
	}

	jQuery('#dlcSelectHersteller').change(function (e) {
		if(jQuery(this).val() != "-1") {
			getModell(jQuery(this).val());			
			jQuery('#dlcInsertModel').fadeIn('fast');
		}
	});	
	
	jQuery('#dlcSelectModel').change(function (e) {
		if(jQuery(this).val() != '-1') {
			getDetails(jQuery(this).val());
		}
	});
	
	jQuery('#dlcselectOS').change(function (e) {
		if(jQuery(this).val() != '-1') {
			getFiltered();	
		}
	});
	
	jQuery('#dlcselectTyp').change(function (e) {
		if(jQuery(this).val() != '-1') {
			getFiltered();	
		}
	});
});

function getFiltered() {
	jQuery.post('/webapps/dlc/getData.php', {'action':'getFilterd','os':jQuery('#dlcselectOS').val(),'typ':jQuery('#dlcselectTyp').val()}, function (dat) {
		jQuery('#dlcHandyDownloads').html('');
		jQuery.each(dat.dls, function(i,e) {
			jQuery('#dlcHandyDownloads').append('<div class="dlcdownloadItem"><a href="'+e[1]+'" class="dlcDownloadLink">'+e[0]+'</a><br />'+e[2]+'<br /><br />'+e[3]+'</div>');
		});
	},"json");
}

function getModell (hersteller) {
	
	jQuery.post('/webapps/dlc/getData.php', {'action':'getModel','hersteller':hersteller}, function (data) {
		jQuery('#dlcSelectModel').append(data);
	});	

}

function getDetails(modell) {
	jQuery.post('/webapps/dlc/getData.php', {'action':'getDetails','modell':modell}, function (data) {
		jQuery('#dlcHandyDownloads').html('');
		jQuery('#dlcselectOS').attr('options').length = 1;
		jQuery('#dlcselectTyp').attr('options').length = 1;
		jQuery('#dlcHandyDetails').html(data.headline);
		jQuery('#dlcHandyImg').html('<img src="'+data.img+'" alt="Download" />');
		jQuery.each(data.dls, function(i,e) {
			jQuery('#dlcHandyDownloads').append('<div class="dlcdownloadItem"><a href="'+e[1]+'" class="dlcDownloadLink">'+e[0]+'</a><br />'+e[2]+'<br /><br />'+e[3]+'</div>');
		});
		jQuery.each(data.os, function (i,e) {
			var vals = e.split('|');
			jQuery('#dlcselectOS').append('<option value="'+vals[0]+'">'+vals[1]+'</option>');
		});
		jQuery.each(data.type, function (i,e) {
			var vals = e.split('|');
			jQuery('#dlcselectTyp').append('<option value="'+vals[0]+'">'+vals[1]+'</option>');
		});
		jQuery('#dlcstepOne').fadeOut('fast');	
		jQuery('#dlcsteoTwo').fadeIn('fast');
	},"json");
		
}




function clickTab (toActive) {
jQuery('#'+activeTab).hide();
jQuery('#tabCont'+toActive).show();
activeTab = 'tabCont'+toActive;
jQuery('.contentTabs > li').removeClass('selected');
jQuery('.contentTabs > li').each(function(i,e) {
if((i+1) == toActive) {
jQuery(e).addClass('selected');
}
});
			
}



jQuery.fn.ForceNumericOnly =
function()
{
    return this.each(function()
    {
        $(this).keydown(function(e)
        {
            var key = e.charCode || e.keyCode || 0;
            // allow backspace, tab, delete, arrows, numbers and keypad numbers ONLY
            return (
                key == 8 || 
                key == 9 ||
                key == 46 ||
                (key >= 37 && key <= 40) ||
                (key >= 48 && key <= 57) ||
                (key >= 96 && key <= 105));
        });
    });
};
