	function addCommas(nStr)
	{
		nStr += '';
		x = nStr.split('.');
		x1 = x[0];
		x2 = x.length > 1 ? '.' + x[1] : '';
		var rgx = /(\d+)(\d{3})/;
		while (rgx.test(x1)) {
			x1 = x1.replace(rgx, '$1' + ',' + '$2');
		}
		return x1 + x2;
	}
	
	
//WARNING: This price matrix is DUPLICATED in price.php!!!! EDITS HERE MUST BE REFLECTED THERE!
var postcardsOnlySmall = { 250:99.95, 500:124.95, 1000:149.95, 2000:214.95, 2500:234.95, 5000:274.95, 7500:394.95, 10000:449.95, 15000:649.95, 20000:824.95, 25000:949.95 };
var postcardsOnlyLarge = { 250:128.95, 500:174.95, 1000:219.95, 2000:269.95, 2500:294.95, 5000:364.95, 7500:589.95, 10000:634.95, 15000:934.95, 20000:1214.95, 25000:1414.95};
var postcardsPriceSmall = { 500:449, 1000:649, 2000:1089, 3000:1589, 4000:1989, 5000:2249, 6000:2649, 7000:3149, 8000:3449, 9000:3889, 10000:4189, 11000:4489, 12000:4889, 13000:5249, 14000:5649, 15000:6049, 16000:6449, 17000:6849, 18000:7249, 19000:7649, 20000:8049 };
var postcardsPriceJumbo = { 500:589, 1000:789, 2000:1289, 3000:1889, 4000:2489, 5000:2989, 6000:3489, 7000:3989, 8000:4489, 9000:4989, 10000:5489, 11000:5989, 12000:6489, 13000:6989, 14000:7489, 15000:7989, 16000:8489, 17000:9489, 18000:9989, 19000:10489, 20000:10989 };
var postcardsSmalleach = { 500:0.77, 1000:0.56, 2000:0.44, 3000:0.48, 4000:0.45, 5000:0.39, 6000:0.39, 7000:0.39, 8000:0.39, 9000:0.38, 10000:0.36, 11000:0.36, 12000:0.35, 13000:0.35, 14000:0.35, 15000:0.34, 16000:0.34, 17000:0.34, 18000:0.34, 19000:0.34, 20000:0.33 };
var postcardsJumboeach = { 500:1.09, 1000:0.68, 2000:0.49, 3000:0.58, 4000:0.54, 5000:0.48, 6000:0.45, 7000:0.43, 8000:0.43, 9000:0.42, 10000:0.39, 11000:0.39, 12000:0.39, 13000:0.39, 14000:0.39, 15000:0.38, 16000:0.38, 17000:0.38, 18000:0.38, 19000:0.38, 20000:0.37 }; 

 	function postcardsOnly(checkbox)
 	{
		if(checkbox.checked)
 		{
			rebuildDropDown(postcardsPriceSmall,document.getElementById("package").packagequantity.value);
//		document.getElementById("whatsincluded").style.display = "inline";
		document.getElementById("sid").style.display="inline";
		document.getElementById("jid").style.display="inline";
document.getElementById("smallcost").innerHTML = "$" + addCommas(Number(postcardsPriceSmall[document.getElementById("package").packagequantity.value]));

document.getElementById("jumbocost").innerHTML = "$" + addCommas(Number(postcardsPriceJumbo[document.getElementById("package").packagequantity.value]));



document.getElementById("smalleach").innerHTML = postcardsSmalleach[document.getElementById("package").packagequantity.value];

document.getElementById("jumboeach").innerHTML = postcardsJumboeach[document.getElementById("package").packagequantity.value];


document.getElementById("st").value=Number(postcardsPriceSmall[document.getElementById("package").packagequantity.value]);

document.getElementById("ju").value=Number(postcardsPriceJumbo[document.getElementById("package").packagequantity.value]);
		
		}
		else
		{
//		document.getElementById("whatsincluded").style.display = "none";
document.getElementById("sid").style.display="none";
		document.getElementById("jid").style.display="none";
		// if checked
rebuildDropDown(postcardsOnlySmall,document.getElementById("package").packagequantity.value);

document.getElementById("smallcost").innerHTML = "$" + addCommas(Number(postcardsOnlySmall[document.getElementById("package").packagequantity.value]));

document.getElementById("jumbocost").innerHTML = "$" + addCommas(Number(postcardsOnlyLarge[document.getElementById("package").packagequantity.value]));



document.getElementById("st").value=Number(postcardsOnlySmall[document.getElementById("package").packagequantity.value]);

document.getElementById("ju").value=Number(postcardsOnlyLarge[document.getElementById("package").packagequantity.value]);



				
		}
 		
 	}
 	
 	function rebuildDropDown(list,checked)
 	{
		//document.getElementById("hidsel").value=checked;
		document.getElementById("package").packagequantity.options.length = 0;
			i=0;
 			for(quantity in list)
 			{
				if(checked == quantity)
					{ checkIt = true; }
				else
					{ checkIt = false; }
				document.getElementById("package").packagequantity.options[i] = new Option(addCommas(quantity),quantity,false,checkIt);
 				i++;
 			}
 	}
 	
 	
 	// Version 0.0 Experimental Version - no transparent PNG support in IE
