<!--
var stparr = null;
var stpno = 0;
var eqstr = "";
var eqstps = "";

var tmpl = "<table border=0><tr><td class=wht rowspan=4>WHLNUM&nbsp;</td></tr><tr><td class=wht style='text-align:center;'>NMRTR</td></tr><tr><td class=wht height=2><img src='images/ydot.jpg' height=2 width=100%></td></tr><tr><td class=wht style='text-align:center;'>DNMRTR</td></tr></table>";


function setEq()
{
    var elm = document.getElementById("eqn");
    if (elm != null) {elm.innerHTML = eqstr;}
    stparr = eqstps.split("|");
    stpno = 0;
    elm = document.getElementById("eqstp");
    if (elm != null) {elm.innerHTML = "";}
}

function showStep()
{
    if (stparr.length > stpno)
    {
        var elm = document.getElementById("eqstp");
        if (elm != null) {var chld = elm.appendChild(document.createElement('div')); if (chld != null) {chld.innerHTML = stparr[stpno]}}
    }
    stpno++;
}

function getOpt()
{
    opt = 0;
    var elm = document.getElementById("vard");
    if (elm != null) {if (elm.checked) {opt += 1;}}
    elm = document.getElementById("vari");
    if (elm != null) {if (elm.checked) {opt += 2;}}
    if (opt == 0) {opt = 1;}
}


function showNew()
{
    getOpt();
    var eqtype = opt; if (opt == 3) {eqtype = getrand(1,2);}
    if ((eqtype & opt) == 1)
    {
        if (getrand(1,2) == 1) {setDirect_1();} else {setDirect_2();}
    }
    else if ((eqtype & 2) == 2)
    {
        if (getrand(1,2) == 1) {setInDirect_1();} else {setInDirect_2();}
    }
    setEq();
}

function getfactor(v)
{
    var arr = new Array();
    var max = Math.round(v/2);
    for (var i = 2; i < max; i++)
    {
        if (v % i == 0) {arr.push(i);}
    }
    if (arr.length == 0) {return 1;}
    var c = arr.length-1; return arr[getrand(0,c)];
}
function roundme(x) {return Math.round(x*1000)/1000;}


function setInDirect_1()
{
    var y = getrand(2,10);var x = getrand(1,10);
    var y2 = 1;
    if (getrand(1,2) == 1) {x = ((2*x-1)*5)/10;y2 = getfactor(x*y*10);y2=y2/10;} else {y2 = getfactor(x*y);}
    var k = y*x;
    var x2 = roundme(k/y2);
    eqstr = "If Y varies inversely as X and Y = " + y + " when X = " + x + ", find Y when X = " + x2 + ".";
    var tblstr = tmpl; tblstr = tblstr.replace("WHLNUM", "Y = ");tblstr=tblstr.replace("NMRTR", "&nbsp;k&nbsp;");tblstr=tblstr.replace("DNMRTR", "X");
    eqstps = "First, write the equation " + tblstr;
    eqstps += "|As we know Y = " + y + " when X = " + x + ", substitute these values into equation.";
    tblstr = tmpl; tblstr = tblstr.replace("WHLNUM", y + " = ");tblstr=tblstr.replace("NMRTR", "&nbsp;k&nbsp;");tblstr=tblstr.replace("DNMRTR", x);
    eqstps += "|" + tblstr;
    eqstps += "|" + y + "&times;" + x + " = k";
    eqstps += "|i.e. k = " + k;
    tblstr = tmpl; tblstr = tblstr.replace("WHLNUM", "Y = ");tblstr=tblstr.replace("NMRTR", "&nbsp;" + k + "&nbsp;");tblstr=tblstr.replace("DNMRTR", "X");
    eqstps += "|Now, substitute k value in the first equation to get " + tblstr;
    eqstps += "|As you need to find Y when X = " + x2 + ", substitute X in the above equation";
    tblstr = tmpl; tblstr = tblstr.replace("WHLNUM", "Y = ");tblstr=tblstr.replace("NMRTR", "&nbsp;" + k + "&nbsp;");tblstr=tblstr.replace("DNMRTR", x2);
    eqstps += "|" + tblstr;
    eqstps += "|<span class='grn'>Y = " + y2 + "</span>";
}

