﻿//<!-- 
var MaxBlink=5;
var cnt = MaxBlink;
function ClickCompareCheckbox(checkBoxId, partnum)  {
	var bRet = false;
	var uCpartnum = partnum;
	partnum = uCpartnum;
	uCpartnum = uCpartnum.toUpperCase();
	if (document.getElementById(checkBoxId).checked) {
		bRet = AddProductToCompare(uCpartnum); 
		if (!bRet)
			document.getElementById(checkBoxId).checked = false;
		else {
			cnt = MaxBlink;
			setTimeout('BlinkHeader()', 10);
		}
	} else {
		RemoveProductFromCompare(uCpartnum);
	}
}
function BlinkHeader() {
	if(headCompId==null) return;
	cnt--;
	var c = document.getElementById(headCompId);
	if(cnt>0 && compCount>0) {
		if(cnt % 2) {
			SetClass(c, 'B', false);
			setTimeout('BlinkHeader()', 100);
		} else {
			SetClass(c, 'B', true);
			setTimeout('BlinkHeader()', 300);
		}
	} else {
		cnt = MaxBlink;
		SetClass(c, 'B', false);
	}
}
function AddProductToCompare(uCpartnum) {
	uCpartnum = uCpartnum.toUpperCase();
	if (compCount >= compMax ) {
		alert ("You may compare " + compMax + " items at a time. Click \"Compare\" and \"Remove All\" to start again or \"Remove\" individual items and select additional ones to compare.");
		return false;
	}
	if (f_checkDuplicate(uCpartnum)) return true;
	prodList[compCount] = uCpartnum;
	compCount ++;
	WriteCompareCookie();
	RefreshCompare();
	return true;
}
function RemoveProductFromComparePage(uCpartnum, pageLoad, addPartnum) {
	LoadCompareCookie();
	RemoveProductFromCompare_base(uCpartnum);
	if (compCount <= 0 && addPartnum == "")
		RemoveAll(pageLoad);
	else
		LaunchProductCompare(addPartnum, true);
}
function RemoveProductFromCompare(uCpartnum) {
	RemoveProductFromCompare_base(uCpartnum);
	WriteCompareCookie();
	RefreshCompare();
	return true;
} 
function RemoveProductFromCompare_base(uCpartnum) {
	if (compCount <= 0) {
		RefreshCompare();
		return false;
	}
	uCpartnum = uCpartnum.toUpperCase();
	var i=0;
	for (i=0;i<=prodList.length;i++) {
		if(prodList[i] == uCpartnum) {
			prodList.splice(i,1); 
			compCount--;
			break;
		}
	}
}
function f_checkDuplicate(uCpartnum) {
	var bExists = false;
	if (uCpartnum.length == 0) return bExists;
	uCpartnum = uCpartnum.toUpperCase();
	for (i=0; i <= prodList.length; i++) {
		if (prodList[i]) {
			if (uCpartnum == prodList[i]) {
				bExists = true;
				break;
			}
		}
	}
	return bExists;
}
function ResetControlIds() {
	compIdList.splice(0, compIdList.length);
	chkIdList.splice(0, chkIdList.length);
}
function RegisterCompareId(ctlId) {
	compIdList.push(ctlId);
}
function RegisterCheckId(ctlId) {
	chkIdList.push(ctlId); 
}
function RefreshCompIds(bEnable) {
	if(chkIdList == null)
		return;
	var i =0;
	var ObjHtml = null;
	var sTitle = "";
	if (compCount == 0)
		sTitle = "You need to select at least one item to compare.";
	for(i=0; i < compIdList.length; i++) {
		ObjHtml = document.getElementById(compIdList[i]);
		if(ObjHtml != null) {
			ObjHtml.disabled = !bEnable;
			var len=ObjHtml.className.length;
			if(len>0)
				if (bEnable)
					SetClass(ObjHtml, 'D', false);
				else
					SetClass(ObjHtml, 'D', true);
			if (compCount > 0) {
				sTitle = "Click to " + GetCompareText();
				ObjHtml.title = sTitle; 
			}
		}
	}	
}
function RefreshMainCompare() {
	var objheadCompId = document.getElementById(mainCompId);
	if(objheadCompId != null) {
		objheadCompId.style.visibility = (compCount > 0) ? "visible" : "hidden";
		objheadCompId.title = GetCompareText();
	}
}
function EnableCompareIds(bEnable) {
	var i =0;
	var ObjHtml = null;
	for(i=0; i<compIdList.length; i++) {
		ObjHtml = document.getElementById(compIdList[i]);
		if(ObjHtml != null) {
			ObjHtml.Title = (bEnable) ? "Click to " + GetCompareText() : "";
			ObjHtml.disabled = !bEnable;
		}
	}	
}
function EnableCheckIds(bEnable) {
	if(chkIdList == null)
		return;
	var i =0;
	var ObjHtml = null;
	for(i=0; i < chkIdList.length; i++) {
		ObjHtml = document.getElementById(chkIdList[i]);
		if(ObjHtml != null) {
			if(bEnable) 
				ObjHtml.disabled = false;
			else {
				if(ObjHtml.checked) {
					ObjHtml.disabled = false;
					ObjHtml.Title = "You may only remove items from compare or click compare button";
				} else
					ObjHtml.disabled = true;
			}
		}
	}	
}
function SetClass(ctl, pend, b) {
	var s = ctl.className; 
	var temp = s.substring(s.length-pend.length);
	if(b) {
		if(temp!=pend)
			s = s + pend;
	} else {
		if(temp==pend)
			s = s.substring(0, s.length-pend.length);
	}
	ctl.className = s;
}
function LaunchPrevPage() {
	var url = compUrl;
	if(url==null || url=="") url = "/";
	window.location = url;
}
// -->