/** script common.js - clerc-et-net.com - 24/11/04 */

var navDom = (document.getElementById && document.getElementsByTagName && document.createElement) ? true : false;

var scrW = screen.availWidth;
var scrH = screen.availHeight;

if (self.innerWidth)
{
	frameWidth = self.innerWidth;
	frameHeight = self.innerHeight;
}
else if (document.documentElement && document.documentElement.clientWidth) {
	frameWidth = document.documentElement.clientWidth;
	frameHeight = document.documentElement.clientHeight;
}
else if (document.body) {
	frameWidth = document.body.clientWidth;
	frameHeight = document.body.clientHeight;
} 
else
{
	frameWidth = null;
	frameHeight = null
}

var winName = window.name;
var newWin = new Array();
var winIndex = 0;

/* lang */
if (navDom)
{
	if (tagHtml = document.getElementsByTagName('html')[0])
	{
		var pageLang = tagHtml.getAttribute("xml:lang");
	}
	else
	{
		var pageLang = 'fr';
	}
}
else
{
	var pageLang = 'fr';
}

libelles = new Array();
libelles['top'] = new Array();
libelles['top']['fr'] = 'Remonter';
libelles['top']['en'] = 'Up';
libelles['top']['de'] = 'Up';
libelles['top']['nl'] = 'Up';


function popupWin(url,attribs)
{
	var relSplit = attribs.split(":");
	
	if (relSplit[1] > scrW) {
		pW = scrW - 10;
	} else {
		pW = relSplit[1];
	}
	
	if (relSplit[2] > scrH) {
		pH = scrH - 40;
	} else {
		pH = relSplit[2];
	}
	
	scrX = (scrW - pW - 10) * .5;
	scrY = (scrH - pH - 30) * .5;
	
	var windowAttributes = "width=" + pW + ",height=" + pH + ",left=" + scrX + ",top=" + scrY + ",screenX=" + scrX + ",screenY=" + scrY;
	
	if (relSplit[3] == "console") {
		windowAttributes += ",resizable";
	} else if (relSplit[3] == "consoleScroll") {
		windowAttributes += ",scrollbars,resizable";
	} else if (relSplit[3] == "fixed") {
		windowAttributes += ",status";
	} else if (relSplit[3] == "fixedScroll") {
		windowAttributes += ",scrollbars,status";
	} else if (relSplit[3] == "elastic") {
		windowAttributes += "toolbar,menubar,scrollbars,resizable,location";
	} else {
		windowAttributes += ",location,resizable,scrollbars";
	}
	
	winName = (winName != '') ? winName : 'winpp';
	
	if (typeof(relSplit[4]) != "undefined") {
		windowName = relSplit[4];
	} else {
		windowName = winName + '_' + winIndex;
		winIndex = winIndex + 1;
	}	
	
	if (typeof(newWin[windowName]) != 'undefined' && !newWin[windowName].closed && newWin[windowName].location) {
		newWin[windowName].focus();
	} else {
		newWin[windowName] = window.open(url, windowName, windowAttributes);
		newWin[windowName].name = windowName;
		newWin[windowName].focus();
	}
	return false;
}

function popupWindows()
{
	if(!navDom) {
		return;
	}
	
	var anchors = document.getElementsByTagName("a");
	
	for (var i = 0; i < anchors.length; i++) {
		var anchor = anchors[i];
		var relIndex = anchor.getAttribute("rel");
		
		if (relIndex) {
			var relSplit = relIndex.split(":");
			
			if(relSplit[0] == "popup") {
				anchor.onclick = function () {
					popupWin(this.href, this.rel);
					return false;
				};
			}
		}
	}
}

function linkClosePopup(text) {
	if (document.getElementById('footer')) {
	    div = document.createElement('div');
	    div.className = "fermeture";
	    
		a = document.createElement('a');
	    a.setAttribute('href', '#');
	    a.setAttribute('title', 'fermer la fenêtre');
	    a.onclick = function () {self.close();};
		var linkTxt = (text != '') ? text : 'FERMER';
	    textNode = document.createTextNode(linkTxt);
	    a.appendChild(textNode);
	    
		div.appendChild(a);
		document.getElementById('footer').appendChild(div);
	}
}

function FitToPicName(name)
{
	if (frameWidth && frameHeight) {
		iWidth = document.images[name].width - frameWidth;
		iHeight = document.images[name].height - frameHeight;
		window.resizeBy(iWidth, iHeight);
		self.focus();
	}
};

function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      oldonload();
      func();
    }
  }
}

if (window.opener && winName.indexOf('ppcn_') != -1) {
	
	links = document.getElementsByTagName('link');
	
	for(i=0; i< links.length; i++) {
		var link = links[i];
		var title = link.getAttribute("title");
		if (title == 'defaut') {
			
			if (document.styleSheets)
				document.styleSheets[i].disabled = true;
			
			link.parentNode.removeChild(link);
			
			document.writeln('<link href="css/ppcn.css" type="text/css" rel="stylesheet" />');
			
			addLoadEvent(function() {
					linkClosePopup('');
				}
			);
		}
	}
}

function get_height(id)
{
	if (obj = document.getElementById(id))
	{
		if (obj.innerHeight)
		{
			return obj.innerHeight;
		}
		else if (obj.clientHeight)
		{
			return obj.clientHeight;
		}
	}
	else
	{
		return null;
	}
}

function link_top()
{
	if (hauteur_page = get_height('pagewidth'))
	{
		if ((hauteur_page > frameHeight) && document.getElementById('footer'))
		{   
			/* ancre haut de page */
			a = document.createElement('a');
		    a.setAttribute('id', 'top');
			document.getElementsByTagName('body')[0].insertBefore(a, document.getElementById('pagewidth'));
			
			/* lien bas de page */
			a = document.createElement('a');
		    a.setAttribute('id', 'link_top');
			a.setAttribute('href', '#top');
		    textNode = document.createTextNode(libelles['top'][pageLang]);
		    a.appendChild(textNode);
		    
			document.getElementById('main').appendChild(a);
		}
	}
}

addLoadEvent(popupWindows);
addLoadEvent(link_top);
