
/* mmh/common/utility.js */

 function popWin(url,wn,wd,ht,scroll) {
	useScroll = 1;
	width = 600;
	height = 520;
	winName = "newWin";
	if (scroll == 0)	{
		useScroll = 0;
	}
	if(ht != null) {
		height = ht;
	}
	if(wd != null) {
		width = wd;
	}
	if(wn != null) {
		winName = wn;
	}
	thisURL = url;
	popupWin=window.open(thisURL,winName,"width=" + width + ",height=" + height + ", scrollbars=" + useScroll + ",resizable")
}

function swapPlusMinus (thisImg) {
	if(thisImg.src.indexOf('/mmh/images/icon_myhome_plus.gif') != -1) {
		thisImg.src = '/mmh/images/icon_myhome_minus.gif';
	} else {
		thisImg.src = '/mmh/images/icon_myhome_plus.gif'
	}
}

function showTip (e, obj) {
	alert("add tooltips function");
}

function advance(frmName, currentField,nextField,fieldMax) {
    if (currentField.value.length == fieldMax)
        document.findProducts[nextField].focus();
}

function setElementProperty(elm, property, value){
	var thisElm = null;
	if(typeof(elm) == "object"){
		thisElm = elm;
	} else {
		thisElm = document.getElementById(elm);
	}
	if((thisElm != null) && (thisElm.style != null)){
		thisElm = thisElm.style;
		thisElm[property] = value;
	}
}

curCat = "";
curHlCat = "";
curCatItem = "";
curSubCat = "";
function hlCat(thisCat) {
	if(thisCat.id != curCatItem) {
		curHlCat = thisCat;
	}
}

function unHlCat(thisCat) {
	if(thisCat == curHlCat) {
		curHlCat = "";
	}
}

function showSubCat(thisCatItem,thisCat) {
	if($(thisCatItem)==null) return;
	var thisAnchor = $(thisCatItem).getElementsByTagName('a')[0];
	if(thisCatItem != curCatItem) {
		if(curCatItem != "") {
			var currentAnchor = $(curCatItem).getElementsByTagName('a')[0];
			resetCurSubCat();
		}
		curCatItem = thisCatItem;
		curCat = thisCat;
		curHlCat = "";
	}
}

function actSubCat(thisSubCat) {
	if($(thisSubCat)==null) return;
	var thisAnchor = $(thisSubCat).getElementsByTagName('a')[0];
	if(thisSubCat != curSubCat) {
		resetCurSubCat();
		//Also do something else. Show a subcategory panel, pane, div. Something. Pending creative direction.
		$(thisSubCat).show();
		curSubCat = thisSubCat;
	}
}

function resetCurSubCat(){
	if (curSubCat != "") {
		var currentAnchor = $(curSubCat).getElementsByTagName('a')[0];
	}
}

function popUpPrintableView(url)
{
  var newWindow=window.open(url, 'printableViewWindow',
    'height=600,width=800,resizable=yes,scrollbars=yes,toolbar=yes,location=no,menubar=yes');
  if (window.focus) {newWindow.focus()}
}

aCurFlip = new Array(0,0,0);

function nextFlip(thisFlip){
	thisArrayCount = thisFlip - 1;
	if(aCurFlip[thisArrayCount] == aLastFlip[thisArrayCount]) {
		flipImgInfo(thisFlip, 0);
		aCurFlip[thisArrayCount] = 0;
	} else {
		flipImgInfo(thisFlip, aCurFlip[thisArrayCount] + 1);
		aCurFlip[thisArrayCount] = aCurFlip[thisArrayCount] + 1;
	}
}

function flipImgInfo(thisFlip, intArray){
	strFlipName = "flip" + thisFlip;
	document.getElementById(strFlipName + "Img").src = eval(strFlipName).bindings[intArray].image;
	flipTextContent = "<a href=\"" + eval(strFlipName).bindings[intArray].linkURL + "\">" + eval(strFlipName).bindings[intArray].headline + "</a>";
	document.getElementById(strFlipName + "Text").innerHTML = flipTextContent;
}


// for ajax (timeout) redirect
Ajax.Responders.register({onComplete: function(response)
 	{
	 	var browserName=navigator.appName; 
	 	var ajaxRedirect = response.getHeader('X-MMH-ajaxRedirect');
  		if (ajaxRedirect != null ) {
   			window.location = ajaxRedirect;
		}
	}
});
