

/**
 * @method 被iframe调用的回调函数
 * @return 
 * @author 
 * @update 08.09.18 13:20:54
 */
function cbUploadImg(flag,code)
{
	if(flag == 'fail')
		alert(code);
	else
	{
			jQuery("#imgshow").attr('src',code);
			processImg.init ("draw");
			//$('#leftslider').show();
			//$('#rightslider').show();

	}
}


/**
 * @OBJ :  chip用户上传头像
 * @ps      
 * @return 
 * @author 
 * @update 08.11.17 18:59:48
 */
var processImg = {
  _imgsetWH : [120,120],
  _showimgWH : [120,120],
  _showimgTL:[0,0],
  _min : 0,
  _max : 100,
  _start : 50
};

processImg.init = function(flag){

	jQuery("#imgshow").draggable({
	  snapMode:'outer',
	  cursor: 'move',
	  //containment: $('#imgwrapp'),
	  drag: function(e, ui) {
		  processImg._showimgTL[0] = ui.position.top;
		  processImg._showimgTL[1] = ui.position.left;
	  },
	  stop: function(e,ui){
		//debug(processImg._showimgTL);
	  }
	});

	if(flag == "draw")
		jQuery("#imgshow").load(this.getimgwh); //注册事件 图片加载完成时取图片的原始大小
	else
		this.getimgwh();
	this.slider();
}

// 改函数给showimg的load事件调用，所以这里的this 是showimg
processImg.getimgwh = function(){
	var src = jQuery("#imgshow").attr("src");
	var timg = jQuery('<img>').attr('src', src).css({ position: 'absolute', top: '-1000px', left: '-1000px' }).appendTo('body');
	var size = [ timg.get(0).offsetWidth, timg.get(0).offsetHeight ];
	try { document.body.removeChild(timg[0]); }
	catch(e) {};
	processImg._showimgWH = size; // 得到加载图片的原始大小
	var left = (size[0] - processImg._imgsetWH[0]) / 2;
	var top = (size[1] - processImg._imgsetWH[1]) / 2;
	jQuery("#imgshow").css("left",-left+"px");
	jQuery("#imgshow").css("top",-top+"px");
}; 

processImg.slider = function(){
  
  jQuery("#imgshow").removeAttr("width"); 
  jQuery("#imgshow").removeAttr("height"); 
  jQuery("#slider3").slider("destroy");
  jQuery("#slider3").slider({
	min:processImg._min,
	max:processImg._max,
	startValue:processImg._start,
	stop:function(e,ui){},
	slide:function(e,ui){
	  
	  var P = processImg;
	  var oldw = jQuery("#imgshow").attr("width");
	  var oldh = jQuery("#imgshow").attr("height");
	  
	  var w,h,t,l;
	  var v = ui.value;
	  var rate = v / P._start;

	  if(rate*P._showimgWH[0] <= P._imgsetWH[0] || rate*P._showimgWH[1] <= P._imgsetWH[1])
	  {
		return;
	  }
	  w = rate*P._showimgWH[0];
	  h = rate*P._showimgWH[1];
	  var wadd = (w - oldw)/2;
	  var hadd = (h - oldh)/2;

	  l = jQuery("#imgshow").css("left");
	  if(l== 'auto') l = "0px";
	  l = l.split("px")[0];
	  //if(isNaN(l)) l = 0;
	  l = l - wadd;
	  jQuery("#imgshow").css("left",l+"px");
	  
	  t = jQuery("#imgshow").css("top");
	  if(t== 'auto') t = "0px";
	  t = t.split("px")[0];
	  //if(isNaN(t)) t = 0;
	  t = t - hadd;
	  jQuery("#imgshow").css("top",t+"px");
	  
	  jQuery("#imgshow").attr("width",w);
	  jQuery("#imgshow").attr("height",h);
	  
	}
	});
}

processImg.imgchip = function(){
  var para = {};
  var img = jQuery("#imgshow");
  para['w'] = img.attr("width");
  para['h'] = img.attr("height");
  para['l'] = img.css("left").split("px")[0];
  para['t'] = img.css("top").split("px")[0];
  para['img'] = img.attr("src");

  jQuery(":input[name='img']").val(para['img']);
  jQuery(":input[name='w']").val(para['w']);
  jQuery(":input[name='h']").val(para['h']);
  jQuery(":input[name='l']").val(para['l']);
  jQuery(":input[name='t']").val(para['t']);
  
  jQuery("#chipform").submit();
  //var url = "/group/chipimgajax.php";
  //$.post(url,para,function(data){ processImg.cbImgChip(data);}); 
}



processImg.cbImgChip = function(data){
	jQuery("#bglogo").val(proJson_2(data));
}


function closeDiv(id)
{
	$(id).style.display  = "none";
}


// msn invite
function G_MsnInvite(msn, passwd)
{
	$("invitemsg").style.display = "";
	var url = "/home/msninvite_ajax.php";
	var pars = "msn=" + msn + "&passwd=" + passwd;
	var myAjax = new Ajax.Request(url, {method: "post", parameters: pars, onComplete: function (req) { CB_MsnInvite(req); } });
}

function CB_MsnInvite(req)
{
	var  re = proJson(req);
	if(re == 1)
	{
		window.location.href="/home/msninvite_form.php";
	}
	else
	{
		$("invitemsg").style.display = "none";
	}
}

function checkInviteMsn()
{
	var msn = $("msn").value;
	var passwd = $("passwd").value;
	
	if(msn == "" || passwd == "")
	{
		alert("msn账号和密码不能为空");
		return;
	}
	
	G_MsnInvite(msn, passwd);
}

/**
 * @method 复制到剪贴板
 * @return 
 * @author sina & zhoudan@staff.sina.com.cn
 * @update 08.11.14 16:06:04
 */
function copyToClipboard(txt) { 
    if(window.clipboardData) 
    { 
        window.clipboardData.clearData(); 
        window.clipboardData.setData("Text", txt); 
    } 
    else if(navigator.userAgent.indexOf("Opera") != -1) 
    { 
        window.location = txt; 
    } 
    else if (window.netscape) 
    { 
        try { 
            netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect"); 
        } 
        catch (e) 
        { 
            alert("!!被浏览器拒绝！\n请在浏览器地址栏输入'about:config'并回车\n然后将'signed.applets.codebase_principal_support'设置为'true'"); 
        } 
        var clip = Components.classes['@mozilla.org/widget/clipboard;1'].createInstance(Components.interfaces.nsIClipboard); 
        if (!clip) 
            return; 
        var trans = Components.classes['@mozilla.org/widget/transferable;1'].createInstance(Components.interfaces.nsITransferable); 
        if (!trans) 
            return; 
        trans.addDataFlavor('text/unicode'); 
        var str = new Object(); 
        var len = new Object(); 
        var str = Components.classes["@mozilla.org/supports-string;1"].createInstance(Components.interfaces.nsISupportsString); 
        var copytext = txt; 
        str.data = copytext; 
        trans.setTransferData("text/unicode",str,copytext.length*2); 
        var clipid = Components.interfaces.nsIClipboard; 
        if (!clip)
            return false; 
        clip.setData(trans,null,clipid.kGlobalClipboard); 
    } 
    return true; 
}

function go(url)
{
	window.location.href = url;
}