function getObj(id) {
    return (document.all)? document.all[id] : document.getElementById(id);
}

function addEvent(obj, event, fn) { 
    if(obj.addEventListener) { 
        obj.addEventListener(event, fn, false);
        return true;
    } else if (obj.attachEvent) {
        return obj.attachEvent("on" + event, fn);
    } else { 
        obj["on"+event] = fn;
    }
}

function getNewCaptcha(id, url) {
	var imgObj =document.images[id];	
	imgObj.src = url+'&'+Math.floor(Math.random()*1000);
}

/**
* toggle object
**/
function toggle(name) {
	var x = getObj(name);
	x.style.display = (x.style.display == 'none' || x.style.display == '')? 'block' : 'none';
}

function validateOrderForm() { 
	var x = document.orderForm;
	var quantity = x.quantity;
	var pass = 0;

	if (quantity.length) {
		for (var i=0; i<quantity.length; ++i) {
			var qvalue = parseInt(quantity[i].value);
			if (qvalue > 0) {
				pass = 1;
			}
		}
	} else if (parseInt(quantity.value) > 0)
		 pass = 1;
		 
	if (pass == 0)
		alert('Please enter quantity');
	else if (parseInt(x.productID.value) > 0)
		x.submit();
}

nocontextmenu = function() {
	alert("If you want this image, please contact info@macyfair.com");
	return false;
}

norightclick = function() {
	if (document.all) {
		if (event.button==2||event.button==3) {
			nocontextmenu();
		}
	} else if (document.layers) {
		if (e.which == 3) {
			nocontextmenu();
		}
	} else if (document.getElementById){
		if (event.which==3){
			nocontextmenu();
		}
	}
}

function init() {
	var x = document.images;
	for(image in x) {
		x[image].oncontextmenu = nocontextmenu;
		x[image].onmousedown = norightclick;
	}
}

addEvent(window, 'load', init);


