function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function eraseCookie(name) {
	createCookie(name,"",-1);
}

// JQuery Stuff
$(document).ready(function(){	
	
	$(".menuSub").mouseover(function(){
		$(this).css("border-left","4px solid #ffffff");
	});
	$(".menuSub").mouseout(function(){
		$(this).css("border-left","0px solid #ffffff");		
	});
	
	$("#reorderSelect").click(function(e){
		var pcat = $("#pcat").val();
		var scat = $("#secondary_category").val();
		window.location='index.php?page=products_reorder&primary_category='+pcat+'&secondary_category='+scat;
	});	
	
    $(".titleHover").mouseover(function(){
    	$(this).fadeTo( 50, .5);
    });
    $(".titleHover").mouseout(function(){
    	$(this).fadeTo( 100, 1);
    });
	
	// Defines numeric inputs
	$("input.numeric").keypress(function(event){
		if (!(event.which >= 48 && event.which <= 57) && event.which != 0 && event.which != 8 && event.which != 46)
		{
			event.preventDefault();
		}
	});
		
	
	$("#contactform").validate({
		rules: {
			contactName: {
				required: true
			},
			contactEmail: {
				required: true,
				email: true
			},
			contactContent: {
				required: true
			}
			
		},
		submitHandler: function(form) {
			form.submit();
		}
		
	});
});
