//<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
/******* Debug Log **********/
//var path = "/fvlogger_todd/logger.js";
//document.write("<" + "script src=\"" + path + "\" language=\"javascript\" type=\"text/javascript\"></" + "script>");
/******* Debug end **********/

/******* Core Js **********/
/*	Based on prototypes (prototype.conio.net)
/*	Modifid by Todd Lee (www.todd-lee.com)
/*	Last update: 2005-10-31
*/

var Prototype = {
  Version: '1.3.1',
  emptyFunction: function() {}
}

var Class = {
  create: function() {
    return function() { 
      this.initialize.apply(this, arguments);
    }
  }
}

var Abstract = new Object();

Object.extend = function(destination, source) {
  for (property in source) {
    destination[property] = source[property];
  }
  return destination;
}

Object.prototype.extend = function(object) {
  return Object.extend.apply(this, [this, object]);
}

Function.prototype.bind = function(object) {
  var __method = this;
  return function() {
    __method.apply(object, arguments);
  }
}

Function.prototype.bindAsEventListener = function(object) {
  var __method = this;
  return function(event) {
    __method.call(object, event || window.event);
  }
}

Number.prototype.toColorPart = function() {
  var digits = this.toString(16);
  if (this < 16) return '0' + digits;
  return digits;
}

var Try = {
  these: function() {
    var returnValue;

    for (var i = 0; i < arguments.length; i++) {
      var lambda = arguments[i];
      try {
        returnValue = lambda();
        break;
      } catch (e) {}
    }

    return returnValue;
  }
}

/*--------------------------------------------------------------------------*/

var PeriodicalExecuter = Class.create();
PeriodicalExecuter.prototype = {
  initialize: function(callback, frequency) {
    this.callback = callback;
    this.frequency = frequency;
    this.currentlyExecuting = false;

    this.registerCallback();
  },

  registerCallback: function() {
    setInterval(this.onTimerEvent.bind(this), this.frequency * 1000);
  },

  onTimerEvent: function() {
    if (!this.currentlyExecuting) {
      try { 
        this.currentlyExecuting = true;
        this.callback(); 
      } finally { 
        this.currentlyExecuting = false;
      }
    }
  }
}

/*--------------------------------------------------------------------------*/
function $() { 
	var elements = new Array(); 
	for (var i = 0; i < arguments.length; i++) { 
		var element = arguments[i]; 
		if (typeof element == 'string') 
			element = document.getElementById(element); 
		if (arguments.length == 1) 
			return element; 
		elements.push(element); 
	} 
	return elements; 
}

/*--------------------------------------------------------------------------*/
String.prototype.extend({
  stripTags: function() {
    return this.replace(/<\/?[^>]+>/gi, '');
  },

  escapeHTML: function() {
    var div = document.createElement('div');
    var text = document.createTextNode(this);
    div.appendChild(text);
    return div.innerHTML;
  },

  unescapeHTML: function() {
    var div = document.createElement('div');
    div.innerHTML = this.stripTags();
    return div.childNodes[0].nodeValue;
  }
});

/*--------------------------------------------------------------------------*/
var Ajax = {
  getTransport: function() {
    return Try.these(
      function() {return new ActiveXObject('Msxml2.XMLHTTP')},
      function() {return new ActiveXObject('Microsoft.XMLHTTP')},
      function() {return new XMLHttpRequest()}
    ) || false;
  }
}

Ajax.Base = function() {};
Ajax.Base.prototype = {
  setOptions: function(options) {
    this.options = {
      method:       'post',
      asynchronous: true,
      parameters:   ''
    }.extend(options || {});
  },

  responseIsSuccess: function() {
    return this.transport.status == undefined
        || this.transport.status == 0 
        || (this.transport.status >= 200 && this.transport.status < 300);
  },

  responseIsFailure: function() {
    return !this.responseIsSuccess();
  }
}

Ajax.Request = Class.create();
Ajax.Request.Events = 
  ['Uninitialized', 'Loading', 'Loaded', 'Interactive', 'Complete'];

Ajax.Request.prototype = (new Ajax.Base()).extend({
  initialize: function(url, options) {
    this.transport = Ajax.getTransport();
    this.setOptions(options);
    this.request(url);
  },

  request: function(url) {
    var parameters = this.options.parameters || '';
    if (parameters.length > 0) parameters += '&_=';

    try {
    if (this.options.method == 'get') {
	    if ( parameters.length>0 ) {
		    url += '?' + parameters;
	    }
    }


      this.transport.open(this.options.method, url,
        this.options.asynchronous);

      if (this.options.asynchronous) {
        this.transport.onreadystatechange = this.onStateChange.bind(this);
        setTimeout((function() {this.respondToReadyState(1)}).bind(this), 10);
      }

      this.setRequestHeaders();

      var body = this.options.postBody ? this.options.postBody : parameters;
      this.transport.send(this.options.method == 'post' ? body : null);

    } catch (e) {
    }
  },

  setRequestHeaders: function() {
    var requestHeaders = 
      ['X-Requested-With', 'XMLHttpRequest',
       'X-Prototype-Version', Prototype.Version];

    if (this.options.method == 'post') {
      requestHeaders.push('Content-type', 
        'application/x-www-form-urlencoded');

      /* Force "Connection: close" for Mozilla browsers to work around
       * a bug where XMLHttpReqeuest sends an incorrect Content-length
       * header. See Mozilla Bugzilla #246651. 
       */
      if (this.transport.overrideMimeType)
        requestHeaders.push('Connection', 'close');
    }

    if (this.options.requestHeaders)
      requestHeaders.push.apply(requestHeaders, this.options.requestHeaders);

    for (var i = 0; i < requestHeaders.length; i += 2)
      this.transport.setRequestHeader(requestHeaders[i], requestHeaders[i+1]);
  },

  onStateChange: function() {
    var readyState = this.transport.readyState;
    if (readyState != 1)
      this.respondToReadyState(this.transport.readyState);
  },

  respondToReadyState: function(readyState) {
    var event = Ajax.Request.Events[readyState];
	var _arguments = this.options['responseArguments'];
	
    if (event == 'Complete')
      (this.options['on' + this.transport.status]
       || this.options['on' + (this.responseIsSuccess() ? 'Success' : 'Failure')]
       || Prototype.emptyFunction)(this.transport, _arguments);
	  
    (this.options['on' + event] || Prototype.emptyFunction)(this.transport, _arguments);

    /* Avoid memory leak in MSIE: clean up the oncomplete event handler */
    if (event == 'Complete')
      this.transport.onreadystatechange = Prototype.emptyFunction;
  }
});

