/* Sets the cell spacing to 0 on any tables which don't have it set. */
function removeCellSpacings() {
	var tables = $A(document.getElementsByTagName('table'));
	tables.each(function(table) {
		if (!table.getAttribute('cellspacing')) table.cellSpacing = '0';
	})
}

/* Rounds the corners on blocks with a class of rounded. */
function roundCorners() {
	var blocks = $$('div.rounded');
	
	blocks.each(function (block) {
		var html = block.innerHTML;
		
		var newHtml = '<div class="rounded_top_left"><div class="rounded_top_right"></div></div>';
		newHtml    += '<div class="rounded_text">' + html + '</div>';
		newHtml    += '<div class="rounded_bottom_right"><div class="rounded_bottom_left"></div></div>';
		
		block.innerHTML = newHtml;
	});
}

/* Adds a title attribute to any link with a shortcut key. */
function shortcutTitles() {
	var links = $A(document.getElementsByTagName('a'));
	links.each(function(link) {
		if (link.getAttribute('accesskey')) link.title = "Shortcut key: " + link.getAttribute('accesskey');
	});
}

/* Adds styling hooks to the Vebra pages. */
function addVebraHooks() {	
	if (document.location.href.match(/refine.asp/i)) {	
		var checkboxes = getElementsByAttribute(document, "input", "type", "checkbox");
		checkboxes.each(function (checkbox) {
			Element.addClassName(checkbox, "refine_checkbox")
		});
	}
	
	if (document.location.href.match(/register.asp/i)) {
		var radios = getElementsByAttribute(document, "input", "type", "radio");
		radios.each(function (radio) {
			Element.addClassName(radio, "radiobutton");
		});
		
		var checkboxes = getElementsByAttribute(document, "input", "type", "checkbox");
		checkboxes.each(function (checkbox) {
			Element.addClassName(checkbox, "checkbox")
		});
	}
	
	if (document.location.href.match(/basket.asp/i)) {
		//$$('span.BasketRegister').parentNode.textAlign = 'center';
		var full_details = getElementsByAttribute(document, "img", "src", "http://www.ardentstudio.co.uk/personal_agent/images/full-details.gif");
		full_details.each(function (img) {
			Element.addClassName(img, "BasketFullDetails");
		});
	}
}

/*
    Copyright Robert Nyman, http://www.robertnyman.com
    Free to use if this text is included

	Returns any elements with the specified attributes.
*/
function getElementsByAttribute(oElm, strTagName, strAttributeName, strAttributeValue){
    var arrElements = (strTagName == "*" && oElm.all)? oElm.all : oElm.getElementsByTagName(strTagName);
    var arrReturnElements = new Array();
    var oAttributeValue = (typeof strAttributeValue != "undefined")? new RegExp("(^|\\s)" + strAttributeValue + "(\\s|$)") : null;
    var oCurrent;
    var oAttribute;
    for(var i=0; i<arrElements.length; i++){
        oCurrent = arrElements[i];
        oAttribute = oCurrent.getAttribute && oCurrent.getAttribute(strAttributeName);
        if(typeof oAttribute == "string" && oAttribute.length > 0){
            if(typeof strAttributeValue == "undefined" || (oAttributeValue && oAttributeValue.test(oAttribute))){
                arrReturnElements.push(oCurrent);
            }
        }
    }
    return $A(arrReturnElements);
}