$(document).ready(function() {

	var url = window.location; 

	/* Lib Functions */
	function getURLVar(urlVarName) { var urlHalves = String(document.location).split('?'); var urlVarValue = ''; if(urlHalves[1]){ var urlVars = urlHalves[1].split('&'); for(i=0; i<=(urlVars.length); i++){ if(urlVars[i]){ var urlVarPair = urlVars[i].split('='); if (urlVarPair[0] && urlVarPair[0] == urlVarName) { urlVarValue = urlVarPair[1]; } } } } return urlVarValue;   }
	function disableSelect(el){ elm = $(el); elm.html(''); elm.attr('disabled', true); }

	//Detect IE6
	var isIE6 = /msie|MSIE 6/.test(navigator.userAgent);

	// Add Commas
	function addCommas(nStr) { nStr += ''; x = nStr.split('.'); x1 = x[0]; x2 = x.length > 1 ? '.' + x[1] : ''; var rgx = /(\d+)(\d{3})/; while (rgx.test(x1)) { x1 = x1.replace(rgx, '$1' + ',' + '$2'); } return x1 + x2; }

	
	/* Global Vars */
    var gbl = { 
		ajaxFile : 'rfqprocess.php',
		imgDir : 'img/rfq'
        }
	var get = {
		id :getURLVar('id'),
		step: getURLVar('step'),
		incentive: getURLVar('inc')
	};
    var el = {
		dHoperation : $('#dHoperation'),
		dEpower : $('#dEpower'),
		hub : $('#ihub'),
		ch : $('#ich'),
		span : $('#ispan'),
		capacity : $('#icapacity'),
        step2form : $("#step2"),
		step2submittop : $("#step2submit_top"),
		step2submitbottom : $("#step2submit_bottom"),
		incentiveform : $("#fincentive"),
		incentivesubmit : $("#step5submit"),
		gift : $('#gift'),
		address : $("#iaddress"),
		city : $("#icity"),
		state : $("#istate"),
		zip : $("#izip"),
		step3form : $("#step3"),
		step3submittop : $("#step3submit_top"),
		step3submitbottom : $("#step3submit_bottom"),
		fname : $("#ifname.required"),
		lname : $("#ilname"),
		company : $("#icompany"),
		email : $("#iemail")
	};
	var hoist = {
		selecthoist : $('#selecthoist'),
		hoperation : $('#hoperation'),
		epower : $('#epower')
	}
	var jib = {
                jib : $('#jib'),
		img : $('img#jibimg'),
		hoist : $('#jibhoist'),
		hoistM : $('#jibhoistM'),
		capacity : $('#jib #capacity'), 
		span : $('#jib #span'),
		hub : $('#jib #hub'),
		ch : $('#jib #ch'),
        ch_td : $('#jib #ch td')
	};

	/* Manages the state of the image */
	function changeImageState(vals){ 
		var d = '--'; 
		if('description' in vals){ d = vals.description; } 
		num = (typeof(vals.num) != 'undefined') ? vals.num : get.id; 
		if(typeof(vals.type) != 'undefined'){
			type = vals.type; 
		}else{ 
			type = 'L'; 
			if(hoist.selecthoist.val() == "YES"){ type =(hoist.hoperation.val() == "Electric Operated") ? 'LH' :'LHM'; } 
		} 
			img = 'img/rfq/jib'+num+type+'.png';
		if(isIE6){
			j = document.getElementById('jib'); 
			ji = document.getElementById('jibimg'); 
			j.removeChild(ji);
			j2 = document.createElement('img');  
			j2.src = img;
			j2.id = 'jibimg';  
			j.appendChild(j2); 
		}else{
			jib.img.attr('src',img);
		}
                 
/*		jib.jib.prepend('<img alt="'+d+'" src="'+img+'" id="jibimg">'); */ 
	}
	function changeJibImage(type){ 

		/* Hack to solve the image state issue for Crane #12 */ 
		thisType = (type) ? type : ''; 
		if((get.id == 12) && (el.hub.val() > 15)){  changeImageState({type : thisType, num : 1 }); return; } 
		changeImageState({type : thisType}); 
		} 

	/* Initialization */
	// Tooltip Initialization
	el.dHoperation.easyTooltip();
	el.dEpower.easyTooltip();

	/* Initial Load of page -- textplacements */
	createTextPlacements(get.id); 


	/*
	Clearing selects incase they page is refreshed and the select option is not null 
	HUB is changed to a text box for cranes 5 - 10 (and it is optional), so no textbox is required.
	*/ 

	disableSelect(el.span); 
	if(!(get.id > 4 || get.id < 11)){ disableSelect(el.hub); }  

	// Clearing Input
	if($('input.required').val() == "") { $('input.required').clearingInput({text : '(required)'}); }
	if($('input.optional').val() == "") { $('input.optional').clearingInput({text : '(optional)'}); }

/* Added functions */

	function ajax_url(args){ str = Array(); var n = 0; for(var key in args){  str[n] = key+'='+args[key]; n++; }; return gbl.ajaxFile+'?'+str.join("&"); }

/* Validation Functions */

	function validatecapacity(){ var a = el.capacity.val(); if(a != "" && a != undefined) { el.capacity.next().css("display","none"); el.capacity.css('color', 'black');  return true; } else { el.capacity.next().css("display","block"); el.capacity.css('color','#b80000'); return false; }  } 
	function validatespan(){ var a = el.span.val(); if(a != "" && a != undefined) { el.span.next().css("display", "none"); el.span.css('color', 'black'); return true; } else { el.span.next().css("display", "block"); jib.span.html('Span'); el.span.css('color', '#b80000'); return false; } } 
	function validatehub(){ var a = el.hub.val(); if(get.id < 4 || get.id > 10) { if(a != "" && a != undefined) { el.hub.next("display","non"); el.hub.css('color','black'); return true; }else{ el.hub.next().css("display","block"); el.hub.css("color", "#b80000"); return false; } }else{ /* Hub is not required for 5-11 */ return true; }}
	function validatefname(){ if(el.fname.val().length < 2  || el.fname.val() == "(required)") { el.fname.addClass("error"); return false; } else { el.fname.removeClass("error"); return true; } }
	function validatelname(){ if(el.lname.val().length < 2  || el.lname.val() == "(required)") { el.lname.addClass("error"); return false; } else { el.lname.removeClass("error"); return true; } }
	function validatecompany(){ if(el.company.val().length < 2  || el.company.val() == "(required)") { el.company.addClass("error"); return false; } else { el.company.removeClass("error"); return true; } }
	function validateemail(){ var a = el.email.val(); var filter = /^[a-zA-Z0-9]+[a-zA-Z0-9_.-]+[a-zA-Z0-9_-]+@[a-zA-Z0-9]+[a-zA-Z0-9-.]+.[a-z]{2,4}$/; if(filter.test(a)){ el.email.removeClass("error"); return true; } else { el.email.addClass("error"); return false; } }

	function validatehoist(){ var a = hoist.selecthoist.val(); var b = hoist.hoperation.val(); if(a == "YES" && b == "") { hoist.hoperation.next().css("display", "block"); hoist.hoperation.css('color', '#b80000'); return false; } else { hoist.hoperation.next().css("display", "none"); hoist.hoperation.removeAttr('style'); return true; } } 
	function validateoah(){ ich = $('#ich'); var a = ich.val(); if(get.id == "4" && a == "") { ich.next().css("display", "block"); ich.css('color', '#b80000'); return false; } else { ich.next().css("display", "none"); ich.removeAttr('style'); return true; } } 
	function validategift(){ var a = el.gift.val(); if(a != "" && a != undefined) { el.gift.prev().removeClass("error"); 
		return true; } else { el.gift.prev().addClass("error"); return false; } }
	function validateaddress(){ if(el.address.val().length < 1) { el.address.prev().addClass("error"); return false; } else { el.address.prev().removeClass("error"); return true; } }
	function validatecity(){ if(el.city.val().length < 1) { el.city.prev().addClass("error"); return false; } else { el.city.prev().removeClass("error"); return true; } }
	function validatestate(){ if(el.state.val().length < 1) { el.state.prev().addClass("error"); return false; } else { el.state.prev().removeClass("error"); return true; } }
	function validatezip(){ if(el.zip.val().length < 1) { el.zip.prev().addClass("error"); return false; } else { el.zip.prev().removeClass("error"); return true; } }

/* Apply Default Strings */

	if(get.step == "2") { jib.capacity.html('Capacity'); }
	if(get.step == "2") { jib.span.html('Span'); } 
	if(get.step == "2") { jib.hub.html('Height Under Boom'); }
	if(get.step == "2" && get.id < 5 || get.id > 10) { jib.ch_td.html('Overall<br />Height'); }

/* Attach events to elements */

	// Validation while typing	
	el.fname.blur(validatefname);
	el.fname.keyup(validatefname);
	el.lname.blur(validatelname);
	el.lname.keyup(validatelname);
	el.email.blur(validateemail);
	el.email.keyup(validateemail);
	el.company.blur(validatecompany);
	el.company.keyup(validatecompany);
	el.gift.change(validategift);
	el.address.blur(validateaddress);
	el.address.keyup(validateaddress);
	el.city.blur(validatecity);
	el.city.keyup(validatecity);
	el.state.blur(validatestate);
	el.state.keyup(validatestate);
	el.zip.blur(validatezip);
	el.zip.keyup(validatezip);

/* Show Popup on load for step 1 and no type */

	if(get.step < 2) { $('#popup').show(); }


/* Capacity Select Element */

	el.capacity.change(function() {
		if(!validatecapacity()){  
			el.capacity.next().css("display", "block"); 
			jib.capacity.html('Capacity'); 
			el.capacity.css('color', '#b80000'); 
			if((get.id < 4) || (get.id > 10)) {
                                disableSelect(el.hub); 
                                disableSelect(el.span);
                                $('.extra').remove();
			} else {
                                disableSelect(el.span); 
			}
			return; 
		}

		el.capacity.next().css("display", "none"); 
		el.capacity.css('color', 'black'); 

		/* Url for requests to rfqprocess.php */
                get_url = ajax_url({capacity:$(this).val(),id:get.id}); 

		if($(this).val() != "") {

			/* Add text to jib.capacity */
			jib.capacity.html(addCommas($(this).val()));
			if(get.id == "4") {
				el.ch.removeAttr('disabled');
				$('#ich option').remove();
				$('#ispan option').remove();
				jib.ch_td.html("Overall <br />Height");
				prepend_func = 'el.ch.prepend(data)'; 
			} else if(get.id > 4 && get.id < 11) {
				el.span.removeAttr('disabled');
				$('#ispan option').remove();
				prepend_func = 'el.span.prepend(data)';
			} else {
				el.hub.removeAttr('disabled');
				el.span.attr('disabled', true);
			}

			if((get.id < 4 || get.id > 10)) {
				$('#ihub option').remove();
				$('#ispan option').remove();
				jib.ch_td.html("Overall <br />Height");
				prepend_func = 'el.hub.prepend(data)';
				$('.extra').remove();
                        }

			/* Make the ajax call to populate the HUB select element */
			$.get(get_url, function(data) { eval(prepend_func); });
               
	}
	});


		



		

/* Add keyup event for hub textbox when id is 5-8 */
if(get.id >4 && get.id < 11){
   el.hub.keyup(function(){
     if(el.hub.val() == "") {
     	jib.hub.html("Height Under Boom");
     } else {
        jib.hub.html(el.hub.val()+" feet"); 
	 }

   }); 

}else{


/* el.hub select element */

        el.hub.change(function(){
		if(!validatehub()){
			el.hub.next().css("display", "block"); 
			jib.hub.html('Height Under Boom'); 
			el.hub.css('color', '#b80000'); 
			disableSelect(el.span);
			$('.extra').remove();
			return;
		}
		if(get.id > 4 && get.id < 11){
			if(el.hub.val() > 1) {
				jib.hub.html(el.hub.val()+" feet");
			} else if(el.hub.val() < 1) {
				jib.hub.html("Height Under Boom");
			}
		}
		el.hub.next().css("display", "none"); 
		el.hub.css('color', 'black'); 

		this_val = $(this).val(); 
		if(this_val != ""){
			if(get.id > 4 && get.id < 11 && this_val > 1) {
				jib.hub.html(this_val+" feet");
			} else if(get.id > 4 && get.id < 11 && this_val < 1) {
				jib.hub.html("Height Under Boom");
			}
			if((get.id < 5) || (get.id > 10)) {
				jib.hub.html(this_val+" feet");
				$('#ispan option').remove();
				jib.ch_td.html("Overall <br />Height");	
				$.get(ajax_url({capacity:el.capacity.val(),hub:$(this).val(),id:get.id}), function(data) {
					el.span.prepend(data);
					/* need to use selector incase element doesn't exist */
					if(get.id == 12) { 
/*
						jib_img = $('#jibimg'); 
						jib_img.remove();
*/
						jibNum = (el.hub.val() > 14) ? 1 : 12; 
						 createTextPlacements(jibNum); 
						changeImageState({description: 'Foundationless Jib Crane', num : jibNum});    
					}
				});
			}
			$('.extra').remove();
			el.span.removeAttr('disabled');
		} 
	});
}
/* Overall Height -- Select element */
       /* Not on all models, so check if it exists */
	if($('#ich')){ 
	$('#ich').change(function() {
        if(validateoah()){
			if(get.id == "4") {
				jib.ch_td.html($(this).val()+" feet");
			} else if(get.id < 4 || get.id > 10) {
				jitem.html($(this).val()+" feet");
			}
			$.get(ajax_url({capacity:el.capacity.val(),oah:$(this).val(),id:get.id}), function(data) {
				$('#ispan option').remove();
				el.span.prepend(data);
			});
				if(el.ch.val() != "") {
					el.span.removeAttr('disabled');
				} else {
					el.span.attr('disabled', true);
				}
        }
	});	
	}

/* Span (feet) --  select element */
	el.span.change(function(){
	if(validatespan()){
	  var noteMsg = "Note: Actual dimensions and specifications may vary and are subject to engineering review.";
		if(get.id == "4") {
			$.getJSON(ajax_url({capacity:el.capacity.val(),oah:el.ch.val(),span:$(this).val(),id:get.id}), function(json) {
			$('.extra').remove();
			if(json == null){ jib.hub.html("N/A"); }else{ jib.hub.html(json.result); }
			$('#sidebar').append("<div class=\"extra\"><h3>SHIPPING WEIGHT (lbs)</h3>\n<span style=\"color: #39f;\">"+json.weight+" lbs.</span></div>\n<div class=\"extra\"><p style=\"width:175px; color: #FF5F5F;\">"+noteMsg+"</p></div>");
			});
			jib.span.html($(this).val()+" feet"); 
		} else if(get.id > 4 && get.id < 11) {
			$.getJSON(ajax_url({capacity:el.capacity.val(),span:$(this).val(),id:get.id}), function(json) {
			$('.extra').remove();
			$('#sidebar').append("<div class=\"extra\"><h3>SHIPPING WEIGHT (lbs)</h3>\n<span style=\"color: #39f;\">"+json.weight+" lbs.</span></div>\n<div class=\"extra\"><p style=\"width:175px; color: #FF5F5F;\">"+noteMsg+"</p></div>");
			});
			jib.span.html($(this).val()+" feet"); 
		} else if(get.id == 11) {
			$.getJSON(ajax_url({capacity:el.capacity.val(),hub:el.hub.val(),span:$(this).val(),id:get.id}), function(json) {
				jib.ch_td.html("Overall <br />Height");
				$('.extra').remove();
				if(json == null) { jib.ch_td.html("N/A"); }else{ jib.ch_td.html(json.result); }
				$('#sidebar').append("<div class=\"extra\"><h3>SHIPPING WEIGHT (lbs)</h3>\n<span style=\"color: #39f;\">"+json.weight+" lbs.</span></div>\n<div class=\"extra\"><p style=\"width:175px; color: #FF5F5F;\">"+noteMsg+"</p></div>");
			});
			jib.span.html($(this).val()+" feet");
		} else {
			jib.span.html($(this).val()+" feet");
			//$.get(ajax_url({capacity:el.capacity.val(),hub:el.hub.val(),span:$(this).val(),id:get.id}), function(data) {
			$.getJSON(ajax_url({capacity:el.capacity.val(),hub:el.hub.val(),span:$(this).val(),id:get.id}), function(json) {
				jib.ch_td.html("Overall <br />Height");
				$('.extra').remove();
				if(json == null) { jib.ch_td.html("N/A"); }else{ jib.ch_td.html(json.result); }
				$('#sidebar').append("<div class=\"extra\"><h3>SHIPPING WEIGHT (lbs)</h3>\n<span style=\"color: #39f;\">"+json.weight+" lbs.</span></div>\n<div class=\"extra\"><h3>FOOTER SIZE (WxLxH)</h3>\n<span style=\"color: #39f;\">"+json.footing+"</span></div>\n<div class=\"extra\"><p style=\"width:175px; color: #FF5F5F;\">"+noteMsg+"</p></div>");
			});
		}
	}
	});


/* Do you need a hoist? -- Toggle */
	hoist.selecthoist.change(function() {
		if(hoist.selecthoist.val() == "YES") {
				hoist.hoperation.removeAttr('disabled');
				changeJibImage('LH'); 
		} else {
				$('#hoperation option:eq(0)').attr("selected", "selected");
				$('#epower option:eq(0)').attr("selected", "selected");
				hoist.hoperation.attr('disabled', true); 
				hoist.epower.attr('disabled', true); 	
				changeJibImage('L'); 
		}
	});


/* Hoist Operation --- Select */
	/* Note:
	the function PowerChange(){...} was removed from being an inline event handler; its functionality was absorbed by this event handler  
	*/
	hoist.hoperation.change(function(){ 
		if($(this).val() == "Manual Operated") {
			$('#epower option:eq(0)').attr("selected", "selected");
			hoist.epower.attr('disabled',true);
			changeJibImage('LHM'); 
		} else {
		  if($(this).val() == "Electric Operated") {
			hoist.epower.removeAttr('disabled'); 
		  } else {
		  	hoist.epower.attr('disabled',true);
		  }
			changeJibImage('LH'); 
		}
	});

/* Validation Submit Functions */
	el.step2submitbottom.click(function(){
		if(validatecapacity() & validatespan() & validatehub() & validatehoist() & validateoah()) {
			el.step2form.submit();
			return true
		} else {
			$.scrollTo(180, 400, {onAfter:function() {
			  alert("Please fill out the fields marked in red");
			}});
			return false;
		}
	});
	el.step3submitbottom.click(function(){
		if(validatefname() & validatelname() & validateemail() & validatecompany()) {
			el.step3form.submit();
			return true
		} else {
			alert("Please fill out the fields marked in red");
			return false;
		}
	});
	el.incentivesubmit.click(function(){
		if(validategift() & validateaddress() & validatecity() & validatestate() & validatezip()) {
		  $.post("rfqprocess.php", el.incentiveform.serialize(), function() {
			el.incentiveform.slideUp("slow", function() {
			  el.incentiveform.after("<div id=\"thank\">Thank you, your free gift will be sent out shortly.</div>");
			  $('#thank').slideDown("fast");
			  $('#thank').fadeOut(3000);
			});
		  });
		  return true
		} else {
		  var msg = "Please fill out the fields marked in red";
		  alert(msg);
		  return false;
		}
	});

	// Products show when specifying a type in url
	var i=0;
	var j=0;

	if(get.type == "1") {
	  $('.product:eq(0)').show("fast", function() {
	  if(i<3) {
		i++;
		$(this).next().show("fast", arguments.callee);
	  }
	  $('.product:eq(10)').show("fast", function() {
			  if(j<1) {
				j++;
				$(this).next().show("fast", arguments.callee);
			  }
			  });
	  });
	} else if(get.type == "2") {
	  $('.product:eq(4)').show("fast", function() {
	  if(i<5) {
		i++;
		$(this).next().show("fast", arguments.callee);
	  }
	  });
	}

	// Function for keyup text placement
	function textPlacement(args) {
               for(n = 0; n < args.length; n++){
	        jitem = eval('jib.'+args[n][2]);  
		jitem.css({top: (args[n][0]+'px'), left: (args[n][1]+'px')}); 
               }
	}
	// Highlight Functions
	function highlight(width, height, top, left, img, item) {	
                var item =  item; 
                var iwidth = width+'px';
                var iheight = height+'px';
                var itop = top+'px';
                var ileft = left+'px';
                var iimage = gbl.imgDir+'/'+img;  
                var hitem = eval('el.'+item); 

		hitem.hover(function() {

			/* hitem:over */
			$(".highlight").remove();
			if(item == "capacity") {
				jib.jib.append("<div class='highlight'></div>");
				$('.highlight').css({ backgroundImage: 'url('+iimage+')', width: iwidth, height: iheight, top: itop, left: ileft });
			} else {
				jib.jib.append("<div class='highlight'><div></div><span></span></div>");
				$('.highlight').css({ width: iwidth, height: iheight, top: itop, left: ileft });
				$('.highlight div').css({ width: iwidth, height: iheight });
				$('.highlight span').css({ width: iwidth, height: iheight, backgroundImage: 'url('+iimage+')' });
			}
			if(isIE6) {
				var i = $($(this).attr('alt').val());
				alert(i);
			} else {
				var i = $(this).attr("alt");
			}
			$('#'+i+'').css("display", "none");
			}, 

			/* hitem:out */
			function() {
				var i = $(this).attr("id").substring(1);
				$('div.highlight').remove();
				$('#'+i+'').css("display", "block");
			}); 
		// End hover function
	} // End highlight function

function createTextPlacements(id){
        /*  Make sure the id is a string and can be compared properly */
	id = id.toString();
 
	// Text Placement Declarations
	switch (id) {
	  case "1":
	/* Free Standing Jib Crane */
		highlight(96,97,335,374, 'highlight_capacity.png', 'capacity');
		highlight(325,27,16,137, 'highlight_span.png', 'span');
		highlight(27,318,103,278, 'highlight_hub.png', 'hub');
		textPlacement([[397,321,'capacity'],[23,200,'span'],[257,192,'hub'],[183,-39,'ch']]);
		break;
	  case "2":
	/* Free standing work station jib crane */
	    highlight(96,97,335,373, 'highlight_capacity.png', 'capacity');
		highlight(336,27,15,125, 'highlight_span.png', 'span');
		highlight(27,331,92,271, 'highlight_hub.png', 'hub');
		textPlacement([[397,321,'capacity'],[22,193,'span'],[251,186,'hub'],[176,-39,'ch']]);
		break;
	  case "3":
	/* Free standing articulating Jib Crane */
	    highlight(96,97,335,373, 'highlight_capacity.png', 'capacity');
		highlight(280,27,20,129, 'highlight_span.png', 'span');
		highlight(27,318,105,320, 'highlight_hub.png', 'hub');
		textPlacement([[397,321,'capacity'],[26,170,'span'],[251,233,'hub'],[184,-39,'ch']]);
		break;
	  case "4":
		highlight(96,97,335,373, 'highlight_capacity.png', 'capacity');
		highlight(336,27,205,124, 'highlight_span.png', 'span');
		highlight(27,339,84,195, 'highlight_hub.png', 'hub');
		highlight(27,403,18,46, 'highlight_ch.png', 'ch');
		textPlacement([[397,321,'capacity'],[211,199,'span'],[247,111,'hub'],[167,-39,'ch']]);
		break;
	  case "5":
		highlight(96,97,335,373, 'highlight_capacity.png', 'capacity');
		highlight(406,27,16,35, 'highlight_span.png', 'span');
		highlight(27,204,216,135, 'highlight_hub.png', 'hub');
		textPlacement([[397,321,'capacity'],[22,139,'span'],[310,49,'hub']]),
		jib.ch.remove();
		break;
	  case "6":
		highlight(96,97,335,373, 'highlight_capacity.png', 'capacity');
		highlight(431,27,27,21, 'highlight_span.png', 'span');
		highlight(27,252,169,135, 'highlight_hub.png', 'hub');
		textPlacement([[397,321,'capacity'],[34,138,'span'],[288,50,'hub']]);
		jib.ch.remove();
		break;
	  case "7":
		highlight(96,97,335,373, 'highlight_capacity.png', 'capacity');
		highlight(358,27,25,33, 'highlight_span.png', 'span');
		highlight(27,300,121,210, 'highlight_hub.png', 'hub');
		textPlacement([[397,321,'capacity'],[31,112,'span'],[264,124,'hub']]);
		break;
	  case "8":
		highlight(96,97,335,373, 'highlight_capacity.png', 'capacity');
		highlight(392,27,24,22, 'highlight_span.png', 'span');
		highlight(27,304,117,212, 'highlight_hub.png', 'hub');
		textPlacement([[397,321,'capacity'],[30,122,'span'],[262,127,'hub']]);
		break;
	  case "9":
		highlight(96,97,335,373, 'highlight_capacity.png', 'capacity');
		highlight(333,27,24,26, 'highlight_span.png', 'span');
		highlight(27,298,121,253, 'highlight_hub.png', 'hub');
		textPlacement([[397,321,'capacity'],[30,94,'span'],[262,166,'hub']]);
		break;
	  case "10":
		highlight(96,97,335,373, 'highlight_capacity.png', 'capacity');
		highlight(297,27,20,82, 'highlight_span.png', 'span');
		highlight(27,309,110,280, 'highlight_hub.png', 'hub');
		textPlacement([[397,321,'capacity'],[27,130,'span'],[257,194,'hub']]);
		break;
	  case "11":
		highlight(96,97,335,374, 'highlight_capacity.png', 'capacity');
		highlight(286,27,14,176, 'highlight_span.png', 'span');
		highlight(27,315,104,329, 'highlight_hub.png', 'hub');
		highlight(27,403,18,46, 'highlight_ch.png', 'ch');
		textPlacement([[397,321,'capacity'],[22,218,'span'],[253,243,'hub'],[179,-39,'ch']]);
		break;
	  case "12":
                highlight(96,97,335,373, 'highlight_capacity.png', 'capacity');
		highlight(336,27,15,125, 'highlight_span.png', 'span');
		highlight(27,331,92,271, 'highlight_hub.png', 'hub');
		textPlacement([[397,321,'capacity'],[22,193,'span'],[251,186,'hub'],[176,-39,'ch']]);	
		break;

	}
}

	// Mount Hover for IE6
	$('#popup span img').hover(function() {
		$(this).addClass("hover");
	}, function() {
		$(this).removeClass("hover");
	});

	// Popup Click Functions
	$('#popup span img').click(function() {
		$('#popup span img').removeClass("select");
		$(this).addClass("select");
		$('.product').css("display", "none");
		var i=0;
		var j=0;
		
		var url = window.location;
		var string = String(url);
		var id = string.search(/id=/);
		
		if(id == -1) {
			if($(this).attr("title") == "fm") {
			  $('.product:eq(0)').show("fast", function() {
			  if(i<3) {
				i++;
				$(this).next().show("fast", arguments.callee);
			  }
			  $('.product:eq(10)').show("fast", function() {
			  if(j<1) {
				j++;
				$(this).next().show("fast", arguments.callee);
			  }
			  });
			  });
			} else if($(this).attr("title") == "wm") {
			  $('.product:eq(4)').show("fast", function() {
			  if(i<5) {
				i++;
				$(this).next().show("fast", arguments.callee);
			  }
			  });
			}
		} else {
			if($(this).attr("title") == "fm") {
				document.location = "rfq.php?type=1";
			} else if($(this).attr("title") == "wm") {
				document.location = "rfq.php?type=2";
			}
		}
		
		$('#popup').fadeOut("slow");
		var mtype = $(this).prev("h3").html();
		$('#mount span').text(mtype);
		$('#type').remove();
		$('#step1').prepend("<input id=\"type\" name=\"00N70000002N5vp\" type=\"hidden\" value=\""+mtype+"\" />");
	});

	// Popup Toggle
	$('#mount span').click(function() {
		var url = window.location;
		var string = String(url);
		var id = string.search(/id=/);
		$('#popup').toggle();	
	});

	// Product Hover for IE6
	$('.product').hover(function() {
		$(this).addClass("hover");
	}, function() {
		$(this).removeClass("hover");
	});

	// Thank you text Hover
	$('#panel').hover(function() {
		$('#panel p').css('color', '#333');
	}, function() {
		$('#panel p').css('color', '#898989');
	});

	// Product Click Functions
	$('.product').click(function() {
		var str = $(this).children('img').attr("src");
		var str2 = str.replace(/.png/, "");
		var id = str2.replace(/img\/rfq\/jib/, "");
		$('#step1').attr("action", "rfq.php?id="+id+"&step=2");
		$('.product').removeClass("select");
		$(this).addClass("select");
		var pvalue = $(this).children('h2').html();
		$("#model").remove();
		$('#step1').prepend("<input id=\"model\" name=\"00N70000002N5wE\" type=\"hidden\" value=\""+pvalue+"\" />");
		$('#step1').submit();
	});

	// Previous Page Button
	$('.btn_previous').click(function() {
		var url = window.location;
		var string = String(url);
		var id = string.search(/id=/);
		var step2 = string.search(/step=2/);
		var step3 = string.search(/step=3/);
		var sstring = string.substring(id+3, step3-1);
		
		if(step2 != -1) {
			window.location = "rfq.php";
		} else if(step3 != -1) {
		  if(id != -1) {
		    window.location = "rfq.php?id="+get.id+"&step=2";
		  } else {
			window.location = "rfq.php?step=2";
		  }
		}
	});
}); // End jquery


$(document).ready(function() {
  $('#gift').click(function() {
    if(document.getElementById('gift').checked == true) {
		$('#step3').prepend("<input name=\"00N70000002NL3B\" id=\"inc\" type=\"hidden\" value=\"Yes\" />");
	} else if(document.getElementById('gift').checked == false) {
		$('#inc').remove();
	};
  });
});