// JavaScript Document

function mycal()
{
	//document.getElementById("rawspace_cost").value=parseFloat(document.getElementById("rawspace_cost").value);
	//document.getElementById("builtupspace_cost").value=parseFloat(document.getElementById("builtupspace_cost").value);



	var currency=document.formID.currency.value;

	if(currency=="INR")
	{
		if(!isNaN(document.getElementById('rawspace').value))
		{
			document.getElementById("rawspace_cost").value=roundVal(parseFloat(document.getElementById("rawspace").value)*parseFloat('8500'));
		}
		else
		{
			document.getElementById("rawspace_cost").value=parseFloat('0.00');
		}
		if(!isNaN(document.getElementById('builtupspace').value))
		{
			document.getElementById("builtupspace_cost").value=roundVal(parseFloat(document.getElementById("builtupspace").value)*parseFloat('9000'));
		}
		else
		{
			document.getElementById("builtupspace_cost").value=parseFloat('0.00');
		}
	}
	else if(currency=="USD")
	{
		if(!isNaN(document.getElementById('rawspace').value))
		{
			document.getElementById("rawspace_cost").value=roundVal(parseFloat(document.getElementById("rawspace").value)*parseFloat('275'));
		}
		else
		{
			document.getElementById("rawspace_cost").value=parseFloat('0.00');
		}
		if(!isNaN(document.getElementById('builtupspace').value))
		{
			document.getElementById("builtupspace_cost").value=roundVal(parseFloat(document.getElementById("builtupspace").value)*parseFloat('300'));
		}
		else
		{
			document.getElementById("builtupspace_cost").value=parseFloat('0.00');
		}
	}
	
	calculate();
}





function roundVal(val){
	var dec = 2;
	var result = Math.round(val*Math.pow(10,dec))/Math.pow(10,dec);
	return result;
}

function calculate()
{
	var currency=document.formID.currency.value;
	var rawspace_cost=document.getElementById("rawspace_cost").value;
	var builtupspace_cost=document.getElementById("builtupspace_cost").value;

	var netspace_charges=parseFloat(rawspace_cost)+parseFloat(builtupspace_cost);

	var servicetax=roundVal((netspace_charges*10.3)/100);

	document.getElementById("servicetax").value=servicetax;

	document.getElementById("security_deposit").value=roundVal((netspace_charges*10)/100);
	var security_deposit=document.getElementById("security_deposit").value;


	if(currency=="INR")
	{
		document.getElementById("catalogue_entry_charges").value=parseFloat('1000');
		var catalogue_entry_charges=document.getElementById("catalogue_entry_charges").value;
	}
	else if(currency=="USD")
	{
		document.getElementById("catalogue_entry_charges").value=parseFloat('25');
		var catalogue_entry_charges=document.getElementById("catalogue_entry_charges").value;
	}


	document.getElementById("net_amount_payable").value=roundVal(parseFloat(netspace_charges)+parseFloat(servicetax)+parseFloat(catalogue_entry_charges)+parseFloat(security_deposit));

}

function space_cost(fld, val)
{
	var currency=document.formID.currency.value;
	if(currency=="INR")
	{
		if(fld=="rawspace")
		{
			if(!isNaN(document.getElementById(fld).value))
			{
				document.getElementById("rawspace_cost").value=parseFloat(document.getElementById(fld).value)*parseFloat('8500');
			}
			else
			{
				document.getElementById("rawspace_cost").value=parseFloat('0.00');
			}
		}
		else if(fld=="builtupspace")
		{
			if(!isNaN(document.getElementById(fld).value))
			{
				document.getElementById("builtupspace_cost").value=parseFloat(document.getElementById(fld).value)*parseFloat('9000');
			}
			else
			{
				document.getElementById("builtupspace_cost").value=parseFloat('0.00');
			}
		}
	}
	else if(currency=="USD")
	{
		if(fld=="rawspace")
		{
			if(!isNaN(document.getElementById(fld).value))
			{
				document.getElementById("rawspace_cost").value=parseFloat(document.getElementById(fld).value)*parseFloat('275');
			}
			else
			{
				document.getElementById("rawspace_cost").value=0.00;
			}
		}
		else if(fld=="builtupspace")
		{
			if(!isNaN(document.getElementById(fld).value))
			{
				document.getElementById("builtupspace_cost").value=parseFloat(document.getElementById(fld).value)*parseFloat('300');
			}
			else
			{
				document.getElementById("builtupspace_cost").value=0.00;
			}
		}
	}
	calculate();	
}


function validate2fields()
{
	var error="";
	var rawspace=$("#rawspace").val();
	var builtupspace=$("#builtupspace").val();
	var numericExpression = /^[0-9]+$/;
	if($("#rawspace").val()!="(Only Numeric Value not less than 27)")
	{
		if(rawspace.match(numericExpression))
		{
			if(rawspace<27)
				error+="Value Should Not be Less than 27";
		}
		else
		{
			error+="Numbers Only\n";
		}
	}
	if($("#builtupspace").val()!="(Only Numeric Value not less than 9)")
	{
		if(builtupspace.match(numericExpression))
		{
			if(builtupspace<9)
				error+="Value Should Not be Less than 9";
		}
		else
		{
			error+="Numbers Only\n";
		}
	}
	if($("#rawspace").val()=="(Only Numeric Value not less than 27)" && $("#builtupspace").val()=="(Only Numeric Value not less than 9)")
	{
		error+="Either Select Raw Space or Builtup Space\n";
	}

	if((rawspace!="(Only Numeric Value not less than 27)" && builtupspace!="(Only Numeric Value not less than 9)"))
	{
		if(rawspace!="" || builtupspace!="")
		{
			error+="Either Select Raw Space or Builtup Space\n";
		}
	}
	if(error=="")
	{
		//return true;
	}
	else
	{
		return error;
	}
}

