﻿$(document).ready(function () {
	$('.soktittel input').click(function () {
		var button = $(this);
		var webcontainer = $(button).parent().parent();
		var isShowing = false;
		$(webcontainer).find('#webhit').each(function () {

			if ($(this).attr('style') == "display: none;" || $(this).attr('style') == "DISPLAY: none"
            || $(this).attr('style') == "display: none") {
				$(this).show();
				isShowing = true;
			} else {
				$(this).hide();
			}
		});

		if (isShowing) {
			$(button).attr('src', '/Templates/CoBuilder/Styles/Images/semindre.gif')
		} else {
			$(button).attr('src', '/Templates/CoBuilder/Styles/Images/seflere.gif')
		}
		return false;
	});

	$('#morefilescontainer a').click(function () {

		var parent = $(this).parent().parent().parent();
		var repAllDocuments = $(parent).find('#repAllDocuments');
		var moreFilesContainer = $(parent).find('#morefilescontainer');

		if ($(repAllDocuments).attr('style') == "display: none;" || $(repAllDocuments).attr('style') == "DISPLAY: none"
        || $(repAllDocuments).attr('style') == "display: none") {
			$(repAllDocuments).show();
			$(this).parent().attr('style', 'display: none;');
			var mindre = $(moreFilesContainer).find('div.katmindre')
			$(mindre).show();
		} else {
			$(repAllDocuments).hide();
			$(this).parent().attr('style', 'display: none;');
			var flere = $(moreFilesContainer).find('div.katflere')
			$(flere).show();
		}
		return false;
	});

	$('.kattittel a').mouseover(function () {
		strID = $(this).attr('class');
		var popUpHtml = $("#bedinfo" + strID).html();
		$("#bedinfoinnhold" + strID).html(popUpHtml);
		$('#bedinfoboks' + strID).show();
		return false;
	});

	$('.kattittel').mouseleave(function () {
		return closeBedriftsInfoPopup();
	});

	$('div.popupfav').mouseleave(function () {
		return closeBedriftsInfoPopup();
	});

	$('.mfnavn a').mouseover(function () {
		strID = $(this).attr('class');
		var popUpHtml = $("#bedinfo" + strID).html();
		$("#bedinfoinnhold" + strID).html(popUpHtml);
		$('#bedinfoboks' + strID).show();
		return false;
	});

	$('.mfnavn').mouseleave(function () {
		return closeBedriftsInfoFavoritePopup();
	});

	$('div.popupfav2').mouseleave(function () {
		return closeBedriftsInfoFavoritePopup();
	});

	$('.minedoku a').click(function () {
		var parent = $(this).parent();
		$(parent).hide();
		var folders = $(parent).next();
		$(folders).show();
		return false;
	});

	$('.minedoc a').click(function () {
		var parent = $(this).parent();
		$(parent).hide();
		var folders = $(parent).next();
		$(folders).show();
		return false;
	});

	$('#mcobuilderiandreland a').click(function () {
		strID = $(this).attr('href');
		$("#intinnhold").load("/../Templates/CoBuilder/PopUps/International.htm " + strID);
		$('#intboks').show();
		return false;
	});

	$('#lukk').click(function () {
		$('#intboks').hide();
	});

	$('div.katcheck input').click(function () {
		$(this).prevAll().each(function () {
			if ($(this).attr('style') == 'display: none;' || $(this).attr('style') == 'DISPLAY: none') {
				$(this).show();
			} else {
				$(this).hide();
			}
		});
	});


});


function doHourglass() {
	document.body.style.cursor = 'wait';
}

function TryLogin() {
	var dropdownlist = $("#login").find('.loginlinje select');
	var selected = dropdownlist.find('option:selected');
	var selectedText = selected.text();
	var returnvalue = false;
	if (selectedText == 'Velg tjeneste') {
	    $('.ChooseServiceTextError').removeClass('novisible');
    return false; }
	if (selectedText == 'BASS') {
		SetHiddenFields();
    }
    else {
        if (!$('.ChooseServiceTextError').hasClass('novisible'))
            $('.ChooseServiceTextError').addClass('novisible');
		returnvalue = true;
	}
	return returnvalue;
}

function SetHiddenFields() {
	var username;
	var password;
	$("#login").find('.loginlinje input').each(function () {
		if ($(this).attr('tabindex') == 2) {
			username = $(this).val();
		} else if ($(this).attr('tabindex') == 3) {
			password = $(this).val();
		}
	});

	$("#hiddendiv").find('input').each(function () {
		if ($(this).attr('name') == 'user_name') {
			$(this).val(username);
		} else if ($(this).attr('name') == 'password') {
			$(this).val(password);
		}
	});

	document.forms[0].action = "http://hms.cobuilder.no/substance_library/validate_login.asp?ref=";
	document.forms[0].submit();
}

function tipsfriend() {
	$('#tipsinfo').show();
	$('#tipsinfoboks').show();
	return false;
}

function tipsfrienderror() {
	$('#tipserror').show();
	$('#tipsinfoboks').show();
	return false;
}

function tipsfriendsuccess() {
	$('#tipssuccess').show();
	$('#tipsinfoboks').show();
	return false;
}

function closepopup() {
	$('#tipsinfoboks').hide();
	return false;
}

function closeBedriftsInfoPopup() {
	$("#contentsok").find('.kattittel a').each(function (i) {
		strID = $(this).attr('class');
		$('#bedinfoboks' + strID).hide();
	});
	return false;
}

function closeBedriftsInfoFavoritePopup() {
	$("#content").find('.mfnavn a').each(function (i) {
		strID = $(this).attr('class');
		$('#bedinfoboks' + strID).hide();
	});
	return false;
}

function dropdownchanged(clientid) {
	var val = $(clientid).val();
	if (val == "+ Legg til mappe" || val == "+ Lägg till mapp") {
		$(clientid).hide();
		$(clientid).next().show();
	}
	return false;
};

function GetSearchQuery() {
	var query = $('#sokdiv input').val();
	$('#hiddenquerydiv input').val(query);
	return true;
}

