﻿/***
 * Generic calculator scripts, to handle visibility of sections of the  
 * calculator, using ajax to load certain parts of the calculator to the 
 * page, etc.
 *************************************************************************/
 
 function GetSalaryDD(name)
 {
    toggle(name);
    y = document.getElementById('calcYear').value;
    op = document.getElementById('schemePlan').value;
    zss = "A";
    
    makeRequest('CMSAjax.aspx?Action=Salary&year='+y+'&option='+op+'&zss='+zss);
 }
 
 function toggle(name)
 {
    document.getElementById(name).style.display='inline';
 }
 
 function Process()
 {
    y = document.getElementById('calcYear').value;
    p = document.getElementById('schemePlan').value;
    i = document.getElementById('cbsalary').value;
    
    selectors = document.getElementsByTagName('select');
    
    ad = selectors[selectors.length - 2].value;
    cd = selectors[selectors.length - 1].value;
    
    makeRequest("CMSAjax.aspx?Action=PCalculator&year="+y+"&plan="+p+"&income="+i+"&ad="+ad+"&cd="+cd);
    
    return false;
 }
 

//-----------------------------------------------------------------
//AJAX SPECIFIC FUNCTION
//-----------------------------------------------------------------
var xmlHttp, res;

function GetXmlHttpObject(){
    var xmlHttp = null;
    if(window.XMLHttpRequest){
        xmlHttp = new XMLHttpRequest();
    } else if ( window.ActiveXObject ){
        xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
    }
    return xmlHttp;
}


function makeRequest(url)
{
    xmlHttp = GetXmlHttpObject();
    if (url.match("Salary") != null)
        xmlHttp.onreadystatechange = function () {
            if (xmlHttp.readyState === 4) {
                document.getElementById('salband').innerHTML = xmlHttp.responseText;
            }
        };
    else
        xmlHttp.onreadystatechange = function () {
            if (xmlHttp.readyState === 4) {
                //this section is for displaying on the screen the results                
                document.getElementById('result').innerHTML = xmlHttp.responseText;
                var boxdiv = document.getElementById('resultDiv');
                boxdiv.style.backgroundColor = "#E5EBF1";
                boxdiv.style.padding = "8px";
                //toggle('resultDiv');
            }
        };
    xmlHttp.open('GET', url, true);
    xmlHttp.send(null);
}



