window.onload = function(){
	safariSearch();
	domTableEnhance();
	//langSwitch();
	//productsNav();
	addDate();
	getScreenSize();
	//getHeaderText();
	//linkFootnotes();
}


function safariSearch(){ // changes search box in Safari only
	if (navigator.userAgent.indexOf("Safari") != -1){
		document.forms[0].elements[0].type = 'search';
		document.forms[0].elements[0].value = '';
		document.forms[0].elements[0].placeholder = '';
		//document.forms[0].elements[0].style.width='156px';
		document.forms[0].elements[0].onclick=function(){
			document.forms[0].elements[0].value='';
		}
	}
}

function getHeaderText(){
/*
	ht = document.createElement("span");
	ht.appendChild(document.createTextNode('vitality'));
	document.getElementById("header_image").appendChild(ht);
	*/
}


function langSwitch(){
    if (window.location.href.indexOf('en/') > 0) { // english page
		newLoc = window.location.href.replace('en/','fr/');
    } else {
		a=document.getElementById('lang');
		a.removeChild(a.firstChild);
		a.appendChild(document.createTextNode('English'));
		newLoc = window.location.href.replace('fr/','en/');
    }
	document.getElementById('lang').setAttribute("href",newLoc);
}

function linkFootnotes(){
	var b=document.getElementById('content');
	/* */
	var sups = b.getElementsByTagName('sup');
	for (var i=0;i<sups.length;i++){
		var n=sups[i].firstChild.nodeValue;
		sups[i].removeChild(sups[i].firstChild);
		var na=document.createElement('a');
		na.setAttribute('href','#');
		na.setAttribute('onclick','window.location="#n'+n+'";return false;');
		na.appendChild(document.createTextNode(n));
		//ns=document.createElement('span');
		//ns.setAttribute('id','note'+n);
		na.setAttribute('id','note'+n);
		sups[i].appendChild(na);
		//sups[i].appendChild(ns);
	}
	
	/* */
	var notes=b.getElementsByTagName('div');
	for(var d=0;d<notes.length;d++){
		if (notes[d].className == 'footnotes'){
			var ps = notes[d].getElementsByTagName('p');
			for (var i=0;i<ps.length;i++){
				var num=new RegExp(/\D*[0-9]+/);
				var ptext = ps[i].firstChild.nodeValue.substring(0,3);
				if (num.test(ptext)){
					ptext=ptext.replace(/\D/,'');
					ptext=ptext.replace(/\D/,'');
					ps[i].setAttribute('id','n'+ptext);
					
					var lnk=document.createElement('a');
					lnk.setAttribute('href','#');
					lnk.setAttribute('onclick','window.location="#note'+ptext+'";return false;');
					if (navigator.userAgent.indexOf("MSIE") >=0){
					var str='\u00a0\u00a0<<';
					} else {
					var str='\u00a0\u00a0\u21a9';
					}
					lnk.appendChild(document.createTextNode(str));
					ps[i].appendChild(lnk);
				}
			}
			
		}
	}
}

