function UpdateShippingCost(newval){


current = document.getElementById('shippingcost').value;

document.getElementById('shippingcost').value = (newval*1+current*1)-document.getElementById('curentshippingcost').value*1;

document.getElementById('curentshippingcost').value = newval*1;


	
}

function toggleLayer( whichLayer )
{
  var elem, vis;
  if( document.getElementById ) 
    elem = document.getElementById( whichLayer );
  else if( document.all ) 
      elem = document.all[whichLayer];
  else if( document.layers ) 
    elem = document.layers[whichLayer];
  vis = elem.style;

  if(vis.display==''&&elem.offsetWidth!=undefined&&elem.offsetHeight!=undefined)    vis.display = (elem.offsetWidth!=0&&elem.offsetHeight!=0)?'block':'none';  vis.display = (vis.display==''||vis.display=='block')?'none':'block';
}

function CheckoutAlert(text, CheckoutLink){

var answer = confirm (text)
if (answer)
window.location= CheckoutLink;


}
 
function HideCheckoutBtn(whichLayer){
 
  var elem, vis;
  if( document.getElementById ) 
    elem = document.getElementById( whichLayer );
  else if( document.all ) 
      elem = document.all[whichLayer];
  else if( document.layers ) 
    elem = document.layers[whichLayer];
  vis = elem.style;

  if(vis.display==''&&elem.offsetWidth!=undefined&&elem.offsetHeight!=undefined)    vis.display = (elem.offsetWidth!=0&&elem.offsetHeight!=0)?'none':'none';  vis.display = (vis.display==''||vis.display=='none')?'none':'none';

} 

function CheckRemaindingQty(total){

	FindQty = $("#CustomQty").text();
	if(FindQty ==""){ FindQty=1; }
	
	ThisQty = document.getElementById('QtyTotal').value; 
	Remain = FindQty*1 + ThisQty*1;
	
	document.getElementById('QtyTotal').value = Remain ;
	 
	if( (  total*1 - Remain*1  ) < 1){
	
	HideCheckoutBtn('BuyButton');
	HideCheckoutBtn('displayQtyField');
	
	}

	// UPDATE THE QTY LISTBOX
	if(total > 2){
		changeList(document.getElementById('UpdateQtyBox'),total,document.getElementById('UpdateQtyBox').value); 
	}

}

function ChangeCustomShip(val){

 document.getElementById('CustomShipping').innerHTML = val;
}

function ChangeCustomSize(val){
 
 document.getElementById('CustomSize').innerHTML = val;

}

function ChangeCustomQty(val){

  document.getElementById('CustomQty').innerHTML = val;

}

function ChangeCustomColor(val){

 document.getElementById('CustomColor').innerHTML = val;

}

function bookmark_us(url, title){

if (window.sidebar) // firefox
    window.sidebar.addPanel(title, url, "");
else if(window.opera && window.print){ // opera
    var elem = document.createElement('a');
    elem.setAttribute('href',url);
    elem.setAttribute('title',title);
    elem.setAttribute('rel','sidebar');
    elem.click();
}
else if(document.all)// ie
    window.external.AddFavorite(url, title);
}


// CHANGE QTY OF LIST BOX ON PRODUCT PAGE
function emptyList( box ) {
	// Set each option to null thus removing it
	while ( box.options.length ) box.options[0] = null;

}

// This function assigns new drop down options to the given
// drop down box from the list of lists specified

function fillList( box,total, amount  ) {

ThisQty = document.getElementById('QtyTotal').value;
NewAmount = total*1 - ThisQty*1;

	for ( i = 1; i < NewAmount+1 ; i++ ) {

		// Create a new drop down option with the
		// display text and value from arr

		option = new Option( i, i );

		// Add to the end of the existing options

		box.options[box.length] = option;
	}

	// Preselect option 0

	box.selectedIndex=0;
}

// This function performs a drop down list option change by first
// emptying the existing option list and then assigning a new set

function changeList( box, total, amount ) {

	// Next empty the slave list

	emptyList( box );

	// Then assign the new list values

	fillList( box, total, amount  );
}

 