Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*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). */
- var cart=new Array();
- var prices=new Array();
- var quantity=new Array();
- function changeCat(cat)
- {
- if(cat=='shoppingcart' && document.getElementById('shoppingcart').innerHTML==""){
- alert("Nothing in cart!");
- }
- else if(cat=='shoppingcart' && document.getElementById('shoppingcart').innerHTML=="Nothing here, go away."){
- alert("Nothing in cart!");
- }
- else{
- document.getElementById('action').style.display="none";
- document.getElementById('fps').style.display="none";
- document.getElementById('rpg').style.display="none";
- document.getElementById('rts').style.display="none";
- document.getElementById('shoppingcart').style.display="none";
- document.getElementById(cat).style.display="block";
- }
- }
- function addCart(product, setPrice)
- {
- var num=prompt("Please enter a quantity");
- num=parseInt(num);
- if (num==""){
- alert("Please enter a quantity!");
- }
- else if(num==null){
- //DO NOTHING
- }
- else{
- var isfound=false;
- for (var i=0; i<cart.length; i++){
- if (cart[i]==product.id){
- isfound=true;
- }
- }
- if (isfound){
- alert("Product already in cart!");
- }
- else{
- cart.push(product.id);
- prices.push(setPrice*num);
- quantity.push(num);
- calculate();
- }
- }
- }
- function remove(product)
- {
- cart[product.title]="";
- prices[product.title]="";
- quantity[product.title]="";
- calculate();
- if (document.getElementById("shoppingcart").innerHTML==""){
- document.getElementById("shoppingcart").innerHTML="Nothing here, go away.";
- }
- }
- function calculate()
- {
- document.getElementById("shoppingcart").innerHTML="";
- for (product in cart){
- var title=cart[product];
- var src="";
- if (title!=""){
- if (title=="ac"){
- title="Assassin's Creed";
- src="ac";
- }
- else if (title=="batman"){
- title="BM: Arkham Asylum";
- src="batman";
- }
- else if (title=="bf2"){
- title="SW: Battlefront 2";
- src="bf2";
- }
- else if (title=="gta4"){
- title="Grand Theft Auto IV";
- src="gta4";
- }
- else if (title=="lanoire"){
- title="L.A. Noire";
- src="lanoire";
- }
- else if (title=="rdr"){
- title="Red Dead Redemption";
- src="rdr";
- }
- else if (title=="rfg"){
- title="Red Faction Guerrilla";
- src="rfg";
- }
- else if (title=="saboteur"){
- title="The Saboteur";
- src="saboteur";
- }
- else if (title=="sr3"){
- title="Saints Row: The Third";
- src="sr3";
- }
- else if (title=="tombraider"){
- title="TR: Anniversary";
- src="tombraider";
- }
- else if (title=="bc2"){
- title="BF: Bad Company 2";
- src="bc2";
- }
- else if (title=="bf3"){
- title="Battlefield 3";
- src="bf3";
- }
- else if (title=="cod4"){
- title="Call of Duty 4";
- src="cod4";
- }
- else if (title=="crysis"){
- title="Crysis";
- src="crysis";
- }
- else if (title=="deadisland"){
- title="Dead Island";
- src="deadisland";
- }
- else if (title=="fc2"){
- title="Far Cry 2";
- src="fc2";
- }
- else if (title=="hl2"){
- title="Half Life 2";
- src="hl2";
- }
- else if (title=="l4d"){
- title="Left 4 Dead";
- src="l4d";
- }
- else if (title=="metro"){
- title="Metro 2033";
- src="metro";
- }
- else if (title=="ro2"){
- title="Red Orchestra 2";
- src="ro2";
- }
- else if (title=="dao"){
- title="Dragon Age Origins";
- src="dao";
- }
- else if (title=="dxhr"){
- title="DX: Human Revolution";
- src="dxhr";
- }
- else if (title=="eve"){
- title="EVE Online";
- src="eve";
- }
- else if (title=="fallout3"){
- title="Fallout 3";
- src="fallout3";
- }
- else if (title=="kotor"){
- title="SW: KOTOR";
- src="kotor";
- }
- else if (title=="me"){
- title="Mass Effect";
- src="me";
- }
- else if (title=="oblivion"){
- title="TESIV: Oblivion";
- src="oblivion";
- }
- else if (title=="skyrim"){
- title="TESV: Skyrim";
- src="skyrim";
- }
- else if (title=="witcher2"){
- title="Witcher 2";
- src="witcher2";
- }
- else if (title=="x3"){
- title="X3: Terran Conflict";
- src="x3";
- }
- else if (title=="ao3"){
- title="Age of Empires III";
- src="aoe3";
- }
- else if (title=="aom"){
- title="Age of Mythology";
- src="aom";
- }
- else if (title=="coh"){
- title="Company of Heroes";
- src="coh";
- }
- else if (title=="dow2"){
- title="Dawn of War II";
- src="dow2";
- }
- else if (title=="medieval2"){
- title="Medieval II: Total War";
- src="medieval2";
- }
- else if (title=="mow"){
- title="Men of War";
- src="mow";
- }
- else if (title=="ra3"){
- title="C&C: Red Alert 3";
- src="ra3";
- }
- else if (title=="ron"){
- title="Rise of Nations: Gold";
- src="ron";
- }
- else if (title=="sc2"){
- title="Starcraft II";
- src="sc2";
- }
- else if (title=="shogun2"){
- title="Total War: Shogun 2";
- src="shogun2";
- }
- /*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>";*/
- 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>";
- }
- }
- }
Add Comment
Please, Sign In to add comment