function productsNav(){
	if (navigator.userAgent.indexOf('MSIE') != -1 && navigator.userAgent.indexOf('Windows') != -1){
		/*
		litems = document.getElementsByTagName('li');
		for(i=0;i<litems.length;i++){
		
			litems[i].onmouseover=function()
			{
				this.className='over';
			}
			litems[i].onmouseout=function()
			{
				this.className='';
			}
		}
		// */
		/*productCategories = new Array('generalhealth','immunehealth','boneandjoint','organhealth','cardiohealth','menshealth','womenshealth','sportperformance');
		for (i=0;i<productCategories.length;i++){
			if (document.getElementById(productCategories[i])){
				t = productCategories[i]+'_productlist';
				document.getElementById(productCategories[i]).onmouseover=function(){
					document.getElementById(t).style.display = 'block';
				}
				document.getElementById(productCategories[i]).onmouseout=function(){
					document.getElementById(t).style.display = 'none';
				}
			}
		}
		*/
		if (document.getElementById('generalhealth')){
			document.getElementById('generalhealth').onmouseover=function(){
				document.getElementById('generalhealth_productlist').style.display = 'block';
			}
			document.getElementById('generalhealth').onmouseout=function(){
				document.getElementById('generalhealth_productlist').style.display = 'none';
			}
		}
		if (document.getElementById('immunehealth')){
			document.getElementById('immunehealth').onmouseover=function(){
				document.getElementById('immunehealth_productlist').style.display = 'block';
			}
			document.getElementById('immunehealth').onmouseout=function(){
				document.getElementById('immunehealth_productlist').style.display = 'none';
			}
		}
		if (document.getElementById('boneandjoint')){
			document.getElementById('boneandjoint').onmouseover=function(){
				document.getElementById('boneandjoint_productlist').style.display = 'block';
			}
			document.getElementById('boneandjoint').onmouseout=function(){
				document.getElementById('boneandjoint_productlist').style.display = 'none';
			}
		}
		if (document.getElementById('organhealth')){
			document.getElementById('organhealth').onmouseover=function(){
				document.getElementById('organhealth_productlist').style.display = 'block';
			}
			document.getElementById('organhealth').onmouseout=function(){
				document.getElementById('organhealth_productlist').style.display = 'none';
			}
		}
		if (document.getElementById('cardiohealth')){
			document.getElementById('cardiohealth').onmouseover=function(){
				document.getElementById('cardiohealth_productlist').style.display = 'block';
			}
			document.getElementById('cardiohealth').onmouseout=function(){
				document.getElementById('cardiohealth_productlist').style.display = 'none';
			}
		}
		if (document.getElementById('menshealth')){
			document.getElementById('menshealth').onmouseover=function(){
				document.getElementById('menshealth_productlist').style.display = 'block';
			}
			document.getElementById('menshealth').onmouseout=function(){
				document.getElementById('menshealth_productlist').style.display = 'none';
			}
		}
		if (document.getElementById('womenshealth')){
			document.getElementById('womenshealth').onmouseover=function(){
				document.getElementById('womenshealth_productlist').style.display = 'block';
			}
			document.getElementById('womenshealth').onmouseout=function(){
				document.getElementById('womenshealth_productlist').style.display = 'none';
			}
		}
		if (document.getElementById('sportperformance')){
			document.getElementById('sportperformance').onmouseover=function(){
				document.getElementById('sportperformance_productlist').style.display = 'block';
			}
			document.getElementById('sportperformance').onmouseout=function(){
				document.getElementById('sportperformance_productlist').style.display = 'none';
			}
		}
	}
	if (document.getElementById('product_list')){
		p = document.getElementById('product_list');
		pCategories = p.getElementsByTagName('li');
		for (i=0;i<pCategories.length;i++){
			d=pCategories[i].getElementsByTagName('div');
			for(j=0;j<d.length;j++){
				if (d[j].className == "sub_menu"){
					e = d[j].getAttribute('id');
					dd = d[j].getElementsByTagName('div');
					if (dd.length == 4) {
						colW = 135;
					} else if (dd.length == 3) {
						colW = 160;
					} else if (dd.length == 2) {
						colW = 200;
					} else if (dd.length == 1) {
						colW = 230;
					} else {
						colW = 108;
					}
					//alert(e+' has '+dd.length+' columns.');
					for(k=0;k<dd.length;k++){
						dd[k].style.width=colW+'px';
						if (k == (dd.length -1)){
							dd[k].style.borderRight = 'none';
						}
					/*
						ul = dd[k].getElementsByTagName('ul');
						for (li=0;li<ul.length;li++){
							len = ul[li].firstChild.nodeValue.length;
						}
						
					// */
					}
				}
			}
		}
	}
	// */
}

window.onresize = function(){
	//alert('resize!');
	getScreenSize();
}


function getScreenSize(){
/*
	if (document.body.offsetWidth > 1220) {
		setLayoutSize('layoutLarge');
	} else if  (document.body.offsetWidth > 990) {
		setLayoutSize('layoutMedium');
	} else {
	*/
		setLayoutSize('layoutSmall');
//	}
	//sizeTimer = setTimeout("getScreenSize()", 100);
}

function setLayoutSize(title) {
	var i, a, main;
	for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
		if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title") && (a.getAttribute("title").indexOf('layout') > -1) ) {
			a.disabled = true;
			if(a.getAttribute("title") == title){
				a.disabled = false;
			}
		}
	}
}


function submitSearch(val){
    if (window.location.href.indexOf('en/') > 0) { // english page
	//window.location='/prototype/en/search.html';
	} else {
	//window.location='/prototype/fr/search.html';
	}
}

function show(element){
	e=document.getElementById(element);
	if (e){
		if (e.style.display != 'block'){
			e.style.display = 'block';
		} else {
			e.style.display = 'none';
		}
	}
}



function addDate(){
	dDate = document.createElement("span");
	dDate.appendChild(document.createTextNode(doDate()));
	document.getElementById("credit").appendChild(dDate);
}


function doDate(){
	mydate = new Date();
	year=mydate.getYear();
	if (year < 1000){
		year+=1900;
	}
	day=mydate.getDay();
	month=mydate.getMonth();
	daym=mydate.getDate();
	if (daym<10){ 
		daym="0"+daym;
	}
	
	dayarray=new Array("Dimanche","Lundi","Mardi","Mercredi","Jeudi","Vendredi","Samedi");
	montharray=new Array("janv.","f" + String.fromCharCode(233) + "v.","mars","avril","mai","juin","juillet","ao" + String.fromCharCode(251) + "t","sept.","oct.","nov.","d" + String.fromCharCode(233) + "c.");
	return dayarray[day]+", "+daym+" "+montharray[month]+" "+year;
}


