$(function()
{
	signin();
});


/*** Methods for label inside inputbox for sigin on frontpage *** Jakob */
function signin() {
	var loginEmail = document.getElementById('LoginEMail');
	var LoginPassword = document.getElementById('LoginPassword');

	if ( loginEmail != null ){
		loginEmail.value = "Netfang";
		loginEmail.onfocus = clearuser;
		loginEmail.onblur = resetuser;
	}
	if ( LoginPassword != null ){
		if (navigator.appName != "Microsoft Internet Explorer"){
			LoginPassword.type = "text";
			LoginPassword.value = "Lykilorð";
			LoginPassword.onfocus = clearpass;
			LoginPassword.onblur = resetpass;
		}
		else {
			LoginPassword.value = "Lykilorð";
			LoginPassword.onfocus = clearpass;
			LoginPassword.onblur = resetpass;
		}
	}
}

function clearuser(){
	var loginEmail = document.getElementById('LoginEMail');
	if ( loginEmail != null ){
		if ( loginEmail.value == "Netfang"){
			loginEmail.value = "";
		}
	}
}

function clearpass(){
	var LoginPassword = document.getElementById('LoginPassword');
	if ( LoginPassword != null ){
		if (navigator.appName != "Microsoft Internet Explorer"){
			if ( LoginPassword.value == "Lykilorð"){
				LoginPassword.type = "password";
				LoginPassword.value = "";
			}
		}
		else {
			LoginPassword.value = "";
		}
	}
}

function resetuser(){
	var loginEmail = document.getElementById('LoginEMail');
	if ( loginEmail != null ){
		if ( loginEmail.value == ""){
			loginEmail.value = "Netfang";
		}
	}

}

function resetpass(){
	var LoginPassword = document.getElementById('LoginPassword');
	if ( LoginPassword != null ){
		if ( LoginPassword.value == ""){
			if (navigator.appName != "Microsoft Internet Explorer"){
				LoginPassword.type = "text";
			}
			LoginPassword.value = "Lykilorð";
		}
	}
}


/***** LinkCollection *****/

function showLinkCollection(id)
{
	$('.linkContainer').hide();
	$('#' + id).show();
}

function displayLinkDescr( id )
{
	$('.longdescr').slideUp();
	if(!$('#longdescr' + id).is(':visible'))
		$('#longdescr' + id).slideDown();
	return false;
}

/* Facebook link */
function fbs_click()
{
	var u = location.href;
	var t = document.title
	window.open('http://www.facebook.com/sharer.php?u=' +
		encodeURIComponent(u) +
		'&t=' +
		encodeURIComponent(t)
		,'sharer','toolbar=0,status=0,width=626,height=436'
	)
}




/*** maillist ajax ***

$(function()
{
	var options = { 
		beforeSubmit: showRequest
	};
	$('#newsletter').submit(function() { 
		this.ajaxSubmit(options); 
		return false; 
	});


	$('#SearchString').originalValue();

});

function showRequest(formData, jqForm, options) { 
	box = $('body #rightcol .box #newsletter');

	if(!isValidEmail(box.find('#maillist input').val()))
	{
		box.find('#message').hide();
		box.find('#message').html( "Netfangið er ekki á réttu formi!" );
		box.find('#message').fadeIn();
		return false;
	}
	else
	{
		box.find('#message').hide();
		box.find('#message').html( box.find('#maillist input').val() + '<br />hefur verið skráð á póstlista!' );
		box.find('#message').fadeIn();
		return true;
	}
	return true;
}
*/

/* Spjallið - takkar fyrir syntax*/
function addtag(tag) 
	{
		var txt = document.getElementById('mta');

		if(document.selection) 
		{
			txt.focus();
			sel = document.selection.createRange();
			sel.text = '[' + tag + ']' + sel.text + '[/' + tag + ']';
		} 

	else 
	if(txt.selectionStart || txt.selectionStart == '0') 
	{	
		txt.value = (txt.value).substring(0, txt.selectionStart) + "["+tag+"]" + (txt.value).substring(txt.selectionStart, txt.selectionEnd) + "[/"+tag+"]" + 	(txt.value).substring(txt.selectionEnd, txt.textLength);
	} 
	else 
	{
	txt.value = '[' + tag + '][/' + tag + ']';
	}
	
	return;
}


function addurltag() 
{
var txt = document.getElementById('mta');
var link = prompt("Sláðu inn vefslóðina:", "http://");

if(link.length == 0 || link == "http://") 
{
return;
} 

else 
{
var link = "=\"" + link + "\"";
var text;
var sel2 = "";


if(document.selection)
{
txt.focus();
sel = document.selection.createRange();
sel2 = sel.text;
} 

else
		
if(txt.selectionStart || txt.selectionStart == '0') 
{
sel2 = (txt.value).substring(txt.selectionStart, txt.selectionEnd);
}

if(sel2.length > 0) 
{		                                			
text = sel2;
} 

else 
{
	text = prompt("Sláðu inn texta fyrir hlekk", "");
}
		                                  
}

if(document.selection)
 {	
txt.focus();
sel = document.selection.createRange();
sel.text = "[link'" + link + "']" + text + "[/link]";
}

else 
{
txt.value = (txt.value).substring(0, txt.selectionStart) + "[link" + link + "]" + text + "[/link]" + (txt.value).substring(txt.selectionEnd, txt.textLength);
}
return;
		                                        
}


function addpictag() 
{
	var txt = document.getElementById('mta');
	var link = prompt("Sláðu inn slóðina á myndina", "http://");
	if(link.length == 0 || link == "http://") 
	{
		return;
	} 
	else 
	{
		var link = link;
		var text;
		var sel2 = "";
		if(document.selection) 
		{
		txt.focus();
		sel = document.selection.createRange();
		sel2 = sel.text;
		} 
			else 
			if(txt.selectionStart || txt.selectionStart == '0') 
			{
				sel2 = (txt.value).substring(txt.selectionStart, txt.selectionEnd);
			}
	}


							                                        	if(document.selection) 
{
txt.focus();
sel = document.selection.createRange();
sel.text = "[img=]" + link + "[/img]";
	} 
	else {
txt.value = (txt.value).substring(0, txt.selectionStart) + "[img=]" + link + "[/img]" + (txt.value).substring(txt.selectionEnd, txt.textLength);
}
return;
}


function addyoutubetag() 
{
	var txt = document.getElementById('mta');
	var link = prompt("Sláðu inn slóðina myndbandið", "http://");
	if(link.length == 0 || link == "http://") 
	{
		return;
	} 
	else 
	{
		var link = link;
		var text;
		var sel2 = "";
		if(document.selection) 
		{
		txt.focus();
		sel = document.selection.createRange();
		sel2 = sel.text;
		} 
			else 
			if(txt.selectionStart || txt.selectionStart == '0') 
			{
				sel2 = (txt.value).substring(txt.selectionStart, txt.selectionEnd);
			}
	}


if(document.selection) 
{
txt.focus();
sel = document.selection.createRange();
sel.text = "[img=]" + link + "[/img]";
	} 
	else {
txt.value = (txt.value).substring(0, txt.selectionStart) + "[youtube=]" + link + "[/youtube]" + (txt.value).substring(txt.selectionEnd, txt.textLength);
}
return;
}

function addYouTube()
{
	$('#mta').val($('#mta').val() + "youtube:=" + $('#youtubeid').val());
}
