function setFocuslogin()
{
	document.forms['login'].username.focus();
}
function sfAddNews(){document.addNews.title.focus();}
function sfAddUser(){document.addUser.firstname.focus();}
function sfUserPrefs(){document.userPrefs.firstname.focus();}
function sfActivateUser(){document.activateUser.username.focus();}
function sfAddCat(){document.addCat.category.focus();}
function sfRenameCat(){document.renameCat.category.focus();}

function PopupPic(sPicURL,cat,ptype)
{
	ptype = ptype || "";
	if(ptype == "news")
		window.open("photo_details.php?image="+escape(sPicURL)+"&newsid="+escape(cat)+"&sh="+window.screen.height,"","resizable=1,height=800,width=800");
	else
		window.open("photo_details.php?image="+escape(sPicURL)+"&category="+escape(cat)+"&sh="+window.screen.height,"","resizable=1,height=800,width=800");
}

function editcaptionpop(capurl)
{
	window.open( capurl, "","resizable=1,height=200,width=300");
}

function editcategorypop(caturl)
{
	window.open( caturl, "","scrollbars=1,resizable=1,height=400,width=200");
}

function winCloseRefresh(rURL)
{
	opener.location.href=rURL;
	window.close();
}

function toggleLayer(whichLayer)
{
	if (document.getElementById)
	{
		// this is the way the standards work
		var style2 = document.getElementById(whichLayer).style;
		style2.display = style2.display? "":"block";
	}
	else if (document.all)
	{
		// this is the way old msie versions work
		var style2 = document.all[whichLayer].style;
		style2.display = style2.display? "":"block";
	}
	else if (document.layers)
	{
		// this is the way nn4 works
		var style2 = document.layers[whichLayer].style;
		style2.display = style2.display? "":"block";
	}
}

function toggleLayerReturn(whichLayer)
{
	if (document.getElementById)
	{
		// this is the way the standards work
		var style2 = document.getElementById(whichLayer).style;
		style2.display = style2.display? "":"block";
		if (style2.display)
		{
			return true;
		}
		else
		{
			return false;
		}
	}
	else if (document.all)
	{
		// this is the way old msie versions work
		var style2 = document.all[whichLayer].style;
		style2.display = style2.display? "":"block";
		if (style2.display)
		{
			return true;
		}
		else
		{
			return false;
		}
	}
	else if (document.layers)
	{
		// this is the way nn4 works
		var style2 = document.layers[whichLayer].style;
		style2.display = style2.display? "":"block";
		if (style2.display)
		{
			return true;
		}
		else
		{
			return false;
		}
	}
}

function toggleLayersCommentEditor(whichLayer)
{
	if (document.getElementById)
	{
		// this is the way the standards work
		var style2 = document.getElementById("comm"+whichLayer).style;
		style2.display = style2.display? "":"none";
		var style3 = document.getElementById("commedit"+whichLayer).style;
		style3.display = style3.display? "":"block";
	}
	else if (document.all)
	{
		// this is the way old msie versions work
		var style2 = document.all["comm"+whichLayer].style;
		style2.display = style2.display? "":"none";
		var style3 = document.all["commedit"+whichLayer].style;
		style3.display = style3.display? "":"block";
	}
	else if (document.layers)
	{
		// this is the way nn4 works
		var style2 = document.layers["comm"+whichLayer].style;
		style2.display = style2.display? "":"none";
		var style3 = document.layers["commedit"+whichLayer].style;
		style3.display = style3.display? "":"block";
	}
}

function arraySearch(needle,haystack)
{
  for (var i=0;i<haystack.length;i++)
  {
    if (haystack[i]==needle)
    {
      return true;
    }
  }
  return false;
}

function addSlashes(text)
{
  var invalid = new Array("\\","'","\"");
  for (var i=0;i<text.length;i++)
  {
    if (arraySearch(text.charAt(i),invalid))
    {
      text = text.substring(0,i)+"\\"+text.substring(i,text.length-1);
      i++
  }
  }
  return text;
}

function preProcess()
{
	document.forms['login'].sh.value = window.screen.height;
}

function confirmDelete()
{
	var agree=confirm("Are you sure you wish to delete this entry?");
	if (agree)
	{
		return true ;
	}
	else
	{
		return false ;
	}
}

var miLastID = 1; //default of input element already written
function addNewInputElement(sourceCloneID, targetParentID)
{
	var ndSource = document.getElementById(sourceCloneID);
	var ndTargetParent = document.getElementById(targetParentID);
	if(ndSource)
	{
		var ndClone = ndSource.cloneNode(true);
		//change clones id 
		var ndCloneName = getNextID(ndClone.id);
		ndClone.setAttribute('id', ndCloneName);
		ndClone.setAttribute('name', ndCloneName);
		ndClone.value = '';
		//append as child
		ndTargetParent.appendChild(ndClone);
	}
}
function getNextID(sEdit)
{
	//create String object
	var objEdit = new String(sEdit);
	//update counter for next ID
	miLastID = miLastID + 1;
	//substring only works if same node is cloned with id='nd1'
	//return new id
	return objEdit.substr(0, objEdit.length -1) + miLastID;
}

