var twitterID;
var preview;
var preview_url;
var current_offer = 1;
var current_product_image = 0;
var num_of_product_images;
var offer_id;

$(function(){

    $('.offer3.heroOfferImageTAG').click(function() {
        showOfferPopup(3);
    })

	/* ==========SEARCH BOX========== */
	$('.searchBox').click(function(){
	  $(this).val('');
	  $(".searchBox").css( { border:"1px solid #ddd" } );
	}); //CLEAR ON CLICK

	  $(".searchBox").keyup(function(event){
      if(event.keyCode == 13){
        showSearchResults();
      }
    });

	$('body, #container').click(function(){ $("#resultsList").hide(); }); //CLEAR ON CLICK

	/* ==========HOMEPAGE CAROUSEL========== */
	$(".default .jCarouselLite").jCarouselLite({
		btnNext: ".default #next",
		btnPrev: ".default #prev",
		speed: 200,
		auto:0
	});

	/* ==========DROP DOWN FUNCTIONALITY========== */
	$(".navTabFill, .dropdown").mouseover(function(){

	    //$(this).find('.navTitle').css( { color:"#5474b9" } );
		$(this).find(".dropdown").show();

	});

	$(".navTabFill").mouseout(function(){

		//$(this).find('.navTitle').css( { color:"#9E9E9E" } );
		$('.dropdown').hide();

	});

	$(".dropdown").mouseout(function(){

		$('.dropdownPreview .preview').attr("src", "img/previews/preview_black.jpg");
	});

	$(".navTitle").mouseover(function(){
		 if ($(this).text() == "Our Products"){
			 $('.dropdownPreview .preview').attr("src", "img/previews/doors.jpg");
		 }
		 else if ($(this).text() == "Why Warmseal?"){
			 $('.dropdownPreview .preview').attr("src", "img/previews/latestnews.jpg");
		 }
	});

	$(".dropdownTable a").mouseover(function(){

		preview = $(this).text().replace(/ /g,'');
        preview = preview.toLowerCase();

		preview_url = $(this).attr("href");
		//alert(preview_url);

		$('.dropdownPreview .preview').attr("src", "img/previews/"+preview+".jpg");
		$('.previewURL').attr("href", preview_url);

		var link_num = $(this).attr("class");
		$('.bullet'+link_num).css( { "background":"#ff9900" } );
		//$('.dropdown').hide();
	});



	$(".dropdownTable a").mouseout(function(){

		var link_num = $(this).attr("class");
		$('.bullet'+link_num).css( { "background":"#666" } );
		//$('.dropdown').hide();
	});

    /* ==========SIGNPOST HOVER EFFECT========== */
	$('#signpostRow .slide1, #signpostRow .slide2, #signpostRow .slide3').hover(
	  //function () {	$(this).fadeTo(200, 1); },
	 // function () {	$(this).fadeTo(200, 0.85); }
	);

	$('.submitButton').hover(
	  function () {	$(this).fadeTo(200, 1); },
	  function () {	$(this).fadeTo(200, 0.75); }
	);

	/*==========DRAG TO SHARE CODE (DC TOOL v1)==========*/
	$(".draggableBlock").draggable({

		"zIndex":40000,
		cursorAt: { cursor:"pointer", top:-5, left:-5 },
		revert: true,
		opacity:0.4,
		helper: "clone",
		handle:$(".handle"),
	    start: function(event, ui) {

		var title = $(this).closest("a").attr("title");

		// if the above title var is undefined (it will be on the homepage) fallback on the current element's title attribute
		if (title === undefined){
		var title = $(this).attr("title");
		}
		var img_src = $(this).attr("src");
		$(".ogImage").attr("content",img_src);
		var shareSummary = $(this).html();
		var splitResult = title.split("|");

		$(".shareName").html(splitResult[0]);
		$(".shareURL").html(splitResult[1]);
		$(".shareTitle").html(($(this)).attr("title"));

		$(".metaTitle").attr("content",splitResult[0]);

		$('#socialShare').fadeIn(750); },

		stop: function(event, ui) { $('#socialShare').slideUp(500); $.unblockUI(); }

	});

				//test mouseover functionality
				$("#Twitter").mouseover(function(){ $(this).attr("src",ROOT_PATH+"img/drag_to_share_twitter_hover.png"); });
				$("#Twitter").mouseout(function(){ $(this).attr("src",ROOT_PATH+"img/drag_to_share_twitter.png"); });
				//test mouseover functionality
				$("#LinkedIn").mouseover(function(){ $(this).attr("src",ROOT_PATH+"img/drag_to_share_linkedin_hover.png");});
				$("#LinkedIn").mouseout(function(){ $(this).attr("src",ROOT_PATH+"img/drag_to_share_linkedin.png");	});
				//test mouseover functionality
				$("#Facebook").mouseover(function(){ $(this).attr("src",ROOT_PATH+"img/drag_to_share_facebook_hover.png"); });
				$("#Facebook").mouseout(function(){ $(this).attr("src",ROOT_PATH+"img/drag_to_share_facebook.png");	});
				//test mouseover functionality
				$("#Digg").mouseover(function(){ $(this).attr("src",ROOT_PATH+"img/drag_to_share_digg_hover.png"); });
				$("#Digg").mouseout(function(){ $(this).attr("src",ROOT_PATH+"img/drag_to_share_digg.png");	});
				//test mouseover functionality
				$("#Google").mouseover(function(){ $(this).attr("src",ROOT_PATH+"img/drag_to_share_google_hover.png"); });
				$("#Google").mouseout(function(){ $(this).attr("src",ROOT_PATH+"img/drag_to_share_google.png");	});
				//test mouseover functionality
				$("#StumbleUpon").mouseover(function(){ $(this).attr("src",ROOT_PATH+"img/drag_to_share_stumbleupon_hover.png"); });
				$("#StumbleUpon").mouseout(function(){ $(this).attr("src",ROOT_PATH+"img/drag_to_share_stumbleupon.png"); });
				//test mouseover functionality
				$("#Email").mouseover(function(){ $(this).attr("src",ROOT_PATH+"img/drag_to_share_email_hover.png"); });
				$("#Email").mouseout(function(){ $(this).attr("src",ROOT_PATH+"img/drag_to_share_email.png"); });


				/*==========DROPPABLE FUNCTIONALITY========== */
				$(".droppable").droppable({
		  	      tolerance: "pointer",
				  over: function() {	var id = $(this).attr("id");
									    var staticSRC = $(this).attr("src");

									   //store droppable ID. Used in next drop function.
										$(".droppableHover").html(id); },
				  drop: function() {	id = $(".droppableHover").html();
												      var shareTitle = $(".shareName").html();
												      var url = $(".shareURL").html();

															//When a user drops the draggable onto an icon direct user to respective site
												      if (id == "Facebook") {	window.location.href = "http://www.facebook.com/sharer.php?u="+url+"&t="+shareTitle+"";	}
												      else if (id == "Twitter") {	window.location.href = "http://twitter.com/home?status="+shareTitle+" "+url+"";	}
												      else if (id == "LinkedIn") { window.location.href = "http://www.linkedin.com/shareArticle?mini=true&url="+url+"&title="+shareTitle+""; }
												      else if (id == "Digg") { window.location.href = "http://digg.com/submit?phase=2&url="+url+"&title="+shareTitle+"";	}
												      else if (id == "Google") { window.location.href = "http://www.google.com/bookmarks/mark?op=edit&bkmk="+url+"&title="+shareTitle+"&annotation="+shareTitle+""; }
												      else if (id == "StumbleUpon") { window.location.href = "http://www.stumbleupon.com/submit?url="+url+"&title="+shareTitle+"";	}
															else if (id == "Email") {

																window.location.href = "mailto:?subject="+shareTitle+"&body=Link: "+url+"";
																//$("#emailPopup").show();
																//$("#emailPopup .defaultMessage").text("Check out this page... "+url);
																//window.location.href = "mailto:?subject=Check out the Drummond Central website!&body=I have just came across this fantasic website: "+ROOT_PATH+"";
															}

						               },
					out: function()  {	$(".droppable").removeClass("ui-state-highlight");
								              $(".droppableHover").css({"display":"none"});
													 }
				});

				$('.offerSubmitButton').click(function(){ processOfferForm(); });
				$('.submitButton').click(function(){ processQuoteForm(); });

});

