﻿var Dialog = function(params)
{
	this.Title	= params.title ;
	this.Content = params.content ;
	this.Width	= params.width;
	this.Height	= params.height;
	this.Callback = params.callBack;
	this.Focus = params.focus;	
	this.IframeUrl = params.url;
	
	
}

Dialog.prototype = {

    ShowComfirm: function () {

        this.Close();

        var wt = (document.documentElement.clientHeight - this.Height) / 2;
        var wl = (document.body.clientWidth - this.Width) / 2;



        var wh = document.documentElement.scrollTop;
        var body_width = document.body.clientWidth + 'px';
        var body_height;

        if (document.documentElement.scrollHeight > document.documentElement.clientHeight) {
            body_height = document.documentElement.scrollHeight + wh + 'px';
        }
        else {
            body_height = document.documentElement.clientHeight + wh + 'px';
        }


        var dialogbg = createDiv("dialogbg", "#D5D5D5", "0px", "0px", "absolute", body_width, body_height, "999");
        dialogbg.style.filter = 'progid:DXImageTransform.Microsoft.Alpha(opacity=60,finishOpacity=10,style=0)';
        dialogbg.style.opacity = 0.8;
        dialogbg.style.top = '0px';
        dialogbg.style.left = '0px';
        document.body.appendChild(dialogbg);


        var dialog = createDiv("dialog", "#ffffff", "0px", "0px", "absolute", "0px", "0px", "10000");

        dialog.style.top = (wt + wh) + 'px';
        dialog.style.left = wl + 'px';
        dialog.style.border = "1px solid #04a0d0";

        dialog.style.width = this.Width + 10 + 'px';
        dialog.style.height = this.Height + 'px';

        dialog.style.textAlign = "center";

        document.body.appendChild(dialog);

        dialog.innerHTML = '<div style="background-color:#04a0d0;width:' + this.Width + 'px;padding:0px 5px;line-height:20px;height:20px;"><div  style="float:left;color:#FFFFFF;overflow:hidden;text-align:left;font-weight:bold;font-size:14px;">' + this.Title + '</div>'

		+ '<div style="float:right;><img src="/images/dialog_close.gif" style="cursor:hand" onclick="close_dialog()"></div>'

		+ '</div>'

		+ '<div style="clear:both;background-color:#ffffff;width:' + this.Width + 'px;overflow:hidden;text-align:left;padding:5px; border:0px solid #000000;color:#333;height:' + (this.Height - 80) + 'px;font-size:14px;">' + this.Content + '</div>'

		+ '<div style="background-color:#ffffff;width:' + this.Width + 'px;padding:5px;"><input id="dialog_confirm" type="button" value="确定" style="border:1px solid #04a0d0;background-color:#04a0d0;width:80px;color:#fff;">&nbsp;<input id="dialog_cancel" type="button" value="取消" style="border:1px solid #04a0d0;background-color:#04a0d0;width:80px;color:#fff;"></div>';

        //		dialog.innerHTML="<table class=\"pop_dialog_table\" style=\"WIDTH: 100%; HEIGHT: 100%\"><tbody><tr><td class=\"pop_topleft\"></td><td class=\"pop_border\"></td><td class=\"pop_topright\"></td></tr><tr><td class=\"pop_border\"></td><td class=\"pop_content\"><h2><span>提示</span></h2><div class=\"dialog_content\"><div class=\"dialog_body\">确定要删除这条状态吗?</div><div class=\"dialog_buttons\"><input class=\"input-submit\" type=\"button\" id=\"dialog_confirm\" value=\"确定\" dialog=\"1\"><input id=\"dialog_cancel\" class=\"input-submit gray\" type=\"button\" value=\"取消\" dialog=\"1\"></div></div></td><td class=\"pop_border\"></td></tr><tr><td class=\"pop_bottomleft\"></td><td class=\"pop_border\"></td><td class=\"pop_bottomright\"></td></tr></tbody></table>";

        var button_confirm = $('dialog_confirm');
        var button_cancel = $('dialog_cancel');


        if (button_confirm) {
            if (window.attachEvent) {
                button_confirm.attachEvent("onclick", DialogConfirmCallBackYes);
            }

            if (window.addEventListener) {
                button_confirm.addEventListener("click", DialogConfirmCallBackYes, false);
            }
            button_confirm.focus();
        }

        if (button_cancel) {

            if (window.attachEvent) {
                button_cancel.attachEvent("onclick", DialogConfirmCallBackNo);
            }

            if (window.addEventListener) {
                button_cancel.addEventListener("click", DialogConfirmCallBackNo, false);
            }
        }

    },
    ShowAlert: function () {

        this.Close();

        var wt = (document.documentElement.clientHeight - this.Height) / 2;
        var wl = (document.body.clientWidth - this.Width) / 2;

        var wh = document.documentElement.scrollTop;

        var body_width = document.body.clientWidth + 'px';
        var body_height;

        if (document.documentElement.scrollHeight > document.documentElement.clientHeight) {
            body_height = document.documentElement.scrollHeight + wh + 'px';
        }
        else {
            body_height = document.documentElement.clientHeight + wh + 'px';
        }


        var dialogbg = createDiv("dialogbg", "#D5D5D5", "0px", "0px", "absolute", body_width, body_height, "999");
        dialogbg.style.filter = 'progid:DXImageTransform.Microsoft.Alpha(opacity=60,finishOpacity=100,style=0)';
        dialogbg.style.opacity = 0.8;
        dialogbg.style.top = '0px';
        dialogbg.style.left = '0px';
        document.body.appendChild(dialogbg);


        dialog = createDiv("dialog", "#ffffff", "0px", "0px", "absolute", "0px", "0px", "10000");

        dialog.style.top = (wt + wh) + 'px';
        dialog.style.left = wl + 'px';
        dialog.style.border = "1px solid #04a0d0";

        dialog.style.width = this.Width + 10 + 'px';
        dialog.style.height = this.Height + 'px';

        dialog.style.textAlign = "center";

        document.body.appendChild(dialog);

        dialog.innerHTML = '<div style="background-color:#04a0d0;width:' + this.Width + 'px;padding:0px 5px;line-height:20px;height:20px;"><div  style="float:left;color:#FFFFFF;overflow:hidden;text-align:left;font-weight:bold;font-size:14px;">' + this.Title + '</div>'

		+ '<div style="float:right;><img src="/images/dialog_close.gif" style="cursor:hand" onclick="close_dialog()"></div>'

		+ '</div>'

		+ '<div style="clear:both;background-color:#ffffff;width:' + this.Width + 'px;overflow:hidden;text-align:left;padding:5px; border:0px solid #000000;color:#333;height:' + (this.Height - 80) + 'px;font-size:14px;">' + this.Content + '</div>'

		+ '<div style="background-color:#ffffff;width:' + this.Width + 'px;padding:5px;"><input id="dialog_confirm" type="button" value="确定" style="border:1px solid #04a0d0;background-color:#04a0d0;width:80px;color:#fff;"></div>';


        var button_confirm = $('dialog_confirm');


        if (button_confirm) {
            if (window.attachEvent) {
                button_confirm.attachEvent("onclick", DialogAlertCallBack);
            }

            if (window.addEventListener) {
                button_confirm.addEventListener("click", DialogAlertCallBack, false);
            }
            button_confirm.focus();
        }

    },
    ShowLoading: function () {

        this.Close();

        var wt = (document.documentElement.clientHeight - this.Height) / 2;
        var wl = (document.body.clientWidth - this.Width) / 2;

        var wh = document.documentElement.scrollTop;

        var body_width = document.body.clientWidth + 'px';
        var body_height;

        if (document.documentElement.scrollHeight > document.documentElement.clientHeight) {
            body_height = document.documentElement.scrollHeight + wh + 'px';
        }
        else {
            body_height = document.documentElement.clientHeight + wh + 'px';
        }


        var dialogbg = createDiv("dialogbg", "#D5D5D5", "0px", "0px", "absolute", body_width, body_height, "999");
        dialogbg.style.filter = 'progid:DXImageTransform.Microsoft.Alpha(opacity=60,finishOpacity=100,style=0)';
        dialogbg.style.opacity = 0.8;
        dialogbg.style.top = '0px';
        dialogbg.style.left = '0px';
        document.body.appendChild(dialogbg);


        dialog = createDiv("dialog", "#ffffff", "0px", "0px", "absolute", "0px", "0px", "10000");

        dialog.style.top = (wt + wh) + 'px';
        dialog.style.left = wl + 'px';
        dialog.style.border = "1px solid #04a0d0";

        dialog.style.width = this.Width + 10 + 'px';
        dialog.style.height = this.Height + 'px';

        dialog.style.textAlign = "center";

        document.body.appendChild(dialog);

        dialog.innerHTML = '<div style="background-color:#04a0d0;width:' + this.Width + 'px;padding:0px 5px;line-height:20px;height:20px;"><div  style="float:left;color:#FFFFFF;overflow:hidden;text-align:left;font-weight:bold;font-size:14px;">' + this.Title + '</div>'


		+ '</div>'

		+ '<div style="clear:both;background-color:#ffffff;width:' + this.Width + 'px;overflow:hidden;text-align:center;padding:5px; border:0px solid #000000;color:#333;height:' + (this.Height - 80) + 'px;font-size:14px;">' + this.Content + '<br/><br/><img src="images/loading.gif"/></div>'

		+ '<div style="background-color:#ffffff;width:' + this.Width + 'px;padding:5px;text-align:center;"></div>';
    },
    ShowIframe: function () {

        this.Close();

        var wt = (document.documentElement.clientHeight - this.Height) / 2;
        var wl = (document.body.clientWidth - this.Width) / 2;

        var wh =Math.max( document.documentElement.scrollTop,document.body.scrollTop);
       
        var body_width = document.body.clientWidth + 'px';
        var body_height;

        if (document.documentElement.scrollHeight > document.documentElement.clientHeight) {
            body_height = document.documentElement.scrollHeight + wh + 'px';
        }
        else {
            body_height = document.documentElement.clientHeight + wh + 'px';
        }


        var dialogbg = createDiv("dialogbg", "#D5D5D5", "0px", "0px", "absolute", body_width, body_height, "999");
        dialogbg.style.filter = 'progid:DXImageTransform.Microsoft.Alpha(opacity=60,finishOpacity=100,style=0)';
        dialogbg.style.opacity = 0.8;
        dialogbg.style.top = '0px';
        dialogbg.style.left = '0px';
        document.body.appendChild(dialogbg);


        dialog = createDiv("dialog", "#ffffff", "0px", "0px", "absolute", "0px", "0px", "10000");

        dialog.style.top = (wt + wh) + 'px';
        dialog.style.left = wl + 'px';
        dialog.style.border = "2px solid #04a0d0";

        dialog.style.clear = "both";

        dialog.style.width = this.Width + 10 + 'px';
        dialog.style.height = this.Height + 45 + 'px';

        dialog.style.textAlign = "center";

        document.body.appendChild(dialog);

        dialog.innerHTML = '<div style="background-color:#04a0d0;width:' + this.Width + 'px;padding:0px 5px;line-height:20px;height:20px"><div  style="float:left;color:#FFFFFF;overflow:hidden;text-align:left;font-weight:bold;font-size:14px;">' + this.Title + '</div>'

	    + '<div style="float:right;overflow:hidden;text-align:right;font-weight:bold;"><a href="javascript:void(0);" onclick="CloseDialog();" style="color:#ffffff;text-decoration:none;"> 关闭 </a></div></div>'

	    + '<div style="background-color:#ffffff;width:' + this.Width + 'px;padding:5px;"><iframe id="yorkdialog_iframe" name="yorkdialog_iframe"  marginheight="0"  marginwidth="0"  frameborder="0"  scrolling="auto"  width="' + (this.Width) + 'px"  height="' + (this.Height) + 'px" src="' + this.IframeUrl + '"></iframe></div>';

    },
    ShowIframe1: function () {

        this.Close();

        var wt = (document.documentElement.clientHeight - this.Height) / 2;
        var wl = (document.body.clientWidth - this.Width) / 2;

        var wh = Math.max(document.documentElement.scrollTop, document.body.scrollTop);
       
        var body_width = document.body.clientWidth + 'px';
        var body_height;
        if (document.documentElement.scrollHeight > document.documentElement.clientHeight) {
            body_height = document.documentElement.scrollHeight + wh + 'px';
        }
        else {
            body_height = document.documentElement.clientHeight + wh + 'px';
        }


        var dialogbg = createDiv("dialogbg", "#D5D5D5", "0px", "0px", "absolute", body_width, body_height, "999");
        dialogbg.style.filter = 'progid:DXImageTransform.Microsoft.Alpha(opacity=60,finishOpacity=100,style=0)';
        dialogbg.style.opacity = 0.8;
        dialogbg.style.top = '0px';
        dialogbg.style.left = '0px';
        document.body.appendChild(dialogbg);


        dialog = createDiv("dialog", "#ffffff", "0px", "0px", "absolute", "0px", "0px", "10000");

        dialog.style.top = (wt + wh) + 'px';
        dialog.style.left = wl + 'px';
        //dialog.style.border = "2px solid #04a0d0";

        dialog.style.clear = "both";
        dialog.style.width = this.Width + 'px';
        dialog.style.height = this.Height + 'px';

        dialog.style.textAlign = "center";

        document.body.appendChild(dialog);

        dialog.innerHTML = '<div style="float:right;Position:absolute;top:7px;left:360px"><a href="javascript:void(0);" onclick="CloseDialog()" style="color:#ffffff;text-decoration:none;">关闭</a></div><iframe  marginheight="0"  marginwidth="0"  frameborder="0"  scrolling="auto"  width=' + (this.Width) + 'px"  height=' + (this.Height) + 'px" src="' + this.IframeUrl + '"></iframe>';

    },
    Close: function () {

        try {
            var dialogbg = $("dialogbg");
            var dialog = $("dialog");
            document.body.removeChild(dialogbg);
            document.body.removeChild(dialog);
        }
        catch (e) {

        }
    }


}

