/* author: Keith Atkins */
/* Version 2.001 Creation date: 23/08/01 */	
na   = navigator.userAgent
if (na.search(/msie/i)== -1){IE = false}else{IE = true}	
//-------------------------------------------------------------
function servicesJS()
{ 
return true
} 
//------------------------------------------------------------
function setOpacity(O,V)
{  
if (V  > 100){V=100}
if (V  < 0){V=0} 
O.style.filter  = "alpha(opacity="+V+")"	
O.style.opacity =  V/100 	
return 
}
//------------------------------------------------------------
function getOpacity(O)
{  
var V
if (IE)
{
  var opacity =   O.style.filter 
  var s       =   opacity.search(/[=]/i)
  V           =   parseInt(opacity.substr(s+1))
}
else
{
  V = O.style.opacity*100
} 
return V
}
//---------------------------------------------------------------
function getEvent(e)
{  
if (e+"" == "undefined"){return event}
var E=new Object()
E["srcElement"] = e.target
E["button"]     = e.which
E["keyCode"]    = e.which
E["clientX"]    = e.pageX
E["clientY"]    = e.pageY
return E
}
//--------------------------------------------   Offset functions ----------------------------------------
function offsetLeft(el)
{
     x = el.offsetLeft
     for (e = el.offsetParent; e; e = e.offsetParent)
       {x += e.offsetLeft}
     return  x
}
function offsetTop(el)
{	
    y = el.offsetTop
    for (e = el.offsetParent; e; e = e.offsetParent)
      {y += e.offsetTop;}
    return y
} 
//--------------------------------------
function getHTMLFolder()
{				
var l = location+""	
	if (l.search(/localhost/i) != -1)
	{	
	return "http://localhost/bishopswaltham/html"
	}
	else
	{	
	return "http://bishopswaltham.net"
	}	
}
//------------------------------------------------ Which Browser ------------------------------------------
function browserType()
{
	na = navigator.userAgent.toLowerCase()
	if (na.indexOf("msie")== -1){r = "notie"}else{r = "ie"}
return r
} 
//------------------------------------------------------------
function setNewLines()
{ 
	setNewLines1("Div")
	setNewLines1("P")
	setNewLines1("Span") 
	setNewLines1("TD")
} 
//---------------------------------------------------------------
function setNewLines1(str)
{  
A = document.getElementsByTagName(str)
for (var i in A)
	{ 
	try{  
	A[i].innerHTML = A[i].innerHTML.replace(/[~]/g,"<BR />")
	}
	catch(e){}
	finally{}
	}
} 
//----------------------------------------------------------------
function getCurrentStyle(oElm, strCssRule){
	var strValue = ""; 
	//alert("Services  code="+code+" iD="+oElm.id)
	if(document.defaultView && document.defaultView.getComputedStyle)
	{	
	    try{ 
		strValue            = document.defaultView.getComputedStyle(oElm, "").getPropertyValue(strCssRule); 
		var myComputedStyle  = document.defaultView.getComputedStyle(oElm, null);  
        var strValue         = myComputedStyle[strCssRule]; 
		}
		catch(e){strValue=18}
		finally{}
	}
	else if(oElm.currentStyle)
	{
		strCssRule = strCssRule.replace(/\-(\w)/g, function (strMatch, p1){
	    return p1.toUpperCase();
		});	
		strValue = oElm.currentStyle[strCssRule];
	}
	//alert("Value="+strValue)
	return strValue;
} 
//--------------------------------------------------------------------------------  
function sendLogMsg(M,C) 
{ 
folder    = getHTMLFolder()
window.open(folder+"/serverScripts/sendLogMsg.asp?msg="+M+"&color="+C,"_blank","height=200,width=200")
}
//------------------------------------- Merge colors  start ---------------------------------------*******
//Returns an array with 'sets' entries 1st is 'Col1' and last is 'Col2' and sets-2 between
MC_ConA     = new Array('0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F','F') 
function mergeColors(FirstCol,Col1,Col2,Sets) 
{
Msg1 = "mergeColors - must be of the form rgb(red,green,blue) or #rrggbb in hex.\nFace color="+FirstCol+"\nFirst color="+Col1+"\nLast Color="+Col2
//alert("Merge "+FirstCol+"  "+Col1+"  "+Col2+"  "+Sets)
MC_Array    = new Array();
MC_Array[0] = FirstCol
var ConA  = MC_ConA;
if (Sets == 0) {MC_Array[0]=Col1;MC_Array[1]=Col2;return MC_Array}
if (Sets <   0) {MC_Array[0]=Col1;return MC_Array} 
if (FirstCol.substr(0,1).toLowerCase() != "#" && FirstCol.substr(0,3).toLowerCase() != "rgb"){FirstCol = "#000000"}
// Process Col1
switch(Col1.substr(0,1).toLowerCase())
{
	case "#" :if (Col1.length != 7){alert("Color1  "+Msg1);return}
	          Red1   = parseInt(Col1.substr(1,2),16);
	          Green1 = parseInt(Col1.substr(3,2),16);
	          Blue1  = parseInt(Col1.substr(5,2),16);
			  break;
	case  "r" :	A    = Col1.split("(")
	          B      = A[1].split(",")
	          Red1   = parseInt(B[0]);
	          Green1 = parseInt(B[1]);
	          Blue1  = parseInt(B[2]);
	          break;
	default:  Red1   = 0
	          Green1 = 0
	          Blue1  = 0
}
// Process Col2	
switch(Col2.substr(0,1).toLowerCase())
{
	case "#" :if (Col2.length != 7){alert("Color2  "+Msg1);return}
	         Red2    = parseInt(Col2.substr(1,2),16);
	         Green2  = parseInt(Col2.substr(3,2),16);
	         Blue2   = parseInt(Col2.substr(5,2),16);
			 break;	
	case "r" :A      = Col2.split("(")
	          B      = A[1].split(",")
	          Red2   = parseInt(B[0]);
	          Green2 = parseInt(B[1]);
	          Blue2  = parseInt(B[2]);
	          break;
	default  :Red2   = 255
	          Green2 = 255
	          Blue2  = 255
}
dRed     = (Red2-Red1)/(Sets-1);
dGreen   = (Green2-Green1)/(Sets-1);
dBlue    = (Blue2-Blue1)/(Sets-1);
n = Sets;
for (i=0;i<n;i++)
  {
  R = ConA[Math.floor(Red1/16)]+ConA[Math.floor(Red1%16)];
  G = ConA[Math.floor(Green1/16)]+ConA[Math.floor(Green1%16)];
  B = ConA[Math.floor(Blue1/16)]+ConA[Math.floor(Blue1%16)];
  MC_Array[i+1] = "#"+R+G+B;
  Red1   +=dRed;
  if (Red1 < .1) Red1=0;
  Green1 +=dGreen;
  if (Green1 < .1) Green1=0;
  Blue1  +=dBlue;
  if (Blue1 < .1) Blue1=0; 
  }	
return MC_Array;
}
//---------------- Merge colors End ----------------------------------------- 
//------------------------------------------------------------------------
function copyToClipboard(txtId)
{
 document.getElementById(txtId).focus();
 document.getElementById(txtId).select(); 
 var CopiedTxt = document.selection.createRange();
 CopiedTxt.execCommand("Copy");	 
}  
//---------------- DOM Functions -----------------------------------------
function getFirstChild(O)
{ 
 if (O.childNodes[0].nodeName != "#text")
 { 
  return O.childNodes[0]
 }
 else
 {
  return O.childNodes[1]
 }
}  
//-----------------------------------------------------
function findNextSibling(e)
{ 
var nextS       =  e.nextSibling; 
while(nextS+"" != "null" && nextS.nodeType!=1)
{  
 nextS=nextS.nextSibling;
}  
return nextS
} 
//--------------------------------------------------------
function insertAfter(parent, node, referenceNode)
 {
  parent.insertBefore(node,referenceNode.nextSibling);
 }
// ***************************  End Java Services *****************************************


