var EstimationPayment={};
EstimationPayment.totalPayByCust=0;
EstimationPayment.totalReturn=0;
EstimationPayment.actualPay=0;
//EstimationPayment.actualPay=Math.floor(Math.random() *150);

EstimationPayment.setPayment=function(actualPay)
{
	document.body.style.backgroundImage="url(images/background2.jpg)";
	EstimationPayment.actualPay=actualPay;
	EstimationPayment.selectNoteCustPay();
}

EstimationPayment.setPaymentData=function()
{

	EstimationPayment.setNoteForReturn();
}

EstimationPayment.setNoteForReturn=function()
{
	var i=0,coin=0,notes=3,mainDiv;
	for(i=0;i<9;i++)
	{
		div=document.createElement('div');
		div.setAttribute("id","returnMoney"+(i+1));
		if(i>4)
		{
			div.setAttribute("class","noPadding col-xs-3 col-sm-3 col-md-3 col-lg-3");
			mainDiv=document.getElementById("note");
		}
		else
		{
			if(i==4)
				div.setAttribute("class","noPadding col-xs-4 col-sm-4 col-md-4 col-lg-4");
			else
				div.setAttribute("class","noPadding col-xs-2 col-sm-2 col-md-2 col-lg-2");
			mainDiv=document.getElementById("coins");
		}
		img=document.createElement('img');
		img.setAttribute("id","returnMoneyImg"+(i+1));
		img.setAttribute("class","noPadding col-xs-12 col-sm-12 col-md-12 col-lg-12 img-responsive"); 
		img.setAttribute("src","images/"+EstimationPayment.moneyImages[i]);
		img.setAttribute("onclick","EstimationPayment.returnMoneyCount(this.id)");
		img.setAttribute("value",EstimationPayment.moneyValues[i]);
		div.appendChild(img);
		mainDiv.appendChild(div);
	}
}


EstimationPayment.selectNoteCustPay=function()
{
	var moneyArray=[10,20,50,100,200,500,2000];
	while(1)
	{
		EstimationPayment.totalPayByCust = moneyArray[Math.floor(Math.random() * moneyArray.length)];
		console.log(EstimationPayment.totalPayByCust);
		if(EstimationPayment.totalPayByCust>=EstimationPayment.actualPay)
		{
			console.log("break");
			break;
		}	
	}
	document.getElementById("custGive").innerHTML="customer Gives Rs."+EstimationPayment.totalPayByCust;
	document.getElementById("cost").innerHTML="Cost="+EstimationPayment.actualPay;
}

EstimationPayment.returnMoneyCount=function(returnID)
{
	var value=0,span=0,text;
	value=document.getElementById(returnID).getAttribute('value');
	EstimationPayment.totalReturn=EstimationPayment.totalReturn+parseInt(value);
	span=document.createElement("span");
	text=document.createTextNode(value+"+");
	span.appendChild(text);
	document.getElementById("returnMoneyCount").appendChild(span);
	document.getElementById("totalReturn").innerHTML="Total="+EstimationPayment.totalReturn;
}
EstimationPayment.clearReturns=function()
{
	document.getElementById("totalReturn").innerHTML="Total=0";
	document.getElementById("returnMoneyCount").innerHTML="";
	EstimationPayment.totalReturn=0;
}

EstimationPayment.checkResult=function()
{

	if(EstimationPayment.actualPay==EstimationPayment.totalPayByCust-EstimationPayment.totalReturn)
	{alert("correct");
	reset();}
	else
		alert("wrong");	
	
	EstimationPayment.totalPayByCust=0;
	EstimationPayment.clearReturns();
	//EstimationPayment.selectNoteCustPay();
	//document.getElementById('payment').style.display="none";
	//document.getElementById('payment').style.display="block";
	//document.getElementById('gamepage').style.display="block";
	//

}
EstimationPayment.checkResultOfNothing=function()
{
	EstimationPayment.clearReturns();
	EstimationPayment.checkResult();
}