var currentConfirm = null;

function Reset(){
	window.location=window.location;
}

function CloseDialog(){

    try
	{
		var dialogbg=$("dialogbg");
		var dialog = $("dialog");
		document.body.removeChild(dialogbg);
		document.body.removeChild(dialog);			
	}
    catch(e)
    {

    }
}


function DialogConfirm()
{
	
	var params = {
            width : 400,
			height: 120,           
            callBack : null,
            focus : null,
			title : '信息提示',
			content : '你确定要删除这条信息吗'
    };
	
	var ars = arguments;
	if(ars.length>0)
	{		
		if (ars[0].title)  params.title = ars[0].title;
		if (ars[0].callBack)  params.callBack = ars[0].callBack;
		if (ars[0].width)  params.width = ars[0].width;
		if (ars[0].height)  params.height = ars[0].height;
		if (ars[0].focus)  params.focus = ars[0].focus;
		if (ars[0].content)  params.content = ars[0].content;
	}	
	
	currentConfirm = new Dialog(params);
	currentConfirm.ShowComfirm();
}

function DialogLoading()
{
	
	var params = {
            width : 400,
			height: 150,           
            callBack : null,
            focus : null,
			title : '信息提示',
			content : ''
			
    };
	
	var ars = arguments;
	if(ars.length>0)
	{		
		if (ars[0].title)  params.title = ars[0].title;
		if (ars[0].callBack)  params.callBack = ars[0].callBack;
		if (ars[0].width)  params.width = ars[0].width;
		if (ars[0].height)  params.height = ars[0].height;
		if (ars[0].focus)  params.focus = ars[0].focus;
		if (ars[0].content)  params.content = ars[0].content;
	}
	
	currentConfirm = new Dialog(params);
	currentConfirm.ShowLoading();
}

