function promotion_chk()
{

	var element = document.getElementById("disc_tr");
	if (document.checkout.promotion.checked)
	{
		document.checkout.promotion.value = 1
		
		document.checkout.promo_chk.value = 1
		element.style.display = 'block';
		
		document.checkout.books_cnt1.value = document.checkout.no_of_books.value;	
	}
	else
	{
		element.style.display = 'none';
	}  
	
	cal_price();  
	  
}
	
function verify_books()
{
	books = "no_of_books"; 
	var element = document.getElementById(books);
	if(isNaN(new Number(element.value)))
		element.value = element.value.substring(0, element.value.length - 1) 
		
	document.checkout.books_cnt.value = document.checkout.no_of_books.value;
	
	document.checkout.books_cnt1.value = document.checkout.no_of_books.value;
	
	if(document.checkout.shipping_city.value == 'Other')
		document.checkout.billing_cnt.value = document.checkout.no_of_books.value;		
	
	cal_price();

}

function disp()
{
//document.checkout.price.value=document.checkout.total_price.value;
document.checkout.price.value=document.checkout.price.value;
//document.checkout.subs_desc.value = "The 30-day subscription allows you access to all MoneySaver coupons for 30 days from the day you register.";
document.checkout.subs_desc.value = "The 180-day subscription allows you access to all MoneySaver coupons for 180 days from the day you register.";
}

	
function subscription_price()
{
	var type_of_subscription = document.getElementById("type_of_subscription").value;
	if(type_of_subscription == '30 days')
	{
		price = '99';
		document.checkout.subs_desc.value = "The 30-day subscription allows you access to all MoneySaver coupons for 30 days from the day you register.";
	}
	else if(type_of_subscription == '90 days')
	{
		price = '199';
		document.checkout.subs_desc.value = "The 90-day subscription allows you access to all MoneySaver coupons for 90 days from the day you register.";
		//alert(price);
	}
	else if(type_of_subscription == '180 days')
	{
		price = '349';
		document.checkout.subs_desc.value = "The 180-day subscription allows you access to all MoneySaver coupons for 180 days from the day you register.";
	}
	document.getElementById("price").value = price;
	
	cal_price();
}

function cal_price()
{ 
	books = "document.checkout.no_of_books"; 	
	billing_cnt = "document.checkout.billing_cnt"; 
	
	disc_amt = "document.checkout.disc_amt";
	disc_amt_original = "document.checkout.disc_amt_original";
	//alert(eval(disc_amt_original).value);
	disc_type = "document.checkout.disc_type";
	
	total_price = "document.checkout.total_price"  ; 
	price = "document.checkout.price"  ;
	
	amount = document.getElementById("price").value;

	if (ValidateNum(eval(books).value))
	{
		original_price =   Number(eval(books).value) * amount;
		//alert(original_price);
		shipping_price =   Number(eval(billing_cnt).value) * 35;
		
		if (document.checkout.promotion.checked)
		{
			//if (ValidateNum(eval(disc_amt).value))
			if (ValidateNum(eval(disc_amt_original).value))
			{
				//disc_price =   Number(eval(disc_amt).value) * Number(eval(books).value);
//				eval(total_price).value = Number(original_price) - Number(disc_price) + Number(shipping_price)  ;
				//alert(eval(disc_amt).value);
				//alert(eval(disc_type).value);
				if((eval(disc_type).value) == '2')
				{
					
					disc_price =   Number(eval(disc_amt_original).value) * Number(eval(books).value);
					eval(total_price).value = Number(original_price) - ((Number(original_price)/100)*(eval(disc_amt_original).value) ) + Number(shipping_price);
					//eval(disc_amt).value = ((Number(original_price)/100)*(eval(disc_amt_original).value) ); // full discount amt display
					eval(disc_amt).value = ((Number(original_price)/100)*(eval(disc_amt_original).value) )/Number(eval(books).value);
					eval(disc_amt).value =Math.round(eval(disc_amt).value*Math.pow(10,2))/Math.pow(10,2);
				}
				else
				{
					disc_price =   Number(eval(disc_amt_original).value) * Number(eval(books).value);
					eval(total_price).value = Number(original_price) - Number(disc_price) + Number(shipping_price)  ;
				}
			}
			else
			{
				eval(total_price).value = Number(original_price) + Number(shipping_price)  ;	
						
			}
		}
		else
		{
			eval(total_price).value = Number(original_price) + Number(shipping_price)  ;			
		}
		eval(total_price).value =Math.round(eval(total_price).value*Math.pow(10,2))/Math.pow(10,2);
		
		eval(total_price).value = currencyformated(eval(total_price).value);
	}
}
function ValidateNum(NumObject)
{
	var checkOK = "0123456789";
	var checkStr = NumObject;
	var allValid = true;
	for (i = 0;  i < checkStr.length;  i++)
	{
		ch = checkStr.charAt(i);
		for (j = 0;  j < checkOK.length;  j++)
		if (ch == checkOK.charAt(j))
		break;
		if (j == checkOK.length)
		{
			allValid = false;
			break;
		}
	}
	return(allValid);
}

