

function openpage(frmname){

    document.form1.includepage.value=frmname;

    document.form1.submit(document.form1);

}

function openhelp(anchorname)

{

    helpwindow=window.open("help.htm","","directories=no,menubar=no,toolbar=no,status=no,location=no,height=400,scrollbars=yes");

    helpwindow.location.href="help.htm#"+anchorname;

}



function opencompare(){


    portfolioname1=document.getElementsByName('portfolio1')[0];
    portfolioname2=document.getElementsByName('portfolio2')[0];
    if(portfolioname1!=""){
        if (!checkkey(portfolioname1)){
            alert("Please enter Alpha Numerics only in Portfolio A name") ;
            return;
        }
    }
    if(portfolioname2!=""){
        if (!checkkey(portfolioname2)){
            alert("Please enter Alpha Numerics only in Portfolio B name") ;
            return;
        }
    }


    var alocA,alocB,astA,astB,p1,p2,st;
    if (document.form1.usr.value=="guest"){
        document.getElementById("msgCompare").style.display="block";
        return;
    }

    make_total();

    if (!((document.form1.tota.value=="100%") && (document.form1.totb.value=="100%"))) {

        alert("Only Full ie 100% allocated portfolios can be compared");

        return;

    }





    // Copy

    alocA = document.form1.alocationa0.value;

    alocA=alocA + "``" + document.form1.alocationa1.value;

    alocA=alocA + "``" + document.form1.alocationa2.value;

    alocA=alocA + "``" + document.form1.alocationa3.value;

    alocA=alocA + "``" + document.form1.alocationa4.value;

    alocA=alocA + "``" + document.form1.alocationa5.value;

    alocA=alocA + "``" + document.form1.alocationa6.value;

    alocA=alocA + "``" + document.form1.alocationa7.value;

    alocA=alocA + "``" + document.form1.alocationa8.value;

    alocA=alocA + "``" + document.form1.alocationa9.value;

    alocA=alocA + "``" + document.form1.alocationa10.value;

    alocA=alocA + "``" + document.form1.alocationa11.value;

	

    astA=document.form1.asca0.value;

    astA=astA + "``" +  document.form1.asca1.value;

    astA=astA + "``" +  document.form1.asca2.value;

    astA=astA + "``" +  document.form1.asca3.value;

    astA=astA + "``" +  document.form1.asca4.value;

    astA=astA + "``" +  document.form1.asca5.value;

    astA=astA + "``" +  document.form1.asca6.value;

    astA=astA + "``" +  document.form1.asca7.value;

    astA=astA + "``" +  document.form1.asca8.value;

    astA=astA + "``" +  document.form1.asca9.value;

    astA=astA + "``" +  document.form1.asca10.value;

    astA=astA + "``" +  document.form1.asca11.value;

	

    p1=document.form1.portfolio1.value;

    if((p1)=="")

    {
        p1=document.form1.port_a_cmb.value;
    }



    //



    alocB = document.form1.alocationb0.value;

    alocB=alocB + "``" + document.form1.alocationb1.value;

    alocB=alocB + "``" + document.form1.alocationb2.value;

    alocB=alocB + "``" + document.form1.alocationb3.value;

    alocB=alocB + "``" + document.form1.alocationb4.value;

    alocB=alocB + "``" + document.form1.alocationb5.value;

    alocB=alocB + "``" + document.form1.alocationb6.value;

    alocB=alocB + "``" + document.form1.alocationb7.value;

    alocB=alocB + "``" + document.form1.alocationb8.value;

    alocB=alocB + "``" + document.form1.alocationb9.value;

    alocB=alocB + "``" + document.form1.alocationb10.value;

    alocB=alocB + "``" + document.form1.alocationb11.value;

	





    astB = document.form1.ascb0.value;

    astB=astB + "``" +  document.form1.ascb1.value;

    astB=astB + "``" +  document.form1.ascb2.value;

    astB=astB + "``" +  document.form1.ascb3.value;

    astB=astB + "``" +  document.form1.ascb4.value;

    astB=astB + "``" +  document.form1.ascb5.value;

    astB=astB + "``" +  document.form1.ascb6.value;

    astB=astB + "``" +  document.form1.ascb7.value;

    astB=astB + "``" +  document.form1.ascb8.value;

    astB=astB + "``" +  document.form1.ascb9.value;

    astB=astB + "``" +  document.form1.ascb10.value;

    astB=astB + "``" +  document.form1.ascb11.value;



    p2=document.form1.portfolio2.value;

    if((p2)=="")

    {
        p2=document.form1.port_b_cmb.value;
    }



    usr=document.form1.usr.value;

    mnthA=document.form1.monthcmb1.value;

    mnthB=document.form1.monthcmb2.value;

    yearA=document.form1.yearcmb1.value;

    yearB=document.form1.yearcmb2.value;

    tradassetA=document.form1.trad_cmb1.value;

    tradassetB=document.form1.trad_cmb2.value;

    tradassetfeesA=document.form1.trad_asset_fees1.value;

    tradassetfeesB=document.form1.trad_asset_fees2.value;

    advisoryfeesA=document.form1.advisory1.value;

    advisoryfeesB=document.form1.advisory2.value;



    portacmb=document.form1.port_a_cmb.value;

    portbcmb=document.form1.port_b_cmb.value;



    //URLEncode(

    //	st="?alocationA="+alocA+"&alocationB="+alocB+"&assetA="+astA+"&assetB="+astB+"&portfolio1="+p1+"&portfolio2="+p2;

    //	st=st+"&usr="+usr+"&mnthA="+mnthA+"&mnthB="+mnthB+"&yearA="+yearA+"&yearB="+yearB+"&tradassetA="+tradassetA;

    //	st=st+"&tradassetB="+tradassetB+"&tradassetfeesA="+tradassetfeesA+"&tradassetfeesB="+tradassetfeesB;

    //	st=st+"&advisoryfeesA="+advisoryfeesA+"&advisoryfeesB="+advisoryfeesB;





    st="?alocationA="+URLEncode(alocA)+"&alocationB="+URLEncode(alocB)+"&assetA="+URLEncode(astA)+"&assetB="+URLEncode(astB)+"&portfolio1="+URLEncode(p1)+"&portfolio2="+URLEncode(p2);

    st=st+"&usr="+URLEncode(usr)+"&mnthA="+URLEncode(mnthA)+"&mnthB="+URLEncode(mnthB)+"&yearA="+URLEncode(yearA)+"&yearB="+URLEncode(yearB)+"&tradassetA="+URLEncode(tradassetA);

    st=st+"&tradassetB="+tradassetB+"&tradassetfeesA="+tradassetfeesA+"&tradassetfeesB="+tradassetfeesB;

    st=st+"&advisoryfeesA="+URLEncode(advisoryfeesA)+"&advisoryfeesB="+URLEncode(advisoryfeesB);

    st=st+"&port_a_cmb="+URLEncode(portacmb)+"&port_b_cmb="+URLEncode(portbcmb);









    //	 We will unset mode

    document.form1.mode.value="COMPARE";

    //	openwin("vfp.php",st);

    location.href="vfp.php"+st;

//	cmpwindow=window.open

//("vfp.php"+st,"","directories=no,location=top,scrollbars=yes,dependent=yes,screenX=0,screenY=0");

//	cmpwindow.location.href="compare.php#chart";

	

}



