/* linkOb    - the anchor element that you want to popup
   aname     - the name of the popup window
   onSuccess - page to redirect to on success (not required!)
*/

var _quotetimeout;

function popupQuote (linkOb,aname,onSuccess) {
    var url  = linkOb.href;

    if ( ! url ) {
        return false;
    }

	var thewidth  = 770;
	var theheight = 500;
	var winnX     = 0;
	var winnY     = 10;
	var str_WinParams;

    if ( screen ) {
        var diffX = (screen.width-thewidth); /* don't want to do a division by 0 */
        if ( diffX > 0 ) winnX = diffX / 2;
        if ( screen.width >= 1024 ) theheight = 650;

        str_WinParams = 'top=' + winnY+',left=' + winnX + ',status=1,scrollbars=1,resizable=1,width='+thewidth+',height='+theheight;
    } else {
        str_WinParams = 'status=1,scrollbars=1,resizable=1,width='+thewidth+',height='+theheight;
    }

    thewindowobject = window.open(url,aname,str_WinParams);

    if (window.focus) thewindowobject.focus();

    if ( thewindowobject ) {
        if ( ! onSuccess ) {
            return true; // success!!
        } else {
            if (  _quotetimeout ) {
                clearTimeout(_quotetimeout);
                _quotetimeout = '';
            }
            if ( window.location.href == onSuccess ) return true; /* page is the same as the current page */
            
            var code = 'window.location.href = "' + onSuccess + '";';
            
            _quotetimeout = setTimeout(code, 100); // 100 ms

            return true;
        }
    }

    return false; // failed
}
