// *******************************************************
//    JavaScript used on every Commerce page
// *******************************************************
/// <reference path="jquery-1.3.2-vsdoc2.js" />
//var engine;
try {
    Sys.Application.add_load(function() {
      

        var d = new Date();


        // Adjust cache setting to fix IE6 background image flicker
        try { document.execCommand('BackgroundImageCache', false, true); } catch (e) { }

 

        // Position the white glow behind the logo in the header
        positionLogoHighlight();

        // Add psitioning function to window resize event
       

        addListItemClasses();
        addTableRowClasses();

        //analyzeLinks();
        //analyzeImages();
        //analyzeMeta();

        d = new Date();
    });
}
catch (ex) {
    $(window).bind('ready', function() {
  

        var d = new Date();


        // Adjust cache setting to fix IE6 background image flicker
        try { document.execCommand('BackgroundImageCache', false, true); } catch (e) { }

       

        // Position the white glow behind the logo in the header
       

        // Add psitioning function to window resize event
        $(window).bind('resize', function() {
            positionLogoHighlight();
        });

        addListItemClasses();
        addTableRowClasses();

        //analyzeLinks();
        //analyzeImages();
        //analyzeMeta();

        d = new Date();
    });
}
$(window).bind('resize', function() {
    positionLogoHighlight();
});
$(window).ready(function() {

positionLogoHighlight();
writePrintPageLink();
});

// write "Print This Page" link on page
function writePrintPageLink() {
    var list = $('#PageFuncitonList');
    if (list){

        var linkElement = $('<a href="#" title="Print this Page" class="printPage" onclick = "window.print(); ">Print</a>');
    
        var listElement = $('<li></li>');

        listElement.append(linkElement);

        list.prepend(listElement);
    }
}

// add first, alt, and last classes to appropriate list items
function addListItemClasses() {

    $("ul").each(function() {
        $(this).find("li:first").addClass("first");
        $(this).find("li:last").addClass("last");
        $(this).find("li:odd").addClass("alt");

    });
    $("ol").each(function() {
        $(this).find("li:first").addClass("first");
        $(this).find("li:last").addClass("last");
        $(this).find("li:odd").addClass("alt");

    });
}
function addTableRowClasses() {
    $("table").each(function() {
  
        if ($(this).find("tr:first").children().eq(0)[0].tagName == "TH") {
            $(this).find("tr:even").addClass("alt");
        }
        else {
            $(this).find("tr:odd").addClass("alt");
        }
    });
}

// stub firebug functions


// Position white highlight behind logo in header
function positionLogoHighlight() {
	var elementLogoHighlight = window.document.getElementById('LogoHighlight');
	if (elementLogoHighlight) {
		//var highlightPosition = parseInt(getViewportWidth()/2 - 580);
		var highlightPosition = parseInt(($(window).width()/2) - 580);
		if (highlightPosition >= -130) {
			elementLogoHighlight.style.backgroundPosition = highlightPosition.toString() + 'px 0';
			elementLogoHighlight.style.backgroundImage = 'url(/r/i/logobg.jpg)';
			/*elementLogoHighlight.style.backgroundImage = 'url(/r/i/logo.gif)';
			elementLogoHighlight.style.backgroundColor = '#F99';*/
		}
		else {
			elementLogoHighlight.style.backgroundImage = 'none';
			/*elementLogoHighlight.style.backgroundImage = 'url(/r/i/logo.gif)';
			elementLogoHighlight.style.backgroundColor = '#F99';*/
		}
	}
}

// Strip an input's value of everything resembling a tag, for .Net submissions
function cleanInput(inputElement) {
	if (inputElement.value) {
		inputElement.value = inputElement.value.replace(/(<[^>]*>)|(<)|(>)/gi,'');
		return true;
	}
	else {
		return false;
	}
}

// Usability testing functions
/*function analyzeLinks() {
    jQuery('a').each(function(el) {
        if (!jQuery(el.title) && !$chk(el.name)) {
            el.css({ 'border': 'solid 1px red' });
            console.error('analyzeLinks >> Link to "' + trimHost(el.href) + '" does not have a title.');
        }

        //console.log(linkLocation);
        if (el.href == window.location.href) {
            el.css({ 'border': 'solid 1px red' });
            console.error('analyzeLinks >> Link to "' + (($chk(el.title)) ? el.title : trimHost(el.href)) + '" does not go anywhere.');
        }
    });
}
function analyzeImages() {
    jQuery('img').each(function(el) {
        //console.info('analyzeImages >> Image "' + trimHost(el.src) + '" has alt of "' + el.alt + '" and a width height of ' + el.width + ' ' + el.height + ' and a style width height of ' + el.getStyle('width') + ' ' + el.getStyle('height'));
        if (!el.attr('alt')) {
            el.css({ 'border': 'solid 1px red' });
            console.warn('analyzeImages >> Image "' + trimHost(el.src) + '" has alt of "' + el.alt + '".');
        }
    });
}
function analyzeMeta() {
    var metaElements = jQuery('meta');
    
    var metaAuthor = metaElements.filter(function(index) {
        return item.attr('name') == 'author';
    });
    if (metaAuthor.length > 0) {
        console.info('analyzeMeta >> Author is ' + metaAuthor[0].content);
    }
    else {
        console.error('analyzeMeta >> Page does not contain author meta tag.');
    }
    
    var metaKeywords = metaElements.filter(function(item, index) {
        return item.name == 'keywords';
    });
    if (metaKeywords.length > 0) {
        console.info('analyzeMeta >> Keywords are ' + metaKeywords[0].content);
    }
    else {
        console.warn('analyzeMeta >> Page does not contain keywords meta tag.');
    }
    
    var metaDescription = metaElements.filter(function(item, index) {
        return item.name == 'description';
    });
    if (metaDescription.length > 0) {
        console.info('analyzeMeta >> Description is ' + metaDescription[0].content);
    }
    else {
        console.warn('analyzeMeta >> Page does not contain description meta tag.');
    }
    
    var metaCopyright = metaElements.filter(function(item, index) {
        return item.name == 'copyright';
    });
    if (metaCopyright.length > 0) {
        console.info('analyzeMeta >> Copyright is ' + metaCopyright[0].content);
    }
    else {
        console.error('analyzeMeta >> Page does not contain copyright meta tag.');
    }
    
    var metaDate = metaElements.filter(function(item, index) {
        return item.name == 'date';
    });
    if (metaDate.length > 0) {
        console.info('analyzeMeta >> Date is ' + metaDate[0].content + ' (' + metaDate[0].scheme + ')');
    }
    else {
        console.error('analyzeMeta >> Page does not contain date meta tag.');
    }
    
    var metaGenerator = metaElements.filter(function(item, index) {
        return item.name == 'generator';
    });
    if (metaGenerator.length > 0) {
        console.info('analyzeMeta >> Generator is ' + metaGenerator[0].content);
    }
    else {
        console.error('analyzeMeta >> Page does not contain generator meta tag.');
    }
    
    var metaContentType = metaElements.filter(function(item, index) {
        return (item.content.search(/^text\/html;/) > -1);
    });
    if (metaContentType.length > 0) {
        console.info('analyzeMeta >> ContentType is ' + metaContentType[0].content);
    }
    else {
        console.error('analyzeMeta >> Page does not contain content-type meta tag.');
    }
}
function trimHost(url) {
    var result = window.location.protocol + '//' + window.location.host;
    result = url.replace(result, '');
    if (!$chk(result)) {
        result = url;
    }
    return result;    
}
*/
// 3/17/2010 3:09:25 PM