var chk="begin ";
var stk = "begin ";
var ctk ="begin";
function selectCity(ob)
{

    var rem = "," + ob.value ;
	if(ob.checked)
	{
		ctk+= rem;
		
	}
	else
	{

       ctk =ctk.replace(rem,"");
	}
window.document.getElementById("cityList").value= ctk;
var aj="";
//aj=window.document.getElementById("cityList").value;

}
function selectState(ob)
{
    var rem = "," + ob.value ;
	if(ob.checked)
	{
		stk+= rem;
		
	}
	else
	{

       stk =stk.replace(rem,"");
	}

document.getElementById('stateList').value= stk;
//alert(stk);
//clearCity();
showCity(stk);
}
function addCity(ob)
{
	var rem = "," + ob.value ;
	if(ob.checked)
	{
		chk+= rem;
		var cityCount=parseInt(document.getElementById('selected_cities').value) + 1;	
	}
	else
	{
       chk =chk.replace(rem,"");
	   var cityCount=parseInt(document.getElementById('selected_cities').value) - 1;	  
	}
document.getElementById('cityList').value= chk;


var days =parseInt(document.getElementById('days').value);
var charges = (cityCount*days*3);
var disco =  (discount(days,charges));
var totalValue= charges - disco;

showValues(cityCount,charges,disco,totalValue);

}
function showValues(cityCount,charges,disco,totalValue)
{
	document.getElementById('selected_cities').value = (cityCount);
	document.getElementById('charges').value = "$"+charges+".00";	
	document.getElementById('discount').value = "$"+disco+".00";
	document.getElementById('totalValue').value =  "$"+totalValue+".00";	

}
function discount(days,charges)
{
	var disco = 0;
	days = parseInt(days);
	if(days >=20 && days< 50)
	{
		disco =charges*10/100;
	}
	if(days>=50 && days< 100)
	{
		disco =charges*15/100;
	}
	if(days>=100 && days< 200)
	{
		disco =charges*20/100;
	}
	if(days>200)
	{
		disco =charges*25/100;
	}
	return disco;
}
function changeDay(days)
{
	var cityCount=parseInt(document.getElementById('selected_cities').value);

	if(cityCount!=0)
	{
		var charges = (cityCount*days*3);
		var disco = discount(days,charges);
		var totalValue= charges - disco;
		showValues(cityCount,charges,disco,totalValue);
		
	}
}
function clearCity()
{
	//alert(document.getElementById('cityList').value);
	//alert(document.getElementById('stateList').value);
    chk="begin ";
    stk = "begin ";
	ctk ="begin";
	window.document.getElementById("cityList").value="";
	document.getElementById('selected_cities').value = 0;
	document.getElementById('charges').value = "";	
	document.getElementById('discount').value = "";
	document.getElementById('totalValue').value =  "";	

}




