var previousColor='#FFFFFF';

function setGalleryName(galleryHome) {
	select=document.GallerySelectForm.GalleryHomeMenu;
	index=select.selectedIndex;
	gallery=select[index].value;
	
	document.GallerySelectForm.GalleryName.value=gallery;
	document.GallerySelectForm.GalleryHome.value=galleryHome + "/" + gallery;
}

function popup(url) {
	window.open(url,"popup","status=0,height=400,width=630,resizable=1,dependent=1,fullscreen=0,scrollbars=1");
}

function setMenus(menuCount) {
	//var name=document.mainImageForm.mainImageName.value;
	var name=document.mainImageForm.image.value;
	//alert(name);
	
	var indexOne=name.lastIndexOf('+')+1;
	var indexTwo=name.lastIndexOf('.');
	var disabled=null;
	if((indexOne > 0) && (indexTwo > indexOne)) {
		var sub=name.slice(indexOne,indexTwo);
		disabled=new Array(sub.length);
		for(var i=0; i < sub.length; i++) {
			disabled[i]="form"+sub.charAt(i);
		}
	}
	
	for(var i=1; i <= menuCount; i++) {
		var currentForm="form"+i;
		document.forms[currentForm].item.disabled=false;
		document.forms["pp"+currentForm].addToCart.disabled=false;
		document.forms["pp"+currentForm].quantity.disabled=false;
		
		if(disabled == null) continue;
	
		for(var j=0; j < disabled.length; j++) {
			if(disabled[j] == currentForm) {
				document.forms[currentForm].item.disabled=true;
				document.forms["pp"+currentForm].addToCart.disabled=true;
				document.forms["pp"+currentForm].quantity.disabled=true;
			}
		}
	}
}
		
function init(menuCount) {
	name=document.mainImageForm.image.value;
	document.mainImageForm.mainImageName.value=stripImageName(name);
	document.mainImageForm.image.value=name;
	
	for(var i=0; i < document.images.length; i++) {
		document.images[i].onmousedown=noDrag;
		document.images[i].ondragstart=noDrag;
		document.images[i].onselectstart=noDrag;
	}
	
	loading=false;
	
	setMenus(menuCount);
}
	
function mouseOver(image) { 
	previousColor=image.style.borderColor;
	image.style.borderColor='#000066';
}
		
function mouseOut(image) { 
	image.style.borderColor=previousColor;
}
		
function mouseClick(name,path,image,menuCount) { 
	image.style.borderColor='#999999';
	previousColor=image.style.borderColor;
			
	document.mainImage.src=path;
	document.mainImageForm.mainImageName.value=stripImageName(name);
	document.mainImageForm.image.value=name;
	
	setMenus(menuCount);
}
		
function setItem(form,ppForm) { 
	//image=document.mainImageForm.mainImageName.value;
	image=document.mainImageForm.image.value;
	index=form.item.selectedIndex;
	price=form.item[index].value;
	name=form.item[index].text;
	sindex=name.indexOf(':');
	name=name.substring(0,sindex);
	ppForm.item_name.value=image+": "+name;
	ppForm.amount.value=price;
}

function stripImageName(name) {
	index=name.lastIndexOf('.');
	if(index > 0) name=name.substring(0,index);
	
	index=name.lastIndexOf('+');
	if(index > 0) name=name.substring(0,index);
	
	return name;
}

function noDrag() {
	return false;
}


