function  UserProfilePicture(login,title)
{
  var XMLProfileRequest = new XMLRequestf();
  XMLProfileRequest.openxmlurl = "../addressbook/profilepicturexml.php?u=" + login;
  XMLProfileRequest.loadedcallback =  "CreateUserProfilePicture('" + title + "');";
  XMLProfileRequest.loaderrorcallback =  "DialogBox(\"userprofile\",'" + title + "',\"\",400,300);";
  XMLProfileRequest.LoadRequest();
}

function  UserProfile(login,title)
{
  var XMLProfileRequest = new XMLRequestf();
  XMLProfileRequest.openxmlurl = "../addressbook/profilexml.php?u=" + login;
  XMLProfileRequest.loadedcallback =  "CreateUserProfile('" + title + "');";
  XMLProfileRequest.loaderrorcallback =  "DialogBox(\"userprofile\",'" + title + "',\"\",400,300);";
  XMLProfileRequest.LoadRequest();
}

function CreateUserProfile(title)
{

  profile = "<table id=\"profiletable\" border=\"0\" cellspacing=\"3\" cellpadding=\"3\">\n";
  var xmluser = XMLRequest.responseXML.getElementsByTagName("user");
  xmlusercn = xmluser.item(0).childNodes;
  var names = new Array();
  var values = new Array();  
  var count = 0;
    for (i=0;i<xmlusercn.length;i++)
	{
     if (xmlusercn.item(i).nodeType==1)
     {
      names[count] = xmlusercn.item(i).nodeName;
      values[count] = xmlusercn.item(i).childNodes[0].nodeValue;
	  count++;	  
	 }
	}		
    for (i=0;i<names.length;i++)
	{
	 lname = names[i];
	 lvalue = values[i];
	 i++;
	 name = names[i];	 
	 value = values[i];
	 switch (name)
     {
     case "givenname":
     profile += "<tr><td align=\"right\"><b>" + lvalue + ":</b></td><td align=\"left\">"+ value + "</td>";	 
     break
     case "picture":
      profile += "<td valign=\"top\" rowspan=\"" + names.length + "\">" + value + "</td></tr>\n";
     break
     case "description":
      profile += "<tr><td align=\"right\"><b>" + lvalue + ":</b></td><td align=\"left\"></td></tr>\n";
      profile += "<tr valign=\"top\"><td colspan=\"3\" align=\"left\">" + value + "</td></tr>\n";
  	 break
     case "editprofile":
      profile += "<tr valign=\"top\"><td colspan=\"3\" align=\"left\"><span class=\"button\"><span class=\"buttonmargin\"><a href=\"" + value + "\" class=\"buttonlink\">" + lvalue +  "</a></span></span></td></tr>\n";
  	 break
	 default:
     profile += "<tr><td align=\"right\"><b>" + lvalue + ":</b></td><td align=\"left\">"+ value + "</td></tr>\n";
	 break
	 }
	}
  profile += "</table>\n";  
  
  DialogBox("userprofile",title,profile,400,300);
  var oheight = parseInt(document.getElementById("profiletable").offsetHeight);
  var owidth = parseInt(document.getElementById("profiletable").offsetWidth);
  document.getElementById("userprofile").style.height = oheight + "px";
  document.getElementById("userprofile").style.width = owidth + 80 + "px"; 
  
// var wwidth = document.documentElement.clientWidth - 40;
// var hheight = document.documentElement.clientHeight - 156;
 var wwidth = document.documentElement.clientWidth - 40;
 var hheight = document.documentElement.clientHeight - 156;
 var posX = PosXSearch(owidth);
 var posY = PosYSearch(oheight);
    
 document.getElementById("userprofile").style.top = posY + "px";
 document.getElementById("userprofile").style.left = posX + "px";
 
  
}

function CreateUserProfilePicture(title)
{
 profile = "\n";
 var givenname = "";
 var surname = "";
 var width = 0;
 var height = 0;
  var xmluser = XMLRequest.responseXML.getElementsByTagName("user");
  xmlusercn = xmluser.item(0).childNodes;
  var names = new Array();
  var values = new Array();  
  var count = 0;
    for (i=0;i<xmlusercn.length;i++)
	{
     if (xmlusercn.item(i).nodeType==1)
     {
      names[count] = xmlusercn.item(i).nodeName;
      values[count] = xmlusercn.item(i).childNodes[0].nodeValue;
	  count++;	  
	 }
	}		
    for (i=0;i<names.length;i++)
	{
	 lname = names[i];
	 lvalue = values[i];
	 i++;
	 name = names[i];	 
	 value = values[i];
	 switch (name)
     {
     case "picture":
      profile += value + "\n";
      break
     case "givenname":
      givenname = value;
      break
     case "surname":
      surname = value;
      break    
     case "widthlarge":
      width = parseInt(value);
      break         
     case "heightlarge":
      height = parseInt(value);
      break 
	 }
	}
 title = givenname + " " + surname;
 profile = "<div class=\"imagemargin\">" +  profile +  "</div>";   
 DialogBox("userprofile",title,profile,width,height);
}

