Subversion Repositories SmartDukaan

Rev

Rev 4395 | Rev 4530 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
1456 varun.gupt 1
$(function(){
2
	$('#loopedSlider').loopedSlider();
3
 
4
	runEffect();
5
 
6
	$(".controls").tabs();
7
 
8
	$('#forgot_username_link').tipsy({gravity: 'w'});
9
 
10
	$("#zipcode").val($("#defaultpincode").val());
11
 
3830 chandransh 12
    updateEstimate(getSeletectedItemId());
1456 varun.gupt 13
 
1761 vikas 14
    var prodid = $("#product_id").val();
15
 
16
	add_to_storage_set("histitems", prodid);
17
 
1623 rajveer 18
    load_history_widget();
1761 vikas 19
 
2652 rajveer 20
    load_accessories_widget();
3406 rajveer 21
 
22
    load_most_compared_widget();
2754 rajveer 23
 
2731 varun.gupt 24
    myNotes.getNotes();
25
 
4489 varun.gupt 26
    // Fix to always show first image's title on page load
27
    $('.slides .modelName').html(title_1[0]);
28
 
3830 chandransh 29
    function getSeletectedItemId(){
30
    	 return $("#item_id").val();
31
    }
32
 
33
 
1922 varun.gupt 34
    /**
35
     * Code to track user clicks on Product slides and 'Proceed to Payment' option
36
     */
37
	$('a.vt').click(function(){
38
		trackEventWithGA('Product', $(this).children('span').text(), $('title').text().split('|')[0].trim());
39
	});
40
 
3830 chandransh 41
	$('#computeShippingEstimate').click(function(){
42
		updateEstimate(getSeletectedItemId());
43
	});
44
 
45
    $("#addToCart").click(function(){
2811 rajveer 46
    	jQuery.ajax({
1456 varun.gupt 47
			type: "POST",
1614 rajveer 48
			url: "/addtocart",
3830 chandransh 49
			data: "productid=" + getSeletectedItemId(),
1456 varun.gupt 50
			success: function(msg)	{
2036 rajveer 51
	   			 if(msg==""){
3830 chandransh 52
	   				 trackEventWithGA('Order', 'Add to Cart', getSeletectedItemId() + '');
2036 rajveer 53
					 window.location = "/cart";
54
				 }else{
2810 rajveer 55
					 displayRelatedProducts(msg);
2754 rajveer 56
				 }			
57
	   		}
1456 varun.gupt 58
		});
59
	});
60
 
3830 chandransh 61
	$("#colorSelector").change(function(){
62
		var itemid = $("#colorSelector option:selected").val();
1456 varun.gupt 63
		$('#sp').html(PARAMETERS[itemid].SP);
64
		$('#mrp').html(PARAMETERS[itemid].MRP);
65
		$('#saving').html(PARAMETERS[itemid].SAVING);
66
		$("#item_id").val(itemid);
67
		updateEstimate(itemid);
68
		return false;
69
	});
70
 
3830 chandransh 71
/*	$("a.colorselector").click(function() {
1456 varun.gupt 72
		$('.a.colorselector').addClass('deselect');
73
		$(this).addClass('deselect');
1567 vikas 74
		var itemid = $(this).attr('itemid');
1456 varun.gupt 75
		$('#sp').html(" "+PARAMETERS[itemid].SP);
76
		$('#mrp').html(" "+PARAMETERS[itemid].MRP);
77
		$('#saving').html(PARAMETERS[itemid].SAVING);
78
		$("#item_id").val(itemid);
79
		return false;
3830 chandransh 80
	});*/
2228 rajveer 81
 
3830 chandransh 82
	$(".util_compare").click(function() {
2755 rajveer 83
		$.colorbox({
84
			inline:true, 
85
			href:"#compareLightBox",
86
    		width:"350px",
87
    		height:"230px",
88
 
89
    		onComplete: function(){
90
    			$('#compareLightBox').show();
91
    		},
92
    		onCleanup: function(){
93
    			$('#compareLightBox').hide();
94
    		}
95
    	});
2228 rajveer 96
	});
3830 chandransh 97
 
98
	$('.util_addnewresearch').click(function(){
99
		addResearch('', 'single');
100
	});
101
 
2236 rajveer 102
    $('#mobilename').keypress(function(e) {
103
    	if(e.keyCode == 13) {
104
    		return compareProducts();
105
        }
106
    });
107
 
108
 
2228 rajveer 109
    $("#compare_continue").click(function() {
2236 rajveer 110
    	return compareProducts();
2228 rajveer 111
    });
2236 rajveer 112
 
3305 rajveer 113
    $('.tooltip').click(function() {
114
    	trackEventWithGA('Product', 'Helpdoc Click', $(this).attr('name'));
115
    });
116
 
2320 rajveer 117
    $('.tooltip').each(function(index) {
118
    	   $(this).qtip({
119
    		style: { width: 300, overflow: 'auto',
120
    			tip: { corner: 'topLeft' }, 
121
    			border: { width: 2, radius: 2, color: '#DDDDDD' } },
122
    		show: { when: { event: 'click' } },
123
    		content: { url: "/helpdocs/" + $(this).attr('name'), title: { text: ' ', button: 'Close'} },
124
    		hide: { when: { event: 'unfocus' } },
125
    		position: { adjust: {screen: true} }
126
    		});
127
    	});
128
 
129
 
2236 rajveer 130
    function compareProducts(){
131
		var productName = $("#mobilename").val();
4143 varun.gupt 132
		var productTwo = typeof(productIdNames['mobiles'][productName]) == 'undefined' ? productIdNames['laptops'][productName] : productIdNames['mobiles'][productName];
133
 
2236 rajveer 134
		if(typeof productTwo == 'undefined'){
135
			alert("Please select a valid product");
136
			return false;
137
		}
2827 rajveer 138
		var productOne = $("#catalog_id").val();
2236 rajveer 139
		window.location = "/compare-mobile-phones?p1="+productOne+"&p2="+productTwo;	
140
	}
2228 rajveer 141
 
2802 rajveer 142
    $("#accessories table td div a").live('click', function() {
143
    	var productId = $(this).parent().parent().parent().children().find('input[type=checkbox]').val();
144
    	trackEventWithGA('Widget', 'Accessory Click', productId);
145
    });
146
 
1456 varun.gupt 147
});
148
 