var auto;

function nextOffer(auto){
	//alert('right');
	//alert($('#heroContent img').size());

	if (auto == 0){
	  heroFadeInSpeed = 0;
	}
	else{
	  heroFadeInSpeed = 1000;
	}

	if (current_offer >= 3){

		if (current_offer == 3) {
			  $(".buttonMore").removeAttr("onclick");
     $('.buttonMore').click(function() { showOfferPopup(1); });

		}
	    current_offer = 1;
	    $('.heroOfferImageTAG').hide(); $('.headerText1,.headerText2,.headerText3,.headerText4,.headerText5,.headerText6').hide(); $('.subText1,.subText2,.subText3,.subText4,.subText5,.subText6').hide();
		$('.offer'+current_offer).fadeIn(heroFadeInSpeed);
		$('.headerText'+current_offer).fadeIn(heroFadeInSpeed);
		$('.subText'+current_offer).fadeIn(heroFadeInSpeed);
		$('.paginatorBlock1').css( { background:"#999" } );
		$('.square'+current_offer).css( { background:"#ff9900" } ); // change square colour



	}
	else{
		current_offer += 1;
	    $('.heroOfferImageTAG').hide(); $('.headerText1,.headerText2,.headerText3,.headerText4,.headerText5,.headerText6').hide(); $('.subText1,.subText2,.subText3,.subText4,.subText5,.subText6').hide();
		$('.offer'+current_offer).fadeIn(heroFadeInSpeed);
		$('.headerText'+current_offer).fadeIn(heroFadeInSpeed);
		$('.subText'+current_offer).fadeIn(heroFadeInSpeed);
		$('.paginatorBlock1').css( { background:"#999" } );
		$('.square'+current_offer).css( { background:"#ff9900" } ); // change square colour

		$(".buttonMore").removeAttr("onclick");
        $('.buttonMore').click(function() { showOfferPopup(current_offer); });
	}

	clearTimeout(heroOfferInterval);
	heroOfferInterval = setInterval("nextOffer(1)",6000);
}

