﻿//updated at 30Sept2009
function tagChangeBackground(status,id) {
	var tagcolor=new Array();
	tagcolor[1]="green";
	tagcolor[2]="green";
	tagcolor[3]="green";
	tagcolor[4]="gray";
	tagcolor[5]="gray";
	if (status=="over") {
		document.getElementById('tag'+id+'a').style.cursor="pointer"
		document.getElementById('tag'+id+'b').style.cursor="pointer"
		document.getElementById('tag'+id+'c').style.cursor="pointer"
		}
	if (status=="click") {
		document.getElementById('tag'+id+'a').src="images/tag_blue_1.jpg"
		var $ = function(id) { return document.getElementById(id); } 
		$('tag'+id+'b').style.background="url(images/tag_blue_2.jpg)";
		document.getElementById('tag'+id+'c').src="images/tag_blue_3.jpg"
			for (i=4;i<6;i++) {
				if (i!=id) {
					/*if (tagcolor[i]=="green") {
						document.getElementById('tag'+i+'a').src="images/index_34.jpg"
						document.getElementById('tag'+i+'b').style.background="url('images/index_35.jpg')"
						document.getElementById('tag'+i+'c').src="images/index_36.jpg"					
					} */
					if (tagcolor[i]=="gray") {
						if(document.getElementById('tag'+i+'a') != undefined)
							document.getElementById('tag'+i+'a').src="images/tag_gray_1.jpg";
						if(document.getElementById('tag'+i+'b') != undefined)
							document.getElementById('tag'+i+'b').style.background="url('images/tag_gray_2.jpg')";
						if(document.getElementById('tag'+i+'c') != undefined)
							document.getElementById('tag'+i+'c').src="images/tag_gray_3.jpg";
					}
					if(document.getElementById('tag1') != undefined)
						document.getElementById('tag1').src="images/tag_01.jpg";
					if(document.getElementById('tag2') != undefined)
						document.getElementById('tag2').src="images/tag_02.jpg";
					if(document.getElementById('tag3') != undefined)
						document.getElementById('tag3').src="images/tag_01.jpg";
				}
			}
		}
}

function tagChangeBackgroundB(status,id) {
	if (status=="over") {
		document.getElementById('tag'+id).style.cursor="pointer"
		}
	if (status=='click') {
			if (id==1)  {
			document.getElementById('tag1').src="images/tag_03.jpg"
			document.getElementById('tag2').src="images/tag_02.jpg"
			//document.getElementById('tag3').src="images/tag_01.jpg"
			}
			if (id==2) {
			document.getElementById('tag1').src="images/tag_01.jpg"
			document.getElementById('tag2').src="images/tag_04.jpg"
			//document.getElementById('tag3').src="images/tag_01.jpg"
			}
			/*if (id==3) {
			document.getElementById('tag1').src="images/tag_01.jpg"
			document.getElementById('tag2').src="images/tag_02.jpg"
			document.getElementById('tag3').src="images/tag_03.jpg"
			}*/
			document.getElementById('tag4a').src="images/tag_gray_1.jpg"
			document.getElementById('tag4b').style.background="url('images/tag_gray_2.jpg')"
			document.getElementById('tag4c').src="images/tag_gray_3.jpg"
			document.getElementById('tag5a').src="images/tag_gray_1.jpg"
			document.getElementById('tag5b').style.background="url('images/tag_gray_2.jpg')"
			document.getElementById('tag5c').src="images/tag_gray_3.jpg"
		}
}

//updated at 30Sept2009

function topTagChangeBackground(status,id) {
	if (status=="over") {
		document.getElementById('toptag'+id+'a').style.cursor="pointer"
		document.getElementById('toptag'+id+'b').style.cursor="pointer"
		document.getElementById('toptag'+id+'c').style.cursor="pointer"
		}
	if (status=="click") {
		document.getElementById('toptag'+id+'a').src="images/tag_white1.png"
		var $ = function(id) { return document.getElementById(id); } 
		$('toptag'+id+'b').style.background="url(images/tag_white2.png)";
		$('toptag'+id+'b').className="lightblue15ptbold";
		document.getElementById('toptag'+id+'c').src="images/tag_white3.png"
			for (i=1;i<6;i++) {
				if (i!=id) {
					document.getElementById('toptag'+i+'a').src="images/tag_lightgray1.jpg"
					document.getElementById('toptag'+i+'b').style.background="url('images/tag_lightgray2.jpg')"
					document.getElementById('toptag'+i+'b').className="gray15ptbold";
					document.getElementById('toptag'+i+'c').src="images/tag_lightgray3.jpg"
				}
			}
		if (id==1){
			window.location.href = 'index_afterlogin.html';
		}
		if (id==2){
			window.location.href = 'index_friendlist.html';
		}
		if (id==3){
			window.location.href = 'conversation_history.html';
		}
		if (id==4){
			window.location.href = 'invite_friend.html';
		}
		if (id==5){
			window.location.href = 'editprofile.html';
		}
	}

}