149
function changeSignInClass(){
150
	if(document.getElementById("signinClass").className.indexOf("signin1") > -1)	{
151
		document.getElementById("signinClass").className = 'signin';
152
	} else	{
153
		document.getElementById("signinClass").className = 'signin1';
154
	}
155
}
156
 
2228 rajveer 157
 
1456 varun.gupt 158
function updateEstimate(itemId)	{
3830 chandransh 159
	itemId = itemId || $("#colorSelector option:selected").val();
1456 varun.gupt 160
 
161
	jQuery.ajax({
162
		type: "GET",
1919 rajveer 163
		url: "/estimate/" + $("#zipcode").val() + "_" + itemId,
1456 varun.gupt 164
		beforeSend: function()	{
3830 chandransh 165
			$("#shipping_time").html("Receive in <img src='/images/loader_l.gif'> business days");
1456 varun.gupt 166
		},
167
		success: function(msg)	{
3830 chandransh 168
			var response = eval('(' + msg + ')');
169
			var deliveryEstimate = parseInt(response['delivery_estimate']);
170
			var isCODAvailableForLocation = (response['is_cod_available_for_location'] === 'true');
171
 
172
			if(deliveryEstimate == -1)	{
173
				$("#shipping_time").html('This Location is not serviceable');
174
			} else	{
175
				$("#shipping_time").html('Receive in <label class="red">' + deliveryEstimate + ' Business Days</label>');
176
			}
177
 
4395 rajveer 178
			if (isCODAvailableForLocation && parseInt($('#sp').html()) < 10000 && parseInt($('#sp').html()) > 100)	{
3830 chandransh 179
				$('#cod').show();
180
			} else {
181
				$('#cod').hide();
182
			}
1456 varun.gupt 183
		}
184
	});
2228 rajveer 185
}
186
 
3406 rajveer 187
function load_most_compared_widget(){
188
	jQuery.ajax({
189
		type : "GET",
190
		url : "/most-compared-products/" + $("#product_id").val(),
191
		cache: false,
192
		success : function(html) {
193
   		    $("#mostcompared").html(html);
194
 
195
		    // Product Title
196
		    $("#mostcompared table td div a").each(function() {
197
					$(this).truncate({addtitle : true});
198
		    });
199
 
200
		    // Product Price
201
		    $("#mostcompared table td div div.price").each(function() {
202
					$(this).truncate({addtitle : true});
203
			});
204
 
205
		    // Product Details
206
		    $("#mostcompared table td div div.text").each(function() {
207
					$(this).truncate( {addtitle : true});
208
			});
209
	    }
210
	});
211
}