//* Utility functions
//*
//* 01/12/04 1.0 js New
//* 09/12/04 1.1 js Chg omoverCmt to position cmt above anchor
//* 11/01/05 1.2 js Add getAllIds() getAllTags() getObjType() (for debugging)
//* 26/01/05 1.3 js Add isInFrames()
//* 13/05/05 1.4 js Mv pic_window() from our_area.html
//* 15/05/05 1.5 js Add resize to pic_window()
//*

//* display a 'comment' just below and right of an 'anchor' enclosing tag (in the example its a span)
//* use with cmtAnch and cmtText style definitions
//* 
//* example: "Traditional and modern <span id="cmtA1" class=cmtAnch onmouseover="omoverCmt('cmtA1','cmtT1')" 
//*          onmouseout="omoutCmt('cmtT1')" >liturgies</span>
//*          <span id="cmtT1" class=cmtText> set of words, music and actions</span>, but without music.
//* 

//* Take the id of the anchor and the comment, and work out the coords of the anchor
//* Position the comment just below and right of the anchor and change 'display' to inline

function omoverCmt(a_id, c_id) {
	a=document.all(a_id)
	if (a==null)
		alert("invalid anchor id ["+a_id+"]")
	c=document.all(c_id)
	if (c==null)
		alert("invalid comment id ["+c_id+"]")

	if (a==null || c==null)
		return
		
	a_oh=a.offsetTop
	a_ol=a.offsetLeft	
	el=a

	// work backwards up enclosing container tree
	while (el.tagName != "BODY") {
		el = el.offsetParent;
		a_ol = a_ol + el.offsetLeft;
		a_oh = a_oh + el.offsetTop;
	}
	

	//alert("a_oh="+a_oh+" a_ol="+a_ol)

	c_oh=c.offsetHeight
	c_ol=c.offsetLeft
	//alert("c_oh="+c_oh+" c_ol="+c_ol)
	//alert("disp="+c.display)

	c.style.left=a_ol+10
	c.style.top=a_oh+30
	c.style.width=100
	c.style.display="inline"
}


//* hide comment and ensure text does not take up anyspace in page
function omoutCmt(c_id) {
	//c=document.all(c_id)
	c.style.display="none"
}



//* convert links from CMS /aspawdcms/opencms to /aspawdcms/export
//* where this is not done by CMS export (in AREA tag under MAP tag)
//* <script>if (CMSLINK_IMAGES_PATH.indexOf("export")>0) conv_link_x("home_but_map");</script>

function conv_link_x(id) {

//<map name="home_but_map">
//<area shape="rect" coords="0,0,50,20" href="/aspawdcms/opencms/index.html" 
//onmouseover="if(document.images) document.home_but.src='/aspawdcms/opencms/system/galleries/pics/graphics/home_but_o.gif';"
//onmouseout="if(document.images) document.home_but.src='/aspawdcms/opencms/system/galleries/pics/graphics/home_but_n.gif';">
//</area>
//</map>

m=document.all(id)
mapname=m.name

// assume 1 childnode of name AREA
area=m.childNodes[0]
anName=area.nodeName // ie AREA

var aa=""
for (var i=0; i< area.attributes.length ; i++) {
	if (area.attributes[i].value != "null" && area.attributes[i].value != ""){
		an=area.attributes[i].name
		av=area.attributes[i].value
		if (av.indexOf("/aspawdcms/opencms")>0){
			av2=av.replace("/aspawdcms/opencms","/aspawdcms/export")
			area.attributes[i].value=av2
//			alert("attr="+area.attributes[i].value)
		}
//		aa=aa+","+an+"="+av
		
	}
}
//alert("all attrs: anname="+anName+" aa"+aa)
}



var win;
function openmsgwin(role){
//win=window.open("","initsesswin","scrollbars,resizeable,menubar,status,width=700");
win=window.open("","openmsgwin","resizeable,status,width=700,height=400");
var win_html="";
win_html=win_html+"<HTML><BODY bgColor=white>"
win_html=win_html+"<script type=\"text/javascript\">document.location.href=\"/jmail/sendmsg.jsp?role="
win_html=win_html+role+"&stylesheet="+document.getElementById("aspawdcss").href+"\"<\/script>"
win_html=win_html+"<\/BODY><\/HTML>"
win.document.write(win_html);
win.document.close(); //close write stream
win.focus();
}

//* workout if the page is in a frame set or standalone
//* if top-path and our path are same then not in frames
function isInFrames() {
ourpath=document.location.pathname;
//* avoid access denied messages?
try {
  toppath=top.document.location.pathname;
}
catch (e) {
  alert("isInFrames() catch top-path access:e="+e)
  toppath="xxxx"
}

if (ourpath==toppath)
  return(false);
else
  return(true);
}