function currencyformated(amount)
{
	var i = parseFloat(amount);
	s = new String(i);
	if(s.indexOf('.') < 0) { s += '.00'; }
	if(s.indexOf('.') == (s.length - 2)) { s += '0'; }
	return s
}
function submitform()
{
  //alert(document.checkout.fname.value);
	document.checkout.submit();
}

function books_changed()
{
	books = "no_of_books"; 
	var element = document.getElementById(books);
	if(isNaN(new Number(element.value)))
		element.value = element.value.substring(0, element.value.length - 1) 
		
	document.checkout.books_cnt.value = document.checkout.no_of_books.value;
	
	
	calculate_price();

}

function calculate_price()
{ 
	books = "document.checkout.no_of_books"; 	
	
	total_price = "document.checkout.total_price"  ; 	

	if (ValidateNum(eval(books).value))
	{
		original_price =   Number(eval(books).value) * 399;
		
		eval(total_price).value = Number(original_price) ;			
		
		eval(total_price).value =Math.round(eval(total_price).value*Math.pow(10,2))/Math.pow(10,2);
		
		eval(total_price).value = currencyformated(eval(total_price).value);
	}
}

function dis_img(txt)
{
var temp=txt;
if(txt=="step1")
{
	document.getElementById("dis_img1").src="images/step1.jpg";
	document.getElementById("step1").style.backgroundColor="#CCE6F9";
	document.getElementById("step2").style.backgroundColor="#fff";
	document.getElementById("step3").style.backgroundColor="#fff";
	document.getElementById("step4").style.backgroundColor="#fff";
}
if(txt=="step2")
{
	document.getElementById("dis_img1").src="images/step2.jpg";
	document.getElementById("step1").style.backgroundColor="#fff";
	document.getElementById("step2").style.backgroundColor="#CCE6F9";
	document.getElementById("step3").style.backgroundColor="#fff";
	document.getElementById("step4").style.backgroundColor="#fff";
}
if(txt=="step3")
{
	document.getElementById("dis_img1").src="images/step3.jpg";
	document.getElementById("step1").style.backgroundColor="#fff";
	document.getElementById("step2").style.backgroundColor="#fff";
	document.getElementById("step3").style.backgroundColor="#CCE6F9";
	document.getElementById("step4").style.backgroundColor="#fff";	
}
if(txt=="step4")
{
	document.getElementById("dis_img1").src="images/step4.jpg";
	document.getElementById("step1").style.backgroundColor="#fff";
	document.getElementById("step2").style.backgroundColor="#fff";
	document.getElementById("step3").style.backgroundColor="#fff";
	document.getElementById("step4").style.backgroundColor="#CCE6F9";	
}
}