var xmouse;
var ymouse;
var code = "";
var cols = 4;
var rows = 2;
var showTitle = true;
var showFriends = true;
var showNames = true;
var showOnline = true;
var showAllFriends = true;
var showComments = true;
var titleText = "My Friend Space";
var titleAlign = "left";
var friendsText = 'I have <span class="redbtext">100</span> friends';
var friendsAlign = "left";
var allFriendsText = "View All of My Friends";
var allFriendsAlign = "right";
var allFriendsURL = "http://";
var commentsText = "View/Edit All Comments";
var commentsAlign = "right";
var commentsURL = "http://";
var scrollComments = false;
var hideComments = false;
var centerAll = false;
var centerComments = false;
var limitWd = true;

var spots = new Array(5);
for (i=0; i<5; i++){
  spots[i] = new Array(8);
  for(j=0; j<8; j++){
    spots[i][j] = new Array(3);
    spots[i][j][0]='javascript:showForm('+i+','+j+')';
    spots[i][j][1]='Click Me!';
    spots[i][j][2]='http://i.myspace.com/site/images/no_pic.gif';
  }
}

function setCols(val){
  cols = val;
  update();
}

function setRows(val){
  rows = val;
  update();
}

function setTitle(val){
  showTitle = val;
  if(val){
    document.settings['titleText'].value=titleText;
    document.settings['titleAlign'].value=titleAlign;
    document.getElementById('titleText').style.display='block';
  }
  else document.getElementById('titleText').style.display='none';
  update();
}

function setFriends(val){
  showFriends = val;
  if(val){
    document.settings['friendsText'].value=friendsText;
    document.settings['friendsAlign'].value=friendsAlign;
    document.getElementById('friendsText').style.display='block';
  }
  else document.getElementById('friendsText').style.display='none';
  update();
}

function setNames(val){
  showNames = val;
  update();
}

function setOnline(val){
  showOnline = val;
  update();
}

function setAllFriends(val){
  showAllFriends = val;
  if(val){
    document.settings['allFriendsText'].value=allFriendsText;
    document.settings['allFriendsURL'].value=allFriendsURL;
    document.settings['allFriendsAlign'].value=allFriendsAlign;
    document.getElementById('allFriendsText').style.display='block';
  }
  else document.getElementById('allFriendsText').style.display='none';
  update();
}

function setComments(val){
  showComments = val;
  if(val){
    document.settings['commentsText'].value=commentsText;
    document.settings['commentsURL'].value=commentsURL;
    document.settings['commentsAlign'].value=commentsAlign;
    document.getElementById('commentsText').style.display='block';
  }
  else document.getElementById('commentsText').style.display='none';
  update();
}

function setTitleText(val){
  titleText=val;
  update();
}

function setTitleAlign(val){
  titleAlign=val;
  update();
}

function setFriendsText(val){
  friendsText=val;
  update();
}

function setFriendsAlign(val){
  friendsAlign=val;
  update();
}

function setAllFriendsText(val){
  allFriendsText=val;
  update();
}

function setAllFriendsAlign(val){
  allFriendsAlign=val;
  update();
}

function setAllFriendsURL(val){
  allFriendsURL=val;
  update();
}

function setCommentsText(val){
  commentsText=val;
  update();
}

function setCommentsAlign(val){
  commentsAlign=val;
  update();
}

function setCommentsURL(val){
  commentsURL=val;
  update();
}

function setScroll(val){
  scrollComments = val;
  update();
}

function setHide(val){
  hideComments = val;
  document.settings['scrollComments'].disabled=val;
  document.settings['centerComments'].disabled=val;
  document.settings['centerComments'].checked=false;
  centerComments = false;
  update();
}

function setCenterAll(val){
  centerAll = val;
  document.settings['centerComments'].checked=false;
  centerComments = false;
  update();
}

function setCenterComments(val){
  centerComments = val;
  document.settings['centerAll'].checked=false;
  centerAll = false;
  update();
}

function setLimitWd(val){
  limitWd=val;
  update();
}

function showForm(row, col){
  document.fillForm['row'].value = row;
  document.fillForm['col'].value = col;
  if(spots[row][col][0].substr(0,4)=="http")document.fillForm['url'].value = spots[row][col][0];
  else document.fillForm['url'].value = "http://";
  document.fillForm['image'].value = spots[row][col][2];
  if(spots[row][col][1]!="Click Me!")document.fillForm['name'].value = spots[row][col][1];
  else document.fillForm['name'].value = "Nobody";

  document.getElementById('fill').style.left = 660;
  document.getElementById('fill').style.top = 660;
  document.getElementById('fill').style.display = 'block';
}

function cancel(){
  document.getElementById('fill').style.display = 'none';
}

