  /* MC JavaScript Namespace and globlal methods */

  var MC = function() {
	
	return {
	  	 
	  addLoadEvent : function(func) {
		var currentOnLoad = window.onload;
		if (typeof window.onload != 'function') {
		  window.onload = func;
		} else {
		  window.onload = function() {
			currentOnLoad();
			func();
		  } 
		}
	  }, 
	  
	  getElementById : function(elementId) {
		if ( document.getElementById ) {
		  return document.getElementById( elementId );
		} else if ( document.all ) {
		  return document.all[elementId];
		} else {
		  return null;
		}
	  }, 
	  
	  formatCurrency : function(num) {
		num = num.toString().replace(/\$|\,/g,'');
		
		if (isNaN(num)) { num = "0" } 
		
		sign = (num == (num = Math.abs(num)));
		num = Math.floor(num*100+0.50000000001);
		cents = num%100;
		num = Math.floor(num/100).toString();
		
		if (cents < 10) { cents = "0" + cents; }
		
		for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++) {
		  num = num.substring(0,num.length-(4*i+3)) + ',' + num.substring(num.length-(4*i+3));
		}
		
		return (((sign)?'':'-') + '$' + num + '.' + cents);
	  }
	  
	};
  }();
    

  var Confirm = function() {
	
	return {

	  addToCart : function(name,quantity) {
		alert(quantity + ' - ' + name + ' has been added to your cart.');
	  }, 
	  
	  updateQuantity : function(name,quantity) {
		alert(name + ' quantity has been updated.');
	  }, 
	  
	  outOfStock : function(name,quantity) {
		alert('The quantity you requested (' + quantity + ') is not currently in stock.');
	  },
	  
	  belowMinQty : function(name,quantity) {
		alert('You are not allowed to purchase fewer than ' + quantity + ' of ' + name + '.');
      },
      
	  aboveMaxQty : function(name,quantity) {
		alert('You are not allowed to purchase more than ' + quantity + ' of ' + name + '.');
	  }
	};
  }();
  
  
  var Window = function() {
	var isNetscape = (navigator.appName == "Netscape") ? true : false;
	
	return {
	  	
	  open : function(url, name, width, height, scrollbars, resizable) {
		var left = (screen.width - width) / 2;
		var top = (screen.height - height) / 2;
		resizable = 'yes';
		var properties = 'height=' + height + ',width=' + width + ',top=' + top + ',left=' + left + ',scrollbars=' + scrollbars + ',resizable=' + resizable + ',toolbar=0,location=0,statusbar=0,menubar=0';

		var win = window.open(url, 'win', properties);
        
		if (isNetscape) { 
		  win.window.focus(); 
		} else {
		  win.focus();
		}
	  }, 

	  close : function (win) {
		win.close();
	  }, 

	  print : function(win) {
		win.print();
	  }, 

	  center : function(win) {
		var width, height;
		var left, top;
        
		width = win.outerWidth;
		height = win.outerHeight;
        
		if(win.document.layers || (win.document.getElementById && !win.document.all)) { 
		  width = win.outerWidth;
		  height = win.outerHeight;
		} else if(win.document.all) {
		   width = win.document.body.clientWidth;
		   height = win.document.body.clientHeight;
		}  
        
		left = (screen.width - width) / 2;
		top = (screen.height - height) / 2;
       
		if (parseInt(navigator.appVersion) >= 4) {
		  window.moveTo(left, top); 
		}
	  }, 

	  resizeToObject : function(object,extraWidth,extraHeight) { 
		var offsetTop = 100;
		var offsetLeft = 100;
		
		if (object) {		
		  width = (object.width + extraWidth) ; 
		  height = (object.height + extraHeight); 

		  if (height-offsetTop > screen.availHeight) { height = screen.availHeight-offsetTop; }
		  if (width-offsetLeft > screen.availWidth) { width = screen.availWidth-offsetLeft; }

		  window.moveTo(offsetLeft,offsetTop);
		  window.resizeTo(width, height);
		}
	  }
	  
	};
  }();
      

