﻿Device = {
	PageId: "",
	PageName: "",
	Init: function () {
		this.News.ShowMore();
	},
	InfoSubscription: {

		Lightbox: {
			Open: function () {
				Tre.Lightbox.Open('DeviceInfoSubscriptionLightbox',
					'<h1>Intresseanmälan</h1>\
					<p class="text12">Vill du ha koll på när mobiltelefonen blir tillgänglig för försäljning och vad den kommer att kosta? Fyll i intresseanmälan så hör vi av oss när vi vet mer.</p>\
					<div class="clearfix customForm">\
						<fieldset>\
							<label class="caption" for="dis_name">Ditt namn:</label>\
							<input type="text" class="textInput165" name="name" id="dis_name">\
						</fieldset>\
						<fieldset>\
							<label class="caption" for="dis_phonenumber">Ditt telefonnummer:</label>\
							<input type="text" class="textInput165" name="phonenumber" id="dis_phonenumber">\
						</fieldset>\
						<fieldset>\
							<label class="caption" for="dis_email">Din e-postadress:</label>\
							<input type="text" class="textInput165" name="email" id="dis_email">\
						</fieldset>\
						<fieldset>\
							<div class="caption">Hur vill du bli kontaktad?</div>\
							<select name="contactMethod" id="contactMethod">\
								<option value="email">E-post</option>\
								<option value="phone">Telefon</option>\
							</select>\
						</fieldset>\
						<fieldset class="alreadyCustomer">\
							<p class="caption">Är du 3-kund?</p>\
							<input type="radio" name="alreadyCustomer" id="dis_iscustomer" value="1"> <label for="dis_iscustomer">Ja</label>\
							<input type="radio" name="alreadyCustomer" id="dis_notcustomer" value="0"> <label for="dis_notcustomer">Nej</label>\
						</fieldset>\
					</div>\
					<div class="button"><a href="javascript:"><img src="/media/images/buttons/send-btn.png" /></a></div>\
					<p><strong>Så här behandlar vi din intresseanmälan.</strong></p>\
					<p>Din intresseanmälan är inte bindande och fungerar inte som en beställning av mobiltelefonen. Vi kommer endast att kontakta dig med mer information om den mobiltelefon som du anmält intresse för.</p>'
				);

				$(".DeviceInfoSubscriptionLightbox .button a").click(function () {
					Device.InfoSubscription.Lightbox.Submit(Device.PageId, Device.PageName);
				});
			},
			Submit: function (pageId, pageName) {
				
				var params = {
					name: $('input[name=name]:first').val(),
					pageName:Device.PageName,
					phoneNumber: $('input[name=phonenumber]:first').val(),
					email: $('input[name=email]:first').val(),
					contactMethod: $('select[name=contactMethod] option:selected').val(),
					alreadyCustomer: $('input[name=alreadyCustomer]').siblings(".jNiceChecked").next().val() == "1" ? "Ja" : "Nej"
				};
				Tre.Lightbox.Close();
				Tre.SendXForm("SubmitInterest",
			    {
			    	pageId: pageId,
			    	formName: "InformationSubscription",
			    	formData: params

			    },
			    function (data) {
			    	var response = (typeof data.d) == 'string' ? eval('(' + data.d + ')') : data.d;
			    	Debug.Log("resoibse", response.Success);
			    	if (response.Success) {
			    		/*$.get("/Templates/UtilityPages/MobileSwitchInfoInterestMail.aspx",
			    		{
			    		name: name,
			    		phoneNumber: phoneNumber,
			    		email: email,
			    		contactMethod: contactMethod,
			    		alreadyCustomer: alreadyCustomer
			    		});*/
			    		Tre.Lightbox.Open('mobileSwitchInterestNotificationLightboxFeedback', '<p class="text12">' + response.Message + '</p> <div class="close"><a href="javascript:" onclick="Tre.Lightbox.Close();"><img src="/media/images/buttons/close-btn.png" alt="Stäng" /></a></div>');
			    	}
			    	else
			    		Tre.Lightbox.Open('mobileSwitchInterestNotificationLightboxFeedback', '<p class="text12" style="color: #FF0000;">FEL: ' + response.Message + '</p> <div class="close"><a href="javascript:" onclick="Tre.Lightbox.Close();"><img src="/media/images/buttons/close-btn.png" alt="Stäng" /></a></div>');
			    },
			    function () {
			    	Tre.Lightbox.Open('mobileSwitchInterestNotificationLightboxFeedback', '<p class="text12" style="color: #FF0000;">Ett fel uppstod när intresseanmälan skulle skickas.</p> <div class="close"><a href="javascript:" onclick="Tre.Lightbox.Close();"><img src="/media/images/buttons/close-btn.png" alt="Stäng" /></a></div>');
			    });
			}
		}
	},
	News: {
		StartCount: 5,
		ShowMore: function () {
			var hidden = $('div.productInfoBlock div.newsList div.deviceBlogPost:hidden');
			hidden.slice(0, this.StartCount).show();
			$('div.productInfoBlock div.newsList div.showMore a:first-child').css('display', (this.StartCount >= hidden.length ? 'none' : 'block'));
			if (typeof (curvyCorners) !== 'undefined') { curvyCorners.redraw(); }
		}
	},
	Tweets: {
		StartCount: 10,
		ShowMore: function () {
			var hidden = $('div.productInfoBlock div.tweetList div.deviceTweet:hidden');
			hidden.slice(0, this.StartCount).show();
			$('div.productInfoBlock div.tweetList div.showMore a:first-child').css('display', (this.StartCount >= hidden.length ? 'none' : 'block'));
			if (typeof (curvyCorners) !== 'undefined') { curvyCorners.redraw(); }
		}
	}
}

//                $("#deviceInfoSubscriptionSubmit").click(function() {
//                    alert("click");
//                }

$(function(){ 
	Device.Init();
});

$(function () {
    $("#deviceInfoSubscriptionSubmit").click(function (evt) {
        alert("click");
    });
});
