/*
$(document).ready( function() {
	var height = 0;
	var h = 0;
	var element = null;

	element = $(document).find("#leftmenu");
	if (element != null) {
		// h = element.attr("offsetHeight");
		h = element.height();
		if (h != null && h > height) {
			height = h;
		}
	}

	element = $(document).find("#contentleft");
	if (element != null) {
		// h = element.attr("offsetHeight");
		h = element.height();
		if (h != null && h > height) {
			height = h;
		}
	}

	element = $(document).find("#contentright");
	if (element != null) {
		// h = element.attr("offsetHeight");
		h = element.height();
		if (h != null && h > height) {
			height = h;
		}
	}

	if (height <= 600) {
		height = 600;
	}

	if (height > 0) {
		height = height + 10;

		element = $(document).find("#leftmenu");
		if (element != null) {
			element.height(height);
		}

		element = $(document).find("#contentleft");
		if (element != null) {
			element.height(height);
		}

		element = $(document).find("#contentright");
		if (element != null) {
			element.height(height);
		}
	}
});

$(document).ready( function() {
	var element = $(document).find("#header");
	if (element != null) {
		// element.css({ "background-color":"#FFF8E8" });
		element.height(96);
	}
});
 */

$(document).ready( function() {
	$(".pagehelp").find("a").click( function() {
		var helpwindow = window.open(this.href, "HelpWindow", "height=500, width=500, resizable=0, location=0, scrollbars=1, status=0");
		if (helpwindow!=null){
			helpwindow.focus();
		}
		return false;
	});
});

$(document).ready( function() {
	$(".terms").find("a").click( function() {
		var helpwindow = window.open(this.href, "TermsWindow", "height=500, width=500, resizable=0, location=0, scrollbars=1, status=0");
		if (helpwindow!=null){
			helpwindow.focus();
		}
		return false;
	});
});

$(document).ready( function() {
	$(".listen").find("a").attr("href", "http://isi.phoneticom.com/cgi-bin/rsxt?customerid=1&url=" + location.href);
});


$( function() {
	$("form.slowload").submit( function() {
		var glasspane = $('#glasspane');
		if(glasspane.attr('id') == null)
			$('<div id="glasspane"></div>').appendTo($("body"));
		$('<div id="loadingpopup"><div class="row1"><img src="image/bluewait.gif" alt="Sidan laddas..."/></div><div class="row2">Sidan laddas...</div><div class="row3"><a href="#">Stäng</a></div></div>').appendTo($("body"));

		var glasspane = $('#glasspane');
		glasspane.css('opacity', '0.6');

		var popup = $('#loadingpopup');
		var windowWidth = $(window).width();
		var windowHeight = $(window).height();
		var popupHeight = popup.height();
		var popupWidth = popup.width();

		popup.css( {
		   'opacity' :'1.0',
		   'top' :'' + windowHeight / 2 - popupHeight / 2,
		   'left' :'' + windowWidth / 2 - popupWidth / 2
		});
		
		$('#loadingpopup a').click( function() {
			$('#glasspane').remove();
			$('#loadingpopup').remove();
		});
	})
	
	$("form.slowload").ready( function() {
		$('#loadingspan').remove();
	})	
});

$( function() {
	var inputs = $("form:not([class*=nofocus]) :input:visible").not(".nofocus");
	if (inputs.size()>0){
		for(var i=0 ; i<inputs.size();i++) {
			if(!inputs[i].disabled) {
				try {
					inputs[i].focus();
				} catch(err) {
				}
				break;
			}
		}
	}
})

function openInfoWindow(loc) {
	features = 
		   'toolbar=no, location=no, directories=no, status=yes, menubar=no, ' +
		   'scrollbars=yes, resizable=yes'; 
	menutitle=""
	window.open(loc,menutitle,features);
	return false;	
}

$(document).ready(
		function () {
			$(".hiddenloginlink").each(function () {
				//$(this).css("display","inline");
			});
		}
	);

$(document).ready(
		function() {
			$("#loginCornerButton").click( function() {
				$(".loginuppgifter").css("display","inline");
				$("#username").focus();
				$(".hiddenloginlink").css("display","none");
				return false;
			}
		);
	}
);