function switchCalc() {
    if (cookieSummaryCalc == 'true') {
        optFormSummary.switchState();
        optFormDetailed.switchState();
        cookieSummaryCalc= 'false';
    }
    else {
        optFormDetailed.switchState();
        optFormSummary.switchState();
        cookieSummaryCalc= 'true';
    }
    createCookie("cookieSummaryCalc",cookieSummaryCalc,0.5);
    return false;
}

function resetCalc(){
    var optionForm=document.getElementById('optionInput');
    var n, fields;
    if(optionForm!=null){

        fields= optionForm.elements;
        n=fields.length;

        var i, fieldId, cookie;
        for (i=0; i<n; i++ ){
            fieldId=fields[i].id;
            cookie= readCookie(fieldId);
            if(cookie!=null) eraseCookie(fieldId);
        }
    }
    window.location=(window.location).toString().replace(/#/, "");
    return false;
}

function checkInput(field, low, lowStrict, high, highStrict){

    if(field.type=="submit" || field.type=="hidden" || field.type=="select"){
        validated=true;
        return false;
    }

    if(!IsNumeric(field.value)){
        alert("The input is not a number.");
        field.value=tempValue;
        validated=true;
        return false;
    }

    var currValue=field.value.toString();
    if(currValue.match("%")){
        currValue=currValue.replace(/%/, "");
        currValue=currValue/100;
    }

    if( (lowStrict==false && currValue<low) ||
        (lowStrict==true && currValue<=low) ||
        (highStrict==false && currValue>high) ||
        (highStrict==true && currValue>=high)
        ){
        alert("Value outside required interval.");
        field.value=tempValue;
        validated=true;
        return false;
    }


    syncSameFields(field);
    validated=true;
    return false;
}

function updateForDomPrice(selectObj){
    forDomPrice= document.getElementById('forDomPriceSelector').value;
    showPrices(showPricesFlag);
    return false;
}

function updateForDomDelta(selectObj){
    plainPremDelta= document.getElementById('deltaSelector').value;
    showDeltas(showDeltasFlag);
    return false;
}

function showPrices(flag){
    showPricesFlag=flag;
    var notionalFor, notionalDom, fdText1, fdText2, tv0, tv1, tv2, mid0, mid1, mid2;

    var tvCashDom=         parseFloat(document.getElementById('answer_value').value);
    var midCashDom=      parseFloat(document.getElementById('answer_midPrice').value);

    var spot=          parseFloat(document.getElementById('sent_spot').value);
    var notional=      parseFloat(document.getElementById('sent_notional').value);
    var notionalIn_fd= document.getElementById('sent_fd').value;
    var strike=null;

    //Case of options with strike that enable the calculation of the notional in the other sense
    if(document.getElementById('sent_strikeLessOption').value=="no"){
        strike=parseFloat(strike=document.getElementById('sent_strike').value);
        //Notional in Domestic
        if (notionalIn_fd=="1"){
            notionalDom= notional;
            notionalFor= notional/strike;
        }
        //Notional in Foreign
        if (notionalIn_fd=="-1"){
            notionalDom= notional*strike;
            notionalFor= notional;
        }
        if (forDomPrice=='dom'){
            tv0=        tvCashDom;
            mid0=       midCashDom;
            fdText1=    '%DOM';
            tv1=        tvCashDom/notionalDom;
            mid1=       midCashDom/notionalDom;
            fdText2=    'DOM/ 100FOR';
            tv2=        tvCashDom/notionalFor*100;
            mid2=       midCashDom/notionalFor*100;
        }
        if (forDomPrice=='for'){
            tv0=        tvCashDom/spot;
            mid0=       midCashDom/spot;
            fdText1=    '%FOR';
            tv1=        tvCashDom/spot/notionalFor;
            mid1=       midCashDom/spot/notionalFor;
            fdText2=    'FOR/ 100DOM';
            tv2=        tvCashDom/spot/notionalDom*100;
            mid2=       midCashDom/spot/notionalDom*100;
        }
        tv0=roundRelevant(tv0, 4);
        tv1=roundRelevant(tv1*100,4)+"%";
        tv2=roundRelevant(tv2, 4);
        mid0=roundRelevant(mid0, 4);
        mid1=roundRelevant(mid1*100,4)+"%";
        mid2=roundRelevant(mid2, 4);
    }

    //Case of options withOUT strike that disable the calculation of the notional in the other sense
    if(document.getElementById('sent_strikeLessOption').value=="yes"){
        //Notional in Domestic
        if (notionalIn_fd=="1"){
            notionalDom= notional;
            notionalFor= null;

            if (forDomPrice=='dom'){
                tv0=        tvCashDom;
                mid0=       midCashDom;
                fdText1=    '%DOM';
                tv1=        tvCashDom/notionalDom;
                mid1=       midCashDom/notionalDom;
                tv0=roundRelevant(tv0, 4);
                tv1=roundRelevant(tv1*100,4)+"%";
                mid0=roundRelevant(mid0, 4);
                mid1=roundRelevant(mid1*100,4)+"%";
            }
            if (forDomPrice=='for'){
                tv0=        tvCashDom/spot;
                mid0=       midCashDom/spot;
                fdText1=    'FOR/ 100DOM';
                tv1=        tvCashDom/spot/notionalDom*100;
                mid1=       midCashDom/spot/notionalDom*100;
                tv0=roundRelevant(tv0, 4);
                tv1=roundRelevant(tv1, 4);
                mid0=roundRelevant(mid0, 4);
                mid1=roundRelevant(mid1, 4);
            }
        }
        //Notional in Foreign
        if (notionalIn_fd=="-1"){
            notionalDom= null;
            notionalFor= notional;

            if (forDomPrice=='dom'){
                tv0=        tvCashDom;
                mid0=       midCashDom;
                fdText1=    'DOM/ 100FOR';
                tv1=        tvCashDom/notionalFor*100;
                mid1=       midCashDom/notionalFor*100;
                tv0=roundRelevant(tv0, 4);
                tv1=roundRelevant(tv1, 4);
                mid0=roundRelevant(mid0, 4);
                mid1=roundRelevant(mid1, 4);
            }
            if (forDomPrice=='for'){
                tv0=        tvCashDom/spot;
                mid0=       midCashDom/spot;
                fdText1=    '%FOR';
                tv1=        tvCashDom/spot/notionalFor;
                mid1=       midCashDom/spot/notionalFor;
                tv0=roundRelevant(tv0, 4);
                tv1=roundRelevant(tv1*100,4)+"%";
                mid0=roundRelevant(mid0, 4);
                mid1=roundRelevant(mid1*100,4)+"%";
            }
        }
    }

    document.getElementById('tvPrice').innerHTML=tv0;
    document.getElementById('midPrice').innerHTML=mid0;
    if(showPricesFlag){
        var labelTxt, tvTxt, midTxt;
        if(document.getElementById('sent_strikeLessOption').value=="no"){
            labelTxt="<br><span id='labelPrcPct'> &nbsp; "+fdText1+"</span>\n\
                       <br><span id='labelPrc_nom'> &nbsp; "+fdText2+"</span>"
            tvTxt="<br><span id='tvPct' align='right'>"+tv1+"</span>\n\
                   <br><span id='tv_nom' align='right'>"+tv2+"</span>";
            midTxt="<br><span id='midPct' align='right'>"+mid1+"</span>\n\
                     <br><span id='mid_nom' align='right'>"+mid2+"</span>";
        }
        if(document.getElementById('sent_strikeLessOption').value=="yes"){
            labelTxt="<br><span id='labelPrcPct'> &nbsp; "+fdText1+"</span>"
            tvTxt="<br><span id='tvPct' align='right'>"+tv1+"</span>";
            midTxt="<br><span id='midPct' align='right'>"+mid1+"</span>";
        }

        document.getElementById('priceScalesLabels').innerHTML=labelTxt;
        YAHOO.util.Dom.setStyle('priceScalesLabels','height','auto');
        YAHOO.util.Dom.setStyle('priceScalesLabels','visibility','visible');

        document.getElementById('priceScalesTv').innerHTML=tvTxt;
        YAHOO.util.Dom.setStyle('priceScalesTv','height','auto');
        YAHOO.util.Dom.setStyle('priceScalesTv','visibility','visible');

        document.getElementById('priceScalesMid').innerHTML=midTxt;
        YAHOO.util.Dom.setStyle('priceScalesMid','height','auto');
        YAHOO.util.Dom.setStyle('priceScalesMid','visibility','visible');

        document.getElementById('showPrices').innerHTML='';
    }
}

function showDeltas(flag){
    showDeltasFlag=flag;
    var notionalFor, notionalDom, fdText1, fdText2, tv0, tv1, tv2;

    var tvCashDom=         parseFloat(document.getElementById('answer_value').value);
    var deltaFor=        parseFloat(document.getElementById('answer_delta').value);

    var spot=          parseFloat(document.getElementById('sent_spot').value);
    var notional=      parseFloat(document.getElementById('sent_notional').value);
    var notionalIn_fd= document.getElementById('sent_fd').value;
    var strike=null;

    //Case of options with strike that enable the calculation of the notional in the other sense
    if(document.getElementById('sent_strikeLessOption').value=="no"){
        strike=parseFloat(strike=document.getElementById('sent_strike').value);
        //Notional in Domestic
        if (notionalIn_fd=="1"){
            notionalDom= notional;
            notionalFor= notional/strike;
        }
        //Notional in Foreign
        if (notionalIn_fd=="-1"){
            notionalDom= notional*strike;
            notionalFor= notional;
        }
        if (plainPremDelta=='plain'){
            tv0=        deltaFor;
            fdText1=    '%FOR';
            tv1=        deltaFor/notionalFor;
            fdText2=    'DOM';
            tv2=        -deltaFor*spot;
        }
        if (plainPremDelta=='premAdj'){
            tv0=        deltaFor-tvCashDom/spot;
            fdText1=    '%FOR';
            tv1=        (deltaFor-tvCashDom/spot)/notionalFor;
            fdText2=    'DOM';
            tv2=        -(deltaFor-tvCashDom/spot)*spot;
        }
        tv0=roundRelevant(tv0, 4);
        tv1=roundRelevant(tv1*100,4)+"%";
        tv2=roundRelevant(tv2, 4);
    }

    //Case of options withOUT strike that disable the calculation of the notional in the other sense
    if(document.getElementById('sent_strikeLessOption').value=="yes"){
        //Notional in Domestic
        if (notionalIn_fd=="1"){
            notionalDom= notional;
            notionalFor= null;

            if (plainPremDelta=='plain'){
                tv0=        deltaFor;
                fdText1=    'DOM';
                tv1=        -deltaFor*spot;
                fdText2=    '%DOM';
                tv2=        -deltaFor*spot/notionalDom;
            }
            if (plainPremDelta=='premAdj'){
                tv0=        deltaFor-tvCashDom/spot;
                fdText1=    'DOM';
                tv1=        -(deltaFor-tvCashDom/spot)*spot;
                fdText2=    '%DOM';
                tv2=        -(deltaFor-tvCashDom/spot)*spot/notionalDom;
            }
            tv0=roundRelevant(tv0, 4);
            tv1=roundRelevant(tv1, 4);
            tv2=roundRelevant(tv2*100,4)+"%";
        }
        //Notional in Foreign
        if (notionalIn_fd=="-1"){
            notionalDom= null;
            notionalFor= notional;

            if (plainPremDelta=='plain'){
                tv0=        deltaFor;
                fdText1=    '%FOR';
                tv1=        deltaFor/notionalFor;
                fdText2=    'DOM';
                tv2=        -deltaFor*spot;
            }
            if (plainPremDelta=='premAdj'){
                tv0=        deltaFor-tvCashDom/spot;
                fdText1=    '%FOR';
                tv1=        (deltaFor-tvCashDom/spot)/notionalFor;
                fdText2=    'DOM';
                tv2=        -(deltaFor-tvCashDom/spot)*spot;
            }
            tv0=roundRelevant(tv0, 4);
            tv1=roundRelevant(tv1*100,4)+"%";
            tv2=roundRelevant(tv2, 4);
        }
    }
    var labelTxt, deltaTxt;
    document.getElementById('deltaValue').innerHTML=tv0;
    if(showDeltasFlag){
        deltaTxt="<br><span id='deltaFOR' align='right'>"+tv1+"</span>\n\
                        <br><span id='deltaDOM' align='right'>"+tv2+"</span>";
        labelTxt="<br><span id='labelDeltaFOR'> &nbsp; "+fdText1+"</span>\n\
                     <br><span id='labelDeltaDOM'> &nbsp; "+fdText2+"</span>";

        document.getElementById('deltaScalesLabels').innerHTML=labelTxt;
        YAHOO.util.Dom.setStyle('deltaScalesLabels','height','auto');
        YAHOO.util.Dom.setStyle('deltaScalesLabels','visibility','visible');

        document.getElementById('deltaScalesVal').innerHTML=deltaTxt;
        YAHOO.util.Dom.setStyle('deltaScalesVal','height','auto');
        YAHOO.util.Dom.setStyle('deltaScalesVal','visibility','visible');

        document.getElementById('showDeltas').innerHTML='';
    }
}

//function collapseAll(){
//	$('description').hide();
//	description.setExpanded(false);
//	$('divWrapMarketUnderlyings').hide();
//	divWrapMarketUnderlyings.setExpanded(false);
//	$('divWrapMarketIR').hide();
//	divWrapMarketIR.setExpanded(false);
//	$('divWrapMarketOpt').hide();
//	divWrapMarketOpt.setExpanded(false);
//	$('divWrapContractSide').hide();
//	divWrapContractSide.setExpanded(false);
//	$('divWrapContractPrices').hide();
//	divWrapContractPrices.setExpanded(false);
//	$('divWrapContractDates').hide();
//	divWrapContractDates.setExpanded(false);
//	$('divWrapContractQuantity').hide();
//	divWrapContractQuantity.setExpanded(false);
//	$('divWrapValMain').hide();
//	divWrapValMain.setExpanded(false);
//	return false;
//}
//
//function showAll(){
//	$('description').show();
//	description.setExpanded(true);
//	$('divWrapMarketUnderlyings').show();
//	divWrapMarketUnderlyings.setExpanded(true);
//	$('divWrapMarketIR').show();
//	divWrapMarketIR.setExpanded(true);
//	$('divWrapMarketOpt').show();
//	divWrapMarketOpt.setExpanded(true);
//	$('divWrapContractSide').show();
//	divWrapContractSide.setExpanded(true);
//	$('divWrapContractPrices').show();
//	divWrapContractPrices.setExpanded(true);
//	$('divWrapContractDates').show();
//	divWrapContractDates.setExpanded(true);
//	$('divWrapContractQuantity').show();
//	divWrapContractQuantity.setExpanded(true);
//	$('divWrapValMain').show();
//	divWrapValMain.setExpanded(true);
//	return false;
//}