// Cart.js
// author:  Mike Pass
// Company:  Digital Mason LLC
// Copyright: 2006 Digital Mason LLC
// For use on Signature Minerals Only
// 11-10-06

/*  Example Usage:
kit1 = new kit("Basically Me Kit",57.00);
kit1.addSet("Foundation",2);
kit1.addSet("Blushes",2);
kit1.addSet("EyeColors",3);
kit1.addSet("Veil",2);
*/

function sendme(cnt,titl){
a = document.forms["tset"].elements;
k=0;str="";
for (var i in a) { 
if(a[i].checked==true) 
{
k++;
str += a[i].value+"<br>";
}
}
if(k>cnt){alert("You are only allowed "+cnt+" choices.\n You have "+k+".\n  Please adjust."); return false}
if(k<cnt && !confirm("You are allowed up to "+cnt+" choices.\n You only have "+k+".\n  Are you sure this is all you want to add?")){return false;}
fm = '<html>Adding to Cart...<form action="http://www.ewebcart.com/cgi-bin/cart.pl" method="post" name="tform">';
fm +='<input type="hidden" name="merchant" value="17092">';
fm +='<input type="hidden" name="add" value="Add to Cart">';
fm +='<input type="hidden" name="description" value="'+str+'">';
fm +='<input type="hidden" name="name" value="-'+titl+'-">';
fm +='<input type="hidden" name="price" value="0.00">';
fm +='<input type="hidden" name="quantity" value="1">';
fm +='</form></html>';
document.write(fm);
document.forms["tform"].submit();
//alert(fm);
return false;
}

kitset = function(){
this.names = new Object();
this.allowed=allowed;
}


function kit(titl,price){
this.titl=titl;
this.price=price;
this.ord="";
this.cnt=0;
this.ks = new Object();
this.merch="17092";
}

kit.prototype.addSet = function(formname,allowed){
this.ks[formname] = allowed;
this.cnt++;
}

kit.prototype.getValues = function(){
var nul=null;
// each kitset is a form with a collection of checkboxes.
this.ord="";
for (j in this.ks){  //alert(j);
var a = eval("document."+j+".elements"); 
k=0;str="<b>"+j+":</b><br>";cnt=this.ks[j];
for ( l in a) {
//if(a[l]!=nul && a[l].type=='checkbox' && a[l].checked==true) st1 += a[l].name+" ";
if(a[l]!=nul && a[l].type=='checkbox' && a[l].checked===true){k++;str += a[l].value+"<br>";}}
if(k>cnt){alert("You are only allowed "+cnt+" choices in group '"+ j +"'.\n You have "+k+".\n  Please adjust your order."); return false}
if(k<cnt && !confirm("You are allowed up to "+cnt+" choices in group '"+j+"'.\n You only have "+k+".\n  Are you sure this is all you want to add?")){return false;}
this.ord+=str;
}
return true;
}

kit.prototype.getTotal = function(priceeach){
var nul=null;
// each kitset is a form with a collection of checkboxes.
this.ord="";
for (j in this.ks){  //alert(j);
var a = eval("document."+j+".elements"); 
k=0;str="<b>"+j+":</b><br>";cnt=this.ks[j];
for ( l in a) {
//if(a[l]!=nul && a[l].type=='checkbox' && a[l].checked==true) st1 += a[l].name+" ";
if(a[l]!=nul && a[l].type=='checkbox' && a[l].checked===true){k++;str += a[l].value+"<br>";}}
this.ord+=str;
}
tprice=k*priceeach;
tprice=tprice.toFixed(2);
if(tprice==0.00){alert("Please make your selections");return false;}
if(!confirm("Your have ordered "+k+" items.\nYour pre-discounted price will be $"+tprice+". \n\nAre you ready to add this to your cart?")) return false;
this.price=tprice;
return true;
}


kit.prototype.getTotalNoVol = function(priceeach){
var nul=null;
// each kitset is a form with a collection of checkboxes.
this.ord="";
for (j in this.ks){  //alert(j);
var a = eval("document."+j+".elements"); 
k=0;str="<b>"+j+":</b><br>";cnt=this.ks[j];
for ( l in a) {
//if(a[l]!=nul && a[l].type=='checkbox' && a[l].checked==true) st1 += a[l].name+" ";
if(a[l]!=nul && a[l].type=='checkbox' && a[l].checked===true){k++;str += a[l].value+"<br>";}}
this.ord+=str;
}
tprice=k*priceeach;
tprice=tprice.toFixed(2);
if(tprice==0.00) {alert("Please make your selections"); return false;}
if(!confirm("Your have ordered "+k+" items.\nYour price will be $"+tprice+". \n\nAre you ready to add this to your cart?")) return false;
this.price=tprice;
return true;
}

kit.prototype.sendMe = function(){
if(this.getValues()){
fm = '<html>Adding to Cart...<form action="http://www.ewebcart.com/cgi-bin/cart.pl" method="post" name="tform">';
fm +='<input type="hidden" name="merchant" value="'+this.merch+'">';
fm +='<input type="hidden" name="add" value="Add to Cart">';
fm +='<input type="hidden" name="description" value="'+this.ord+'">';
fm +='<input type="hidden" name="name" value="-'+this.titl+'-">';
fm +='<input type="hidden" name="price" value="'+this.price+'">';
fm +='<input type="hidden" name="quantity" value="1">';
fm +='</form></html>';
document.write(fm);
document.forms["tform"].submit();
}
return false;
}

kit.prototype.sendMe2 = function(){
if(this.getTotal(this.price)){
fm = '<html>Adding to Cart...<form action="http://www.ewebcart.com/cgi-bin/cart.pl" method="post" name="tform">';
fm +='<input type="hidden" name="merchant" value="'+this.merch+'">';
fm +='<input type="hidden" name="add" value="Add to Cart">';
fm +='<input type="hidden" name="description" value="'+this.ord+'">';
fm +='<input type="hidden" name="name" value="-'+this.titl+'-">';
fm +='<input type="hidden" name="price" value="'+this.price+'">';
fm +='<input type="hidden" name="quantity" value="1">';
fm +='</form></html>';
document.write(fm);
document.forms["tform"].submit();
}
return false;
}

kit.prototype.sendMe3 = function(){
if(this.getTotalNoVol(this.price)){
fm = '<html>Adding to Cart...<form action="http://www.ewebcart.com/cgi-bin/cart.pl" method="post" name="tform">';
fm +='<input type="hidden" name="merchant" value="'+this.merch+'">';
fm +='<input type="hidden" name="add" value="Add to Cart">';
fm +='<input type="hidden" name="description" value="'+this.ord+'">';
fm +='<input type="hidden" name="name" value="-'+this.titl+'-">';
fm +='<input type="hidden" name="price" value="'+this.price+'">';
fm +='<input type="hidden" name="quantity" value="1">';
fm +='</form></html>';
document.write(fm);
document.forms["tform"].submit();
}
return false;
}