﻿/// <reference path="jquery.js" />

/* ============================
DotControl copyright 2010
==============================*/

$(function () {

	// banners fix
	i = 0;
	$(".Banner a img").each(function (index) {
		if ($(this).width() == 1) {
			$(this).parent().parent().hide();
			i++;
		}
		if (i > 0) {
			$('.Content').addClass('LeftBannered');
		}
	});
});

var loaded = false;

function applyFixes() {

	if (!loaded) {

		fixLoginForm();
		
		// Poll fix
		$("div[id$='Survey_pnlSurvey']").addClass('pnlSurvey').append('<div class="line" />');
		var $mainPanel = $('div.pnlSurvey');
		var $childPanel = $('div.pnlSurvey td.surveyitems');
		$childPanel.append('<div class="buttons" />')
		$('div.buttons', $childPanel).append($('a.CommandButton', $mainPanel));
		$("div[id$='Survey_pnlResults']").addClass('pnlSurveyResults');

		// Dictionary fix
		$('.DCDictionarySuggest').append('<div class="buttons" />')
		$('.DCDictionarySuggest .buttons').append($('.DCDictionarySuggest .CommandButton'));

		

		// pager fix
		$('a[disabled=disabled], a[disabled=true]', 'div.Pager').addClass('disabled').removeAttr('disabled');

		//feed
		$('.feedItem .text').each(function () {
			$(this).find('br:first').remove();
		});

		
		loaded = true;
	}

	// Home page right column fix
var height = $('.topContent').height() + 10;
	$('.Zone3').css('margin-top', -height).css('padding-top', '0');

	//IE7 links outline fix
	if (/msie/i.test(navigator.userAgent) && !/opera/i.test(navigator.userAgent)) {
		$('a').focus(function () {
			$(this).blur();
		}); 
	}


	//print button
	$(".printBtn").click(function () {
		$(".DetailedView").printElement({ printMode: 'popup',
		printBodyOptions:
            {
            	classNameToAdd: 'print'
            }
		});
	});

    // buttons fix
    ConvertToButton('a.CommandButton');
    ConvertToButton('.contactme', 'contactBtn');
    $('span.CommandButton input').remove();

    RoundedButton('input.StandardButton');
    RoundedButton('.replaceRounded');

	// inputs
	$('input[type="text"], input[type="password"]').addClass('txtBox');
	$('input[type="checkbox"]').addClass('chkBox');
	$('input[type="radio"]').addClass('rBtn');

	// optimize
	$('.DCDictionary .ResultHolder .Item').Optimize();
	$('.newsListItem', ".main").Optimize();
	$('.newsListItem', ".sidebar").Optimize();
	$('.Items').each(function () {
		$(this).find('.newsListItem').Optimize();
	});

	// default text
	$('.txtSearch').hint();
	$('.Captcha .txtBox').hint('Vul hier bovenstaande code in');

	// Zapline fix
	$('.Zapline').each(function () {
	    if ($(this).text() == "" || $(this).text() == " ") {
	        $(this).remove();
	    }
	});
}



function ConvertToButton(items, css) {
	$(items).each(function () {
		var $css = 'defaultButton';
		//save value as variable
		var text = $(this).html();
		// assign css classes
		$css += " " + $(this).attr('class');

		if (css) {
			$css += " " + css;
		}
		// remove text and css from source lnk
		$(this).removeAttr('class').html('');
		//create a span inside source link
		$('<span />').html(text).appendTo(this);
		// outer container
		var $container = $('<div />').addClass($css);
		$(this).wrap($container);
		// clearing div
		$(this).after('<div class="line" />');
	});
}


function RoundedButton(items) {
	$(items).each(function () {
		$(this).wrap('<span class="RoundedButton" />').after('<div class="line" />');
		$(this).wrap('<span class="rc" />');
		$(this).wrap('<span class="lc" />');
	});
}


// Login fix
/* #### Dont try to read this code #### */
function fixLoginForm() {
	
}


