Subversion Repositories SmartDukaan

Rev

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