
var ns4 = (document.layers) ? 1 : 0;
var ie4 = (document.all) ? 1 : 0;
var ns6 = (document.getElementById && !document.all) ? 1 : 0;

// Browser Window Dimensions
function winWidth(){
   return (ns4||ns6) ? window.innerWidth : document.body.clientWidth;
}

function winHeight(){
   return (ns4||ns6) ? window.innerHeight : document.body.clientHeight;
}

// switch menu images on mouse over
function MenuRollOver(intMenuID, obj){
	var oLeft, oMiddle, oRight;
	
	eval("oLeft		= document.getElementById('TopMenuLeft"		+ intMenuID + "');");
	eval("oMiddle	= document.getElementById('TopMenuMiddle"	+ intMenuID + "');");
	eval("oRight	= document.getElementById('TopMenuRight"	+ intMenuID + "');");

	if (oLeft && oMiddle && oRight){
		oLeft.background	= '/images/MenuLeftSide-over.gif';
		oMiddle.background	= '/images/MenuMiddle-over.gif';
		oRight.background	= '/images/MenuRightSide-over.gif';
	}else{
		ShowProperties(obj)
	}
}

// retore menu images on mouse out
function MenuRollOut(intMenuID, obj){
	var oLeft, oMiddle, oRight;
	eval("oLeft		= document.getElementById('TopMenuLeft"		+ intMenuID + "');");
	eval("oMiddle	= document.getElementById('TopMenuMiddle"	+ intMenuID + "');");
	eval("oRight	= document.getElementById('TopMenuRight"	+ intMenuID + "');");

	if (oLeft && oMiddle && oRight){
		oLeft.background	= '/images/MenuLeftSide.gif';
		oMiddle.background	= '/images/MenuMiddle.gif';
		oRight.background	= '/images/MenuRightSide.gif';
	}
}



function ShowHideLayer(theObj, vis){
	document.getElementById(theObj).style.display=vis;
}

function ShowLayer(ele){
	ShowHideLayer(ele, 'block');
}

function HideLayer(ele){
	ShowHideLayer(ele, 'none');
}

function IsValidEmail(sEmail){
	return (sEmail.search("^[_a-zA-Z0-9-]+(\.[_a-zA-Z0-9-]+)*@[a-zA-Z0-9-]+([\.][a-zA-Z0-9-]+)+$") != -1);
}

function IsValidURL(sURL){
	//return (sURL.search("(((http)|(https)|(ftp)|(telnet)|(mailto)|(gopher)|(news))://[^<>\s]+)") != -1);
	return (sURL.search("^(http|https|ftp)\://[a-zA-Z0-9\-\.]+\.[a-zA-Z]{2,3}") != -1);
}

function Replace(sString, sWhat, sBy){
	return sString.replace(sWhat, sBy);
}

function Reverse(sString) {
	for (var sNewString = '', i = sString.length-1;i>-1;i=i-1){
		sNewString += sString.charAt(i);
	}
	return sNewString;
}

function Trim(t){
	return t.replace(/(^\s*)|(\s*$)/g, "");
}

function IsEven(x){ 
	return (x % 2) ? false : true; 
}

function IsOdd(x){ 
	return !IsEven(x); 
}

function IsInteger(Number) {
    //Set the pattern
    var p = /^\d+$/; 

    if (Number) { 
        //Apply the pattern
        if (!p.test(Number)) { 
            return false;
        }else {
            return true;
        }
    }else{
        return false;
    }
}

function Max(Number1, Number2){
	return (Number1 > Number2) ? Number1 : Number2;
}

function Min(Number1, Number2){
	return (Number1 < Number2) ? Number1 : Number2;
}



// show object properties
function ShowProperties(obj){
	if (obj){
		try{
		
			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);
			if (wShowProperties){
				wShowProperties.document.open();
				wShowProperties.document.write("<html><head><title>Properties</title></head><body><pre>" + buff + "</pre></body></html>");
				wShowProperties.document.close();
				wShowProperties.focus();
			}
		}catch(e){
			alert(e)
		}
	}
}

function IsValidURL(sURL){
	return (sURL.search("^(http|https|ftp)\://[a-zA-Z0-9\-\.]+\.[a-zA-Z]{2,3}") != -1);
}
	
function IsValidDateRange(Date1,Date2){
	var dtDate1 = Date1.split("-");
	var dtDate2 = Date2.split("-");

	firstDate = new Date(dtDate1[1]+'/'+dtDate1[2]+'/'+dtDate1[0]); // Month-Day-Year
	secondDate = new Date(dtDate2[1]+'/'+dtDate2[2]+'/'+dtDate2[0]);

	return (secondDate.getTime() >= firstDate.getTime());
}