function openwin(frmname,st)

{

    //	alert(st);

    //	alert(frmname);

    cmpwindow=window.open(frmname+st,"","directories=no,location=top,scrollbars=yes,dependent=yes,screenX=0,screenY=0");

}



function settext(st)

{

    document.form1.vl.value=st;

}



function incr()

{
    for(i=0;i<document.form1.elements.length;i++)


    {
            if (document.form1.elements[i].name==document.form1.vl.value)


            {
                var v=parseFloat(document.form1.elements[i].value,10);

                if (isNaN(v)==true)

                {

                    document.form1.elements[i].value=0;

                    make_total();

                    return;

                }

                else {

                    if ((document.form1.elements[i].name=="advisory1")||(document.form1.elements[i].name=="advisory2"))

                    {
                        v=v+.01;

                        if (v>2.5) v=2.50;

                        document.form1.elements[i].value=(Math.floor(v*100))/100;

                        return;

                    }

                    else  {

                        v=v+1.0;

                        if (v>100) v=100;

                        document.form1.elements[i].value=v;

                        make_total();

                        return;

                    }

                }

            }

			

        }

}



function decr(){

    for(i=0;i<document.form1.elements.length;i++){

        if (document.form1.elements[i].name==document.form1.vl.value)

        {
            var v=parseFloat(document.form1.elements[i].value,10);

            if (isNaN(v) ==true)

            {

                document.form1.elements[i].value=0;

                make_total();

                return;

            }

            else{

                if ((document.form1.elements[i].name=="advisory1")||(document.form1.elements[i].name=="advisory2")){

                    v=v-.01;

                    if (v<0) {
                        v=0.00
                        };

                    document.form1.elements[i].value=(Math.floor(v*100))/100;

                    return;

                }

                else {

                    v=v-1;

                    if (v<0) v=0;

                    document.form1.elements[i].value=v;

                    make_total();

                    return;

                }

            }

        }

    }

}


