window.onload = init;

/* DOM Load */
$(function()
{
	$('input#changeuserinfo').click(function(){
		if($(this).attr('checked')){
			$('#showinfo').show();
		}
		else{
			$('#showinfo').hide();			
		}
	});
	$('#search-box, #search_again').originalValue();
	//$.fontsizer('#header-controls', true);

	$("#helptext,#application .pin_number, #application #help").hide();



	$('a#help').click(function() {

		$('#helptext').toggle('slow');

		return false;

  	});

	$('#LoginEMail').originalValue();
	$('#LoginPassword').originalValue();

	$('#LostPassword').click(function(){
		window.location.replace('http://shell.dev.innn.is/Tynt');
	});

	$('#confirm').click(function(){

		var url = 'http://shell.dev.innn.is/?PageId=41'; 
		var newurl = url; 
		var ssn = $('#ssn').val();
		var email = $('#email').val();
		var email2 = $('#email2').val();
		var phone = $('#phone').val();

		if( ssn != '' & ssn != 'Kennitala')
			newurl = newurl + '&ssn=' +  ssn;
		if( email != '' & email != 'Netfang')
			newurl = newurl + '&email=' +  email; 
		if( email2 != '' & email2 != 'Staðfesta netfang')
			newurl = newurl + '&email2=' +  email2;
		if( phone != '' & phone != 'Sími')
			newurl = newurl + '&phone=' +  phone;
		
		if(url != newurl)
			window.location.replace(newurl);
		else
			return false; 
	});

	$("#orkukey input").keypress(function (e) {   
		if ((e.which && e.which == 13) || (e.keyCode && e.keyCode == 13)) {   
			$("#confirm").click();   
			return false;   
		} else {   
			return true;   
		}   
	});  
	function CheckMe()
	{
		$(this).parent().next().find('.pin_number').toggle('slow');
		if( $('.checkme:checked').length )
		{
			$('#help').show('slow');
			$('#helptext').show('slow');
		}
		else
		{
			$('#help').hide('slow');
			$('#helptext').hide('slow');
		}
	}
	$('.checkme').click(CheckMe);
	$('.checkme:checked').each(CheckMe);

	$(".cards .key").change(function()
	{
		if($(this).val() == 'true')
			$(this).parent().next().find('img').attr('src','/library/Images/Template/Pagecomponents/orkan-lykill_breyting-small.png');
		else
			$(this).parent().next().find('img').attr('src','/library/Images/Template/Pagecomponents/orkukort.gif');
	});
	if($.datepicker)
	{
		/* Icelandic initialisation for the jQuery UI date picker plugin. */
		/* Written by Haukur H. Thorsson (haukur@eskill.is). */
		$.datepicker.regional['is'] = {clearText: 'Hreinsa', clearStatus: '',
			closeText: 'Loka', closeStatus: '',
			prevText: '< Fyrri', prevStatus: '',
			nextText: 'N&aelig;sti >', nextStatus: '',
			currentText: '&Iacute; dag', currentStatus: '',
			monthNames: ['Jan&uacute;ar','Febr&uacute;ar','Mars','Apr&iacute;l','Ma&iacute','J&uacute;n&iacute;',
			'J&uacute;l&iacute;','&Aacute;g&uacute;st','September','Okt&oacute;ber','N&oacute;vember','Desember'],
			monthNamesShort: ['Jan','Feb','Mar','Apr','Ma&iacute;','J&uacute;n',
			'J&uacute;l','&Aacute;g&uacute;','Sep','Okt','N&oacute;v','Des'],
			monthStatus: '', yearStatus: '',
			weekHeader: 'Vika', weekStatus: '',
			dayNames: ['Sunnudagur','M&aacute;nudagur','&THORN;ri&eth;judagur','Mi&eth;vikudagur','Fimmtudagur','F&ouml;studagur','Laugardagur'],
			dayNamesShort: ['Sun','M&aacute;n','&THORN;ri','Mi&eth;','Fim','F&ouml;s','Lau'],
			dayNamesMin: ['Su','M&aacute;','&THORN;r','Mi','Fi','F&ouml;','La'],
			dayStatus: 'DD', dateStatus: 'D, M d',
			dateFormat: 'dd/mm/yy', firstDay: 0, 
			initStatus: '', isRTL: false, minDate : new Date(2008, 0, 1) };
		$.datepicker.setDefaults($.datepicker.regional['is']);

		$(".datepicker").datepicker($.extend({},
			$.datepicker.regional["is"],
			{ 
				showAnim: "slideDown",
				dateFormat: "d.m.yy"
			}
		));
	}
});

function ShowRows(count)
{
	for(var i = 1; i <= 20; i++)
	{
		document.getElementById('row_' + i).style.display = 'none';
	}        

	for(var i = 1; i <= count; i++)
	{
		document.getElementById('row_' + i).style.display = '';
	}    
}

function numeric(evt)
{
	var charCode = (evt.which) ? evt.which : event.keyCode

         if (charCode > 31 && (charCode < 48 || charCode > 57))
            return false;

         return true;
}

function init() {

	apptypeChange();
	var payment = jQuery("input[name = 'paymenttype']");

	if(payment.length == 0) return;

	var update_ui = function()
	{
		payment.each(function()
		{
			if(this.checked)
			{
				jQuery("div." + this.value).removeClass("hidden");
			}
			else
			{
				jQuery("div." + this.value).addClass("hidden");
			}
		});
	}

	payment.bind("click", function()
	{
		update_ui();
	});

	update_ui();
};

function apptypeChange()
{
	var apptype = jQuery("input[name = 'apptype']");
	if(apptype.length == 0) return;
	var update_ui = function()
	{
		apptype.each(function()
		{
			if(this.checked)
			{
				jQuery("div." + this.value).removeClass("hidden");
				jQuery("div." + this.value + "_rev").addClass("hidden");
			}
			else
			{
				jQuery("div." + this.value).addClass("hidden");
				jQuery("div." + this.value + "_rev").removeClass("hidden");
			}
		});
	}

	apptype.bind("click", function()
	{
		update_ui();
	});

	update_ui();
};

function deletePasswordText()
{
	document.getElementById('passwordText').style.visibility = 'hidden';
	document.getElementById('LoginPassword').focus() 
}

function WriteFlash(movie, width, height)
{
	var flash = '<object codeBase="'+location.protocol+'//download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=5,0,0,0" height="' + height + '" width="' + width + '" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000">';
	flash += '<param name="Movie" value="' + movie + '">';
	flash += '<embed src="' + movie + '" quality="high" bgcolor="" height="' + height + '" width="' + width + '" type="application/x-shockwave-flash" pluginspage="'+location.protocol+'//www.macromedia.com/go/getflashplayer">';
	flash += '</embed>';
	flash += '</object>';
	document.write(flash);
}


/* originalValue by Lakio */
(function(){
jQuery.fn.originalValue = function( originalValue ){
	this.each(function(){
		if( originalValue )
			$(this).val(originalValue);
		$(this).attr( 'originalValue', $(this).val() );
	}).blur(function(){
		if( !$(this).val() )
			$(this).val( $(this).attr('originalValue') );
	}).focus(function(){
		if( $(this).val() === $(this).attr('originalValue') )
			$(this).val('');
	});
}
})(jQuery);

