// utilities javascript

// alert('Utilities open');

function refresh ()
{
  history.go(0);
}

function reload ()
{
  history.go(0);
}

function closeWindowOnEnter () // close window on enter key
{
  if (event.keyCode == 13) { self.close(); }
} 

function resizeWindow(w, h) // for single image
{
  if ( document.images[0] )
  {
    window.resizeTo(document.images[0].width+w,document.images[0].height+h);
  }
  self.focus();
}

function popupWindow (url,name,opt) // correct order
{
  // alert ('in popupWindow');
  if (opt == '' || opt == 'default')
  {
    opt = 'height=300,width=300,resizable=1,scrollbars=1,toolbar=0,menubar=0,titlebar=0';
  }
  var newwin = window.open(url,name,opt);
  newwin.focus();
}

function toggleSection (sec)
{
  var thisflag = eval('document.mainform.show'+sec+'.value');
  if (thisflag == 'no')
  {
    eval('document.mainform.show'+sec+'.value="yes"') ;
  }
  else
  {
    eval('document.mainform.show'+sec+'.value="no"') ;
  }
  document.mainform.submit();
}

function lexicalPopup (id)
{
  var dspwin = window.open('lexicalpopup.cfm?id='+id,'lexicalPopup','height=200,width=350,resizable=1,scrollbars=0,toolbar=0,menubar=0,titlebar=0');
  dspwin.focus();
}

function confirmLogout ()
{
  if ( confirm ('Are you sure you want to logout?') == true )
  {
    window.location.href='../logout.cfm?dc=yes';
  }
}
function confirmExit ()
{
  if ( confirm ('Are you sure you want to exit?') == true )
  {
    window.location.href='../logout.cfm?dc=no';
  }
}
function confirmCloseWindow ()
{
  if ( confirm ('Are you sure you want to close this window?') == true )
  {
    window.close();
  }
}

function openChatWindow (room)
{
  if (room == '' || room == undefined) {room = 'main';}
  // alert('Going to room: ' + room + '...');
  var chatwin = window.open('../user/chat.cfm?init='+room,'HHPChat','width=500,height=300,resizable=1,scrollbars=1');
  chatwin.focus();
}

function testLink (url,name)
{
  popupWindow (url,'TestLink','default');
}

function confirmDelete (id)
{
  if ( confirm ('Are you sure you want to delete this record?') == true )
  {
    document.mainform.id.value = id;
    document.mainform.action.value = 'delete';
    document.mainform.submit();
  }
}

function confirmUpdate (id)
{
  if ( confirm ('Are you sure you want to update this record?') == true )
  {
    document.mainform.id.value = id;
    document.mainform.action.value = 'update';
    document.mainform.submit();
  }
}

function unconfirmedUpdate (id)
{
    document.mainform.id.value = id;
    document.mainform.action.value = 'update';
    document.mainform.submit();
}

function changeMajorText (txt)
{
  window.status = txt;
  
  if (false) //i.e. IE
  {
    document.all.majortext.innerHTML = txt;
    document.all.minortext.innerHTML = "<br>";
  }
  else // netscape
  {
    document.getElementById("majortext").innerHTML = txt;
    document.getElementById("minortext").innerHTML = "<br>";
  }
   
  return true;
}

function changeMinorText (txt)
{
  if (false) //i.e. IE
  {
    document.all.minortext.innerHTML = txt + "&nbsp";
  }
  else // netscape
  {
    document.getElementById("minortext").innerHTML = txt + "&nbsp";
  }
  window.status=txt;
  
  return true;
}

function changeColor (c)
{
  
  document.bgColor = c;
  if (false) //i.e. IE
  {
    document.all.title.style.color=c;
    document.all.majortext.style.color=c;
    document.all.hr1.style.color=c;
    document.all.hr2.style.color=c;
    document.all.datestamp.style.color=c;
  }
  else // netscape
  {
    document.getElementById("title").style.color = c;
    document.getElementById("majortext").style.color = c;
    document.getElementById("hr1").style.color=c;
    document.getElementById("hr2").style.color=c;
    document.getElementById("datestamp").style.color=c;
  }
}

function changeMajorTextIframe (txt)
{
  if (parent.document.all) //i.e. IE
  {
    parent.document.all.majortext.innerHTML = txt;
  }
  else // netscape
  {
    parent.document.getElementById("majortext").innerHTML = txt;
  }
  window.status=txt;
  
  return true;
}

function changeMinorTextIframe (txt)
{
  if (parent.document.all) //i.e. IE
  {
    parent.document.all.minortext.innerHTML = txt;
  }
  else // netscape
  {
    parent.document.getElementById("minortext").innerHTML = txt;
  }
  window.status=txt;
  return true;
}