var heroOfferInterval = setInterval("nextOffer(1)",6000);
var heroFadeInSpeed = 1000;

function previousOffer(auto){
	//alert(current_offer);

	if (auto == 0){
	  heroFadeInSpeed = 0;
	}
	else{
	  heroFadeInSpeed = 1000;
	}

	if (current_offer <= 1){
	    current_offer = 3;
	    $('.heroOfferImageTAG').hide(); $('.headerText1,.headerText2,.headerText3,.headerText4,.headerText5,.headerText6').hide(); $('.subText1,.subText2,.subText3,.subText4,.subText5,.subText6').hide();
		$('.offer'+current_offer).fadeIn(heroFadeInSpeed);
		$('.headerText'+current_offer).fadeIn(heroFadeInSpeed);
		$('.subText'+current_offer).fadeIn(heroFadeInSpeed);
		$('.paginatorBlock1').css( { background:"#999" } );
		$('.square'+current_offer).css( { background:"#ff9900" } ); // change square colour
	}
	else{
		current_offer -= 1;
	    $('.heroOfferImageTAG').hide(); $('.headerText1,.headerText2,.headerText3,.headerText4,.headerText5,.headerText6').hide(); $('.subText1,.subText2,.subText3,.subText4,.subText5,.subText6').hide();
		$('.offer'+current_offer).fadeIn(heroFadeInSpeed);
		$('.headerText'+current_offer).fadeIn(heroFadeInSpeed);
		$('.subText'+current_offer).fadeIn(heroFadeInSpeed);
		$('.paginatorBlock1').css( { background:"#999" } );
		$('.square'+current_offer).css( { background:"#ff9900" } ); // change square colour
	}

	clearTimeout(heroOfferInterval);
	heroOfferInterval = setInterval("nextOffer()",6000);
}

