CrediWeb – Credit Reporting System

JavaScript
$(function() {
   $.support.placeholder = false;
   test = document.createElement('input');
   if('placeholder' in test) $.support.placeholder = true;
});

$(function() {
   if(!$.support.placeholder) {
      var active = document.activeElement;
      $(':text').focus(function () {
         if ($(this).attr('placeholder') != '' && $(this).val() == $(this).attr('placeholder')) {
            $(this).val('').removeClass('hasPlaceholder');
			$(this).css({'color': '#000'});
         }
      }).blur(function () {
         if ($(this).attr('placeholder') != '' && ($(this).val() == '' || $(this).val() == $(this).attr('placeholder'))) {
            $(this).val($(this).attr('placeholder')).addClass('hasPlaceholder');
			$(this).css({'color': '#999'});
         }
      });
      $(':text').blur();
      $(active).focus();
      $('form:eq(0)').submit(function () {
         $(':text.hasPlaceholder').val('');
      });
   }
});

$(document).ready(function() {
	$('dl.tabs dt').click(function(){
		$(this)
			.siblings().removeClass('selected').end()
			.next('dd').andSelf().addClass('selected');
	});

	$('#content .f-block.registration fieldset.r-group input.with-contract:checked').each(function(){
		$('#content .f-block.registration fieldset.with-contract').addClass('opened');
		$('#content .f-block.registration .actions').removeClass('type-2');
	});

	$('body').click(function(){
		var el = $('#content .f-block.registration fieldset.r-group input.with-contract');
		if(el.is(':checked')) {
			$('#content .f-block.registration fieldset.with-contract').addClass('opened');
			$('#content .f-block.registration .actions').removeClass('type-2');
		} else {
			$('#content .f-block.registration fieldset.with-contract').removeClass('opened');
			$('#content .f-block.registration .actions').addClass('type-2');
		}
	});

	$('#article .info .title a, #article a.opener, a.special').click(function(e){
		e.preventDefault();
	});
	$('#article .info .title').click(function(){
		if($(this).hasClass('closed')) {
			$(this)
				.siblings().removeClass('closed').end()
				.nextAll('dd').andSelf().removeClass('closed');
		} else {
			$(this)
				.siblings().removeClass('closed').end()
				.nextAll('dd').andSelf().addClass('closed');
		}
	});

	$('#article a.opener').click(function(){
		if($(this).hasClass('opened')) {
			$(this)
				.siblings().removeClass('opened').end()
				.next('.col').andSelf().removeClass('opened');
		} else {
			$(this)
				.siblings().removeClass('opened').end()
				.next('.col').andSelf().addClass('opened');
		}
	});

	$('#sidebar .info dt a').click(function(){
		var $thisFirst = $(this).closest('.menu').find('a').get(0);
		var $thisFirstId = $($thisFirst).attr('href');
		var $thisId = $(this).attr('href');

		if($(this).attr('href').length >0) {
			var el = $(this).attr('href');
			$('html,body').animate(
				{scrollTop: $(el).position().top+26},
				500,
				function () {
					if($thisFirstId == $thisId) {
						$(this).scrollTop($(el).position().top-20);
					} else {
						$(this).scrollTop($(el).position().top+26);
					}
				}
			);
		}
	});

	var $window = $(window);
	var $sidebar = $('#sidebar .menu');
	var $topBlock = $('#article .b-top');

    function fixPosition(el) {
        var elClone = el.clone().attr('id', '').html('').insertBefore(el).addClass('main');
        var elTop = el.offset().top;

		function stickIt () {
			var scrollTop = $window.scrollTop();

			if (scrollTop - elTop >= -10) {
				el.css({top: 0, left: elClone.offset().left, width: elClone.width(), position: 'fixed'});
				el.addClass('fixed');
			} else {
				el.attr({'style': ''});
				el.removeClass('fixed');
			}
		}
        $window.bind('scroll resize', stickIt);

		//console.log(el.height(), $window.height());
    }

	if($sidebar.length >0) {
		if (!('ontouchstart' in document) && !($.browser.msie && $.browser.version < 7.0) && ($sidebar.height() < $window.height())) {
			fixPosition($sidebar);
		}
	}
	if($topBlock.length >0) {
		if (!('ontouchstart' in document) && !($.browser.msie && $.browser.version < 7.0) && ($topBlock.height() < $window.height())) {
			fixPosition($topBlock);
		}
	}

	var $titleBlock = $('#article .info .title');

	if ($titleBlock.length >0) {
		$titleBlock.each(function() {
			var clone = $(this).clone().attr('id', '').insertBefore($(this)).addClass('clone').addClass($(this).parent().attr('id'));

			clone.css({top: 57, left: clone.offset().left, width: clone.width(), position: 'fixed'});

			clone.hide();
		});
		var $titleBlockClone = $('#article .info .title.clone');

		function isScrolledIntoView(elem) {
			var docViewTop = $window.scrollTop();
			var docViewBottom = docViewTop + $window.height();

			var elemTop = elem.offset().top;
			var elemBottom = elemTop + elem.height() - 58;

			return ((elemBottom >= docViewTop) && (elemTop <= docViewBottom));
		}

		$titleBlock.each(function() {
			if (isScrolledIntoView($(this).closest('dl'))) {
				$('#sidebar .menu a[href="#' + $(this).parent().attr('id') + '"]').closest('dl').addClass('current');
			}
		});
		$window.bind('scroll resize', function() {

			if (! $.browser.msie) {
				$('#article >dl >dt.title.clone').hide();
			}
			$titleBlock.each(function() {
				var self = $(this);
				var selfParent = self.parent();
				var selfParentId = selfParent.attr('id');
				var selfPositionTop = self.position().top;

				if (selfPositionTop - 16 < $window.scrollTop()) {
					if (selfPositionTop - 1 < $window.scrollTop()) {
						$('#article >dl >dt.title.clone.' + selfParentId).show();
					}
				} else {
					$('#article >dl >dt.title.clone.' + selfParentId).hide();
				}

				if (isScrolledIntoView(selfParent)) {
					$('#sidebar dl.' + selfParentId).addClass('current');
				} else {
					$('#sidebar dl.' + selfParentId).removeClass('current');
				}
			});

		});
		// Resize title clones
		$window.bind('resize', function() {
			if ($('#article >dl >dt.title').length >0) {
				var elParent = $('#article >dl >dt.title:not(.clone)');
				var elClone = $('#article >dl >dt.title.clone');
				var newLeft = elParent.offset().left;
				var newWidth = elParent.width();

				elClone.css({'left': newLeft + 'px'});
				elClone.width(newWidth);
			}
		});
	}

	if ($.browser.msie && $.browser.version <= 8.0) {
		$('#article .info .details table .special').mouseenter(function() {
			$(this).css({'z-index': '20'});
		}).mouseleave(function() {
			$(this).css({'z-index': '0'});
		});
	}

	function closeOverlay(){
		$('#overlay').removeClass('opened');
		$(this).closest('.modal').removeClass('opened');
	}
	// Open Modal
	$('a.modal').click(function (e) {
		e.preventDefault();
		$('#overlay').addClass('opened');
		$('#overlay .modal.' + $(this).attr('rel')).addClass('opened');
	});

	// Close Modal
	$('#overlay .close').click(function(e) {
		e.preventDefault();
		closeOverlay();
	});
	$('#overlay').click(function(e) {
		if ($(e.target).closest('.modal').length <= 0) {
			closeOverlay();
		}
	});

	$('a.button2.add-to-favorites').click(function (e) {
		e.preventDefault();
		if($(this).hasClass('selected')) {
			$(this).parent().prepend('<div class="message positive" id="msg1">' + $(this).attr('data-removed') + '</div>');
			$(this).removeClass('selected');
			$('#msg1').fadeOut(1600);
		} else {
			$(this).parent().prepend('<div class="message positive" id="msg1">' + $(this).attr('data-added') + '</div>');
			$(this).addClass('selected');
			$('#msg1').fadeOut(1600);
		}

	});
	$('#article .tabs dd form .hint a').click(function (e) {
		e.preventDefault();
		$(this).closest('.selected').find('input[type="text"]').val($(this).text());
	});
});