//updated at 30Sept2009
function recommendTagChangeBackground(status,id) {
	if (status=="over") {
		document.getElementById('recommendtag'+id+'a').style.cursor="pointer"
		document.getElementById('recommendtag'+id+'b').style.cursor="pointer"
		document.getElementById('recommendtag'+id+'c').style.cursor="pointer"
		}
	if (status=="click") {
		document.getElementById('recommendtag'+id+'a').style.background="url(images/recommend_whitetag_bg1.jpg)";
		var $ = function(id) { return document.getElementById(id); } 
		$('recommendtag'+id+'b').style.background="url(images/recommend_whitetag_bg2.jpg)";
		document.getElementById('recommendtag'+id+'c').style.background="url(images/recommend_whitetag_bg3.jpg)";
			for (i=1;i<=6;i++) {
				if (i!=id) {
					var a = document.getElementById('recommendtag'+i+'a');
					var b = document.getElementById('recommendtag'+i+'b');
					var c = document.getElementById('recommendtag'+i+'c');
					if(a != null && a != undefined)
						a.style.background="url(images/recommend_graytag_bg1.jpg)";
					if(b != null && b != undefined)
						b.style.background="url(images/recommend_graytag_bg2.jpg)";
					if(c != null && c != undefined)
						c.style.background="url(images/recommend_graytag_bg3.jpg)"
				}
			}
		}
}

//updated at 30Sept2009
function friendlistTagChangeBackground(status,id) {
	if (status=="over") {
		document.getElementById('friendlisttag'+id+'a').style.cursor="pointer"
		document.getElementById('friendlisttag'+id+'b').style.cursor="pointer"
		document.getElementById('friendlisttag'+id+'c').style.cursor="pointer"
		}
	if (status=="click") {
		document.getElementById('friendlisttag'+id+'a').style.background="url(images/friendlist_whitetag_bg1.jpg)";
		var $ = function(id) { return document.getElementById(id); } 
		$('friendlisttag'+id+'b').style.background="url(images/friendlist_whitetag_bg2.jpg)";
		document.getElementById('friendlisttag'+id+'c').style.background="url(images/friendlist_whitetag_bg3.jpg)";
			for (i=1;i<5;i++) {
				if (i!=id) {
					var a = document.getElementById('friendlisttag'+i+'a');
					var b = document.getElementById('friendlisttag'+i+'b');
					var c = document.getElementById('friendlisttag'+i+'c');
					if(a != null && a != undefined)
						a.style.background="url(images/friendlist_graytag_bg1.jpg)";
					if(b != null && b != undefined)
						b.style.background="url(images/friendlist_graytag_bg2.jpg)";
					if(c != null && c != undefined)
						c.style.background="url(images/friendlist_graytag_bg3.jpg)"
				}
			}
		}
}

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 controlAnswerpanel(rowKey) {
	var flag = true;
	var img = document.getElementById('frm:queData:'+rowKey+':plus_img');
	if(img.src.indexOf('btn_plus') > 0) {			
		var ajaxImg = document.createElement('img');
		ajaxImg.src = 'images/loading.gif';
		document.getElementById('ajax_'+rowKey).innerHTML = '';
		document.getElementById('ajax_'+rowKey).appendChild(ajaxImg);
	}
	if(img.src.indexOf('btn_minus') > 0) {
		img.src = 'images/btn_plus.jpg';
		flag = false;			
		document.getElementById('frm:queData:'+rowKey+':answerListPanel').style.display = 'none';
	}		
	return flag;
}
function completeAjax(rowKey) {
	var img = document.getElementById('frm:queData:'+rowKey+':plus_img');
	img.src = 'images/btn_minus.jpg';
	document.getElementById('ajax_'+rowKey).innerHTML = '';
}

