function MM_findObj(n, d) { var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) { d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);} if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n]; for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document); if(!x && d.getElementById) x=d.getElementById(n); return x;}
function MM_showHideLayers() { var i,p,v,obj,args=MM_showHideLayers.arguments; for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2]; if (obj.style) { obj=obj.style; v=(v=='show')?'block':(v=='hide')?'none':v; } obj.display=v; }}

function showHide(id,show) {
  MM_showHideLayers(id,'',show ? 'show' : 'hide');
}

function swapText(id){
    document.getElementById('sds_' + id).style.display='none';
    document.getElementById('sdf_' + id).style.display='inline';
}

function convertToPounds(price) {
	return "£" + (price/100).toFixed(2);
}

function clearList(selectBox) {
    var i;

    if (selectBox.options) {

	    for(i=selectBox.options.length-1;i>=0;i--)
	        selectBox.remove(i);

	    while (selectBox.hasChildNodes())
	        selectBox.removeChild(selectBox.firstChild);
    }
}

function replaceList(selectBox,newOptionsArray,selected) {
	clearList(selectBox);

    var optGroup=null;

    for(i=0;i<newOptionsArray.length;i++) {

        if (newOptionsArray[i][0]=="dash") {

            var optn = document.createElement("option");
            optn.text = "--------------------";
            optn.disabled=true;

            selectBox.options.add(optn);

        } else if (newOptionsArray[i][0].substring(0,13)=="optGroupStart") {

            optGroup = document.createElement("optgroup");
            optGroup.label=newOptionsArray[i][1];

        } else if (newOptionsArray[i][0].substring(0,11)=="optGroupEnd") {

            selectBox.appendChild(optGroup)
            optGroup=null;

        } else {

            if (optGroup == null) {

                var optn = document.createElement("option");
                    optn.text = newOptionsArray[i][1];
                    optn.value = newOptionsArray[i][0];

                selectBox.options.add(optn);

            } else {

                var optn = document.createElement("option");
                    optn.text = newOptionsArray[i][1];
                    optn.value = newOptionsArray[i][0];
                optGroup.appendChild(optn);

            }
        }
    }

    for(var i = 0; i < selectBox.length; i++) {
    	if(selectBox.options[i].value == selected) {
    		selectBox.options[i].selected = true;
    	} else {
    		selectBox.options[i].selected = false;
    	}
    }
}

Number.implement({

	/*
	Property: numberFormat
		Format a number with grouped thousands.

	Arguments:
		decimals, optional - integer, number of decimal percision; default, 2
		dec_point, optional - string, decimal point notation; default, '.'
		thousands_sep, optional - string, grouped thousands notation; default, ','

	Returns:
		a formatted version of number.

	Example:
		>(36432.556).numberFormat()  // returns 36,432.56
		>(36432.556).numberFormat(2, '.', ',')  // returns 36,432.56
	*/

	numberFormat : function(decimals, dec_point, thousands_sep) {
		decimals = Math.abs(decimals) + 1 ? decimals : 2;
		dec_point = dec_point || '.';
		thousands_sep = thousands_sep || ',';

		var matches = /(-)?(\d+)(\.\d+)?/.exec((isNaN(this) ? 0 : this) + ''); // returns matches[1] as sign, matches[2] as numbers and matches[3] as decimals
		var remainder = matches[2].length > 3 ? matches[2].length % 3 : 0;
		return (matches[1] ? matches[1] : '') + (remainder ? matches[2].substr(0, remainder) + thousands_sep : '') + matches[2].substr(remainder).replace(/(\d{3})(?=\d)/g, "$1" + thousands_sep) +
				(decimals ? dec_point + (+matches[3] || 0).toFixed(decimals).substr(2) : '');
	}


});