function fillSpot(){
  var i = document.fillForm['row'].value;
  var j = document.fillForm['col'].value;
  
  spots[i][j][0]=document.fillForm['url'].value;
  spots[i][j][1]=document.fillForm['name'].value;
  spots[i][j][2]=document.fillForm['image'].value;
  
  document.getElementById('fill').style.display = 'none';
  update();
}


function update(target){
  var code2="";
  var title="";
  var friends="";
  var name="";
  var online="";
  var online2="";
  var allfriends="";
  var comments="";
  var scroll="";
  var hide="";
  var centerAllTxt="";
  var centerCommentsTxt="";
  var width="";
  var cc2='';
  var hide2='';
  
  if(showTitle)title='<tr><td align="left" height="20" width="435"><table style="height:20px" bgcolor="ffcc99" cellpadding="0" cellspacing="0" width="100%"><tr><td width="100%" align="'+titleAlign+'"><span class="orangetext15" style="display:inline">&nbsp;&nbsp;&nbsp;'+titleText+'</span></td></tr></table></td></tr>';
  if(showFriends)friends='<tr><td class="text" colspan="'+cols+'" width="100%" align="'+friendsAlign+'"><span style="font-weight:bold;">'+friendsText+'</span></td></tr>';
  if(centerAll){
    centerAllTxt='</td></tr></table>';
    cc2='class="text"';
  }
  if(hideComments)document.codeForm['hidecomments'].value='1';
  else document.codeForm['hidecomments'].value='0';
  code = '</td></tr></table></td></tr></table>'+centerAllTxt+'<table border="0" bordercolor="000000" cellpadding="2" cellspacing="0" width="435">'+title+friends+'<tr><td><table align="center" border="0" cellpadding="5" cellspacing="0" width="100%"><tr><td align="center" valign="top" width="1"><table align="center" border="0" cellspacing="0">';
  code2=code;
  for (i=0; i<rows; i++){
    code += '<tr>';
    code2 += '<tr>';
    for (j=0; j<cols; j++){
        var uid = spots[i][j][0].split("/");
        if(uid[3]==undefined)uid[3]="0";
        if(showNames)name='<tr><td align="center" valign="top" width="107"><a href="'+spots[i][j][0]+'">'+spots[i][j][1]+'</a></td></tr>';
        else name='';
        if(showOnline){
            online2='<br><div style="width:80px;height:20px;" ID="UserDataNode'+(i*10+j)+'" CLASS="DataPoint=OnlineNow;UserID='+uid[3]+';"></div>';
            online='<br><div style="width:80px;height:20px;" ID="UserDataNode'+(i*10+j)+'" CLASS="DataPoint=OnlineNow;UserID='+uid[3]+';"><img src="http://i.myspace.com/site/images/onlinenow.gif"/></div>';
        }
        else {online=''; online2='';}
        if(limitWd)width='style="width:auto!important; width:90px; max-width:90px"';
        code += '<td align="center" valign="top" width="1"><table align="center" border="0" cellspacing="3">'+name+'<tr><td align="center" valign="top" width="25%"><a href="javascript:showForm('+i+','+j+')"><img src="'+spots[i][j][2]+'" '+width+'></a>'+online+'</td></tr></table></td>';
        code2 += '<td align="center" valign="top" width="1"><table align="center" border="0" cellspacing="3">'+name+'<tr><td align="center" valign="top" width="25%"><a href="'+spots[i][j][0]+'"><img src="'+spots[i][j][2]+'" '+width+'></a>'+online2+'</td></tr></table></td>';
    }
    code += '</tr>';
    code2 += '</tr>';
  }
  if(showAllFriends)allfriends='<tr align="'+allFriendsAlign+'" valign="center"><td colspan="4" bgcolor="ffffff"><a target="_blank" href="'+allFriendsURL+'" class="redlink">'+allFriendsText+'</a></td></tr>';
  if(showComments)comments='<tr align="'+commentsAlign+'" valign="center"><td colspan="4" bgcolor="ffffff"><a target="_blank" href="'+commentsURL+'">'+commentsText+'</a></td></tr>';
  if(scrollComments)scroll='display:block; height:400px; overflow:auto;';
  if(hideComments)hide='<div style="display:none">';
  if(centerComments){
    centerCommentsTxt='</td></tr></table></td></tr></table>';
    cc2='class="text"';
  }
  if(!hideComments)hide2='<tr><td><table style="'+scroll+'"><tr><td '+cc2+'><table style="display:none">';
  code += '</table></td></tr>'+allfriends+comments+'</table>'+centerCommentsTxt+'<br>'+hide+'<table>'+hide2+'<tr><td><table><tr><td>';
  code2 += '</table></td></tr>'+allfriends+comments+'</table>'+centerCommentsTxt+'<br>'+hide+'<table>'+hide2+'<tr><td><table><tr><td>';
  document.getElementById('code').innerHTML = code;
  document.codeForm['area'].value = code2;
}

function getMouse(eventObject){
	xmouse = eventObject.clientX;
	ymouse = eventObject.clientY;
}
