String.prototype.trim = function() {
    return this.replace(/(^\s*)|(\s*$)/g, "");
} // -------------------------------------------------------------------------------------------

function truncateForm( form ) {
	for( i = 0 ; i < form.length ; i++ )
	{
	    if( form.elements[i].type == 'text' || form.elements[i].type == 'textarea' )
			form.elements[i].value = form.elements[i].value.trim();
	};
}

function isEmail( str ) {
    var supported = 0;

    if (window.RegExp) 
    {
        var tempStr = "a";
        var tempReg = new RegExp(tempStr);
        if (tempReg.test(tempStr)) supported = 1;
    }
    if (!supported) 
        return (str.indexOf(".") > 2) && (str.indexOf("@") > 0);
    var r1 = new RegExp("(@.*@)|(\\.\\.)|(@\\.)|(^\\.)");
    var r2 = new RegExp("^.+\\@(\\[?)[a-zA-Z0-9\\-\\.]+\\.([a-zA-Z]{2,3}|[0-9]{1,3})(\\]?)$");
    str = str.replace(/ /,'');
    return (!r1.test(str) && r2.test(str));
}

function show_picture(name,w,h)
{   
    window.open(name,null,"height="+h+",width="+w+",status=no,toolbar=no,menubar=no,location=no,scrollbars=yes");
} // -------------------------------------------------------------------------------------------


function openwindow(name)
{   
	var hWnd = null; 
	var nLeftPos, nTopPos; 
	if ( arguments.length == 1 ) {
		nWidth = 100;
		nHeight = 100;
 	} else {
		var nWidth = arguments[1];
		var nHeight = arguments[2];
	}
 
    nLeftPos = Math.round(screen.availWidth/2) - Math.round(nWidth/2); 
    nTopPos  = Math.round(screen.availHeight/2) - Math.round(nHeight/2); 

    hWnd = window.open(name,null,"height="+nHeight+",width="+nWidth+",status=no,toolbar=no,menubar=no,location=no,scrollbars=yes,resizable=yes");
    
    hWnd.moveTo( nLeftPos, nTopPos );

} // -------------------------------------------------------------------------------------------


function isEmail( str ) {
    var supported = 0;

    if (window.RegExp) 
    {
        var tempStr = "a";
        var tempReg = new RegExp(tempStr);
        if (tempReg.test(tempStr)) supported = 1;
    }
    if (!supported) 
        return (str.indexOf(".") > 2) && (str.indexOf("@") > 0);
    var r1 = new RegExp("(@.*@)|(\\.\\.)|(@\\.)|(^\\.)");
    var r2 = new RegExp("^.+\\@(\\[?)[a-zA-Z0-9\\-\\.]+\\.([a-zA-Z]{2,3}|[0-9]{1,3})(\\]?)$");
    str = str.replace(/ /,'');
    return (!r1.test(str) && r2.test(str));
}