function showHeroOffer(offer_id){

	current_offer = offer_id;
	$('.heroOfferImageTAG').hide(); $('.headerText1,.headerText2,.headerText3,.headerText4,.headerText5,.headerText6').hide(); $('.subText1,.subText2,.subText3,.subText4,.subText5,.subText6').hide();
	$('.offer'+current_offer).show();
	$('.headerText'+current_offer).show();
	$('.subText'+current_offer).show();
	$('.paginatorBlock1').css( { background:"#999" } );
	$('.square'+current_offer).css( { background:"#ff9900" } ); // change square colour

	$(".buttonMore").removeAttr("onclick");
    $('.buttonMore').click(function() { showOfferPopup(current_offer); });


	clearTimeout(heroOfferInterval);
	//heroOfferInterval = setInterval("nextOffer()",6000);
}

/*==================== PRODUCT PAGE - LEFT/RIGHT ARROW FUNCTIONS ====================*/
function nextProductImage(){

	num_of_product_images = $('.productImageContainer img').size();
	num_of_product_images = num_of_product_images - 1;

	if (current_product_image >= num_of_product_images){

		current_product_image = 0;
		$('.productImageContainer img').hide();
		$('.productImageContainer img').eq(current_product_image).show();
	}
	else{
		current_product_image += 1;
		$('.productImageContainer img').hide();
		$('.productImageContainer img').eq(current_product_image).show();
	}

	clearInterval(productInterval);
	productInterval = setInterval("nextProductImage()",5000);

}

var productInterval = setInterval("nextProductImage()",5000);

function previousProductImage(){


	num_of_product_images = $('.productImageContainer img').size();
	num_of_product_images = num_of_product_images - 1;
	//alert(num_of_product_images);
	if (current_product_image <= 0){

		current_product_image = num_of_product_images;
		$('.productImageContainer img').hide();
		$('.productImageContainer img').eq(current_product_image).show();
	}
	else{
		current_product_image -= 1;
		$('.productImageContainer img').hide();
		$('.productImageContainer img').eq(current_product_image).show();
	}
}

//==================== OFFER POPUP PROCESSING ====================//
var offer_popup_id;
var openingColorbox = false;
function showOfferPopup(offer_popup_id){
  $(".offerFormError").hide();
  if (offer_popup_id == 1){ $.blockUI( { message: "<h2>Terms and Conditions</h2>Not to be used in conjunction with any other offer.<br/><br/><button class='bookAppointmentButton' style='border:0;background:url(img/book_appointment.png) no-repeat;width:163px;height:29px' onclick='window.location=\"contactus.php\"'></button><button style='top:0px;right:0px' class='quoteFormCloseButton' onclick='closePopup()'></button>", css: { width:"436px", background:"#e6e6e6", border:"5px solid #fff", "margin-left":"0px" } } ); }
  else if(offer_popup_id == 2)  {	$.blockUI( { message: "<h2>Terms and Conditions</h2>Not to be used in conjunction with any other offer.<br/><br/><button class='bookAppointmentButton' style='border:0;background:url(img/book_appointment.png) no-repeat;width:163px;height:29px' onclick='window.location=\"contactus.php\"'></button><button style='top:0px;right:0px' class='quoteFormCloseButton' onclick='closePopup()'></button>", css: { width:"436px", background:"#e6e6e6", border:"5px solid #fff", "margin-left":"0px" } } );	}
  else if(offer_popup_id == 3)  {
      if (!openingColorbox) {
          openingColorbox = true;
          $('#survey').colorbox({
              href: '/survey.php',
              open: true,
              iframe: true,
              overlayClose: false,
              escKey: false,
              fixed: true,
              close: false,
              width: '700px',
              height: '450px',
              onClosed: function() {
                  openingColorbox = false;
              }
          });
      }
  }
  else if(offer_popup_id == 4)  {	$.blockUI( { message: "<h2>Terms and Conditions</h2>Not to be used in conjunction with any other offer.<br/><br/><button class='bookAppointmentButton' style='border:0;background:url(img/book_appointment.png) no-repeat;width:163px;height:29px' onclick='window.location=\"contactus.php\"'></button><button style='top:0px;right:0px' class='quoteFormCloseButton' onclick='closePopup()'></button>", css: { width:"436px", background:"#e6e6e6", border:"5px solid #fff", "margin-left":"0px" } } );	}
  else if(offer_popup_id == 5)  {	$.blockUI( { message: "<h2>Terms and Conditions</h2>Not to be used in conjunction with any other offer.<br/><br/><button class='bookAppointmentButton' style='border:0;background:url(img/book_appointment.png) no-repeat;width:163px;height:29px' onclick='window.location=\"contactus.php\"'></button><button style='top:0px;right:0px' class='quoteFormCloseButton' onclick='closePopup()'></button>", css: { width:"436px", background:"#e6e6e6", border:"5px solid #fff", "margin-left":"0px" } } );	}
  else if(offer_popup_id == 6)  {	$.blockUI( { message: "<h2>Terms and Conditions</h2>Not to be used in conjunction with any other offer.<br/><br/><button class='bookAppointmentButton' style='border:0;background:url(img/book_appointment.png) no-repeat;width:163px;height:29px' onclick='window.location=\"contactus.php\"'></button><button style='top:0px;right:0px' class='quoteFormCloseButton' onclick='closePopup()'></button>", css: { width:"436px", background:"#e6e6e6", border:"5px solid #fff", "margin-left":"0px" } } );	}

}

