/*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, tlbr, loc, resize, scrollbar, menu, statusbar) 
{ 
	if (height == 500){
		height = 700;
		}
	winl            = ( screen.width  - width  ) / 2;
	wint            = ( screen.height - height ) / 2;
	    
	if ( pPW.focus)
	{
		pPW.close();
	}
	    
	pPW = window.open(OpenPage,title,'toolbar=' + tlbr + ',location=' + loc + ',directories=0,resizable=' + resize + ',menubar=' + menu + ',status=' + statusbar + ',scrollbars=' + scrollbar + ',width='+ width +',height='+ height +',top='+ wint +',left=' + winl);
	    
	if ( self.focus ) pPW.focus();    
}

function ShowHideLayer(theObj, vis){
	document.getElementById(theObj).style.display=vis;
}

function ShowLayer(ele){
	ShowHideLayer(ele, 'block');
}

function HideLayer(ele){
	ShowHideLayer(ele, 'none');
}

function selectValue(oFld,sValue){
	for(var x = 0; sValue && x < oFld.options.length; x++)
		if(oFld.options[x].value == sValue)
			oFld.selectedIndex = x;
	if(oFld.selectedIndex == -1)
		return "";
	else
		return oFld.options[oFld.selectedIndex].value;
}

function enlargePhoto(photo){
	// showtrail(photo,'','','1',5,433);
}

function reducePhoto(){
	// hidetrail();
}

function Trim(t){
	return t.replace(/(^\s*)|(\s*$)/g, "");
}

function IsValidEmail(sEmail){
	return (sEmail.search("^[_a-zA-Z0-9-]+(\.[_a-zA-Z0-9-]+)*@[a-zA-Z0-9-]+([\.][a-zA-Z0-9-]+)+$") != -1);
}

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.display = "none";
	}
	else if (ie4){
		document.all[ID_Div].style.display = "none";
	}
	else if (ns4){
		document.layers[ID_Div].display = "none";
	}
}

function showDiv(ID_Div){
	if (dom){
		document.getElementById(ID_Div).style.display = "";
	}
	else if (ie4){
		document.all[ID_Div].style.display = "";
	}
	else if (ns4){
		document.layers[ID_Div].display = "";
	}
}

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 getDomainName(){
	var vszDomain = window.location.href.toLowerCase();
	
	//vszDomain = Replace(vszDomain, 'http://www.', '')
	vszDomain = Replace(vszDomain, 'http://', '')
	return vszDomain.substring(0, vszDomain.indexOf('/'));
}

function getScriptName(){
	var vszURL = window.location.href.toLowerCase();
	
	vszURL = Replace(vszURL, 'http://', '')
	return vszURL = Replace(vszURL, getDomainName(), '');
	
	
}

function DeleteCookie(name, path, domain) {
	var expires = ';expires=Thu, 01-Jan-70 00:00:01 GMT';
	(path)    ? ';path='    + path                  : '';
	(domain)  ? ';domain='  + domain                : '';

	if (GetCookie(name)){
		document.cookie = name + '=' + expires + path + domain;
	}
}

function GetCookie(name) {
	var cookies = document.cookie;
	var start = cookies.indexOf(name + '=');
	if (start == -1){
		return null;
	}
	var len = start + name.length + 1;
	var end = cookies.indexOf(';',len);
	if (end == -1){
		end = cookies.length;
	}
	return unescape(cookies.substring(len,end));
}

function IsCookieEnabled() {
	if (document.all) {
		if (!navigator.cookieEnabled) {
			return false;
		}else{
			return true;
		}
	}else {
		SetCookie('temp','temp');
		var temp = GetCookie('temp');
		if (!temp) {
			return false;
		}else{
		return true;
		}
	}
}

function SetCookie(name, value, expires, path, domain, secure) {
	value = escape(value);
	expires = (expires) ? ';expires=' + expires.toGMTString() :'';
	path    = (path)    ? ';path='    + path                  :'';
	domain  = (domain)  ? ';domain='  + domain                :'';
	secure  = (secure)  ? ';secure'                           :'';

	document.cookie = name + '=' + value + expires + path + domain + secure;
}

function getExpiryDate(nodays){
	var UTCstring;
	Today = new Date();
	nomilli=Date.parse(Today);
	Today.setTime(nomilli+nodays*24*60*60*1000);
	return Today;
}