var testwindow;

function pg_init()
{
document.getElementById('st').checked=true;
document.getElementById('title').style.display="block";
document.getElementById('mpt').style.display="block";
document.getElementById('pt').innerHTML=document.getElementById('title_text').value;

document.getElementById('saft').checked=true;
document.getElementById('aft').style.display="block";
document.getElementById('maft').style.display="block";
document.getElementById('paft').innerHTML=document.getElementById('aft_text').value;

document.getElementById('snfap').checked=true;
document.getElementById('so').checked=true;

document.getElementById('svaf').checked=true;
document.getElementById('vaf').style.display="block";

document.getElementById('slp').checked=true;

renderfriends();
}

function showpg(fid)
{
        x = "furl"+fid;
        b = document.getElementById(x).value;
        y = "fname"+fid;
        c = document.getElementById(y).value;
        z = "fpic"+fid;
        d = document.getElementById(z).value;

        testwindow= window.open ("", "mywindow", "location=0,status=0,scrollbars=0,width=300,height=250");
        testwindow.focus();
        testwindow.opener = window;
        testwindow.opener.name = self.name;
        testwindow.document.write("<script type='text/javascript'>\n");
        testwindow.document.write("function yesgo()\n{\n");
        testwindow.document.write("window.opener.document.getElementById('"+x+"').value=document.getElementById('fpurl').value;\n");
        testwindow.document.write("window.opener.document.getElementById('"+y+"').value=document.getElementById('fdname').value;\n");
        testwindow.document.write("window.opener.document.getElementById('"+z+"').value=document.getElementById('fdpic').value;\n");
        testwindow.document.write("window.opener.renderfriends();\n");
        testwindow.document.write("window.close();\n");
        testwindow.document.write("return false;\n}\n");
        testwindow.document.write("</script>\n");

        testwindow.document.write("<b>Provide Info</b><br><form name=ss method=post action='#' onSubmit='return yesgo();'>");
        testwindow.document.write("<b>What is the URL to this Friend's Profile?");
        testwindow.document.write("<br><input type='text' id='fpurl' name='fpurl' value='' size='30'>");
        testwindow.document.write("<br><b>What is the Friend's Display Name?");
        testwindow.document.write("<br><input type='text' id='fdname' name='fdname' value='NoBody' size='30'>");
        testwindow.document.write("<br><b>What is the Friend's Display Picture URL?");
        testwindow.document.write("<br><input type='text' id='fdpic' name='fdpic' value='' size='30'>");
        testwindow.document.write("<br><input type='submit' name='Submit' value='Save'>");
        testwindow.document.write("&nbsp;&nbsp;<input type='reset' name='Reset' value='Reset'>");
        testwindow.document.write("&nbsp;&nbsp;<input type='button' name='Cancel' value='Cancel' onClick='window.close();'>");
        testwindow.document.write("</form>");
        
        testwindow.document.write("<script type='text/javascript'>");
        testwindow.document.write("document.getElementById('fpurl').value='"+b+"';");
        testwindow.document.write("document.getElementById('fdname').value='"+c+"';");
        testwindow.document.write("document.getElementById('fdpic').value='"+d+"';");
        testwindow.document.write("</script>");
        
}

function showtitle()
{
        if(document.getElementById('st').checked==1)
        {
                document.getElementById('title').style.display="block";
                document.getElementById('mpt').style.display="block";
                document.getElementById('pt').innerHTML=document.getElementById('title_text').value;
        }
        else
        {
                document.getElementById('title').style.display="none";
                document.getElementById('mpt').style.display="none";
        }
}

function showaft()
{
        if(document.getElementById('saft').checked==1)
        {
                document.getElementById('aft').style.display="block";
                document.getElementById('maft').style.display="block";
                document.getElementById('paft').style.display="block";
                document.getElementById('paft').innerHTML=document.getElementById('aft_text').value;
        }
        else
        {
                document.getElementById('aft').style.display="none";
                document.getElementById('paft').style.display="none";
        }
}

function showvaf()
{
        if(document.getElementById('svaf').checked==1)
        {
                document.getElementById('vaf').style.display="block";
        }
        else
        {
                document.getElementById('vaf').style.display="none";
        }
}

function showvac()
{
//        if(document.getElementById('svac').checked==1)
              document.getElementById('vac').style.display="block";
//        else
//                document.getElementById('vac').style.display="none";
}

function hideall()
{
        if(document.getElementById('hac').checked==1)
        {
                document.getElementById('sc').disabled=true;
                document.getElementById('mocc').disabled=true;
                document.getElementById('svac').checked=true;
                showvac();
        }
        else
        {
                document.getElementById('sc').disabled=false;
                document.getElementById('mocc').disabled=false;
                document.getElementById('svac').checked=false;
                showvac();
        }
}

function chd()
{
        document.getElementById('pt').innerHTML=document.getElementById('title_text').value;
}

function chd2()
{
        document.getElementById('paft').innerHTML=document.getElementById('aft_text').value;
}

function talign(whichone,newalign)
{
        document.getElementById(whichone).align=newalign;
}

function vafalign(newalign)
{
        document.getElementById('vaf_align_h').value=newalign;
}

function vacalign(newalign)
{
        document.getElementById('vac_align_h').value=newalign;
}

function renderfriends()
{
        var i, j, k, showname, onlinenow, rows, cols, ih, sn, onl;
        ih = "";
        if (document.getElementById('snfap').checked) showname=1; else showname=0;
        if (document.getElementById('so').checked) onlinenow=1; else onlinenow=0;
        rows = document.getElementById('frows').value;
        cols = document.getElementById('fcols').value;
        i = 1; j=1;
        ih = "<table width=20% border=0 cellsapcing=3 cellpadding=3>";
        k = 1;
        for(i=1;i<=rows;i++)
        {
           ih = ih+"<tr>";
           for(j=1;j<=cols;j++)
           {
                if(showname)
                {
                        fn = "fname"+k;
                        sn=document.getElementById(fn).value;
                        if(sn=="NoBody") sn="Click Me";
                }
                else
                sn="";
                fpic = "fpic"+k;
                pic=document.getElementById(fpic).value;
                if(pic=="http://") pic="../friend/friend.png";

                if(onlinenow)
                onl = "<img src='onlinenow.gif' width=80 height=20>";
                else
                onl="";
                ih = ih+"<td align=center>"+ sn +"<br><a href='javascript:void(0);' onClick=\"showpg('"+ k +"');\"><img src='"+ pic +"' border='0'></a><br>"+ onl + "</td>";
                k++;
           }
           ih = ih+"</tr>";
        }

        //GENERATE VIEW ALL FRIENDS LINK
        if (document.getElementById('svaf').checked)
        {
                ih= ih+"<tr><td colspan="+ cols +" align="+ document.getElementById('vaf_align_h').value +">"+document.getElementById('vaf_text').value+"</td></tr>";
        }
        if (document.getElementById('svac').checked)
        {
                if(document.getElementById('vac_color').value=="") $color="0000FF"; else $color=document.getElementById('vac_color').value;
                ih= ih+"<tr><td colspan="+ cols +" align="+ document.getElementById('vac_align_h').value +"><font color=#"+$color+">"+document.getElementById('vac_text').value+"</td></tr>";
        }
        ih = ih+"</table>";
        document.getElementById('friends').innerHTML=ih;
}


