
/* teclan Javascript function to change
 dynamic product choice images within drop down layout  */
function updateDynamicChoiceImage(dropDown,widgetID,imageList)  {
	
	var myindex  = dropDown.selectedIndex
    var SelValue = dropDown.options[myindex].value
	var SelName = dropDown.options[myindex].text;
	//retrieve image map
	var imageMap = getProdChoiceImageMap(imageList);
	//get image
	var selectedImageFile = getImageFileFromName(imageMap,SelName);
	//set the image
	var theImage = document.getElementById("DD_" + widgetID);
	if (theImage) {
		//change image src
		theImage.src = selectedImageFile;
		theImage.alt =  SelName;
		theImage.title = SelName;
	}
}

/* Method retrieves the global variable 
ProdChoiceImageMap
and returns 2-d array of image/file name */
function getProdChoiceImageMap(imageList) {
	
	//check if we have any data to parse
	if (imageList != '') {
		//first split into temp array
		var tempMap = imageList.split(",");
		//create image map array
		var imageMap = new Array(tempMap.length);
		//split and populate array
		for(var i=0; i < tempMap.length; i++) {
			//and newster array into array
			imageMap[i] = new Array(2);
			//split contents into map
			var arr = tempMap[i].split("=");
			for (var x=0; x < arr.length;x++) {
				imageMap[i][x] = arr[x];
			}
		}
	}
	return imageMap;
}



/* method to return image match from image match */
function getImageFileFromName(imageMap,imageName) {
	var imageFileName = "";
	if (imageName != "") {
	
		for (var i=0;i<imageMap.length;i++) {
			if (imageName == imageMap[i][0]) {
				imageFileName = imageMap[i][1];
				break;
			}
			else {
				imageFileName = "blank.jpg";
			}
		}
	}
	return imageFileName;
}





