//		CatalogSearch.js


//alert('CatalogSearch.js');
AddEvent(window, "load", jsInitializeBuyMbira);
AddEvent(window, "load", jsDisappearSearching);
AddEvent(window, "load", jsDisplayAlert);


//=========================
function AddEvent(oElement, sEventName, fnFunction)
//=========================
{
	if (oElement)
	{
		if (oElement.attachEvent)
		{
			oElement.attachEvent("on" + sEventName, fnFunction);
		}
		else
		{
			oElement.addEventListener(sEventName, fnFunction, true);
		}
	}
}


var sMbiraBuyClass = 'mbira-check';
//=========================
function jsInitializeBuyMbira()
//=========================
{
//alert('function jsInitializeBuyMbira()');

	// get all links on the page
	var aLinks = document.getElementsByTagName('A');
		if (!aLinks) return;

	var regClassMatch = new RegExp('(^|\\s)' + sMbiraBuyClass + '(\\s|$)');
	//alert('regClassMatch.Pattern = ' + regClassMatch.source);

	for (var iLink=0; iLink < aLinks.length; iLink++)
	{
		sClass = aLinks[iLink].className;
		
			if (sClass && sClass > '')
			{
				//alert('Got a class: ' + sClass);
				if (regClassMatch.test(sClass))
				{
					//alert('Found a match: ' + sClass);
					aLinks[iLink].onclick = jsBuyMbiraConfirm;
				}
			}
	}
	
}


//=========================
function jsBuyMbiraConfirm(evt)
//=========================
{
	// cancel event-bubbling
		if (evt) { event = evt; }
	event.cancelBubble = true;

	sMessage = "I understand that MBIRA may sell instruments (without instructional DVD) to purchasers in these categories:\n" +
"\n" +
"1. Buyer has enrolled in, and paid MBIRA for, a future workshop, Mbira Camp, or lessons, or workshops or lessons taken during the past 2 years; or\n" +
"\n" +
"2. Buyer is an educational non-profit organization, including K-12 schools and universities.\n" +
"\n" +
"Click OK to proceed to checkout if you are a buyer who meets this requirement.\n" +
"\n" +
"Click CANCEL to buy an mbira with instructional DVD only.";

bResponse = confirm(sMessage);

	if (bResponse)
	{
		return true;
	}
	else
	{
		document.location = "?cat=dvds";
		return false;
	}

}


//=========================
function jsDisappearSearching()
//=========================
{
//alert('function jsDisappearSearching()');

	if (document.getElementById)
	{
		document.getElementById("objPleaseWait").style.display = "none";
	}
}


var jsAlertMsg = "";
//=========================
function jsDisplayAlert()
//=========================
{
	if (jsAlertMsg!=''){alert(jsAlertMsg);}

//alert('function jsDisplayAlert()');
}


