/* Used so that for JS enabled browsers the seller-notes box doesn't appear */
document.write("<style type='text/css'>");

/*
16555 starts here
commented since shipping portion is wired off in live-470 

document.write("a#col_calculate-total-link {display: inline;}");
document.write("a#col_outside-us-link {display: inline;}");
document.write("a#col_inside-us-link {display: inline;}");

document.write("a#exp_calculate-total-link {display: inline;}");
document.write("a#exp_outside-us-link {display: inline;}");
document.write("a#exp_inside-us-link {display: inline;}");

document.write("div#col_inside-us {display:none;}");
document.write("div#col_outside-us {display:none;}");

document.write("div#exp_inside-us {display:none;}");
document.write("div#exp_outside-us {display:none;}");

document.write("span#col_zipcode-us{display:none;}");
document.write("span#exp_zipcode-us{display:none;}");

16555 ends here
*/


document.write("table#cart td#notes div textarea { display: none;}");
document.write("</style>");

/* CONSTANTS */
var TITLE_TAG_COLLAPSED = "Click to view purchase details";
var TITLE_TAG_EXPANDED = "Click to close purchase details";

/*
	Original From: Dustin Diaz - Vitamin
	Modified by: Emanuele Fabrizio
*/
YAHOO.widget.Effect = function(el) {
	this.oEl = YAHOO.util.Dom.get(el);
	this.height = parseInt(YAHOO.util.Dom.getStyle(this.oEl,'height'));
	this.width = parseInt(YAHOO.util.Dom.getStyle(this.oEl,'width'));
};

/* Performs the closing of the widget towards the top. The iTimer takes
 an integer in seconds. The onComplete callback function it's not used
 */
YAHOO.widget.Effect.prototype.BlindUp = function(iTimer, onComplete) {
	var timer = iTimer || 1;
	// Make sure TO NOT SPECIFY a unit of percentage or Firefox will be confused
	var blind = new YAHOO.util.Anim(this.oEl, { height: { to:0 } }, timer, YAHOO.util.Easing.easeOut);
	if ( onComplete ) {
		blind.onComplete.subscribe(onComplete);
	}
	blind.animate();
};

/* Performs the opening of the widget towards the bottom. The iTimer takes
 an integer in seconds. The onComplete callback function it's not used
 */
YAHOO.widget.Effect.prototype.BlindDown = function(iTimer, onComplete) {
	var timer = iTimer || 1;
   this.oEl.style.visibility = 'hidden';
   this.oEl.style.overflow = 'hidden';
   this.oEl.style.height = '';
	var finalHeight = parseInt(YAHOO.util.Dom.getStyle(this.oEl,'height'));
   this.oEl.style.height = '0';
   this.oEl.style.visibility = 'visible';
	//Make sure TO SPECIFY a unit of percentage or IE will not expand the item completely
	var blind = new YAHOO.util.Anim(this.oEl, { height: { to:finalHeight, from:0, unit: '%'} }, timer, YAHOO.util.Easing.easeOut);
	if ( onComplete ) {
		blind.onComplete.subscribe(onComplete);
	}
	blind.animate();
};

/* This controller applies to the container with ID purchase-detail which in
 turn will execute the animation on the container with ID of cover
 */
toggle = function() {
	var $D = YAHOO.util.Dom;
	var $E = YAHOO.util.Event;
	var $ = $D.get;
	var objExpando = null;
	
	return {
		init : function() {
			objExpando = $('expander');
			if( !isOrderEditable() ){
				$D.addClass('purchase-detail','collapsed');
			}
			$E.on('expander','click',this.controller,$('cover'),true);
		},
		controller : function(e) {
			var z = new YAHOO.widget.Effect(this);
			if ( !$D.hasClass('purchase-detail','collapsed') ) {
				$D.addClass('purchase-detail','collapsed')
				z.BlindUp(2);
				if( objExpando ) objExpando.title = TITLE_TAG_COLLAPSED;
				
			}
			else {
				$D.removeClass('purchase-detail','collapsed')
				z.BlindDown(2);
				if( objExpando ) objExpando.title = TITLE_TAG_EXPANDED;
			}
			$E.stopEvent(e);
		}
	};
}();

/* Method used to check whether there are any fields in the order details
 component which are editable. If so the method returns true
*/
function isOrderEditable(){
	var result = false;
	var objValue = document.getElementById( 'editable-order' );
	if( objValue ){
		result = ( objValue.value == '1' ) ? true : false;
	}
	return result;
}

/* Method invoked to display all textarea tags which are within the container
 with ID of notes. It also toggles the controller link seller-notes-toggle
 to add the appropriate CSS class
*/
function enableNotesTextArea(){
	var elements = null;
	if( document.getElementById('notes') ){
		elements = document.getElementById('notes').getElementsByTagName('textarea');
	}
	if( elements ){
		for( var i = 0; i < elements.length; i++ ){
			YAHOO.util.Dom.setStyle(elements[i],'display','block')
		}
		modifyLink( 'on' );
	}
}

/* Used so that for JS enabled browsers the seller-notes-toggle link appears
 with the proper visual design. If toggle has a value then the class 'opened'
 is added, otherwise it gets removed
*/
function modifyLink( toggle ){
	if( toggle == 'on' ){
		YAHOO.util.Dom.addClass(document.getElementById('seller-notes-toggle'), 'opened');
	} else {
		YAHOO.util.Dom.removeClass(document.getElementById("seller-notes-toggle"), 'opened')
	}
}


