/*
	::: preload images
*/
image = new Image();
image.src = "http://5.5inventory.org/img/ajax-loader.gif";


function toggleItem(box) {

    if (document.getElementById(box).style.display == 'none') {
        //document.getElementById(box).style.display = 'block';
		Effect.Appear(box);
    } else {
        //document.getElementById(box).style.display = 'none';
		Effect.Fade(box);
    }

	return false;
}

function checkform(form) {
	// see http://www.thesitewizard.com/archive/validation.shtml
	// for an explanation of this script and how to use it on your
	// own website

	// ** START **
	// documents
	if (form.title) {
		if (form.title.value == "") {
			Effect.Shake('title');
			alert( "The title is missing.\nPlease amend the form and try again." );
			form.title.focus();
			return false ;
		}
	}
	if (form.description) {
		if ((form.description.value == "")) {
			Effect.Shake('description');
			alert( "The description is missing.\nPlease select a file and try again." );
			form.description.focus();
			return false ;
		}
	}
	if (form.filename) {
		if (form.filename.value == "") {
			Effect.Shake('filename');
			alert( "The document to upload is missing.\nPlease select a file and try again." );
			form.filename.focus();
			return false ;
		}
	}
	if (form.tos) {
		if ((form.tos.checked == false)) {
			Effect.Shake('tos');
			alert( "You must agree to the terms of service first.\nPlease read the terms of service and try again." );
			form.tos.focus();
			return false ;
		}
	}

	// results
	if (form.season) {
		if (form.season.value == "") {
			Effect.Shake('season');
			alert( "The race's season is missing.\nPlease amend the form and try again." );
			form.season.focus();
			return false ;
		}
	}
	if (form.race) {
		if (form.race.value == "") {
			Effect.Shake('race');
			alert( "The race's name is missing.\nPlease amend the form and try again." );
			form.race.focus();
			return false ;
		}
	}
	if (form.location) {
		if (form.location.value == "") {
			Effect.Shake('location');
			alert( "The race's location is missing.\nPlease amend the form and try again." );
			form.location.focus();
			return false ;
		}
	}

	// links
	if (form.asset) {
		if ((form.asset.value == "http://") || (form.asset.value == "")) {
			Effect.Shake('asset');
			alert( "The link's URL is missing.\nPlease amend the form and try again." );
			form.asset.focus();
			return false ;
		}
	}

	// notes
	if (form.note) {
		if (form.note.value == "") {
			Effect.Shake('note');
			alert( "The note is missing.\nPlease amend the form and try again." );
			form.note.focus();
			return false ;
		}
	}

	// notes
	if (form.firstname) {
		if (form.firstname.value == "") {
			Effect.Shake('firstname');
			alert( "Your firstname is missing.\nPlease amend the form and try again." );
			form.firstname.focus();
			return false ;
		}
	}
	if (form.lastname) {
		if (form.lastname.value == "") {
			Effect.Shake('lastname');
			alert( "Your lastname is missing.\nPlease amend the form and try again." );
			form.lastname.focus();
			return false ;
		}
	}
	if (form.email) {
		if (form.email.value == "") {
			Effect.Shake('email');
			alert( "Your e-mail address is missing.\nPlease amend the form and try again." );
			form.email.focus();
			return false ;
		}
	}
	// ** END **

	showLoading();
	return true ;
}

function checkpasswdform(form) {
	// see http://www.thesitewizard.com/archive/validation.shtml
	// for an explanation of this script and how to use it on your
	// own website

	// ** START **
	if (form.oldpassword.value == "") {
		Effect.Shake('oldpassword');
		alert( "Your current password is missing.\nPlease try again." );
		form.oldpassword.focus();
		return false ;
	}
	if (form.newpassword.value == "") {
		Effect.Shake('newpassword');
		alert( "Your new password is missing.\nPlease try again." );
		form.newpassword.focus();
		return false ;
	}
	if (form.confirmation.value == "") {
		Effect.Shake('confirmation');
		alert( "The confirmation of your new password is missing.\nPlease  try again." );
		form.confirmation.focus();
		return false ;
	}
	if (form.confirmation.value != form.newpassword.value) {
		Effect.Shake('confirmation');
		alert( "Your new password and its confirmation are different.\nPlease try again." );
		form.newpassword.focus();
		return false ;
	}
	// ** END **

	showLoading();
	return true ;
}

function showLoading() {
		
	if (!document.getElementById) return false;
	var button = document.getElementById("buttons");	// submit button
/*
	var image = document.getElementById("progress");	// animated GIF

	button.style.display = "none";	// hide button
	image.style.display = "block";	// show loading animated GIF
*/
	button.innerHTML = '<img src="/img/ajax-loader.gif" alt="Uploading file and related information to server.." title="Uploading file and related information to server.."  /> Uploading file and related information to server..';

	return true;
}

function ToggleTableList() {
	
    if (document.getElementById('reorder_div').style.display == 'none') {
		Element.toggle('upload_div');
		Element.toggle('table_docs');
		Element.toggle('reorder_div');
		return false;
    } else {
		//Element.toggle('list_docs');
		//Element.toggle('table_docs');
		return true;
    }

	return false;
}

function toggleAble(element) {
    
    if (!document.getElementById) return true;			// do it the php way
	if (!document.getElementsByClassName) return true;	// do it the php way

	// (1) get all elements with the 'commodity' class
	select = document.getElementsByClassName(element);
	for(i=0; i<select.length; i++) {

        if (select[i].disabled== true) {
            
            select[i].disabled=false;
        }
        else {
            
            select[i].disabled=true;
        }
	}
	
	return false;
}

