/* scserver.js - Javascript common to all Site Caddy websites
 */

//
// --------- Page preview ------------
//

function alertNoLinks(evt) {
	window.alert('Links are disabled on Preview pages');
	if (evt.preventDefault) {
		evt.preventDefault();
	}
	return false;
}

function disableLinks() {
	var lLinks = document.links;	// avoids silly Eclipse warning
	for (var i=0; i < lLinks.length; i++) {
		var oLink = lLinks[i];
		if (oLink.addEventListener) {
			oLink.addEventListener("click", alertNoLinks, false);
		} else if (oLink.attachEvent) {
			oLink.attachEvent('onclick', alertNoLinks);
		}
	}
}

//
// --------- Menus ------------
//
//	For drop down menus.
//

startList = function() {
 if (document.all&&document.getElementById) {
  navRoot = document.getElementById("primaryNav");
  for (i=0; i<navRoot.childNodes.length; i++) {
   node = navRoot.childNodes[i];
   if (node.nodeName=="LI") {
    node.onmouseover=function() {
     this.className+=" over";
    }
    node.onmouseout=function() {
     this.className=this.className.replace(" over", "");
    }
   }
  }
 }
}

//
// --------- Shop Caddy ------------
//
//	This will be moved to the Shop Caddy JS file when Module Manager
//  is in place.  - NS
//

function validateReqProdAttrs(frm) {
	try {
		var bOK = true;
		for (var i=0; i<frm.elements.length; i++) {
			var elt = frm.elements[i];
			if ((elt.type == 'select-one' || elt.type == 'select-multiple') &&
					elt.className.match(/.*isRequired.*/)) {
				bOK = bOK && (elt.value !== "");
			}
		}
		if (!bOK) {
			window.alert('Please select all required options (denoted with an asterisk) ' +
			      		 'before adding this product to your cart.');
		}
		return bOK;
	} catch(e) {
		return true;
	}
}
