﻿// JScript File


       function txtPacket_Change()
         {
         var txtPersonValue=0;
         var txtPacketValue=0;
         var CalculatedValue=0;
         
         
         document.getElementById("spnTopTextBox").firstChild.nodeValue=ClickHandler.ReadTopValueTextFile().value;
         
         txtPersonValue=document.getElementById("txtPerson").value;
         txtPacketValue=document.getElementById("txtPacket").value;
         if(txtPersonValue.length<=0 || txtPacketValue.length<=0 ||isNaN(txtPersonValue)|| isNaN(txtPacketValue) )
         CalculatedValue=0;
         else
         CalculatedValue=txtPersonValue* txtPacketValue;
        
         
         
         if(document.getElementById("divCalc")!=null &&  document.getElementById("divCalc").firstChild!=null)
         document.getElementById("divCalc").firstChild.nodeValue=CalculatedValue;
         if( document.getElementById("spnLabelPacket")!=null && document.getElementById("spnLabelPacket").firstChild!=null && document.getElementById("topDescriptionValue5")!=null)
         document.getElementById("spnLabelPacket").firstChild.nodeValue=" "+document.getElementById("topDescriptionValue5").firstChild.nodeValue + " a" +" ";
         else if( document.getElementById("spnLabelPacket")!=null && document.getElementById("spnLabelPacket").firstChild && document.getElementById("pnlDiv5")!=null)
         {
         document.getElementById("spnLabelPacket").firstChild.nodeValue=" "+document.getElementById("pnlDiv5").firstChild.nodeValue + " a" +" ";
         }
         }
         
         
         
  function showHideContent(obj)
{
 
if(obj==1)
{
document.getElementById("divJulkort"+2).style.display="none";
document.getElementById("divJulkort"+3).style.display="none";
document.getElementById("divJulkort"+4).style.display="none";

}
else if(obj==2)
{
document.getElementById("divJulkort"+1).style.display="none";
document.getElementById("divJulkort"+3).style.display="none";
document.getElementById("divJulkort"+4).style.display="none";
 
}
else if(obj==3)
{
document.getElementById("divJulkort"+1).style.display="none";
document.getElementById("divJulkort"+2).style.display="none";
document.getElementById("divJulkort"+4).style.display="none";

}
else
{
document.getElementById("divJulkort"+1).style.display="none";
document.getElementById("divJulkort"+2).style.display="none";
document.getElementById("divJulkort"+3).style.display="none";

}
if(document.getElementById("divJulkort"+obj)!=null && document.getElementById("divJulkort"+obj).style.display=="none")
 document.getElementById("divJulkort"+obj).style.display="block";
 ClickHandler.SaveSelectedOptionValueToDatabase(TemplateId,"divJulkort"+obj);
 ClickHandler.SaveSelectedOptionValueToTextFileFromDatabase("divJulkort"+obj);
 var indexValue=ClickHandler.GetCalculatorIndexForSelectedTemplateOption("divJulkort"+obj);
 if(indexValue!=null)
 indexValue=indexValue.value;
  Next_Click(indexValue);
 
}