Ajax.Updater = Class.create();
Ajax.Updater.ScriptFragment = '(?:<script.*?>)((\n|.)*?)(?:<\/script>)';

Ajax.Updater.prototype.extend(Ajax.Request.prototype).extend({
  initialize: function(container, url, options) {
    this.containers = {
      success: container.success ? $(container.success) : $(container),
      failure: container.failure ? $(container.failure) :
        (container.success ? null : $(container))
    }

    this.transport = Ajax.getTransport();
    this.setOptions(options);

    var onComplete = this.options.onComplete || Prototype.emptyFunction;
    this.options.onComplete = (function() {
      this.updateContent();
      onComplete(this.transport);
    }).bind(this);

    this.request(url);
  },

  updateContent: function() {
    var receiver = this.responseIsSuccess() ?
      this.containers.success : this.containers.failure;

    var match    = new RegExp(Ajax.Updater.ScriptFragment, 'img');
    var response = this.transport.responseText.replace(match, '');
    var scripts  = this.transport.responseText.match(match);

    if (receiver) {
      if (this.options.insertion) {
        new this.options.insertion(receiver, response);
      } else {
        receiver.innerHTML = response;
      }
    }

    if (this.responseIsSuccess()) {
      if (this.onComplete)
        setTimeout((function() {this.onComplete(
          this.transport)}).bind(this), 10);
    }

    if (this.options.evalScripts && scripts) {
      match = new RegExp(Ajax.Updater.ScriptFragment, 'im');
      setTimeout((function() {
        for (var i = 0; i < scripts.length; i++)
          eval(scripts[i].match(match)[1]);
      }).bind(this), 10);
    }
  }
});

Ajax.PeriodicalUpdater = Class.create();
Ajax.PeriodicalUpdater.prototype = (new Ajax.Base()).extend({
  initialize: function(container, url, options) {
    this.setOptions(options);
    this.onComplete = this.options.onComplete;

    this.frequency = (this.options.frequency || 2);
    this.decay = 1;

    this.updater = {};
    this.container = container;
    this.url = url;

    this.start();
  },

  start: function() {
    this.options.onComplete = this.updateComplete.bind(this);
    this.onTimerEvent();
  },

  stop: function() {
    this.updater.onComplete = undefined;
    clearTimeout(this.timer);
    (this.onComplete || Ajax.emptyFunction).apply(this, arguments);
  },

  updateComplete: function(request) {
    if (this.options.decay) {
      this.decay = (request.responseText == this.lastText ? 
        this.decay * this.options.decay : 1);

      this.lastText = request.responseText;
    }
    this.timer = setTimeout(this.onTimerEvent.bind(this), 
      this.decay * this.frequency * 1000);
  },

  onTimerEvent: function() {
    this.updater = new Ajax.Updater(this.container, this.url, this.options);
  }
});

/*--------------------------------------------------------------------------*/
document.getElementsByClassName = function(className) { 
	var children = document.getElementsByTagName('*') || document.all; 
	var elements = new Array(); 
	for (var i = 0; i < children.length; i++) { 
		var child = children[i]; 
		var classNames = child.className.split(' '); 
		for (var j = 0; j < classNames.length; j++) { 
			if (classNames[j] == className) { 
				elements.push(child); 
				break; 
			} 
		} 
	} 
	return elements; 
} 

/*--------------------------------------------------------------------------*/
if (!window.Element) {
  var Element = new Object();
}
Object.extend(Element, {
	toggle: function() { 
		for (var i = 0; i < arguments.length; i++) { 
			var element = $(arguments[i]); 
			element.style.display = (element.style.display == 'none' ? '' : 'none'); 
		} 
	}, 
	hide: function() { 
		for (var i = 0; i < arguments.length; i++) { 
			var element = $(arguments[i]); 
			element.style.display = 'none'; 
		} 
	}, 
	show: function() { 
		for (var i = 0; i < arguments.length; i++) { 
			var element = $(arguments[i]); 
			element.style.display = ''; 
		} 
	}, 
	remove: function(element) { 
		element = $(element); 
		element.parentNode.removeChild(element); 
	}, 
	getWidth: function(element) { 
		element = $(element); 
		return element.offsetWidth; 
	},
	getHeight: function(element) { 
		element = $(element); 
		return element.offsetHeight; 
	},
	swapClassName: function(element) {
		element = $(element); 
		for (var i = 1; i < arguments.length; i++) {
			if (element.className == arguments[i]) {
				element.className = (i == arguments.length - 1 ? arguments[1] : arguments[i+1]);
				break;
			}
		}
	},
	getParentElementByTagName: function(element, tagName) {
		element = $(element); 
		while (element.tagName != tagName) {
			element = element.parentNode;
		}
		return element;
	},
	getParentElementByClassName: function(element, _className) {
		element = $(element); 
		while (element.className != _className) {
			element = element.parentNode;
		}
		return element;
	},
	//objPos = Element.getPosition(Obj); objPosLeft = objPos.left; objPosTop = objPos.top;
	getPosition: function(element) {
		for (var sumTop = 0, sumLeft = 0; element != document.body/* && element.tagName != "HTML"*/; sumTop += element.offsetTop, sumLeft += element.offsetLeft, element = element.offsetParent);
		return {left: sumLeft, top: sumTop};
	}
});

/*--------------------------------------------------------------------------*/

