var checked = new Array();
checked[4] = true;
checked[12] = false;
checked[16] = false;
checked[6] = false;
checked[5] = false;
checked[7] = false;
checked[8] = false;
checked[9] = false;
checked[10] = false;

var current = 0;



function checktrue() {
Array.prototype.clean = function(deleteValue) {for (var i = 0; i < this.length; i++) { if (this[i] == deleteValue) { this.splice(i, 1); i--; } } return this;};
var truevalues = new Array();
var truearray = new Array();

for(var i in checked) {
if(checked[i] == true) {
truevalues[i] = i;
}}
truevalues.clean(undefined);

var truestring = truevalues.join('-');
return truestring;
}


function getquantity() {
var quantity = document.buildform.totalquantity.value;
if(isNaN(quantity) || quantity == ""){
quantity = 1;
}
return quantity;
}


function getprice() {
var cquantity = getquantity();
var products = checktrue();

$.post("catalog/view/theme/sy/price.php", { product:products, quantity: cquantity }, function(data) { 
document.getElementById('price').innerHTML = data;
});
}



function superSubmit() {
var quantity = getquantity();
var postvalues = new Array();

for(var i in checked) {
if(checked[i] == true) {
postvalues[i] = quantity;
} else if(checked[i] == false) {
postvalues[i] = 0;
}}

for (var i = 0; i < postvalues.length; i++) {
if (postvalues[i] == undefined) {         
postvalues[i] = 0;
}
}

$.post("index.php?route=checkout/cart", { 'quantity[]':postvalues }, function(data, status) {
if (status == 'success') {
location.href="index.php?route=checkout/cart";
}
});
}



function optionsClick(product) {
if(checked[product] == false) {
checked[product] = true;
$("#op-" + product).addClass("onbuild");
} else {
checked[product] = false;
$("#op-" + product).removeClass("onbuild");
}
document.images["build-img"].src = "catalog/view/theme/sy/image/build/" + checktrue() + ".jpg";
getprice();
}



function switchClick(product) {
if(product == 6) {
var one = 5;
var two = 7;
var add = 8;
var other = 9;
} else if(product == 5) {
var one = 6;
var two = 7;
var add = 8;
var other = 9;
} else if(product == 7) {
var one = 6;
var two = 5;
var add = 9;
var other = 8;
}
var adon = 6;

if(!(current == product)) {
checked[adon] = false;
checked[product] = true;
checked[add] = true;
checked[10] = true;
$("#op-" + product).addClass("onbuild");
checked[other] = false;
checked[one] = false;
checked[two] = false;
if(product == 5) {checked[adon] = true;}
current = product;
} else {
checked[adon] = false;
checked[product] = false;
checked[add] = false;
checked[10] = false;
$("#op-" + product).removeClass("onbuild");
checked[other] = false;
checked[one] = false;
checked[two] = false;
current = 0;
}
document.images["build-img"].src = "catalog/view/theme/sy/image/build/" + checktrue() + ".jpg";
getprice();
$("#op-" + one).removeClass("onbuild");
$("#op-" + two).removeClass("onbuild");
}


window.onload = getprice;
