// Flash header Script
// Club Express

if(window.attachEvent) //IE
{
	window.attachEvent("onload", _initPageFunction);
}
else if(window.addEventListener) //DOM
{
	window.addEventListener("load", _initPageFunction, false);
}

// Function used to initialize all functions used in page
function _initPageFunction()
{
	_initLogo();
	_checkMessageBarDashboard();
	fix_cart();

}

// function that insert a link over the logo in the header of the page for SEO
function _initLogo()
{
	var oDivLogo = document.getElementById('contentLogo');
	var oDivHeader = document.getElementById('contentHeader');
	
	if(oDivLogo){oDivLogo.innerHTML = '<a href="/" title="Club Express">Club Express</a>';}
	if(oDivHeader){oDivHeader.innerHTML = '<a href="/" title="Imprimerie Papineauville">Imprimerie Papineauville</a>';}
}

function _checkMessageBarDashboard()
{
	if(Form1.action.indexOf("Dashboard.aspx") != -1)
	{
		var statusBar = document.getElementById("oDivStatusBar");
		if(statusBar)
		{
			var tableStatusBar = statusBar.firstChild;
			if(tableStatusBar)
			{
				tableStatusBar.style.marginTop = "55px";
			}
		}
	}
}


function openCatalog(sPath, sLang)
{	
							
	var w = 1000 + 32;
 	var h = 700 + 96;
  	
	var wleft = (screen.width - w) / 2;
  	var wtop = (screen.height - h) / 2;
	
	var win = window.open('/ecom_theme/img/medias/catalogue/catalogue.htm?p='+sPath+'&l='+sLang,'mywindow','width=1000,height=700,left='+wleft+'top='+wtop);
	
	if(win && win.moveTo)
	{
	
		try
		{		
			win.moveTo(wleft,wtop);

			win.focus();
		}
		catch(e){}
	}
}



function openPdfFile(sFileName)
{
	
	var sFile = '/ecom_theme/img/medias/catalogue/' + sFileName;

	var w = 900 + 32;
 	var h = 600 + 96;
  	
	var wleft = (screen.width - w) / 2;
  	var wtop = (screen.height - h) / 2;

	var win = window.open(sFile, 'mypdfwindow','width=900, height=600, resizable=yes, left='+wleft+', top='+wtop);
	
	if(win && win.moveTo)
	{
		try
		{
			win.moveTo(wleft,wtop);
		}
		catch(e){}
	}


}

function getQueryVariable(variable) 
{  
	var query = window.location.search.substring(1);  
	var vars = query.split("&");  

	for (var i=0;i<vars.length;i++) 
	{    
		var pair = vars[i].split("=");
		if (pair[0] == variable) 
		{      
			return pair[1];    
		}  
	} 
}

document.getElementsByClassName = function()
{
	//Ie getElementsByClassName fix
	if(document.hasChildNodes && arguments[0])
	{
		var data = new Array();
		
		for(a=0;a<document.getElementsByTagName("*").length;a++)
		{
			if(document.getElementsByTagName("*")[a].className == arguments[0])
			{
				data.push(document.getElementsByTagName("*")[a]);
			}
		}
		
		return data;
	}
}



function fix_cart()
{

	var imgDiv=document.createElement('div');
	
	imgDiv.innerHTML='<img src="/ecom_theme/img/sp.gif" style="float:right;width:195px;height:31px;" />';

	var a = document.getElementById("contentPageContent");
	var b = document.getElementById("contentPageTitle");
	var c = document.getElementById("shopping-cart");
	var d = document.getElementById("lblMessageTop");

	var contenu_contentPageContent = a.innerHTML;
	var tableau=document.getElementsByClassName("newProductPromotion");

	if(d)
	{

		if(navigator.userAgent.indexOf("Firefox")!=-1)
		{		
			d.innerHTML="";
			d.appendChild(imgDiv);
		
			d.innerHTML+=contenu_contentPageContent;
		}

		if(navigator.userAgent.indexOf("OfficeLivePatch")!=-1)
		{	
			d.innerHTML="";
			d.appendChild(imgDiv);
		
			d.innerHTML+=contenu_contentPageContent;
		}

		if(navigator.userAgent.indexOf("Safari")!=-1)
		{	
			imgDiv.innerHTML='<img src="/ecom_theme/img/sp.gif" style="float:right;width:195px;height:50px;" />';
			d.innerHTML="";
			d.appendChild(imgDiv);
		
			d.innerHTML+=contenu_contentPageContent;
		}

		if(navigator.userAgent.indexOf("Chrome")!=-1)
		{
			imgDiv.innerHTML='<img src="/ecom_theme/img/sp.gif" style="float:right;width:195px;height:50px;" />';
			d.innerHTML="";
			d.appendChild(imgDiv);
	
			d.innerHTML+=contenu_contentPageContent;
		}
	}

	if(b!=null)
	{
		if(b.offsetHeight==0&&tableau[0]!=null&&c!=null)
		{
			if(navigator.userAgent.indexOf("Firefox")!=-1)
			{
				tableau[0].style.paddingTop="35px";
			}

			if(navigator.userAgent.indexOf("Safari")!=-1)
			{
				tableau[0].style.paddingTop="60px";
			}

			if(navigator.userAgent.indexOf("Chrome")!=-1)
			{
				tableau[0].style.paddingTop="60px";
			}

			if(navigator.userAgent.indexOf("OfficeLivePatch")!=-1)
			{
				tableau[0].style.paddingTop="25px";
			}
	
		}
	}

	if(tableau[0]==null&&d==null)
	{
		if(navigator.userAgent.indexOf("Firefox")!=-1)
		{
			a.innerHTML="";
			a.appendChild(imgDiv);
	
			a.innerHTML+=contenu_contentPageContent;

		}

		if(navigator.userAgent.indexOf("OfficeLivePatch")!=-1)
		{
			a.innerHTML="";
			a.appendChild(imgDiv);
		
			a.innerHTML+=contenu_contentPageContent;

		}
		
		if(navigator.userAgent.indexOf("Safari")!=-1)
		{
			imgDiv.innerHTML='<img src="/ecom_theme/img/sp.gif" style="float:right;width:195px;height:50px;" />';
			a.innerHTML="";
			a.appendChild(imgDiv);
	
			a.innerHTML+=contenu_contentPageContent;
		}

		if(navigator.userAgent.indexOf("Chrome")!=-1)
		{
			imgDiv.innerHTML='<img src="/ecom_theme/img/sp.gif" style="float:right;width:195px;height:50px;" />';
			a.innerHTML="";
			a.appendChild(imgDiv);
	
			a.innerHTML+=contenu_contentPageContent;
		}
	}
}