function show_survey()
{
		$('#survey').colorbox({
				href: '/survey.php',
				open: true,
				iframe: true,
				overlayClose: false,
				escKey: false,
				fixed: true,
				close: false,
				width: '700px',
				height: '450px',
				onClosed: function() {
						openingColorbox = false;
				}
		});
}
//==================== OFFER POPUP PROCESSING END ====================//

function processOfferForm(){

  var validated = 1;
  var error_string = "";
  var quoteform_name = $('.offerform_name').eq(0).val();
  var quoteform_email = $('.offerform_email').val();
  var quoteform_tel = $('.offerform_tel').val();
  var quoteform_housenumber = $('.offerform_housenumber').val();
  var quoteform_postcode = $('.offerform_postcode').val();

  if (quoteform_name == "" || quoteform_email == "" || quoteform_tel == "" || quoteform_housenumber == "" || quoteform_postcode == ""){
    //alert(quoteform_name+quoteform_email+quoteform_tel+quoteform_housenumber+quoteform_postcode);
	validated = 0;
  }

  if (validated == 0){
	//alert(validated);
	$(".offerFormError").hide();
    $(".form").prepend("<p class='offerFormError'>Please complete all fields.</p>");
  }
  else{

	$.get("AJAX_database.php", { mode:"offer", name:quoteform_name, email:quoteform_email, telephone:quoteform_tel, house_number:quoteform_housenumber, postcode:quoteform_postcode }, function(data){

		window.location = "http://109.123.80.212/email.php?mode=offer&name="+quoteform_name+"&email="+quoteform_email+"&telephone="+quoteform_tel+"&action=x";

	});




	$(".offerFormError").hide();
	$('.printVoucherButton').attr('disabled', false);
    $('.printVoucherButton').css('background', 'url(img/print_voucher.png) no-repeat');


  }

}

