/*Browsercheck object*/
function cm_bwcheck(){
	//In theory we should use object detection, but this script needs work-arounds for almost every browser...
	this.ver=navigator.appVersion
	this.agent=navigator.userAgent.toLowerCase()
	this.dom=document.getElementById?1:0
	this.ns4=(!this.dom && document.layers)?1:0;
	this.op=window.opera 
	this.moz=(this.agent.indexOf("gecko")>-1 || window.sidebar)
	this.ie=this.agent.indexOf("msie")>-1 && !this.op
	if(this.op){
		this.op5=(this.agent.indexOf("opera 5")>-1 || this.agent.indexOf("opera/5")>-1)
		this.op6=(this.agent.indexOf("opera 6")>-1 || this.agent.indexOf("opera/6")>-1)
		this.op7=this.dom&&!this.op5&&!this.op6 //So all higher opera versions will use it
	}else if(this.moz) this.ns6 = 1
	else if(this.ie){
		this.ie4 = !this.dom && document.all
  	this.ie5 = (this.agent.indexOf("msie 5")>-1)
  	this.ie55 = (this.ie5 && this.agent.indexOf("msie 5.5")>-1)
  	this.ie6 = this.dom && !this.ie4 && !this.ie5 && ! this.ie55
	}
	this.mac=(this.agent.indexOf("mac")>-1)
	this.bw=(this.ie6 || this.ie5 || this.ie4 || this.ns4 || this.ns6 || this.op5 || this.op6 || this.op7)
  this.usedom= this.ns6||this.op7//Use dom creation
  this.reuse = this.ie||this.op7||this.usedom //Reuse layers
  this.px=this.dom&&!this.op5?"px":""
	return this
}
	
function Replace(sString, sWhat, sBy){
	return sString.replace(sWhat, sBy);
}

function ShowProperties(obj){
	if (obj){
		alert("please wait, loading items")
		var buff;
		for (p in obj) {
			buff += p+' : '+obj[p]+'\n';
		}
		alert("done loading items")
		var width 	= 400;
		var height 	= 400;
		var winl	= ( screen.width  - width  ) / 2;
		var wint	= ( screen.height - height ) / 2;


		var specs = 'toolbar=0,location=0,directories=0,resizable=yes,menubar=0,status=0,scrollbars=yes,width='+ width +',height='+ height +',top='+ wint +',left=' + winl;

		wShowProperties = window.open("","ShowProperties",specs);
		wShowProperties.document.open();
		wShowProperties.document.write("<html><head><title>Properties</title></head><body><pre>" + buff + "</pre></body></html>");
		wShowProperties.document.close();
		wShowProperties.focus();
	}
}

function ValidateZip(f,zip){
		f.elements[zip].value = f.elements[zip].value.toUpperCase();
		var cp = f.elements[zip].value;  
		cp = cp.replace(' ','')
		if(!(cp.length == 6) || 
			!(cp.charAt(0) >= 'A' && cp.charAt(0) <= 'Z') ||
			!(cp.charAt(1) >= '0' && cp.charAt(1) <= '9') ||
			!(cp.charAt(2) >= 'A' && cp.charAt(2) <= 'Z') ||
			!(cp.charAt(3) >= '0' && cp.charAt(3) <= '9') ||
			!(cp.charAt(4) >= 'A' && cp.charAt(4) <= 'Z') ||
			!(cp.charAt(5) >= '0' && cp.charAt(5) <= '9'))  {
			return false;
		}else{
			return true;
		}
	}

var pPW = "";
function popupWindow( height, width, OpenPage, title, resize, scrollbar) 
{ 
	winl            = ( screen.width  - width  ) / 2;
	wint            = ( screen.height - height ) / 2;
	    
	if ( pPW.focus)
	{
		pPW.close();
	}
	    
	pPW = window.open(OpenPage,title,'toolbar=0,location=0,directories=0,resizable=' + resize + ',menubar=0,status=0,scrollbars=' + scrollbar + ',width='+ width +',height='+ height +',top='+ wint +',left=' + winl);
	    
	if ( self.focus ) pPW.focus();    
}

function IsValidEmail(sEmail){
	return (sEmail.search("^[_a-zA-Z0-9-]+(\.[_a-zA-Z0-9-]+)*@[a-zA-Z0-9-]+([\.][a-zA-Z0-9-]+)+$") != -1);
}

var ns4 = (document.layers)? true:false;            //NS 4 
var ie4 = (document.all)? true:false;               //IE 4 
var dom = (document.getElementById)? true:false;    //DOM 

//Fonction permettant de positionner un DIV à une position occupée par une ancre
function setToAnchor(ID_Anchor,Name_Anchor,ID_Div){
	var DivLeft = 0;   //Position du Div par rapport au côté gauche de la page 
	var DivTop = 0;   //Position du Div par rapport au haut de la page 
	if (dom){
		pos = document.getElementById(ID_Anchor);
		DivLeft = getLeft(pos);
		DivTop = getTop(pos);
		document.getElementById(ID_Div).style.left = DivLeft;
		document.getElementById(ID_Div).style.top = DivTop;
	}
	else if (ie4){
		pos = document.all[ID_Anchor];
		DivLeft = getLeft(pos);
		DivTop = getTop(pos);
		document.all[ID_Div].style.posLeft = DivLeft;
		document.all[ID_Div].style.posTop = DivTop;
	}
	else if (ns4){
		pos = document.anchors[Name_Anchor];
		DivLeft = pos.x;
		DivTop = pos.y;
		document.layers[ID_Div].pageX = DivLeft;
		document.layers[ID_Div].pageY = DivTop;
	}
}

function hideDiv(ID_Div){
	if (dom){
		document.getElementById(ID_Div).style.visibility = "hidden";
	}
	else if (ie4){
		document.all[ID_Div].style.visibility = "hidden";
	}
	else if (ns4){
		document.layers[ID_Div].visibility = "hide";
	}
}
function showDiv(ID_Div){
	if (dom){
		document.getElementById(ID_Div).style.visibility = "visible";
	}
	else if (ie4){
		document.all[ID_Div].style.visibility = "visible";
	}
	else if (ns4){
		document.layers[ID_Div].visibility = "show";
	}
}

function getLeft(MyObject){
    if (MyObject.offsetParent)
        return (MyObject.offsetLeft + getLeft(MyObject.offsetParent));
    else 
        return (MyObject.offsetLeft);
} 

function getTop(MyObject){
    if (MyObject.offsetParent)
        return (MyObject.offsetTop + getTop(MyObject.offsetParent));
    else
        return (MyObject.offsetTop);
}

function Trim(t){
	return t.replace(/(^\s*)|(\s*$)/g, "");
}