function controlAnswerpanel2() {
	var flag = true;
	var img = document.getElementById('jingxuanImg');
	if(img.src.indexOf('btn_plus') > 0) {			
		var ajaxImg = document.createElement('img');
		ajaxImg.src = 'images/loading.gif';
		document.getElementById('ajax_div').innerHTML = '';
		document.getElementById('ajax_div').appendChild(ajaxImg);
	}
	if(img.src.indexOf('btn_minus') > 0) {
		img.src = 'images/btn_plus.jpg';
		flag = false;
		document.getElementById('frm:jingxuanAnswerPanel').style.display = 'none';				
	}
	return flag;
}
function completeAjax2() {
	var img = document.getElementById('jingxuanImg');
	img.src = 'images/btn_minus.jpg';
	document.getElementById('ajax_div').innerHTML = '';
}
function trim(obj) {
	try {
		var str = obj.value;
		str = str.replace(/(^\s*|\s*$)/g, "");
		obj.value = str;
	} catch (error) {
		alert(error);
	}
}
// 去除数组重复的元素
Array.prototype.unique = function(){     
	  var a = {};   
	  var len = this.length;   
	  for(var i=0; i<len; i++)  {     
		if(typeof a[this[i]] == "undefined")     
		a[this[i]] = 1;     
	  }     
	  this.length = 0;     
	  for(var i in a)     
	  this[this.length] = i;     
	  return this;     
}  

function checkEmail() {
	var rows = document.getElementById('frm:emailData:tbody_element').rows.length;
	var msg = '';
	var emailArray = new Array();
	var m = 0;
	if(rows > 0) {
		for(var i = 0; i < rows; i++) {
			var email = document.getElementById('friendEmail['+i+']');
			for(var j = 0; j < i; j++) {
				var email2 = document.getElementById('friendEmail['+j+']');
				if(j != i) {
					if(email.value != '' && email2.value != '' && email.value.toLowerCase() == email2.value.toLowerCase()) {
						emailArray[m++] = email.value.toLowerCase();
					}
				}
			}
		}
	}
	emailArray.unique();
	for(var n = 0; n < emailArray.length;n++) {
		msg += '[ '+emailArray[n]+' ]重复，不能输入重复的Email！\n';
	}
	if(msg != '') {
		alert(msg);
		return false;
	}
	return true;
}
// 验证是否输入发问内容
function askQueValidate() {
	var question = document.getElementById('question');
	if(question.value == '') {
		alert('请输入发问内容！');
		question.focus();
		return false;
	}
	if(question.value.length > 200) {
		alert('发问内容字数不能超过200！');	
		question.select();
		return false;
	}
	return true;	
}
// 验证日期格式是否正确
function isDate(str){ 
	var reg = /^((((1[6-9]|[2-9]\d)\d{2})-(0?[13578]|1[02])-(0?[1-9]|[12]\d|3[01]))|(((1[6-9]|[2-9]\d)\d{2})-(0?[13456789]|1[012])-(0?[1-9]|[12]\d|30))|(((1[6-9]|[2-9]\d)\d{2})-0?2-(0?[1-9]|1\d|2[0-8]))|(((1[6-9]|[2-9]\d)(0[48]|[2468][048]|[13579][26])|((16|[2468][048]|[3579][26])00))-0?2-29-))$/;
	if (reg.test(str)) return true;
	return false;
}
// 验证出生日期
function validateBorth(maxYear) {
	var borth = document.getElementById('borth');
	if(borth.value != '') {
		var year = borth.value.substring(0, 4);		
		if(!isDate(borth.value)) {
			alert('您输入的出生日期格式错误！');
			borth.select();
			return false;
		}
		if(parseInt(year) > parseInt(maxYear)) {
			alert('您输入的出生日期无效！');
			borth.select();
			return false;
		}
	}
	return true;
}
// 发问内容
function validateQuestion() {
	var question = $('#question').val();
	var errorMsg = '';
	if(question == '') {
		errorMsg = '请输入发问内容！';
	}
	
	if(question.length > 200) {
		errorMsg += '发问内容字数不能超过200！';	
	}
	var expChk  = document.askFrm.expRadio;		
	var count = 0;
	if(expChk.length > 0) {
		for(var i = 0; i < expChk.length; i++) {
			if(expChk[i].checked) {
				count = 1;
			}
		}
	}
	if(document.getElementById('otherExpertise').value != '') {
		count = 1;
	}
	if(count == 0) {
		var notSelect = '请选择您的问题所属的主题！';
		errorMsg = errorMsg != ''?errorMsg+'\n'+notSelect:notSelect;
	}
	if(errorMsg != '') {

		alert(errorMsg);
		return false;
	}
	return true;
}

