function isEmpty(s)
{   return ((s == null) || (s.length == 0))
}


function card_type(number)
{
	/*
	//	Card Prefixes
	//
	//	Mastercard	51-55
	//	Visa		4
	//	AmEx		34,37
	//	Discover	6011
	*/
	var cc_type = false;
	var number = number.toString();
	var f = number.substring(0,1);
	var f3 = number.substring(0,3);


	if (f == 4) {
		cc_type = "Visa";
	}

	var f2 = number.substring(0,2);
	if (f2 > 50 && f2 < 56) {
		cc_type = "Master Card";
	}

	if (f2 == 34 || f2 == 37) {
		cc_type = "AMEX";
	}

	var f4 = number.substring(0,4);
	if (f4 == 6011) {
		cc_type = "Discover";
	}
	return cc_type;
}

function mod10(number) {

	var total = 0;
	var flag = 0;
	for (var i=(number.length - 1);i>=0; i--) {
		if (flag == 1) {
			if(number.charAt(i)>="0" && number.charAt(i)<="9") {
				var digits = number.charAt(i) * 2;
				if (digits > 9) digits -= 9;
				total += digits;
	//			var reminder = digits % 10;
	//			var quotient = (digits - reminder) / 10;
	//			total = total + parseInt(reminder);
	//			total = total + parseInt(quotient);
				flag = 0;
			}
		} else {
			if(number.charAt(i)>="0" && number.charAt(i)<="9") {
				total = total + parseInt(number.charAt(i));
				flag = 1;
			}
		}
	}

	if ((total%10) == 0) {
		return true;
	} else {
		return false;
	}

}



function fcur( num ) {
	var isNegative = false;
	num = num.toString().replace(/\$|\,/g,'');
	if( isNaN( num ) ) {
	  num = "0";
	}
	if ( num < 0 ) {
	  num = Math.abs( num );
	  isNegative = true;
	}
	cents = Math.floor( ( num * 100 + 0.5 ) % 100 );
	num = Math.floor( ( num * 100 + 0.5 ) / 100 ).toString();
	if ( cents < 10 ) {
	  cents = "0" + cents;
	}
	for ( 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 ) );
	}

	var result = num + '.' + cents;
	if ( isNegative ) {
	  result = "-" + result;
	}
	return result;
}



function isDef(o)
{
	varToStr=eval("' "+o+"'");
	if (varToStr==" undefined") {
		return false;
	}
	else 	{
		return true;
	}
}//isDef

function calc(sh)
{
	cs = document.forms.cart.elements.ship.length; // count shipping variants
	for(i=0; i<cs; i++) {
		shi = document.forms.cart.elements.ship[i];
		shp = document.forms.cart.elements['ship_hidden_'+shi.value];
		if( shi.checked ) {
			sh_price = parseFloat(shp.value);
		}
	}
	st = parseFloat(document.getElementById('subtotal').innerHTML);
	st += sh_price;// + parseFloat(tax);
	t = document.getElementById('total');
	obj = document.getElementById('shipping_price');
	obj.innerHTML = '$'+fcur(sh_price);
	if( isDef(t) ) {
		t.innerHTML = fcur(st);
	}

}//calc

function showElement(elementID)
{
   document.getElementById(elementID).style.display = 'inline';
}

function hideElement(elementID)
{
   document.getElementById(elementID).style.display = 'none';
}