function Next_Click_SaveToChoosedTemplate()
{
 var totalCount=ClickHandler.GetCountCalculatorUsed(43);
 var ChkId=null;
 indexCalculator++;

if(indexCalculator<=totalCount.value)
{
ChkId=ClickHandler.GetSiteMapIdForSelectDescription(43,indexCalculator)
}
else
{
indexCalculator=0;
ChkId=ClickHandler.GetSiteMapIdForSelectDescription(43,1)
}
if(indexCalculator==0)
indexCalculator=1;
ClickHandler.SaveSelectedCalculatorIndexToDatabase(TemplateId,indexCalculator);
var dataTableDescription=ClickHandler.GetDescriptionFromJavascript(ChkId.value);
 var myDataTable=dataTableDescription.value;
 if(myDataTable.Rows.length>0)
 {
 if(document.getElementById("topDescriptionValue1")!=null )
 {
 if(document.getElementById("txtPacket")!=null)
 document.getElementById("txtPacket").value="";
 if(document.getElementById("txtPerson")!=null)
 document.getElementById("txtPerson").value="";
 if(document.getElementById("divCalc")!=null)
 document.getElementById("divCalc").innerText="";
 if(document.getElementById("spnLabelPacket")!=null)
 document.getElementById("spnLabelPacket").innerText="";
 
 if(myDataTable.Rows[0]!=null)
 document.getElementById("topDescriptionValue1").innerHTML=myDataTable.Rows[0].BriefDescription;

 if(myDataTable.Rows[1]!=null)
 document.getElementById("topDescriptionValue2").innerHTML=myDataTable.Rows[1].BriefDescription;
 if(myDataTable.Rows[2]!=null)
 document.getElementById("topDescriptionValue3").innerHTML=myDataTable.Rows[2].BriefDescription;
 if(myDataTable.Rows[3]!=null)
 document.getElementById("topDescriptionValue4").innerHTML=myDataTable.Rows[3].BriefDescription;
 if(myDataTable.Rows[4]!=null)
 document.getElementById("topDescriptionValue5").innerHTML=myDataTable.Rows[4].BriefDescription;
 }
  }



}

 function Next_Click(idxValue)
  {
  var totalCount=ClickHandler.GetCountCalculatorUsed(43);
  var ChkId=null;

if(idxValue<=totalCount.value)
{
ChkId=ClickHandler.GetSiteMapIdForSelectDescription(43,idxValue)
}
else
{
 ChkId=ClickHandler.GetSiteMapIdForSelectDescription(43,1)
}
var dataTableDescription=ClickHandler.GetDescriptionFromJavascript(ChkId.value);
 var myDataTable=dataTableDescription.value;
 if(myDataTable.Rows.length>0)
 {
 if(document.getElementById("topDescriptionValue1")!=null )
 {
 if(document.getElementById("txtPacket")!=null)
 document.getElementById("txtPacket").value="";
 if(document.getElementById("txtPerson")!=null)
 document.getElementById("txtPerson").value="";
 if(document.getElementById("divCalc")!=null)
 document.getElementById("divCalc").innerText="";
 if(document.getElementById("spnLabelPacket")!=null)
 document.getElementById("spnLabelPacket").innerText="";
 
 if(myDataTable.Rows[0]!=null)
 document.getElementById("topDescriptionValue1").innerHTML=myDataTable.Rows[0].BriefDescription;
 if(myDataTable.Rows[1]!=null)
 document.getElementById("topDescriptionValue2").innerHTML=myDataTable.Rows[1].BriefDescription;
 if(myDataTable.Rows[2]!=null)
 document.getElementById("topDescriptionValue3").innerHTML=myDataTable.Rows[2].BriefDescription;
 if(myDataTable.Rows[3]!=null)
 document.getElementById("topDescriptionValue4").innerHTML=myDataTable.Rows[3].BriefDescription;
 if(myDataTable.Rows[4]!=null)
 document.getElementById("topDescriptionValue5").innerHTML=myDataTable.Rows[4].BriefDescription;
 }
  }
}

          
          function calculate_total()
          {         
                  var txtPersonValue=0;
                   var txtPacketValue=0;
                  var CalculatedValue=0;
                  var TotalCalculatedValue=0;
                  var bonus1=0;
                  
                  txtPersonValue=document.getElementById("txtPerson").value;
                 txtPacketValue=document.getElementById("txtPacket").value;
                 if(txtPersonValue.length<=0 || txtPacketValue.length<=0 ||isNaN(txtPersonValue)|| isNaN(txtPacketValue) )
                   CalculatedValue=0;
                 else
                  CalculatedValue=txtPersonValue* txtPacketValue;
                   bonus1=calculate_bonus(CalculatedValue);
                   
                if( document.getElementById("txtTopValue")!=null )
                 var val= document.getElementById("txtTopValue").value;
                 val=ClickHandler.ReadTopValueTextFile().value;
                if(isNaN(val) || val.length<=0)
                   TotalCalculatedValue=0;
                else
                TotalCalculatedValue=(CalculatedValue * val)+ bonus1;
                document.getElementById("spnAfterButtonClick").firstChild.nodeValue=TotalCalculatedValue;
          }
         
         
         
         function  calculate_bonus(value)
         {
         var bonus=0;
         
         if(value<200) bonus=0;
         
         else if(value>=200 && value<=299) bonus=200;
         
         else if (value>=300 && value<=399) bonus=400;
         
          else if (value>=400 && value<=499) bonus=500;
          
          else if (value>=500 && value<=599) bonus=600;
          
          else if (value>=600 && value<=699) bonus=700;
          
          else if (value>=700 && value<=799) bonus=800;
          
          else if (value>=800 && value<=899) bonus=900;
          
          else if (value>=900 && value<=999) bonus=1000;         
          
else
{

bonus = truncate(value.toString());
bonus= bonus + 200;

}
          
          return bonus;  
         

         
         }
         
         
         
function truncate(result)
{
    var i;
   
    
    var temp1=result.length-2;

    
    var temp2=result.charAt(0)+result.charAt(1);

 
for(i=1; i<=temp1; i++) temp2=temp2+0;

return (parseInt(temp2));




}


    
