// JavaScript Document
    function getPageSize() { //as seen in so many api's
			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;
		};

   



  function loadContent(type){
    //$('#regvarcontent').hide(function(){
      $('#regvarcontent').load('includes/register_sniplet.php?content='+type+'&rnd='+Math.random()+' #regvarcontent > *', function(){
       //niceform init
       init();
       //$('#regvarcontent').show();
      });
    //});  
  }

  function setoverlay(){
    var arrPageSizes = getPageSize();
    $('#overlay').width(arrPageSizes[0]);
		$('#overlay').height(arrPageSizes[1]);
  }

  function toggleFormOff(){
      $('#popupform').hide();    
      $('#overlay').hide();       
  }

  function toggleFormOn(content){      
      setoverlay();
      $('#overlay').show();
      $('#popupform').show();
      $('#popupform').load('includes/popup_contents.php?case='+content+'&rnd='+Math.random()+' #popupform > *', function(){
       //niceform init
       init();
       initcontent(content);      
      });                             
  }
  
  function disableEnterSubmit(){
    $('input').keydown(function(e){
      if (e.keyCode == 13) {
        return false;
      }
    });
  }
  
  //event bindings 
  function initcontent(content){
    disableEnterSubmit();
    if (content=='step1'){
      $('.price_free').mouseenter(function(){      
        $('.popmain').addClass('state1');
        $(this).mouseleave(function(){        
          $('.popmain').removeClass('state1');                             
        });
      }).click(function(){
        $(this).blur();            
        $('.popmain').removeClass('state2').addClass('state1');
        $('.price_free').unbind('mouseenter').unbind('mouseleave');
        $('.price_premium').unbind('mouseenter').unbind('mouseleave');
        $('#weiter').unbind('click');      
        $('#weiter').click(function(){
          $('#popupform').load('includes/popup_contents.php?case=step2&rnd='+Math.random()+' #popupform > *', function(){
            //niceform init
            init();
            initcontent('step2');
          });          
        }).show().attr('class','weiter');
        return false;
      });    
      $('.price_premium').mouseenter(function(){      
        $('.popmain').addClass('state2');
        $(this).mouseleave(function(){        
          $('.popmain').removeClass('state2');                             
        });
      }).click(function(){
        $(this).blur();            
        $('.popmain').removeClass('state1').addClass('state2');
        $('.price_free').unbind('mouseenter').unbind('mouseleave');
        $('.price_premium').unbind('mouseenter').unbind('mouseleave');
        $('#weiter').unbind('click');      
        $('#weiter').click(function(){
          $('#popupform').load('includes/popup_contents.php?case=step2b&rnd='+Math.random()+' #popupform > *', function(){
            //niceform init
            init();
            initcontent('step2b');
          });          
        }).show().attr('class','weiter');
        return false;
      });
    }else if(content=='step2'){
      $('.registrieren').click(function(){            
        $.post('includes/popup_contents.php', $('#step2form').serialize(), function(data) {                  
  				$('#popupform').replaceWith(data);
          //niceform init
          init();
          initcontent('step2');				
  			});
  			return false;
      });			
    }else if(content=='step2b'){
      $('input[name=os0]').change(function(){        
        $('#weiter').unbind('click');
        $('#weiter').click(function(){            
          $.post('includes/popup_contents.php', $('#step2bform').serialize(), function(data) {                  
    				$('#popupform').replaceWith(data);
            //niceform init
            init();
            initcontent('step3b');				
    			});
    			return false;
        }).attr('disabled','').attr('class','weiter');
      });			
    }else if(content=='step3b'){
      $('.registrieren').click(function(){            
        $.post('includes/popup_contents.php', $('#step3bform').serialize(), function(data) {                  
  				$('#popupform').replaceWith(data);
          //niceform init
          init();
          initcontent('step3b');
          //submit paypal form
          //alert($('#paypalform').serialize());
          $('#paypalform').trigger('submit'); 				
  			});
  			return false;
      });			
    }else if(content=='stepu1'){
      $('input[name=os0]').change(function(){        
        $('#weiter').unbind('click');
        $('#weiter').click(function(){            
          $.post('includes/popup_contents.php', $('#stepu1form').serialize(), function(data) {                  
    				$('#popupform').replaceWith(data);
            //niceform init
            init();
            initcontent('stepu2');				
    			});
    			return false;
        }).attr('disabled','').attr('class','weiter');
      });			
    }else if(content=='stepu2'){
      $('#upgrade').click(function(){            
        $.post('includes/popup_contents.php', $('#stepu2form').serialize(), function(data) {                  
  				$('#popupform').replaceWith(data);
          //niceform init
          init();
          initcontent('stepu2');
          //submit paypal form
          //if ($('#paypalform').length){
          //  alert($('#paypalform').serialize());          
          //}
          $('#paypalform').trigger('submit'); 				
  			});
  			return false;
      });			
    }else if(content=='stepv1'){
      $('#weiter').click(function(){            
        $.post('includes/popup_contents.php', $('#stepv1form').serialize(), function(data) {                  
  				$('#popupform').replaceWith(data);
          //niceform init
          init();
          initcontent('stepv1');           				
  			});
  			return false;
      });			
    }    
  }
  
  //resize overlay on window resize
  $(window).resize(function() {
    setoverlay();
  });

