// toggle visibility 

function toggle( targetId ){
  if (document.getElementById){
  		target = document.getElementById( targetId );
                        alert (target.style.display);
  			if (target.style.display == "none"){
  				target.style.display = "";
  			} else {
  				target.style.display = "none";
  			}
  	}
}

// image switcher

function showPic (whichpic) {
	if (document.getElementById) {
 		document.getElementById('imgtitle').childNodes[0].nodeValue = whichpic.childNodes[0].nodeValue;
		document.getElementById('mainscreen').src = whichpic.href;
		if (whichpic.title) {
  			document.getElementById('desc').childNodes[0].nodeValue = whichpic.title;
  		} else {
			document.getElementById('desc').childNodes[0].nodeValue = whichpic.childNodes[0].nodeValue;
		}
		return false;
	} else {
		return true;
	}
}

// school selector

function mychange(schoolid) {
	if (schoolid != "") {
   		window.open ('http://www.infodirect.us/' + schoolid);
	}
}

function formatCurrency(num) {
   num = num.toString().replace(/\$|\,/g,'');
   if(isNaN(num))
      num = "0";
   sign = (num == (num = Math.abs(num)));
   num = Math.floor(num*100+0.50000000001);
   cents = num%100;
   num = Math.floor(num/100).toString();
   if(cents<10)
      cents = "0" + cents;
   for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
      num = num.substring(0,num.length-(4*i+3))+','+
      num.substring(num.length-(4*i+3));
   return (((sign)?'':'-') + '$' + num + '.' + cents);
}

////////////////////////////////////////////////////////////////////////////////
   // only used on /support/infodirect/index.php
function calcInfoDirect() {
   IDfinanced = (document.idsignup.IDfinanced.value);
   IDpricedWithK = (document.idsignup.IDpricedWithK.value);
   
   if (IDfinanced==1)   IDfinanced=true;     else IDfinanced=false;
   if (IDpricedWithK==1)IDpricedWithK=true;  else IDpricedWithK=false;
   
   enrollNum  = ((!document.getElementById('enrollNum1'))?0:parseInt((!document.getElementById('enrollNum1').value?0:document.getElementById('enrollNum1').value)));
   enrollNumK = ((!document.getElementById('enrollNum2'))?0:parseInt((!document.getElementById('enrollNum2').value?0:document.getElementById('enrollNum2').value)));
   x = enrollNum + enrollNumK;
   
   if (document.idsignup.totalEnrollment[0]) enrollAll = ((document.idsignup.totalEnrollment[0].checked)?true:false);
   else                                      enrollAll = true;
   
   devs = document.getElementById('Devotionals').checked;
   bans = document.getElementById('Bannerads').checked;

   if (IDfinanced) {
      switch(true) {
         case ((0 < x) && (x <= 350)):
            rate = .50;
            break;
         case ((350 < x) && (x <= 500)):
            rate = .44;
            break;
         case ((500 < x) && (x <= 800)):
            rate = .38;
            break;
         case (800 < x):
            rate = .31;
            break;
         default:
            rate = .50;
      }
   } else {
      switch(true) {
         case ((0 < x) && (x <= 350)):
            rate = 8;
            break;
         case ((350 < x) && (x <= 500)):
            rate = 7;
            break;
         case ((500 < x) && (x <= 800)):
            rate = 6;
            break;
         case (800 < x):
            rate = 5;
            break;
         default:
            rate = 8;
      }
   }

   totalBeforeDisc = ((enrollNum * rate) + (enrollNumK * (rate * .5))); //regular rate (includes k5 at half price)
   //alert("before: "+enrollNum+"+"+enrollNumK+"="+x+"\n"+"("+enrollNum+" * "+rate+") + ("+enrollNumK+" * ("+rate+" * .5))"+"="+totalBeforeDisc);
   totalAfterDisc = ((enrollAll)?(totalBeforeDisc - (totalBeforeDisc * .25)):totalBeforeDisc);  // discount: 25% off
   
   if (IDfinanced) { // FINANCED CALCULATION
      totalMonthly = totalBeforeDisc;
      totalFirstMonth = ((devs)?(totalMonthly+35):totalMonthly);  // devotional: $35
      totalFirstMonth = ((bans)?(totalFirstMonth+60):totalFirstMonth);  // banner: $60
      
      if(document.getElementById('monthlytotal'))
         document.getElementById('monthlytotal').value = formatCurrency(totalMonthly);   // format output for monthly amount (if applicable)
      if(document.getElementById('firstMonth'))
         document.getElementById('firstMonth').value = formatCurrency(totalFirstMonth);   // format output for monthly amount (if applicable)
   }// end: if IDfinanced
   total = ((devs)?(totalAfterDisc+35):totalAfterDisc);  // devotional: $35
   total = ((bans)?(total+60):total);  // banner: $60

   document.getElementById('total').value = formatCurrency(total);   // format output for yearly amount (if applicable)
   
}
////////////////////////////////////////////////////////////////////////////////

