
 


function changePrice(price, discount, image, coupon) {
	
objSection = document.getElementById('pricediv');

if (objSection != null) {

	var origPrice = parseFloat(price);
	var discPrice = (origPrice-(origPrice*discount)).toFixed(2);//applies discount and rounds to 2 decimal places
	
	objSection.innerHTML =  "<span class='strikePrice'> $" +  price.toFixed(2) + "</span> $" + discPrice ;
}

document.getElementById('couponcodesection').innerHTML='<input type="hidden" name="coupon" value="' +coupon +  '">';
document.getElementById('bookstore_gif').innerHTML='<img src="/princetonreview/images/' + image + '"hspace="0" alt="Bookstore" width="467" height="87" />';

}





function read_cookie(cookie_name) {

if(document.cookie)
	{
		index = document.cookie.indexOf(cookie_name);
	
		if (index!=-1)
		{
			return true;
		}
		return false;
	}
	return false;
/*
  if(document.cookie) {
    
	document.write(index);
    if (index != -1)
	 {
      return (true);
    }
	return (false);
  }
  return (false);*/
}

function gup( name )
{
  name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
  var regexS = "[\\?&]"+name+"=([^&#]*)";
  var regex = new RegExp( regexS );
  var results = regex.exec( window.location.href );
  if( results == null )
    return "blank";
  else
    return results[1];
}

function checkForCoupon(coupon_name)
{
var couponCode = gup('coupon');

if (couponCode ==coupon_name)
	return true;
return false;



}




function write_cookie(write_cookie_name) {
	
  if(document.cookie)
   {
 
	index = document.cookie.indexOf(write_cookie_name);
	
  } 
  else
   {
    index = -1;
  }

  if (index == -1)
   {
    document.cookie=write_cookie_name+"=1; path=/princetonreview/; expires=Monday, 1-June-2012 08:00:00 GMT;";
	
   } 
}


function discountPrice(price)
{
	
	 if (checkForCoupon('REVIEW15'))
	{
			write_cookie('REVIEW15_cookie');
		changePrice(price, .15, 'bookstorecoupon15.gif', 'REVIEW15');
	}
	else if (read_cookie('REVIEW15_cookie'))
	{
			changePrice(price, .15, 'bookstorecoupon15.gif', 'REVIEW15');
	}
	
	else if (checkForCoupon('sendtraffic35'))
	{
		
		write_cookie('discount_cookie');
		changePrice(price, .35, 'bookstorecoupon.gif', 'sendtraffic35');
	}

	else if(read_cookie('discount_cookie'))
	{

		
			changePrice(price, .35, 'bookstorecoupon.gif', 'sendtraffic35');
		
	}
	else if (checkForCoupon('giveabook08'))
	{
			write_cookie('giveabook08_cookie');
		changePrice(price, .15, 'bookstorecoupon15.gif', 'giveabook08');
	}
	else if (read_cookie('giveabook08_cookie'))
	{
			changePrice(price, .15, 'bookstorecoupon15.gif', 'giveabook08');
	}
	else if (checkForCoupon('HSPARENT'))
	{
		
			write_cookie('HSPARENT_cookie');
			
			changePrice(price,  .15, 'bookstorecoupon15.gif', 'HSPARENT');
	}
	else if (read_cookie('HSPARENT_cookie'))
	{
			changePrice(price,  .15, 'bookstorecoupon15.gif', 'HSPARENT');
	}
	else if (checkForCoupon('APSCORE'))
	{
		
			write_cookie('APSCORE_cookie');
			
			changePrice(price,  .15, 'bookstorecoupon15.gif', 'APSCORE');
	}
	else if (read_cookie('APSCORE_cookie'))
	{
			changePrice(price,  .15, 'bookstorecoupon15.gif', 'APSCORE');
	}
		else if (checkForCoupon('COUNSELOR'))
	{
		
			write_cookie('COUNSELOR_cookie');
			
			changePrice(price,  .10, 'bookstorecoupon_counselor.gif', 'COUNSELOR');
	}
	else if (read_cookie('COUNSELOR_cookie'))
	{
			changePrice(price,  .10, 'bookstorecoupon_counselor.gif', 'COUNSELOR');
	}
	

}

// JavaScript Document
