// string prototypes 
String.prototype.trim = function() {
    return (this.replace(/\s+$/, '').replace(/^\s+/, ''));
};

// validate email address
function ValidateEmailAddress(e)
{
    var a = false;
    var b = false;
    
    if (typeof(RegExp) == 'function')
    {
        b = new RegExp('abc');
        a = b.test('abc') == true;
    }
    
    if (a == true)
    {
        b = new RegExp('^([a-zA-Z0-9\\-\\.\\_]+)(\\@)([a-zA-Z0-9\\-\\.]+)' + 
            '(\\.)([a-zA-Z]{2,4})$');
        a = b.test(e);
    }
    else
    {
        a = e.search('@') >= 1 && e.lastIndexOf('.') > e.search('@') && 
            e.lastIndexOf('.') >= email.length - 5;
    }
        
    return a;
}

// open centered popup with given dimensions
function OpenDialog(url, name, w, h)
{
    var o = '';
    
    if (w > 0 && h > 0)
    {
        if (document.compatMode && document.all)
            w += 15;
        
        o = 'height=' + h + ',width=' + w + ',';
    }
    
    l = (screen.width - w) / 2;
    t = (screen.height - h) / 2;
    
    o += 'top=' + t + ',left=' + l + ',';
    o += 'scrollbars=yes,status=yes,location=no,toolbar=no,menubar=no';
    
    window.open(url, name, o);
}        

function UnhideMail(dom, user, mailto){
  return((mailto ? "mail"+"to:" : "")+user+"@"+dom.replace(/%23/g,"."));
}

function ConvertToUnicode(source) {
    result = '';
	for (i = 0; i < source.length; i++) 
	    result += '&#' + source.charCodeAt(i) + ';';
	return result;
}

function HideEmail(str)
{
    return ConvertToUnicode(str.replace(/AT/g, "@").replace(/DOT/g, "."));
}