function DialogAlert()
{
	
	var params = {
            width : 400,
			height: 150,           
            callBack : null,
            focus : null,
			title : '信息提示',
			content : ''
			
    };
	
	var ars = arguments;
	if(ars.length>0)
	{		
		if (ars[0].title)  params.title = ars[0].title;
		if (ars[0].callBack)  params.callBack = ars[0].callBack;
		if (ars[0].width)  params.width = ars[0].width;
		if (ars[0].height)  params.height = ars[0].height;
		if (ars[0].focus)  params.focus = ars[0].focus;
		if (ars[0].content) params.content = ars[0].content;		
	}
	
	currentConfirm = new Dialog(params);
	currentConfirm.ShowAlert();
}

function DialogIframe() {

    var params = {
        width: 400,
        height: 150,
        callBack: null,
        focus: null,
        title: '信息提示',
        content: '',
        url: ''

    };
    var ars = arguments;
    if (ars.length > 0) {
        if (ars[0].title) params.title = ars[0].title;
        if (ars[0].callBack) params.callBack = ars[0].callBack;
        if (ars[0].width) params.width = ars[0].width;
        if (ars[0].height) params.height = ars[0].height;
        if (ars[0].focus) params.focus = ars[0].focus;
        if (ars[0].content) params.content = ars[0].content;
        if (ars[0].url) params.url = ars[0].url;
    }

    currentConfirm = new Dialog(params);
    currentConfirm.ShowIframe();
}

