var gApplication	= getApplication()
var NSP = (gApplication=='PPKOPAS');

/* ----------------------------- */
/* Get the Application ID        */
/* ----------------------------- */
function getApplication() {
	var zApplication = ''
	try {zApplication = window.external.Pop('AppID');} catch(e) {
		try {zApplication = window.external.ppkGetIdentValue("Application")} catch(e) {}
	}		
	if ((top.location==self.location) && (zApplication=='PPKOPAS')) zApplication=''

	if (zApplication=='PPKOPAS') {
		try {
			if (!window.external.GetLocalBrowserCmd().isAdminZone(self.location)) zApplication = ''
		} catch (e) {
			try {
				oSession = window.external.PopIntf('AppSession')
				oSession.Push('AdminZone', self.location)
				oSession.Call('IsAdminZone')
			
				if (oSession.Pop('Result')!='T') zApplication = ''
			} catch (e) {}
		}
	}
	return zApplication
}

// Preload table-type buttons
function preloadButton(pButton,pImagePath) {
	var z = String(pImagePath.toUpperCase())
	if (z.indexOf('STD')!=-1) return
	
	var zPath = pImagePath + pButton + '/'
	var d=document; 
	if(d.images) { 
		if(!d.MM_p) d.MM_p=new Array();
		var i
		var j=d.MM_p.length
		d.MM_p[j]=new Image; d.MM_p[j++].src=zPath + 'btnl.gif';
		d.MM_p[j]=new Image; d.MM_p[j++].src=zPath + 'btnl_over.gif';
		d.MM_p[j]=new Image; d.MM_p[j++].src=zPath + 'btnl_down.gif';
		d.MM_p[j]=new Image; d.MM_p[j++].src=zPath + 'btnl_dis.gif';
		d.MM_p[j]=new Image; d.MM_p[j++].src=zPath + 'btnc.gif';
		d.MM_p[j]=new Image; d.MM_p[j++].src=zPath + 'btnc_over.gif';
		d.MM_p[j]=new Image; d.MM_p[j++].src=zPath + 'btnc_down.gif';
		d.MM_p[j]=new Image; d.MM_p[j++].src=zPath + 'btnc_dis.gif';
		d.MM_p[j]=new Image; d.MM_p[j++].src=zPath + 'btnr.gif';
		d.MM_p[j]=new Image; d.MM_p[j++].src=zPath + 'btnr_over.gif';
		d.MM_p[j]=new Image; d.MM_p[j++].src=zPath + 'btnr_down.gif';
		d.MM_p[j]=new Image; d.MM_p[j++].src=zPath + 'btnr_dis.gif';
	}
}   		

// Get the attribute of a specific stylesheet class		
function getStyleValue(pClass, pAttribute) {
    var zRetValue = '';
    try {
		if (document.styleSheets.length == 0) return zRetValue;

		var zClass = pClass.toUpperCase();
		var zRules = 'rules';
		if (document.styleSheets[0].cssRules) zRules = 'cssRules';

    
		for(var j=0;j< document.styleSheets.length;j++)
		{
			var objStyle = document.styleSheets[j];
			for(var i=0;i< eval('objStyle.' + zRules + '.length');i++)
			{
				var zStyleClass = eval('objStyle.' + zRules + '[' + i + '].selectorText');
				var zTest = zStyleClass.toUpperCase()
				if (zTest == zClass) {
					var zAttrValue = eval('objStyle.' + zRules + '[' + i + '].style.' + pAttribute)
					if (zAttrValue) {if (zAttrValue != '') zRetValue = zAttrValue;}
				}
			}
		}
    } catch (e) {}
    return zRetValue;
}

