// common scripts
// Core scripts v.3.5 - 09.07.02

/*
These scripts are designed to be root relative - they require the site to operating as a domain or port number!

*/

function isIE6() {
 var nom_nav = navigator.appName;
 var ver_nav = navigator.appVersion;

 // IE6
 var isIE6 = false;
 var ie6 = "MSIE 6.0";
 if(nom_nav == "Microsoft Internet Explorer" && ver_nav.search(ie6) != -1){
   isIE6 = true;
 }
 return isIE6;
}


// Window open code

// Better window code


function openWin( winURL, winName, winWidth, winHeight, winX, winY, scrollBars, statusBar, menuBar, resizable ) {
	winName = window.open( winURL, winName, 'width='  + winWidth + ',height='  + winHeight + ',top=' + winX + ',left=' + winY + ',screenX=' + winX + ',screenY=' + winY + ',location=no,scrollbars=' + scrollBars + ',directories=no,status=' + statusBar + ',menubar=' + menuBar + ',personalbar=no,resizable=' + resizable );
	// winName.scrollTo( 0, 0 );
}

// Better window code lite
function openWinLite( winURL, winName ) {
	winName = window.open( winURL, winName, 'width=400,height=300,top=100,left=100,screenX=100,screenY=100,location=no,scrollbars=no,directories=no,status=no,menubar=no,personalbar=no,resizable=no' );
	// winName.scrollTo( 0, 0 );
}

function printerFriendlyWin(winURL) {
	winName = window.open( winURL, 'printerWin', 'width=570,location=yes,scrollbars=yes,directories=yes,status=yes,menubar=yes,personalbar=no,resizable=yes');
}

function openHelpWin( winURL, winName, winWidth, winHeight ) {
	winName = window.open( winURL, winName, 'width='  + winWidth + ',height='  + winHeight + ',top=100,left=100,screenX=100,screenY=100,location=no,scrollbars=yes,directories=no,status=yes,menubar=no,personalbar=no,resizable=yes' );
	// winName.scrollTo( 0, 0 );
}


// Calendar window opener
function calendarWin( winURL, winWidth, winHeight ) {
	calendarWinRef = window.open( winURL, 'calendarWinSysName', 'width='  + winWidth + ',height='  + winHeight + ',top=50,left=50,screenX=50,screenY=50,location=no,scrollbars=yes,directories=no,status=yes,menubar=no,personalbar=no,resizable=yes' );
	// calendarWinRef.scrollTo( 0, 0 );
}

function printerBCardWin(winURL) {
	winName = window.open( winURL, 'printerWin', 'width=400,height=350,location=yes,scrollbars=yes,directories=yes,status=yes,menubar=yes,personalbar=no,resizable=yes');
}


// Generally, it's safe to amalgamate all Dreamweaver code down here

function createObject( n, d ) {
	// Object creation code
	var p, i, x;
	if( !d ) {
		d = document;
	}
	if( ( p = n.indexOf( "?" ) ) > 0 && parent.frames.length ) {
		d = parent.frames[n.substring( p + 1 )].document;
		n = n.substring( 0, p );
	}
	if( !( x = d[n] ) && d.all ){
		x = d.all[n];
		for( i = 0; !x && i < d.forms.length; i++ ) {
			x = d.forms[i][n];
		}
		for( i = 0; !x && d.layers && i < d.layers.length; i++ ) {
			x = createObject( n, d.layers[i].document );
		}
	}
	return x;
}

function preloadImages() {
	var d = document;
	if( d.images ){
		if( !d.preloadArr ) {
			d.preloadArr = new Array();
			var i, j = d.preloadArr.length, a = preloadImages.arguments;
			for( i = 0; i < a.length; i++ ) {
				if ( a[i].indexOf( "#" ) != 0 ){
					d.preloadArr[j] = new Image; d.preloadArr[j++].src = a[i];
				}
			}
		}
	}
}

function swapImage() {
	var i, j = 0, x, a = swapImage.arguments;
	document.imageRestoreArr = new Array;
	for( i = 0; i < ( a.length - 2 ); i += 3 )
		if( ( x = createObject( a[i] ) ) != null ) {
			document.imageRestoreArr[j++] = x;
			if( !x.oSrc )
				x.oSrc = x.src;
				x.src = a[i + 2];
				}
}

function swapImageRestore() {
	var i, x, a = document.imageRestoreArr;
	for( i = 0; a && i < a.length && ( x = a[i] ) && x.oSrc; i++ ) {
		x.src = x.oSrc;
	}
}

/* onLoad="preloadImages('images/navigation/home_over.gif')" */

/* onMouseOver="swapImage('aboutus','','image_over.file',1)" onfocus="swapImage('aboutus','','image_over.file',1)" onMouseOut="swapImageRestore()" onblur="swapImageRestore()" */

function searchOnClick(searchInput) {
   if(searchInput.value == "") {
      searchInput.value = "";
   }
}

function searchOnBlur(searchInput) {
   if(searchInput.value == '') {
      searchInput.value = "";
   }
}

function getElementsByClassName(name, parentElement)
{
	parentElement = parentElement !=  null ? parentElement : document;
  var         my_array = parentElement.getElementsByTagName("*");
  var         retvalue = new Array();
  var        i;
  var        j;

  for (i = 0, j = 0; i < my_array.length; i++)
  {
    var c = " " + my_array[i].className + " ";
    if (c.indexOf(" " + name + " ") != -1)
      retvalue[j++] = my_array[i];
  }
  return retvalue;
}

function getfirstElementByClassName(name, parentElement)
{
	var retvalue = null;
	var elementArray = getElementsByClassName(name, parentElement);
	if(elementArray != null && elementArray.length > 0) {
		retvalue = elementArray[0];
	}
	return retvalue;
}

function displayAgence(agenceIndex, agences) {
	for(var i=0; i<agences.length; ++i) {
		var divAgence = agences[i];
		divAgence.style.display = "none";
	}
	agences[agenceIndex].style.display = "block";
}

function goToContactForm(formUrl, reason, source) {
   var sourceStr = "";
   if(source != null) {
      sourceStr = "&source="+escape(source);
   }
   document.location.href = formUrl+"?reason="+escape(reason)+sourceStr;
}


function openVideo(file) {
  myLightWindow.activateWindow ({
    href:'/video/video.html?file=' + file,
    type: 'external',
    title: '',
    height: 470,
    width: 595
  });
}