﻿// JScript File

function getPriceText(price)
{	
	
	retText="";
	price_array = price.split(",");
	price_length = price_array.length;
	price = "";
	for(i = 0;i < price_length; i++)
	{
		price += price_array[i];
	}
	lprice = price.length;
	
	if(price == 0)
	{
		retText += "Price should be greater than '0'";
	}
	
	
	else
	{
		if(lprice>=12)
		{
				retText+="Price is too big. Please contact us";
		}
		else if(lprice==11)
		{
			retText+=price.substr(0,2)+" Billion ";
			if(price.substr(2,2)!="00")
				retText+=price.substr(2,2)+" Crore ";
			if(price.substr(4,2)!="00")
				retText+=price.substr(4,2)+" Lakh";
			if(price.substr(6,2)!="00" && price.substr(6,1)!="0")
				retText+=" and "+price.substr(6,2)+" Thousand";
			if(price.substr(6,2)!="00" && price.substr(6,1)=="0")
				retText+=" and "+price.substr(7,1)+" Thousand";
		}
		else if(lprice==10)
		{
			retText+=price.substr(0,1)+" Billion ";
			if(price.substr(1,2)!="00")
				retText+=price.substr(1,2)+" Crore ";
			if(price.substr(3,2)!="00")
				retText+=price.substr(3,2)+" Lakh";
				
			if(price.substr(5,2)!="00" && price.substr(5,1)!="0")
				retText+=" and "+price.substr(5,2)+" Thousand";
			if(price.substr(5,2)!="00" && price.substr(5,1)=="0")
				retText+=" and "+price.substr(6,1)+" Thousand";
		}
		else if(lprice==9)
		{
			retText+=price.substr(0,2)+" Crore ";
			if(price.substr(2,2)!="00")
				retText+=price.substr(2,2)+" Lakh";
			if(price.substr(4,2)!="00" && price.substr(4,1)!="0")
				retText+=" and "+price.substr(4,2)+" Thousand";
			if(price.substr(4,2)!="00" && price.substr(4,1)=="0")
				retText+=" and "+price.substr(5,1)+" Thousand";
		}
		
		else if(lprice==8)
		{
			retText+=price.substr(0,1)+" Crore ";
			if(price.substr(1,2)!="00")
				retText+=price.substr(1,2)+" Lakh";
			if(price.substr(3,2)!="00" && price.substr(3,1)!="0")
				retText+=" and "+price.substr(3,2)+" Thousand";
			if(price.substr(3,2)!="00" && price.substr(3,1)=="0")
				retText+=" and "+price.substr(4,1)+" Thousand";
		}
	
		else if(lprice==7)
		{
			retText+=price.substr(0,2)+" Lakh";
	
			if(price.substr(2,2)!="00" && price.substr(2,1)!="0")
				retText+=" and "+price.substr(2,2)+" Thousand";
			if(price.substr(2,2)!="00" && price.substr(2,1)=="0")
				retText+=" and "+price.substr(3,1)+" Thousand";
	
		}	
		else if(lprice==6)
		{
			
				retText+=price.substr(0,1)+" Lakh";
			
			if(price.substr(1,2)!="00" && price.substr(1,1)!="0")
				retText+=" and "+price.substr(1,2)+" Thousand";
			if(price.substr(1,2)!="00" && price.substr(1,1)=="0")
				retText+=" and "+price.substr(2,1)+" Thousand";
		}
		else if(lprice==5)
		{

			if(price.substr(0,2)!="00" && price.substr(0,1)!="0")
				retText+=price.substr(0,2)+" Thousand(s)";
			if(price.substr(0,1)=="0" && price.substr(1,1)!="0") 
				retText+=price.substr(1,1)+" Thousand(s)";
				
				
		}
		else if(lprice==4)
		{
		
			if(price.substr(0,1)!="0" && price.substr(0,2)!="00")
				retText+=price.substr(0,1)+" Thousand(s)";
				
			
		}
		else if(lprice<=3)
		{
			retText+="Price Should be in thousands";
		}
		
		if(lprice<12)
				retText+=" PKR";
	}
	return retText;
	
}//End of Function

function showPrice()
{
    var price = document.getElementById("txtPrice").value;
    var status;
    
    if(isNaN(price))
    {
        status = "<font color=\"red\">Price must contain numbers only</font>";
    }
    else
    {
        status = getPriceText(price);
    }
    
    document.getElementById("spnPrice").innerHTML = status;
}