
function getDocHeight(doc)
{
	var docHt = 0, sh, oh;
	if (doc.height) docHt = doc.height;
	else if (doc.body)
	{
		if (doc.body.scrollHeight) docHt = sh = doc.body.scrollHeight;
		if (doc.body.offsetHeight) docHt = oh = doc.body.offsetHeight;
		if (sh && oh) docHt = Math.max(sh, oh);
	}
	return docHt;
}

function setIframeHeight(iframeName)
{
	var iframeWin = window.frames[iframeName];
	var iframeEl = document.getElementById? document.getElementById(iframeName): document.all? document.all[iframeName]: null;
	if ( iframeEl && iframeWin )
	{
		iframeEl.style.height = "auto";
		var docHt = getDocHeight(iframeWin.document);
		if (docHt) iframeEl.style.height = docHt + 30 + "px";
	}
}

function loadIframe(iframeName, url)
{
	if ( window.frames[iframeName] )
	{
		window.frames[iframeName].location = url;   
		return false;
	}
	else return true;
}



/* Application Form Items */




function chkSpec(formVal,trueTR,falseTR)
{
	var trueObj = document.getElementById(trueTR);
	var falseObj = document.getElementById(falseTR);
	
	if(formVal.value == 1)
	{
		trueObj.style.display = "";
		falseObj.style.display = "none";
	}
	if(formVal.value == 0)
	{
		trueObj.style.display = "none";
		falseObj.style.display = "";
	}
}




function chkMailing(element)
{
	var trObj = document.getElementById('mailaddrTR');
	if(element.checked == true)
	{
		trObj.style.display = "";
	}
	if(element.checked == false)
	{
		trObj.style.display = "none";
	}
}
function chkBool(element,tr)
{
	var trObj = document.getElementById(tr);
	if(element.value == 1)
	{
		trObj.style.display = "";
	}
	if(element.value == 0)
	{
		trObj.style.display = "none";
	}
}
function chkBoolNo(element,tr)
{
	var trObj = document.getElementById(tr);
	if(element.value == 0)
	{
		trObj.style.display = "";
	}
	if(element.value == 1)
	{
		trObj.style.display = "none";
	}
}

function showHide(el)
{
	var elObj = document.getElementById(el);
	if(elObj.style.display == "none")
	{
		elObj.style.display = "";
		if(document.getElementById('bullet'))
		{
			swapImage('bullet','','/images/img_bulletarrow_down.gif',0);
		}
	}
	else
	{
		elObj.style.display = "none";
		if(document.getElementById('bullet'))
		{
			swapImage('bullet','','/images/img_bulletarrow.gif',0);
		}
	}
}




/* Image Preloader */
function preloadImages()
{
	var d=document; if(d.images){ if(!d.p) d.p=new Array();
	var i,j=d.p.length,a=preloadImages.arguments; for(i=0; i<a.length; i++)
	if (a[i].indexOf("#")!=0){ d.p[j]=new Image; d.p[j++].src=a[i];}}
}

/* Find Element on Page */
function findObj(n, d)
{
	var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
	d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
	if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
	for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=findObj(n,d.layers[i].document);
	if(!x && document.getElementById) x=document.getElementById(n); return x;
}