//==================== QUOTE FORM PROCESSING ====================//
function processQuoteForm(){

	var validated = 1;
	var error_string = "";
	var quoteform_name = $('.quoteform_name').val();
	var quoteform_email = $('.quoteform_email').val();
	var quoteform_tel = $('.quoteform_tel').val();
	var quoteform_housenumber = $('.quoteform_housenumber').val();
	var quoteform_postcode = $('.quoteform_postcode').val();

	if (quoteform_name == ""){
		error_string += "<div class='orangeBlock'></div><div style='float:left'>Name</div>"; validated = 0;
	}
	if (quoteform_email == ""){
		error_string += "<div class='orangeBlock'></div><div style='float:left'>Email</div>"; validated = 0;
	}
	if (quoteform_tel == ""){
		error_string += "<div class='orangeBlock'></div><div style='float:left'>Telephone</div>"; validated = 0;
	}
	if (quoteform_housenumber == ""){
		error_string += "<div class='orangeBlock'></div><div style='float:left'>House Number</div>"; validated = 0;
	}
	if (quoteform_postcode == ""){
		error_string += "<div class='orangeBlock'></div><div style='float:left'>Postcode</div>"; validated = 0;
	}

	if (validated == 0){
		$.blockUI( { "message":"<div class='quotePopup' style='height:167px'><h2>Error</h2>Please enter or correct your entry for the following fields:<br/><br/>"+error_string+"<br/><br/><button class='quoteFormCloseButton' onclick='closePopup()'></button></div>" } );
	}
	else{


		$.get("AJAX_database.php", { mode:"quote", name:quoteform_name, email:quoteform_email, telephone:quoteform_tel, house_number:quoteform_housenumber, postcode:quoteform_postcode }, function(data){

			window.location = "http://109.123.80.212/email.php?mode=quote&name="+quoteform_name+"&email="+quoteform_email+"&telephone="+quoteform_tel+"&action=x";

		});

	}
}
//==================== QUOTE FORM PROCESSING END ====================//

function printVoucher(){

	window.location = "thankyou.php?ref=offer"; //redirect user to thank you page

}

function designDoorPopup(){

  $.blockUI( { message:"<iframe style='background:#fff;border:6px solid #ccc' frameborder='0' scrolling='no' src='http://www.door-glass.co.uk/door-designer-warmseal.html' width='940' height='590'><p>Your browser does not support iframes.</p></iframe><button style='background:url(img/close.gif) no-repeat;border:0;width:66px;height:22px;position:absolute;right:-85px;top:21px' onclick='closePopup()'></button>",
  			    css: { top:"10%", "margin-left":"-247px" }
  });
}

function closePopup(){
  $.unblockUI(); $('.offerPopup').hide();
}

var newsletterFormOpen = 0;

function showNewsletterForm(){

  if (newsletterFormOpen == 1){

	 $("#newsletterForm").animate({"right": "-241px"}, 750);

	 newsletterFormOpen = 0;
  }
  else{

	 $("#newsletterForm").animate({"right": "0px"}, 750);
     $(".newsletterError").empty();

     newsletterFormOpen = 1;

  }


}

function submitNewsletter(){

	var newsletter_name = $(".newsletter_name").val();
	var newsletter_email = $(".newsletter_email").val();

	if (newsletter_name == "" || newsletter_email == ""){

	$(".newsletterError").text("Please complete all fields.").css( { color:"#aa5555" } );

	}
	else{

		$.get("AJAX_database.php", { mode:"newsletter", name:newsletter_name, email:newsletter_email }, function(data){

			window.location = "http://109.123.80.212/email.php?mode=newsletter&name="+newsletter_name+"&email="+newsletter_email+"&telephone=x&action=x";


		});

		$(".newsletter_name").val(""); $(".newsletter_email").val("");
		hideNewsletterForm();

	}

}

function hideNewsletterForm(){
  $("#newsletterForm").animate({"right": "-241px"}, 750);
}

function showSearchResults(){

	var query = $(".searchBox").val();

	if (query == ""){ $(".searchBox").css( { border:"1px solid #aa1111" } ); }
	else{

	  $.get("AJAX_searchPopup.php", { query:query }, function(data){
		  //alert("");
		  $.blockUI( { "message":"<div class='quotePopup' style='height:270px'><h2>Site Search</h2>You searched for: <span style='font-weight:bold'>"+query+"</span><br/><br/><hr />"+data+"<button class='quoteFormCloseButton' onclick='closePopup()'></button></div>" }	);
		  $(".searchBox").val('');
		});

	}

}

