﻿
/*================================
    Background Cache
==================================*/
if (jQuery.browser.msie && parseInt(jQuery.browser.version, 10) == 6) {
    try {
        document.execCommand("BackgroundImageCache", false, true);
    } catch (err) { }
}


/*================================
	Common functions
==================================*/
var otherMemberGoals = [];
var currentOtherMemberGoal = 0;
var blank = new Image();

var addThisHoverTimeout;

blank.src = '/Standard.Website/Images/Common/blank.gif';

$J(document).ready(function()
{
    var badBrowser = (/MSIE ((5\.5)|6)/.test(navigator.userAgent) && navigator.platform == "Win32");

    //Find if ie6 and check all images for png's
    if (badBrowser)
    {
        $J('img.pngFix, .pngFix img, .largeCommIcon img, img[src$=.png]').each(function()
        {
            if (!this.complete) this.onload = function() { fixPng(this) };
            else fixPng(this);
        });
    }

    if ($J('.print'))
    {
        $J('.print').click(function()
        {
            window.print();
        });
    }

    /*================================
    Input Button Rollovers
    ==================================*/

    //Send btn
    //=====================// 
    $J('input.btnSendSubmit').hover(function()
    {
        $J(this).addClass('btnSendSubmitOver');
    }, function()
    {
        $J(this).removeClass('btnSendSubmitOver');
    });


    //Send Report btn
    //=====================// 
    $J('input.btnSendReport').hover(function()
    {
        $J(this).addClass('btnSendReportOver');
    }, function()
    {
        $J(this).removeClass('btnSendReportOver');
    });

    //Join Community btn
    //=====================// 
    $J('input.btnJoinCommunity').hover(function()
    {
        $J(this).addClass('btnJoinCommunityOver');
    }, function()
    {
        $J(this).removeClass('btnJoinCommunityOver');
    });

    //Browse btn
    //=====================// 
    $J('input.btnBrowse').hover(function()
    {
        $J(this).addClass('btnBrowseOver');
    }, function()
    {
        $J(this).removeClass('btnBrowseOver');
    });

    //Create Group btn
    //=====================// 
    $J('input.btnCreateGroup').hover(function()
    {
        $J(this).addClass('btnCreateGroupOver');
    }, function()
    {
        $J(this).removeClass('btnCreateGroupOver');
    });

    //Update Results btn
    //=====================// 
    $J('input.btnUpdateResults').hover(function()
    {
        $J(this).addClass('btnUpdateResultsOver');
    }, function()
    {
        $J(this).removeClass('btnUpdateResultsOver');
    });


    //Alternate views contact form
    //=================================// 
    if ($J('select.enquiryType').length > 0)
    {
        $J('select.enquiryType').change(function()
        {
            updateEnquiryForm();
        });
        updateEnquiryForm();
    }

    //Share this button
    //=====================//
    $J('.addthis_toolbox').css({ opacity: 0 });

    $J('a.shareThis').hover(function()
    {
        var tempPosLeft = getAbsoluteLeft(this);
        var tempPosTop = getAbsoluteTop(this);

        //Panel Position
        $J('.addthis_toolbox').css({ display: 'block',
            left: tempPosLeft - 12 + 'px',
            top: tempPosTop + this.offsetHeight - 3 + 'px'
        }).stop().fadeTo("fast", 1.0);

        tempHeight = $J('.addthis_toolbox')[0].offsetHeight;

        //Position the shim underneath      
        $J('.addThisShim').css({ opacity: 0 });
        $J('.addThisShim').css({ left: tempPosLeft - 12 + 'px',
            top: tempPosTop + this.offsetHeight - 3 + 'px',
            height: tempHeight + 'px'
        });

        enterAddThis();

    }, function()
    {
        exitAddThis();
    });

    $J('.addthis_toolbox').hover(function()
    {
        enterAddThis();
    }, function()
    {
        exitAddThis();
    })


    //Table formatting
    //========================================================================================================================================
    $J('.productAccordion .accordion table').each(function()
    {
        curTable = $J(this);
        formatTable(curTable);
    });

    $J('div#innerLeftColumn table').each(function()
    {
        curTable = $J(this);
        formatTable(curTable);
    });
   
});

	
function formatTable(focusTable){
    $J(focusTable).addClass('alternatingTable');
        
    var tableRows = $J('tr', focusTable);
            
    for(p=0; p<tableRows.length; p++){
        if(p%2 != 0) $J(tableRows[p]).addClass('alt')
        
        var tableCols = $J('td', tableRows[p]);
        
        for(q=0; q<tableCols.length; q++){
            if(q != 0) $J(tableCols[q]).addClass('value');
        }
    }
}


function updateEnquiryForm(){
    
    if($J('select.enquiryType').length > 0){
        temp = $J('select.enquiryType')[0];
        
        if($J(temp).val() == 'Product complaints'){
            $J('.subjectEnquiry').css('display', 'block');
            $J('.productEnquiry').css('display', 'block');
            $J('.technicalEnquiry').css('display', 'none');
            
        }else if($J(temp).val() == 'Website technical problems'){
            $J('.subjectEnquiry').css('display', 'none');
            $J('.productEnquiry').css('display', 'none');
            $J('.technicalEnquiry').css('display', 'block');
        
        }else{
            $J('.subjectEnquiry').css('display', 'block');
            $J('.productEnquiry').css('display', 'none');
            $J('.technicalEnquiry').css('display', 'none');
        
        }
    }
}

function enterAddThis(){
    if(addThisHoverTimeout) clearTimeout(addThisHoverTimeout);
}

function exitAddThis(){
    //Set Time delay to hide dropdown and hover state
    addThisHoverTimeout = setTimeout(function(){
        $J('.addthis_toolbox').stop().fadeTo("fast", 0.0, function(){ $J('.addthis_toolbox').css('left', '-40000px'); 
                                                                      $J('.addThisShim').css('left', '-40000px');});
    }, 150);    
}

/* Fire Popup Window */
function openPopup(url, width, height){
    var centerX;
    var centerY;
    
    //half the screen width minus half the new window width (plus 5 pixel borders).
    centerX = (window.screen.width / 2) - ((width / 2) + 30);
    centerY = (window.screen.height / 2) - ((height / 2) + 50);
    
    window.open(url, 'popupWindow', 'toolbar=0, scrollbars=1, location=0, statusbar=0, menubar=0, resizable=1, width='+width+',height='+height+',left='+centerX+',top='+centerY);
}

/* Common positioning functions */
function getAbsoluteLeft(focusObject) {
	// Get an object left position from the upper left viewport corner
	o = $J(focusObject)[0];
	oLeft = o.offsetLeft;
	while(o.offsetParent!=null) {
		oParent = o.offsetParent;
		oLeft += oParent.offsetLeft;
		o = oParent;
	}
	return oLeft;
}

function getAbsoluteTop(focusObject) {
	// Get an object top position from the upper left viewport corner
	o = $J(focusObject)[0];
	oTop = o.offsetTop;
	while(o.offsetParent!=null) {
		oParent = o.offsetParent;
		oTop += oParent.offsetTop;
		o = oParent;
	}
	return oTop;
}
