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

EstimationPayment.setPayment=function(actualPay)
{
	document.getElementById("paymentSide2").style.backgroundImage="url('images/pyBG2.png')";
	document.getElementById('custImg').src="images/custImg.png";
	//gamePageId=gameId;
	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<6)
		{
			if(i<3)
			{
				div.setAttribute("class","noPadding  notesClass col-xs-4 col-sm-4 col-md-4 col-lg-4");
				mainDiv=document.getElementById("notes1");
			}
			else
			{
				div.setAttribute("class","noPadding  notesClass col-xs-4 col-sm-4 col-md-4 col-lg-4");
				mainDiv=document.getElementById("notes2");
			}
			img=document.createElement('img');
			img.setAttribute("id","returnMoneyImg"+(i+1));
			img.setAttribute("class","noPadding noteImg col-xs-10 col-sm-10 col-md-10 col-lg-10 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);
		}
		else
		{
			div.setAttribute("class","noPadding col-xs-11 col-sm-11 col-md-11 col-lg-11 col-xs-offset-1 col-sm-offset-1 col-lg-ofset-1 col-md-offset-1");
			mainDiv=document.getElementById("coins");
			img=document.createElement('img');
			img.setAttribute("id","returnMoneyImg"+(i+1));
			img.setAttribute("class","noPadding coinImg 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);
		}
		
	}
	document.getElementById('clearReturns').src="images/resetbutton.png";
	document.getElementById('submitbtn').src="images/tickbutton.png";
}


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('paidNoteImg').src="images/"+EstimationPayment.totalPayByCust+"rs.png";
	//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");
	span.setAttribute("class","returnMoneyClass");
	text=document.createTextNode(value+"+");
	span.appendChild(text);
	document.getElementById("returnMoneyCount").appendChild(span);
	document.getElementById("totalReturn").innerHTML="="+EstimationPayment.totalReturn;
}
EstimationPayment.clearReturns=function()
{
	document.getElementById("totalReturn").innerHTML="= 0";
	document.getElementById("returnMoneyCount").innerHTML="";
	EstimationPayment.totalReturn=0;
}

EstimationPayment.checkResult=function()
{
	if(EstimationPayment.actualPay==EstimationPayment.totalPayByCust-EstimationPayment.totalReturn)
		alert("correct");
	else
		alert("worng");
		
	//EstimationPayment.actualPay=Math.floor(Math.random() *150);
	console.log(EstimationPayment.actualPay);
	EstimationPayment.totalPayByCust=0;
	EstimationPayment.clearReturns();
	//EstimationPayment.selectNoteCustPay();
	document.getElementById('payment').style.display="none";
	//gamePageId.style.display="block";
	Laddoo.nextQuestion();
	
}
EstimationPayment.checkResultOfNothing=function()
{
	EstimationPayment.clearReturns();
	EstimationPayment.checkResult();
}