//* view key structures in DOM of subtree under id
function debug_DOM(id) {

el=document.all(id)
elname=el.name

var nn="El child.nodeNames: len="+el.childNodes.length+" "
for (var i=0; i< el.childNodes.length; i++) {
	nn=nn+","+el.children[i].nodeName
}

var ll="doc links: len="+document.links.length+" "
for (i=0; i< document.links.length; i++) {
	ll=ll+","+document.links[i]
}

var aa="doc anchors: len="+document.anchors.length+""
for (i=0; i< document.anchors.length; i++) {
	aa=aa+","+document.anchors[i].href
}

var ii="doc images: len="+document.images.length+" "
for (i=0; i< document.images.length; i++) {
	ii=ii+","+document.images[i].src
}

var ff="doc forms: len="+document.forms.length+" "
for (i=0; i< document.forms.length; i++) {
	ff=ff+","+document.forms[i].name
}

var ss="doc styleSheets len="+document.styleSheets.length+" "
for (i=0; i< document.styleSheets.length; i++) {
	ss=ss+","+document.styleSheets[i].href
}

//* get a style:
//* Unless a style is explicitly set for an element then null will be returned when an element's style is referenced.
//* If a class is set, style settings are not returned (DHTM p878). You can get the effective style attributes 
//* individually by .currentStyle.backgroundColor etc (W3C/NN6 use window.getComputedStyle()?)

//document.getElementById("table1").style.left=22;
//alert("get a style(table1):"+document.getElementById("table1").style.left) //=22

//alert("get a style(table1):"+document.getElementById("table1").currentStyle.backgroundColor)

alert("el name="+elname+", el nodeType="+el.nodeType+", "+nn+"\n"+ll
	+ "\n"+aa+"\n"+ii+"\n"+ff+"\n"+ss)
	
//area=el.childNodes[0]
//anName=area.nodeName

}


function getAllIds() {
	var doc=window.document
	var res=""
	var tp=""
	var i
	// 'all' is collection of elments nested within current element
	// document.all is a collection (array) of all element objects contained by the document
	// including nested objects. Sorted in source code order of element tags 
	// DHTML 543
    for (i = 0; i < doc.all.length; i++) {
		res=res+" i="+i+":"+doc.all[i].id
        
		// get more info (seem always to return 'object')!
		// could also try: if (obj instanceof array) ... treat as array, but always seems to
		// return false - at least in IE6
		// DHTML 1202, 1204
		
		tp=getObjType(doc.all[i])
		res=res+" type="+tp+ " name="+doc.all[i].name+","
		
			 
    }
	alert(getObjType("xxxx"))
    alert("getAllIds()"+res)
}

// eg getAllTags("TABLE")
function getAllTags(opt) {
	res=""
	var tagsarr=document.all.tags(opt)
	for (i=0; i < tagsarr.length; i++)
		res=res+" i="+i+":"+tagsarr[i].id+","
	alert("getAllTags("+opt+") "+res)
}

// eg alert(getObjType("xxxx")) returns 'string'
// eg alert(getObjType(getObjType())) returns 'function'
function getObjType(obj) {
	if (typeof obj == "string")
		 tp="string";
	else if (typeof obj == "function")
		 tp="function";
	else if (typeof obj == "number")
		 tp="number";
	else if (typeof obj == "object")
		 tp="object";
	else if (typeof obj == "boolean")
		 tp="boolean";
	else if (typeof obj == "undefined")
		 tp="undefined";
	else
		tp="??!"
		
	return tp;
}


function pic_window(id){
img=document.all(id);
//alert("img="+img.src+" - "+img.alt);

//* substitute 100 for 400 in URL for larger image
imgsrc2=img.src.replace("100","400"); 

var win=window.open("","pic_win","height=325,width=405,titlebar=no");
//ht=300,wd=400 extras added to allow for table border

win_html="<HTML><head><LINK href=\"/aspawdcms/opencms/system/resources/aspawd_pub.css\"";
win_html=win_html+"type=text/css rel=STYLESHEET></head><body class=margin0  onload=fit_image()>";
win_html=win_html+"<table id=pic_win_tbl cellSpacing=0 cellPadding=1 border=1>";
win_html=win_html+"<tr><td class=pubtextA align=center>"+img.alt+"</td><tr>";
win_html=win_html+"<tr><td align=center valign=middle><img src=\""+imgsrc2+"\" border=\"0\" alt=\"click to close\"  onclick='window.close()'></tr></td>";
win_html=win_html+"</table><script>function fit_image() {wd=document.images[0].width; ht=document.images[0].height; window.resizeTo(wd+4, ht+25);}</script>";
win_html=win_html+"</body></html>";

win.document.write(win_html); 
win.document.close(); //close writestream
win.focus();
}
