function getViewportHeight() {
  if (self.innerHeight) // all except Explorer
  {
    y = self.innerHeight;
  }
  else if (document.documentElement && document.documentElement.clientHeight)
    // Explorer 6 Strict Mode
  {
    y = document.documentElement.clientHeight;
  }
  else if (document.body) // other Explorers
  {
    y = document.body.clientHeight;
  }
  return( y );
}

function getViewportWidth() {
  if (self.innerHeight) // all except Explorer
  {
    x = self.innerWidth;
  }
  else if (document.documentElement && document.documentElement.clientHeight)
    // Explorer 6 Strict Mode
  {
    x = document.documentElement.clientWidth;
  }
  else if (document.body) // other Explorers
  {
    x = document.body.clientWidth;
  }
  return( x );
}


function getViewportScrollX() {
  if (self.pageYOffset) // all except Explorer
  {
    x = self.pageXOffset;
  }
  else if (document.documentElement && document.documentElement.scrollTop)
    // Explorer 6 Strict
  {
    x = document.documentElement.scrollLeft;
  }
  else if (document.body) // all other Explorers
  {
    x = document.body.scrollLeft;
  }
  return( x );
}

function getViewportScrollY() {
  if (self.pageYOffset) // all except Explorer
  {
    y = self.pageYOffset;
  }
  else if (document.documentElement && document.documentElement.scrollTop)
    // Explorer 6 Strict
  {
    y = document.documentElement.scrollTop;
  }
  else if (document.body) // all other Explorers
  {
    y = document.body.scrollTop;
  }
  return( y );
}

function grayOut() {
	document.getElementById("grayOut").style.display = "block";
	document.getElementById("grayOut").style.height = (getViewportScrollY() + getViewportHeight()) + "px";
}

function centerPopUp()
{
	topMargin = Math.round(((getViewportScrollY() + getViewportHeight())-450)/2);
	leftMargin = Math.round(((getViewportScrollX() + getViewportWidth())-675)/2);
	document.getElementById("popUp").style.top = topMargin+"px";
	document.getElementById("popUp").style.left = leftMargin+"px";
	document.getElementById("popUp").style.display = "block";
}

function openWindow(page,id)
{
	document.getElementById('iWindow').src = page + "?id="+id;
}

function disableButtons(formButton) {
  formButton.disabled = 'true';
}

function editSubmit(formButton, formName, wAction) {
  confirmPageExit = false;
  if(wAction == 'delete')
  {
 	var answer = confirm("Delete this item?")
	if (answer)
	{
  		disableButtons(formButton);
		document.forms[formName].windowAction.value=wAction;
 		document.forms[formName].submit();
	}
	else
	{
		
	}
  }
  else
  {
	if(formName == "rotationEdit" && document.forms[formName].title.value == "")
	{
		alert("Item must be given a title");
		return(false);
	}
  	disableButtons(formButton);
	document.forms[formName].windowAction.value=wAction;
 	document.forms[formName].submit();
  	return true;
  }
}

function editCancel(ref)
{
	parent.document.getElementById("popUp").style.display = "none";
	parent.document.getElementById('iWindow').src = "blank.html";
	parent.document.getElementById("grayOut").style.display = "none";
	parent.window.location.href = ref; //used to be ../index.php
}

function showHide(x,y)
{
	i = 0;
	while(i < y)
	{
		document.getElementById("ieSectionHide"+i).style.display = "none";
		i++;
	}
	document.getElementById("ieSectionHide"+x).style.display = "block";
}

function hideAllSections(x)
{
	i = 0;
	while(i <= x)
	{
		document.getElementById("ieSectionHide"+i).style.display = "none";
		i++;
	}
}

function checkTitle(formName,actionText)
{
	alert("in here");
	if(document.getElementById(formName).title.value !== "")
	{
		document.getElementById(formName).action = "";
		alert("Item must be given a title");
		return(false);
	}
	else
	{
		document.getElementById(formName).action = actionText;
	}
}
