String.prototype.ixsubst = function(pType) {
	switch (pType) {
	case 'MARK':return this.replace(/PPK_BEGIN_MARK/g, '<em Class="HightLightedWordItem">').replace(/PPK_END_MARK/g,'</em>'); break;
	case 'HIGHLIGHT':return this.replace(/PPK_BEGIN_MARK/g, '<em>').replace(/PPK_END_MARK/g,'</em>'); break;
	default:return this.replace(/PPK_BEGIN_MARK/g, '').replace(/PPK_END_MARK/g,''); break;
	}
}
function selectIndexation(pId,pNo,pType) {
	var obj = indexation[pId]
	if (obj[0].Key=='T') {
		switch (pType) {
		case 'T':
			DoSearchIndexation(pType,obj[0].Z3950UseSubject,obj[pNo].term,obj[pNo].display.ixsubst())
			break;
		default:
			DoSearchIndexation(pType,obj[0].Z3950UseVedette,obj[pNo].accumTerm,obj[pNo].accumDisplay.ixsubst())
			break;
		}
	} else {
		switch (pType) {
		case 'T':
			DoSearchIndexation(pType,obj[0].Z3950UseSubject,'',obj[pNo].display.ixsubst())
			break;
		default:
			DoSearchIndexation(pType,obj[0].Z3950UseVedette,'',obj[pNo].accumDisplay.ixsubst())
			break;
		}
	}
}
function highlightIndexation(pId, pNo, pSwitch) {
	var obj = indexation[pId]
	var objDIV = document.getElementById(pId)
	var alltags = objDIV.getElementsByTagName("span")
	for (i=0;i<alltags.length;i++) {
		var spanObj = alltags[i]
		var id = spanObj.id
		var zL = pId.length
		if (id.substr(0,2+zL)=='IV'+pId) {
			var zNo = Number(id.substr(2+zL))
			var aObj = document.getElementById("IVLink" + pId + zNo)
			switch(pSwitch) {
			case 'T':
				if (zNo <= pNo) {
					spanObj.className="HighLightIndexation"
					aObj.className="HighLightIndexation"
					aObj.innerHTML = obj[zNo].display.ixsubst('HIGHLIGHT')
				}
				break;
			default:
				spanObj.className="ISBDIndex"
				aObj.className="ISBDIndex"
				aObj.innerHTML=obj[zNo].display.ixsubst('MARK')
				break;
			}
		}
		
	}
}
var indexation = new Array
var indexationElement
var indexationId = 0
function initIndexation(pSep,pPrmType, pPrmStructured, pPrmLinkOnTerm, pPrmLinkOnStartString,
							pHintTerm,pHintVedette,pZ3950UseSubject,
							pZ3950UseVedette,pImg, pImgMoreInfo,
							pSubjectActive, pVedetteActive, pKey) {
	indexationId++
	var zId = "NZRTDC" + indexationId
	document.write('<span id="'+zId+'"></span>')
	indexation[zId] = new Array()
	indexationElement = indexation[zId]
	indexationElement[0] = new Object()
	indexationElement[0].param_type = pPrmType
	indexationElement[0].param_structured = pPrmStructured
	indexationElement[0].param_linkOnTerm = pPrmLinkOnTerm
	indexationElement[0].param_linkOnStartString = pPrmLinkOnStartString
	indexationElement[0].sep = String(pSep.trim())
	indexationElement[0].vedette = ''
	indexationElement[0].id = zId
	indexationElement[0].hintTerm = pHintTerm
	indexationElement[0].hintVedette = pHintVedette
	indexationElement[0].Z3950UseSubject = pZ3950UseSubject
	indexationElement[0].Z3950UseVedette = pZ3950UseVedette
	indexationElement[0].SubjectActive = pSubjectActive
	indexationElement[0].VedetteActive = pVedetteActive
	indexationElement[0].Key = pKey
	indexationElement[0].accumTerm = ''
	indexationElement[0].accumDisplay = ''
	indexationElement[0].img = pImg
	indexationElement[0].imgMoreInfo = pImgMoreInfo
}

