$(document).ready(function() {
	
	var $form = $('form.kontakt-formular'),
		$licensTip = $('<div/>'),
		$licensTipLink = $('<span/>'),
		$versionTip = $('<div/>'),
		$versionTipLink = $('<span/>'),
		lx,ly,vl,vy,
		$styresystem = $('#styresystem'),
		$styresystemAndet = $('#styresystemandet').parents('li'),
		windows,bit;
		
	$('p.respons').animate({opacity:.2},100,function() {
		$(this).animate({opacity:1},500);
	})

	if ( $('.fejl',$form).length != 0 ) {
		$('.fejl:first input', $form).focus();
	} else {
		$('input:first', $form).focus();
	}

	if ( $(':selected',$styresystem).val() == '-' ) {
		windows = getPlatform();
		bit = getBit();
		if (windows == 'xp') {
			if (bit == 'x64') {
				$styresystem.val('Windows XP x64');
			} else {
				$styresystem.val('Windows XP x86');
			}
		} else if (windows == 'vista') {
			if (bit == 'x64') {
				$styresystem.val('Windows Vista x64');
			} else {
				$styresystem.val('Windows Vista x86');
			}
		} else if (windows == 'win7') {
			if (bit == 'x64') {
				$styresystem.val('Windows 7 x64');
			} else {
				$styresystem.val('Windows 7 x86');
			}
		} else {
			$styresystem.val('Andet');
		}
	}
	
//					<option value="Windows XP">Windows XP</option>
//					<option value="Windows Vista x86">Windows Vista (32bit)</option>
//					<option value="Windows Vista x64">Windows Vista (64bit)</option>
//					<option value="Windows 7 x86">Windows 7 (32bit)</option>
//					<option value="Windows 7 x64">Windows 7 (64bit)</option>
//					<option value="Andet">Andet...</option>

	
	if ($styresystem.val() != 'Andet') {
		$styresystemAndet.hide();
	}
	
	$styresystem.change(function() {
		if ($styresystem.val() == 'Andet') {
			$styresystemAndet.slideDown();
		} else {
			$styresystemAndet.slideUp();
		}
	});
		
	$licensTipLink
		.addClass('tiplink')
		.text('?')
		.hover(function() {
			$licensTip.fadeIn(250);
		}, function() {
			$licensTip.fadeOut(250);
		})
		.insertAfter($('#licensnr'));

	lx = $licensTipLink.position().left+20;
	ly = $licensTipLink.position().top-50;
	
	$licensTip
		.addClass('tipboks')
		.html($('#tip-licens').html())
		.css({top: ly,left: lx})
		.appendTo($('body'));

	$versionTipLink
		.addClass('tiplink')
		.text('?')
		.hover(function() {
			$versionTip.fadeIn(250);
		}, function() {
			$versionTip.fadeOut(250);
		})
		.insertAfter($('#winkasproversion'));

	vx = $versionTipLink.position().left+20;
	vy = $versionTipLink.position().top-50;
	
	$versionTip
		.addClass('tipboks')
		.html($('#tip-version').html())
		.css({top: ly,left: lx})
		.appendTo($('body'));
		
});

function getPlatform(){
	var uAgent = navigator.userAgent.toLowerCase(),
		strOs;

//Windows
	if (uAgent.indexOf('win')!=-1) {
// Win Vista
		if ((uAgent.indexOf('windows nt 6.0')!=-1) || (uAgent.indexOf('vista')!=-1)){
			strOs = 'vista';
		}
// Win 7
		else if ((uAgent.indexOf('windows nt 6.1')!=-1) || (uAgent.indexOf('windows nt 7.0')!=-1)){
			strOs = 'win7';
		}
// Win XP
		else if ((uAgent.indexOf('windows nt 5.1')!=-1) || (uAgent.indexOf('winxp')!=-1)){
			strOs = 'xp';
		}
// Unknown
		else {
			strOs = '';
		}
	}
//Unknown platform
	else {
		strOs = '';
	}

return strOs;

}

function getBit(){
	var uAgent = navigator.userAgent.toLowerCase(),
		strBit;

	if ((uAgent.indexOf('wow64')!=-1) || (uAgent.indexOf('x64')!=-1) || (uAgent.indexOf('win64')!=-1) || (uAgent.indexOf('ia64')!=-1)) {
		strBit = 'x64'
	}
	else {
		strBit = 'x68'
	}
	
	return strBit
}
