
// For xml treatment

function get_firstChild(pnode) {
	
	var y=null;
	if (pnode!=null) {
		y=pnode.firstChild;
		while (y!=null && y.nodeType!=1)  {  y=y.nextSibling;  }
	}
	return y;
}


function get_nextsibling(pnode) {
	
	var x=pnode.nextSibling;
	while (x!=null && x.nodeType!=1) { x=x.nextSibling;  } // Skip no DOM elements
	return x;
}

function getTagValue(pnode, tagname) {
	
	var retvalue="";
	var nodes=pnode.getElementsByTagName(tagname);
	if ( (nodes!=null) && (nodes.length>0) ) {
		var tagnode=nodes[0];
		var valuenode=tagnode.childNodes[0];
		if (valuenode!=null) retvalue=valuenode.nodeValue; 
	}
	// else  alert("getTagValue(): node "+tagname+" not found");
	return retvalue;
}


function getChildFromElt(n, elt, tagChild) {

	if (elt==null) return null;
		
	var childs = elt.childNodes;
	var index = 0;
	for (var i=0; i<childs.length; i++) {
		if (childs[i].tagName == tagChild) {
			index++;
			if(n == index) return childs[i];
		}
	}
	return null;
}


function getTagValueIE(pnode, tagname) {
	
	var retvalue="";
	var nodes=pnode.childNodes;
	if ( (nodes!=null) && (nodes.length>0) ) {
		var debuginfo="";
		for (var i=0; i<nodes.length; i++) {
			if (nodes[i].nodeType==1 && nodes[i].tagName==tagname) {
				retvalue=nodes[i].childNodes[0].nodeValue;
				
				if (retvalue==null) retvalue=""; 
			}
		}
	}		
	return retvalue;
}


function getTagValueInfo(pnode, tagname) {

	var firstNode=get_firstchild(pnode);
	var node=firstNode;
	var nodeinfo="firstchild="+node.nodeName+"="+node.childNodes[0].nodeValue;
	
	for (i=0;i<firstNode.childNodes.length;i++) {
		var node=firstNode.childNodes[i];
		if (node.nodeType==1)  {
			nodeinfo+=node.nodeName+"="+node.childNodes[0].nodeValue;
		}
	} 
}


function get_TagValue(mainnode,tagname){
	
	var debuginfo="";
	var retvalue="";

	var child=mainnode.firstChild;
	if ((child!=null) && (child.nodeType==1) ) {
		if (child.tagName.toUpperCase()==tagname) {
			found=true;
			retvalue=child.childNodes[0].nodeValue; 
		}
	}
	while (found==false && child!=null) { 
		child=child.nextSibling;  
		if ((child!=null) && (child.nodeType==1) ) {
			if (child.tagName.toUpperCase()==tagname) {
				found=true;
				retvalue=child.childNodes[0].nodeValue; 
			}
		}
	}
	
	return retvalue;
}

function XMLtoArray(xmlinfo, ptag) {
	
	var list = new Array();
	
	var fiches=new Array();
	var pos=0;
	var lastpos=0;
	var tag="</"+ptag+">";
	if (xmlinfo!=null) {
		while ( (pos=xmlinfo.indexOf(tag, (lastpos+tag.length) ))!=-1) {
			fiches[fiches.length]=xmlinfo.substring(lastpos,pos);
			lastpos=pos+tag.length;
		}
		if (fiches!=null) {
			
			var ind=0;
			var xmlnode=fiches[ind]; 
		
			while (	xmlnode!=null) {
				list[list.length]=xmlnode;
				xmlnode=fiches[++ind];
			}
		}
	}	

	return list;
}


function getTagInfo(tag, str) {
	
	var balise1="<"+tag+">";
	var balise2="</"+tag+">";
	var retvalue="";
	var pos1=str.indexOf(balise1);
	if (pos1!=-1) {
		pos1+=balise1.length;
		var pos2=str.indexOf(balise2, pos1);
		if ( pos2!=-1) {
			retvalue=str.substring(pos1,pos2);
		}
	}
		
	return retvalue;
}