function DialogIframe1()
{
	
	var params = {
            width : 400,
			height: 150,           
            callBack : null,
            focus : null,
			title : '信息提示',
			content : '',
			url :''
			
    };
	var ars = arguments;
	if(ars.length>0)
	{		
		if (ars[0].title)  params.title = ars[0].title;
		if (ars[0].callBack)  params.callBack = ars[0].callBack;
		if (ars[0].width)  params.width = ars[0].width;
		if (ars[0].height)  params.height = ars[0].height;
		if (ars[0].focus)  params.focus = ars[0].focus;
		if (ars[0].content)  params.content = ars[0].content;
		if (ars[0].url)  params.url = ars[0].url;
	}
	
	currentConfirm = new Dialog(params);
	currentConfirm.ShowIframe1();
}



function DialogConfirmCallBackYes()
{	
    try
    {
	    currentConfirm.Close();
	    if(currentConfirm.Callback)
	    {
		    currentConfirm.Callback(true);
		    currentConfirm.Focus.focus();
	    }
	}
    catch(e)
    {

    }
	
}
function DialogConfirmCallBackNo()
{	
	try
    {
	    currentConfirm.Close();
	    if(currentConfirm.Callback)
	    {
		    currentConfirm.Callback(false);
		    currentConfirm.Focus.focus();
	    }
	}
    catch(e)
    {

    }
}