function requestCallback(){
  $.blockUI( { "message":"<div class='quotePopup' style='height:268px'><h2>Request a Callback</h2>Please call us on 0800  321 7011.<br/><br/>Alternatively fill out your details below and we will get in touch.<br/><br/><div class='callbackForm'><table style='float:left;width:400px;'><tr><td>Name:</td><td> <input class='callbackName' type='text' /></td></tr><tr><td>Email:</td><td> <input class='callbackEmail' type='email' /></td></tr><tr><td>Telephone:</td><td> <input class='callbackTelephone' type='text' /></td></tr></table><br/><br/><br/><br/><br/></div><br/><br/><button style='float:left;margin-top:20px' class='submitButton' onclick='processCallbackRequest()'></button><button class='quoteFormCloseButton' onclick='closePopup()'></button></div>" }	);
}

function requestBrochure(){
  $.blockUI( { "message":"<div class='quotePopup' style='height:268px'><h2>Request a Brochure</h2>Please select a brochure type and enter your details.<br/><br/><input style='margin-bottom:8px' onclick='switchBrochureForm(1)' class='brochure1' type='radio' name='brochure' CHECKED/> E-Brochure<br/><input onclick='switchBrochureForm(2)' class='brochure2' type='radio' name='brochure' /> Standard Brochure<br/><br/><div style='float:left' class='brochureForm'><table style='float:left;width:400px;'><tr><td>Name:</td><td><input class='brochureName' type='text' /></td></tr><tr><td>Email:</td><td><input class='brochureEmail' type='email' /></td></tr><tr><td>Type:</td><td><select class='type'><option value='General Brochure'>General Brochure</option><option value='Doors'>Doors</option><option value='Canopy'>Canopy</option><option value='Roofline'>Roofline</option><option value='Windows'>Windows</option><option value='Garage Doors'>Garage Doors</option><option value='Conservatory'>Conservatory</option></select></td></tr></table></div><br/><br/><button style='float:left;margin-top:20px' class='submitButton' onclick='processRequestBrochure()'></button><button class='quoteFormCloseButton' onclick='closePopup()'></button></div>" }	);
}

var brochureFormID;

function switchBrochureForm(brochureFormID){

				if (brochureFormID == 1){
				$(".brochureForm").html("<table style='float:left;width:400px;'><tr><td>Name:</td><td><input class='brochureName' type='text' /></td></tr><tr><td>Email:</td><td><input class='brochureEmail' type='email' /></td></tr><tr><td>Type:</td><td><select class='type'><option value='General Brochure'>General Brochure</option><option value='Doors'>Doors</option><option value='Canopy'>Canopy</option><option value='Roofline'>Roofline</option><option value='Windows'>Windows</option><option value='Garage Doors'>Garage Doors</option><option value='Conservatory'>Conservatory</option></select></td></tr></table><br/><br/><br/><br/><br/>");
				}
				else{
				$(".brochureForm").html("<table style='float:left;width:400px;'><tr><td>Name:</td><td> <input class='brochureName' type='text' /></td></tr><tr><td>Email:</td><td> <input class='brochureEmail' type='email' /></td></tr><tr><td>Address:</td><td> <input class='brochureAddress' type='text' /></td></tr><tr><td>Postcode:</td><td> <input class='brochurePostcode' type='text' /></td></tr></table><br/><br/><br/><br/><br/>");
				}

}

