/* mct: computerbags javascript */

function showPic(id, className) {
	$("a." + className).hide();
	$("a#" + id).show();
}

function showLeftPic() {
	var e = document.getElementById('leftSelect');
	changeValue('op4', e.options[e.selectedIndex].value);
	showPic('img_left_' + e.options[e.selectedIndex].id, 'gallery-product-left');
}

function showRightPic() {
	var e = document.getElementById('rightSelect');
	changeValue('op4', e.options[e.selectedIndex].value);
	showPic('img_right_' + e.options[e.selectedIndex].id, 'gallery-product-right');
}

// mct: make sure select box color matches default onload
function selectLeftDefaultColor() {
	var f = document.getElementById('productForm');
	
	hide('rightOrientationColors');
	hide('rightOrientationImages');
	hide('rightColorImages');
	hide('leftColorImages');
	show('leftColorImages');
	for (var i=0;i<f.length;i++)
  {
		element = f.elements[i];
		if (element.id == "leftSelect" && element.selectedIndex >= 0) {
			leftCurrent = element.options[element.selectedIndex].id;
			leftColor = element.options[element.selectedIndex].value;
			changeValue('op4', leftColor);
      changeColorSizeSelect(element.options[element.selectedIndex].id);
			showPic('img_left_' + leftCurrent, '');
		}
  }

}

// mct: make sure select box color matches default onload
function selectBothDefaultColors() {
	var f = document.getElementById('productForm');

	hide('rightOrientationColors');
	hide('rightOrientationImages');
	hide('rightColorImages');
	hide('leftOrientationColors');
	hide('leftOrientationImages');
	hide('leftColorImages');
	
	// loop through all form elements, showing hidden objects based on orientation, and setting up the default pic
	orientation = '';
	for (var i=0;i<f.length;i++)
  {
		element = f.elements[i];
		if (element.name == 'orientation') {
			if (element.checked == true && element.value == 0) {
				show('leftOrientationColors');
				show('leftOrientationImages');
				show('leftColorImages');
				orientation = 'left';
			}
			if (element.checked == true && element.value == 1) {
				show('rightOrientationColors');
				show('rightOrientationImages');
				show('rightColorImages');
				orientation = 'right';
			}
		}
		if (orientation == 'left' && element.id == "leftSelect" && element.selectedIndex >= 0) {
			leftCurrent = element.options[element.selectedIndex].id;
			leftColor = element.options[element.selectedIndex].value;
			changeValue('op4', leftColor);
			showPic('img_left_' + leftCurrent, '');
		}
		if (orientation == 'right' && element.id == "rightSelect" && element.selectedIndex >= 0) {
			rightCurrent = element.options[element.selectedIndex].id;
			rightColor = element.options[element.selectedIndex].value;
			changeValue('op4', rightColor);
			showPic('img_right_' + rightCurrent, '');
		}
  }

}

function toggleProductControls(isLeftOrientation) {
	if(isLeftOrientation) {
		show('leftOrientationColors');
		show('leftOrientationImages');
		show('leftColorImages');

		hide('rightOrientationColors');
		hide('rightOrientationImages');
		hide('rightColorImages');
	}
	else { //right orientation
    hide('leftOrientationColors');
    hide('leftOrientationImages');
    hide('leftColorImages');

    show('rightOrientationColors');
    show('rightOrientationImages');
    show('rightColorImages');
	}
}

// mct: be certain
function doubleConfirm(mess1) {
	if (confirm(mess1)) {
		if (confirm('Are you really sure you want to do this\?')) {
			return true;
		}
	}
	return false;
}

function changeSrc(id, src) {
}

function changeValue(input, value) {
  if (!value) { value = ''; }
	var field = document.getElementById(input);
	field.value = value;
	return false;
}

function changeFormSelect(formID, newID) {
	var f = document.getElementById(formID);
	for (var i=0;i<f.length;i++)
 	{
    //alert(f.options[i].id);
    if (newID == f.options[i].id) {
      f.options.selectedIndex = i;
      changeValue('op4', f.options[i].value);
    }
    //showPic('img_left_' + leftCurrent, '');
  }
}
	
function changeColorSizeSelect(newID) {
  $("select.color_size_select").hide();
  e = 'sizes_for_color_' + newID;
  show(e);
  e = document.getElementById(e);
  if (e != null) {
    changeValue('op5', e.options[e.selectedIndex].value );
  }
}

function validate(form_id,email) {
  var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
  var address = document.forms[form_id].elements[email].value;

  if (reg.test(address) == false) {
    alert('Please enter a valid email address.');

    return false;
  }
}

function onYouTubePlayerReady(player) {
  ytplayer = document.getElementById("ytplayer");
  ytplayer.cueVideoById('Yz7FFlFy8eM');
}

function pauseVideo() {
  if (ytplayer.getPlayerState() == 2) {
    ytplayer.playVideo();
  } else {
    ytplayer.pauseVideo();
  }
}

function menuToggle(link, id) {
  id = $('#'+id);
  link = $('#'+link);

  if (id.css("display") == "none") {
    $(link).css("backgroundImage", "url(/images/home-arrow-on.gif)");
  } else {
    $(link).css("backgroundImage", "url(/images/home-arrow-off.gif)");
  }
  id.toggle();
  return false;
}