function noKifIDfinanced_calcInfoDirect() {
   IDfinanced = (document.getElementById('enrollNum2')?0:1);
   // only used on /support/infodirect/index.php
if (IDfinanced == 0) {
   enrollNum = ((document.getElementById('enrollNum1').value=="")?0:parseInt(document.getElementById('enrollNum1').value));
   enrollNumK = ((document.getElementById('enrollNum2').value=="")?0:parseInt(document.getElementById('enrollNum2').value));
   x = enrollNum + enrollNumK;
   
   enrollAll = ((document.idsignup.totalEnrollment[0].checked)?true:false);
   devs = document.getElementById('Devotionals').checked;
   bans = document.getElementById('Bannerads').checked;

   switch(true) {
      case ((0 < x) && (x <= 350)):
         rate = 8;
         break;
      case ((350 < x) && (x <= 500)):
         rate = 7;
         break;
      case ((500 < x) && (x <= 800)):
         rate = 6;
         break;
      case (800 < x):
         rate = 5;
         break;
      default:
         rate = 8;
   }

   totalBeforeDisc = ((enrollNum * rate) + (enrollNumK * (rate * .5))); //regular rate (includes k5 at half price)
   total = ((enrollAll)?(totalBeforeDisc - (totalBeforeDisc * .25)):totalBeforeDisc);  // discount: 25% off
   total = ((devs)?(total+35):total);  // devotional: $35
   total = ((bans)?(total+60):total);  // banner: $60
   
} else { // FINANCED CALCULATION
   enrollNum = ((document.getElementById('enrollNum1').value=="")?0:parseInt(document.getElementById('enrollNum1').value));
   devs = document.getElementById('Devotionals').checked;
   bans = document.getElementById('Bannerads').checked;
   rate = .5;
   
   total = enrollNum * rate; //regular rate (includes k5 at half price)
   total = ((devs)?(total+35):total);  // devotional: $35
   total = ((bans)?(total+60):total);  // banner: $60
   totalMonthly = (enrollNum * rate)/12;
   totalFirstMonth = ((devs)?(totalMonthly+35):totalMonthly);  // devotional: $35
   totalFirstMonth = ((bans)?(totalFirstMonth+60):totalFirstMonth);  // banner: $60
   
   document.getElementById('monthlytotal').value = formatCurrency(totalMonthly);   // format output for monthly amount (if applicable)
   document.getElementById('firstMonth').value = formatCurrency(totalFirstMonth);   // format output for monthly amount (if applicable)
   
} // end: if IDfinanced

   document.getElementById('total').value = formatCurrency(total);   // format output for yearly amount (if applicable)
   
}
////////////////////////////////////////////////////////////////////////////////

// page redirect

function move(url) {
	window.location = url;
}
var timer = null;