function renameValue(x,cat)
{
	document.renameCat.oldcat.value = cat;
	document.renameCat.category.value = cat;
	changeInner( 'catt', cat );
	if(toggleLayerReturn(x))
	{
		sfRenameCat();
	}
	else
	{
		toggleLayerReturn(x);
		sfRenameCat();
	}
}

function addValue(x)
{
	if(toggleLayerReturn(x))
	{
		sfAddCat();
	}
	else
	{
		toggleLayerReturn(x)
	}
}

function changeInner(objID,newVal)
{
	if( document.getElementById )
	{
		document.getElementById(objID).innerHTML = newVal;
	}
	else if( document.all )
	{
		document.all[objID].innerHTML = newVal;
	}
	else if( document.layers )
	{
		document.layers[objID].innerHTML = newVal;
	}
}

function getCookie(NameOfCookie)
{
	if (document.cookie.length > 0)
	{
		begin = document.cookie.indexOf(NameOfCookie+"=");
		if (begin != -1) // Note: != means "is not equal to"
		{
			begin += NameOfCookie.length+1;
			end = document.cookie.indexOf(";", begin);
			if (end == -1) end = document.cookie.length;
				return unescape(document.cookie.substring(begin, end)); 
		}
	}
	return null;
}

function setCookie(NameOfCookie, value, expiredays)
{
	var ExpireDate = new Date ();
	ExpireDate.setTime(ExpireDate.getTime() + (expiredays * 24 * 3600 * 1000));
	document.cookie = NameOfCookie + "=" + escape(value) +
	((expiredays == null) ? "" : "; expires=" + ExpireDate.toGMTString());
}

function delCookie (NameOfCookie)
{
	if (getCookie(NameOfCookie))
	{
		document.cookie = NameOfCookie + "=" +
		"; expires=Thu, 01-Jan-70 00:00:01 GMT";
	}
}

function tr_onmouseover(element)
{
	var oTR = getElement(element, "TR");
	if (oTR != null)
		oTR.style.backgroundColor = "#D7D9AB";
}

function tr_onmouseout(element)
{
	var oTR = getElement(element, "TR");
	if (oTR != null)
		oTR.style.backgroundColor = "";
}

function tr_onclick(addrtype, id)
{
	if (ignoreClick)
		ignoreClick = false;
	else
		location.href = "address_details.php?type=" + addrtype + "&id=" + id;
}

function getElement(src, tagName)
{
	var obj = src;
	while (obj != null && obj.tagName != tagName)
		obj = obj.parentElement;
	return obj;
}

function viewCalDetails( t )
{
	location.href = "calendar.php?action=details&t=" + t;
}

function calSelect( valF )
{
	if( valF == "Birthday" )
	{
		disableElemById( "detailsBox" );
		changeValElemById( "detailsBox", "Text will be automatically added for this Birthday" )
		tres = toggleLayerReturn( "birthdayHelp" );
		if( !tres )
			toggleLayer( "birthdayHelp" );
	}
	else
	{
		enableElemById( "detailsBox" );
		changeValElemById( "detailsBox", "" )
		tres = toggleLayerReturn( "birthdayHelp" );
		if( tres )
			toggleLayer( "birthdayHelp" );
	}
}

function disableElemById( whichElem )
{
	if ( document.getElementById )
	{
		// this is the way the standards work
		var theElem = document.getElementById( whichElem );
		theElem.disabled = true;
	}
	else if ( document.all )
	{
		// this is the way old msie versions work
		var theElem = document.all[whichElem];
		theElem.disabled = true;
	}
	else if ( document.layers )
	{
		// this is the way nn4 works
		var theElem = document.layers[whichElem];
		theElem.disabled = true;
	}
}

function enableElemById( whichElem )
{
	if ( document.getElementById )
	{
		// this is the way the standards work
		var theElem = document.getElementById( whichElem );
		theElem.disabled = false;
	}
	else if ( document.all )
	{
		// this is the way old msie versions work
		var theElem = document.all[whichElem];
		theElem.disabled = false;
	}
	else if ( document.layers )
	{
		// this is the way nn4 works
		var theElem = document.layers[whichElem];
		theElem.disabled = false;
	}
}

function changeValElemById( whichElem, changeText )
{
	if ( document.getElementById )
	{
		// this is the way the standards work
		var theElem = document.getElementById( whichElem );
		theElem.value = changeText;
	}
	else if ( document.all )
	{
		// this is the way old msie versions work
		var theElem = document.all[whichElem];
		theElem.value = changeText;
	}
	else if ( document.layers )
	{
		// this is the way nn4 works
		var theElem = document.layers[whichElem];
		theElem.value = changeText;
	}
}