Guest User

Untitled

a guest
May 23rd, 2018
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.74 KB | None | 0 0
  1. /*Just a note, I normally do my function brackets on separate lines while I do my ifs/fors/whiles with the first bracket on the same line. Just to clarify so you don't think I'm cheating (I've done this before if you look at my past work). */
  2.  
  3. var cart=new Array();
  4. var prices=new Array();
  5. var quantity=new Array();
  6.  
  7. function changeCat(cat)
  8. {
  9. if(cat=='shoppingcart' && document.getElementById('shoppingcart').innerHTML==""){
  10. alert("Nothing in cart!");
  11. }
  12. else if(cat=='shoppingcart' && document.getElementById('shoppingcart').innerHTML=="Nothing here, go away."){
  13. alert("Nothing in cart!");
  14. }
  15. else{
  16. document.getElementById('action').style.display="none";
  17. document.getElementById('fps').style.display="none";
  18. document.getElementById('rpg').style.display="none";
  19. document.getElementById('rts').style.display="none";
  20. document.getElementById('shoppingcart').style.display="none";
  21. document.getElementById(cat).style.display="block";
  22. }
  23. }
  24.  
  25. function addCart(product, setPrice)
  26. {
  27. var num=prompt("Please enter a quantity");
  28. num=parseInt(num);
  29. if (num==""){
  30. alert("Please enter a quantity!");
  31. }
  32. else if(num==null){
  33. //DO NOTHING
  34. }
  35. else{
  36. var isfound=false;
  37. for (var i=0; i<cart.length; i++){
  38. if (cart[i]==product.id){
  39. isfound=true;
  40. }
  41. }
  42.  
  43. if (isfound){
  44. alert("Product already in cart!");
  45. }
  46. else{
  47. cart.push(product.id);
  48. prices.push(setPrice*num);
  49. quantity.push(num);
  50. calculate();
  51. }
  52.  
  53. }
  54.  
  55. }
  56.  
  57. function remove(product)
  58. {
  59. cart[product.title]="";
  60. prices[product.title]="";
  61. quantity[product.title]="";
  62. calculate();
  63. if (document.getElementById("shoppingcart").innerHTML==""){
  64. document.getElementById("shoppingcart").innerHTML="Nothing here, go away.";
  65. }
  66. }
  67.  
  68. function calculate()
  69. {
  70. document.getElementById("shoppingcart").innerHTML="";
  71.  
  72. for (product in cart){
  73. var title=cart[product];
  74. var src="";
  75.  
  76. if (title!=""){
  77. if (title=="ac"){
  78. title="Assassin's Creed";
  79. src="ac";
  80. }
  81. else if (title=="batman"){
  82. title="BM: Arkham Asylum";
  83. src="batman";
  84. }
  85. else if (title=="bf2"){
  86. title="SW: Battlefront 2";
  87. src="bf2";
  88. }
  89. else if (title=="gta4"){
  90. title="Grand Theft Auto IV";
  91. src="gta4";
  92. }
  93. else if (title=="lanoire"){
  94. title="L.A. Noire";
  95. src="lanoire";
  96. }
  97. else if (title=="rdr"){
  98. title="Red Dead Redemption";
  99. src="rdr";
  100. }
  101. else if (title=="rfg"){
  102. title="Red Faction Guerrilla";
  103. src="rfg";
  104. }
  105. else if (title=="saboteur"){
  106. title="The Saboteur";
  107. src="saboteur";
  108. }
  109. else if (title=="sr3"){
  110. title="Saints Row: The Third";
  111. src="sr3";
  112. }
  113. else if (title=="tombraider"){
  114. title="TR: Anniversary";
  115. src="tombraider";
  116. }
  117. else if (title=="bc2"){
  118. title="BF: Bad Company 2";
  119. src="bc2";
  120. }
  121. else if (title=="bf3"){
  122. title="Battlefield 3";
  123. src="bf3";
  124. }
  125. else if (title=="cod4"){
  126. title="Call of Duty 4";
  127. src="cod4";
  128. }
  129. else if (title=="crysis"){
  130. title="Crysis";
  131. src="crysis";
  132. }
  133. else if (title=="deadisland"){
  134. title="Dead Island";
  135. src="deadisland";
  136. }
  137. else if (title=="fc2"){
  138. title="Far Cry 2";
  139. src="fc2";
  140. }
  141. else if (title=="hl2"){
  142. title="Half Life 2";
  143. src="hl2";
  144. }
  145. else if (title=="l4d"){
  146. title="Left 4 Dead";
  147. src="l4d";
  148. }
  149. else if (title=="metro"){
  150. title="Metro 2033";
  151. src="metro";
  152. }
  153. else if (title=="ro2"){
  154. title="Red Orchestra 2";
  155. src="ro2";
  156. }
  157. else if (title=="dao"){
  158. title="Dragon Age Origins";
  159. src="dao";
  160. }
  161. else if (title=="dxhr"){
  162. title="DX: Human Revolution";
  163. src="dxhr";
  164. }
  165. else if (title=="eve"){
  166. title="EVE Online";
  167. src="eve";
  168. }
  169. else if (title=="fallout3"){
  170. title="Fallout 3";
  171. src="fallout3";
  172. }
  173. else if (title=="kotor"){
  174. title="SW: KOTOR";
  175. src="kotor";
  176. }
  177. else if (title=="me"){
  178. title="Mass Effect";
  179. src="me";
  180. }
  181. else if (title=="oblivion"){
  182. title="TESIV: Oblivion";
  183. src="oblivion";
  184. }
  185. else if (title=="skyrim"){
  186. title="TESV: Skyrim";
  187. src="skyrim";
  188. }
  189. else if (title=="witcher2"){
  190. title="Witcher 2";
  191. src="witcher2";
  192. }
  193. else if (title=="x3"){
  194. title="X3: Terran Conflict";
  195. src="x3";
  196. }
  197. else if (title=="ao3"){
  198. title="Age of Empires III";
  199. src="aoe3";
  200. }
  201. else if (title=="aom"){
  202. title="Age of Mythology";
  203. src="aom";
  204. }
  205. else if (title=="coh"){
  206. title="Company of Heroes";
  207. src="coh";
  208. }
  209. else if (title=="dow2"){
  210. title="Dawn of War II";
  211. src="dow2";
  212. }
  213. else if (title=="medieval2"){
  214. title="Medieval II: Total War";
  215. src="medieval2";
  216. }
  217. else if (title=="mow"){
  218. title="Men of War";
  219. src="mow";
  220. }
  221. else if (title=="ra3"){
  222. title="C&C: Red Alert 3";
  223. src="ra3";
  224. }
  225. else if (title=="ron"){
  226. title="Rise of Nations: Gold";
  227. src="ron";
  228. }
  229. else if (title=="sc2"){
  230. title="Starcraft II";
  231. src="sc2";
  232. }
  233. else if (title=="shogun2"){
  234. title="Total War: Shogun 2";
  235. src="shogun2";
  236. }
  237.  
  238.  
  239. /*document.getElementById('shoppingcart').innerHTML=document.getElementById('shoppingcart').innerHTML+"<p>"+title+" ("+quantity[product]+") - $"+prices[product]+" <span title='"+product+"'class='remove' onclick='remove(this)'>[X]</span></p>";*/
  240. document.getElementById("shoppingcart").innerHTML=document.getElementById("shoppingcart").innerHTML+"<span class='carttd'><img class='cart' src='images/"+src+".jpg'>"+title+"<p>Quantity: "+quantity[product]+"</p><p>Price: $"+prices[product]+"</p><p><span title='"+product+"'class='remove' onclick='remove(this)'>[Remove from cart]</span></p></span>";
  241. }
  242. }
  243. }
Add Comment
Please, Sign In to add comment