function formatAsMoney(mnt) {
    mnt -= 0;
    mnt = (Math.round(mnt*100))/100;
    return (mnt == Math.floor(mnt)) ? mnt + '.00' 
          : ( (mnt*10 == Math.floor(mnt*10)) ? 
                   mnt + '0' : mnt);
}

//remove item (string or number) from an array
function removeItem(originalArray, itemToRemove) {
	var j = 0;
	while (j < originalArray.length) {
		if (originalArray[j] == itemToRemove) {
			originalArray.splice(j, 1);
		} else {
			j++;
		}
	}
	return originalArray;
}


// Shows or hides a div
function showHideDiv(div, display){
    if(display){
        $(div).setStyle('display','block');
    }else{
        $(div).setStyle('display','none');
    }
}

// Global Ajax loader
function loadAjaxURL(content, url){
    // Clear notifications
    window.onDomReady(function(){Site.page_ClearNotifications();});
    // Clear old content
    $(content).setHTML();
    // First make our loading image
    var loadingDiv = new Element('div').addClass('loadingDiv').injectInside($(content));
    var img = new Element('img').setProperties({
        src: "/images/global/ajax_loader.gif",
        title: "Loading content, please be patient",
        alt: "Loading content, please be patient"
    }).injectInside($(loadingDiv));
    // Create the cache buster
	var d = new Date()
	url += "?cachebuster="+d.getTime();
	// Perform the request
	new Ajax(url, {
		update: content,
		method: 'get',
		evalScripts: true,
		onComplete: function(){
		    Site.page_launchNotificationBubble();
		}
	}).request();
}

function isInteger (s){
    var i;
    if (isEmpty(s))
    if (isInteger.arguments.length == 1) return 0;
    else return (isInteger.arguments[1] == true);
    for (i = 0; i < s.length; i++){
        var c = s.charAt(i);
        if (!isDigit(c)) return false;
    }
    return true;
}

function isEmpty(s){
  return ((s == null) || (s.length == 0))
}

function isDigit (c){
  return ((c >= "0") && (c <= "9"))
}


// Get querystring
function queryString(q) {
    string = window.location.search.substring(1);
    values = string.split("&");
    for (i=0;i<values.length;i++) {
        result = values[i].split("=");
        if (result[0] == q) {
            return result[1];
        }
    }
}



preloadImagesArray = new Array();
preloadImagesArray = [
                        '/images/global/popup_bg.gif',
                        '/images/global/popup_bdtop.gif',
                        '/images/global/popup_bdbot.gif',
                        '/images/header/header_butPrescriptions_on.gif',
                        '/images/header/header_butHealthInfo_on.gif',
                        '/images/header/header_butShop_on.gif',
                        '/images/global/search_go_on.gif',
                        '/images/global/but_addtobasket_on.gif',
                        '/images/global/but_addtocart_on.gif',
                        '/images/global/but_continue_checkout_on.gif'
                        
                    ];

var img = new Asset.images(preloadImagesArray,{
  //onProgress: showProgress
    onComplete: function(){
        //alert('all images loaded!');
    }
});



ghostArray = ['n.ewart@spin.com.au','enquiries@pulsepharmacy.com.au'];
function writeemail(){
    // Get all our links to be ghosted
    var mailLinks = document.getElementsByTagName('span');
    for(i=0;i<mailLinks.length;i++){
        if(mailLinks[i].className == "ghost"){
            mailLinks[i].style.display = "none"; 
            var newemail = document.createElement("a")
            newemail.setAttribute("href","javascript:launchemail("+mailLinks[i].innerHTML+");");
            newemail.innerHTML = ghostArray[mailLinks[i].innerHTML];
            mailLinks[i].parentNode.appendChild(newemail);
        }
    }
}

function writeemailimg(){
    // Get all our links to be ghosted
    var el = document.getElementById('eml');
    el.setAttribute("href","mailto:"+ghostArray[1] + /*"?cc=" + ghostArray[0] +*/ "?subject=Pulse website feedback&body=Please let us know what we can be doing better or what you like about the site!" );
}

function opennewwindow(url, w, h)
{
    newwindow = window.open(url,'name','height=' + h + ',width=' + w + ',scrollbars=1');
    if (window.focus) {newwindow.focus()}
}    
