function helpme(wbv_id) {
	window.open("../Inschrijvingen/HelpWoningType.aspx?wbv="+wbv_id, "_blank", "toolbar=no,location=no,menubar=no,scrollbars=yes,width=720,resizable=yes,status=no");
}

function helpZoek() {
	window.open("HelpZoek.aspx", "_blank", "toolbar=no,location=no,menubar=no,scrollbars=yes,width=720,resizable=yes,status=no");
}

function popupWindow(Name, width, height) {
	style = "height=" + height + ",width=" + width + ", status=no, toolbar=no, menubar=yes, location=yes, scrollbars=yes, resizable=yes";
	open( Name, '_blank', style );
}

function popupMapWindow(Name, width, height) {
	style = "height=" + height + ",width=" + width + ", status=no, toolbar=no, menubar=no, location=no, scrollbars=no, resizable=no";
	open( Name, '_blank', style );
}

function toggle(obj) {
	//getObj(obj).style.display = (getObj(obj).style.display == "none") ? "block" : "none";
	$("#" + obj).slideToggle();
}

function getObj(obj) {
	return (document.getElementById) ? document.getElementById(obj) : document.all[obj];
}

function TopObjects(sVisibility) {
	oSelects = document.getElementsByTagName('SELECT');
	if (oSelects.length > 0) {
		for (i = 0; i < oSelects.length; i++) {
			oSelects[i].style.visibility = sVisibility;
		}
	}

	oObjects = document.getElementsByTagName('OBJECT');
	if (oObjects.length > 0) {
		for (i = 0; i < oObjects.length; i++) {
			oObjects[i].style.visibility = sVisibility;
		}
	}
}

function straalweg(sVisibility) {
	document.getElementById('ddstraalN').style.visibility = sVisibility;
}

function sendEmail(encodedEmail, advid)
{
	location.href = "mailto:" + decodeEmail(encodedEmail) + "?subject=Reactie Woningruil.nl op advertentienummer " + advid;
}

function decodeEmail(encodedEmail)
{
	var email = "";

	// go through and decode the email address
	for (i=0; i < encodedEmail.length;)
	{
		// holds each letter (2 digits)
		var letter = "";
		letter = encodedEmail.charAt(i) + encodedEmail.charAt(i+1)

		// build the real email address
		email += String.fromCharCode(parseInt(letter,16));
		i += 2;
	}
	return email;
}

function fotoVolgorde()
{
	$('#errornotice').hide();
	$('#fotosurvey_notice').fadeIn();
	$('#btn_add').hide();

	$('#volgordeWijzig').hide();
	$('#volgordeOpslaan').show();
	$('#volgordeOpslaan').attr('style', 'display: inline-block');
	$('#volgordeAnnuleren').show();
	$('#volgordeAnnuleren').attr('style', 'display: inline-block');

	$('.fotosurvey_item .wijzig').fadeOut('fast');
	$('.fotosurvey_item .verwijder').fadeOut('fast', function() {
		$('.fotosurvey_item .move').fadeIn('fast');
	});

	$('.fotosurvey_item').addClass('fotoMove');

	$('.fotosurvey_item input.foto').each(function() {
		$(this).hide();
		var img = $("<img>").attr('src', $(this).attr('src')).addClass('tempfoto');
		$(this).parent().append(img);
	});

	aangepast = false;
	$('.pnlFotoFoto').sortable({
		items: '.fotosurvey_item',
 		placeholder: 'fotoPlaceholder',
 		tolerance: 'pointer',
 		opacity: 0.6,
 		revert: true,
 		change: function(event, ui) { aangepast = true; }
 	});
 	$('.pnlFotoFoto').sortable('enable');
 	$('.pnlFotoFoto').disableSelection();
}

function fotoVolgordeOpslaan() {
	var newVolgorde = new String();
	var woningNr = 0;

	$('#fotosurvey_notice').hide();
	$('#btn_add').show();

	$('#volgordeWijzig').show();
	$('#volgordeOpslaan').hide();
	$('#volgordeAnnuleren').hide();

	$('.fotosurvey_item .move').hide();
	$('.fotosurvey_item .wijzig').fadeIn('fast');
	$('.fotosurvey_item .verwijder').fadeIn('fast');

	$('.fotosurvey_item').removeClass('fotoMove');

	$('.fotosurvey_item input.foto').each(function() {
		$(this).show();
	});
	$('.fotosurvey_item .tempfoto').remove();

	$('.fotosurvey_item .docid').each(function() {
		if (newVolgorde.length > 0) { newVolgorde += ","; }
		newVolgorde += $(this).html();
	});

	if ($('#rb_Won1').attr('checked') == true) { woningNr = 1; }
	if ($('#rb_Won2').attr('checked') == true) { woningNr = 2; }

	$.post('FotoVolgorde.ashx', { volgorde: newVolgorde, woningnr: woningNr },
		function(data) {
		    if (data != "1") {
		        $('#errornotice').html(data)
		        $('#errornotice').slideDown();
		    }
		    else { location.reload(); }
		});

	$('.pnlFotoFoto').sortable('destroy');
}

function fotoVolgordeAnnuleren() {

	$('#fotosurvey_notice').hide();
	$('#btn_add').show();

	$('#volgordeWijzig').show();
	$('#volgordeOpslaan').hide();
	$('#volgordeAnnuleren').hide();

	$('.fotosurvey_item .move').hide();
	$('.fotosurvey_item .wijzig').fadeIn('fast');
	$('.fotosurvey_item .verwijder').fadeIn('fast');

	$('.fotosurvey_item').removeClass('fotoMove');

	$('.fotosurvey_item input.foto').each(function() {
		$(this).show();
	});
	$('.fotosurvey_item .tempfoto').remove();

	if (aangepast) {
		$('.pnlFotoFoto').sortable('cancel');
	} else {
		$('.pnlFotoFoto').sortable('disable');
	}

}

$(document).ready(function() {

    $(".btnLogin").click(function(e) {
        e.preventDefault();
        $(".loginPanel").toggle(200);
        $(".btnLogin").toggleClass("menu-open");
    });

    $(".loginPanel").mouseup(function() {
        return false
    });
    $(document).mouseup(function(e) {
        if ($(e.target).parent("a.btnLogin").length == 0) {
            $(".btnLogin").removeClass("menu-open");
            $(".loginPanel").hide();
           
        }
    });
});