﻿$(document).ready(function() {
	
	$("#picture-viewer").click(function() {
		//$("table").css("margin-top", "0px");
		$("#picture-viewer").hide();
		
	});
	
	$("td img").click(function() {
		//$("table").css("margin-top", "470px");
		$("table td img").removeClass('selected');
		$(this).addClass('selected');
	 
		$("#picture-viewer").show();
		name = $(this).attr('src');
		name = name.substr( name.lastIndexOf("/")+1 ); // Remove leading path
		$("#picture-viewer div").html('<img src="slir/w395-h760/studio220/' + path + name + '" />');
		name = name.substr( 0, name.lastIndexOf(".") ); // Remove file extenstion
		$("#picture-viewer h2").html(name);
	});

});

function check_login() {

	$.ajax({
		type: "POST",
		url: "test_login.php",
		data: "email=" + $("input#email").val() + "&password=" + $("input#password").val(),
		success: function(msg){
			msg = jQuery.trim(msg); // Trim out whitespaces and line breaks
			
			if( msg == 'false' ) val = 0;
			else val = 1;
			
			if( val ) {
				window.location = "session.php?email=" + $("input#email").val() + "&password=" + $("input#password").val() ;
				}
			else {
				$("div.denied").show();
			}
			
		}
	});

	return false;
}

function verify_login(email, password) {

	$.ajax({
		type: "POST",
		url: "test_login.php",
		data: "email=" + email + "&password=" + password,
		success: function(msg){
			msg = jQuery.trim(msg); // Trim out whitespaces and line breaks
			
			if( msg == 'false' ) val = 0;
			else val = 1;

			if( !val ) {
				window.location = ".";
			}
			
		}
	});

	return false;
}
