/*
 *   Selected ramdom image for top banner -DJB
 */
var imgNum = '' + (Math.floor( Math.random() * 10 ) + 1);
if ( 1 == imgNum.length) imgNum = '0' + imgNum;
var outStr = '<style type="text/css">'; 
outStr += '	#tHeader {background-image:url(../../../SiteCollectionImages/CustomerPortal/header/tarmac_head_img-'+imgNum+'.jpg)}';
outStr += '</style>';
document.writeln(outStr);


/*
 *  Fix bug in ASP.NET doPostBack function - Tony Scott
 */
var __oldDoPostBack; //Make sure this is scoped outside the following function
function fixDoPostBack()
{
    if ('function' != typeof(__doPostBack))
        setTimeout(fixDoPostBack,500);
    else
    {
        // save a reference to the original __doPostBack
        __oldDoPostBack = __doPostBack;

        // replace __doPostBack with another function
        __doPostBack = function (eventTarget, eventArgument)
        {
            var thisForm = document.forms['aspnetForm'];

            if (!thisForm)
                thisForm = document.aspnetForm;

            if (thisForm)
                thisForm.onsubmit = null;

            return __oldDoPostBack(eventTarget, eventArgument);
        }
    }
}
fixDoPostBack();

/*
 *   Open popup window - DJB
 *
 *   popup.open(href,[target,['small'/'medium'/'big'/'credit'/'custom',[options,[{x:<size>,y:<size>}]]])
 */
var popup =
{
    _credit: {x:500,y:250},
    _small:  {x:500,y:350},
    _medium: {x:640,y:480},
    _big:    {x:800,y:600},
    _menuBar:'no',
    debug:   false,
    
    _vars:   'location=no,menubar=no,scrollbars=yes,status=no,toolbar=no,resizable=yes',
    errorMsg:'Popup Blocked!', //Error replaced from resourse file by toplinks.ascx
    
    /*
     * .open(href,[target,['small'/'medium'/'big'/'credit'/'custom',[options,[{x:<size>,y:<size>}]]])
     */
    open: function(href,target,size,options,customSize)
    {
        try //Sharepoint hides JS errors, so we have to catch them or loose them.
        {
            var size = this._getSize(size,customSize);
            
            if (!options) 
                var options = this._vars;
            
            var newWin = window.open(href,target,size+','+options); //Open window
            
            this._testWinOpened(newWin);
            
            return false; //Stop HTML link firing.
        }
        catch (err)
        {
            if (this.debug) alert('ERROR: '+err);
            return false;
        }
    },
    
    /*
     * Check window opened ok
     */
    _testWinOpened: function(newWin)
    {
        if (!newWin)
            alert(this.errorMsg);
    },
    
    /*
     *  ._getSize('small'/'medium'/'big'/'credit'/'custom',[{x:<size>,y:<size>])
     */
    _getSize: function(size,customSize)
    {
        var oSize;
        
        switch(size)
        {
            case 'credit':
                oSize = this._credit;
                break;
            case 'custom':
                oSize = customSize; //Passed in custom size
                break;
            case 'small':
                oSize = this._small;
                break;
            case 'medium':
                oSize = this._medium;
                break;
            default:
                oSize = this._big;
        }
        
        return 'width=' + oSize.x + ',height=' + oSize.y;
    }
}

