﻿function replace(string,text,by) {

    // Replaces text with by in string
    var strLength = string.length, txtLength = text.length;
    if ((strLength == 0) || (txtLength == 0)) return string;

    var i = string.indexOf(text);
    if ((!i) && (text != string.substring(0,txtLength))) return string;
    if (i == -1) return string;

    var newstr = string.substring(0,i) + by;

    if (i+txtLength < strLength)
        newstr += replace(string.substring(i+txtLength,strLength),text,by);

    return newstr;
		
}





function left(str, n){

	if (n <= 0)
	    return '';
	else if (n > String(str).length)
	    return str;
	else
	    return String(str).substring(0,n);
}





function right(str, n){

    var iLen;

    if (n <= 0)
       return '';
    else if (n > String(str).length)
       return str;
    else {
       var iLen = String(str).length;
       return String(str).substring(iLen, iLen - n);
    }

}





function contact(username, hostname) {

   var linktext = username + "@" + hostname;
   
	 document.write('<a href="' + 
	                'mailto:' + 
									username +
									'@' + 
									hostname + '">' + 
									linktext + '</a>');
									
}





function popup(page, name, width, height) { 

   var LeftPosition, TopPosition, settings, new_window;
      
   LeftPosition=(screen.width)?(screen.width-width)/2:100;
   TopPosition=(screen.height)?(screen.height-height)/2:100;
	 
   settings = 'width=' + width + 
	          ',height=' + height + 
			  ',top=' + TopPosition + 
			  ',left=' + LeftPosition + 
			  ',scrollbars=yes,location=no,' +
			  'directories=no,status=yes,' +
			  'menubar=no,toolbar=no,resizable=no';
	 
   new_window = window.open(page, name, settings);
			
   if (window.focus)
   {
      new_window.focus();
   }
   
}