﻿    function ValidateForm() {
        //if(document.forms[0].State.selectedIndex==0 && document.forms[0].Chain.selectedIndex==0) {
        //    alert("Please select a chain or a state.");
        //    return false;
        //} 
        document.forms[0].action="Historical.aspx";
        document.forms[0].submit();
    }
    
    function SelectAll() {
        for (e=0;e<document.form1.elements.length;e++) {
  	        if(document.form1.elements[e].type == "checkbox") {
	  		    document.form1.elements[e].checked=true;
            }
         }
     }
     
     function SaveToMyTS() {
        document.form1.action = "SaveToMyTS.aspx";
        document.form1.submit();
     }
     
     function WriteXLS() {
        var state = document.form1.State.options[document.form1.State.selectedIndex].text;
        var chain = document.form1.Chain.options[document.form1.Chain.selectedIndex].text;
        var title = "Historical Averages for ";
        if(document.form1.Chain.selectedIndex != 0) title+= chain + " stops";
        if(document.form1.Chain.selectedIndex != 0 && document.form1.State.selectedIndex != 0) title += " in ";
        if(document.form1.State.selectedIndex != 0) title += state;
        document.form1.DataTitle.value = title;
        document.form1.DataText.value = document.getElementById("ResultsContent").innerHTML;
        //document.form1.target="_blank";
       // document.form1.action = "XLS.aspx";
        //document.form1.submit();
     }
     
     function SendMail() {
        document.getElementById("Wait").innerHTML = "<img src=\"images/loading.gif\">";
        var state = document.form1.State.options[document.form1.State.selectedIndex].text;
        var chain = document.form1.Chain.options[document.form1.Chain.selectedIndex].text;
        var title = "Historical Averages for ";
        if(document.form1.Chain.selectedIndex != 0) title+= chain + " stops";
        if(document.form1.Chain.selectedIndex != 0 && document.form1.State.selectedIndex != 0) title += " in ";
        if(document.form1.State.selectedIndex != 0) title += state;
        document.form1.DataTitle.value = title;
        document.form1.DataText.value = escape(document.getElementById("ResultsContent").innerHTML);
        SendPOSTRequest(emailurl,buildEmailString());
        document.form1.DataText.value="";
        
     }

