var currentColor;

function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      if (oldonload) {
        oldonload();
      }
      func();
    }
  }
}


function init(){
	
	// Set the style for images within the COPY div based on their alignment
	var copy = document.getElementById('content');
	if(copy){
		var images = copy.getElementsByTagName('IMG');
		for(var i=0;i<images.length;i++){
			var align = images[i].getAttribute('align');
			if((align == 'left')||(align == 'right')){
				//images[i].setAttribute('align', '');
				images[i].setAttribute('className', align);
				images[i].setAttribute('class', align);
			}
		}
		
		/* Find Anchors with the "imagelink" class and set them up for lightbox*/
		var anchors = copy.getElementsByTagName('A');
		for(var i=0;i<anchors.length;i++){
			if(anchors[i].className == 'imagelink'){
				anchors[i].setAttribute('rel', 'lightbox[set]');
			}
		}	
	}
	
	var useBilling = document.getElementById('use_billing');
	if(useBilling){
		
		if(useBilling.checked == true){
			toggleShipping('off');
		}
		
		if(document.all){
			useBilling.onpropertychange = function(){
				if(this.checked == true){
					toggleShipping('off');
				} else {
					toggleShipping('on');
				}
			}
		} else {
			useBilling.onchange = function(){
				if(this.checked == true){
					toggleShipping('off');
				} else {
					toggleShipping('on');
				}
			}	
		}
	}
	
	// CONTINUE ORDER
//	var cont = document.getElementById('continue');
//	if(cont){
//		cont.onclick = function(){
//			history.back();
//			return false;
//		}
//	}


}

addLoadEvent(init);

function toggleShipping(tog){
	
	var sh_name = document.getElementById('sh_name');
	var sh_address_1 = document.getElementById('sh_address_1');
	var sh_address_2 = document.getElementById('sh_address_2');
	var sh_city = document.getElementById('sh_city');
	var sh_state = document.getElementById('sh_state');
	var sh_zip = document.getElementById('sh_zip');
	var sh_phone = document.getElementById('sh_phone');
	
	var inputs = [sh_name,sh_address_1,sh_address_2,sh_city,sh_state,sh_zip,sh_phone];
	
	if(tog == 'off') {
		
		for (var i=0; i<inputs.length; i++){
			if(inputs[i]){
				inputs[i].disabled=true;
				inputs[i].style.backgroundColor="#D6D5D9";
				inputs[i].style.border="1px solid #999";
			}
		}
		
	} else {
		for (var i=0; i<inputs.length; i++){
			if(inputs[i]){
				inputs[i].disabled=false;
				inputs[i].style.backgroundColor="#FFF";
				inputs[i].style.border="1px solid #A7A6AA";
			}
		}
	}
}