String.prototype.ReplaceAll = strReplaceAll;
String.prototype.trim = strtrim;

function strReplaceAll(AFindText,ARepText){ 
	raRegExp = new RegExp(AFindText,"g");
	return this.replace(raRegExp,ARepText);
}

function strtrim(){ return this.replace(/^\s*|\s*$/g,""); }

function fnAddFav(title, url){
  var url="http://www.ipart.cn";
  var title="爱情公寓";
  if(document.all){
		window.external.AddFavorite(url, title);
  }else if (window.sidebar){
		window.sidebar.addPanel(title, url, "")
	}	
}
function MM_openBrWindow(theURL,winName,features) {
  window.open(theURL,winName,features);
}
function _login_ipart(objFrm){
	if(trim(objFrm.username.value)=='' || trim(objFrm.password.value)==''){
		alert("请填入登入信息");
  	(objFrm.username.value=="") ? objFrm.username.focus() : objFrm.password.focus();
    return false;
  }  
  objFrm.btnLogin.disabled = true;
  return true;
}
function trim(str){
  return str.replace(/^\s*|\s*$/g,"");
}

function _gFA(){
	$.ajax({	url: '/ajax/',
	data: 'func=doFavAction&uid='+_uid+'&aid='+_aid+'&tit='+encodeURI(_tit)+'&cover='+_cover+'&pcnt='+_pcnt+'&fid='+_fid+'&ftype=0&fmt=html',
    type: 'POST',
    dataType: 'html',
    timeout: 3000,
    error: function(){
        alert('收藏相册失败');
    },
    success: function(html){    	
    	if(_fid==-1){
    		if(html.trim()=="fail"){ alert("收藏相册失败"); return false;}
    		alert("收藏相册成功");
    		_fid = html.trim(); $("#btn_fav").attr("value","取消收藏");
    	}else{
    		if(html.trim()=="ok"){ alert("取消收藏相册成功");	}else{ alert("取消收藏相册失败"); }
    		$("#btn_fav").attr("value","收藏相册"); _fid= '-1';
    	}
    }
	});
}

function failimg(imgobj){
	imgobj.onerror = function(){};
	//imgobj.src = "http://c.photo.ipart.cn/images/album_default.gif";
	imgobj.src = "http://c.photo.ipart.cn/images/errorImg.gif";
}
	
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
function documentWrite(url) {
	if(typeof(url) != "undefined") {
		document.write("<script src='" + url + "' charset='gb2312'></script>");
	}
}

function photo_menu_init() {
  $("#menu_user_photo").html(user["u_p"]);  
  if(user["u_s"] == "M"){
    user_sex_pic = "<img src=\"http://van.ipart.cn/images2/b.gif\" class=\"memberSex\">";
    $("#sexy_text").html('他'); 
  } else {
    user_sex_pic = "<img src=\"http://van.ipart.cn/images2/g.gif\" class=\"memberSex\">";
    $("#sexy_text").html('她');	
  }
  $("#menu_user_nickname").html('<a href="http://'+user["u_i"]+'.ipart.cn"" target="_blank">'+user["u_n_k"]+'</a>');  
  if(user["v_l"] == 2){
  	$("#menu_vip_level").html('<img src="http://van.ipart.cn/images2/vip_icon1.gif" class="memberVip">');
  }  
  if(user["i_bir"] == "1"){
    $("#menu_user_birthday").html('<img src="http://van.ipart.cn/images2/mybirthday.gif" alt="生日榜" class="cake">');
  }
  if(user["c_r_o"] != 0){
  	$("#menu_user_live").html('<img src="http://van.ipart.cn/images2/ifile/double.gif" class="double">');	
  }else{
  	$("#menu_user_live").html(user_sex_pic);
  }
  if($("#menu_user_show_file")){
  	if(user["u_s_f"] == 0){
  		$("#menu_user_show_file").html('<img src="http://van.ipart.cn/images2/ifile/lock.gif" class="online">');			
		}else{
			$("#menu_user_show_file").html('<img src="http://van.ipart.cn/images2/ifile/lockopen.gif" class="online">');  
		}
  }
  if (document.getElementById("menu_user_online")) {
	  if(typeof(user_online_status) != "undefined" && user_online_status == 1 ){ //&& user["u_s_o"] == 1)
	  //if(typeof(user_online_status) != "undefined" && user_online_status == 1 && user["u_s_o"] == 1){
	     document.getElementById("menu_user_online").innerHTML = "<a href=\"javascript:void(0);\" onclick=\"open_mini_talk();\"><img src=\"http://van.ipart.cn/images2/ifile/online.gif\" alt=\"在线\"  class=\"online\" border=\"0\"></a>";
	  	//$("#menu_user_online").html('<img src="http://van.ipart.cn/images2/ifile/online.gif\" alt="在线" class="online">');  
	  }else{
	  	
	  	if(typeof(user_online_status) != "undefined")
	  		document.getElementById("menu_user_online").innerHTML = "<a href=\"javascript:void(0);\" onclick=\"open_mini_talk();\"><img src=\"http://van.ipart.cn/images2/ifile/offline.gif\" alt=\"离线\"  class=\"online\" border=\"0\"></a>";
	  	//$("#menu_user_online").html('<img src="http://van.ipart.cn/images2/ifile/offline.gif" alt="离\" class="online">'); 
	  }
  }
  $("#menu_user_no").html(user["u_n"]);
  
  // action 091001
//  if (typeof(actMsg091001)!="undefined" && actMsg091001!=""){
//      document.getElementById('menu_icon_091001').innerHTML = '<a href="http://www.ipart.cn/html/action/091001/index.php"><img border="0" src="http://van.ipart.cn/images/action/091001/title_icon.gif" title="我爱中国"/></a>';
//      document.getElementById('menu_msg_091001').innerHTML = actMsg091001;
//  }
}

function getFriendList(){  
  var html = "";
  var currend_group_no = 0; 
  html += "<select id=\"menu_friend_option\" name=\"menu_friend_option\" onchange=\"visit_user_friend(this.value);\" class=\"friInput\">";
  html += "<option value=\"0\">-好友列表-</option>";
  for(var i = 0;i < user_friend.length;i++) {
    var detail = user_friend[i].split("{:}");
    var tar_no	        = detail[0];
    var tar_id	        = detail[1];
    var tar_sex	        = detail[2];
    var tar_nickname	  = detail[3];
    var tar_desc	      = detail[4];
    var group_no	      = detail[5];
    var group_name	    = detail[6];
    if(currend_group_no != group_no) {
      currend_group_no = group_no;
      html += "<OPTGROUP LABEL=\"" + group_name + "\">";
    }
    html += "<option value=\"" + tar_id + "\">" + tar_nickname  + "</option>";    
  }
  html += "</select>";
  delete(user_friend);
  $("#FriendSelect_new").html(html);
}
function visit_user_friend(user_id) {
  if(user_id == 0 || user_id == "") return false;  
  window.open("http://"+user_id+".photo.ipart.cn");
}
  
function openWindows(url, w, h, s){
	window.open(url,"popWin","toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars="+s+",resizable=no,width="+w+",height="+h);
	return;
}

//for mini falk
function open_mini_talk(){
    if (user_online_status=="0"){
        alert('对方IME不在线哟～');
    }
    if(typeof(user_allow_talk)!='undefined' && !user_allow_talk) {
        alert('您还不是'+(user["u_s"]=='M' ? '他 ': '她')+'的好友哦～');
    }else if (typeof(openByUserId)=='function') {
        openByUserId(user["u_n"], user_online_status);
    }
}