function domTableEnhance()
{
	if(!document.createTextNode){return;}
	var tableClass='enhancedtable';
	var colourClass='row1';
	var hoverClass='enhancedtablerowhover';
	var activeClass='enhancedtableactive';
	var alltables,bodies,i,j,k,addClass,trs,c,a;
	alltables=document.getElementsByTagName('table');
	for (k=0;k<alltables.length;k++)
	{
		if(!alltables[k].className.match(tableClass)){continue;}
		bodies=alltables[k].getElementsByTagName('tbody');
		for (i=0;i<bodies.length;i++)
		{
			trs=bodies[i].getElementsByTagName('tr')
			for (j=0;j<trs.length;j++)
			{
				if(trs[j].getElementsByTagName('td').length>0)
				{
					addClass=j%2==0?' '+colourClass:'';
					trs[j].className=trs[j].className+addClass;
					trs[j].onclick=function()
					{
						if(this.className.match(activeClass))
						{
							var rep=this.className.match(' '+activeClass)?' '+activeClass:activeClass;
							this.className=this.className.replace(rep,'');
						} else {
							this.className+=this.className?' '+activeClass:activeClass;
						}
					}
					trs[j].onmouseover=function()
					{
						this.className=this.className+' '+hoverClass;
					}
					trs[j].onmouseout=function()
					{
						var rep=this.className.match(' '+hoverClass)?' '+hoverClass:hoverClass;
						this.className=this.className.replace(rep,'');
					}
				}
			}
		}
	}		
}


opacityChange=5;
imgH = 0;
imgV = 0;
dH = 0;
dV = 0;
iH=0;
iV=0;

function initImage(h,v, ih, iv) {
	imgH = h;
	imgV = v;
	iH = ih;
	iV = iv;
	// rate of change:
	dH = (h-ih) / (100 / opacityChange);
	dV = (v-iv) / (100 / opacityChange);
	imageId = 'largeimage';
	image = document.getElementById(imageId);
	setOpacity(image, 0);
	image.style.visibility = 'visible';
	image.style.display = 'block';
	window.setTimeout("fadeIn('"+imageId+"',"+0+",'up')", 50);
				
}

function setOpacity(obj, opacity) {
	opacity = (opacity == 100)?99.999:opacity;
  
  // IE/Win
	obj.style.filter = "alpha(opacity:"+opacity+")";
  	
  // Safari<1.2, Konqueror
	obj.style.KHTMLOpacity = opacity/100;
  
  // Older Mozilla and Firefox
	obj.style.MozOpacity = opacity/100;
  
  // Safari 1.2, newer Firefox and Mozilla, CSS3
	obj.style.opacity = opacity/100;

}

function hideImageDetails(){
	for (i=0;i<imagesToLoad.length;i++){
		document.getElementById(imagesToLoad[i]+"_details").style.display="none";
	}
}

function fadeIn(objId,opacity,direction) {
	if (document.getElementById) {
		obj = document.getElementById(objId);
		if (direction=="up") {
			if (opacity <= 100) {
				setOpacity(obj, opacity);
				//obj.style.width = ((imgH*opacity) / 100)+'px';
				//obj.style.height = ((imgV*opacity) / 100)+'px';
				if (opacity == 5){
				}
				obj.style.width = (iH+(dH*(opacity / opacityChange)))+'px';
				obj.style.height = (iV+(dV*(opacity / opacityChange)))+'px';
				opacity += opacityChange;
				window.setTimeout("fadeIn('"+objId+"',"+opacity+",'up')", 50);
			} else {
				document.getElementById('close_box').style.position='absolute';
				document.getElementById('close_box').style.top=(iV+(dV*(opacity / opacityChange))-5)+'px';
				document.getElementById('close_box').style.width=(iH+(dH*(opacity / opacityChange))-7)+'px';
				document.getElementById('close_box').style.left='-'+(iH+(dH*(opacity / opacityChange))-203)+'px';
				document.getElementById('close_box').style.display='block';
			}
		} else {
			if (opacity >= 0) {
				setOpacity(obj, opacity);
				opacity -= opacityChange;
				window.setTimeout("fadeIn('"+objId+"',"+opacity+",'dn')", 50);
			}
		}
	}
}

function closeLargeImage(){
	document.getElementById('largeimage').style.display = 'none';
	document.getElementById('close_box').style.display = 'none';
}
	

function reveal(e,d){
	if (document.getElementById(e)){
		document.getElementById(e).style.display = d;
	} else {
	}
}



/*function addEvent( obj, type, fn )
{
	if (obj.addEventListener)
		obj.addEventListener( type, fn, false );
	else if (obj.attachEvent)
	{
		obj["e"+type+fn] = fn;
		obj[type+fn] = function() { obj["e"+type+fn]( window.event ); }
		obj.attachEvent( "on"+type, obj[type+fn] );
	}
}

function removeEvent( obj, type, fn )
{
	if (obj.removeEventListener)
		obj.removeEventListener( type, fn, false );
	else if (obj.detachEvent)
	{
		obj.detachEvent( "on"+type, obj[type+fn] );
		obj[type+fn] = null;
		obj["e"+type+fn] = null;
	}
}

addEvent(window,onload,domTableEnhance);
*/

/*
*/
