// JavaScript Document

$(document).ready(function(){
$('.slidesubtotal').show();
});						   

function UpdateTotal(theform)
{
	var the_value = parseInt(theform.subtotal_AR.value) + parseInt(theform.subtotal_slides.value); 
	
	if (isNaN(the_value)==true) { the_value=0; }
	
theform.Total.value = the_value;

//$('input[title=theform.Total]').val(the_value);
}

// user has checked the Combined box
function CheckCombined(theform, chk)
{
var const_cost_for_all = 1995;
var subtotal = 0;

if(theform.select_all_spreadsheets.checked==true){
subtotal = const_cost_for_all;
for (i = 0; i < chk.length; i++) 
chk[i].checked = true ;
}else{
for (i = 0; i < chk.length; i++)
chk[i].checked = false ;
}

document.myform.subtotal_AR.value = subtotal;
UpdateTotal(document.myform);
}

// user has checked one of the single annual report boxes
function CheckAnnualReport(theform,chk)
{
	var max = chk.length;
	var cost = 0;
	var const_cost_per_report = 995;
	var max_cost_reports = 1995; // if it's more than this, check the Combined
	var total_cost_all_reports = 6965; // the max cost if all were selected
     
	for (var idx = 0; idx < max; idx++) 
		{
		if (eval("chk[" + idx + "].checked") == true) 
			{
			cost += const_cost_per_report; //parseInt(eval("chk[" + idx + "].value"));
			}
		}

// If they've selected all the boxes, check the Combined and give the lower price
if (cost > max_cost_reports) {
	document.myform.select_all_spreadsheets.checked = true;
	cost = max_cost_reports;
}

theform.subtotal_AR.value = cost;
UpdateTotal(theform);
}

function SelectAllSlides(theform, chk)
{
	var total_slides = 252;
    var total_cost_all_slides = 1995;

if(theform.SelectAllSlidesCheck.checked==true){
for (i = 0; i < chk.length; i++) 
chk[i].checked = true ;
}else{
for (i = 0; i < chk.length; i++)
chk[i].checked = false ;
}

// if they've unselected All Slides then figure out what is checked
if(theform.SelectAllSlidesCheck.checked==false){
	CheckSlides(theform,chk);
}
else {
	theform.number_slides.value = total_slides; 
	theform.subtotal_slides.value = total_cost_all_slides;
	UpdateTotal(theform);
}
}

function CheckSlides(theform,chk)
{
	var max = chk.length;
	var cost = 0;
	var const_cost_per_company = 25;
    var number_of_slides = 0;
	var max_cost_slides = 1995; // Don't allow them to pay more than this
	
	for (var idx = 0; idx < max; idx++) 
		{
		if (eval("chk[" + idx + "].checked") == true) 
			{
			cost += const_cost_per_company; //parseInt(eval("chk[" + idx + "].value"));
		    number_of_slides++;
			}
		}

// If they've selected too many boxes, check the Combined and give the lower price
if (cost > max_cost_slides) {
	document.myform.SelectAllSlidesCheck.checked=true;
	cost = max_cost_slides;
}
else {
	//CheckSlides(theform,chk);
}

theform.number_slides.value = number_of_slides; 
theform.subtotal_slides.value = cost;
UpdateTotal(theform);
}


var gnum = 0;

function highlight_div(checkbox_node)
{
    label_node = checkbox_node.parentNode;

    if (checkbox_node.checked)
	{
		label_node.style.backgroundColor='#0a246a';
		label_node.style.color='#fff';
		gnum++;
		alert(gnum);

	}
	else
	{
		label_node.style.backgroundColor='#fff';
		label_node.style.color='#000';
		gnum--;
		alert(gnum);
	}
}

// End
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

