 $(function(){
	// disable context menu on image
	$("img").oncontextmenu = function() {return false;},  
	 
	$("img").mousedown(function(e) { 
		if (e.button == 2) {
			//alert("If you want this image, please contact my cup of tea");
			//return false;
		}
	}),
	 
	// swap menu buttons
	$(".swapButton").hover(				
		function() {
			$replaceBy = $(this).attr("src").replace(/([^/]+)_off((\.gif)|(\.jpg))$/g, "$1_on$2");
			$(this).attr("src", $replaceBy);
		},
		function() {
			$replaceBy = $(this).attr("src").replace(/([^/]+)_on((\.gif)|(\.jpg))$/g, "$1_off$2");
			$(this).attr("src", $replaceBy);
		}
	),
	
	// popup window
	//$.modalWindow({classPrefix : "popup"});
	
	// toggle product rollover menu
	$("#submeunProducts").css({top: 22 + $("#menuProducts").position().top + "px", left: $("#menuProducts").position().left - 12 + "px" }),
	$("#menuProducts").mouseover (
		function() {
			$("#submeunProducts").show();
		 	$("#submeunProducts").hover (
		 	 		function() {
		 	 			$("#submeunProducts").show();
		 	 		}, function() {
		 	 			$("#submeunProducts").hide();
		 	 		}
		 	 	)
		} 
 	)
});




function getObj(id) {
    return (document.all)? document.all[id] : document.getElementById(id);
}

function IaddEvent(element, event, listenerFn) {
    if(element.addEventListener) {
        element.addEventListener(event, listenerFn, false);
    } else if (element.attachEvent) {
        element.attachEvent("on" + event, listenerFn);
    } else {
        element["on"+event] = listenerFn;
    }
}


function getNewCaptcha(id, url) {
	var imgObj = getObj(id);
	imgObj.src = url+'&'+Math.random();
}

function validateProductForm() { 
	var x = document.orderForm;
	var quantity = x.quantity;
	
	if (parseInt(quantity.value) > 0)
		 x.submit();
	else
		alert('Please enter quantity');
}

function validateOrderForm() {
	var x = document.orderForm;
	var ok = true;
	
	for(i = 0; i < x.length; i++) { 
		if (0 == x[i].name.indexOf("quantity[")) {
			if (x[i].value == "" || parseInt(x[i].value) >= 0) {
				
			} else {
				ok = false;
				x[i].focus();
				alert('Invalid quantity');
				break;
			}
		}
	}
	
	if (ok == true) {
		x.submit();
	}
}

/**
* swap image
**/
function swap(id, src) {
	document.images[id].src = src;
}

/**
* toggle object
**/
function toggle(name) {
	var x = getObj(name);
	x.style.display = (x.style.display == 'none' || x.style.display == '')? 'block' : 'none';
}



function setPaymethod() {
	var paymentMethod = ($('#creditCardType').val());
	switch (paymentMethod) {
		case 'visa':
		case 'mc':
			$('#cardInfo').show()
			break;
		default:
			$('#cardInfo').hide()
			break;
	}
}

