$(document).ready(function() {
      // put all your jQuery goodness in here.
});


function printComplete(){
	window.open("?mode=print",'mywindow','width=400,height=200,toolbar=yes,location=yes,directories=yes,status=yes,menubar=yes,scrollbars=yes,copyhistory=yes,resizable=yes');
}
function loadContent(step){
	$.ajax({
			type: "POST",
			url: "ajax.php",
			data: "get="+step,
			success: function(content){
				$('#mainpanel1').fadeOut('fast',function(){
					$('#mainpanel1').html(content).fadeIn('fast');
				});
				_gaq.push(['_trackPageview', "/price-your-steel-building/"+step+".html"]);
			}
		});
		switch(step){
			case 'step1':
				document.title = 'Armstrong Steel Buildings - Let\'s Begin!';
				break;
			case 'step2':
				document.title = 'Armstrong Steel Buildings - Your Location';	
				break;
			case 'step3':
				document.title = 'Armstrong Steel Buildings - Building Dimensions';
				break;		
			case 'step4':
				document.title = 'Armstrong Steel Buildings - Doors & Windows';
				break;		
			case 'step5':
				document.title = 'Armstrong Steel Buildings - Accessories';
				break;		
			case 'step6':
				document.title = 'Armstrong Steel Buildings - Choose Color';
				break;	
			case 'step7':
				document.title = 'Armstrong Steel Buildings - Building Completed';
				break;	
			default:		
				document.title = 'Armstrong Steel Buildings - BUILDING COMPLETED';
		}	
	$('html,body').scrollTop(0);	
	randpicture = Math.floor(Math.random()*(parseInt(pictures.length)-1));
	if (randpicture == 0) randpicture = randpicture+1;
	$('#rightpanel').html('<img src="images/random/'+pictures[randpicture]+'">'); 
}

function getCountry(form){
	$.ajax({
		type: "POST",
		url: "ajax.php",
		data: "get=countries&code="+$(form).val(),
		success: function(content){
			$('#country').html(content);
			$('#country').attr('disabled',false);
		}
	});
}



function addDoorAjax(key,val){
	var doorwidth = $('#doorwidth').val();
	var doorheight = $('#doorheight').val();
	var doorelectric = $('#doorelectric').val();
	var doorquantity = $('#doorquantity').val();

	$.ajax({
		type: "POST",
		url: "ajax.php",
		data: "set=doors&key="+key+"&val="+val+"&doorwidth="+doorwidth+"&doorheight="+doorheight+"&doorelectric="+doorelectric+"&doorquantity="+doorquantity,
		success: function(content){
			html_result = "<tr style='background-color:#ff0000;'><td>" + doorquantity + "</td><td>"+doorwidth+"</td><td>"+doorheight+"</td><td>"+doorelectric+"</td><td>"+val+"</td><td><span onclick='removeDoorAjax(\""+doorquantity+"\",\""+doorwidth+"\",\""+doorheight+"\",\""+doorelectric+"\",\""+key+"\",this);' style='floar:right;cursor:pointer;'><img src='images/del.gif' border='0' alt=''/></span></td></tr>";
			if ($('#emptyRow')) {
				$('#emptyRow').remove();
			} 
			$('#doorAdded').children(':first').children(':first').after(html_result);
			$('#doorAdded').children(':first').children(':first').next().animate({ backgroundColor: "#EEEE00" }, 800);
			
		}
	});
	
}

function removeDoorAjax(doorwidth,doorheight,doorelectric,doorquantity,key,toRem){
	$.ajax({
		type: "POST",
		url: "ajax.php",
		data: "remove=doors&key="+key+"&doorwidth="+doorwidth+"&doorheight="+doorheight+"&doorelectric="+doorelectric+"&doorquantity="+doorquantity,
		success: function(content){
			$(toRem).parent().parent().fadeOut('normal',function(){
				$(this).remove();
			});
		}
	});
}

function addWindowAjax(key,val){
	var windowwidth = $('#windowwidth').val();
	var windowheight = $('#windowheight').val();
	var windowquantity = $('#windowquantity').val();

	$.ajax({
		type: "POST",
		url: "ajax.php",
		data: "set=windows&key="+key+"&val="+val+"&windowwidth="+windowwidth+"&windowheight="+windowheight+"&windowquantity="+windowquantity,
		success: function(content){
			html_result = "<tr style='background-color:#ff0000;'><td>" + windowquantity + "</td><td>"+windowwidth+"</td><td>"+ windowheight +"</td><td>"+val+"</td><td><span onclick='removeWindowAjax(\""+windowwidth+"\",\""+windowheight+"\",\""+windowquantity+"\",\""+key+"\",this);' style='floar:right;cursor:pointer;' ><img src='images/del.gif' border='0' alt='' /></span></td></tr>";
			if ($('#emptyRowWindow')) {
				$('#emptyRowWindow').remove();
			} 
			$('#windowsAdded').children(':first').children(':first').after(html_result);
			$('#windowsAdded').children(':first').children(':first').next().animate({ backgroundColor: "#EEEE00" }, 800);
			
		}
	});
}