function checkPopupBlockers(){
	var wWindow
	wWindow = window.open("","dummy","toolbar=0,location=0,directories=0,resizable=no,menubar=0,status=0,scrollbars=no,width=1,height=1,top=1,left=1");
	self.focus();
	if (wWindow){
		wWindow.close();
		return true;
	}else{
		return false;
	}
}


function GetDate10201 (){
	navvers = navigator.appVersion.substring ( 0, 1 );
	var suffixe = "";
	if ( navvers > 3 )
		navok = true;
	else
		navok = false;
		today  = new Date;
		jour   = today.getDay();
		numero = today.getDate();
		if ( numero < 10 )
			numero = "0" + numero;
		mois = today.getMonth();
		if ( navok )
			annee = today.getFullYear();
		else
			annee = today.getYear();

		TabJour = new Array (	"dimanche",
								"lundi",
								"mardi",
								"mercredi",
								"jeudi",
								"vendredi",
								"samedi"
							);
		TabMois = new Array (	"janvier",
								"février",
								"mars",
								"avril",
								"mai",
								"juin",
								"juillet",
								"août",
								"septembre",
								"octobre",
								"novembre",
								"décembre"
							);				
	//	return TabJour[jour] + " " + numero + " " + TabMois[mois] + " " + annee;
	return numero + " " + TabMois[mois] + " " + annee;
}

function GetDate10202 (){
	navvers = navigator.appVersion.substring ( 0, 1 );
	var suffixe = "";
	if ( navvers > 3 )
		navok = true;
	else
		navok = false;
		today  = new Date;
		jour   = today.getDay();
		numero = today.getDate();
		if ( numero < 10 )
			numero = "0" + numero;
		mois = today.getMonth();
		if ( navok )
			annee = today.getFullYear();
		else
			annee = today.getYear();
		TabJour = new Array (	"Sunday",
								"Monday",
								"Tuesday",
								"Wednesday",
								"Thuersday",
								"Friday",
								"Saturday"
							);
		TabMois = new Array (	"January",
								"February",
								"March",
								"April",
								"May",
								"June",
								"July",
								"August",
								"September",
								"October",
								"November",
								"December"
							);
		switch (today.getDate())
		{
		  case 31:
		    suffixe =  ("st");
		    break;
		  case 21:
		    suffixe =  ("st");
		    break;
		  case 1:
		    suffixe =  ("st");
		    break;
		  case 2, 22:
		    suffixe =  ("nd");
		    break;
		  case 2:
		    suffixe =  ("nd");
		    break;
		  case 3:
		    suffixe =  ("rd");
		    break;
		  case 3, 23:
		    suffixe =  ("rd");
		    break;
		  default:
		    suffixe =  ("th");
		}
	return TabMois[mois] + " " + numero + ", " + annee;
}

function addBookmark(){
	var bookmarkurl		= window.location.href;
	var bookmarktitle	= document.title;
	if (document.all)
		window.external.AddFavorite(bookmarkurl,bookmarktitle)
}

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;
	}
}

function openPopupWindow(sURL, sName, sFeatures, sReplace)
{	    	  
	window.open(sURL, sName, sFeatures, sReplace);
}

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();    
}

var NewWindow = ""
function popup( height, width, OpenPage, title, resize, scrollbar){ 
    winl            = ( screen.width  - width  ) / 2;
    wint            = ( screen.height - height ) / 2;
	        
    if ( NewWindow.focus){
		NewWindow.close();
    }
	        
    NewWindow = 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 ) NewWindow.focus();    
}


function SetPageTitle(vszTitle){
	try{
		el = bw.ie4?document.all["txtMainTitle"]:document.getElementById("txtMainTitle");
		el.innerHTML = vszTitle;
	}catch(e){
	
	}
}
function setElementStyle(id, newClass){
	try{
		el = bw.ie4?document.all[id]:document.getElementById(id);
		el.className = newClass;
	}catch(e){
	
	}

}

var pAdmin = "";
function popupAdmin(vszURL){
	var width	= screen.width * 0.80;
	var height	= screen.height * 0.80;
	var winl	= ( screen.width  - width  ) / 2;
    var wint	= ( screen.height - height ) / 2;
	        
    if ( pAdmin.focus){
		pAdmin.close();
    }
	        
    pAdmin = window.open(vszURL,'admin','toolbar=0,location=0,directories=0,resizable=1,menubar=1,status=1,scrollbars=1,width='+ width +',height='+ height +',top='+ wint +',left=' + winl);
	        
    if ( self.focus ) pAdmin.focus(); 
}

function SetLink(url, type){
    switch (type){
        case 'external' :
                            window.open(url, '', 'toolbar=1,location=0,directories=1,resizable=1,menubar=1,status=1,scrollbars=1');
                            break;
        default         :   document.location.href = url;
                            break;
    }
}