document.selected = 'unselected';

function MM_findObj(n, d) { //v4.0
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && document.getElementById) x=document.getElementById(n); return x;
}

/*function MM_showHideLayers() { //v3.0
  var i,p,v,obj,args=MM_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v='hide')?'hidden':v; }
    obj.visibility=v; }
}*/

function MM_showHideLayers() { //v3.0
  // modified to use display:none instead of visiblity:hidden
  var i,p,v,obj,args=MM_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
    if (obj.style) { 
		obj=obj.style; 
		if (v == 'show') obj.display = 'block';
		else obj.display = 'none';
	}
	}
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function showMe(num) {
	myIDs = document.myIDs;
	stepNum = document.stepNum;
	id = myIDs[num];
	
	// reset all layers/icons
	for (i = 0; i < myIDs.length; i++) {
		im = 'ch' + myIDs[i];
		l = 'model' + myIDs[i];
		imFile = 'images/step0' + stepNum + '_choices_' + myIDs[i] + '.gif';
		if (i != document.selected) document[im].src=imFile;
		MM_showHideLayers(l,'','hide');
	}
	
	if (num != document.selected) document['ch' + id].src='images/step0' + stepNum + '_choices_' + id + '_ov.gif';
	MM_showHideLayers('model' + id,'','show');
}

function selectMe(num) {
	myIDs = document.myIDs;
	stepNum = document.stepNum;
	id = myIDs[num];
	for (i = 0; i < myIDs.length; i++) {
		im = 'ch' + myIDs[i];
		l = 'model' + myIDs[i];
		imFile = 'images/step0' + stepNum + '_choices_' + myIDs[i] + '.gif';
		document[im].src=imFile;
	}
	document['ch' + id].src='images/step0' + stepNum + '_choices_' + id + '_dn.gif';
	document.forms[0].selectedItem.value = num;
	document.selected = num;
}

function launch(url) {
  self.name = "opener";
  remote = open(url, "remote", "resizable,scrollbars,status,width=310,height=400,left=10,top=10");
}

function showSelected() {
	if (document.selected!='unselected') showMe(document.selected);
}

function showMould(name) {
	newCode = getNewCode(document.selected, name);
	document.newCode = newCode;
	if (newCode != document.selected) {
		MM_showHideLayers('model' + newCode,'','show');
		MM_showHideLayers('model' + document.selected,'','hide');
	}
}

function showSelectedMould() {
	if (document.newCode != document.selected) {
		MM_showHideLayers('model' + document.selected,'','show');
		MM_showHideLayers('model' + document.newCode,'','hide');
	}
}

function selectMould(name) {
	newCode = getNewCode(document.selected, name);
	document.selected = newCode;
	//document.newCode = newCode;
}

function getNewCode(oldCode, name) {
	switch (name.charAt(0)) {
		case 'c' :
			newCode = name.charAt(name.length-1) + oldCode.slice(1,3);
			break;
		case 'p' :
			newCode = oldCode.slice(0,1) + name.charAt(name.length-1) + oldCode.slice(2,3);
			break;
		default :
			newCode = oldCode.slice(0,2) + name.charAt(name.length-1);
	}
	return newCode;
}

function confirm(step) {
	if ((step == 3 || step == 4 || step == 5 || step == 8) && document.selected=='unselected') {
		alert('You must make a selection by clicking on an icon.'); 
		errFree = false;
	} else {
		errFree = true;
	}
	return errFree;
}
