function saveallianceandlastyear(){
var typeGraph='AllianceWiseBar';
var newurlh="method=saveData&graphType="+typeGraph;
for(var aa=0;aa<namesarrayalliance.length;aa++){
var names=namesarrayalliance[aa];
var namesac=namesarrayalliance[aa];
if (document.getElementById(names+"2004").value=='')  document.getElementById(names+"2004").value=0;
if (document.getElementById(names+"lead").value=='')  document.getElementById(names+"lead").value=0;
if (document.getElementById(names+"won").value=='')  document.getElementById(names+"won").value=0;
if (namesac=='Others') namesac='Fourth Front';
    newurlh=newurlh+"&pname"+(aa+1)+"="+namesac+"-@@-"+document.getElementById(names+"2004").value+"-@@-"+document.getElementById(names+"lead").value+"-@@-"+document.getElementById(names+"won").value+"-@@-Y";
}
saveallianceandlastyearajax(typeGraph,newurlh);
}

function saveallianceandlastyearajax(typeGraph,newurlh){
xmlHttp.open("POST", "/cmsadmin/generalElectionresult2009.do",  true); 
xmlHttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");
xmlHttp.onreadystatechange =processStateChangealliance;
xmlHttp.send(newurlh);
//alert(newurlh);
}

function processStateChangealliance(){
if(xmlHttp.readyState  == 4 && xmlHttp.status  == 200) {
alert("Data submitted and graph made sucessfully");
}
}


function savePartyWise(){
var typeGraph='PartyWiseBar';
var newurlh="method=saveData&graphType="+typeGraph;
for(var aa=0;aa<namesarrayPartyWise.length;aa++){
var names=namesarrayPartyWise[aa];
var namesac=namesarrayPartyWise[aa];
if (document.getElementById(names+"2004").value=='')  document.getElementById(names+"2004").value=0;
if (document.getElementById(names+"lead").value=='')  document.getElementById(names+"lead").value=0;
if (document.getElementById(names+"won").value=='')  document.getElementById(names+"won").value=0;
if (namesac=='OthersY') namesac='Others';
    newurlh=newurlh+"&pname"+(aa+1)+"="+namesac+"-@@-"+document.getElementById(names+"2004").value+"-@@-"+document.getElementById(names+"lead").value+"-@@-"+document.getElementById(names+"won").value+"-@@-Y";
}
savePartyWiseajax(typeGraph,newurlh);
}

function savePartyWiseajax(typeGraph,newurlh){

xmlHttp.open("POST", "/cmsadmin/generalElectionresult2009.do",  true); 
xmlHttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");
xmlHttp.onreadystatechange =processStateChangeP;
xmlHttp.send(newurlh);
//alert(newurlh);
}

function processStateChangeP(){
if(xmlHttp.readyState  == 4 && xmlHttp.status  == 200) {
alert("Data submitted and graph made sucessfully");
}
}



function onlysomeNumberAllowed(obj){
    var nums="0123456789";
    if (obj.value==''){ 
    obj.value=0;
    return;
    }
    var fstr="";
    var i=0;
    for(var i=0;i<obj.value.length;i++){
     if (nums.indexOf(obj.value.charAt(i))!=-1){
      fstr=fstr+obj.value.charAt(i);
    }
   }
   obj.value=fstr;
   if (obj.value==''){ 
    obj.value=0;
   }
   //alert(fstr);
}  

var xmlHttp;
function createXmlHttpObject(){
if (window.XMLHttpRequest){     // Object of the current windows
    xmlHttp = new XMLHttpRequest();     // Firefox, Safari, ...
   } 
   else if (window.ActiveXObject){   // ActiveX version
    xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");  // Internet Explorer 
    } 
  return xmlHttp;
 }

xmlHttp=createXmlHttpObject();
function watchgraph(){
    var paths="<img src='/mnc/images/AllianceWiseBar2009.jpg' width='500' height='200'><br>";
    paths=paths+"<img src='/mnc/images/PartyWisePie2009.jpg' width='500' height='200'><br>";
    paths=paths+"<img src='/mnc/images/PartyWiseYearBar2009.jpg' width='500' height='200'><br>";
    paths=paths+"<img src='/mnc/images/PartyWiseBar2009.jpg' width='500' height='200'><br>";
    
    document.getElementById("graphsimg").innerHTML=paths;
}
function hidegraph(){
document.getElementById("graphsimg").innerHTML="";
}

function saveStatewiseData(){
var newurlh="method=saveDataState";
if (document.getElementById("selectstate").selectedIndex==0){
document.getElementById("selectstate").focus();
alert('please select state name');
return;
}
if (document.getElementById("selectpartyName").selectedIndex==0){
document.getElementById("selectpartyName").focus();
alert('please select party name');
return;
}
if (document.getElementById("Contested2004new").value=='')  document.getElementById("Contested2004new").value=0;
if (document.getElementById("Won2004new").value=='')  document.getElementById("Won2004new").value=0;
if (document.getElementById("Contested20009new").value=='')  document.getElementById("Contested20009new").value=0;
if (document.getElementById("Won2009new").value=='')  document.getElementById("Won2009new").value=0;
    newurlh=newurlh+"&pname"+1+"="+document.getElementById("selectpartyName").value+"-@@-"+document.getElementById("Contested2004new").value+"-@@-"+
             document.getElementById("Won2004new").value+"-@@-"+
             document.getElementById("Contested20009new").value+"-@@-"+
             document.getElementById("Won2009new").value+"-@@-"+
             document.getElementById("selectstate").value+"-@@-";
            
saveStatewiseDataajax(newurlh);

}

function saveStatewiseDataajax(newurlh){
xmlHttp.open("POST", "/cmsadmin/generalElectionresult2009.do",  true); 
xmlHttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");
xmlHttp.onreadystatechange =processStateChangestate;
xmlHttp.send(newurlh);
}

function processStateChangestate(){
if(xmlHttp.readyState  == 4 && xmlHttp.status  == 200) {
alert("Data submitted sucessfully.");
}
}

function fetchResultstate(){
if (document.getElementById("selectstate").selectedIndex==0){
return;
}
if (document.getElementById("selectpartyName").selectedIndex==0){
return;
}

var newurlh="method=getStateWiseData";
newurlh=newurlh+"&partyName="+document.getElementById("selectpartyName").value;
newurlh=newurlh+"&stateid="+document.getElementById("selectstate").value;
fetchdataStatewiseDataajax(newurlh);

}
function fetchdataStatewiseDataajax(newurlh){
xmlHttp.open("POST", "/cmsadmin/generalElectionresult2009.do",  true); 
xmlHttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");
xmlHttp.onreadystatechange =processStateChangeFetch;
xmlHttp.send(newurlh);
}

function processStateChangeFetch(){
if(xmlHttp.readyState  == 4 && xmlHttp.status  == 200) {
var res=xmlHttp.responseXML;
    if (res!=null && res.getElementsByTagName("c2004")[0]!=null
        && res.getElementsByTagName("w2004")[0] && res.getElementsByTagName("w2009")[0]
        &&  res.getElementsByTagName("c2004")[0]){
      document.getElementById("Contested2004new").value=res.getElementsByTagName("c2004")[0].childNodes[0].nodeValue;
      document.getElementById("Won2004new").value=res.getElementsByTagName("w2004")[0].childNodes[0].nodeValue;
      document.getElementById("Contested20009new").value=res.getElementsByTagName("c2009")[0].childNodes[0].nodeValue;
      document.getElementById("Won2009new").value=res.getElementsByTagName("w2009")[0].childNodes[0].nodeValue
}
}
}
