﻿function showManuscripts()
{
  document.all("divManuscript").style.display = "inline";
}


function hideManuscripts()
{
  document.all("divManuscript").style.display = "none";
}


function calcTotalSelected( f )
{  
  var elem = f.elements;
  var SelectedCheckBoxIndices = new Array();  
  var Counter = 0;
  var PriceArray = new Array();  
  var txtTotalDue = null;
  var txtTotalRegistrationField = null;
  var txtOriginalTotalField = null;
  
  for(var i=0;i<elem.length;i++)
  {
    if ( elem[i].type == "checkbox" && elem[i].id.indexOf("dnsCheckBoxList1") >= 0 )
    {      
      if ( elem[i].checked )
      {
        var LastIndex = elem[i].id.lastIndexOf("_");
        var ClientID = elem[i].id.substring(LastIndex+1);
        SelectedCheckBoxIndices[Counter] = ClientID;        
        Counter++;
      }  
    } 
    else if ( elem[i].type == "text" )
    {
        if ( elem[i].id.indexOf("txtFeesDue") != -1 )
        txtTotalDue = document.getElementById(elem[i].id);
        
        if ( elem[i].id.indexOf("Total1") != -1 )
        txtTotalRegistrationField = document.getElementById(elem[i].id);
    }
    else if ( elem[i].type == "hidden" )
    {
      if ( elem[i].id.indexOf("hidAcademyPrices") >= 0 )
      {
        PriceArray = elem[i].value.split(',');
      }
            
      if ( elem[i].id.indexOf("hidTotalRegistrationFeesOriginal") != -1 )
      txtOriginalTotalField = document.getElementById(elem[i].id);
    } 
  }
    
  var Total = 0.00;
    
  // Loop through selected checkbox indices
  // Assumption: the length of the SelectedCheckBoxIndices array 
  // and PriceArray are the same size
  for(var i=0;i<SelectedCheckBoxIndices.length;i++)
  {
    Total += parseFloat(PriceArray[SelectedCheckBoxIndices[ i ]]);
  }
  
  if ( txtOriginalTotalField != null )
  {
    txtTotalRegistrationField.value = formatCurrency( Total + parseFloat(txtOriginalTotalField.value) );    
  }
  
  txtTotalDue.value = formatCurrency(Total);
}



function resetPrice( f )
{
  var elem = f.elements;
  
  for(var i=0;i<elem.length;i++)
  {
    if ( elem[i].type == "text" && elem[i].id.indexOf("txtFeesDue") >= 0 )
    {
      elem[i].value = formatCurrency(parseFloat("0.00"));
    }
  }  
}



// Formatting functions
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);
}



// Trim functions
function Trim(TRIM_VALUE)
{
  if(TRIM_VALUE.length < 1)
  {
    return"";
  }

  TRIM_VALUE = RTrim(TRIM_VALUE);
  TRIM_VALUE = LTrim(TRIM_VALUE);

  if(TRIM_VALUE=="")
  {
    return "";
  }
  else
  {
    return TRIM_VALUE;
  }
}

function RTrim(VALUE)
{
  var w_space = String.fromCharCode(32);
  var v_length = VALUE.length;
  var strTemp = "";
  if(v_length < 0)
  {
    return"";
  }
  
  var iTemp = v_length -1;

  while(iTemp > -1)
  {
    if(VALUE.charAt(iTemp) == w_space)
    {
    }
    else
    {
    strTemp = VALUE.substring(0,iTemp +1);
    break;
    }
    
    iTemp = iTemp-1;

  } //End While
  
  return strTemp;

} //End Function

function LTrim(VALUE)
{
  var w_space = String.fromCharCode(32);
  if(v_length < 1)
  {
  return"";
  }

  var v_length = VALUE.length;
  var strTemp = "";
  var iTemp = 0;

  while(iTemp < v_length)
  {
    if(VALUE.charAt(iTemp) == w_space)
    {
    }
    else
    {    
      strTemp = VALUE.substring(iTemp,v_length);
      break;
    }
    
    iTemp = iTemp + 1;
  } //End While
  
  return strTemp;
} //End Function