/**
 ** changeDropDownValueSelected - finds a match to newIndexValue among the option values and sets the
 **									matching value to be the selected option
 ** Params:
 ** dropDownId - id of select drop down
 ** newSelectValue - new selected option value
**/
function changeDropDownValueSelected(dropDownId, newSelectValue) {
	var selectDropDown = document.getElementById(dropDownId);
	for(i=0; i < selectDropDown.options.length; i++) {
		var optionVal = selectDropDown.options[i].value;
		if (optionVal == newSelectValue) {
			selectDropDown.options[i].selected = true;
			return;
		}
	}
}
/**
 ** sets a global variable 'thumbnailPerspective' if it exists on the page
 **/
function setThumbnailPerspective(perspectiveValue) {
	if (thumbnailPerspective != undefined) {
		thumbnailPerspective = perspectiveValue;
	}
}

/**
 ** swapImgWithUrl() -- replaces target image src with given src string
 ** Params:
 **   ToImg - pass in the name of the target iamge
 **   NewImgUrl - pass in the new src URL to replace target image
 **/
 function swapImgWithUrl(ToImg, NewImgUrl)
 {
	if (document.images[ToImg] != undefined) {
		document.images[ToImg].src = NewImgUrl
	}
 }
 
/**
 ** swapImgsWithUrls() -- calls swapImgWithUrl for every element in the array
 ** Params:
 ** ToImgArray - array of target image names
 ** NewImgUrlArray - array of new src URL strings
 **/
 function swapImgsWithUrls(ToImgArray, NewImgUrlArray)
 {
	for(i=0; i < ToImgArray.length; i++) {
		swapImgWithUrl(ToImgArray[i], NewImgUrlArray[i])
	}
}
/**
 ** swapImg() -- swaps two images
 ** Params:
 **   ToImg - pass in the name of the target image
 **  FromImg - pass in the name of the original image
 **/
function swapimg(ToImg, FromImg)
{
	document.images[ToImg].src=document.images[FromImg].src
}

/**
** simulateClickSwatch -- used in prod_detail pages to simulate onclick of swatch images 
** with id=imageIdPrepend_<<chosenVal in dropdown>>
** Params:
**	imageIdPrepend -- the string to prepend to the id string e.g. imageColor_
**  dropDownId -- id of the select dropDown element
**/
function simulateClickSwatch(imageIdPrepend, dropDownId) {
	var dropDown = document.getElementById(dropDownId)
	//get the value selected
	var chosenVal = dropDown.options[dropDown.options.selectedIndex].value
	var imgId = imageIdPrepend + chosenVal;
	eval(jQuery('#' + imgId + ' > a').attr('href'));
}
/**
** getURLParam -- get url parameter value
**/
function getURLParam(strParamName){
var strReturn = "";
var strHref = window.location.href;
if ( strHref.indexOf("?") > -1 ){
   var strQueryString = strHref.substr(strHref.indexOf("?")).toLowerCase();
   var aQueryString = strQueryString.split("&");
   for ( var iParam = 0; iParam < aQueryString.length; iParam++ ){
      if (aQueryString[iParam].indexOf(strParamName + "=") > -1 ){
        var aParam = aQueryString[iParam].split("=");
        strReturn = aParam[1];
        break;
      }
   }
}
return strReturn;
}
