$(document).ready(fun10);
//<div hind="slider" class="sliderBg" StartValue="500000" EndValue="200000000" DiffValue="600000"  CurrentValueTo="#txtLoanAmt"><img src="Scroll_Red1.jpg" /></div></td>
function fun10()
{
  $("DIV[hind='slider']").each(function () {
        startValue = parseFloat($(this).attr("StartValue"));
        endValue = parseFloat($(this).attr("EndValue"));
        unitValue = parseFloat($(this).attr("DiffValue"));
        size = parseFloat($(this).attr("Size"));

        if (startValue == null || isNaN(startValue)) { startValue = 0; }
        if (endValue == null || unitValue == null || isNaN(endValue) || isNaN(unitValue)) 
              alert("Dost, Add kar na value for EndValue or DiffValue")
        
        var width = ((endValue - startValue) / unitValue) * size;
        $(this).width(width) 
        
        if (size != 0 || size != 1) { $(this).attr("ValueChange",1); }
        
        } ).mousedown(sliderMouseDown).mouseup(sliderMouseUp).mousemove(sliderMouseMove);       
}

var unitValue, startValue, currentStartPos, leftPos, currentValue, size;
var mouseDown = false;
function sliderMouseDown() { mouseDown = true; }
function sliderMouseUp() { mouseDown = false; }
  
function sliderMouseMove(evt) {
  if (mouseDown)
  { 
    currentStartPos = $(this).offset().left;
    if (evt.pageX - currentStartPos <= $(this).width()) {
      leftPos = evt.pageX - currentStartPos;
      $(this).children("IMG").css("left", leftPos);
      
      startValue = parseFloat($(this).attr("StartValue"));
      unitValue = parseFloat($(this).attr("DiffValue"));
      size = parseFloat($(this).attr("Size"));
      
      if (startValue == null || isNaN(startValue)) { startValue = 0; }
      //var unitValue = (endValue - startValue) / ($("DIV[hind='slider']").width());//UnitValue must always be in mutiple of width of Slider bar
      
      if (size != 0 || size != 1) {
        var cv = parseFloat($(this).attr("ValueChange"));
        if (cv < size) {
          $(this).attr("ValueChange",cv+1);
        }
        else {
          currentValue = unitValue * (leftPos) / size + startValue;
          $(this).attr("ValueChange",1);
        }
      }
      else {
        currentValue = unitValue * leftPos + startValue;
      }
      $(this).attr("value",currentValue);
      
      if ($(this).attr("CurrentValueTo") != null) {
        $($(this).attr("CurrentValueTo")).val(currentValue);
      }
      Calculate();
    }
  }
}
///////////////////////
$(window).load(Accord);

function Accord() {
    $("#divAcc > div > div").slideUp("fast");
    $("#divAcc div:last-child > div").slideDown("fast");
    $("#divAcc > div > h6").bind("click",headClick)
}

function headClick() {
    $("#divAcc > div > div").slideUp("fast");
    $(this).next().slideDown("slow");
}
/////////////////////
//Calculation for EMI
function Calculate()
{
    var p = parseFloat($('#txtLoanAmt').val());
    var m = parseFloat($('#txtMonths').val());
    var r = parseFloat($('#txtPercen').val())/1200;
    
    var emi = Math.round((p*r* Math.pow(1+r,m) ) / (Math.pow(1+r,m)-1));
    if (!isNaN(emi))
        $("#txtEmi").val(emi);
}

function msg(txt)
{
  $("#msg").html($("#msg").text() + "  ; <br /> " + txt); 
}
