function wk() {}

function kriesi_disable(){
	$('.schritt2 .prepaid_radio').each(function(i){
	if($(this).attr("checked")){this_change();}
	$(this).bind("click",this_change);
	
	function this_change(){		
		var which_block_on = ".schritt2 fieldset:eq("+i+") input, .schritt2 fieldset:eq("+i+") select ";
		$(".schritt2 fieldset:eq("+i+") label").css({color:"#000"});
		$(which_block_on).removeAttr("disabled").css({backgroundColor:"#FFF"});						   
		var which_block_off = ".schritt2 fieldset:not(fieldset:eq("+i+"))";
		$(which_block_off + " label").css({color:"#666"});
		$(which_block_off + " input:text").attr("value","");
		$(which_block_off + " input:text, "+ which_block_off +" select").attr("disabled","disabled").css({backgroundColor:"#EFEFEF"});
		}
	});
}
	
	
	




function kriesi_modal(var_clickelement,var_loadfile){
	$("body").append("	<div class='handykick_overlay' style='display:none;'></div><div id='handykick_modal_window' style='display:none;'></div>");
	
	modal = $("#handykick_modal_window");
	overlay = $(".handykick_overlay");
	
	handykick_modal_open = false;
	
	 $(window).resize(modal_position);
	 $(window).scroll(modal_position);	
	
	
	$(overlay).click(function(){close_modal()});
	$(modal).click(function(){close_modal()});
	$(var_clickelement).css({cursor:"pointer"}).mouseover(function(){
									$(this).css({backgroundPosition:"bottom"});							   
								}).mouseout(function(){
									$(this).css({backgroundPosition:"top"});							   
								}).click(function(){
															   
								if(handykick_modal_open){return false}
									handykick_modal_open = true;
								
									modal.load(var_loadfile, function(){
								
									modal_position();

									overlay.fadeIn(400,function(){
									modal.fadeIn(400);

																});
									})	;
								 });
	
	
	
	
	function close_modal(){
							if(!handykick_modal_open){return false}
								handykick_modal_open = false;
								
								modal.empty().css({display:"none"});
								overlay.css({display:"none"});
							  
							  }
							  
							  
	
	function modal_position(){
			win_data = ___getPageSize() ;
			win_offset = ___getPageScroll();
										
			modal_h= modal.height();
			modal_w= modal.width();	
			
			
			if	(modal_h < win_data[3]){						
			modal.css({top:((win_data[3] / 2)+win_offset[1]) - (modal_h / 2), left:(win_data[2] / 2) - (modal_w / 2)});
			} else{
			modal.css({top:0, left:(win_data[2] / 2) - (modal_w / 2)});
			}
			overlay.css({opacity:"0.4", width:win_data[0], height:win_data[1]});

		}

}
function ___getPageSize() {
			var xScroll, yScroll;
			if (window.innerHeight && window.scrollMaxY) {	
				xScroll = window.innerWidth + window.scrollMaxX;
				yScroll = window.innerHeight + window.scrollMaxY;
			} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
				xScroll = document.body.scrollWidth;
				yScroll = document.body.scrollHeight;
			} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
				xScroll = document.body.offsetWidth;
				yScroll = document.body.offsetHeight;
			}
			var windowWidth, windowHeight;
			if (self.innerHeight) {	// all except Explorer
				if(document.documentElement.clientWidth){
					windowWidth = document.documentElement.clientWidth; 
				} else {
					windowWidth = self.innerWidth;
				}
				windowHeight = self.innerHeight;
			} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
				windowWidth = document.documentElement.clientWidth;
				windowHeight = document.documentElement.clientHeight;
			} else if (document.body) { // other Explorers
				windowWidth = document.body.clientWidth;
				windowHeight = document.body.clientHeight;
			}	
			// for small pages with total height less then height of the viewport
			if(yScroll < windowHeight){
				pageHeight = windowHeight;
			} else { 
				pageHeight = yScroll;
			}
			// for small pages with total width less then width of the viewport
			if(xScroll < windowWidth){	
				pageWidth = xScroll;		
			} else {
				pageWidth = windowWidth;
			}
			arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight);
			return arrayPageSize;
		};
		/**
		 / THIRD FUNCTION
		 * getPageScroll() by quirksmode.com
		 *
		 * @return Array Return an array with x,y page scroll values.
		 */
		function ___getPageScroll() {
			var xScroll, yScroll;
			if (self.pageYOffset) {
				yScroll = self.pageYOffset;
				xScroll = self.pageXOffset;
			} else if (document.documentElement && document.documentElement.scrollTop) {	 // Explorer 6 Strict
				yScroll = document.documentElement.scrollTop;
				xScroll = document.documentElement.scrollLeft;
			} else if (document.body) {// all other Explorers
				yScroll = document.body.scrollTop;
				xScroll = document.body.scrollLeft;	
			}
			arrayPageScroll = new Array(xScroll,yScroll);
			return arrayPageScroll;
		};	


	

