function toggleMe(a){
  var e=document.getElementById(a);
  if(!e)return true;
  if(e.style.display=="none"){
    e.style.display="block"
  } else {
    e.style.display="none"
  }
  return true;
}

function selectIt(id)
{
	document.getElementById(id).focus();
    document.getElementById(id).select();
}

function copyToClip(id) {
	document.getElementById(id).focus();
   document.getElementById(id).select();
   CopiedTxt = document.selection.createRange();
   CopiedTxt.execCommand("Copy");
  }

var f=10;
function IsNumeric(sText)
{
   var ValidChars = "0123456789.";
   var IsNumber=true;
   var Char;

 
   for (i = 0; i < sText.length && IsNumber == true; i++) 
      { 
      Char = sText.charAt(i); 
      if (ValidChars.indexOf(Char) == -1) 
         {
         IsNumber = false;
         }
      }
   return IsNumber;
   
   }
function CheckCommaIndex(sText)
{

   var Char;
   var amount;
    amount=0;
	var che=0;
 
   for (i = 0; i < sText.length ; i++) 
      { 

      		Char = sText.charAt(i); 
			if (Char == "." )
			{
				che=1;
				return amount;
				
			}
			else
			{
				amount = amount + 1;
			}		
      
      }
	  if (che==0 )
	  {
	  	
		return amount;
	  }
}

function mc()
{
	
	if (mpAmount.value==null || mpAmount.value<1) 
	{
		alert ("Value Must be Numeric one")
		mpAmount.value=null;
	}
	else if (IsNumeric(mpAmount.value)==false)
	{
		alert ("Value Must be Numeric one")
		mpAmount.value=null;
	}
	else if (IsNumeric(mpAmount2.value)==false)
	{
		alert ("Value Must be Numeric one")
		mpAmount2.value=null;
	}

	else if (IsNumeric(mpAmount3.value)==false)
	{
		alert ("Value Must be Numeric one")
		mpAmount3.value=null;
	}
	else if (IsNumeric(mpAmount4.value)==false)
	{
		alert ("Value Must be Numeric one")
		mpAmount4.value=null;
	}

	else if (mpAmount2.value==null )
	{
		alert ("Value Must be Numeric one")
		mpAmount2.value=null;
	}
	else if (mpAmount2.value<0 || mpAmount2.value>100)
	{
		alert ("value Must not be great then 100 and less then 0")
		mpAmount2.value=null;
	}
	
	else if (mpAmount4.value<0 || mpAmount4.value>100)
	{
		alert ("Value Must not be great then 100 and less then 0")
		mpAmount4.value=null;
	}
	else if (mpAmount3.value==null || mpAmount3.value<=0)
	{
		alert ("Value Must be Numeric one")
		mpAmount3.value=null;
	}
	
	else if (mpAmount4.value==null)
	{
		alert ("Value Must be Numeric one")
		mpAmount4.value=null;
	}
	else
	{
		var mpriAmount=mpAmount3.value;
		var down=mpAmount4.value;
		var downres =(mpriAmount/100)*down;
		mrAmount.value=Math.round(downres*100)/100;
		mrAmount1.value=Math.round((mpriAmount-downres)*100)/100;
	
		var intrate=mpAmount2.value/1200;
		var uppRes=intrate*mrAmount1.value;
		var subbtRes=1+intrate;
		var bRes= 1-(Math.pow(subbtRes,-(mpAmount.value*12)));
		var tRes=uppRes/bRes;
		mrAmount2.value=Math.round(tRes*100)/100;
		var d=CheckCommaIndex(mrAmount2.value);
		//var decimal=((parseInt(rAmount2.value.length)) - (parseInt(CheckCommaIndex(rAmount2.value))+ 1));
		
		function a(place,r)
		{
			var dec;
			var final;
			final="";
			var check=5;
		
				dec=parseInt(place) - 1;						
			

			var count;
			count=0;
			for (i=dec; i>=0; i--)
			{
				count=count+1;
				final= r.charAt(i) + final;

				if (count==3 && i >=1)
				{					
					final= "," + final;					
				}
				if (count==check && i >=1)
				{
					final= "," + final;
					check=parseInt(check) +2;
				}				
			}
		
		return final;
		}
		
		function aa(len,len2,str,str1)
		{
			var resu;
			resu=str1;
			for(i=len2; i <=parseInt(len)-1; i++)
			{
				resu=resu + (str.charAt(i));
			}
			return resu;
		}
		
		var res= a(d,mrAmount2.value);
	    //alert(res);
		mrAmount2.value=aa(mrAmount2.value.length,d,mrAmount2.value,res);		
		
		var dd=CheckCommaIndex(mrAmount1.value);
		res= a(dd,mrAmount1.value);
		mrAmount1.value=aa(mrAmount1.value.length,dd,mrAmount1.value,res);		
			
		dd=CheckCommaIndex(mrAmount.value);
		res= a(dd,mrAmount.value);
		mrAmount.value=aa(mrAmount.value.length,dd,mrAmount.value,res);		
	
		
		
		
	}
	
}