var logPopup = false;
var logFolder = "shared";

// show producer document
function showdocument(id, width, height, bypasslogin)
{
	if (!width) width = 550;
	if (!height) height = 500;
	bypasslogin = !(!bypasslogin);
	login(defaultSite + "/common/shared/ctl/displaydocument.aspx?id="+ escape(id),width,height,true,true,false,false,bypasslogin);
}

function loguser(url, formname, viewForgetPW, width, height, language)
{
	if (!height)
		height = "340";								// define the popup's height;
	if (!width)
		width = "380";								// define the popup's width;
	var top = (screen.availHeight-height)/2;		// define the popup's vertical position on screen;
	var left = (screen.availWidth-width)/2;			// define the popup's horizontal position on screen;
	if (language == null)
		url = defaultSite + '/common/' + logFolder + '/navigation/login.aspx?rfr=' + escape(location.href) + '&url='+ escape(url) + '&formname=' + formname;
	else
		url = defaultSite + '/common/' + logFolder + '/navigation/login-' + language + '.aspx?rfr=' + escape(location.href) + '&url='+ escape(url) + '&formname=' + formname;
	if (viewForgetPW) // précise s'il faut afficher ou non le texte "Forgot your ID / password?" => autre texte en haut de popup
		url = url + '&viewForgetPW='+ viewForgetPW
	logPopup = window.open(url, getLinkID(url),"width="+width+",height="+height+",titlebar=0,toolbar=0,scrollbars=0,resizable=no,top="+top+",left="+left);
	if (logPopup)
		if (!logPopup.closed)
			logPopup.focus();
}

function login(url, width, height, redirect, resizable, loginwidth, loginheight, bypasslogin)
{
	var left = (screen.availWidth-width)/2;
	var top = (screen.availHeight-height)/2;
	if (!loginwidth) loginwidth = 380;
	if (!loginheight) loginheight = 340;
	if (!height) height = 400;
	bypasslogin = !(!bypasslogin);
	redirect = (redirect == false)? "no" : "yes";
	resizable = (resizable == false)? "no" : "yes";
	if (bypasslogin || GetCookie(".ASPXUSERDEMO")!=null)
	{
		if (width)
		{
			logPopup = window.open(url, getLinkID(url),'width='+ width + ',height='+ height +',titlebar=0,toolbar=0,scrollbars=1,resizable='+resizable+',left='+left+',top='+top);
		}
		else
		{
			location.href = url;
			logPopup = false;
		}
	}
	else
	{
		url = defaultSite + '/common/' + logFolder + '/navigation/login.aspx?rfr=' + escape(location.href) + '&url='+ escape(url);
		if (width)
			url += "&target=popup&width="+ width + "&height="+ height +"&r=" + redirect +"&s=" + resizable;
		logPopup = window.open(url, getLinkID(url),'width='+loginwidth+',height='+loginheight+',titlebar=0,toolbar=0,scrollbars=0,resizable=no,top=130,left=250');
	}
	if (logPopup)
		if (!logPopup.closed)
			logPopup.focus();
}

function closePopup()
{
	if(logPopup) {
		if (!logPopup.closed)
		{
			logPopup.close();
			logPopup = false;
		}
	}
}
var linkArray = new Array();

window.onUnload=closePopup();

function getLinkID(url)
{
	var id = "";
	for(i=0; i<url.length; i++)
	{
		id += url.charCodeAt(i, i+1);
	}
	return id;
}

function GetCookie(name) {
	var cookie = " " + document.cookie;
	var tmpCookie = cookie.toUpperCase();
	name = name.toUpperCase();

	var offset = 0;
	var end = 0;
	var end2 = 0;
	var search = " " + name + "=";
	offset = tmpCookie.indexOf(search);
	if (offset != -1) {
		offset += search.length;
		end = tmpCookie.indexOf(";", offset)
		if (end == -1) {
			end = tmpCookie.length;
		}
		end2 = tmpCookie.indexOf("&", offset)
		if (end2 == -1) {
			end2 = tmpCookie.length;
		}
		if (end2 < end)
			end = end2;
		return unescape(cookie.substring(offset, end));
	}
	var search = "&" + name + "=";
	offset = tmpCookie.indexOf(search);
	if (offset != -1) {
		offset += search.length;
		end = tmpCookie.indexOf(";", offset)
		if (end == -1) {
			end = tmpCookie.length;
		}
		end2 = tmpCookie.indexOf("&", offset)
		if (end2 == -1) {
			end2 = tmpCookie.length;
		}
		if (end2 < end)
			end = end2;
		tmpCookie = unescape(cookie.substring(offset, end));
		if (tmpCookie != "") {
			return tmpCookie;
		}
	}
	return null;
}