Subversion Repositories SmartDukaan

Rev

Rev 2320 | Rev 2731 | 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
 
12
    updateEstimate();
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();
21
 
1922 varun.gupt 22
    /**
23
     * Code to track user clicks on Product slides and 'Proceed to Payment' option
24
     */
25
	$('a.vt').click(function(){
26
		trackEventWithGA('Product', $(this).children('span').text(), $('title').text().split('|')[0].trim());
27
	});
28
 
1761 vikas 29
    $("#addcart").click(function(){
1456 varun.gupt 30
		jQuery.ajax({
31
			type: "POST",
1614 rajveer 32
			url: "/addtocart",
1456 varun.gupt 33
			data: "productid=" + $("#item_id").val(),
34
			success: function(msg)	{
2036 rajveer 35
	   			 if(msg==""){
36
					 window.location = "/cart";
37
				 }else{
38
					 alert(msg);
39
				 }			}
1456 varun.gupt 40
		});
41
	});
42
 
43
	$("#colorselector").change(function(){
44
		var itemid = $("#colorselector option:selected").val();
45
 
46
		$('#sp').html(PARAMETERS[itemid].SP);
47
		$('#mrp').html(PARAMETERS[itemid].MRP);
48
		$('#saving').html(PARAMETERS[itemid].SAVING);
49
		$("#item_id").val(itemid);
50
		updateEstimate(itemid);
51
		return false;
52
	});
53
 
54
	$("a.colorselector").click(function() {
55
		$('.a.colorselector').addClass('deselect');
56
		$(this).addClass('deselect');
1567 vikas 57
		var itemid = $(this).attr('itemid');
1456 varun.gupt 58
		$('#sp').html(" "+PARAMETERS[itemid].SP);
59
		$('#mrp').html(" "+PARAMETERS[itemid].MRP);
60
		$('#saving').html(PARAMETERS[itemid].SAVING);
61
		$("#item_id").val(itemid);
62
		return false;
63
	});
2228 rajveer 64
 
65
	$("#util_compare").click(function() {
66
		$.fn.colorbox({inline:true, href:".colorSelLightBoxColor", open:true, onComplete:function(){
67
			var posLeft = (document.documentElement.clientWidth / 2) - (parseInt($('#colorbox').css('width')) / 2);
68
			var posTop = (document.documentElement.clientHeight / 2) - (parseInt($('#colorbox').css('height')) / 2);
69
 
70
			$('#colorbox').css('top', posTop);
71
			$('#colorbox').css('left', posLeft);
72
		}});
73
	});
74
 
75
	/* This code is for compare with button */
76
	var availableNames = [];
77
	for (var k in productIdNames)availableNames.push(k);
2235 rajveer 78
    $("#mobilename").autocomplete({  autoFocus: true, minLength: 3, 
2228 rajveer 79
        source: availableNames
80
    });
81
 
82
 
2236 rajveer 83
    $('#mobilename').keypress(function(e) {
84
    	if(e.keyCode == 13) {
85
    		return compareProducts();
86
        }
87
    });
88
 
89
 
2228 rajveer 90
    $("#compare_continue").click(function() {
2236 rajveer 91
    	return compareProducts();
2228 rajveer 92
    });
2236 rajveer 93
 
2320 rajveer 94
    $('.tooltip').each(function(index) {
95
    	   $(this).qtip({
96
    		style: { width: 300, overflow: 'auto',
97
    			tip: { corner: 'topLeft' }, 
98
    			border: { width: 2, radius: 2, color: '#DDDDDD' } },
99
    		show: { when: { event: 'click' } },
100
    		content: { url: "/helpdocs/" + $(this).attr('name'), title: { text: ' ', button: 'Close'} },
101
    		hide: { when: { event: 'unfocus' } },
102
    		position: { adjust: {screen: true} }
103
    		});
104
    	});
105
 
106
 
2236 rajveer 107
    function compareProducts(){
108
		var productName = $("#mobilename").val();
109
		var productTwo = productIdNames[productName];
110
		if(typeof productTwo == 'undefined'){
111
			alert("Please select a valid product");
112
			return false;
113
		}
114
		var productOne = $("#catelog_id").val();
115
		window.location = "/compare-mobile-phones?p1="+productOne+"&p2="+productTwo;	
116
	}
2228 rajveer 117
 
1456 varun.gupt 118
});
119
 
120
function changeSignInClass(){
121
	if(document.getElementById("signinClass").className.indexOf("signin1") > -1)	{
122
		document.getElementById("signinClass").className = 'signin';
123
	} else	{
124
		document.getElementById("signinClass").className = 'signin1';
125
	}
126
}
127
 
2228 rajveer 128
 
1456 varun.gupt 129
function updateEstimate(itemId)	{
130
	itemId = itemId || $("#item_id").val();
131
 
132
	jQuery.ajax({
133
		type: "GET",
1919 rajveer 134
		url: "/estimate/" + $("#zipcode").val() + "_" + itemId,
1456 varun.gupt 135
		beforeSend: function()	{
2652 rajveer 136
			$("#days").html("<img src='/images/loader_l.gif'>");
1456 varun.gupt 137
		},
138
		success: function(msg)	{
139
			$("#shipping_time").html(msg);
140
		}
141
	});
2228 rajveer 142
}
143
 
2652 rajveer 144
function load_accessories_widget(){
145
	jQuery.ajax({
146
		type : "GET",
147
		url : "/related-accessories/" + $("#product_id").val(),
148
		cache: false,
149
		success : function(html) {
150
   		    $("#accessories").html(html);
151
 
152
		    // Product Title
153
		    $("#accessories table td div a").each(function() {
154
					$(this).truncate({addtitle : true});
155
		    });
156
 
157
		    // Product Price
158
		    $("#accessories table td div div.price").each(function() {
159
					$(this).truncate({addtitle : true});
160
			});
161
 
162
		    // Product Details
163
		    $("#accessories table td div div.text").each(function() {
164
					$(this).truncate( {addtitle : true});
165
			});
166
	    }
167
	});
168
}