/*
  $Id: ccc_javascript.js,v 1.4 2005/06/17 17:20:50 stephen Exp $

  Copyright (c) 2005 SNJ Computers

  Released under the GNU General Public License
*/

function ccc_popup(url) { window.open(url, 'popupWindow', 'toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=yes, resizable=yes, copyhistory=no, width=400, height=400, screenX=250, screenY=150, top=150, left=250'); } 

/* commented out original to make way for new and improved!!
function buildImage(imageName, separator){ if (imageName == 'images/'){ imageName = 'images/nopic.gif'; } var link = '<img src="'+imageName+'" border="2" width="100" height="100" onmouseover="this.style.cursor=\'hand\'" onclick="javascript:ccc_popup(\'ccc_image.php?image='+imageName+'\')">' + separator; return link; }*/
function buildImage(imageName, separator){ 
if (imageName == ''){ 
	imageName = 'images/nopic.gif'; 
} 
if (imageName == 'images/'){ 
	imageName = 'images/nopic.gif'; 
} 
var link = '<a href="javascript:ccc_popup(\'ccc_image.php?image='+imageName+'\')"><img src="'+imageName+'" width="100" height="100" border="none" /></a>' + separator; 
return link; 
} 

function createHiddenField(name, value){ var redone = 0; try { kids = builds.childNodes; for (var i = 0; i < kids.length; i++) { if (kids[i].id == name){ kids[i].value = value; redone = 1; } } if (redone == 0){ throw ''; } } catch(e){ var input = document.createElement('INPUT'); input.setAttribute('type', 'hidden'); input.setAttribute('name', name); input.setAttribute('id', name); input.setAttribute('value', value); builds.appendChild(input); } } function build_table_content(name){ var table_content = ''; ElementType = document.getElementById(name).getAttribute('type'); switch (ElementType){ case 'drop': var text = document.getElementById(name).options[document.getElementById(name).options.selectedIndex].getAttribute('text'); table_content += text + "<br>"; break; case 'radio': case 'checkbox': elements = document.getElementsByName(name+'[]'); if (elements){ for (f = 0; f < elements.length; f++){ if (elements[f].checked){ table_content += elements[f].getAttribute('text') + "<br>"; } } } break; } return table_content; } function build_table(){ var table = '<table>';
for(a=0; a<Computers.length; a++){
	try {
		table += '<tr><td align="right" valign="top"><a href="#' + Computers[a][0] + '"><b>' + Computers[a][0] + ':</b></a></td><td>' + build_table_content(Computers[a][1]) + '</td>';
	}
	catch ( e ) { }
} return table; } function update_total(totalTrans){ var total = 0; var Selects = document.builds.getElementsByTagName("select"); for (d=0; d<Selects.length; d++){ _selected = Selects[d].options.selectedIndex; if (Selects[d].disabled == false){ total += Math.abs(Selects[d].options[_selected].getAttribute('price')); } } var Selects = document.builds.getElementsByTagName("input"); for (e=0; e<Selects.length; e++){ if (Selects[e].disabled == false && Selects[e].checked == true){ total += Math.abs(Selects[e].getAttribute('price')); } } if (totalTrans > 0){ total += Math.abs(totalTrans); } if (showSubTotal == 'true'){ document.getElementById('SubTotal_Top').innerHTML = symbol_left + custRound(total, false) + symbol_right; document.getElementById('SubTotal_Bottom').innerHTML = document.getElementById('SubTotal_Top').innerHTML; } if (baseProductPrice > 0){ createHiddenField('basePrice', baseProductPrice); if (showBase == 'true'){ document.getElementById('Base_Top').innerHTML = symbol_left + custRound(baseProductPrice, false) + symbol_right; document.getElementById('Base_Bottom').innerHTML = document.getElementById('Base_Top').innerHTML; } total += Math.abs(baseProductPrice); } if (buildPrice >= 0){ if (buildPrice <= 0){ buildPriceShown = textFree; }else{ buildPriceShown = symbol_left + custRound(buildPrice, false) + symbol_right; createHiddenField('buildPrice', buildPrice); total += Math.abs(buildPrice); } if (showBuild == 'true'){ document.getElementById('Build_Top').innerHTML = buildPriceShown; document.getElementById('Build_Bottom').innerHTML = document.getElementById('Build_Top').innerHTML; } } if (useCommission == 'true'){ if (commissionRate <= 0){ commissionShown = textNone; }else{ commissionTotal = Math.round((total * commissionRate) / 100); commissionShown = symbol_left + custRound(commissionTotal, false) + symbol_right; createHiddenField('commissionTotal', commissionTotal); total += commissionTotal; } if (showCommission == 'true'){ document.getElementById('Commission_Top').innerHTML = commissionShown; document.getElementById('Commission_Bottom').innerHTML = document.getElementById('Commission_Top').innerHTML; } } if (showTotal == 'true'){ document.getElementById('Total_Top').innerHTML = symbol_left + custRound(total, true) + symbol_right; document.getElementById('Total_Bottom').innerHTML = document.getElementById('Total_Top').innerHTML; } if (showCurrentProducts == 'true'){ document.getElementById('sysdesc').innerHTML = build_table(); } } 

