var dateFlag=0;
var ajax=new Array();


function showReading(cityCode,fdate,tdate){
var index = ajax.length;
if(dateFlag==0){
var chkFrom=document.getElementById('chkFrom').value;
var chkTo=document.getElementById('chkTo').value;
if(fdate==chkFrom && tdate==chkTo)
	return;
}
dateFlag=0;

var lodingId=document.getElementById('lodingimgBtn');
lodingId.style.visibility='visible';
ajax[index] = new sack();	
ajax[index].requestFile = 'getWholeStation.php?cId='+escape(cityCode)+'&fdate='+escape(fdate)+'&tdate='+escape(tdate);	
//alert(ajax[index].requestFile);
ajax[index].onCompletion = function(){ 
results=ajax[index].response;
lodingId.style.visibility='hidden';
document.getElementById('democitystation').style.visibility='visible';
document.getElementById('dispWhole').style.visibility='visible';
document.getElementById('dispWhole').innerHTML=results;
};	
ajax[index].runAJAX();		// Execute AJAX function
}

function getwholeStationList(ele){

var cityCode=ele.options[ele.selectedIndex].value;
//alert(cityCode);
var citynameSpan=document.getElementById('cityNameSpan');
if(cityCode=='-1')return;
if(citynameSpan.innerHTML==ele.options[ele.selectedIndex].text)return;
var fdate=document.getElementById('toadydemoDate').value;
var tdate=document.getElementById('backdemoDate').value;
if(cityCode.length>0){
cityCode=cityCode;
citynameSpan.innerHTML=ele.options[ele.selectedIndex].text;
dateFlag=1;
showReading(cityCode,fdate,tdate);}
}


function getStation(ele){

var cityCode=ele.options[ele.selectedIndex].value;
var citynameSpan=document.getElementById('stationNameSpan');
if(cityCode=='-1')return;
if(citynameSpan.innerHTML==ele.options[ele.selectedIndex].text)return;
var fdate=document.getElementById('toadydemoDate').value;
var tdate=document.getElementById('backdemoDate').value;
if(cityCode.length>0){
cityCode=cityCode;
citynameSpan.innerHTML=ele.options[ele.selectedIndex].text;
dateFlag=1;
showStation(cityCode,fdate,tdate);}
}

function getYear(ele1,ele2)
{
		var fromy=ele1.options[ele.selectedIndex].value;
		var toy=ele2.options[ele.selectedIndex].value;
		alert(fromy);
		alert(toy);
}

function ClickHereToPrint(printdivId,index,pageTitle){
try{
var oIframe = document.getElementById('ifrmPrint'+index);
var printDiv=document.getElementById('printShow'+index);
var cName=document.getElementById('cityNameSpan').innerHTML;
var pContent=printDiv.innerHTML;
printDiv.innerHTML='';
var oContent = document.getElementById(printdivId).innerHTML;
var oDoc = (oIframe.contentWindow || oIframe.contentDocument);
if (oDoc.document) oDoc = oDoc.document;
oDoc.write("<html><head><link href=\"demoCMS/css/print_css.css\" rel=\"stylesheet\" type=\"text/css\">");
oDoc.write("</head><body onload='this.focus(); this.print();'><center><div style='font-weight:bold;font-size:15px;text-align:center;' >"+pageTitle+cName+"</div>");
oDoc.write(oContent + "</center></body></html>");
oDoc.close();
printDiv.innerHTML=pContent;
}
catch(e){
self.print();
}
}

function storethisform3(cityId){
	alert(cityId);
if(cityId!='#'){
var tObj=document.getElementById('knowcityTable');
for(i=0;i<tObj.rows.length;i++){
for(j=0;j<tObj.rows[i].cells.length;j++){
tObj.rows[i].cells[j].disabled=true;
}
}
window.location='demostore.php?cId='+escape(cityId);
}

}


////////////// Water Readings Display ////////////////

function getWtrStationList(ele){

var cityCode=ele.options[ele.selectedIndex].value;
//alert(cityCode);
//var citynameSpan=document.getElementById('cityNameSpan');
if(cityCode=='-1')return;
//if(citynameSpan.innerHTML==ele.options[ele.selectedIndex].text)return;
var fdate=document.getElementById('toadydemoDate').value;
var tdate=document.getElementById('backdemoDate').value;
if(cityCode.length>0){
cityCode=cityCode;
//citynameSpan.innerHTML=ele.options[ele.selectedIndex].text;
dateFlag=1;
swReading(cityCode,fdate,tdate);}
}

function swReading(cityCode,fdate,tdate){
if(cityCode==''){alert('Please Select Station !!!'); return;};
if(fdate=='-1'){alert('Invalid "From Year" Selection !!!'); return;}
if(tdate=='-1'){alert('Invalid "To Year" Selection !!!'); return;}
if(fdate>tdate){alert('Invalid Year Selection !!!'); return;}
var index = ajax.length;
var lodingId=document.getElementById('lodingimgBtn');
lodingId.style.visibility='visible';
document.getElementById('drpdemocname').disabled=true;
document.getElementById('fromy').disabled=true;
document.getElementById('toy').disabled=true;
document.getElementById('shwRead').disabled=true;

ajax[index] = new sack();	
ajax[index].requestFile = 'getWaterStation.php?cId='+escape(cityCode)+'&fdate='+escape(fdate)+'&tdate='+escape(tdate);	
//alert(ajax[index].requestFile);
ajax[index].onCompletion = function(){ 
results=ajax[index].response;
//alert(results);

document.getElementById('drpdemocname').disabled=false;
document.getElementById('fromy').disabled=false;
document.getElementById('toy').disabled=false;
document.getElementById('shwRead').disabled=false;
lodingId.style.visibility='hidden';

document.getElementById('democitystation').style.visibility='visible';
document.getElementById('dispWhole').style.visibility='visible';
document.getElementById('dispWhole').innerHTML=results;
};	
ajax[index].runAJAX();		// Execute AJAX function
}