function addIndexationSF3(pVedette) {
	indexationElement[0].vedette = pVedette
}
function addIndexation(pTerm, pDisplay) {
	var obj = indexationElement
	var zNo = obj.length
	var zTerm = pTerm
	var zDisplay = pDisplay
	var zLinkTerm = false
	var zLinkVedette = false

	switch (obj[0].param_type) {
	case '':
		if	(	((obj[0].param_structured=='T') && (obj[0].param_linkOnTerm == 'T')) ||
				(obj[0].param_structured=='F') 
			) zLinkTerm=true;
		
		if ((obj[0].param_structured=='T') &&
			(obj[0].param_linkOnTerm=='T') &&
			(obj[0].param_linkOnStartString=='T')) zLinkVedette=true;
		break;
	default:
		if	(
				(obj[0].param_structured=='T') &&
				(			
					((obj[0].param_linkOnTerm=='T') && (obj[0].param_linkOnStartString=='F')) ||
					(obj[0].param_linkOnTerm=='F')
				)				
			) zLinkTerm=true;
		if	(
				(obj[0].param_structured=='T') &&
				(			
					((obj[0].param_linkOnTerm=='T') && (obj[0].param_linkOnStartString=='F')) ||
					((obj[0].param_linkOnTerm=='F') && (obj[0].param_linkOnStartString=='T'))
				)				
			) zLinkVedette=true;
		break;
	}	

	if (!zLinkTerm) zTerm = ''

	obj[zNo] = new Object()
	obj[zNo].term 	= zTerm

	if (zNo==1) {
		var zPos = zDisplay.indexOf('PPK_BEGIN_MARK')
		if (zPos==-1) {
			zDisplay = zDisplay.substr(0,1).toUpperCase() + zDisplay.substr(1)
		} else {
			zDisplay = zDisplay.substr(0,zPos+14) + 
						zDisplay.substr(zPos+14,1).toUpperCase() + 
						zDisplay.substr(zPos+15)
		}
	}

	/**
	 * If we have a title constructed such "voir documents~TITLE~SUBTITLE
	 * Save display as "voir documents"
	 * save accumdisplay as TITLE
	 * This only applies to the main title in an Authority Notice
	 */
	zAccumDisplay = zDisplay;
	var seppos = zDisplay.indexOf("~");
	if (seppos!=-1) {
		zAccumDisplay = zDisplay.substr(seppos+1); //
		zDisplay = zDisplay.substr(0,seppos); 
		seppos = zAccumDisplay.indexOf("~");
		if (seppos!=-1) zAccumDisplay = zAccumDisplay.substr(0,seppos); 
	}
	/* End of special treatment */




	obj[zNo].display = zDisplay
	obj[zNo].vedette = ''

	if (!zLinkVedette) zTerm = ''

	if (pTerm!="") obj[0].accumTerm = String(obj[0].accumTerm).trim() + " " + zTerm;
	if (obj[0].accumDisplay!='') obj[0].accumDisplay += " " + indexationElement[0].sep + " ";
	obj[0].accumDisplay += zAccumDisplay;
	obj[zNo].accumTerm = String(obj[0].accumTerm).trim()
	obj[zNo].accumDisplay = obj[0].accumDisplay
}
function displayIndexation() {
	var obj = indexationElement; 
	var zId = obj[0].id
	var objDIV = document.getElementById(zId)
	var zNo = obj.length-1

	var zHTML = ''

	zStatus=0
	if (String(obj[0].accumTerm).trim()=='') {
		obj[0].accumTerm=obj[0].vedette
		if (obj[0].vedette!='') zStatus = 1 
		else zStatus = 2
	}
	if (obj[0].VedetteActive=='F') zStatus = 2
	// No individual term links, so have an overll anchor
	if (zStatus==1) zHTML += '<a href="javascript:selectIndexation(\''+zId+'\',0,\'V\')">'

	// Display each term seperately
	for (var i=1;i<obj.length;i++) {
	
		if (obj[i].term!='') {
			var zMO = "onmouseover=\"highlightIndexation('"+zId+"',"+i+",'T')\"" 
			   zMO += "onmouseout =\"highlightIndexation('"+zId+"',"+i+",'F')\""
			
			zHTML += '<span class="ISBDIndex" id="IV'+zId+i+'">'
			if (i!=1) zHTML += '&#32;'
			
			var lf = "\n"
			if (!is_ie) lf = " "
			//lf = '1. &#13; 2. &#10; 3.OK? 4. &#x000A;'
			
			if (obj[0].SubjectActive=='T') {
				zHTML += '<a class="ISBDIndex" id="IVLink'+zId+i+'" title="'+String(obj[0].hintTerm).quotapos()+lf+String(obj[i].display.ixsubst('')).quotapos()+'" href="javascript:selectIndexation(\''+zId+'\','+i+',\'T\')">'			
				zHTML += obj[i].display.ixsubst('MARK')			
				zHTML += '</a>'
			} else {
				zHTML += '<span id="IVLink'+zId+i+'">' + obj[i].display.ixsubst('MARK') + '</span>'
			}
			
			if ((obj[i].accumTerm != '') && (obj[0].VedetteActive=='T')) {
				zHTML += '<span title="'+String(obj[0].hintVedette).quotapos()+lf+String(obj[i].accumDisplay.ixsubst('')).quotapos()+'" '+zMO+' style="cursor:pointer;cursor:hand">'
				zHTML += '<span onclick="selectIndexation(\''+zId+'\','+i+',\'V\')">&#160;</span>'
				zHTML += '<a class="ISBDIndex" href="javascript:selectIndexation(\''+zId+'\','+i+',\'V\')">'
				if (i==obj.length-1) {
					zHTML += '<img title="'+String(obj[0].hintVedette).quotapos()+lf+String(obj[i].accumDisplay.ixsubst('')).quotapos()+'" border="0" src="'+indexationElement[0].img+'"/>'
				} else {
					zHTML += obj[0].sep
				}
				zHTML += '</a>'
				zHTML += '</span>'
			} else {
				if (i!=obj.length-1) zHTML += '&#32;' + obj[0].sep
			}
			zHTML += '</span>'
		} else {
			if (i!=1) zHTML += '&#32;'
			zHTML += obj[i].display.ixsubst('MARK')
			if (i!=obj.length-1) zHTML += '&#32;' + obj[0].sep
		}		
	}
	
	if (zStatus==1) zHTML += '</a>'
	objDIV.innerHTML = zHTML
}

