var cVAT=1 + (1/100);;
var cSilverDuty=1030;
var cGoldDuty=20600;

function recalc(sym)
{
	var mtl=sym.substr(0,3);
	var inr=parseFloat(document.getElementById("INR_A_RC").innerHTML);
	if(mtl=='INR' || mtl=='XAU'){
		var value=parseFloat(document.getElementById("XAU_A_RC").innerHTML);		
		var prm=getValue("PRMXAU");
		if(!isNaN(value) && !isNaN(inr) && !isNaN(prm)){
			var c=(((value +prm) * 0.03199 * inr) + (cGoldDuty / 1000))* cVAT;
			c*=100;
			c=Math.round(c);
			c/=100;
			document.getElementById("calcXAU995").innerHTML=c;
			var c=(((value +prm) * 0.0321507 * inr) + (cGoldDuty / 1000))* cVAT;
			c*=100;
			c=Math.round(c);
			c/=100;
			document.getElementById("calcXAU999").innerHTML=c;
		}
	}
	if(mtl=='INR' || mtl=='XAG'){
		var value=parseFloat(document.getElementById("XAG_A_RC").innerHTML);		
		var prm=getValue("PRMXAG");
		if(!isNaN(value) && !isNaN(inr) && !isNaN(prm)){
			var c=(((value +prm) * 32.1507 * inr) + cSilverDuty)* cVAT;
			c*=100;
			c=Math.round(c);
			c/=100;
			document.getElementById("calcXAG").innerHTML=c;
		}
	}
}

function getValue(s)
{
	var res=NaN;
	var o=document.getElementById(s);
	if(o!=null)
	{
		if(o.value!="")
		{
			res=parseFloat(o.value);
			if (isNaN(res))res=0;
		}
		else res=0;
	}
	return res;
}

function sc(d)
{
	var c=document.getElementById("calculator");
	if(c!=null)c.style.display=(d?"":"none");
}

var dragapproved=false;
var dragElement=null;
var origX=-1;
var x=-1;
var origY=-1;
var y=-1;

function pop_mv(e) {
	setupEventObject(e);	
  if ((window.event.button == 1 || window.event.button == 0) && dragapproved) {
		var tmpX=parseInt(origX) + window.event.clientX - x;
		var tmpY=parseInt(origY) + window.event.clientY - y;
		dragElement.style.left = tmpX +"px";
		dragElement.style.top = tmpY +"px";
		return false;
  }
}

function setupEventObject(e)
{
	if (!e) return; // IE returns
	// Map NS event object to IEs
	window.event=e;
	window.event.fromElement=e.target;
	window.event.toElement=e.target;
	window.event.srcElement=e.target;
	window.event.x=e.x;
	window.event.y=e.y;	
}

function drg_dwn(e) {
	setupEventObject(e);
  if (window.event.srcElement.className == "pop_drag") {		
    dragapproved = true;
    dragElement = window.event.srcElement;		
    origX = dragElement.style.left;
		origX=origX.replace("px","");
    x = window.event.clientX;
		origY = dragElement.style.top;
		origY=origY.replace("px","");
    y = window.event.clientY;
    document.onmousemove = pop_mv;
  }
}

function drg_up() {  
	dragElement = null;
  dragapproved = false;  
}

document.onmousedown = drg_dwn;
document.onmouseup = drg_up;