// US GUNLEATHER javascript

var order_process = "<div align='center'><img src='images/loader.gif' alt='loader' border='0px' /><br />Creating and sending order...</div>";
var contact_process = "<div align='center'><img src='images/loader.gif' alt='loader' border='0px' /><br />Sending mail...</div>";

var on = false;


function toggleID(id){
	$("#" + id).slideToggle();
	/*
	if(id == 'contact_form'){
		
		if(on == false){
			$("#header").css("background-image", "url(images/logo_blk.png)");
			$("#contact").hide();
			on = true;
		}
		else{
			$("#header").css("background-image", "url(images/logo.png)");
			$("#contact").show();
			on = false;
		}
	}
	*/
}
// show the appropriate holster icon

function holsterPicker(model){
	
	icon = "<img src='images/"+ model +"_icon.jpg' alt='Holster icon' />";
	
	$("#holster_icon").html(icon);
	
	
}


// make the swatch
function makeSwatch(color){
	if(color == "black"){
		$('#swatch').html("<img src='images/swatch/black.jpg' alt='swatch' border='0px' />");
	}
	if(color == "dark brown"){
		$('#swatch').html("<img src='images/swatch/dark_brown.jpg' alt='swatch' border='0px' />");
	}
	if(color == "light brown"){
		$('#swatch').html("<img src='images/swatch/light_brown.jpg' alt='swatch' border='0px' />");
	}
	// null value
	if(color == "#null"){
		$('#swatch').html("<img src='images/swatch/dflt.jpg' alt='swatch' border='0px' />");
	}
	
}

function checkGun(value){
	if(value != "#null"){
		updateTotal(value);	
	}
	else{
		updateTotal('');
	}
	
}

function updateTotal(model){
	
	switch (model){
		// If no gun is selected, then the price is zero
		case "":
		price = "0.00";
		break;
		
		case "1911_govt":
		price = "75.00";
		break;
		
		case "1911_comm":
		price = "70.00";
		break;
		
		case "1911_pro":
		price = "70.00";
		break;
		
		// Default base price
		default:
		price = "65.00";
	}
	
	$("#total").html(price);
	$("#price").val(price);
}



function enable(id){
	$("#" + id).removeAttr("disabled");
}

function disable(id){
	$("#" + id).attr("disabled", "true");
}

function clearField(id){
	$("#" + id).val = "";
}



//



//************************************************************
//*************** ajax form functions ************************
//************************************************************

// contact form mail
function sendMail(){
	disable('contact_bttn');
	$("#contact_status").html = contact_process; 
	$.post("contact_process.php", $("#contact_f").serialize(), function(data){$("#contact_status").html(data);});								
}


// for new model notification
function signupForm(){
	disable('signup_bttn');
	$("#newmodel_status").html("<div class='info' align='center'> Checking the address and adding you to the list... <br /><img src='images/loader_bar.gif' /></div>");
	$.post("signup.php", $("#email_notification").serialize(), function(data){ $("#newmodel_status").html(data);});
}

// order form
function makeOrder(){
	disable('order_bttn');
	$('#status').show();
	$('#status').html(order_process); 
	$.post("make_order.php", $("#holster_order").serialize(), function(data){ $("#status").html(data);});	
	
}

function addNotify(){
	disable('notify_sub');
	$("#add_notify_status").html("<div class='info' align='center'> Adding you to the list... <br /><img src='images/loader_bar.gif' /></div>");
	$.post("notify.php", $("#item_notify").serialize(), function(data){ $("#add_notify_status").html(data);});
}


function scrollto(id){
	window.scrollTo(0,0);
	
	
}