// Version 0.1 Initial release version - AlphaImageLoader for IE added
// Version 0.2 Wasn't positioning to the centre of the insert correctly
// Version 0.3 Add zindex parameter
// Version 1.0 Add .makeDraggable() [requires API v2.59]
// Version 1.1 18/10/2006 use pane 1 instead of G_MAP_MAP_PANE so as to be above GTileLayerOverlay()s
// Version 1.2 02/04/2007 work with MarkerManager

      function EInsert(point, image, size, basezoom, zindex) {
        this.point = point;
        this.image = image;
        this.size = size;
        this.basezoom = basezoom;
        this.zindex=zindex||0;
        // Is this IE, if so we need to use AlphaImageLoader
        var agent = navigator.userAgent.toLowerCase();
        
        if ((agent.indexOf("msie") > -1) && (agent.indexOf("opera") < 1)){this.ie = true} else {this.ie = false}
      } 
      
      //EInsert.prototype = new GOverlay();

      EInsert.prototype.initialize = function(map) {
        var div = document.createElement("div");
        div.style.position = "absolute";
        div.style.zIndex=this.zindex;
        if (this.zindex < 0) {
           map.getPane(G_MAP_MAP_PANE).appendChild(div);
        } else {
           map.getPane(1).appendChild(div);
        }
        this.map_ = map;
        this.div_ = div;
      }
      
      EInsert.prototype.makeDraggable = function() {
        this.dragZoom_ = map.getZoom();
        this.dragObject = new GDraggableObject(this.div_);
        
        this.dragObject.parent = this;
        
        GEvent.addListener(this.dragObject, "dragstart", function() {
          this.parent.left=this.left;
          this.parent.top=this.top;
        });

      
        GEvent.addListener(this.dragObject, "dragend", function() {
          var pixels = this.parent.map_.fromLatLngToDivPixel(this.parent.point);
          var newpixels = new GPoint(pixels.x + this.left - this.parent.left, pixels.y +this.top -this.parent.top);
          this.parent.point = this.parent.map_.fromDivPixelToLatLng(newpixels);
          this.parent.redraw(true);
          GEvent.trigger(this.parent, "dragend", this.parent.point);
        });    
      }

      EInsert.prototype.remove = function() {
        this.div_.parentNode.removeChild(this.div_);
      }

      EInsert.prototype.copy = function() {
        return new EInsert(this.point, this.image, this.size, this.basezoom);
      }

      EInsert.prototype.redraw = function(force) {
       if (force) {
        var p = this.map_.fromLatLngToDivPixel(this.point);
        var z = this.map_.getZoom();
        var scale = Math.pow(2,(z - this.basezoom));
        var h=this.size.height * scale;
        var w=this.size.width * scale;

        this.div_.style.left = (p.x - w/2) + "px";
        this.div_.style.top = (p.y - h/2) + "px";

        if (this.ie) {
          var loader = "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src='"+this.image+"', sizingMethod='scale');";
          this.div_.innerHTML = '<div style="height:' +h+ 'px; width:'+w+'px; ' +loader+ '" ></div>';
        } else {
          this.div_.innerHTML = '<img src="' +this.image+ '"  width='+w+' height='+h+' >';
        }
        
        // Only draggable if current zoom = the initial zoom
        if (this.dragObject) {
          if (z != this.dragZoom_) {this.dragObject.disable();}
        }
        
       } 
      }

      EInsert.prototype.show = function() {
        this.div_.style.display="";
      }
      
      EInsert.prototype.hide = function() {
        this.div_.style.display="none";
      }
      
      EInsert.prototype.getPoint = function() {
        return this.point;
      }
	  
function setCookie(name)
{
    
    document.cookie= name ;
}
function getCookie(name)
{
    if(name!='')
    {
	    var dc = document.cookie;
	    var prefix = name + "=";
	    var begin = dc.indexOf("; " + prefix);
	    if (begin == -1)
	    {
	        begin = dc.indexOf(prefix);
	        if (begin != 0) return null;
	    }
	    else
	    {
	        begin += 2;
	    }
	    var end = document.cookie.indexOf(";", begin);
	    if (end == -1)
	    {
	        end = dc.length;
	    }
	    return unescape(dc.substring(begin + prefix.length, end));
	} 
	else
	{
		return false;
	}
	   
}
function deleteCookie(name)
{
    if (getCookie(name))
    {
        document.cookie = name;
    }
}

