function highlightTableRows(tableId) {
    var previousClass = null;
    var table = document.getElementById(tableId);
    var startRow = 0;
    // workaround for Tapestry not using thead
    if (!table.getElementsByTagName("thead")[0]) {
	    startRow = 1;
    }
    var tbody = table.getElementsByTagName("tbody")[0];
    var rows = tbody.getElementsByTagName("tr");
    // add event handlers so rows light up and are clickable
    for (i=startRow; i < rows.length; i++) {
        rows[i].onmouseover = function() { previousClass=this.className;this.className+=' over' };
        rows[i].onmouseout = function() { this.className=previousClass };
        rows[i].onclick = function() {
            var cell = this.getElementsByTagName("td")[0];
            var link = cell.getElementsByTagName("a")[0];
            if (link.onclick) {
                call = link.getAttribute("onclick");
                if (call.indexOf("return ") == 0) {
                    call = call.substring(7);
                }
                // this will not work for links with onclick handlers that return false
                eval(call);
            } else {
                location.href = link.getAttribute("href");
            }
            this.style.cursor="wait";
            return false;
        }
    }
}

// Show the document's title on the status bar
window.defaultStatus=document.title;

// The following doesn't work in IE 6 or 7
// window.onload = StyleSheetSwitcher.initialize();
//window.onload = function() { StyleSheetSwitcher.initialize(); }


// Open a new window
function openPopup(url,window_title,width,height){
	return window.open(url,window_title,'width=' + width + ',height=' + height + ',toolbar=no,menubar=no,status=yes');
}

function truncateString(value, len) {
	var returnValue = value;
	if (value.length > len) {
	var oldIndex = -1;
	var currIndex = 0;
	
	while(currIndex >= 0) {
		oldIndex = currIndex;
		currIndex = value.indexOf('%20',currIndex+1);
		if(currIndex >= len || currIndex < 0) {
			break;
		}
	}
	
    /* Truncate the content of the P, then go back to the end of the
       previous word to ensure that we don't truncate in the middle of
       a word */
    returnValue = value.substring(0, oldIndex);
	/* Add an ellipses to the end and make it a link that expands
       the paragraph back to its original size */
    returnValue += '...';
  }
  return returnValue;
}
function encodeString(str_in) {
	return escape(str_in);
}


function truncateStringById(name,len) {
	var p = document.getElementById(name);
	if (p) {
	
	  var trunc = p.innerHTML;
	  if (trunc.length > len) {
		/* Truncate the content of the P, then go back to the end of the
	       previous word to ensure that we don't truncate in the middle of
	       a word */
	    trunc = trunc.substring(0, len);
	    trunc = trunc.replace(/\w+$/, '');
	
	    /* Add an ellipses to the end and make it a link that expands
	       the paragraph back to its original size */
	    trunc += '...';
	    p.innerHTML = trunc;
	  }
	}
}

/* This function is used to set cookies */
function setCookie(name,value,expires,path,domain,secure) {
  document.cookie = name + "=" + escape (value) +
    ((expires) ? "; expires=" + expires.toGMTString() : "") +
    ((path) ? "; path=" + path : "") +
    ((domain) ? "; domain=" + domain : "") + ((secure) ? "; secure" : "");
}

/* This function is used to get cookies */
function getCookie(name) {
	var prefix = name + "=" 
	var start = document.cookie.indexOf(prefix) 

	if (start==-1) {
		return null;
	}
	
	var end = document.cookie.indexOf(";", start+prefix.length) 
	if (end==-1) {
		end=document.cookie.length;
	}

	var value=document.cookie.substring(start+prefix.length, end) 
	return unescape(value);
}

/* This function is used to delete cookies */
function deleteCookie(name,path,domain) {
  if (getCookie(name)) {
    document.cookie = name + "=" +
      ((path) ? "; path=" + path : "") +
      ((domain) ? "; domain=" + domain : "") +
      "; expires=Thu, 01-Jan-70 00:00:01 GMT";
  }
}

/*
*   Show google Map
*/
function showMap(path, address, city, province, country){

	var actualAddress = address;
	if(actualAddress.indexOf(city)<0) {
		actualAddress += ' '+city; 
	}
	if(actualAddress.indexOf(province)<0) {
		actualAddress += ' '+province; 
	}
	if(actualAddress.indexOf(country)<0) {
		actualAddress += ' '+country; 
	}
	actualAddress = escape(actualAddress);

	window.open( path + actualAddress ,'Direction','width=970,height=800,menubar=no,status=yes,toolbar=no,resizabled=no,scrollbars=no');
}
