function OpenCenterWindow(url)
{
var argv = OpenCenterWindow.arguments;
var argc = OpenCenterWindow.arguments.length;	
var w = window.screen.width;
var h = window.screen.height;
var W = (argc > 1) ? argv[1] : 600;
var H = (argc > 2) ? argv[2] : h;
var X = Math.ceil((w-W)/2);
var Y = 0;
//Math.ceil((h-H)/2) - 20;

window.open(url, "_blank", "top=" + Y +", left=" + X +", width=" + W +", height=" + H +", scrollbars=1, status=0, menubar=0");
}

var capitalizeMe = function( obj, cap ) {
       val = obj.value;
       newVal = '';
	   charIndex = -1;
       val = val.split(' ');
       for ( var c = 0; c < val.length; c++ )
	     {
	     newVal += val[c].substring( 0, 1 ).toUpperCase();  
		 switch( cap )
		       {
			   case 'UC':
			      newVal += val[c].substring( 1, val[c].length ).toUpperCase();
			   break;
			   case 'LC':
			      charIndex = val[c].search(/\-/);
				  if ( charIndex != -1 ) {
					 newVal += val[c].substring( 1, charIndex + 1).toLowerCase();
					 newVal += val[c].substring( charIndex + 1, charIndex + 2 ).toUpperCase();
					 newVal += val[c].substring( charIndex + 2, val[c].length ).toLowerCase();
					 } 
				  else newVal += val[c].substring( 1, val[c].length ).toLowerCase();
 			   break;
			   default:
			      newVal += val[c].substring( 1, val[c].length );
			   }
		 newVal += ( c == val.length-1 ? '' : ' ' );
		 }
        
       obj.value = newVal;
       }

String.prototype.trim = function() { return this.replace(/^\s+|\s+$/g,""); }

function formatPhone(keyCode, $this) {
	if (keyCode == 8 || keyCode == 37 || keyCode == 39 || keyCode == 46) return;
	var field = $this;
	field.value = formatPhoneValue(field.value);
	if (field.value.length > 13)
		field.onkeyup = '';

}

function formatPhoneValue(value) {
	var phoneDigits = getDigits(value);
	var phone = "(";
	for (i = 0; i < phoneDigits.length; i++) {
		phone += phoneDigits.charAt(i);
		if (i == 2)
			phone += ") ";
		else if (i == 5)
			phone += "-";
	}
	return phone;
}

function getDigits(value) {
	var digits = "";
	for (i = 0; i < value.length; i++) {
		if ("0123456789".indexOf(value.charAt(i)) != -1)
			digits += value.charAt(i);
	}
	return digits;
}

function allowedChars(myfield, e, symbols, dec)
{
var key;
var keychar;

symbols = (symbols ? symbols : "0123456789-" );

if (window.event)
   key = window.event.keyCode;
else if (e)
   key = e.which;
else
   return true;
   
keychar = String.fromCharCode(key);

// control keys
if ((key==null) || (key==0) || (key==8) ||
    (key==9) || (key==13) || (key==27) )
   return true;

// numbers
else if ((symbols.indexOf(keychar) > -1))
   return true;

// decimal point jump
else if (dec && (keychar == "."))
   {
   myfield.form.elements[dec].focus();
   return false;
   }
else
   return false;
}

function Xtend(X, N) {
    var P;
    X = String(X);
    if (/e/i.test(X)) {
        return X;
    }
    while ((P = X.indexOf(".")) < 0) {
        X += ".";
    }
    while (X.length <= P + N) {
        X += "0";
    }
    return X;
}

/************************************************************/

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  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_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}


function toggleBillingAddress(radioButtonObj) {
    var billingDiv = document.getElementById('billingDiv');
    if (radioButtonObj.checked)
	 {
      billingDiv.style.display = 'none';
	  $('#billing_address').val($('#shipping_address').val());
	  $('#billing_city').val($('#shipping_city').val());
	  $('#billing_state_us').val($('#shipping_state_us').val());
	  $('#billing_zip').val($('#shipping_zip').val());
	 }
    else
        billingDiv.style.display = 'inline';
}