/* 
 * Copyright (c) 2010 Mogalupa
 * www.mogalupa.com
 */

function changeOption(attribute, optionsList, active, index) {
 for(i = 0; i < optionsList.length; i++) {
  optionInactive = 'option-' + optionsList[i];
  document.getElementById(optionInactive).className = 'inactive';
 }

 optionActive = 'option-' + active;
 document.getElementById(optionActive).className = 'active';

 document.getElementById(attribute).selectedIndex = index;

 document.getElementById('size-msg').style.display = "none";
}

function displaySubNav() {
 document.getElementById('sub-nav').style.display = "block";
}
function hideSubNav() {
 document.getElementById('sub-nav').style.display = "none";
}

function hideShipping() {
 document.getElementById('opc-shipping').style.display = "none";
 document.getElementById('billing:use_for_shipping_yes').checked = true;
}

function showShipping() {
 document.getElementById('opc-shipping').style.display = "block";
}

function checkReview() {
 hideReview();
checkPassword();
}

function checkPassword() {
 document.getElementById('review-style').style.display = 'block';
 stylePass = document.getElementById('billing:customer_password').className;
 styleConfirm = document.getElementById('billing:confirm_password').className;
 if(stylePass == 'input-text required-entry validate-password validation-failed' || styleConfirm == 'input-text required-entry validate-password validation-failed') {
  hideReview();
 }
 else {
  showReview();
 }
}

function hideReview() {
  document.getElementById('review-container').style.display = 'none';
 document.getElementById('review-style').style.display = 'block';
}

function showReview() {
 document.getElementById('review-container').style.display = 'block';
 document.getElementById('review-style').style.display = 'none';
}

function align()
{
	var lmt = document.getElementById('wrapper');
	var container = document.documentElement;

	if(lmt && container)
	{
	    var containerHeight;
	    if (container.innerWidth)
	    {
            containerHeight = container.innerHeight;
		}
		else
		{
            containerHeight = container.clientHeight;
		}
	    var lmtHeight;
	    if (lmt.innerWidth)
	    {
            lmtHeight = lmt.innerHeight;
		}
		else
		{
            lmtHeight = lmt.offsetHeight;
		}
		var y = Math.ceil((containerHeight - lmtHeight) / 2);
		if(y < 0)
		{
			y = 0;
		}
		lmt.style.position = "relative";
		lmt.style.top = y + "px";
	}
	if (document.getElementById)
	{
		document.body.style.visibility = 'visible';
	}

}

function addevent(obj,evt,fn,capt){
	if(obj.addEventListener)
	{
		obj.addEventListener(evt, fn, capt);
		return true;
	}
	else if(obj.attachEvent)
	{
		obj.attachEvent('on'+evt, fn);
		return true;
	}
	else return false;
}

if (document.getElementById && document.getElementsByTagName)
{
	addevent(window, 'load', align, false);
	addevent(window, 'resize', align, false);
}
