//*-------------------------------------------------------------------------
//* General functions for the site.
//*-------------------------------------------------------------------------

//* get out of frames, just in case.
if (top.frames.length!=0) {
    if (window.location.href.replace)
        top.location.replace(self.location.href);
    else
        top.location.href=self.document.href;
}
//*******************************************************************************
//	Flip Language
//******************************************************************************* 	
function flipLang ()  {

	var dir = location.href.substring(0,location.href.lastIndexOf('/')+1);
	var thefile = location.href.substring(dir.length,location.href.length+1);
//	alert("thefile = " + thefile);	

//* If file name contains # (like in #top), get rid of it
	if (thefile.lastIndexOf('#') > 0 ) thefile = thefile.substring(0,thefile.lastIndexOf('#')+0);  
//alert(thefile.lastIndexOf('#'))
 	
//	alert("thefile = " + thefile);	
 	if (thefile == "" || filenm == urlname || filenm == testurl) thefile = "index-" + pagelang + ".asp";  // pagelang resolved in setup-e ( or -f)

//	alert("2 filenm = |" + filenm.substring(0,filenm.lastIndexOf('.')-0) + "|");
	
  	fileprefx = thefile.substring(0,thefile.lastIndexOf('.')-0);	  // test-f  - filename before "."  
	curlang = rightString(fileprefx,1);								// f or e				
 	fileroot = thefile.substring(0,thefile.lastIndexOf('.')-2);      // the string before -e
   	filetype = thefile.substring(thefile.lastIndexOf('.')+0);   //  .asp
   	
	if (curlang == "") curlang = pagelang; //* curlang will be blank for homepage specified without fn in url, so use failsafe var pagelang.
	if (curlang == "e") {
		newdir = "../fr/";
		newlang = "f";
	}		
	else {
		newdir = "../en/";
		newlang = "e";
	}
	newfile = newdir + fileroot + "-" + newlang + filetype

//	 alert("\nthefile = " + thefile + "\nfileprefx = " + fileprefx + "\ncurlang = " + curlang + "\nfileroot = " + fileroot + "\nfiletype = " + filetype + "\nNew File = " + newfile );
	 
//  var temp = window.location.href;
//  alert(temp.substring(temp.lastIndexOf('/') + 1));

 	location.href = newfile;
}

function getFileName(){
  var temp = window.location.href;
  alert(temp.substring(temp.lastIndexOf('/') + 1));
}


//*******************************************************************************
//	Handle onLoad event - Not used, but here for future use.
//******************************************************************************* 	
function doLoad(){
 //  invi(1, "pageload");   	// 0 = make visible  1=make invisible	
}

//* flag 0 = visible  1 = invisible
function invi(flag, obj){
	if (!DHTML) return;
	var x = new getObj(obj);
	x.style.visibility = (flag) ? 'hidden' : 'visible'
}

function getObj(name)
{
  if (document.getElementById)
  {
  	this.obj = document.getElementById(name);
	this.style = document.getElementById(name).style;
  }
  else if (document.all)
  {
	this.obj = document.all[name];
	this.style = document.all[name].style;
  }
  else if (document.layers)
  {
   	this.obj = document.layers[name];
   	this.style = document.layers[name];
  }
}
 
function flipImg(imgNam,imgTyp,onoff){
//*******************************************************************************
//	Do the mouse over image flipping.
//******************************************************************************* 		
  	if(document.images){ 	
 		document.images[imgNam].src=eval(imgTyp+onoff+'.src');
  	}
}

function doClear ( form ) {	
//*******************************************************************************
// Clear Form  - pagelan is defined in setup-e.js (or -f).
//*******************************************************************************	
//alert(pagelang);
    var msg_e = "Are you sure that you want to clear all the data you have entered on this form?";
    var msg_f = "Voulez-vous vraiment effacer toutes les données?";
    var clearmsg = msg_e;
    if (pagelang == "f") clearmsg = msg_f;
    
	var confirmOK = confirm(clearmsg);
  	if (confirmOK) document.form0.reset();    
}

function doSearch ( form ) {	
//*******************************************************************************
// Validate Form
//*******************************************************************************	
	var firstmessage="Please provide the following valid information:\n____________________________________\n ";
	var errormessage="";
	var len;
	
//	alert("Search Function not yet implemented");
		document.form1.action = "search-" + pagelang + ".asp";  //* Search
  		document.form1.method = "POST";
  		 document.form1.submit();
		return(0); 
}

function clearText(thefield){
//*******************************************************************************
//	Clear default form value on mouse focus
//******************************************************************************* 	
	if (thefield.defaultValue==thefield.value) thefield.value = "";
} 

function setCookie(name, value, expires, path, domain, secure) {
//*******************************************************************************
// Generic rtn to set a cookie.
//*******************************************************************************
       var curCookie = name + "=" + escape(value) +
           ((expires) ? "; expires=" + expires.toGMTString() : "") +
           ((path) ? "; path=" + path : "") +
           ((domain) ? "; domain=" + domain : "") +
           ((secure) ? "; secure" : "");
       document.cookie = curCookie;
}
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 makeArray(){
    this.length = makeArray.arguments.length 
        for (var i = 0; i < this.length; i++)
        this[i + 1] = makeArray.arguments[i]
}

function showStatus(text) {
//*******************************************************************************
// Show text on status bar. Use this to get around IE5 bug.
// onMouseOver="showStatus('text to display');return true" onMouseOut="window.status='';return true"
//*******************************************************************************	
    window.setTimeout('window.status="' + text + '"', 1);
}

function countChar(searchString, theChar) {
//*******************************************************************************
// string for a specific character and stops its search when it finds it or runs out of characters to look for
//*******************************************************************************
	var found = false
	n = 0;
	count = 0;
//	alert(searchString)
 //alert("test".charAt(1))
		for (i=0; i <= searchString.length; i++) {
	//		alert(searchString.charAt[i])
			if (searchString.charAt(i) == theChar){
				found = true;
				count++;
//				alert("count=" + count)
			}			
			else {
				n++;
			}	
		} 
//	alert(count + " n=" + n)
	return(count);
	
}

function xcountChar(searchString, theChar) {
//*******************************************************************************
// string for a specific character and stops its search when it finds it or runs out of characters to look for
//*******************************************************************************
	var found = false
	n = 0;
		while (n <= searchString.length || !found) {
		if (searchString.charAt(n) == theChar){
			found = true;
		}			
		else {
			n++;
		}	
	} 
	return(n);
}
 
function spaceTrim(InString) {
//*******************************************************************************
// Trim leading and trailing spaces of form input fields
//*******************************************************************************
	var LoopCtrl=true;
	while (LoopCtrl) {
		if (InString.indexOf("  ") != -1) {
			Temp = InString.substring(0, InString.indexOf("  "))
			InString = Temp + InString.substring(InString.indexOf("  ")+1, 
				InString.length)
		} else
			LoopCtrl = false;
	}
	if (InString.substring(0, 1) == " ")
		InString = InString.substring(1, InString.length)
	if (InString.substring (InString.length-1) == " ")
		InString = InString.substring(0, InString.length-1)
	return (InString)
}
  	
function isNumberString2 (InString)  {
//***********************************************************
// Just numbers
//***********************************************************
	if(InString.length==0) 
		return (false);
	RefString="1234567890";
	for (Count=0; Count < InString.length; Count++)  {
		TempChar= InString.substring (Count, Count+1);
		if (RefString.indexOf (TempChar, 0)==-1)  
			return (false);
	}
	return (true);
}

function rightString (InString, num)  {
	OutString=InString.substring (InString.length-num, InString.length);
	return (OutString);
}