﻿var showFriendDialog = function(target, namestr, e,strTitle,strOk,strCancel) {
    this.stateChanged(target, namestr, e,strTitle,strOk,strCancel);
}

Function.prototype.method = function(name, fn, e) {
    this.prototype[name] = fn;
    return this;
}

showFriendDialog.prototype.isiebody=function(){
			return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
		}
		


showFriendDialog.method("stateChanged", function(target, str,e,strTitle,strOk,strCancel) {
    //document.documentElement.style.overflow = "hidden";
    var myDialog = this;
    var names = [];
    names = str.split(',');
    var html = "";
    for (i = 0; i < names.length; i++) {
      if (names[i]!=" ")
        if (i == 0)
            html += '<input class="Normal" checked=true id="Radio' + i.toString() + '" name="name"  value="' + names[i] + '" type="radio" /><label class="Normal" for="Radio' + i.toString() + '" >' + names[i] + '</label><br/>';
        else
            html += '<input class="Normal" id="Radio' + i.toString() + '" name="name"  value="' + names[i] + '" type="radio" /><label class="Normal" for="Radio' + i.toString() + '" >' + names[i] + '</label><br/>';
    }
    var div = document.createElement("div");
    div.id = "dialog";
    //var top = document.documentElement.scrollTop;
    var top =this.isiebody().scrollTop;
    //div.style.top = top + "px";
 
  //  if (document.compatMode && document.compatMode!="BackCompat")
   //    { div.style.postion="fixed"; alert(div.style.postion);}
   // else
    //   {  div.style.postion="absolute";alert(div.style.postion);}
       
     div.style.left = window.screen.width / 2.5 + "px";
    div.style.top =top + 200 + "px";
    var container = document.getElementById(target);
    container.appendChild(div);
    div.innerHTML =       '<div class="title">'+ strTitle +'</div>' +
                            '<div class="content" id="target">' +
                            '</div>' +
                            '<div id="bottondiv"><input value="' + strOk + '" id="addname" type="button" class="StandardButton" />  <input id="canclename" value="' + strCancel + '" type=button  class="StandardButton" /></div>'   ;
                        
                        
    document.getElementById("target").innerHTML = html;
   // var delogdiv = document.getElementById("dialog");
   // delogdiv.style.left = window.screen.width / 2.5 + "px";
   // delogdiv.style.top = "200px";
  
    var buttonadd = document.getElementById("addname");
    buttonadd.onclick = function(i) {
   
        myDialog.showName(e, target);
     
    };
  
    var buttoncancle = document.getElementById("canclename");
    buttoncancle.onclick = function(i) {
        myDialog.cancle(target);
    }
})
    .method("showName", function(e, target) {
        var myDialog = this;
        var div = document.getElementById("target");
        var childres = div.childNodes;
        var name;
        var jj;
        for (i = 0; i < childres.length; i++) {
            if (childres[i].checked == true) {
                name = childres[i].value;
                jj=i;             }
        }
        if (name == null) {  }
        else {
            myDialog.cancle(target);
            if(jj==0)
               myDialog.onShow(e, name);
            else
               myDialog.onSaveDirectly(e, name);   
        }
    })
    
    
    .method("cancle", function(targetid) {
        document.documentElement.style.overflow = "auto";
        var div = document.getElementById(targetid);
        div.innerHTML = "";
    })
    .method("onShow", function(e, name) {

    });