function processRequestBrochure(){

				if ($(".brochure1:checked").length==1){

								var brochureName = $(".brochureName").val();
								var brochureEmail = $(".brochureEmail").val();
								var type = $(".type").val();

								if (brochureEmail=="") { alert("Please complete all fields."); }
								else {


								$.get("AJAX_database.php", { mode:"e_brochure", name:brochureName, email:brochureEmail, type:type, telephone:"[Not provided]", address:"[Not provided]", postcode:"[Not provided]" }, function(data){

												window.location = "http://109.123.80.212/email.php?mode=ebrochure&name="+brochureName+"&email="+brochureEmail+"&type="+type+"&action=x";

								});

								closePopup();
								}

				}

				else {

							var brochureName = $(".brochureName").val();
							var brochureEmail = $(".brochureEmail").val();
							var brochureAddress = $(".brochureAddress").val();
							var brochurePostcode = $(".brochurePostcode").val();

							if (brochureName==""||brochureEmail==""||brochureAddress==""||brochurePostcode==""){ alert("Please complete all fields."); }
							else {

							$.get("AJAX_database.php", { mode:"brochure", name:brochureName, email:brochureEmail, address:brochureAddress, postcode:brochurePostcode }, function(data){

									window.location = "http://109.123.80.212/email.php?mode=brochure&name="+brochureName+"&email="+brochureEmail+"&address="+brochureAddress+"&action=x";

							});

							closePopup();

							}

	}

}

function processCallbackRequest(){

	  var callbackName = $(".callbackName").val();
	  var callbackEmail = $(".callbackEmail").val();
	  var callbackTelephone = $(".callbackTelephone").val();

	  if (callbackName == "" || callbackEmail == "" || callbackTelephone == ""){
		 alert("Please complete all fields.");
	  }
	  else{

		 $.get("AJAX_database.php", { mode:"callback", name:callbackName, email:callbackEmail, telephone:callbackTelephone, address:"[Not provided]", postcode:"[Not provided]" }, function(data){

	  		window.location = "http://109.123.80.212/email.php?mode=callback&name="+callbackName+"&email="+callbackEmail+"&telephone="+callbackTelephone;

		 });

     	 closePopup();

	  }

}





function showTerms(){
  $.blockUI( { message: "<h2>Terms and Conditions</h2>Terms and conditions will appear here.<button style='top:0px;right:0px' class='quoteFormCloseButton' onclick='closePopup()'></button>", css: { width:"450px", background:"#e6e6e6", border:"5px solid #fff", "margin-left":"0px" } } );
}

function showWER(){
  $.blockUI( { message: "<h2>Window Energy Ratings</h2><p>Warmseal is a British Standards Institution registered company. This means all of our windows and doors rate extremely highly in terms of energy ratings. The scheme is a method to show compliance of window energy safety ratings. Click <a class='popup-link' href='pdf/KM-567420.pdf' target='_blank'>here</a> to find out more.<br/><br/>Make sure your supplier is Kitemark accredited.</p><button style='top:0px;right:0px' class='quoteFormCloseButton' onclick='closePopup()'></button>", css: { width:"450px", background:"#e6e6e6", border:"5px solid #fff", "margin-left":"0px" } } );
}

function showEE(){
  $.blockUI( { message: "<h2>Energy Efficiency</h2><p>The journey towards zero carbon is well underway. All of our windows use energy efficient glass and are A-C rated. They all currently exceed Building Regulation standards and our 'A' rated windows easily beat the latest legislation requirements.<br/><br/>Zero carbon for all new homes will become mandatory in 2016 and Warmseal is proud to supply the UK's first zero carbon home compliant PVC-U casement windows. The 0.8 W/m2K U-value windows ensure ultra low heat loss and reduced CO2 emissions.<br/><br/>Triple glazed and delivering a solar factor \"g\" of 0.6 W/m2K, the new Warmseal Zero Carbon window is security Kitemarked (BS7950). A green future is now a present reality.</p><button style='top:0px;right:0px' class='quoteFormCloseButton' onclick='closePopup()'></button>", css: { width:"450px", background:"#e6e6e6", border:"5px solid #fff", "margin-left":"0px" } } );
}

function showSS(){
  $.blockUI( { message: "<h2>Security Standards</h2>Content will appear here shortly.<button style='top:0px;right:0px' class='quoteFormCloseButton' onclick='closePopup()'></button>", css: { width:"450px", background:"#e6e6e6", border:"5px solid #fff", "margin-left":"0px" } } );
}

var offer_rotation;
//offer_rotation = setTimeout("nextOffer()", 5000);