function toserver(form,mode){
    var portfolioname="";
    if (mode=='SAVEA'){
        portfolioname=document.getElementsByName('portfolio1')[0];
    }
    if (mode=='SAVEB'){
       portfolioname=document.getElementsByName('portfolio2')[0];
    }
    if(portfolioname!=""){
        if (!checkkey(portfolioname)){
            alert("Please enter Alpha Numerics only") ;
            return;
        }
    }
    document.form1.mode.value=mode;
    document.form1.submit(form);
}

function checkkey(v) {

var validchars=/[^a-zA-Z_0-9_\-_\/_\s]/;
    if (validchars.test(v.value)) {
        return false;
    }
    return true;
}

function copya2b(){

    document.form1.alocationb0.value = document.form1.alocationa0.value;

    document.form1.alocationb1.value = document.form1.alocationa1.value;

    document.form1.alocationb2.value = document.form1.alocationa2.value;

    document.form1.alocationb3.value = document.form1.alocationa3.value;

    document.form1.alocationb4.value = document.form1.alocationa4.value;

    document.form1.alocationb5.value = document.form1.alocationa5.value;

    document.form1.alocationb6.value = document.form1.alocationa6.value;

    document.form1.alocationb7.value = document.form1.alocationa7.value;

    document.form1.alocationb8.value = document.form1.alocationa8.value;

    document.form1.alocationb9.value = document.form1.alocationa9.value;

    document.form1.alocationb10.value = document.form1.alocationa10.value;

    document.form1.alocationb11.value = document.form1.alocationa11.value;

	

    document.form1.ascb0.value = document.form1.asca0.value;

    document.form1.ascb1.value = document.form1.asca1.value;

    document.form1.ascb2.value = document.form1.asca2.value;

    document.form1.ascb3.value = document.form1.asca3.value;

    document.form1.ascb4.value = document.form1.asca4.value;

    document.form1.ascb5.value = document.form1.asca5.value;

    document.form1.ascb6.value = document.form1.asca6.value;

    document.form1.ascb7.value = document.form1.asca7.value;

    document.form1.ascb8.value = document.form1.asca8.value;

    document.form1.ascb9.value = document.form1.asca9.value;

    document.form1.ascb10.value = document.form1.asca10.value;

    document.form1.ascb11.value = document.form1.asca11.value;



    document.form1.trad_asset_fees2.value = document.form1.trad_asset_fees1.value;

    document.form1.advisory2.value = document.form1.advisory1.value;

    document.form1.portfolio2.value = document.form1.portfolio1.value;

    document.form1.trad_cmb2.value = document.form1.trad_cmb1.value;





    make_total();

}



function copyb2a(){

    document.form1.alocationa0.value = document.form1.alocationb0.value;

    document.form1.alocationa1.value = document.form1.alocationb1.value;

    document.form1.alocationa2.value = document.form1.alocationb2.value;

    document.form1.alocationa3.value = document.form1.alocationb3.value;

    document.form1.alocationa4.value = document.form1.alocationb4.value;

    document.form1.alocationa5.value = document.form1.alocationb5.value;

    document.form1.alocationa6.value = document.form1.alocationb6.value;

    document.form1.alocationa7.value = document.form1.alocationb7.value;

    document.form1.alocationa8.value = document.form1.alocationb8.value;

    document.form1.alocationa9.value = document.form1.alocationb9.value;

    document.form1.alocationa10.value = document.form1.alocationb10.value;

    document.form1.alocationa11.value = document.form1.alocationb11.value;

	

    document.form1.asca0.value = document.form1.ascb0.value;

    document.form1.asca1.value = document.form1.ascb1.value;

    document.form1.asca2.value = document.form1.ascb2.value;

    document.form1.asca3.value = document.form1.ascb3.value;

    document.form1.asca4.value = document.form1.ascb4.value;

    document.form1.asca5.value = document.form1.ascb5.value;

    document.form1.asca6.value = document.form1.ascb6.value;

    document.form1.asca7.value = document.form1.ascb7.value;

    document.form1.asca8.value = document.form1.ascb8.value;

    document.form1.asca9.value = document.form1.ascb9.value;

    document.form1.asca10.value = document.form1.ascb10.value;

    document.form1.asca11.value = document.form1.ascb11.value;

	

    document.form1.trad_cmb1.value = document.form1.trad_cmb2.value;

    document.form1.trad_asset_fees1.value = document.form1.trad_asset_fees2.value;

    document.form1.advisory1.value = document.form1.advisory2.value;

    document.form1.portfolio1.value = document.form1.portfolio2.value;



    make_total();

}