// 选择其他专长
function selectOtherExp(obj) {
	if(obj.innerHTML == 'Select') {
		var expChk  = document.askFrm.expRadio;		
		var count = 0;
		if(expChk.length > 0) {
			for(var i = 0; i < expChk.length; i++) {
				if(expChk[i] != undefined) {
					expChk[i].checked = false;
				}			
			}
		}
		var rows = document.getElementById('askFrm:expertiseData').rows;
		if(rows.length > 0) {
			var m = 0;
			for(var i = 0; i < rows.length; i++) {
				var cells = rows[i].cells.length;
				for( var j = 0; j < cells; j++) {
					m++;
					var liObj = document.getElementById(eval(m-1)+':li');
					if(liObj != undefined) {
						liObj.className = '';
					}
				}
			}
		}
		document.getElementById('otherLi').className = 'selected';
		document.getElementById('otherExpertise_div').style.display = '';
		document.getElementById('otherExpertise').focus();
	}
	if(obj.innerHTML == '取消') {
		document.getElementById('otherLi').className = '';
		document.getElementById('otherExpertise_div').style.display = 'none';
		document.getElementById('otherExpertise').value = '';
	}
}
function otherLabel() {
	var tab = document.getElementById('askFrm:expertiseData');
	var rows = tab.rows.length;
	var lastRow = tab.rows(eval(rows-1));
	
	var m = 0;
	for(var i = 0; i < lastRow.cells.length; i++) {
		var cell_V = lastRow.cells[i].innerHTML;
		if(cell_V == '&nbsp;') {
			m = i;
			break;
		} 			
	}
	if(m > 0) {
		lastRow.cells[m].innerHTML = document.getElementById('otherLabel').innerHTML;
	} else {
		document.getElementById('otherLabel').style.display = 'block';
	}
}
// 选择心情图示
function isSelectChk(flag, idx) {
	var emoLi = document.getElementById('emo_li_'+idx);
	var emoChk = document.getElementById('goodIconChk:'+idx+'');
	if(flag == 'click') {
		emoChk.checked = emoChk.checked?false:true;
	}
	document.getElementById('chk_'+idx).style.display=emoChk.checked?'none':'block';
	emoLi.className = emoChk.checked?'selectEmo':'deselectEmo';
}
function initEmochk() {
	var chk = document.frm.goodIconChk;
	var n = 0;
	for(var i = 0; i < chk.length; i++) {
		var emoChk = chk[i];
		if(emoChk.checked) {
			isSelectChk('load', i);
		}
	}
}
// 判断是否选择了三个心情图示
function selectGoodIconChk() {
	var chk = document.frm.goodIconChk;
	var n = 0;
	for(var i = 0; i < chk.length; i++) {
		if(chk[i].checked) {
			n += 1;
		}
	}
	if(n != 3) {
		document.getElementById('errorTab').style.display = '';
		return false;
	}
	return true;	
}

// 删除答案提示
function deleteAnswer() {
	var flag = window.confirm('确定要删除吗？');
	if(!flag) {
		return false;	
	} else {
		return true;
	}
}
// 上传完成
function finishUpload(file) {
	self.parent.tb_remove();	
	var top_photo = window.parent.document.getElementById('myPhoto'); // 顶部头像
	var photo = window.parent.document.getElementById('myPhoto2'); // 中间头像
	var hiddenPhoto = window.parent.document.getElementById('hiddenMyPhoto'); // 中间头像
	var uploadFile_div = window.parent.document.getElementById('uploadFile_div'); // 上传头像DIV
	var editFile_div = window.parent.document.getElementById('editFile_div'); // 编辑头像DIV
	var fileName = file.replace('_tmp', '');
	
	if(fileName != '') {		
		if(top_photo != undefined) {
			top_photo.src = 'upload/'+fileName;	
		}
		if(uploadFile_div != undefined) {
			uploadFile_div.style.display = 'none';	
		}
		if(photo != undefined) {
			photo.src = 'upload/'+fileName;
		}
		if(hiddenPhoto != undefined) {
			hiddenPhoto.value = fileName;
		}
 		if(editFile_div != undefined) {
			editFile_div.style.display = 'block';
		}
	}
}

var xmlHttp = false;
xmlHttp = window.XMLHttpRequest?new XMLHttpRequest():window.ActiveXObject?new ActiveXObject("Microsoft.XMLHTTP"):new XMLHttpRequest();
if (!xmlHttp){
	alert("无法创建 XMLHttpRequest 对象！");
}
// 请求服务器
function reqServer() {
	var url = "Aexperm/AjaxServlet?action=reqServer&date="+new Date();
	xmlHttp.open("GET", url, true);	
	xmlHttp.onreadystatechange = function() {
		
	};
	xmlHttp.send(null);
}
setInterval('reqServer()', 10*1000);
	