var Form = {
  serialize: function(form) {
    var elements = Form.getElements($(form));
    var queryComponents = new Array();
    
    for (var i = 0; i < elements.length; i++) {
      var queryComponent = Form.Element.serialize(elements[i]);
      if (queryComponent)
        queryComponents.push(queryComponent);
    }
    
    return queryComponents.join('&');
  },
  
  getElements: function(form) {
    var form = $(form);
    var elements = new Array();

    for (tagName in Form.Element.Serializers) {
      var tagElements = form.getElementsByTagName(tagName);
      for (var j = 0; j < tagElements.length; j++)
        elements.push(tagElements[j]);
    }
    return elements;
  },
  
  getInputs: function(form, typeName, name) {
    var form = $(form);
    var inputs = form.getElementsByTagName('input');
    
    if (!typeName && !name)
      return inputs;
      
    var matchingInputs = new Array();
    for (var i = 0; i < inputs.length; i++) {
      var input = inputs[i];
      if ((typeName && input.type != typeName) ||
          (name && input.name != name)) 
        continue;
      matchingInputs.push(input);
    }

    return matchingInputs;
  },

  disable: function(form) {
    var elements = Form.getElements(form);
    for (var i = 0; i < elements.length; i++) {
      var element = elements[i];
      element.blur();
      element.disabled = 'true';
    }
  },

  enable: function(form) {
    var elements = Form.getElements(form);
    for (var i = 0; i < elements.length; i++) {
      var element = elements[i];
      element.disabled = '';
    }
  },

  focusFirstElement: function(form) {
    var form = $(form);
    var elements = Form.getElements(form);
    for (var i = 0; i < elements.length; i++) {
      var element = elements[i];
      if (element.type != 'hidden' && !element.disabled) {
        Field.activate(element);
        break;
      }
    }
  },

  reset: function(form) {
    $(form).reset();
  }
}

Form.Element = {
  serialize: function(element) {
    var element = $(element);
    var method = element.tagName.toLowerCase();
    var parameter = Form.Element.Serializers[method](element);
    
    if (parameter)
      return encodeURIComponent(parameter[0]) + '=' + 
        encodeURIComponent(parameter[1]);                   
  },
  
  getValue: function(element) {
    var element = $(element);
    var method = element.tagName.toLowerCase();
    var parameter = Form.Element.Serializers[method](element);
    
    if (parameter) 
      return parameter[1];
  }
}

Form.Element.Serializers = {
  input: function(element) {
    switch (element.type.toLowerCase()) {
      case 'submit':
      case 'hidden':
      case 'password':
      case 'text':
        return Form.Element.Serializers.textarea(element);
      case 'checkbox':  
      case 'radio':
        return Form.Element.Serializers.inputSelector(element);
    }
    return false;
  },

  inputSelector: function(element) {
	var groups = document.getElementsByName(element.name);
	var subValue = new Array();
	for (var i=0; i<groups.length; i++ ) {
		if (groups[i].checked)
		  subValue.push(groups[i].value);
	}
	if (subValue.length < 1)
		subValue = null;
	 return [element.name, subValue];
  },

  textarea: function(element) {
    return [element.name, element.value];
  },

  select: function(element) {
    var value = '';
    if (element.type == 'select-one') {
      var index = element.selectedIndex;
      if (index >= 0)
        value = element.options[index].value || element.options[index].text;
    } else {
      value = new Array();
      for (var i = 0; i < element.length; i++) {
        var opt = element.options[i];
        if (opt.selected)
          value.push(opt.value || opt.text);
      }
    }

    return [element.name, value];
  }
}

/*--------------------------------------------------------------------------*/

var $F = Form.Element.getValue;

/******* Core Js End **********/

/******* My Favor List **********/
/*	Author: Todd Lee (www.todd-lee.com)
/*	Last update: 2005-10-24
*/