function setInDirect_2()
{
    var y = getrand(2,10);var x = getrand(1,10);
    var y2 = 1;
    if (getrand(1,2) == 1) {x = ((2*x-1)*5)/10;y2 = getfactor(x*y*10);y2=y2/10;} else {y2 = getfactor(x*y);}
    var k = y*x;
    var x2 = roundme(k/y2);
    eqstr = "If Y varies inversely as X and Y = " + y + " when X = " + x + ", find X when Y = " + y2 + ".";
    var tblstr = tmpl; tblstr = tblstr.replace("WHLNUM", "Y = ");tblstr=tblstr.replace("NMRTR", "&nbsp;k&nbsp;");tblstr=tblstr.replace("DNMRTR", "X");
    eqstps = "First, write the equation " + tblstr;
    eqstps += "|As we know Y = " + y + " when X = " + x + ", substitute these values into equation.";
    tblstr = tmpl; tblstr = tblstr.replace("WHLNUM", y + " = ");tblstr=tblstr.replace("NMRTR", "&nbsp;k&nbsp;");tblstr=tblstr.replace("DNMRTR", x);
    eqstps += "|" + tblstr;
    eqstps += "|" + y + "&times;" + x + " = k";
    eqstps += "|i.e. k = " + k;
    tblstr = tmpl; tblstr = tblstr.replace("WHLNUM", "Y = ");tblstr=tblstr.replace("NMRTR", "&nbsp;" + k + "&nbsp;");tblstr=tblstr.replace("DNMRTR", "X");
    eqstps += "|Now, substitute k value in the first equation to get " + tblstr;
    eqstps += "|As you need to find X when Y = " + y2 + ", substitute Y in the above equation";
    tblstr = tmpl; tblstr = tblstr.replace("WHLNUM", y2 + " = ");tblstr=tblstr.replace("NMRTR", "&nbsp;" + k + "&nbsp;");tblstr=tblstr.replace("DNMRTR", "X");
    eqstps += "|" + tblstr;
    tblstr = tmpl; tblstr = tblstr.replace("WHLNUM", "X = ");tblstr=tblstr.replace("NMRTR", "&nbsp;" + k + "&nbsp;");tblstr=tblstr.replace("DNMRTR", y2);
    eqstps += "|" + tblstr;
    eqstps += "|<span class='grn'>X = " + x2 + "</span>";
}


function setDirect_1()
{
    var x = getrand(2,10);var k = getrand(1,10); if (getrand(1,3) == 1) {k = ((2*k-1)*5)/10;}
    var y = x*k;
    var x2 = getrand(2,10);var y2 = k*x2;
    eqstr = "If Y varies directly as X and Y = " + y + " when X = " + x + ", find Y when X = " + x2 + ".";
    eqstps = "First, write the equation Y = kX";
    eqstps += "|As we know Y = " + y + " when X = " + x + ", substitute these values into equation.";
    eqstps += "|" + y + " = k &times; " + x;
    var tblstr = tmpl; tblstr = tblstr.replace("WHLNUM", "k = ");tblstr=tblstr.replace("NMRTR", "&nbsp;" + y + "&nbsp;");tblstr=tblstr.replace("DNMRTR", x);
    eqstps += "|" + tblstr;
    eqstps += "|i.e. k = " + k;
    eqstps += "|Now, substitute k value in the first equation to get Y = " + k + "X";
    eqstps += "|As you need to find Y when X = " + x2 + ", substitute X in the above equation";
    eqstps += "|Y = " + k + "&times;" + x2;
    eqstps += "|<span class='grn'>Y = " + y2 + "</span>";
}

function setDirect_2()
{
    var x = getrand(2,10);var k = getrand(1,10); if (getrand(1,3) == 1) {k = ((2*k-1)*5)/10;}
    var y = x*k;
    var x2 = getrand(2,10);var y2 = k*x2;
    eqstr = "If Y varies directly as X and Y = " + y + " when X = " + x + ", find X when Y = " + y2 + ".";
    eqstps = "First, write the equation Y = kX";
    eqstps += "|As we know Y = " + y + " when X = " + x + ", substitute these values into equation.";
    eqstps += "|" + y + " = k &times; " + x;
    var tblstr = tmpl; tblstr = tblstr.replace("WHLNUM", "k = ");tblstr=tblstr.replace("NMRTR", "&nbsp;" + y + "&nbsp;");tblstr=tblstr.replace("DNMRTR", x);
    eqstps += "|" + tblstr;
    eqstps += "|i.e. k = " + k;
    eqstps += "|Now, substitute k value in the first equation to get Y = " + k + "X";
    eqstps += "|As you need to find X when Y = " + y2 + ", substitute Y in the above equation";
    eqstps += "|" + y2 + " = " + k + "X";
    tblstr = tmpl; tblstr = tblstr.replace("WHLNUM", "X = ");tblstr=tblstr.replace("NMRTR", "&nbsp;" + y2 + "&nbsp;");tblstr=tblstr.replace("DNMRTR", k);
    eqstps += "|" + tblstr;
    eqstps += "|<span class='grn'>X = " + x2 + "</span>";
}


function getrand(min, max)
{
  rnd = Math.floor(Math.random()*1000);
  rnd = rnd % (max-min+1);
  return min + rnd;
}

function getws()
{
    getOpt();
    var obj = document.getElementById("hdnvrbl");
    if (obj != null)
    {
        var chld = obj.appendChild(document.createElement('div')); 
        if (chld != null) {chld.innerHTML = "<input type=hidden name=opt value=" + opt + ">";}
    }
    document.y_var_x_frm.submit();
}

//-->

