/* extends Jquery auf exists */
jQuery.fn.exists = function(){return jQuery(this).length>0;}

$(document).ready(function() {
    
    /* INPUT VALUES  - START */
    $('input.del').focus(function(){
		
		var name = $(this).attr('name');
		var typ  = $(this).attr('type')
		var val  = this.value;
		var sval = $(this).data(name);
		
		if(val==sval && typ=='text' && typ!='radio' && typ!='submit' ){
			this.value='';
		}
		
    });
    
    $('input.del').blur(function(){
		
		var name = $(this).attr('name');
		
		if(this.value=='' && $(this).data(name)!=null){
			
			this.value = $(this).data(name);
		}
    });
    
    $('input.del').each(function() {
		
		if (this.value!='') {
			var name = $(this).attr('name');
			$(this).data(name, this.value);
		}
    });
    
	$('input._autoselect').focus();
	
	if($('.scroll_stop').exists()) {
		ScrollStop();
	}
});


/* Scroll Stopper - STOP
 *
 *
 * JS - Cookies | lesen und schreiben - START */

function cookie_schreiben(wert,inhalt) {
    
   document.cookie = wert + "=" + inhalt;
   var check = document.cookie

   if (check && check.indexOf(wert) > -1) return true;
   else return false;
}

function cookie_lesen(wert) {
    
	var inhalt = document.cookie;
	var posName = inhalt.indexOf("; " + wert + "=");
	if (posName == -1) {
      if (inhalt.indexOf(wert + "=") == 0) posName = 0;
      else return null;
	}

	var wertAnfang = inhalt.indexOf("=", posName)+1;
	var wertEnde = inhalt.indexOf(";", posName+1);
	if (wertEnde == -1) {
		wertEnde = inhalt.length;
	}

   var wert = inhalt.substring(wertAnfang, wertEnde);
   return unescape(wert);
}
/* JS - Cookies | lesen und schreiben - STOP */


function ScrollStop () {
  var msie6 = $.browser == 'msie' && $.browser.version < 7;
  if (!msie6) {
    var top = $('.scroll_stop').offset().top - parseFloat($('.scroll_stop').css('margin-top').replace(/auto/, 0));
    $(window).scroll(function (event) {
      var y = $(this).scrollTop();
      
      if (y >= top) {
		var width = $('.scroll_stop').width();
		$('.scroll_stop').addClass('fixed').width(width);
      } else {
		$('.scroll_stop').removeClass('fixed');
      }
    });
  }
};
