//-----------------------------------------------------------------------------------------
//ALTER ARRAY TO DETERMINE FILE TYPES THAT CAN BE UPLOADED
//Written By D Curnow
//-----------------------------------------------------------------------------------------
extArray = new Array(".gif", ".jpg", ".png");
var tooLarge = false;
var fileSize;
var MaxSize = 80;
var file;
function checkFile(form, file) 
{
allowSubmit = false;
if (!file) return false;

while (file.indexOf("\\") != -1)
file = file.slice(file.indexOf("\\") + 1);
ext = file.slice(file.indexOf(".")).toLowerCase();

		for (var i = 0; i < extArray.length; i++) 
		{
			if (extArray[i] == ext) 
			{ 
			allowSubmit = true; break; 
			}
		}

		if (allowSubmit) 
		{
			if(tooLarge==false)
			{
				form.submit();
			}
			else
			{
			alert('The image your are trying to add is too large\n\nPlease reduce the file size of the image and try again or use another image');
			}
		}
		else
		{
		alert("Please only upload files that end in types:  " 
		+ (extArray.join("  ")) + "\n\n"+file+" does not have the correct extension\n\nPlease select a new "
		+ "file to upload and submit again.");
		return false;
		}
}

				function changePrevImg(path)
				{
				allowSubmit = false;
				file=path;
				if (!file) return false;
				
				while (file.indexOf("\\") != -1)
				file = file.slice(file.indexOf("\\") + 1);
				ext = file.slice(file.indexOf(".")).toLowerCase();
				
					for (var i = 0; i < extArray.length; i++) 
					{
						if (extArray[i] == ext) 
						{ 
						allowSubmit = true; break; 
						}
					}
				
					if (allowSubmit) 
					{
				document.getElementById("previewBox").style.display = "";
				document.getElementById("prevImage").innerHTML='<img src="'+path+'" onLoad="checkImgSize(this.fileSize, this.width, this.height)">';			
					}
					else
					{
					alert("Please only upload files that end in types:  " 
					+ (extArray.join("  ")) + "\n\n"+file+" does not have the correct extension\n\nPlease select a new "
					+ "file to upload and submit again.");
					return false;
					}
				}
				
				function checkImgSize(kb,wx,hy)
				{
				var strTooLarge = "";
				kb = kb/1000;
				fileSize = kb;
				fileSize = Math.round(fileSize);
					if (kb > MaxSize)
					{
						tooLarge=true;
						strTooLarge = "   <b> - File size is greater than "+MaxSize+"kb this image cannot be uploaded</b>";
					}
					if (wx>520)
					{
						tooLarge=true;
						strTooLarge = strTooLarge+"<br><b>Width of  "+wx+" exceeds 520 pixels please reduce in size</b>";
					}
					if (hy>250)
					{
					tooLarge=true;
						strTooLarge = strTooLarge+"<br><b>Height "+hy+" exceeds 250 pixels please reduce in size</b>";
					}
					else
					{
						tooLarge=false;
						strTooLarge = "";
					}
				document.getElementById("ChosenImageDeets").innerHTML = '<br>File Name: '+file+'<br>File size: '+fileSize+'kb '+strTooLarge+'<br><br>';
				}