// JavaScript Document
isMac = (window.navigator.appVersion.indexOf("Mac") != -1);
function getTab() {
	var href=document.location.href;
	var arr;
	arr=new Array('quality','services','company','contact','expertise','mission');
	for(i=0; i<arr.length;i++) {
		if(href.indexOf(arr[i])!=-1) {
			document.getElementById('menu-'+arr[i]).className='oN';
		}
	}
}
function openWindow(uurl,w,h,sb,tb,st,rz) {
	if(uurl) {
		if(!w) w=540;
		if(!h) h=540;
		if(sb=="") sb=0;
		if(tb=="") tb=0;
		if(st=="") st=0;
		if(rz=="") rz=1;
		var winH;
		var winW;
		var ttop;
		var lleft;
		winH=h/2;
		winW=w/2;
		ttop=screen.availHeight/2-winH;
		lleft=screen.availWidth/2-winW;
		window.open(uurl,'','top='+ttop+',left='+lleft+',width='+w+',height='+h+',scrollbars='+sb+',toolbars='+tb+',resizable='+rz+',status='+st);
	}
}
function bookmarkIt() { 
  var bookmarktitle = document.title;
  var bookmarkurl = top.document.location;
  var netscape
  var macintosh
  netscape="Attention Netscape Users. To Bookmark this page please click the page you would like to bookmark and press CTRL+D. If you would like to add this page to your Netscape Sidebar, please click OK on the next window which appears.";
  macintosh="Attention Macintosh User. To Bookmark this page please click the page you would like to bookmark and press CTRL+D.";

  if (window.sidebar&&window.sidebar.addPanel) { 
    alert(netscape);
    window.sidebar.addPanel(bookmarktitle, bookmarkurl,""); 
  } else if (isMac) {
    alert(macintosh);
  } else if (document.all) {
    window.external.AddFavorite(bookmarkurl, bookmarktitle);
  } else if (window.opera && window.print) {
    return true;
  }
}
function printIt() {
  //save existing user's info
  /*
  var h = factory.printing.header;
  var f = factory.printing.footer;
  //set header and footer to blank
  factory.printing.header = "";
  factory.printing.footer = "";
  //print page without prompt
  factory.DoPrint(false);
  //restore user's info
  factory.printing.header = h;
  factory.printing.footer = f;*/
  var macprint;
  macprint = "Attention Macintosh User. Unfortunately this functionality is not available on the Macintosh OS. Please click the page you would like to print a select print from your browser menu.";
  if (isMac) { 
    alert(macprint);
  } else {
  	self.print();
  }
}
function sendIt(p,lang) {
	var floc=document.location.href;
	var ftit=document.title;
	if(floc.indexOf('sendpage')==-1)
		document.location.href="/"+lang+"/sendpage.php?p="+p+"&t="+ftit;
}
function setCookie(name, value, path, domain, secure) {
	//deleteCookie(name, path, domain);
	var d=new Date();
	var t=d.getTime()+(61*24*60*60*1000);
	d.setTime(t);
    document.cookie= name + "=" + escape(value) +
        ((d) ? "; expires=" + d.toGMTString() : "") +
        ((path) ? "; path=" + path : "/") +
        ((domain) ? "; domain=" + domain : "") +
        ((secure) ? "; secure" : "");
	return 0;
}
function getCookie(name) {
    var dc = document.cookie;
    var prefix = name + "=";
    var begin = dc.indexOf("; " + prefix);
    if (begin == -1) {
        begin = dc.indexOf(prefix);
        if (begin != 0) return null;
    }
    else {
        begin += 2;
    }
    var end = document.cookie.indexOf(";", begin);
    if (end == -1) {
        end = dc.length;
    }
    return unescape(dc.substring(begin + prefix.length, end));
}
function deleteCookie(name, path, domain) {
    if (getCookie(name)) {
        document.cookie = name + "=" + 
            ((path) ? "; path=" + path : "/") +
            ((domain) ? "; domain=" + domain : "") +
            "; expires=Thu, 01-Jan-70 00:00:01 GMT";
    }
	return 0;
}
function setLanguage(l,page) {
	setCookie('lang',l,"/");
	return document.location.href=page;
}
function verify(lang) {
	al=0;
	i=document.forms[0].elements.length;
	if(lang=="f")
		sRet="Veuillez remplir les champs suivants:\n\n";
	else
		sRet="Please correct these required fields:\n\n";
	for(j=0;j<i;j++) {
		el=eval(document.forms[0].elements[j]);
		if((el.value=="") && el.id!="") {
			sRet+="\n"+el.id;
			if(al!=1) {
				if(el.type!="hidden") el.focus();
			}
			al=1;
			switchClass(el,1);
		}
		else {
			if(el.id.indexOf("email")!=-1 || el.id.indexOf("ourriel")!=-1) {
				if (echeck(el.value)==false) {
					if(lang=="f")
						sRet+="\n"+el.id+" n'est pas valide";
					else
						sRet+="\n"+el.id+" is not valid";
					al=1;
					switchClass(el,1);
				}
				else {
					switchClass(el,0);
				}
			}
			else {
				switchClass(el,0);
			}
		}
	}
	if(al==1) {
		alert(sRet);
		return false;
	}
	else {/*
		if(lang=="f")
			alert('Merci. Nous accuserons la réception de votre demande bientôt.');
		else
			alert('Thank you.  We will acknowledge receipt of your request shortly.');*/
		return true;
	}
}
function switchClass(el,c) {
	var cl;
	if(c==1) {
		if(el.tagName.toLowerCase()=="select") cl="selErr"; else cl="err";
		//alert(t);
	}
	else {
		cl="norm";
	}
	el.className=cl;
	//var t;
	//t=toString(el.id+'-txt');
	//eltxt=document.getElementById(t)
	//if(eltxt) 
	//alert(eltxt.className);//="errtxt";
}
function echeck(str) {
		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		if (str.indexOf(at)==-1){
		   return false;
		}
		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   return false;
		}
		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    return false;
		}
		if (str.indexOf(at,(lat+1))!=-1){
		   return false;
		}
		if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		   return false;
		}
		if (str.indexOf(dot,(lat+2))==-1){
		   return false;
		}		
		if (str.indexOf(" ")!=-1){
		   return false;
		}
 		return true;
}