function make_total(){

    totala=0;

    totalb=0;


    if (isNaN(parseFloat(document.form1.alocationa0.value))==false)

        totala += Math.round(100*parseFloat(document.form1.alocationa0.value))/100;

    if (isNaN(parseFloat(document.form1.alocationb0.value))==false)

        totalb +=Math.round(100*parseFloat(document.form1.alocationb0.value))/100;



    if (isNaN(parseFloat(document.form1.alocationa1.value))==false)

        totala += Math.round(100*parseFloat(document.form1.alocationa1.value))/100;

    if (isNaN(parseFloat(document.form1.alocationb1.value))==false)

        totalb += Math.round(100*parseFloat(document.form1.alocationb1.value))/100;



    if (isNaN(parseFloat(document.form1.alocationa2.value))==false)

        totala += Math.round(100*parseFloat(document.form1.alocationa2.value))/100;

    if (isNaN(parseFloat(document.form1.alocationb2.value))==false)

        totalb += Math.round(100*parseFloat(document.form1.alocationb2.value))/100;



    if (isNaN(parseFloat(document.form1.alocationa3.value))==false)

        totala += Math.round(100*parseFloat(document.form1.alocationa3.value))/100;

    if (isNaN(parseFloat(document.form1.alocationb3.value))==false)

        totalb += Math.round(100*parseFloat(document.form1.alocationb3.value))/100;



    if (isNaN(parseFloat(document.form1.alocationa4.value))==false)

        totala += Math.round(100*parseFloat(document.form1.alocationa4.value))/100;

    if (isNaN(parseFloat(document.form1.alocationb4.value))==false)

        totalb += Math.round(100*parseFloat(document.form1.alocationb4.value))/100;



    if (isNaN(parseFloat(document.form1.alocationa5.value))==false)

        totala += Math.round(100*parseFloat(document.form1.alocationa5.value))/100;

    if (isNaN(parseFloat(document.form1.alocationb5.value))==false)

        totalb += Math.round(100*parseFloat(document.form1.alocationb5.value))/100;



    if (isNaN(parseFloat(document.form1.alocationa6.value))==false)

        totala += Math.round(100*parseFloat(document.form1.alocationa6.value))/100;

    if (isNaN(parseFloat(document.form1.alocationb6.value))==false)

        totalb += Math.round(100*parseFloat(document.form1.alocationb6.value))/100;



    if (isNaN(parseFloat(document.form1.alocationa7.value))==false)

        totala += Math.round(100*parseFloat(document.form1.alocationa7.value))/100;

    if (isNaN(parseFloat(document.form1.alocationb7.value))==false)

        totalb += Math.round(100*parseFloat(document.form1.alocationb7.value))/100;



    if (isNaN(parseFloat(document.form1.alocationa8.value))==false)

        totala += Math.round(100*parseFloat(document.form1.alocationa8.value))/100;

    if (isNaN(parseFloat(document.form1.alocationb8.value))==false)

        totalb += Math.round(100*parseFloat(document.form1.alocationb8.value))/100;



    if (isNaN(parseFloat(document.form1.alocationa9.value))==false)

        totala += Math.round(100*parseFloat(document.form1.alocationa9.value))/100;

    if (isNaN(parseFloat(document.form1.alocationb9.value))==false)

        totalb += Math.round(100*parseFloat(document.form1.alocationb9.value))/100;



    if (isNaN(parseFloat(document.form1.alocationa10.value))==false)

        totala += Math.round(100*parseFloat(document.form1.alocationa10.value))/100;

    if (isNaN(parseFloat(document.form1.alocationb10.value))==false)

        totalb += Math.round(100*parseFloat(document.form1.alocationb10.value))/100;



    if (isNaN(parseFloat(document.form1.alocationa11.value))==false)

        totala += Math.round(100*parseFloat(document.form1.alocationa11.value))/100;

    if (isNaN(parseFloat(document.form1.alocationb11.value))==false)

        totalb += Math.round(100*parseFloat(document.form1.alocationb11.value))/100;


    totala=Math.round(totala*100)/100;
    totalb=Math.round(totalb*100)/100;

    document.form1.tota.value=totala+"%";

    document.form1.totb.value=totalb+"%";

}



