// JavaScript Document
function showhide()
{
	for (var i =0; i<document.formID.additional_entry.length; i++) 
	{
		if (document.formID.additional_entry[i].checked) 
		{
			var val = parseInt(document.formID.additional_entry[i].value);
		}	
	}
	if(val==1)
	{
		document.getElementById("myshow1").style.visibility='visible';
		document.getElementById("myshow2").style.visibility='hidden';
	}
	else if(val==0)
	{
		document.getElementById("myshow1").style.visibility='hidden';
		document.getElementById("myshow2").style.visibility='visible';
	}
}

function security_show_hide()
{
	var val=document.formID.currency.value;
	if(val=="INR")
	{
		document.getElementById("security").style.display='block';
	}
	else if(val=="USD")
	{
		document.getElementById("security").style.display='none';
	}
}

function mycal()
{
	document.getElementById("raw_cost").value=parseFloat(document.getElementById("raw_cost").value);
	document.getElementById("shell_cost").value=parseFloat(document.getElementById("shell_cost").value);



	for (var i =0; i<document.formID.additional_entry.length; i++) 
	{
		if (document.formID.additional_entry[i].checked) 
		{
			var val = parseInt(document.formID.additional_entry[i].value);
		}	
	}
	if(val==1)
		var noofaddentry=document.formID.number_additional_entry.value;
	else
		var noofaddentry=document.formID.number_additional_entry2.value;
	var currency=document.formID.currency.value;

	if(currency=="INR")
	{
		document.formID.additional_entry_cost.value=noofaddentry*500;
		if(!isNaN(document.getElementById('rawspace').value))
		{
			document.getElementById("raw_cost").value=roundVal(parseFloat(document.getElementById("rawspace").value)*parseFloat('10500'));
		}
		else
		{
			document.getElementById("raw_cost").value=parseFloat('0.00');
		}
		if(!isNaN(document.getElementById('shellspace').value))
		{
			document.getElementById("shell_cost").value=roundVal(parseFloat(document.getElementById("shellspace").value)*parseFloat('11500'));
		}
		else
		{
			document.getElementById("shell_cost").value=parseFloat('0.00');
		}
	}
	else if(currency=="USD")
	{
		document.formID.additional_entry_cost.value=noofaddentry*15;
		if(!isNaN(document.getElementById('rawspace').value))
		{
			document.getElementById("raw_cost").value=roundVal(parseFloat(document.getElementById("rawspace").value)*parseFloat('275'));
		}
		else
		{
			document.getElementById("raw_cost").value=parseFloat('0.00');
		}
		if(!isNaN(document.getElementById('shellspace').value))
		{
			document.getElementById("shell_cost").value=roundVal(parseFloat(document.getElementById("shellspace").value)*parseFloat('300'));
		}
		else
		{
			document.getElementById("shell_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 raw_cost=document.getElementById("raw_cost").value;
	var shell_cost=document.getElementById("shell_cost").value;
	var discount=0;

	if(document.getElementById("earlybird_discount"))
	{
		discount=roundVal(((parseFloat(raw_cost)+parseFloat(shell_cost))*10)/100);
		document.getElementById("earlybird_discount").value=discount;
	}
	else
	{
		discount=0;
	}


	var netspace_charges=parseFloat(raw_cost)+parseFloat(shell_cost)-parseFloat(discount);
	document.getElementById("netspace_charges").value=netspace_charges;

	var servicetax=roundVal((netspace_charges*10.3)/100);
	document.getElementById("servicetax").value=servicetax;

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

	var additional_entry_cost=parseFloat(document.getElementById("additional_entry_cost").value);

	if(currency=="INR")
	{
		document.getElementById("security_deposit").value=roundVal((netspace_charges*10)/100);
		var security_deposit=document.getElementById("security_deposit").value;
	}
	else if(currency=="USD")
	{
		document.getElementById("security_deposit").value=parseFloat('0');
		var security_deposit=document.getElementById("security_deposit").value;
	}



	document.getElementById("net_amount_payable").value=roundVal(parseFloat(netspace_charges)-parseFloat(servicetax)+parseFloat(catalogue_entry_charges)+parseFloat(additional_entry_cost)+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("raw_cost").value=parseFloat(document.getElementById(fld).value)*parseFloat('10500');
			}
			else
			{
				document.getElementById("raw_cost").value=parseFloat('0.00');
			}
		}
		else if(fld=="shellspace")
		{
			if(!isNaN(document.getElementById(fld).value))
			{
				document.getElementById("shell_cost").value=parseFloat(document.getElementById(fld).value)*parseFloat('11500');
			}
			else
			{
				document.getElementById("shell_cost").value=parseFloat('0.00');
			}
		}
	}
	else if(currency=="USD")
	{
		if(fld=="rawspace")
		{
			if(!isNaN(document.getElementById(fld).value))
			{
				document.getElementById("raw_cost").value=parseFloat(document.getElementById(fld).value)*parseFloat('275');
			}
			else
			{
				document.getElementById("raw_cost").value=0.00;
			}
		}
		else if(fld=="shellspace")
		{
			if(!isNaN(document.getElementById(fld).value))
			{
				document.getElementById("shell_cost").value=parseFloat(document.getElementById(fld).value)*parseFloat('300');
			}
			else
			{
				document.getElementById("shell_cost").value=0.00;
			}
		}
	}
	calculate();	
}


function validate2fields()
{
	var error="";
	var rawspace=$("#rawspace").val();
	var shellspace=$("#shellspace").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($("#shellspace").val()!="(Only Numeric Value not less than 9)")
	{
		if(shellspace.match(numericExpression))
		{
			if(shellspace<9)
				error+="Value Should Not be Less than 9";
		}
		else
		{
			error+="Numbers Only\n";
		}
	}
	if($("#rawspace").val()=="(Only Numeric Value not less than 27)" && $("#shellspace").val()=="(Only Numeric Value not less than 9)")
	{
		error+="Either Select Raw Space or Shell Space\n";
	}

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

