// JavaScript functions used by RTO27 website 
// ...to protect personal information from robots that harvest email addresses 
// ...to allow reuse of information needed in more than one place
// ...to centralize updating of personal information 
// .. to reduce maintenance and upkeep of website 



//++++++++++++++++++++++++++++++++++++++
// Set up an error handler to give information about undefined variables.
// Likely a call to phone_mail_info(PersonArrayName) fails because the PersonArrayName
// variable has been mistyped or no information has yet been defined for PersonArrayName

window.onerror=myErrorHandler;

// Pass in the language variable to use if different from "e" 
function setlang (which) {
   lang = which;
} 

function myErrorHandler(msg, where, lineno) {
// we want to handle ONLY 'undefined' error messages
   if (msg.match(/undefined/)) { 
      words = msg.split(/ /);
      alert ("Variable "+ words[0]+ " has no information assigned to it.  "+
             "\nPerhaps the variable name is typed incorrectly or " +
             "\nno information has been set up for it");    
      return true;
}
// else return normal system error message.
}

//++++++++++++++++++++++++++++++++++++++++
// Links and contact information


// RETURN a clickable link showing email address to launch email window 
function liveemail(who) {
     return ("<a href='mailto:" + who["email"] + "'>" + who["email"] + "</a>");
}

// Display a clickable link showing email address to launch email window 
function liveemailwsubject(who, subject) {
     abc = "<a href='mailto:" + who["email"] + "?subject=" + subject + "'>" + who["email"] + "</a>";
     //alert (abc);   
     return abc;
}

// Display a clickable link showing a simple email address to launch email window 
function nameemail(who) {
     document.write ("<a href='mailto:" + who["email"] + "'>" + who["email"] + "</a>");
}

// Display a clickable link showing a vertical listing of name and (clickable) email address to launch email window 
function vnameemail(who) {
     document.write (who["name"] +"<br><a href='mailto:" + who["email"] + "'>" + who["email"] + "</a>");
}


// Display an person's name (NOT MUCH USE???)
function contact(who) {
  var aname = who["name"];
  document.write (who["name"]);
}

// Horizontal "for more information, contact..."
function hforinfo(who) {
   if (who["email"] == "") {
      document.write (who["name"] + ', ' + who["phone"]);
   } else {
      document.write (who["name"] + ', ' + who["phone"]+ ', ' + liveemail(who));
   }
}

// Vertical "for more information, contact..."
function vforinfo(who) {
   if (who["email"] == "") {
      document.write ('<br>' + who["name"] + '<br>' + who["phone"]);
   } else {
      document.write ('<br>' + who["name"] + '<br>' + who["phone"]+ '<br>' + liveemail(who));
   }
}


// Horizontal "for more information, contact..."
function hforinfoe(who) {
   document.write ("For further information, contact " +
                    who["name"] + ', <nobr>' + who["phone"]+ ',</nobr> ' + liveemail(who));
}
// Horizontal "for more information, contact..."
function hforinfof(who) {
   document.write ("Pour plus de renseignements, contactez " +
                    who["name"] + ', <nobr>' + who["phone"]+ ',</nobr> ' + liveemail(who));
}

function email (who) {
  document.write (who["name"]);
  document.write ("<br><a href='mailto:" + who["email"] + "'>" + who["email"] + "</a>");
}

function mailchecktov (who) {
  address = "";

// Must have one of: "address" << OR >> "address1", "address2", "address3"
  if (who["address"] == null) {  //if no single "address" array element, then use multiple address lines
    address1 = (who["address1"]) ? who["address1"] : "" ;
    address2 = (who["address2"]) ? "<br>" + who["address2"] : "" ; 
    address3 = (who["address3"]) ? "<br>" + who["address3"] : "" ; 
    address  = address1 + address2 + address3;

  } else {
    address = who["address"];
  }

  address = (address == "") ? "" : "<br>" + address; // add <br> if we have address info
  document.write ("<br>" + who["name"]);
  document.write (address);
}

function fullvcontact (who) {
  address = "";

// Must have one of: "address" << OR >> "address1", "address2", "address3"
  if (who["address"] == null) {  //if no single "address" array element, then use multiple address lines
    address1 = (who["address1"]) ? who["address1"] : "" ;
    address2 = (who["address2"]) ? "<br>" + who["address2"] : "" ; 
    address3 = (who["address3"]) ? "<br>" + who["address3"] : "" ; 
    address  = address1 + address2 + address3;

  } else {
    address = who["address"];
  }

   //alert (who["name"]+"\naddress:"+address+"\n1:"+address1+"\n2:"+address2+"\n3:"+address1);
  address = (address == "") ? "" : "<br>" + address; // add <br> if we have address info
  document.write (who["name"]);
  document.write (address);
  document.write ("<br>" + who["phone"]);
  document.write ("<br><a href='mailto:" + who["email"] + "'>" + who["email"] + "</a>");
}

