/*

xProfile - Copyright by Markup (icewindrain@yahoo.co.uk)
Edited by Paper - Copyright by Paper
2b
*/

    on = true;
    off = false;


    Age = [xage, AlabelPrefix, AlabelSuffix, AvaluePrefix, AvalueSuffix, AwhereShown];
    Location = [xlocation, LlabelPrefix, LlabelSuffix, LvaluePrefix, LvalueSuffix];
    Flags = [xflags, FlabelPrefix, FlabelSuffix, FvaluePrefix, FvalueSuffix, FwhereShown];
    SoundInProfile = xsound;
    
    i = 0;
    newField = [];
    
    document.write('<script>'+xcustom+'</script>');

    var iTable;
    home=location.href.substr(0,location.href.lastIndexOf("/"));
    src="http://www.texasregion.net/js/";
    src2="http://www.texasregion.net/images/";
    flagsAt=src+"flags/";
    sPost=[];
    nFields=typeof(newField)!="undefined"?true:false;
    fID=[[],[]];
    fVal=[[],[]];
    c=0;

    if (location.href.match("act=UserCP&CODE=22"))
	document.write("<SCRIPT src="+src+"sig2.js><\/SCRIPT>");

    if (location.href.match("act=UserCP&CODE=01"))
	document.write("<SCRIPT src="+src+"prof2.js><\/SCRIPT><IFRAME name=fetcher src="+home+"/index.php?act=UserCP&CODE=22 style=height:0;width:0;border-style:none></IFRAME>");

    td=document.getElementsByTagName("TD");
    for (i=0;i<td.length;i++)
	{
	    if ((td[i].className=="post1"||td[i].className=="post2")&&td[i].width!="100%")
		{
		    sPost[c]=td[i].getElementsByTagName("SPAN")[0];
		    fID[c]=[];
		    fVal[c]=[];
		    c++;
		    getFields(td[i+1],false);
		}
	    if (location.href.match("showuser"))
		{
		    if (td[i].innerHTML.match(/<B>Interests<\/B>/i))
			iTable=td[i].parentNode.parentNode;
		    if (td[i].innerHTML.match(/<B>Signature<\/B>/i))
			getFields(td[i+1],true);
		}
	}

    for(i=0;i<sPost.length;i++)
	{
	    cont="<BR>";
	    if (Age[0]&&!isNaN(getAge(lookup(i,'dob')))&&(Age[5].toUpperCase()=="BOTH"||Age[5].toUpperCase()=="POSTS"))
		cont+=Age[1]+"Age: "+Age[2]+Age[3]+getAge(lookup(i,'dob'))+Age[4]+"<BR>";
	    if (nFields)
		for (n=0;n<newField.length;n++)
		    {
			if (newField[n][5].toUpperCase()=="BOTH"||newField[n][5].toUpperCase()=="POSTS")
			    if (lookup(i,"fd"+n))
				if (newField[n][6].length>0)
				    {
					cont+=newField[n][1]+newField[n][0]+": "+newField[n][2]+newField[n][3]+getSelected(newField[n][6])+newField[n][4]+"<BR>";
				    }
				else
				    {
					cont+=newField[n][1]+newField[n][0]+": "+newField[n][2]+newField[n][3]+lookup(i,'fd'+n)+newField[n][4]+"<BR>";
				    }
		    }
	    if (Location[0]&&lookup(i,'loc'))
		cont+=Location[1]+"Location: "+Location[2]+Location[3]+lookup(i,'loc')+Location[4]+"<BR>";
	    if (Flags[0]&&lookup(i,'flg')&&(Flags[5].toUpperCase()=="BOTH"||Flags[5].toUpperCase()=="POSTS"))
		cont+=Flags[1]+"Flag: "+Flags[2]+Flags[3]+"<IMG SRC="+flagsAt+fVal[i][x]+".gif alt="+fVal[i][x]+".gif>"+Flags[4];
	    sPost[i].innerHTML+=cont;
	}

    function getAge(uAge)
	{
	    now=new Date();
	    age=new Date(uAge);
	    nowYear=now.getFullYear();
	    birthYear=age.getFullYear();
	    if (elapsed(nowYear,now.getMonth(),now.getDate())<elapsed(birthYear,age.getMonth(),age.getDate()))
		{
		    return (nowYear-birthYear)-1;
		}
	    return nowYear-birthYear;
	}

    function elapsed(year,months,days)
	{
	    yearDays=0;
	    feb=(year%4==0&&(year%400==0||year%100!=0))?29:28;
	    monthDays=[31,feb,31,30,31,30,31,31,30,31,30,31];
	    for (n=0;n<months;n++)
		yearDays+=monthDays[n];
	    yearDays+=days;
	    return yearDays;
	}

    function getFields(dObj,alt)
	{
	    divX1 = dObj.getElementsByTagName("DIV");
	    if (divX1 !=  null && divX1 !=  "undefined")
		{
		    divFoundX1 = false;
		    for (n=0;n<divX1.length;n++)
			{
			    if (divX1[n].className=="signature")
				{
				    divFoundX1 = true;
				    break;
				}
			}
		    if (divFoundX1)
			{
			    if (divX1[n]||alt)
				{
				    if (alt)
					{
					    c=1;
					}
				    a=alt?dObj.getElementsByTagName("A"):divX1[n].getElementsByTagName("A");
				    for (n=0;n<a.length;n++)
					{
					    if (a[n].href.indexOf("xp/")==7)
						{
						    nFstring=a[n].href.substr(10,a[n].href.length).split("&");
						    for (x=0;x<nFstring.length;x++)
							{
							    nFsplit=nFstring[x].split("=");
							    fID[c-1][x]=nFsplit[0];
							    fVal[c-1][x]=unescape(nFsplit[1]);
							}
						    if (alt)
							onload=showuser;
						    break;
						}
					}
				}
			}
		}
	}

    function lookup(post,id)
	{
	    for (x=0;x<fID[post].length;x++)
		if(fID[post][x]==id)
		    return fVal[post][x];
	    return "";
	}

    function showuser()
	{
	    tr=iTable.getElementsByTagName("TR");
	    for (j=0;j<tr.length;j++)
		if (tr[j].cells[0].innerHTML.match(/<B>Interests<\/B>/i))
		    break;
	    if (Age[0]&&!isNaN(getAge(lookup(0,'dob')))&&(Age[5].toUpperCase()=="BOTH"||Age[5].toUpperCase()=="PROFILE"))
		xProfile(j-1,"Age",getAge(lookup(0,'dob')));
	    if (Flags[0]&&lookup(0,'flg')&&(Flags[5].toUpperCase()=="BOTH"||Flags[5].toUpperCase()=="PROFILE"))
		xProfile(j,"Flag","<IMG SRC="+flagsAt+lookup(0,'flg')+".gif alt="+lookup(0,'flg')+".gif>");
	    if (SoundInProfile&&lookup(0,'msc'))
		{
		    loop=lookup(0,'rpt')==1?true:false;
		    td[0].innerHTML+="<EMBED src=http://"+lookup(0,'msc')+" loop="+loop+" hidden=true autostart=true></EMBED>";
		}
	    if (nFields)
		{
		    for (n=newField.length-1;n>=0;n--)
			if ((newField[n][5].toUpperCase()=="BOTH"||newField[n][5].toUpperCase()=="PROFILE")&&lookup(0,"fd"+n))
			    {
				if(newField[n][6].length>0)
				    {
					xProfile(j,newField[n][0],getSelected(newField[n][6]));
				    }
				else 
				    {
					xProfile(j,newField[n][0],lookup(0,"fd"+n));
				    }
			    }
		}
	}

    function xProfile(iRow,lCell,rCell)
	{
	    nRow=iTable.insertRow(iRow);
	    nCell=nRow.insertCell(0);
	    with (nCell)
		{
		    className="row3";
		    width="30%";
		    vAlign="top";
		    innerHTML="<B>"+lCell+"</B>";
		}
	    nCell=nRow.insertCell(1);
	    with (nCell) 
		{
		    className="row1";
		    width="70%";
		    align="left";
		    innerHTML=rCell;
		}
	}

    function getSelected(sVar)
	{
	    for (z=0;z<sVar.length;z++)
		if (sVar[z].split("@")[0]==lookup(i,"fd"+n))
		    {
			if (sVar[z].match("@"))
			    return "<IMG SRC="+sVar[z].split("@")[1]+" alt="+sVar[z].split("@")[0]+"><BR>";
			return sVar[z];
		    }
	    return "";
	}
