﻿$(document).ready(function() {
	
	
	//Clear/fill default value in the text and textarea inputs
	$('input[type="text"], textarea, input[type="search"]').not('.askquestion')
	.focus(function() {
		if (this.value === this.defaultValue) {
			this.value = '';
		}
	})
	.blur(function() {
		if (this.value === '') {
			this.value = this.defaultValue;
		}
	});
	
	// SIZE GUIDE POPUP
	$("#size_guide").click(function(){
		// Display an external page using an iframe
		var src = "size-guide.php";
		$.modal('<div class="s_close"></div><iframe src="' + src + '" height="600" width="900" style="border:0">', {
			closeClass:'s_close',
			containerCss:{
				backgroundColor:"#fff",
				borderColor:"#fff",
				height:600,
				padding:0,
				width:900
			},
			overlayCss:{
				backgroundColor:"#000"
			},
			overlayClose:true,
			onOpen: function (dialog) {
				dialog.overlay.fadeIn('slow', function () {
					dialog.data.hide();
					dialog.container.fadeIn('slow', function () {
						dialog.data.slideDown('slow');
					});
				});
			}
		});		
	});
	
	//SUBSCRIBE NEWSLETTER
	$("#subscribenews").submit(function(event) {
		event.preventDefault();
		var $form = $(this),
		pemail = $form.find('input[name="email"]').val();
		$.post( '/template/includes/subscribe.php', {email: pemail} ,
			function(data) {
				$.prompt(data);
				if(data.indexOf('Thank you for your subscription.') != -1)
				{
					$form.find('input[name="email"]').val('enter your email to receive the newsletter');
				}
			}
		);
	}); 
	
	$("#question").submit(function(event) {
		event.preventDefault();
		var $form = $(this),
		pemail = $form.find('input[name="email"]').val();
		pmessage = $form.find('textarea[name="message"]').val();
		$.post( '/question.php', {email: pemail, message: pmessage} ,
			function(data) {
				//$.prompt(data);
				if(data.indexOf('Thank you for your time') != -1)
				{
					alert('Thank you for your time. We will respond to your question as soon as possible.');

					window.history.back(-1);
				}
				else
				{
					alert('Please enter a valid e-mail address.');
				}
			}
		);
	});
	
	$("#contact").submit(function(event) {
		event.preventDefault();
		var $form = $(this),
		pemail = $form.find('input[name="email"]').val();
		pmessage = $form.find('textarea[name="message"]').val();
		$.post( '/contact.php', {email: pemail, message: pmessage} ,
			function(data) {
				//$.prompt(data);
				if(data.indexOf('Thank you for your time') != -1)
				{
					alert('Thank you for your time. We will respond to message as soon as possible.');

//					window.history.back(-1);
				}
				else
				{
					alert('Please enter a valid e-mail address.');
				}
			}
		);
	});
	/*
	$("#giftcert").submit(function(event) {
	event.preventDefault();
				$.prompt('Cannot find the given gift certificate code.');
	}); 	
	*/
	//NOT AVAILABLE TOOLTIP
	/*$('a[href="#"]').qtip({
	   content: 'Sorry! This part of our website is not yet available.',
	   show: 'mouseover',
	   hide: 'mouseout',
	   position: {
	      corner: {
	         target: 'topMiddle',
	         tooltip: 'bottomMiddle'
	      }
	   }	   
	})*/
	
	$(".currency").hide();
	$(".submenu li.valutapicker").click(function() {
		$(".currency").toggle();
	});	
	
	$(".currency a").click(function(event) {
		event.preventDefault();
		
		$.get($(this).attr('href'), function(data) {
			if (data)
				window.location.reload();
		});
	});
});
