var divToFill_Id;

var handleSuccess = function(o){
    if(o.responseText !== undefined){
        //forDomPrice='dom';
        //plainPremDelta='plain';
        div=document.getElementById(divToFill_Id);
        div.innerHTML = o.responseText;
        var resultPosition = document.getElementById(divToFill_Id).offsetTop;
        window.scrollTo(0, resultPosition);
        var attributes = {
            backgroundColor: {
                from: '#669999',
                to: '#ECF9FD'
            }
        };
        try {
            if(forDomPrice!='dom') document.getElementById('forDomPriceSelector').options[1].selected=true;
            if(plainPremDelta!='plain') document.getElementById('deltaSelector').options[1].selected=true;
            showPrices(showPricesFlag);
            showDeltas(showDeltasFlag);
        } catch (exception) {
        }

        var anim = new YAHOO.util.ColorAnim(divToFill_Id, attributes, 1, YAHOO.util.Easing.easeOut );
        anim.animate();
    }
}

var handleFailure= function(o){
    div=document.getElementById(divToFill_Id);
    div.innerHTML =  "An error has occured and no result is available for display. Wrong Input<br>	Please contact us by following this <a href=http://www.mathfinance.com/Additions/emailUsForm.php>link</a>.";
}

var callback = {
    success:handleSuccess,
    failure: handleFailure,
    argument: [divToFill_Id]
};

function makeRequest(formObj, divId, url ){
    if(!validated) {
        return false;
    }

    divToFill_Id=divId;

    if(document.getElementById('divToFill_Id')!=null){
        document.getElementById('divToFill_Id')=null;
    }
    //showPricesFlag=false;
    //showDeltasFlag=false;
    //Remove percent (%) symbols from post
    var i, inputFld;
    var formCopy= document.createElement("form");

    var n=formObj.elements.length;
    for (i=0; i<n; i++ ){
        inputFld=document.createElement("input");
        formCopy.appendChild(inputFld);

        formCopy.elements[i].id=formObj.elements[i].id;
        formCopy.elements[i].name=formObj.elements[i].name;
        formCopy.elements[i].value=formObj.elements[i].value;

        var currValue=formCopy.elements[i].value.toString();
        if(currValue.match("%")){
            currValue=currValue.replace(/%/, "");
            currValue=currValue/100;
            formCopy.elements[i].value=currValue;
        }
    }(i=0);n=0;

    var post= $(formCopy).serialize();
    //alert(post);
    var request = YAHOO.util.Connect.asyncRequest('POST', url, callback, post);
    return false;
}