function removeWindowAjax(windowwidth,windowheight,windowquantity,key,toRem){
	$.ajax({
		type: "POST",
		url: "ajax.php",
		data: "remove=windows&key="+key+"&windowwidth="+windowwidth+"&windowheight="+windowheight+"&windowquantity="+windowquantity,
		success: function(content){
			$(toRem).parent().parent().fadeOut('normal',function(){
				$(this).remove();
			});
		}
	});
}


function saveStep2(){
	var country  = $("#country").val();
	var state 	 =  $("#state").val();
	var postcode = $("#postcode").val();
	var source = $("#source").val();
	var medium = $("#medium").val();
	var term = $("#term").val();
	var content = $("#content").val();
	var campaign = $("#campaign").val();
	var csegment = $("#csegment").val();
	var nvisits = $("#nvisits").val();
	$.ajax({
		type: "POST",
		url: "ajax.php",
		data: "saving=values&county=" + country + "&state="+ state +"&postcode="+ postcode + "&source=" + source + "&medium=" + medium + "&term=" + term + "&content=" + content + "&campaign=" + campaign + "&csegment=" + csegment + "&nvisits=" + nvisits,
		success: function(){
			return;
		}
	});
}

function saveStep3(){
	var width  = $('#width').val();
	var length = $('#length').val();
	var height = $('#height').val();
	var pitch  = $('#pitch').val();
	
	$.ajax({
		type: "POST",
		url: "ajax.php",
		data: "saving=values&width=" + width + "&length="+ length+ "&height="+ height+ "&pitch="+ pitch,
		success: function(){
			return;
		}
	});
}

function saveStep5(){
	var vent1 = $('#vent1').val(); 
	var vent2 = $('#vent2').val(); 
	var vent3 = $('#vent3').val(); 
	var insroof = $('#insroof').val(); 
	var inswalls = $('#inswalls').val(); 
	var gutt = $('#gutt').val(); 
	var walkdoors1 = $('#walkdoors1').val(); 
	var walkdoors2 = $('#walkdoors2').val(); 
	var skylights = $('#skylights').val(); 
	
	$.ajax({
		type: "POST",
		url: "ajax.php",
		data: "saving=values&vent1=" + vent1 + "&vent2="+ vent2+ "&vent3="+ vent3+ "&insroof="+ insroof +"&inswalls="+inswalls+"&gutt="+gutt+"&walkdoors1="+walkdoors1+"&walkdoors2="+walkdoors2+"&skylights="+skylights,
		success: function(){
			return;
		}
	});
	
}

function menuMove(){
	$('#leftmenu').children('.active').unbind('click');
	$('#leftmenu').children('.active').bind('click',function(){
		loadContent($(this).attr('id'));
		makeActiveMenu($(this).attr('id'));		
	});
	
	$('#leftmenu').children('.active').children('div').children('i').text('Status: Complete');
	$('#leftmenu').children('.active').attr('class','completed').next().attr('class','active');
	$('#leftmenu').children('.active').children('div').children('i').text('Status: Current');
}

function makeActiveMenu(button){

	$('.active').children('div').children('i').text('Status: Complete');
	$('.active').unbind('click');
	$('.active').attr('class', 'completed').bind('click',function(){
		loadContent($(this).attr('id'));
		makeActiveMenu($(this).attr('id'));
	});
	$('#'+button).attr('class','active');
	$('.active').children('div').children('i').text('Status: Current');
}

function loadContentStep7(){
	var first_name = $('#first_name').val();
	var last_name = $('#last_name').val();
	var phone = $('#phone').val();
	var email = $('#email').val();
	var wantsEmail = $('#wantsEmail').is(':checked');
	$.ajax({
		type: "POST",
		url: "ajax.php",
		data: "saving=values&first_name=" + first_name + "&last_name="+ last_name+ "&phone="+ phone+ "&email="+ email +"&wantsEmail="+ wantsEmail,
		success: function(){
			loadContent('step8');
			//$('#mainpanel1').css('height','680px');
		}
	});
}
function checkThis(e,b){
	var allowed =  (e.which != 8 && e.which != 0 && (e.which < 48 || e.which > 57) && (e.which<96 || e.which>106)) ? false : true;
	var len = $(b).val().length;
	
	if (allowed){
		if (len>5){
			$(b).val($(b).val().substr(0,5));
		}
	}else{
		$(b).val($(b).val().substr(0,(parseInt($(b).val().length) - 1)));
	}
	
}

function enableStep7(){
	$('#step7').bind('click',function(){
		loadContent($(this).attr('id'));
		makeActiveMenu($(this).attr('id'));
	});
	
	$('#step7').css('cursor','pointer');
}