/*
16555 starts here
commented since shipping portion is wired off in live-470 

function colShowInsideUS(){

		if (document.getElementById("col_calculate-shipping"))
		{
			var calculateShipping = document.getElementById("col_calculate-shipping");
			calculateShipping.style.display = "none"; 
		}
		
		var insideUS = document.getElementById("col_inside-us");
		var outsideUS = document.getElementById("col_outside-us");
	
		insideUS.style.display = "block";
		outsideUS.style.display = "none"; 

		if (document.getElementById("exp_calculate-shipping"))
		{
			var calculateShipping = document.getElementById("exp_calculate-shipping");
			calculateShipping.style.display = "none"; 
		}

		var insideUS = document.getElementById("exp_inside-us");
		var outsideUS = document.getElementById("exp_outside-us");
		
		insideUS.style.display = "block";
		outsideUS.style.display = "none"; 


		var shippingAndHandling = document.getElementById("exp_shipping-and-handling");
		var tax = document.getElementById("exp_tax");
		var total = document.getElementById("exp_total");
		
		shippingAndHandling .style.display = "none";
		tax.style.display = "none"; 
		total.style.display = "none"; 

		var shippingAndHandling = document.getElementById("col_shipping-and-handling");
		var tax = document.getElementById("col_tax");
		var total = document.getElementById("col_total");
		
		shippingAndHandling .style.display = "none";
		tax.style.display = "none"; 
		total.style.display = "none";
}



function colShowOutsideUS(){

		if (document.getElementById("col_calculate-shipping"))
		{
			var calculateShipping = document.getElementById("col_calculate-shipping");
			calculateShipping.style.display = "none"; 
		}

		var insideUS = document.getElementById("col_inside-us");
		var outsideUS = document.getElementById("col_outside-us");
	
		outsideUS.style.display = "block"; 
		insideUS.style.display = "none";
		
		if (document.getElementById("exp_calculate-shipping"))
		{
			var calculateShipping = document.getElementById("exp_calculate-shipping");
			calculateShipping.style.display = "none"; 
		}

		var insideUS = document.getElementById("exp_inside-us");
		var outsideUS = document.getElementById("exp_outside-us");
	
		outsideUS.style.display = "block"; 
		insideUS.style.display = "none";

		var shippingAndHandling = document.getElementById("exp_shipping-and-handling");
		var tax = document.getElementById("exp_tax");
		var total = document.getElementById("exp_total");
		
		shippingAndHandling .style.display = "none";
		tax.style.display = "none"; 
		total.style.display = "none"; 

		var shippingAndHandling = document.getElementById("col_shipping-and-handling");
		var tax = document.getElementById("col_tax");
		var total = document.getElementById("col_total");
		
		shippingAndHandling .style.display = "none";
		tax.style.display = "none"; 
		total.style.display = "none";

		
}

function colShowUSZipCodeField(){
	var zipCodeUS = document.getElementById("col_zipcode-us");
	var countryCode = document.getElementById("col_ship_to_country");

	var selIndex = countryCode.selectedIndex;
	if (countryCode.options[selIndex].value=="US")
	{
			zipCodeUS.style.display = "inline"; 
	}
	else
	{
		zipCodeUS.style.display = "none"; 
	}

	var zipCodeUS = document.getElementById("exp_zipcode-us");
	var countryCode = document.getElementById("exp_ship_to_country");

	var selIndex = countryCode.selectedIndex;
	if (countryCode.options[selIndex].value=="US")
	{
			zipCodeUS.style.display = "inline"; 
	}
	else
	{
		zipCodeUS.style.display = "none"; 
	}
}


function expShowUSZipCodeField(){
	var zipCodeUS = document.getElementById("exp_zipcode-us");
	var countryCode = document.getElementById("exp_ship_to_country");

	var selIndex = countryCode.selectedIndex;
	if (countryCode.options[selIndex].value=="US")		
	{
			zipCodeUS.style.display = "inline"; 
	}
	else
	{
		zipCodeUS.style.display = "none"; 
	}
	
}


function submitTheForm(){
	var reviewForm = document.getElementById("reviewForm");
	reviewForm.submit();
}

function showShippingFields()
{
	var shippingCalculatedBy = document.getElementById("shipping-calculated-by");
	if (shippingCalculatedBy.value == 'country')
	{
		colShowOutsideUS();	
	}
	else
	{
		colShowInsideUS();
	}
}

16555 ends here
*/


YAHOO.util.Event.addListener( window, 'load', modifyLink );
YAHOO.util.Event.addListener('seller-notes-toggle', 'click', enableNotesTextArea);
YAHOO.util.Event.onAvailable('purchase-detail', toggle.init, toggle, true);


/*
16555 starts here
commented since shipping portion is wired off in live-470 

YAHOO.util.Event.addListener('exp_calculate-total-link', 'click', colShowInsideUS);
YAHOO.util.Event.addListener('exp_outside-us-link', 'click', colShowOutsideUS);
YAHOO.util.Event.addListener('exp_inside-us-link', 'click', colShowInsideUS);

YAHOO.util.Event.addListener('col_calculate-total-link', 'click', colShowInsideUS);
YAHOO.util.Event.addListener('col_outside-us-link', 'click', colShowOutsideUS);
YAHOO.util.Event.addListener('col_inside-us-link', 'click', colShowInsideUS);

YAHOO.util.Event.addListener('col_ship_to_country', 'change', colShowUSZipCodeField);
YAHOO.util.Event.addListener('exp_ship_to_country', 'change', colShowUSZipCodeField);

YAHOO.util.Event.addListener('col_zip-change-link', 'click', showShippingFields);
YAHOO.util.Event.addListener('exp_zip-change-link', 'click', showShippingFields);

YAHOO.util.Event.addListener('shipping_method', 'change', submitTheForm);

16555 ends here
*/