function kriesi_tooltip(selector, selectname){
 $(selector).each(function(i){
			var allclosed = true;
			var what_to_do = "default";		// default aktion wenn die funktion geladen wird	   
			var html_code = $(this).attr('title'); // extrahiert das title attribut
			$("body").append("<div class='"+selectname+"' id='"+selectname+i+"'></div>"); // fügt für jedes element ein div hinzu
			var myselectname = $("#"+selectname+i); //das aktuelle div
			
			if(html_code.match(/load:/)){ // will der benutzer ein externes html file laden muss der title mit load: beginnen
			what_to_do = "load_url";
			}
			
	
			if(what_to_do == "load_url"){
				html_code = html_code.replace(/load:/, "");
				$(myselectname).load(html_code);
			}
			
			if(what_to_do == "default"){
				html_code = html_code.replace(/\(/g, "<").replace(/\)/g, ">");
				$(myselectname).append(html_code);

			}
			
			
			$(this).css({cursor:"pointer"}).mouseover(function(){
							if(allclosed){
							$(myselectname).fadeIn(400);
							allclosed = false;
							}
									});
			
			$(myselectname).mousemove(function(e){
					position_me(myselectname, e);
			});
			$(this).removeAttr("title").mousemove(function(e){
					position_me(myselectname, e);
			}).mouseout(function(){
					$(myselectname).fadeOut(200, function(){
														  allclosed = true;
														  });
			});
		});
 
 
 
		 function position_me(myselectname, e){
			 win_data = ___getPageSize();
			 win_offset = ___getPageScroll();
			
			var adjustmentX = - myselectname.width() - 90;
			var adjustmentY = - myselectname.height() - 30;
			
			if(myselectname.height() > e.pageY){adjustmentY = - e.pageY + 15 + win_offset[1]; } 
			
			$(myselectname).css({left:e.pageX + adjustmentX, top:e.pageY + adjustmentY});

		 }
 	}
function kriesi_startseite(var_clickelement){
$(var_clickelement).css({cursor:"pointer"}).mouseover(function(){
									$(this).css({backgroundPosition:"bottom"});							   
								}).mouseout(function(){
									$(this).css({backgroundPosition:"top"});							   
								})	
	}
		
    
    
    
/*  SMS Counter  for MA  */

// when textarea is filled with text, a counter runs down from 160 to indicate the end of the sms
function SMS_counter()
{
    // handler is saved into variable to prevent DOM search every call
    textarea = $('#sms_textarea');
    var max = $('#sms_counter').val();
	
    // textarea is bound to the following events
    textarea.bind("click keydown keyup focus change", change_number);
	
	function change_number()
        {
            // defining variables  max = count of maximum characters in one sms 
            // wert = amount of characters currently in textarea
            var wert;            
            
            // wert is defined by the maximum characters minus the characters in the textarea
            wert = max-textarea.val().length;
            
            // if wert below zero, prohibit any further input
            if (wert < 0)
            {
                textarea.val(textarea.val().substring(0,max));
                wert = max-textarea.val().length;
                $('#sms_counter').val(wert);
            }
            else
            {
                // if counter is above zero, allow input
                $('#sms_counter').val(wert);
            }
        }
}    
    
    
    
function free_sms_numberchange()
{
	var country_select = $('#free_sms_country');	
	var changevalueof = $('.sms_form_dialcode, .subtext span');
	
	country_select.bind("change", function()
        {
		
		country_select_value = $('#free_sms_country option:selected').attr('value');
		country_select_value = country_select_value.replace(/^00/, "+");
		changevalueof.html(country_select_value);
		});
}    
    
    
    
		
$(document).ready(function(){
						   kriesi_disable();
    // kriesi_startseite("#handykickmana");
	// kriesi_modal("#handykickmana","../../page/de/aktionen_de.htm");
kriesi_tooltip("abbr", "handykick_tooltip");
SMS_counter();
free_sms_numberchange();
    // kriesi_tooltip("#handykickmana", "handykick_tooltip_big");
});