function mailchequeto (who) {
  address = "";

// Must have one of: "address" << OR >> "address1", "address2", "address3"
  if (who["address"] == null) {  //if no single "address" array element, then use multiple address lines
    address1 = (who["address1"]) ? who["address1"] : "" ;
    address2 = (who["address2"]) ? "<br>" + who["address2"] : "" ; 
    address3 = (who["address3"]) ? "<br>" + who["address3"] : "" ; 
    address  = address1 + address2 + address3;

  } else {
    address = who["address"];
  }

   //alert (who["name"]+"\naddress:"+address+"\n1:"+address1+"\n2:"+address2+"\n3:"+address1);
  address = (address == "") ? "" : "<br>" + address; // add <br> if we have address info
  document.write (who["name"]);
  document.write (address);
  //document.write ("<br>" + who["phone"]);
  //document.write ("<br><a href='mailto:" + who["email"] + "'>" + who["email"] + "</a>");
}


function name (who) {
  document.write (who["name"]);
}

function phone_email (who) {
  document.write (who["phone"]);
  document.write ("<br><a href='mailto:" + who["email"] + "'>" + who["email"] + "</a>");
}
 
// function to COPY array elements by value so as not to overwrite exising arrays.
function handledby(who) {
  var temp = new Array();
  for (info in who) temp[info] = who[info];
  return temp;
}

// Display Bilingual Text
function bil_text(e_text, f_text) {
   if (lang == "e") { 
      document.write(e_text);
   } else {
      document.write(f_text);
   }
}

/*------------------------------------------------------------
	Document Text Sizer- Copyright 2003 - Taewook Kang.  All rights reserved.
	Coded by: Taewook Kang (txkang.REMOVETHIS@hotmail.com)
	Web Site: http://txkang.com
	Script featured on Dynamic Drive (http://www.dynamicdrive.com)
	
	Please retain this copyright notice in the script.
	License is granted to user to reuse this code on 
	their own website if, and only if, 
	this entire copyright notice is included.
--------------------------------------------------------------*/

//Specify affected tags. Add or remove from list:
var tgs = new Array( 'div','td','tr');

//Specify spectrum of different font sizes:
var szs = new Array( 'xx-small','x-small','small','medium','large','x-large','xx-large' );
var startSz = 2;

function ts( trgt,inc ) {
	if (!document.getElementById) return
	var d = document,cEl = null,sz = startSz,i,j,cTags;
	
	sz += inc;
	if ( sz < 0 ) sz = 0;
	if ( sz > 6 ) sz = 6;
	startSz = sz;
		
	if ( !( cEl = d.getElementById( trgt ) ) ) cEl = d.getElementsByTagName( trgt )[ 0 ];

	cEl.style.fontSize = szs[ sz ];

	for ( i = 0 ; i < tgs.length ; i++ ) {
		cTags = cEl.getElementsByTagName( tgs[ i ] );
		for ( j = 0 ; j < cTags.length ; j++ ) cTags[ j ].style.fontSize = szs[ sz ];
	}
}


/*------------------------------------------------------------*/
function windowOpener(url, name, args) {
  if (typeof(popupWin) != "object"){
    popupWin = window.open(url,name,args);
  } else {
    if (!popupWin.closed){ 
      popupWin.location.href = url;
    } else {
      popupWin = window.open(url, name,args);
    }
  }
  popupWin.focus();
}

/* Simpler function */
var popupWin = this.window;
//var popupWin.location = null;

/* Simpler function */
function windowOpener2(url, name, args) {
  if(typeof(popupWin) != "object" || popupWin.closed) {
    if (name = 'details') args = 'WIDTH=500,HEIGHT=300,scrollbars=1,resizable=1';
    if (name = 'event') args = 'WIDTH=700,HEIGHT=500,scrollbars=1,resizable=1';
    popupWin = window.open(url,name,args);
  } else {
    popupWin = window.open(url,name,args);
    //popupWin.location.href = url;
  }

  popupWin.focus();
}  

function windowOpener4(url, name, args) {
  alert ("xx"+typeof(popupWin) );

if (popupWin = this.window) { 
   alert ("THIS");
} else {
   alert ("Something else");
}

  if((typeof(popupWin) != "object") || popupWin.closed || (popupWin = this.window) ) {
    if (name = 'details') args = 'WIDTH=500,HEIGHT=300,scrollbars=1,resizable=1';
    if (name = 'event') args = 'WIDTH=700,HEIGHT=500,scrollbars=1,resizable=1';
    popupWin = window.open(url,name,args);
  } else {  
      alert ('else');    
      popupWin.location.href = url;
  }

   popupWin.focus();
}  

function to_french() {
      var curr_page = window.location;
      curr_page = curr_page.toString();
      var new_page = curr_page.replace(/_e.htm/, "_f.htm");
      location.replace(new_page);
}

function to_english() {
      var curr_page = window.location;
      curr_page = curr_page.toString();
      var new_page = curr_page.replace(/_f.htm$/, "_e.htm");
      location.replace(new_page);
}




//if(typeof(window['popupWin']) != "null" ) {
//}

// NOT USED YET 
function windowOpenerBil(url, name, args, passed_lang) {
  if(typeof(popupWin) != "object" || popupWin.closed) {
    if (name = 'details') args = 'WIDTH=500,HEIGHT=300,scrollbars=1,resizable=1';
    if (name = 'event') args = 'WIDTH=700,HEIGHT=500,scrollbars=1,resizable=1';
    popupWin = window.open(url,name,args);
  } else {
    popupWin.location.href = url;
  }
    lang = passed_lang;

  popupWin.focus();
}