function selectLinks (major, minor, text)
{
  if (major == 'all' && minor == 'all')
  {
    if ( confirm ('Are you sure you want to show ALL links?') == false )
    {
      changeMajorText ('Request cancelled');
      return;
    }
  }
  document.mainform.major.value = major;
  document.mainform.minor.value = minor;
  document.mainform.submit();
}

function selectLinksIframe (major, minor, text)
{
  parent.document.all.level2.src = '/includes/links.cfm?major=' + major + '&minor=' + minor + '&r=' + Math.random();
}


function changeColorIframe (c)
{
  parent.document.bgColor = c;
  if (parent.document.all) //i.e. IE
  {
    parent.document.all.title.style.color=c;
    parent.document.all.majortext.style.color=c;
    parent.document.all.hr1.style.color=c;
    parent.document.all.hr2.style.color=c;
    parent.document.all.datestamp.style.color=c;
  }
  else // netscape
  {
    parent.document.getElementById("title").style.color = c;
    parent.document.getElementById("majortext").style.color = c;
    parent.document.getElementById("hr1").style.color=c;
    parent.document.getElementById("hr2").style.color=c;
    parent.document.getElementById("datestamp").style.color=c;
  }
}

function clearIframe ()
{
  //alert('clearIframe');
  document.all.level2.src = '/includes/dark.html?r=Math.random()';
  return true;
}

function getRandomImage ()
{
  parent.document.all.homepageimage.src = 'http://www.hampson.us/includes/randomimage.cfm';
}

function SwitchMenu (obj)
{
	//alert(obj);
  if(document.getElementById)
  {
	var el = document.getElementById(obj);
	var ar = document.getElementById("cont").getElementsByTagName("DIV");
		if(el.style.display == "none")
    {
			for (var i=0; i<ar.length; i++)
      {
				ar[i].style.display = "none";
			}
			el.style.display = "block";
		}
    else
    {
			el.style.display = "none";
		}
	}
}

function SwitchMenuTest (obj)
{
	// alert(obj);
  
  if(document.getElementById)
  {
	var el = document.getElementById(obj);
	var ar = document.getElementById("cont").getElementsByTagName("DIV");
		if(el.style.display == "none")
    {
			for (var i=0; i<ar.length; i++)
      {
				ar[i].style.display = "none";
			}
			el.style.display = "block";
		}
    else
    {
			el.style.display = "none";
		}
	}
}

function ChangeClass(menu, newClass)
{ 
	 if (document.getElementById)
   { 
	 	document.getElementById(menu).className = newClass;
	 } 
} 

function addChar (c)
{
  var w = document.mainform.chattext.value;
  if (c.length > 1) { alert ('To produce this letter use this combination: ' + c ); }
  document.mainform.chattext.value = w + c;
  document.mainform.chattext.focus();
}

function decToHex (dec)
{
  highdec = Math.floor (dec / 16);
  highhex = digits.charAt(highdec);
  lowdec = dec - (highdec * 16);
  lowhex = digits.charAt(lowdec);
  highlow = String(highhex) + String(lowhex);
  if (highlow.length == 1) {highlow = "0" + highlow;}
  return (highlow);
}

function hexToDec (hex)
{
  hexchar1 = hex.charAt(0);
  hexchar2 = hex.charAt(1);
  hexval1  = digits.indexOf(hexchar1);
  hexval2  = digits.indexOf(hexchar2);
  decval = ((hexval1 * 16) + hexval2);
  return decval;
}

function getmouseXY(e)
{
  if (IE) { // grab the x-y pos.s if browser is IE
    currX = event.clientX + document.body.scrollLeft;
    currY = event.clientY + document.body.scrollTop;
  }
  else {  // grab the x-y pos.s if browser is NS
    currX = e.pageX;
    currY = e.pageY;
  }  
  if (currX < 0) {currX = 0;}
  if (currY < 0) {currY = 0;}
  
  document.coordform.mouseX.value = currX;
  document.coordform.mouseY.value = currY;
  
  deltaX = decToHex(  currX / scrwid * 255 );
  deltaY = decToHex(  currY / scrhgt * 255 );
  
  document.coordform.dx.value = deltaX;
  document.coordform.dy.value = deltaY;
  
  newbgcolor = document.coordform.dx.value + document.coordform.dy.value + bb;
  document.coordform.bg.value = newbgcolor;
  document.bgColor = newbgcolor;
  
  return true;
}

// end of utilities

