var sFlag1=0;
var sFlag2=0;
var sFlag3=0;
var sFlag4=0;

var isell ="";
var iconf ="";
var iwire ="";
var iplug ="";


var  fee = 1.00;

var upgradeFlag=0;

var cell_count = 0.00;
var cell_price = 0.00;
var cell_weight = 0.00;
var config_price = 0.00;
var wire_price = 0.00;
var connector_price = 0.00;
var upgrade_fee = 0.00;
var total_price = 0.00;

var upgrade_str = "UPG";

var shipping = 0.00;

function Disab() {
frm=document.forms[0];
if(frm.cbox.checked)
{frm.Button1.disabled=true}
else {frm.Button1.disabled=false}
}

function setCountCheck() {
  document.config_image.src = "images/select.gif"
  $('div#config_det').empty().append('Left click to display available configurations to choose from.');
   if (document.all) {  //ie
  	config_name.innerText = "Select Configuration";
   }
   else { //firefox
  	document.getElementById('config_name').textContent = "Select Configuration";
   }
  sFlag2=0;
  setPack_price();
  $('div#content_div').load('config.asp',{cellCount:$('#cellCount').val()});
}


function setUpgradeFee() {
  if (upgrade_fee < fee) {
    upgrade_fee = fee;
  } else {
    upgrade_fee = 0.00;
  }
  setPack_price()
}

function setPack_price() {
  cell_count = $('#cellCount').val();
  
 upgrade_str = "";
 if (upgradeFlag == 1) {
   upgrade_str = "UPG";
   $('#upgradebox').show();
   document.custom.upgrade.disabled = '';          
   if (upgrade_fee < fee) {
   upgrade_str = "";
     document.custom.upgrade.value = 'no';
     document.custom.upgrade.checked = false;

   } else {
     document.custom.upgrade.value = 'yes';
     document.custom.upgrade.checked = true;
   upgrade_str = "UPG";

   }

 } else {
     document.custom.upgrade.value = 'no';
          document.custom.upgrade.checked = false;
          document.custom.upgrade.disabled = 'disabled';
          upgrade_fee = 0.00;
   upgrade_str = "";

   $('#upgradebox').hide();
 }

   myPackPrice = shipping + cell_count * (cell_price + upgrade_fee) + config_price + wire_price + connector_price;
  document.custom.qty.value = $('#packCount').val();

  total_price = $('#packCount').val() * myPackPrice;
 if (document.all) {  //ie
	pack_price.innerText = "$" + myPackPrice.toFixed(2).toString();
	  	ttl_price.innerText = " $" + total_price.toFixed(2).toString();

 }
 else { //firefox
	document.getElementById('pack_price').textContent = "$" + myPackPrice.toFixed(2).toString();
	  	document.getElementById('ttl_price').textContent = " $" + total_price.toFixed(2).toString();

 }

 document.custom.weight.value = (cell_weight * cell_count).toFixed(2).toString();

 document.custom.price.value = myPackPrice.toFixed(2).toString();

 document.custom.grand_price.value = total_price.toString();
 
 
 
 if (sFlag1 + sFlag2 + sFlag3 + sFlag4 == 15) {
    document.custom.buyit.disabled = '';
   
 } else {
    document.custom.buyit.disabled = 'disabled';
   
 }
 
 
 invid_str = "C-" + $('#cellCount').val();
 invid_str = invid_str + "-" + isell;
 invid_str = invid_str + "-" + iconf;
 invid_str = invid_str + "-" + iwire;
 invid_str = invid_str + "-" + iplug;
 if (upgrade_str != '') {  invid_str = invid_str + "*" + upgrade_str; };
 document.custom.invid.value = invid_str;
   
  invid_str = "C-" + $('#cellCount').val();
  invid_str = invid_str + "-" + $('#cellid').val();
  invid_str = invid_str + "-" + $('#config').val();
  invid_str = invid_str + "-" + $('#wire').val();
  invid_str = invid_str + "-" + $('#plug').val();
 if (upgrade_str != '') {  invid_str = invid_str + "*" + upgrade_str; };
 document.custom.name.value = invid_str;
}

function go_finalize() {
  $('#products').hide();
  $('#finalize').show();  
}

function toggle_top_cpb_nav() {
  $('#products').hide();
  $('#top_cpb_nav').show();
}

function toggle_products() {
  $('#finalize').hide();
  $('#top_cpb_nav').hide();
  $('#products').show();
}


function setCell(linvid,prod_name,image_name,prod_price,cat1,weight) {
 function showMyTip() {
	
	 isell = linvid;
	 upgradeFlag = 0;
	 if (cat1 == "A") { upgradeFlag=1 };
	 if (cat1 == "SC") { upgradeFlag=1 };

	 cell_weight = parseFloat(weight);

	 document.cell_image.src = document[image_name].src;
	 document.custom.cellid.value = linvid;
	 cell_price = parseFloat(prod_price);
	 if (document.all) {  //ie
		cell_name.innerText = prod_name + " $" + cell_price.toFixed(2).toString();
	 }
	 else { //firefox
		document.getElementById('cell_name').textContent = prod_name + " $" + cell_price.toFixed(2).toString();;
	 }
	 sFlag1 = 1;
	 mstr=$('span#sct_' + linvid).html();$('div#cell_det').empty().append(mstr);
	 setPack_price();
	
 }
 
  popup=$('span#ofs_' + linvid).html();
  if ($('span#ofs_' + linvid).html().length > 10)
  {
    $.prompt(popup,{
        buttons:{Continue:true,Cancel:false},
        callback:function(v,m){
          if (v) { showMyTip() }
        }
    });
  } else  { showMyTip() }
}

function setConfiguration(linvid,prod_name,image_name) {
 iconf =linvid;
 if (iconf == "unknown") { iconf="??"; };
 document.config_image.src = document[image_name].src;
 document.custom.config.value = prod_name;
 if (document.all) {  //ie
	config_name.innerText = prod_name;
 }
 else { //firefox
	document.getElementById('config_name').textContent = prod_name;
 }
 sFlag2 = 2;
mstr=$('span#scnf_' + linvid).html(); $('div#config_det').empty().append(mstr);
 setPack_price();

}

function setWire(linvid,prod_name,image_name) {
 iwire = linvid;
 document.wire_image.src = document[image_name].src;
 document.custom.wire.value = prod_name;
 if (document.all) {  //ie
	wire_name.innerText = prod_name;
 }
 else { //firefox
	document.getElementById('wire_name').textContent = prod_name;
 }
 sFlag3 = 4;
mstr=$('span#sw_' + linvid).html();$('div#wire_det').empty().append(mstr);
 setPack_price();
}

function setConnector(linvid,prod_name,image_name,prod_price) {
 iplug = linvid;
 document.connector_image.src = document[image_name].src;
 document.custom.plug.value = prod_name;
 connector_price = parseFloat(prod_price);
 if (document.all) {  //ie
	connector_name.innerText = prod_name + " $" + connector_price.toFixed(2).toString();;
 }
 else { //firefox
	document.getElementById('connector_name').textContent = prod_name + " $" + connector_price.toFixed(2).toString();;
 }
 sFlag4 = 8;
mstr=$('span#sc_' + linvid).html();$('div#plug_det').empty().append(mstr);
 setPack_price();
}

function textLimit(field, maxlen) {
    if (field.value.length > maxlen)
        field.value = field.value.substring(0, maxlen);
}