// JavaScript Document

//also handles contact.
//alert('Debug Testing: Called Javascript File');
var bigpic = 'NOT_SET';

function checkType (num_thumbs , array_of_nums)
{
	var num_of_thumbs = num_thumbs;
	var pull_array = array_of_nums;
	var array_of_thumbs = pull_array.split("o");
	var goodpic = true;
	for (i = 0; i < num_of_thumbs; i++)
	{
		for (n = 0; n < array_of_thumbs[i]; n++)
		{
			var cellname = i + "_" + n;
			var name = "image_" + cellname;
			var input = document.getElementById(name);
			if(input)
			{
				if (input.value != "") //first see if it exists at all.
				{
					if ((input.value.lastIndexOf(".jpg") == -1) && (input.value.lastIndexOf(".JPG") == -1)  )
					{
						goodpic = false;
					}
				}
			}
		}
	}
	if (!(goodpic))
	{
		alert("Please upload only .jpg files");
	}
	else 
	{
		document.appform.submit();
	}
}
function confirmDelete()
{
	var check = confirm("You have chosen to delete this entry.");
	if (check)
	{
		document.remove.submit();
	}
}

function makeBig (image, file, text, firstbig)
{
	if (bigpic == 'NOT_SET')
	{
		bigpic = firstbig;
	}
	var pass = image;
	var current = bigpic;
	var newtext = text;
	document.getElementById(pass).className = 'item_main_thide'; //make the new bigpic thumbnail disappear
	/*document.getElementById(pass).class = 'item_main_thide'; */
	document.getElementById("item_main_pic").src = "items/medium/" + file; //swap the larger image
	document.getElementById(current).className = 'item_main_tshow'; //make the old bigpic thumbnail show up
	/*document.getElementById(current).class = 'item_main_tshow';*/
	bigpic = pass;
	document.getElementById("main_pic_link").title = newtext;
	document.getElementById("main_pic_link").href = "items/large/" + file;
}

function checkfield(checkbox , field)
{
	var fieldname = field;
	var checkname = checkbox;
	var status = document.getElementById(checkname).checked;
	if (status)
	{
		document.getElementById(fieldname).className = 'formshow';
		/*document.getElementById(fieldname).class = 'formshow';*/
	}
	else
	{
		document.getElementById(fieldname).className = 'formhide';
		/*document.getElementById(fieldname).class = 'formhide';*/
	}
}
function contact_check()
{
	var passthrough = true;
	var emailstatus = document.contact_form.emailcheck.checked;
	var phonestatus = document.contact_form.phonecheck.checked;
	var humancheck = document.contact_form.human_check.value;
	if (humancheck == "")
	{
		passthrough = false;
	}
	if (!(phonestatus || emailstatus))
	{
		passthrough = false;
	}
	var name = document.contact_form.u_name.value;
	if (name == "")
	{
		passthrough = false;
	}
	var email = document.contact_form.email.value;
	var phone = document.contact_form.phone.value;
	if (emailstatus && (email == ""))
	{
		passthrough = false;
	}
	if (phonestatus && (phone == ""))
	{
		passthrough = false;
	}
	
	
	if (passthrough)
	{
		document.contact_form.submit();
	}
	if (passthrough == false)
	{
		alert ('Please fill out all required areas of the form.');
	}
}