function chktAdvisory(no){

    if(no==1)

    {

        if (isNaN(document.form1.advisory1.value)==true){

            alert("Only Numbers Are Allowed");

            document.form1.advisory1.value=0;

        }

        else {

            v=parseFloat(document.form1.advisory1.value);

            if (v<0 || v>2.5){

                alert("Allowed Range is 0 To 2.5");

                if(v<0)

                    document.form1.advisory1.value=0;

                else

                    document.form1.advisory1.value=2.50;

            }

					

        }

			

    }

    else{

        if (isNaN(document.form1.advisory2.value)==true){

            alert("Only Numbers Are Allowed");

            document.form1.advisory2.value=0;

        }

        else {

            v=parseFloat(document.form1.advisory2.value);

            if (v<0 || v>2.5){

                alert("Allowed Range is 0 To 2.5");

                if(v<0)

                    document.form1.advisory2.value=0;

                else

                    document.form1.advisory2.value=2.50;

            }

					

        }


			

    }

}



function chktAssetFee(no){

    if(no==1)

    {

        if (isNaN(document.form1.trad_asset_fees1.value)==true){

            alert("Only Numbers Are Allowed");

            document.form1.trad_asset_fees1.value=0;

        }

        else {

            v=parseInt(document.form1.trad_asset_fees1.value);

            document.form1.trad_asset_fees1.value=v;

            if (v<0 || v>100){

                alert("Allowed Range is 0 To 100");

                if(v<0)

                    document.form1.trad_asset_fees1.value=0;

                else

                    document.form1.trad_asset_fees1.value=100;

            }

					

        }

			

    }

    else{

        if (isNaN(document.form1.trad_asset_fees2.value)==true){

            alert("Only Numbers Are Allowed");

            document.form1.trad_asset_fees2.value=0;

        }

        else {

            v=parseInt(document.form1.trad_asset_fees2.value);

            document.form1.trad_asset_fees2.value=v;

            if (v<0 || v>100){

                alert("Allowed Range is 0 To 100");

                if(v<0)

                    document.form1.trad_asset_fees2.value=0;

                else

                    document.form1.trad_asset_fees2.value=100;

            }

					

        }

			

    }

}



function URLEncode(vl)

{

    // The Javascript escape and unescape functions do not correspond

    // with what browsers actually do...

    var SAFECHARS = "0123456789" +					// Numeric

    "ABCDEFGHIJKLMNOPQRSTUVWXYZ" +	// Alphabetic

    "abcdefghijklmnopqrstuvwxyz" +

    "-_.!~*'()";					// RFC2396 Mark characters

    var HEX = "0123456789ABCDEF";



    //	var plaintext = document.URLForm.F1.value;

    var plaintext =	vl;

    var encoded = "";

    for (var i = 0; i < plaintext.length; i++ ) {

        var ch = plaintext.charAt(i);

        if (ch == " ") {

            encoded += "+";				// x-www-urlencoded, rather than %20

        } else if (SAFECHARS.indexOf(ch) != -1) {

            encoded += ch;

        } else {

            var charCode = ch.charCodeAt(0);

            if (charCode > 255) {

                alert( "Unicode Character '"

                    + ch

                    + "' cannot be encoded using standard URL encoding.\n" +

                    "(URL encoding only supports 8-bit characters.)\n" +

                    "A space (+) will be substituted." );

                encoded += "+";

            } else {

                encoded += "%";

                encoded += HEX.charAt((charCode >> 4) & 0xF);

                encoded += HEX.charAt(charCode & 0xF);

            }

        }

    } // for



    //document.URLForm.F2.value = encoded;

    // return false;

    return encoded;

};



function URLDecode( )

{

    // Replace + with ' '

    // Replace %xx with equivalent character

    // Put [ERROR] in output if %xx is invalid.

    var HEXCHARS = "0123456789ABCDEFabcdef";

    var encoded = document.URLForm.F2.value;

    var plaintext = "";

    var i = 0;

    while (i < encoded.length) {

        var ch = encoded.charAt(i);

        if (ch == "+") {

            plaintext += " ";

            i++;

        } else if (ch == "%") {

            if (i < (encoded.length-2)

                && HEXCHARS.indexOf(encoded.charAt(i+1)) != -1

                && HEXCHARS.indexOf(encoded.charAt(i+2)) != -1 ) {

                plaintext += unescape( encoded.substr(i,3) );

                i += 3;

            } else {

                alert( 'Bad escape combination near ...' + encoded.substr(i) );

                plaintext += "%[ERROR]";

                i++;

            }

        } else {

            plaintext += ch;

            i++;

        }

    } // while

    document.URLForm.F1.value = plaintext;

    return false;

};