/*** exmaple ***
MyFav.favList[0] = new Object;
MyFav.favList[0].id = 1;
MyFav.favList[0].tit = "Todd Lee";
MyFav.favList[0].desc = "Todd Lee Blog";
MyFav.favList[0].url = "http://www.todd-lee.com";

MyFav.favList[1] = new Object;
MyFav.favList[1].id = 2;
MyFav.favList[1].tit = "Todd Lee 2";
MyFav.favList[1].desc = "Todd Lee Blog 2";
MyFav.favList[1].url = "http://www.todd-lee.com";
...
*/
var MyFav = {
	/*** global variables ***/
	styleOut 	: 'myfav',		//the class of myFav object
	styleOver 	: 'myfav-over',	//mouseover class
	styleClick 	: 'myfav-over',	//click class
	
	str_noList			: '暂无链接',	//the notice when there is no my favor
	str_editMyFavTitle 	: '新增',		//the words in edit box title
	str_editMyFavTitle2 : '修改',		//the words in edit box title
	str_noticeWordsTitle: '请填写链接名称',	//
	str_noticeWordsUrl	: '链接地址格式不正确',	//
	str_noticeWordsDel	: '是否确认删除',	//
	str_noticeLoading	: 'Loading...',	//
	str_noticeDone		: '操作成功！',	//
	
	obj_myFavBox 		: 'myFavBox',		//my favor list container 
	obj_popDiv			: 'popDiv',			//my favor cell box
	obj_editMyFavBox	: 'editMyFavBox',	//my favor edit box
	obj_editMyFavTitle 	: 'editMyFavTitle',	//my favor edit box title
	obj_favTitle		: 'favTitle',		//my favor edit box favor's title
	obj_favDesc			: 'favDesc',		//my favor edit box favor's description
	obj_favUrl			: 'favUrl',			//my favor edit box favor's url
	/*** global variables end ***/
	
	favList : new Array(),
	selectedObj : null,
	showing : false,
	
	/*** build my favor list ***/
	buildMyFavList : function() {
		this.showing = false;
		this.selectedObj = null;
		var str = "";
		if( this.favList.length > 0 ) {
			var theObj;
			for( var i=0; i<this.favList.length; i++) {
				theObj = this.favList[i];
				var _desc = (theObj.desc)? "\n"+theObj.desc : "";
				str += "<div id=\"myFav_"+ theObj.id +"\" tit=\""+ theObj.tit +"\"desc=\""+ theObj.desc +"\" url=\""+ theObj.url +"\" class=\""+ this.styleOut +"\" onmouseover=\"MyFav.mouseEvent(event, this)\" onmouseout=\"MyFav.mouseEvent(event, this)\">";
				str += "<a href=\""+ theObj.url +"\" target=\"_blank\" title=\""+ theObj.tit + _desc +"\"><strong>"+ theObj.tit +"</strong><br /><span style=\"text-decoration: none;\">"+ theObj.desc +"</span></a>";
				str += "</div>";
			}
		}
		else {
			str = this.str_noList;
		}
		$(this.obj_myFavBox).innerHTML = str;
	},
	/*** build my favor list end ***/

	/*** style operations of my favor list ***/
	//listen mouse event
	mouseEvent : function(e, theObj, opr) {
		if (!e) 
			var e=window.event;
		if (!theObj) {
			try {
				theObj = e.srcElement;
			}
			catch(e){}
		}
		if (theObj.id.indexOf('myFav_') < 0 && this.selectedObj ) {
			theObj = this.selectedObj;
		}
		if ( e.type == 'mouseover' ){
			this.overCell(theObj);
		}
		else if ( e.type == 'mouseout'  ||  e.type == 'blur' ){
			this.outCell(theObj);
		}
		else if ((e.type == 'click')){
			if (opr == 'delete') {
				this.deleteFav(theObj);
			}
			else if (opr == 'edit'){
				this.editFavCheck(theObj);
			}
			else {
				if (!this.showing) {
					this.selectCell(theObj, opr);
				}
				else {
					this.unSelectCell(theObj);
				}
				this.showing = !this.showing;
			}
		}
	},
	
	//on mouse over to do this
	overCell : function(theObj) {
		if (!this.showing) {
			this.outCellAll();
			theObj.className = this.styleOver;
			this.selectEntry(theObj);
			this.showTip(theObj);
		}
	},
	//on mouse out to do this
	outCell : function(theObj) {
		if (!this.showing) {
			theObj.className = this.styleOut;
			this.hideTip();
		}
	},
	//a shortcut to set all to mouse out style
	outCellAll : function() {
		for (var i=0; i<this.favList.length; i++) {
			this.outCell(this.favList[i]);
		}
	},

	//on mouse click to do this
	selectCell : function(theObj, opr) {
		if (opr != 'add') {
			theObj.className = this.styleOver;
		}
		this.selectEntry(theObj);
		this.showAddBar(theObj, opr);
	},
	//on clear select to do this
	unSelectCell : function(theObj){
		theObj.className = this.styleOut;
		this.unSelectEntry();
		this.hideTip();
		this.hideAddBar();
	},

	//set mark
	selectEntry : function(theObj){
		if ( !this.isSelected(theObj) ){
			this.selectedObj = theObj;
		}
	},
	//clear mark
	unSelectEntry : function(){
		selectedObj = null;
	},
	//whether the object is selected
	isSelected : function(theObj){
		if (this.selectedObj == theObj)
			return true;
		return false;
	},

	//show edit & delete icon
	showTip : function(theObj) {
		var thePopBox = $(this.obj_popDiv);
		var str = "";
		thePopBox.style.display = 'block';
		thePopBox.style.position = 'absolute';
		thePopBox.style.top    = Element.getPosition(theObj).top -0 +1 + 'px';
		thePopBox.style.left   = Element.getPosition(theObj).left -0 +Element.getWidth(theObj) -33 + 'px';
	},
	hideTip : function() {
		$(this.obj_popDiv).style.display = 'none';
	},

	//show edit panel
	showAddBar : function(theObj, opr) {
		$(this.obj_editMyFavBox).style.display = 'block';
		$(this.obj_editMyFavBox).style.position = 'absolute';
		$(this.obj_editMyFavBox).style.top    = Element.getPosition(theObj).top + 'px';
		$(this.obj_editMyFavBox).style.left   = Element.getPosition(theObj).left -0 +Element.getWidth(theObj) -33 + 'px';
		$(this.obj_editMyFavTitle).innerHTML = (opr == 'add')? this.str_editMyFavTitle : this.str_editMyFavTitle2;
		$(this.obj_favTitle).value = (opr == 'add')? '' : theObj.getAttribute('tit');
		$(this.obj_favDesc).value = (opr == 'add')? '' : theObj.getAttribute('desc');
		$(this.obj_favUrl).value = (opr == 'add')? 'http://' : theObj.getAttribute('url');
		$(this.obj_favTitle).select();
		$(this.obj_favTitle).focus();
	},
	hideAddBar : function() {
		$(this.obj_editMyFavBox).style.display = 'none';
	},
	/*** style operations of my favor list end ***/

	/*** data operations of my favor list ***/
	//get the data index of current object
	getSourceDataIndex : function(theObj) {
		for (var i=0; i<this.favList.length; i++) {
			if ('myFav_'+this.favList[i].id == theObj.id) {
				return (i);
			}
		}
		return (-1);
	},
	//confirm delete one
	deleteFav : function(theObj) {
		theObj.className = this.styleOver;
		this.selectEntry(theObj);
		if (confirm(this.str_noticeWordsDel + theObj.getAttribute('tit') +'？')) {
			showTipInfo(MyFav.str_noticeLoading);
			var doDelete = function() {MyFav.requestDeleteStatus(theObj)};
			doIt = setTimeout(doDelete, 1);
			//var doDelete = function() {MyFav.doDeleteFav(theObj)};
			//doIt = setTimeout(doDelete, 1);
		}
		else {
			this.unSelectCell(theObj);
		}
	},
	//request from server
	requestDeleteStatus : function(theObj) {
		var url = '/member/manager/linkManager.do';
		var pars = 'func=del&id=' + this.favList[this.getSourceDataIndex(theObj)].id;
		var myAjax = new Ajax.Request( url, {method: 'get', parameters: pars, onComplete: MyFav.doDeleteFav, responseArguments: theObj } );
	},
	//do delete operation
	doDeleteFav : function(request, theObj) {
		if (request.responseText.indexOf(1) != 0) {
			alert('error code: '+request.responseText);
		}
		else {
			showTipInfo(MyFav.str_noticeDone);
			//theObj = MyFav.selectedObj;
			if ( MyFav.getSourceDataIndex(theObj) >= 0 ) {
				MyFav.favList.splice(MyFav.getSourceDataIndex(theObj), 1);
				MyFav.unSelectCell(theObj);
				MyFav.buildMyFavList();
			}	
		}
		setTimeout(hideTipInfo, 500);
	},
	//check edit data
	editFavCheck : function(theObj) {
		var expRequire = /.+/;
		var expUrl = /^http:\/\/([a-zA-Z0-9]|[-_])+\.[A-Za-z0-9]+[\/=\?%\-&_~`@[\]\':+!]*([^<>\"\"])*$/;
		if( !expRequire.test( $(this.obj_favTitle).value ) ){
			alert(this.str_noticeWordsTitle);
			$(this.obj_favTitle).focus();
		}
		else if( !expUrl.test( $(this.obj_favUrl).value ) ){
			alert(this.str_noticeWordsUrl);
			$(this.obj_favUrl).focus();
		}
		else {
			showTipInfo(MyFav.str_noticeLoading);
			this.requestEditStatus(theObj);
		}
	},
	//request from server
	requestEditStatus : function(theObj) {
		//edit
		if (this.getSourceDataIndex(theObj) >= 0) {
			var url = '/member/manager/linkManager.do';
			var pars = 'func=update&id='+this.favList[this.getSourceDataIndex(theObj)].id+'&title='+$(this.obj_favTitle).value+'&desc='+$(this.obj_favDesc).value+'&link='+$(this.obj_favUrl).value;
			var myAjax = new Ajax.Request( url, {method: 'get', parameters: pars, onComplete: MyFav.doEditFav, responseArguments: theObj } );
		}
		//add
		else {
			var url = '/member/manager/linkManager.do';
			var pars = 'func=add&title='+$(this.obj_favTitle).value+'&desc='+$(this.obj_favDesc).value+'&link='+$(this.obj_favUrl).value;
			var myAjax = new Ajax.Request( url, {method: 'get', parameters: pars, onComplete: MyFav.doEditFav, responseArguments: theObj } );
		}
	},
	//do edit operation
	doEditFav : function(request, theObj) {
		//0id<title<link<desc
		if (request.responseText.indexOf(1) != 0){
			alert('error codevv: '+request.responseText);
		}
		else {
			showTipInfo(MyFav.str_noticeDone);
			//var theObj = (MyFav.selectedObj)? MyFav.selectedObj : $('myFav_add');
			var respArguments = request.responseText.substring(1).split("<");
			if (MyFav.getSourceDataIndex(theObj) >= 0) {
				MyFav.favList[MyFav.getSourceDataIndex(theObj)].tit = respArguments[1];
				MyFav.favList[MyFav.getSourceDataIndex(theObj)].desc = respArguments[3];
				MyFav.favList[MyFav.getSourceDataIndex(theObj)].url = respArguments[2];
			}
			else if ( theObj.id.indexOf('myFav_') >= 0 ) {
				var _obj = new Object();
				_obj.id 	= respArguments[0];
				_obj.tit 	= respArguments[1];
				_obj.desc 	= respArguments[3];
				_obj.url 	= respArguments[2];
				MyFav.favList[MyFav.favList.length] = _obj;
			}
			MyFav.unSelectCell(theObj);
			MyFav.buildMyFavList();
		}
		setTimeout(hideTipInfo, 500);
	}
	/*** data operations of my favor list end ***/
}
/******* My Favor List end **********/



var MyAlbum = {
	/*** global variables ***/
	styleOut 	: 'myfav',		//the class of myFav object
	styleOver 	: 'myfav-over',	//mouseover class
	styleClick 	: 'myfav-over',	//click class
	
	str_noList			: '暂无相册,请创建!',	//the notice when there is no my favor
	str_editMyFavTitle 	: '创建新相册',		//the words in edit box title
	str_editMyFavTitle2 : '修改新相册',		//the words in edit box title
	str_noticeWordsTitle: '请填写相册名称',	//
	str_noticeWordsUrl	: '链接地址格式不正确',	//
	str_noticeWordsDel	: '是否确认删除',	//
	str_noticeLoading	: 'Loading...',	//
	str_noticeDone		: '操作成功！',	//
	
	obj_myFavBox 		: 'myFavBox',		//my favor list container 
	obj_popDiv			: 'popDiv',			//my favor cell box
	obj_editMyFavBox	: 'editMyFavBox',	//my favor edit box
	obj_editMyFavTitle 	: 'editMyFavTitle',	//my favor edit box title
	obj_favTitle		: 'favTitle',		//my favor edit box favor's title
	obj_favDesc			: 'favDesc',		//my favor edit box favor's description
	obj_favUrl			: 'favUrl',			//my favor edit box favor's url
	/*** global variables end ***/
	
	favList : new Array(),
	selectedObj : null,
	showing : false,
	
	/*** build my favor list ***/
	buildMyFavList : function() {
		this.showing = false;
		this.selectedObj = null;
		var str = "";
		if( this.favList.length > 0 ) {
			var theObj;
			for( var i=0; i<this.favList.length; i++) {
				theObj = this.favList[i];
				var _desc = (theObj.desc)? "\n"+theObj.desc : "";
				str += "<div id=\"myFav_"+ theObj.id +"\" tit=\""+ theObj.tit +"\"desc=\""+ theObj.desc +"\" url=\""+ theObj.url +"\" class=\""+ this.styleOut +"\" onmouseover=\"MyAlbum.mouseEvent(event, this)\" onmouseout=\"MyAlbum.mouseEvent(event, this)\">";
				str += "<a href=\"/member/manager/albumUpload?to="+theObj.id+" \" title=\""+ theObj.tit + _desc +"\"><strong>"+ theObj.tit +"</strong><br /><span style=\"text-decoration: none;\">"+ theObj.desc +"</span></a>";
				str += "</div>";
			}
		}
		else {
			str = this.str_noList;
		}
		$(this.obj_myFavBox).innerHTML = str;
	},
	/*** build my favor list end ***/

	/*** style operations of my favor list ***/
	//listen mouse event
	mouseEvent : function(e, theObj, opr) {
		if (!e) 
			var e=window.event;
		if (!theObj) {
			try {
				theObj = e.srcElement;
			}
			catch(e){}
		}
		if (theObj.id.indexOf('myFav_') < 0 && this.selectedObj ) {
			theObj = this.selectedObj;
		}
		if ( e.type == 'mouseover' ){
			this.overCell(theObj);
		}
		else if ( e.type == 'mouseout'  ||  e.type == 'blur' ){
			this.outCell(theObj);
		}
		else if ((e.type == 'click')){
			if (opr == 'delete') {
				this.deleteFav(theObj);
			}
			else if (opr == 'edit'){
				this.editFavCheck(theObj);
			}
			else {
				if (!this.showing) {
					this.selectCell(theObj, opr);
				}
				else {
					this.unSelectCell(theObj);
				}
				this.showing = !this.showing;
			}
		}
	},
	
	//on mouse over to do this
	overCell : function(theObj) {
		if (!this.showing) {
			this.outCellAll();
			theObj.className = this.styleOver;
			this.selectEntry(theObj);
			this.showTip(theObj);
		}
	},
	//on mouse out to do this
	outCell : function(theObj) {
		if (!this.showing) {
			theObj.className = this.styleOut;
			this.hideTip();
		}
	},
	//a shortcut to set all to mouse out style
	outCellAll : function() {
		for (var i=0; i<this.favList.length; i++) {
			this.outCell(this.favList[i]);
		}
	},

	//on mouse click to do this
	selectCell : function(theObj, opr) {
		if (opr != 'add') {
			theObj.className = this.styleOver;
		}
		this.selectEntry(theObj);
		this.showAddBar(theObj, opr);
	},
	//on clear select to do this
	unSelectCell : function(theObj){
		theObj.className = this.styleOut;
		this.unSelectEntry();
		this.hideTip();
		this.hideAddBar();
	},

	//set mark
	selectEntry : function(theObj){
		if ( !this.isSelected(theObj) ){
			this.selectedObj = theObj;
		}
	},
	//clear mark
	unSelectEntry : function(){
		selectedObj = null;
	},
	//whether the object is selected
	isSelected : function(theObj){
		if (this.selectedObj == theObj)
			return true;
		return false;
	},

	//show edit & delete icon
	showTip : function(theObj) {
		var thePopBox = $(this.obj_popDiv);
		var str = "";
		thePopBox.style.display = 'block';
		thePopBox.style.position = 'absolute';
		thePopBox.style.top    = Element.getPosition(theObj).top -0 +1 + 'px';
		thePopBox.style.left   = Element.getPosition(theObj).left -0 +Element.getWidth(theObj) -33 + 'px';
	},
	hideTip : function() {
		$(this.obj_popDiv).style.display = 'none';
	},

	//show edit panel
	showAddBar : function(theObj, opr) {
		$(this.obj_editMyFavBox).style.display = 'block';
		$(this.obj_editMyFavBox).style.position = 'absolute';
		$(this.obj_editMyFavBox).style.top    = Element.getPosition(theObj).top + 'px';
		$(this.obj_editMyFavBox).style.left   = Element.getPosition(theObj).left -0 +Element.getWidth(theObj) -33 + 'px';
		$(this.obj_editMyFavTitle).innerHTML = (opr == 'add')? this.str_editMyFavTitle : this.str_editMyFavTitle2;
		$(this.obj_favTitle).value = (opr == 'add')? '' : theObj.getAttribute('tit');
		$(this.obj_favDesc).value = (opr == 'add')? '' : theObj.getAttribute('desc');
		$(this.obj_favUrl).value = (opr == 'add')? 'http://' : theObj.getAttribute('url');
		$(this.obj_favTitle).select();
		$(this.obj_favTitle).focus();
	},
	hideAddBar : function() {
		$(this.obj_editMyFavBox).style.display = 'none';
	},
	/*** style operations of my favor list end ***/

	/*** data operations of my favor list ***/
	//get the data index of current object
	getSourceDataIndex : function(theObj) {
		for (var i=0; i<this.favList.length; i++) {
			if ('myFav_'+this.favList[i].id == theObj.id) {
				return (i);
			}
		}
		return (-1);
	},
	//confirm delete one
	deleteFav : function(theObj) {
		theObj.className = this.styleOver;
		this.selectEntry(theObj);
		if (confirm(this.str_noticeWordsDel + theObj.getAttribute('tit') +'？')) {
			showTipInfo(MyAlbum.str_noticeLoading);
			var doDelete = function() {MyAlbum.requestDeleteStatus(theObj)};
			doIt = setTimeout(doDelete, 1);
			//var doDelete = function() {MyFav.doDeleteFav(theObj)};
			//doIt = setTimeout(doDelete, 1);
		}
		else {
			this.unSelectCell(theObj);
		}
	},
	//request from server
	requestDeleteStatus : function(theObj) {
		var url = '/member/manager/albumsManager.do';
		var pars = 'func=del&id=' + this.favList[this.getSourceDataIndex(theObj)].id;
		var myAjax = new Ajax.Request( url, {method: 'get', parameters: pars, onComplete: MyAlbum.doDeleteFav, responseArguments: theObj } );
	},
	//do delete operation
	doDeleteFav : function(request, theObj) {
		if (request.responseText.indexOf(1) != 0) {
			alert('error code: '+request.responseText);
		}
		else {
			showTipInfo(MyAlbum.str_noticeDone);
			//theObj = MyFav.selectedObj;
			if ( MyAlbum.getSourceDataIndex(theObj) >= 0 ) {
				MyAlbum.favList.splice(MyAlbum.getSourceDataIndex(theObj), 1);
				MyAlbum.unSelectCell(theObj);
				MyAlbum.buildMyFavList();
			}	
		}
		setTimeout(hideTipInfo, 500);
	},
	//check edit data
	editFavCheck : function(theObj) {
		var expRequire = /.+/;
		var expUrl = /^http:\/\/([a-zA-Z0-9]|[-_])+\.[A-Za-z0-9]+[\/=\?%\-&_~`@[\]\':+!]*([^<>\"\"])*$/;
		if( !expRequire.test( $(this.obj_favTitle).value ) ){
			alert(this.str_noticeWordsTitle);
			$(this.obj_favTitle).focus();
		}
		//else if( !expUrl.test( $(this.obj_favUrl).value ) ){
		//	alert(this.str_noticeWordsUrl);
	//		$(this.obj_favUrl).focus();
	//	}
		else {
			showTipInfo(MyAlbum.str_noticeLoading);
			this.requestEditStatus(theObj);
		}
	},
	//request from server
	requestEditStatus : function(theObj) {
		//edit
		if (this.getSourceDataIndex(theObj) >= 0) {
			var url = '/member/manager/albumsManager.do';
			var pars = 'func=update&id='+this.favList[this.getSourceDataIndex(theObj)].id+'&title='+$(this.obj_favTitle).value+'&desc='+$(this.obj_favDesc).value+'&link='+$(this.obj_favUrl).value;
			var myAjax = new Ajax.Request( url, {method: 'get', parameters: pars, onComplete: MyAlbum.doEditFav, responseArguments: theObj } );
		}
		//add
		else {
			var url = '/member/manager/albumsManager.do';
			var pars = 'func=add&title='+$(this.obj_favTitle).value+'&desc='+$(this.obj_favDesc).value+'&link='+$(this.obj_favUrl).value;
			var myAjax = new Ajax.Request( url, {method: 'get', parameters: pars, onComplete: MyAlbum.doEditFav, responseArguments: theObj } );
		}
	},
	//do edit operation
	doEditFav : function(request, theObj) {
		//0id<title<link<desc
		if (request.responseText.indexOf(1) != 0){
			alert('error codevv: '+request.responseText);
		}
		else {
			showTipInfo(MyAlbum.str_noticeDone);
			//var theObj = (MyFav.selectedObj)? MyFav.selectedObj : $('myFav_add');
			var respArguments = request.responseText.substring(1).split("<");
			if (MyAlbum.getSourceDataIndex(theObj) >= 0) {
				MyAlbum.favList[MyAlbum.getSourceDataIndex(theObj)].tit = respArguments[1];
				MyAlbum.favList[MyAlbum.getSourceDataIndex(theObj)].desc = respArguments[3];
				MyAlbum.favList[MyAlbum.getSourceDataIndex(theObj)].url = respArguments[2];
			}
			else if ( theObj.id.indexOf('myFav_') >= 0 ) {
				var _obj = new Object();
				_obj.id 	= respArguments[0];
				_obj.tit 	= respArguments[1];
				_obj.desc 	= respArguments[3];
				_obj.url 	= respArguments[2];
				MyAlbum.favList[MyAlbum.favList.length] = _obj;
			}
			MyAlbum.unSelectCell(theObj);
			MyAlbum.buildMyFavList();
		}
		setTimeout(hideTipInfo, 500);
	}
	/*** data operations of my favor list end ***/
}
/******* My MyAlbum List end **********/

//open new window in the middle of the screen
//url(String): new window's url
//winName(String): new window's name
//theWidth(Int): new window's width
//theHeight(Int): new window's height
//scrolls(yes|null): wheather can scrolls
function openWindow( url, winName, theWidth, theHeight, scrolls ) {
	var xposition=0; 
	var yposition=0;
	if ( (parseInt(navigator.appVersion) >= 4 ) ){
		xposition = (screen.width - theWidth) / 2;
		yposition = (screen.height - theHeight) / 2;
	}
	var theproperty= "width=" + theWidth + "," ;
	theproperty+= "height=" + theHeight + "," ;
	theproperty+= "location=0," ;
	theproperty+= "menubar=0,";
	theproperty+= "resizable=0,";
	if(scrolls)
		theproperty+= "scrollbars=" + scrolls + ",";
	else
		theproperty+= "scrollbars=0,";	
	theproperty+= "status=0," ;
	theproperty+= "titlebar=0,";
	theproperty+= "toolbar=0,";
	theproperty+= "hotkeys=0,";
	theproperty+= "screenx=" + xposition + ","; //仅适用于Netscape
	theproperty+= "screeny=" + yposition + ","; //仅适用于Netscape
	theproperty+= "left=" + xposition + ","; //IE
	theproperty+= "top=" + yposition; //IE 
	return( window.open( url,winName,theproperty ) );
}

//set cookie
//name(String):	cookie's name
//value(String): cookie's value
//expires(Int:minute|String:never): cookie's expiring time
function setCookie(name, value, expires, path) {
	var str = name + "=" + escape(value);
	if (expires) {
		if (expires == 'never') 
			expires = 100*365*24*60;
		var exp=new Date(); 
		exp.setTime(exp.getTime() + expires*60*1000);
		str += "; expires="+exp.toGMTString();
	}
	if (path) {
		str += "; path=" + path;
	}
	//str += "; path=/; domain="+document.domain;
	document.cookie = str;
} 
//get cookie by cookie's name
//name(String): cookie's name
function getCookie(name){
	var tmp, reg = new RegExp("(^| )"+name+"=([^;]*)(;|$)","gi");
	if( tmp = reg.exec( unescape(document.cookie) ) )
		return(tmp[2]);
	return null;
}

/******* Common Js for Sohu Blog **********/
/*	Author: Todd Lee (www.todd-lee.com)
/*	Last update: 2005-10-15
*/

function toggleSidePanel(arrowObj){
	Element.swapClassName(arrowObj, "arrow-up", "arrow-down");
	var children = Element.getParentElementByClassName(arrowObj, "panel").childNodes;
	for (var i = 0; i < children.length; i++) {
		if (children[i].nodeType == 1 && children[i].className.indexOf("content") != -1) {
			var contentObj = children[i];
			break;
		}
	}
	Element.swapClassName(contentObj, "panel-content", "panel-content-hidden");
}

function toggleItem(arrowObj){
	Element.swapClassName(arrowObj, "arrow-up", "arrow-down");
	var children = Element.getParentElementByClassName(arrowObj, "item").childNodes;
	for (var i = 0; i < children.length; i++) {
		if (children[i].nodeType == 1 && children[i].className.indexOf("body") != -1) {
			var contentObj = children[i];
			break;
		}
	}
	Element.swapClassName(contentObj, "item-body", "item-body-hidden");
}

function isLogin() {
    if (getCookie("blog_cn")!=null && getCookie("blog_cn")!="" && getCookie("blog_cn")!="null")
        return true;
	return false;
}
function hasBlog() {
    if (getCookie("blog_permit")!=null && getCookie("blog_permit")!="" && getCookie("blog_permit")!="null" && getCookie("blog_permit") != 1)
        return true;
	return false;
}
function showTipInfo(text, tipBox) {
	if ($('tipBoxDiv')) {
		var tipBox = $('tipBoxDiv');
	}
	var body = document.body;
	if (!tipBox) {
		var tipBox = document.createElement("div");
		body.appendChild(tipBox);
	}
	tipBox.innerHTML = text;
	tipBox.id = "tipBoxDiv";
	tipBox.style.color = "#333";
	tipBox.style.border = "2px solid #cecece";
	tipBox.style.background = "#ffffe1";
	tipBox.style.padding = "10px";
	tipBox.style.display = "block";
	tipBox.style.zIndex = "1";
	tipBox.style.position = "absolute";
	var x = (body.offsetWidth - tipBox.offsetWidth)/2;
	var y = Math.ceil((document.documentElement.clientHeight - tipBox.offsetHeight)/2) + document.documentElement.scrollTop;
	tipBox.style.left = x + "px";
	tipBox.style.top = y + "px";
}
function hideTipInfo(tipBox, tipBoxShadow) {
	if (tipBox && tipBoxShadow) {
		tipBox.style.display = 'none';
	}
	else {
		$('tipBoxDiv').style.display = 'none';
	}
}
function getBlogTitle() {
	if (!$('blogTitle')) return null;
	return ($('blogTitle').firstChild.innerHTML);
}
function getBlogLink() {
	if (!$('blogTitle')) return null;
	return ($('blogTitle').firstChild.href);
}
function getBlogDesc() {
	if (!$('blogDesc')) return null;
	return ($('blogDesc').innerHTML);
}
function addToFav() {
	var _title = getBlogTitle();
	var _desc = getBlogDesc();
	var _link = getBlogLink();
	if (!_title || !_link) {
		alert('无法获得此站点相应数据');
		return;
	}
	if (menu_tool)	disableMenu(menu_tool);
	showTipInfo(MyFav.str_noticeLoading);
	
	var url = '/member/manager/linkManager.do';
	var pars = 'func=add&title='+ _title +'&desc='+ _desc +'&link='+ _link;
	var myAjax = new Ajax.Request( url, {method: 'get', parameters: pars, onComplete: doneAddToFav } );
}
function doneAddToFav(request) {
	//0id<title<link<desc
	if (request.responseText.indexOf(1) != 0){
		alert('error code: '+request.responseText);
	}
	else {
		showTipInfo(MyFav.str_noticeDone);
	}
	if (menu_tool)	setTimeout(function(){ableMenu(menu_tool)}, 1000);
	setTimeout(hideTipInfo, 1000);
}

//Add friend
function addFriend() {
	alert("\u6dfb\u52a0\u597d\u53cb\u6210\u529f\uff01");
	document.forms["addFriendForm"].submit();
}

function timeStamp() {	var now = new Date();return (now.getTime());};
function checkLogonForm(frm) {	if ($F('username').length <= 0) {alert("请填写用户名");$('username').focus();return false;}if ($F('passwd').length <= 0) {alert("请填写密码");$('passwd').focus();return false;}if ($F('save') >= 1) {setCookie('username', $F('username'), 'never', '/');setCookie('domain', $F('maildomain'), 'never', '/');}else {setCookie('username', '', 'never', '/');setCookie('domain', '', 'never', '/');}setCookie('usernameSaveMode', $F('save'), 'never', '/');$('loginid').value = $F('username') + $F('maildomain');setParm(frm);frm.Submit.disabled = 'disabled';$('submitInfo').style.visibility = 'visible';return true;};
function setLogonForm() {$('username').value = getCookie('username') || '';for (var i = 0; i < $('maildomain').options.length; i++) {if( $('maildomain').options[i].value == getCookie('domain') ) {$('maildomain').options[i].selected = true;break;}}if (getCookie('usernameSaveMode') == 1) {$('save').checked = true;	$('passwd').select();$('passwd').focus();}};
function getLogonForm() {var str = '<form action="http://passport.sohu.com/login.jsp" method="post" name="form_login" id="form_login" onsubmit="return checkLogonForm(this)"><input type="hidden" name="loginid" id="loginid" value="" /><table width="100%" border="0" cellspacing="2" cellpadding="0"><tr><td nowrap="nowrap"><label for="username" class="redfont">用户名</label></td><td><input name="username" type="text" class="text" id="username" value="" /> <select name="maildomain" id="maildomain" class="text"><option value="@sohu.com" selected="selected">@sohu.com</option><option value="@chinaren.com">@chinaren.com</option><option value="@vip.sohu.com">@vip.sohu.com</option><option value="@sms.sohu.com">@sms.sohu.com</option><option value="@sol.sohu.com">@sol.sohu.com</option><option value="@sogou.com">@sogou.com</option></select></td></tr><tr><td nowrap="nowrap" class="redfont"><label for="passwd">密　码</label></td><td><input name="passwd" type="password" class="text" id="passwd" value="" /></td></tr><tr><td></td><td><input name="Submit" id="Submit" type="submit" class="button-submit" value="登  录" />你是新人吗？<a href="/login/regnew.do" class="STYLE5">立刻申请</a><br /><span class="notice" id="submitInfo" style="visibility: hidden">正在登录，请稍候……</span></td></tr><tr><td colspan="2"><label for="save"><input name="save" type="checkbox" id="save" value="1" />保存我的用户名</label></td></tr></table></form>';return str;};
/******* Common Js for Sohu Blog end **********/
