var chosenInd;
/* display or hide msg if option is used */
function showOptionMsg(val,val2){
	var el = document.getElementById(val);
	if(val2==true){
	el.style.display = "block";
	} else {
	el.style.display = "none";
	}
}
/* show/hide selects */
function procSelects(val){
	var els = document.getElementsByTagName("SELECT");
	if(val){
		for(var i=0;i<els.length;i++){
			els[i].style.display = "none";
		}
	} else {
		for(var i=0;i<els.length;i++){
			els[i].style.display = "inline";			
		}
	}
}
/* change main image - used in optionChange() */
function changeMainImg(val){
 	if(!val || val<0){
		chosenInd=0;
	} else {
		chosenInd=val-1;
	}
	var el = document.getElementById('mainImg');
	if(imgArr[chosenInd]=="n/a"){
		el.setAttribute("src",imgArr[0]);
	} else if (imgArr[chosenInd]!=""){
		el.setAttribute("src",imgArr[chosenInd]);
	}
}

/* change enlarged image per selection */
function changeEnlarged(){
	var el2 = document.getElementById('enlargedImg');
	if(!chosenInd || chosenInd<0){
		chosenInd=0;
	}
	if(imgLArr[chosenInd]!=""){
		el2.setAttribute("src",imgLArr[chosenInd]);
	}	
}
/* popup enlarged image */
function imageEnlarge(){
	var el = document.getElementById('enlargedMainCont');
	el.style.display = "block";
	procSelects(true);	
}
/* get selected option and change main image */
function optionChange(val){
	var el = document.getElementById(val);
	var imgind = el.selectedIndex;
	changeMainImg(imgind);
	changeEnlarged();
	showOptionMsg("cartmsg",false);
}

/* check if option is chosen the fire appropriate function */
function optionCheck(val){
	var el = document.getElementById(val);
	if(el.selectedIndex>0){
		showOptionMsg("cartmsg",false);
	} else {
		showOptionMsg("cartmsg",true);
		return false;
	}

}
/* close popin enlarge window */
function enlargeClose() {
	var el = document.getElementById('enlargedMainCont');
	el.style.display = "none";
	procSelects(false);
}