/****************************************************************************************************/
/*
Setup Repository System
Copyright (C) 2010  Kevin Burns, Burnsy Enterprises

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/
/****************************************************************************************************/

var oTable;

$(document).ready(function(){
	$("#loginform").validate(
	{
		rules:
		{
			uname: "required",
			pwd: "required"
		},
		messages:
		{
			uname: "Please enter your username",
			pwd: "Please enter your password"
		}
	});
	
	$("#registerform").validate(
	{
		rules:
		{
			uname: {
				required: true,
				minlength: 5
			},
			pwd: {
				required: true,
				minlength: 5
			},
			email: {
				required: true,
				email: true
			},
			name: {
				required: true
			}
		},
		messages:
		{
			uname: {
				required: "Please enter a username",
				minlength: "Your username must be at least 5 characters long"
			},
			pwd: {
				required: "Please enter a password",
				minlength: "Your password must be at least 5 characters long"
			},
			email:"Please enter a valid email address",
			name: "Please enter a display name."
		}
	});
	
	/*$('#uploadedby').val("<? echo $user->get_property('name')?>");*/
	$('#toggle').click(function() {
		$('#reminders').toggle("slow");
	} );
	
	$('#time').mask("99:99.999");
	
	var iRuploadoptions = {
		target: '#iRuploadoutput',
		beforeSubmit: beforeiRupload,
		success: afteriRupload
	};
	$('#iRupload').submit(function () {
		$(this).ajaxSubmit(iRuploadoptions);
		return false;
	} );
	
	var lfsuploadoptions = {
		target: '#lfsuploadoutput',
		beforeSubmit: beforelfsupload,
		success: afterlfsupload
	};
	$('#lfsupload').submit(function () {
		$(this).ajaxSubmit(lfsuploadoptions);
		return false;
	} );
	
	var irsearchoptions = {
		target: '#searchoutput',
		beforeSubmit: beforeiRsearch,
		success: afteriRsearch
	};
	$('#irsearchform').submit(function () {
		$(this).ajaxSubmit(irsearchoptions);
		return false;
	} );
	
	var lfssearchoptions = {
		target: '#searchoutput',
		beforeSubmit: beforelfssearch,
		success: afterlfssearch
	};
	$('#lfssearchform').submit(function () {
		$(this).ajaxSubmit(lfssearchoptions);
		return false;
	} );
	
	// 
	$('#userstable').dataTable( {
		"bJQueryUI": true,
		"sPaginationType": "full_numbers",
	} );
	
	$('.help button:first').button( {
		icons: { primary: 'ui-icon-document' }
	} ).next().button( {
		icons: { primary: 'ui-icon-document' }
	} ).next().button( {
		icons: { primary: 'ui-icon-document' }
	} ).next().button( {
		icons: { primary: 'ui-icon-document' }
	} ).next().button( {
		icons: { primary: 'ui-icon-document' }
	} ).next().button( {
		icons: { primary: 'ui-icon-document' }
	} );
} );

function beforeiRupload(formData, jqForm, options) {
	var form = jqForm[0];
	if(form.car.value == "All" || form.track.value == "All" || form.type.value == "All")
	{
		alert('The option of \"All\" can not be used, please choose a different option.\nIf no option suits the setup, use \"N/A\".');
		return false;
	}
	
	$('div.iRuploadblock').block({ 
		message: '<h3>Processing</h3>', 
		css: { border: '3px solid #a00' } 
	});

	return true; 
} 

function afteriRupload(responseText, statusText)  {
	$('div.iRuploadblock').unblock();
}

function beforelfsupload(formData, jqForm, options) {
	var form = jqForm[0];
	if(form.car.value == "All" || form.track.value == "All" || form.class.value == "All" || form.type.value == "All")
	{
		alert('The option of \"All\" can not be used, please choose a different option.\nIf no option suits the setup, use \"N/A\".');
		return false;
	}
	
	$('div.lfsuploadblock').block({ 
		message: '<h3>Processing</h3>', 
		css: { border: '3px solid #a00' } 
	});

	return true; 
} 

function afterlfsupload(responseText, statusText)  {
	$('div.lfsuploadblock').unblock();
}

function beforeiRsearch(formData, jqForm, options) {
	$('div.iRsearchblock').block({ 
		message: '<h3>Processing</h3>', 
		css: { border: '3px solid #a00' } 
	});

	return true; 
} 

function afteriRsearch(responseText, statusText)  { 
	$('div.iRsearchblock').unblock();
	
	$('#iRsearchtable').dataTable( {
		"bJQueryUI": true,
		"sPaginationType": "full_numbers",
	} );
}

function beforelfssearch(formData, jqForm, options) { 
	$('div.lfssearchblock').block({ 
		message: '<h3>Processing</h3>', 
		css: { border: '3px solid #a00' } 
	});

	return true; 
} 

function afterlfssearch(responseText, statusText)  { 
	$('div.lfssearchblock').unblock();
	
	$('#lfssearchtable').dataTable( {
		"bJQueryUI": true,
		"sPaginationType": "full_numbers",
	} );
}