function custRound(anynum, calcTax) { 
anynum = eval(anynum*currency_value); 
decimal_places = decimal_places; 
switch(decimal_places){ 
case '1': decimal_places = 10; break; 
case '2': decimal_places = 100; break; 
case '3': decimal_places = 1000; break; 
case '4': decimal_places = 10000; break; 
case '5': decimal_places = 100000; break; 
default: decimal_places = 100; break; 
} 
if (priceWithTax == 'true' && calcTax == true){ 
taxTotal = Math.abs((anynum * tax_rate) / 100); 
if (showTaxes == 'true'){ 
document.getElementById('Taxes_Top').innerHTML = Math.abs((Math.round(taxTotal*decimal_places)/decimal_places)); 
document.getElementById('Taxes_Bottom').innerHTML = document.getElementById('Taxes_Top').innerHTML; 
} 
anynum += taxTotal; 
} 
workNum=Math.abs((Math.round(anynum*decimal_places)/decimal_places)); 
workStr=""+workNum; 
if (workStr.indexOf('.')==-1){ workStr+='.00'; } 
dStr=workStr.substr(0,workStr.indexOf('.')); 
dNum=dStr-0; 
pStr=workStr.substr(workStr.indexOf('.')); 
while (pStr.length<3){ pStr+="0"; } 
pStr=pStr.replace('.', decimal_point); 
if (dNum>=1000) { dLen=dStr.length; dStr=parseInt(""+(dNum/1000))+thousands_point+dStr.substring(dLen-3,dLen); } 
if (dNum>=1000000) { dLen=dStr.length; dStr=parseInt(""+(dNum/1000000))+thousands_point+dStr.substring(dLen-7,dLen); } retval = dStr + pStr; 
return retval; 
} 
function showimage_drop(box_name, initLoad) { 
if (box_name){ 
var _box = document.getElementById(box_name); 
var selectedBox = _box.options[_box.options.selectedIndex]; 
var selectedModel = selectedBox.getAttribute('value'); 
var selectedPrice = selectedBox.getAttribute('price'); 
if (selectedModel == ''){ 
document.getElementById('link_'+box_name).innerHTML = ''; 
}else{ 
document.getElementById('link_'+box_name).innerHTML = '<label onmouseover="this.style.cursor=\'hand\'"; onclick="javascript:ccc_popup(\'ccc_more_info.php?path='+selectedModel+'\')">'+textMoreInfo+'</label>'; 
} 
if (showImages == 'true'){ 
document.getElementById('image_'+box_name).innerHTML = buildImage(selectedBox.getAttribute('image'), '<br>'); 
}
if (showPriceDiffs == 'true'){ for (g=0;g<_box.length;g++){ workingBox = _box.options[g]; workingBoxPrice = workingBox.getAttribute('price'); if (workingBoxPrice > 0){ var productName = new String(workingBox.innerHTML); if (productName.indexOf('[+]') != -1){ productName = productName.substr(0, productName.indexOf('[+]')); } if (productName.indexOf('[-]') != -1){ productName = productName.substr(0, productName.indexOf('[-]')); } var productPriceDiff = (workingBoxPrice - selectedPrice); if (productPriceDiff == 0){ var PlusMinus = ''; productPriceDiff = ''; }else{ if (productPriceDiff > 0){ var PlusMinus = '[+]'; }else{ var PlusMinus = '[-]'; } productPriceDiff = symbol_left + custRound(Math.abs(productPriceDiff), true) + symbol_right; } workingBox.innerHTML = ''; workingBox.innerHTML = productName + PlusMinus + ' ' + productPriceDiff; } } } if (!initLoad){ update_total(); } } } function showimage_checkbox(box_name, initLoad) { if (box_name){ if (showPriceDiffs == 'true'){ spans = document.getElementsByName('price_'+box_name); if (spans.length <= 0){ spans = document.getElementsByName('price_'+box_name+'[]'); } } buttons = document.getElementsByName(box_name+'[]'); if (showPriceDiffs == 'true'){ if (buttons[0].getAttribute('type') == 'radio'){ var selectedPrice = 0; for (f = 0; f < buttons.length; f++){ if (buttons[f].checked){ selectedPrice = Math.abs(buttons[f].getAttribute('price')); break; } } } } var selectedImages = ''; for (h=0; h<buttons.length; h++){ if (showPriceDiffs == 'true'){ var workingSpan = spans[h]; } var workingButton = buttons[h]; if (workingButton.checked){ if (showPriceDiffs == 'true'){ workingSpan.innerHTML = '<b>'+textIncluded+'</b>'; } if (showImages == 'true'){ selectedImages += buildImage(workingButton.getAttribute('image'), ''); } }else{ if (showPriceDiffs == 'true'){ var workingButtonPrice = Math.abs(workingButton.getAttribute('price')); if (workingButton.getAttribute('type') == 'checkbox'){ plus_minus = '[+]'; }else{ workingButtonPrice = (workingButtonPrice-selectedPrice); if (workingButtonPrice < 0){ plus_minus = '[-]'; }else{ plus_minus = '[+]'; } } if (useCommission == 'true'){ workingButtonPrice += Math.abs((workingButtonPrice * commissionRate) / 100); } workingSpan.innerHTML = plus_minus + symbol_left + custRound(Math.abs(workingButtonPrice), true) + symbol_right; } } } if (showImages == 'true'){ if (selectedImages != ''){ document.getElementById('image_'+box_name).innerHTML = selectedImages; }else{ document.getElementById('image_'+box_name).innerHTML = ''; } } if (!initLoad){ update_total(); } } }
