var $j = jQuery.noConflict();
$j(function(){ 
	$j('.date-pick').datePicker(); 
});

$j(document).ready(function(){
	$j("ul#primaryNav li").hover(function() {
		$j(this).find("ul").css({display: "block"});
	}, function(){
		$j(this).find("ul").css({display: "none"});
	});


	$j(".thickbox2").live("click",function(){
		tb_show($j(this).attr("title"), $j(this).attr("href"));
		return false;
	});

	/* Tabs */
	function showTab(tab) {
		$j("#rfqForm ul.tabNav li").removeClass("active");
		$j("#rfqForm div").hide();
		
		$j("#rfqForm .tab-" + tab).show();
		$j("#rfqForm ul.tabNav li.nav-" + tab).addClass("active");
	}
	


	/* NEXT */
	$j("#rfqForm a.next").click(function() {
		var next = $j(this).attr("id");
		next = next.substr(5);
		
		/* Tab 1 - Must enter DeliveryDate and Quantity to advance */
		if (next == 1){
			var fail = "";
			if($j("#DeliveryDate").val() == ""){
				fail = "You must enter a delivery date.\n";
			}
			if($j("#Quantity").val() == ""){
				fail += "You must enter a quantity.";
			}else if(isNaN( parseInt( $j("#Quantity").val() ) )){
				fail += "Your quantity must be a number."
			}
				
			if(fail != ""){
				alert(fail);
				return false;
			}
		}
		
		/* Tab 2 - Must Select a Process to advance */
		if (next == 2){
			var fail = "";
			if($j("#MetalPhoto").attr("checked") == false && $j("#PolyColor").attr("checked") == false && $j("#AlumaJet").attr("checked") == false && $j("#VinylJet").attr("checked") == false && $j("#IDMark").attr("checked") == false){
				fail = "You must select a process.\n";
			}
			if($j("#MetalPhoto").attr("checked") == true || $j("#PolyColor").attr("checked") == true || $j("#AlumaJet").attr("checked") == true || $j("#IDMark").attr("checked") == true || $j("#VinylJet").attr("checked") == true){
				var count = 0;
				$j(".finish input").each(function(index, i){
					if($j(i).attr("checked") == true){
						count++;
					}
				});
				if(count == 0){
					fail = "Please select a finish.";
				}
			}
			
			if(fail != ""){
				alert(fail);
				return false;
			}
			
			
			/* ==== THICKNESSES         ============================== */
			
			/* Set thicknesses for MetalPhoto */
			if($j("#MetalPhoto").attr("checked") == true && ($j("#Matte").attr("checked") == true || $j("#Satin").attr("checked") == true) ) {
				$j("#Thickness").html("<option value=''>Select One</option><option>.003&quot;</option><option>.005&quot;</option><option>.008&quot;</option><option>.012&quot;</option><option>.020&quot;</option><option>.032&quot;</option><option>.039&quot;</option><option>.063&quot;</option><option>.090&quot;</option><option>.125&quot;</option>");
			}
			if($j("#MetalPhoto").attr("checked") == true && $j("#No4").attr("checked") == true){
				$j("#Thickness").html("<option value=''>Select One</option><option>.032&quot;</option><option>.063&quot;</option><option>.090&quot;</option><option>.125&quot;</option>");
			}
			if($j("#MetalPhoto").attr("checked") == true && $j("#Gloss").attr("checked") == true){
				$j("#Thickness").html("<option>.020&quot;</option>");
			}
			
			/* Set thicknesses for AlumaJet */
			if($j("#AlumaJet").attr("checked") == true && ($j("#Matte").attr("checked") == true || $j("#Satin").attr("checked") == true) ) {
				$j("#Thickness").html("<option value=''>Select One</option><option>.005&quot;</option><option>.012&quot;</option>");
			}
			if($j("#AlumaJet").attr("checked") == true && $j("#Brushed").attr("checked") == true){
				$j("#Thickness").html("<option>.016&quot;</option>");
			}
			
			/* Set thicknesses for PolyColor */
			if($j("#PolyColor").attr("checked") == true && ($j("#Matte").attr("checked") == true || $j("#Satin").attr("checked") == true) ) {
				$j("#Thickness").html("<option value=''>Select One</option><option>.005&quot;</option><option>.008&quot;</option><option>.012&quot;</option><option>.020&quot;</option>");
			}
			
			/* Set thicknesses for Vinyl Jet */
			if($j("#VinylJet").attr("checked") == true) {
				$j("#Thickness").html("<option>.004&quot;</option>");
			}
			
			/* Set thicknesses for ID Mark */
			if($j("#IDMark").attr("checked") == true) {
				$j("#Thickness").html("<option value=''>Select One</option><option>.006&quot;</option>");
			}
			
			/* ==== MOUNTING TYPES         ============================== */
			/* Set IDMark mounting types */
			if($j("#IDMark").attr("checked") == true) { $j("#Mounting").html("<option>Adhesive Only</option>"); }

			/* Set VinylJet mounting types */
			if($j("#VinylJet").attr("checked") == true) { $j("#Mounting").html("<option>Adhesive Only</option>"); }
			
			/* ==== COLOR HELP         ============================== */
			
			$j("#ColorHelp").hide();
			/* Set PolyColor color help */
			if($j("#PolyColor").attr("checked") == true){
				$j("#ColorHelp").css("display","block");
				$j("#ColorHelp").html('<strong>Colors Available</strong> : <a href="/images/color-chart.gif" class="thickbox2">Black, cyan, magenta, yellow, green, light green, blue, dark blue, red, orange, gold, hydraulic purple, brown, light gold.</a>');
			}
			
			if($j("#MetalPhoto").attr("checked") == true){
				$j("#ColorHelp").css("display","block");
				$j("#ColorHelp").html('<strong>Colors Available</strong> : <a href="/images/metalphoto-color-chart.jpg" class="thickbox2">Black &amp; gold, black &amp; silver, black &amp; copper.</a>');
			}
			
			if($j("#AlumaJet").attr("checked") == true){
				$j("#ColorHelp").css("display","block");
				$j("#ColorHelp").html("<strong>Colors Available</strong> : Full color range.");
			}
			
			if($j("#VinylJet").attr("checked") == true){
				$j("#ColorHelp").css("display","block");
				$j("#ColorHelp").html("<strong>Colors Available</strong> : Full color range.");
			}
			
			if($j("#IDMark").attr("checked") == true){
				$j("#ColorHelp").css("display","block");
				$j("#ColorHelp").html('<strong>Colors Available</strong> : <a href="/images/id-mark-color-chart.gif" class="thickbox2">Black/white, blue/white, green/white, gray/white, black/yellow, red/white reflective, black/white reflective, black/yellow reflective.</a>');
			}
		}
		
		/* Tab 3 - Must fill out required information to advance. */
		if (next == 3){
			var fail = "";
			if($j("#Color").val() == ""){
				fail = "Please enter your color preferences.\n";
			}
			if($j("#Width").val() == "" || $j("#Height").val() == ""){
				fail += "Please enter your size dimensions.\n";
			}else if(isNaN(parseInt( $j("#Width").val())) || isNaN(parseInt( $j("#Height").val()))){
				fail += "Your Width and Height must be a numerical.\n"
			}
			if($j("#Thickness").val() == ""){
				fail += "Please select a thickness.\n";
			}
			if($j("#Mounting").val() == ""){
				fail += "Please select a mounting type.\n";
			}
			if($j("#Corner").val() == ""){
				fail += "Please select a corner type.\n";
			}
			if($j("#Corner").val() == "Radius" && $j("#Radius").val() == ""){
				fail += "Please enter a radius for your corners.\n";
			}
			if($j("#Description").val() == ""){
				fail += "Please enter a description of your product.\n";
			}
			
			if(fail != ""){
				alert(fail);
				return false;
			}
		}
		
		next = parseInt(next)+1;
		showTab("0"+next);
		
		return false;
	});
	
	/* BACK */
	$j("#rfqForm a.back").click(function() {
		var back = $j(this).attr("id");
		back = back.substr(5);
		back = parseInt(back)-1;
		showTab("0"+back);
		
		return false;
	});
	
	
	/* Show Finish if needed. */
	$j(".process input").click(function() {
		if($j(this).attr("id") == "MetalPhoto"){ 
			showFinishes();

			$j("#Brushed").hide().next("label").hide().next("br").hide();
			$j("#Lexan").hide().next("label").hide().next("br").hide();
		}else if($j(this).attr("id") == "AlumaJet"){
			showFinishes();
			
			$j("#No4").hide().next("label").hide().next("br").hide();
			$j("#Gloss").hide().next("label").hide().next("br").hide();
			$j("#Lexan").hide().next("label").hide().next("br").hide();
		
		}else if($j(this).attr("id") == "PolyColor"){
			showFinishes();
			
			$j("#Brushed").hide().next("label").hide().next("br").hide();
			$j("#No4").hide().next("label").hide().next("br").hide();
			$j("#Gloss").hide().next("label").hide().next("br").hide();
			$j("#Lexan").hide().next("label").hide().next("br").hide();
		
		}else if($j(this).attr("id") == "VinylJet"){
			showFinishes();
			
			$j("#Brushed").hide().next("label").hide().next("br").hide();
			$j("#No4").hide().next("label").hide().next("br").hide();
			$j("#Satin").hide().next("label").hide().next("br").hide();
		
		}else if($j(this).attr("id") == "IDMark"){
			showFinishes();
			
			$j("#Brushed").hide().next("label").hide().next("br").hide();
			$j("#No4").hide().next("label").hide().next("br").hide();
			$j("#Satin").hide().next("label").hide().next("br").hide();
		
		}else{
			$j(".finish").css({display: "none"});
		}
	});
	
	function showFinishes(){
		$j(".finish input").each(function(){
			$j(this).attr("checked","");
		});
		$j(".finish input").show();
		$j(".finish label").show().next("br").show();
		$j(".finish").css({display: "block"});	
	}
	
	/* Show Radius input if user selects a corner radius */
	$j("#Corner").change(function() {

		$j("#Radius").hide();
		$j(".radius").hide();
		if($j("#Corner").val() == "Radius"){
			$j("#Radius").show();
			$j(".radius").show();
		}
	});
	
	/* SUBMIT */
	$j("#rfqForm").submit(function(){
		var fail = "";
		if($j("#Name").val() == ""){
			fail = "Please enter your name.\n";
		}
		if($j("#Email").val() == ""){
			fail += "Please enter your email.\n";
		}else if(!isValidEmail($j("#Email").val())){
			fail += "Please enter a valid email. \n";
		}
		if($j("#Phone").val() == ""){
			fail += "Please your phone number.\n";
		}
		
		if(fail != ""){
			alert(fail);
			return false;
		}
		
		form.post;
	});
	
	
	function isValidEmail(str) {
   		return (str.indexOf(".") > 2) && (str.indexOf("@") > 0);
   	}
	
});


// Get Date For Form Processor
var getDate=new Date()

var getYear=getDate.getYear()
if (getYear < 1000)
getYear+=1900

var getDay=getDate.getDay()

var getMonth=getDate.getMonth()+1
if (getMonth<10)
getMonth="0"+getMonth

var getCurrentDay=getDate.getDate()
if (getCurrentDay<10)
getCurrentDay="0"+getCurrentDay

theDate = getMonth+"/"+getCurrentDay+"/"+getYear 