var subWin
function ShowWindow(Url,h,w,modal,resize)
{
	try {if (subWin) subWin.close()} catch (e) {}

	var isNav = false;
	switch (navigator.appName) {
	case 'Netscape':
		isNav = true
		break;
	case 'Opera':
		isNav = true
		break;
	default:
		break;
	}	
	var date = new Date
	var zURL = Url + '&TimeStamp=' + date.getTime()

	if (resize == true) {
		zResize = 1
		zResizable = 'yes'
	} else {
		zResize = 0
		zResizable = 'no'		
	}

      winLeft = (screen.availWidth - w)/2;
      winTop = (screen.availHeight - h)/2;

	if (isNav) {
	      if (modal==true)
	      {
	        subWin = window.open(zURL,"subwin","scrollbars=0,modal=1,resizable="+zResize+",height="+h+",width="+w+",toolbar=0,directories=0,menubar=0,status=0,location=0,left="+winLeft+",top="+winTop,false);
	      }
	      else
	      {
	        subWin = window.open(zURL,"subwin","scrollbars=0,modal=0,resizable="+zResize+",height="+h+",width="+w+",toolbar=0,directories=0,menubar=0,status=0,location=0,left="+winLeft+",top="+winTop,false);
	      }
	} else {
	      if (modal==true)
	      {
 		subWin = window.showModalDialog(zURL,"","dialogHeight: " + h + "px;dialogWidth: " + w + "px;scroll: No;dialogTop: px; dialogLeft: px; center: Yes; help: No; resizable: "+zResizable+"; status: No;");
	      }
	      else
	      {
	        subWin = window.open(zURL,"subwin","scrollbars=0,modal=0,resizable="+zResize+",height="+h+",width="+w+",toolbar=0,directories=0,menubar=0,status=0,location=0,left="+winLeft+",top="+winTop,false);
	      }
	
	}
}
function GetNodeText(Xml,XPath,Default) {
	var result;
	try {
		result = Xml.selectSingleNode(XPath).text;
		if (typeof(result) == "undefined")
		result = Default;
	} catch (e) {
		if (typeof(Default)!="undefined") result = Default;
		else result = '';
	}
	return result;
}
			
function ShowAccount(LogCode,FullName,DataBase) {
	// Make it the same height and width of calling window
	var win = parent
	if (NSP) win = self
	var obj = getWindowDetails(win)
	ShowUniversalModalWindowPath(CONST_OpacWebDll,self,'AccountAb?XFile=Account&LoginCAb='+LogCode+'&ConsultCAb='+LogCode+'&DataBaseNames='+DataBase,LANG_Consult,obj.height,obj.width,'r','F',obj.top,obj.left);
}
function Login() {
	var zLink = 'GlobalInfo?XFile=LoginAb&Init=T&Action=ShowAccount&ChooseBase=T' + CONST_AllParams + getOpacParams()
	ShowUniversalModalWindowPath(CONST_OpacWebDll,self,zLink,encodeUtf8(LANG_UserId),'310','500','r','T');
}
function reloadMeLeft(pValue) {
	if (NSP) {	
		window.parent.location = CONST_Bib + pValue + '/indexClient.asp?Lang=' + pValue + '&Skin='+CONST_Skin+'&HomePage=F' //+CONST_Params
	} else {
		window.parent.location = CONST_Bib + pValue + '/indexClient.asp?Lang=' + pValue + '&Skin='+CONST_Skin //+CONST_Params
	}
}
function reloadMeCenter(pValue) {
	var wp = window.parent
	wp = wp.parent

	if (NSP) {
		self.location = CONST_Bib + pValue + '/' + returnNSP(pValue) + '?Lang=' + pValue  + '&Skin='+CONST_Skin;
	} else {
		wp.location = CONST_Bib + pValue + '/indexClient.asp?Lang=' + pValue + '&Skin='+CONST_Skin+CONST_Params
	}
}

// Pour NSP
function RDURL(pURL) {
	var RechercheDoc = pURL
	if (NSP) {
		RechercheDoc = RechercheDoc.split('&').join('amp;')
		RechercheDoc = RechercheDoc.replace('?','qm;')
		RechercheDoc = CONST_Site + 
						"IndexFrame.asp?" + 
						"HomePage=F" + 
						"&Lang="+CONST_Lang + 
						"&Skin="+CONST_Skin + 
						"&url=" + 
						RechercheDoc
	}
	return RechercheDoc
}
