function reCode(doFocus) {
	document.getElementById("codeimg").src = r+'images/code_img_out.php?regen&' + Math.random();
	if (doFocus) document.getElementById("reg-captcha").focus();
}

function faq(id) {
	$(".answers").hide();
	$("#"+id).show();
}

var lpass = new Object();

lpass.show = function() {
	$("#dlgemail").val($("#user").val());
	$("#dialogbg").show();
	$("#dialog").show();
	$("#dlgemail").focus();
}

lpass.hide = function() {
	$("#dialog").hide();
	$("#dialogbg").hide();
}

lpass.submit = function() {
	$.post(r+"newpassword.php", { "email": $("#dlgemail").val() }, function(data){
		if (data == "err") {
			$("#dlgerr").html("Error: The address you entered is not registered.");
			$("#dlgemail").focus();
		} else {
			$("#dlgcontent").html(data);
		}
	});
}

lpass.done = function() {
	location.reload(true);
}

var cart = new Object();

cart.clear = function() {
	$.post(r+"cart_submit.php", { "action": "clear" }, function(){
		window.location = r+"cart";
	});
}

cart.add = function(id) {
	$.post(r+"cart_submit.php", $("#prodform"+id).serialize(), function(){
		window.location = r+"cart";
	});
}

cart.update = function() {
	postdata = $("#cartform").serialize();
	postdata += "&action=update";
	$.post(r+"cart_submit.php", postdata, function(data){
		window.location = r+"cart";
	});
}

cart.remove = function(id) {
	$.post(r+"cart_submit.php", { "action": "remove", "removeitem": id }, function(){
		window.location = r+"cart";
	});
}

cart.undo = function() {
	$.post(r+"cart_submit.php", { "action": "undo" }, function(){
		window.location = r+"cart";
	});
}

cart.submitOrder = function(uid) {
	$.post(r+"cart_submit.php", { "action": "submitorder", "uid": uid }, function(){
		window.location = r+"thankyou?qid="+uid;
	});
}

cart.loadFromQuote = function(uid) {
	$.post(r+"cart_submit.php", { "action": "loadfromquote", "uid": uid }, function(){
		window.location = r+"cart";
	});
}

cart.startQuote = function() {
	$.post(r+"cart_submit.php", { "action": "startquote" }, function(data){
		$("#dialogbg").show();
		$("#dialog").html(data);
		$("#dialog").show();
	});
}

cart.addMulti = function() {
	$.post(r+"cart_submit.php", $("#quoteform").serialize(), function(data){
		window.location = r+"cart";
	});
}

function popOver (myID) {
	$(".popup").hide();
	$("#" + myID + "_popup").show();
}
function popOut () {
	$(".popup").hide();
}

function openMedia(divName) {
	$("#dialogbg").show();
	$("#media-"+divName).show();
	$(document).bind('keydown', function(e){
		switch (e.which) {
			case 27:
				closeMedia();
				return false;
				break;
			case 37:
				flipMedia("left");
				break;
			case 39:
				flipMedia("right");
				break;
		}
	});
}
function closeMedia() {
	$(document).unbind('keydown');
	$(".mediaWindow").hide();
	$("#dialogbg").hide();
}

function flipMedia(dir) {
	if ($(".mediaWindow:visible").hasClass("photo")) {
		var currentIndex = parseInt($(".mediaWindow:visible .index").val());
		$(".mediaWindow").hide();
		var switchId = "";
		var fristId = "";
		var lastId = "";
		var thisIndex = 0;
		$(".mediaWindow .index").each(function(){
			thisIndex = parseInt($(this).val());
			if (thisIndex == 0) firstId = $(this).parent().attr("id");
			lastId = $(this).parent().attr("id");
			if (thisIndex == currentIndex+(dir == "left" ? -1 : 1)) {
				switchId = $(this).parent().attr("id");
			}
		});
		if (switchId == "") {
			switchId = (dir == "left" ? lastId : firstId);
		}
		$("#"+switchId).show();
	}
}

