var artsTable = "";
$("#link-arts").click(function()
{
	if(artsTable == "") {
		artsTable = $("<form method='post' action=''><table></table></form>");
		artsTbody = $("<tbody></tbody>");
		$(artsTbody).html("<tr><td class='table-data-left'>BIG-code: </td><td><input style='width: 150px;' type='password' name='bigcode' /></td></tr>");
		$(artsTbody).html($(artsTbody).html() + "<tr><td colspan='2' class='submit-error table-data-left'></td></tr>");
		$(artsTbody).html($(artsTbody).html() + "<tr><td></td><td class='table-data-left'><input type='submit' value=' ' class='link-inloggen' style='border: 0; margin-left: 0' /></td></tr>");
		
		$(artsTable).children().html(artsTbody);
		
		$(this).before(artsTable);
		$(artsTable).children().after($(""));
	}
	$(this).remove();
});

objectPatientGel = false;
objectPatient = false;
patientTable = "";
patientTableGel = "";

$("#link-patient, #link-patient-gel").click(function()
{
	oid = $(this).attr('id');
	if(oid == 'link-patient') {
		if(objectPatient)	{
			$(patientTable).parent().children().css("display", "none");
			
			$(patientTable).css("display", "block");
			$(patientTable).children().each(function()
			{
				$(this).css("display", "block");
				$(this).children().removeAttr('style');
				$(this).children().children().removeAttr('style');
			});
			return;
		} else {
			streepjes_img = "streepjescode.jpg";
			objectPatient = true;
		}
	} else if(oid == 'link-patient-gel') {
		if(objectPatientGel)	{
			$(patientTableGel).parent().children().css("display", "none");
			
			$(patientTableGel).css("display", "block");
			$(patientTableGel).children().each(function()
			{
				$(this).css("display", "block");
				$(this).children().removeAttr('style');
				$(this).children().children().removeAttr('style');
			});
			return;
		} else {
			streepjes_img = "streepjescode.jpg";
			objectPatientGel = true;
		}
	}
	tmpTable = $("<form method='post' action='' class='login-code'><table></table></form>");
	tmpTbody = $("<tbody></tbody>");
	imageObject = $(this).parent().children('img');
	
	$(tmpTbody).html("<tr><td colspan='2'><input type='hidden' name='fromform' value='" + oid + "' /><img src='" + $(imageObject).attr('src') + "' alt='" + $(imageObject).attr('alt') + "' class='" + $(imageObject).attr('class') + "' style='margin: 0' /></td></tr>");
	$(tmpTbody).html($(tmpTbody).html() +"<tr><td colspan='2' class='table-data-left'><img src='/images/" + streepjes_img + "' alt='streepjescode' /></td></tr>");
	$(tmpTbody).html($(tmpTbody).html() + "<tr><td class='table-data-left'>Vul hier de laatste 3 karakters van de streepjescode op de verpakking in: </td><td class='table-data-right'><input size='3' type='text' name='rvgnummer' maxlength='3' /></td></tr>");
	$(tmpTbody).html($(tmpTbody).html() + "<tr><td></td><td><input type='submit' value=' ' class='link-inloggen' style='border: 0' /></td></tr>");
	$(tmpTbody).html($(tmpTbody).html() + "<tr><td colspan='2' class='submit-error table-data-left'></td></tr>");
	$(tmpTbody).html($(tmpTbody).html() + "<tr><td class='table-data-left'><a href='#' class='overzicht'>Overzicht</a></td><td></td></tr>");
	
	$(tmpTable).children().append($(tmpTbody));
	parentObject = $(this).parent().parent().parent().parent();
	$(parentObject).children().css("display", "none");
	
	if(oid == "link-patient") {
		patientTable = $(tmpTable);
		$(parentObject).append($(tmpTable));
	} else if(oid == "link-patient-gel") {
		patientTableGel = tmpTable;
		$(parentObject).append(patientTableGel);
	}
	
	$('.overzicht').click(function() {
		container = $(this).parentsUntil('form').parent();
		$(container).parent().children().css("display", "block");
		$(container).css("display", "none");
		
	});
	$('.link-inloggen.submit').click(function() {
		$(this).parentsUntil('form').parent().submit();
	});
});