function DialogAlertCallBack()
{	
	try
    {
	    currentConfirm.Close();	    
	    if(currentConfirm.Callback)
	    {
		    currentConfirm.Callback();		    
	    }
	    currentConfirm.Focus.focus();
	}
    catch(e)
    {

    }
}

function createDiv(dvid,bgcolor,lft,tp,pos,wdth,hgt,zindex){
	var newdv = document.createElement("div");
	if(dvid!=""){
		newdv.id = dvid;
	}
	if(bgcolor!=""){
		newdv.style.backgroundColor=bgcolor;
	}
	if(lft!=""){
		newdv.style.left = lft;
	}
	if(tp!=""){
		newdv.style.top = tp;
	}
	if(pos!=""){
		newdv.style.position = pos;
	}
	if(wdth!=""){
		newdv.style.width = wdth;
	}
	if(hgt!=""){
		newdv.style.height = hgt;
	}
	if(zindex!=""){
		newdv.style.zIndex = zindex;
	}
	return newdv;
}
function $(id) 
{
	return document.getElementById(id);
}

function ShowAlert(content, objfocus) {
    DialogAlert(
{
    content: content,
    focus: objfocus
});
}

function AddFriend(Addurl, UserId) {  
    if (UserId > 0) {
        DialogIframe(
	{
	    url: Addurl,
	    width: 400,
	    height: 150
	});
    }
    else {
        ShowAlert("请登陆后再加好友");
    }
}

function showLogin(Addurl, UserId) { 
    if (UserId < 0) {
        DialogIframe1(
	{
	    url: Addurl,
	    width: 400,
	    height: 270
	});
    }
    else {
        alert("你已经登录过了");
    }
}



function getNewSubmitForm(method) {
    var submitForm = document.createElement("FORM");
    document.body.appendChild(submitForm);
    if (method)
    {submitForm.method = method;} else {
        submitForm.method = "get";
    }
    return submitForm;
}

//helper function to add elements to the form
function createNewFormElement(inputForm, elementName, elementValue) {
    var newElement = document.createElement("INPUT");
    newElement.type = "hidden";
    newElement.name = elementName;
    inputForm.appendChild(newElement);
    newElement.value = elementValue;
    return newElement;
}
//function that creates the form, adds some elements
//and then submits it
function createFormAndSubmit(createFormElements, actionURL, targetValue, method) {
    var submitForm = getNewSubmitForm(method);
    for (var name in createFormElements) {
        if (createFormElements[name] != "")
            createNewFormElement(submitForm, name, createFormElements[name]);
    }
    submitForm.action = actionURL;
    if (targetValue != undefined && targetValue != null) {
        submitForm.target = targetValue;
    }
    //alert(submitForm.childNodes.item(0).name);
    submitForm.submit();
    return submitForm;
}

function doane(event) {
    e = event ? event : window.event;
    if (is_ie) {
        e.returnValue = false;
        e.cancelBubble = true;
    }
    else if (e) {
        e.stopPropagation();
        e.preventDefault();
    }
}
function OnEnterNext(event, obj) {
    obj = $(obj);
    if (event.keyCode == 13) {
        if (obj != undefined && (obj.tagName == "INPUT" || obj.tagName == "SELECT")) {
            if (obj.getAttribute("type") == "text" || obj.getAttribute("type") == "password" || obj.tagName == "SELECT") {
                obj.focus();
            }
            else if (obj.getAttribute("type") == "button" || obj.getAttribute("type") == "submit") {
                obj.click();
            }
        }
        doane(event);

    }
}

function showMyCenter(id) {
    var showobj = $(id);
    if (showobj) {
        showobj.style.display = "block";
        var objchild = showobj.childNodes.length;
        for (var i = 0; i < objchild; i++) {
            showobj.childNodes[i].onmouseover = function () { showobj.style.display = 'block'; };
        }
    }
}

function PMToMember(Addurl, UserId) {
    if (UserId > 0) {
        DialogIframe(
	{
	    url: Addurl,
	    width: 580,
	    height: 410
	});
    }
    else {
        ShowAlert("只有登录后才能发送短消息");
    }
}