/* Mouseover Function */
function swapImage()
{
	var i,j=0,x,a=swapImage.arguments; document.sr=new Array; for(i=0;i<(a.length-2);i+=3)
	if ((x=findObj(a[i]))!=null){document.sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

/* Mouseover Function: Restore */
function swapImgRestore()
{
	var i,x,a=document.sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

/* Redirect */
function goToURL()
{
	var i, args=goToURL.arguments; document.returnValue = false;
	for (i=0; i<(args.length-1); i+=2) eval(args[i]+".location='"+args[i+1]+"'");
}

/* Popup Window */
function spawnWindow(theURL,winName,features,posX,posY)
{
	myWindow=window.open(theURL,winName,features);
	if (!myWindow.opener) myWindow.opener = self;
	myWindow.focus();
	if(posX || posY)
	{
		myWindow.moveTo(posX,posY);
	}
}

/* Get Window Size */
function getWinSize()
{
	if ((document.layers||document.getElementById)&&(!document.all))
	{
		winWidth = innerWidth;
		winHeight = innerHeight;
	}
	if (document.all)
	{
		winWidth = document.body.clientWidth;
		winHeight = document.body.clientHeight-3;
	}
}

/* Set DIV visiblity/invisibility */
function toggleVisibility(id, NNtype, IEtype, WC3type)
{
	if (document.getElementById)
	{
		eval("document.getElementById(id).style.visibility = \"" + WC3type + "\"");
	}
	else
	{
		if (document.layers)
		{
			document.layers[id].visibility = NNtype;
		}
		else
		{
			if (document.all)
			{
				eval("document.all." + id + ".style.visibility = \"" + IEtype + "\"");
			}
		}
	}
}
			
/* Mmmm... Coookies! */
function setCookie(name, value, expires, path, domain, secure)
{
	var curCookie = name + "=" + escape(value) +
	((expires) ? "; expires=" + expires.toGMTString() : "") +
	((path) ? "; path=" + path : "") +
	((domain) ? "; domain=" + domain : "") +
	((secure) ? "; secure" : "");
	document.cookie = curCookie;
}			
function getCookie(name)
{
	var dc = document.cookie;
	var prefix = name + "=";
	var begin = dc.indexOf("; " + prefix);
	if (begin == -1)
	{
		begin = dc.indexOf(prefix);
		if (begin != 0) return null;
	}
	else
	{
		begin += 2;
		var end = document.cookie.indexOf(";", begin);
		if (end == -1)
		end = dc.length;
		return unescape(dc.substring(begin + prefix.length, end));
	}	
}
function deleteCookie(name, path, domain)
{
	if (getCookie(name))
	{
		document.cookie = name + "=" + ((path) ? "; path=" + path : "") + ((domain) ? "; domain=" + domain : "") + "; expires=Thu, 01-Jan-70 00:00:01 GMT";
	}
}

/* Goto Menu Function */
function jumpMenu(targ,selObj,restore)
{
	if(selObj.options[selObj.selectedIndex].value != "#")
	{
		eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
	}
	if (restore) selObj.selectedIndex=0;
}

/* ====================================	*/
/* [S> Handy Form Utils					*/
/* ==================================== */
var arrOldValues;

function SelectAllList(CONTROL)
{
	for(var i = 0;i < CONTROL.length;i++)
	{
		CONTROL.options[i].selected = true;
	}
}

function DeselectAllList(CONTROL)
{
	if(CONTROL.options)
	{
		for(var i = 0;i < CONTROL.length;i++)
		{
			CONTROL.options[i].selected = false;
		}
	}	
}

function FillListValues(CONTROL)
{
	var arrNewValues;
	var intNewPos;
	var strTemp = GetSelectValues(CONTROL);
	arrNewValues = strTemp.split(",");
	for(var i=0;i<arrNewValues.length-1;i++)
	{
		if(arrNewValues[i]==1)
		{
			intNewPos = i;
		}
	}

	for(var i=0;i<arrOldValues.length-1;i++)
	{
		if(arrOldValues[i]==1 && i != intNewPos)
		{
			CONTROL.options[i].selected= true;
		}
		else if(arrOldValues[i]==0 && i != intNewPos)
		{
			CONTROL.options[i].selected= false;
		}
		if(arrOldValues[intNewPos]== 1)
		{
			CONTROL.options[intNewPos].selected = false;
		}
		else
		{
			CONTROL.options[intNewPos].selected = true;
		}
	}
}

function GetSelectValues(CONTROL)
{
	var strTemp = "";
	for(var i = 0;i < CONTROL.length;i++)
	{
		if(CONTROL.options[i].selected == true)
		{
			strTemp += "1,";
		}
		else
		{
			strTemp += "0,";
		}
	}
	return strTemp;
}

function GetCurrentListValues(CONTROL)
{
	var strValues = "";
	strValues = GetSelectValues(CONTROL);
	arrOldValues = strValues.split(",")
}
	
function CheckAll()
{
	void(d=document);
	void(el=d.getElementsByTagName('INPUT'));
	for(i=0;i<el.length;i++)
	{
		void(el[i].checked=1);
		Toggle(el[i]);
	}
}

function UncheckAll()
{
	void(d=document);
	void(el=d.getElementsByTagName('INPUT'));
	for(i=0;i<el.length;i++)
	{
		void(el[i].checked=0);
		Toggle(el[i]);
	}
}

function Highlight(e)
{
	var r = null;
	if(e.parentNode && e.parentNode.parentNode)
	{
		r = e.parentNode.parentNode;
	}
	else if(e.parentElement && e.parentElement.parentElement)
	{
		r = e.parentElement.parentElement;
	}
	if(r)
	{
		if(r.className == "listeven")
		{
			r.className = "listevensel";
		}
		else if(r.className == "listodd")
		{
			r.className = "listoddsel";
		}
	}
}

function Unhighlight(e)
{
	var r = null;
	if(e.parentNode && e.parentNode.parentNode)
	{
		r = e.parentNode.parentNode;
	}
	else if(e.parentElement && e.parentElement.parentElement)
	{
		r = e.parentElement.parentElement;
	}
	if(r)
	{
		if(r.className == "listevensel")
		{
			r.className = "listeven";
		}
		else if(r.className == "listoddsel")
		{
			r.className = "listodd";
		}
	}
}	
	
function Toggle(e)
{
	if(e.checked)
	{
		Highlight(e);
	}
	else
	{
		Unhighlight(e);
	}
}
/* ====================================	*/
/* [S> Handy Form Utils					*/
/* ==================================== */

/* [S> Multi-form element select (for split multi-selects using different form elements) */
function SelectMoveRows(SS1,SS2,move)
{
	var SelID='';
	var SelText='';
	var ItemExists='';
	/* Move rows from SS1 to SS2 from bottom to top */
	for (i=SS1.options.length - 1; i>=0; i--)
	{
		if (SS1.options[i].selected == true)
		{
			SelID=SS1.options[i].value;
			SelText=SS1.options[i].text;

			/* Scan Option/Value Pairs in Destination - If it's new, add option */
			for (j = 0; j < SS2.options.length; j++)
			{
				if( (SelID == SS2.options[j].value) && (SelText == SS2.options[j].text) )
				{
					ItemExists = 1;
				}
			}
			
			/* If Item wasn't there, Add it */
			if(ItemExists != 1)
			{
				var newRow = new Option(SelText,SelID);
				SS2.options[SS2.length]=newRow;
			}
			if(move)
			{
				SS1.options[i]=null;
			}
		}
	}
}

function SelectSort(SelList)
{
	var ID='';
	var Text='';
	for (x=0; x < SelList.length - 1; x++)
	{
		for (y=x + 1; y < SelList.length; y++)
		{
			if (SelList[x].text > SelList[y].text)
			{
				/* Swap rows */
				ID=SelList[x].value;
				Text=SelList[x].text;
				SelList[x].value=SelList[y].value;
				SelList[x].text=SelList[y].text;
				SelList[y].value=ID;
				SelList[y].text=Text;
			}
		}
	}
}
	
function ConfirmSelect(SelList)
{
	for (x=0; x < SelList.length; x++)
	{
		SelList.options[x].selected = true
	}
}
/* <E] Multi-form element select (for split multi-selects using different form elements) */

/* [S> Move Items up & down in Select Lists (for items in functions above) */
function moveUpList(listField)
{
	if ( listField.length == -1) /* If the list is empty */
	{
		alert("There are no values which can be moved!");
	}
	else
	{
		var selected = listField.selectedIndex;
		if (selected == -1)
		{
			alert("You must select an entry to be moved!");
		}
		else /* Something is selected */
		{  
			if ( listField.length == 0 ) /* If there's only one in the list */
			{  
				alert("There is only one entry!\nThe one entry will remain in place.");
			}
			else /* There's more than one in the list, rearrange the list order */
			{
				if ( selected == 0 )
				{
					alert("The first entry in the list cannot be moved up.");
				}
				else
				{
					/* Get the text/value of the one directly above the hightlighted entry as well as the highlighted entry; then flip them */
					var moveText1 = listField[selected-1].text;
					var moveText2 = listField[selected].text;
					var moveValue1 = listField[selected-1].value;
					var moveValue2 = listField[selected].value;
					listField[selected].text = moveText1;
					listField[selected].value = moveValue1;
					listField[selected-1].text = moveText2;
					listField[selected-1].value = moveValue2;
					listField.selectedIndex = selected-1; /* Select the one that was selected before */
				}
			}
		}
	}
}

function moveDownList(listField)
{
	if ( listField.length == -1) /* If the list is empty */
	{
		alert("There are no values which can be moved!");
	}
	else
	{
		var selected = listField.selectedIndex;
		if (selected == -1)
		{
			alert("You must select an entry to be moved!");
		}
		else /* Something is selected */
		{
			if ( listField.length == 0 ) /* If there's only one in the list */
			{
				alert("There is only one entry!\nThe one entry will remain in place.");
			}
			else /* There's more than one in the list, rearrange the list order */
			{
				if ( selected == listField.length-1 )
				{
					alert("The last entry in the list cannot be moved down.");
				}
				else
				{
					/* Get the text/value of the one directly below the hightlighted entry as well as the highlighted entry; then flip them */
					var moveText1 = listField[selected+1].text;
					var moveText2 = listField[selected].text;
					var moveValue1 = listField[selected+1].value;
					var moveValue2 = listField[selected].value;
					listField[selected].text = moveText1;
					listField[selected].value = moveValue1;
					listField[selected+1].text = moveText2;
					listField[selected+1].value = moveValue2;
					listField.selectedIndex = selected+1; /* Select the one that was selected before */
				}
			}
		}
	}
}
/* <E] Move Items up & down in Select Lists (for items in functions above) */


function setOpacity(obj, opacity) 
{
  opacity = (opacity == 100)?99.999:opacity;
  

  obj.style.filter = "alpha(opacity:"+opacity+")";

  obj.style.KHTMLOpacity = opacity/100;
  

  obj.style.MozOpacity = opacity/100;

  obj.style.opacity = opacity/100;
}

function fadeIn(objId,opacity) 
{
  if (document.getElementById) 
  {
    obj = document.getElementById(objId);
    if (opacity <= 100) 
    {
      setOpacity(obj, opacity);
      opacity += 10;
      window.setTimeout("fadeIn('"+objId+"',"+opacity+")", 100);
    }
  }
}

function fadeOut(objId,opacity)
{
   if (document.getElementById)
   {
      obj = document.getElementById(objId);
      if (opacity > 0)
      {
         setOpacity(obj, opacity);
         opacity -= 10;
         window.setTimeout("fadeOut('" + objId + "'," + opacity + ")", 100);
      }
      else
      {
         var nextImage = Math.ceil(Math.random() * 20);
         obj.src ="images/gallery/" + nextImage + ".jpg";
         fadeIn(objId, 0);
      }
   }
}

function changeImage()
{
   var image_number = Math.ceil(Math.random() * 4);
   var image_id = 'photo' + image_number;
   image = document.getElementById(image_id);
   fadeOut(image_id, 100);
}


