// JScript fucntions to be called from each calculator.htm
// This code will be written, maintained and IP of niro solutions.
// The code is provded for completeness.

function SaveResults (){
    // Call save function to save answer
    var f=document.forms.frmName
    if (document.domain == getDomain() || document.domain == 'localhost'){
        sUpdate = CallServerFunc("http://" + getUrl() + "?Func=SaveCCData&txtIncomeG=" + f.txtIncomeG.value + "&cmbIncomeG=" + f.idIncomeG.value + "&txtIncomeI=" + f.txtIncomeI.value + "&cmbIncomeI=" + f.cmbIncomeI.value + "&txtIncomeO=" + f.txtIncomeO.value + "&txtIncomeF=" + f.txtIncomeF.value + "&txtCont=" + f.txtCont.value + "&cmbCont=" + f.idCont.value + "&Result1=" + TotalIncome + "&Result2=" + TotalCont + "&Result3=" + CoCont + "&Result4=" + MaxCont+ "&Result5=" + MaxCoCont)
        window.alert(sUpdate)
    }
    save=true
}

function LoadResults(){
    // Call get data function to prepopulate
    var f=document.forms.frmName
    if (document.domain == getDomain() || document.domain == 'localhost'){
        sUpdate = CallServerFunc("http://" + getUrl() + "?Func=GetCCData")
        
        if (FindResult(sUpdate, 1) > 0) {
            f.txtIncomeG.value = FindResult(sUpdate, 1)
        }
        if (FindResult(sUpdate, 2) > 0) {
            f.idIncomeG.value = FindResult(sUpdate, 2)
        }
        if (FindResult(sUpdate, 3) > 0) {
            f.txtIncomeI.value = FindResult(sUpdate, 3)
        }
        if (FindResult(sUpdate, 4) > 0) {
            f.idIncomeI.value = FindResult(sUpdate, 4)
        }
        if (FindResult(sUpdate, 5) > 0) {
            f.txtIncomeO.value = FindResult(sUpdate, 5)
        }
        if (FindResult(sUpdate, 6) > 0) {
            f.txtIncomeF.value = FindResult(sUpdate, 6)
        }
        if (FindResult(sUpdate, 7) > 0) {
            f.txtCont.value = FindResult(sUpdate, 7)
        }
        if (FindResult(sUpdate, 5) > 0) {
            f.idCont.value = FindResult(sUpdate, 8)
        }
    }
}

function CallServerFunc(sCall) {
    //functions call asp.net page to 
    var xmlRequest;
    try { xmlRequest = new ActiveXObject("Msxml2.XMLHTTP"); }
    catch (e) { try { xmlRequest = new ActiveXObject("Microsoft.XMLHTTP"); }
    catch (e) { try { xmlRequest = new XMLHttpRequest(); }
    catch (e) { xmlRequest = false; }}}
    if (!xmlRequest) {return null;}
try//250511
{
    xmlRequest.open("GET", sCall, false);
    xmlRequest.send(null);
    return xmlRequest.responseText;
}
catch(e)
{
return ""
}
}

function FindResult(sResultString, iIndex){
    
    var iFound = 0
    var iFoundOld = 0
    var sResult = ""
    
    for(iCount=0;iCount<iIndex;iCount++)
	{
	    iFoundOld = iFound
	    iFound = sResultString.indexOf(";", iFoundOld + 1)
	}
	
	if (iFoundOld == 0)
	{
	    sResult = sResultString.slice(iFoundOld , iFound)
	}else
	{
	sResult = sResultString.slice(iFoundOld + 1, iFound)
	}
	if (sResult == ''){
	    sResult="0"
	}
	return sResult
}


