
// globals ///////////////////////////////////

var bgColour;
var textColour;
var rowBorder;
var classTemp;

var objSel = null;
var intGalleryCurrentIndex = 0;

// globals ///////////////////////////////////

function CheckVal(obj)
{
	return (obj.value != "") && (obj.value != null);
}

function validateForm(f)
{
	var bFormValid = true;

	f.emailto.value = "curry_county_council@yahoo.co.uk";

	if (f.subject.value == "general")
	{
		f.subject.value = "CCC: " + f.SENDER_ADDRESS.value;
		if (!CheckVal(f.REQUEST))
		{
			alert("Please complete the form.");
			bFormValid = false;
		}
	}
	else if (f.subject.value == "mailing list")
	{
		f.subject.value = "Mailing List: " + f.SENDER_ADDRESS.value;		
	}
	
	if (!CheckVal(f.SENDER_ADDRESS))
	{
		alert("Please complete the email address.");
		bFormValid = false;
	}

	return formValid;
}

function swapIn(objTD) 
{
	bgColour = objTD.style.backgroundColor;
	textColour = objTD.style.color;
	objTD.style.backgroundColor = "red";
	objTD.style.color = "white";
}

function swapOut(objTD) 
{
	objTD.style.backgroundColor = bgColour;//"#cccccc";
	objTD.style.color = textColour; //"black";
}

function swapInBorder(objTD) 
{
	rowBorder = objTD.style.border;
	objTD.style.border = "thin solid black";
}

function swapOutBorder(objTD) 
{
	objTD.style.border = rowBorder;
}

function swapInClass(objTD) 
{
	classTemp= objTD.className;
	objTD.className = "cssHighlight";
}

function swapOutClass(objTD) 
{
	objTD.className = classTemp;
}

function linkTo(strURL)
{
	window.location = strURL;
}

function linkTo_WithGet(strURL, strGet)
{
	window.location = strURL + strGet;
}

function linkToIf(strUSER, strINVALID_USER, strURL, strINVALID_URL)
{
	if (strUSER != strINVALID_USER)
	{
		window.location = strURL;
	}
	else
	{
		window.location = strINVALID_URL;		
	}
}

function returnTo(strPage)
{
	opener.location = strPage;
	self.close();
}

function setObjectColour(objSelected, objDoc, strName, rgbColour)
{
	if (objSel != null)
	{
		objSel.style.border = "none";
	}
	objSelected.style.border = "solid #000000";
	var listElements = objDoc.getElementsByName(strName);
	
	listElements[0].style.backgroundColor = rgbColour;
	listElements[0].style.color = rgbColour;
	listElements[0].value = rgbColour;
	objSel = objSelected;
}

function getPageCoords (objElement) 
{
     var coords = { x: 0, y: 0 };
     while (objElement) 
     {
       coords.x += objElement.offsetLeft;
       coords.y += objElement.offsetTop;
       objElement = objElement.offsetParent;
     }
     return coords;
} 

function gallery_MoveNext()
{
	intGalleryCurrentIndex++;
}

function gallery_MovePrev()
{
	if (intGalleryCurrentIndex > 0)
	{
		intGalleryCurrentIndex--;
	}
}

function gallery_ShowCurrentImage()
{
	var objSelectObj = document.getElementById("galleryImages")	
	var strImg = '/images/' + objSelectObj.options[intGalleryCurrentIndex].value;
	document.getElementById("currentImage").src = strImg;
}


function gallery_MouseOver(obj)
{
	if (obj.id = "showprev" && intGalleryCurrentIndex >= 0)
	{
		swapIn(obj);
	}
	else if (obj.id = "shownext")
	{
		swapIn(obj);
	}
}

function gallery_MouseOut(obj)
{
	if (obj.id = "showprev" && intGalleryCurrentIndex >= 0)
	{
		swapOut(obj);
	}
	else if (obj.id = "shownext")
	{
		swapOut(obj);
	}
}

function confirmLinkTo(linkobj, ifYes, ifNo)
{	
	linkobj.href = confirm("Are you sure?") ? ifYes : ifNo;
}

function DefaultFormValidation(f)
{
	return true;
}

function ValidateEventDate(objForm)
{
	var bool_Valid = true;
	
	var theDate = objForm.date.value;
	
	bool_Valid &= (theDate.length == 10);
	
	var int_Day = Number(theDate.substr(0, 2));
	bool_Valid &= int_Day <= 31 && int_Day >= 1;
	
	var int_Month = Number(theDate.substr(3, 2));
	bool_Valid &= int_Month <= 12 && int_Month>= 1;

	var date_today = new Date();
	var int_Year = Number(theDate.substr(6, 4));
	var int_yearDiff = int_Year - date_today.getFullYear();
	
	bool_Valid &= (int_yearDiff >= 0) && (int_yearDiff <= 1);
	
	if (!bool_Valid)
	{
		alert("Date is invalid!");
	}
	
	return bool_Valid;
}


function ToggleDisplay_TD(imgNode, nodeId)
{
	node = document.getElementById(nodeId);
	
	if (node.style.display != "none")
	{
		imgNode.innerHTML = "+"; //+
		node.style.display = "none";
	}
	else
	{
		imgNode.innerHTML = "-"; //-
		try
		{
			node.style.display = "table-cell"; // ie doesn't like this ...
		}
		catch(err)
		{
			node.style.display = "block";
		}
	}
}

function LoadPage()
{
	// normally nothing required
}

