// JavaScript Document
var childCreate=false;

function Offset(e)
//ȡ��ǩ�ľ��λ��
{
	var t = e.offsetTop;
	var l = e.offsetLeft;
	var w = e.offsetWidth;
	var h = e.offsetHeight-2;

	while(e=e.offsetParent)
	{
		t+=e.offsetTop;
		l+=e.offsetLeft;
	}
	return {
		top : t,
		left : l,
		width : w,
		height : h
	}
}
function close_all(){
    try{document.getElementById("selectchilduser[birthday(1i)]").style.display="none";}catch(e){}
}
function loadSelect(obj){
    
	//��һ����ȡ��Select���ڵ�λ��
	var offset=Offset(obj);
	//�ڶ����������select����
	obj.style.display="none";

	//��������һ��div��4����select
	var iDiv = document.createElement("div");
		iDiv.id="selectof" + obj.name;
		iDiv.style.position = "absolute";
		iDiv.style.width=offset.width + "px";
		iDiv.style.height=offset.height + "px";
		iDiv.style.top=offset.top + "px";
		iDiv.style.left=offset.left + "px";
		iDiv.style.background="url(/images/icons/icon_select_focus.gif) no-repeat right ";
		iDiv.style.border="1px solid #D1D4D1";
		iDiv.style.fontSize="9pt";
		iDiv.style.lineHeight=offset.height + "px";
		iDiv.style.textIndent="4px";
	if(iDiv)document.body.appendChild(iDiv);

	//���Ĳ�����select��Ĭ�ϵ�ѡ����ʾ��4
	var tValue=obj.options[obj.selectedIndex].innerHTML;
	iDiv.innerHTML=tValue;

	//���岽��ģ�������
	iDiv.onmouseover=function(){//����Ƶ�
		//iDiv.style.background="url(/images/icon_select_focus.gif) no-repeat right";
	}
	iDiv.onmouseout=function(){//�������
		//iDiv.style.background="url(/images/icon_select_focus.gif) no-repeat right";
	}
	iDiv.onclick=function(){//�����
		if (document.getElementById("selectchild" + obj.name)){
		//�ж��Ƿ䴽���div
			if (childCreate){
				//�жϵ�ǰ����-�ǲ��Ǵ�״̬������Ǵ蝹ľ͹رյ��ǹرյľʹ瑱�
				document.getElementById("selectchild" + obj.name).style.display="none";
                                
				childCreate=false;
			}else{
				document.getElementById("selectchild" + obj.name).style.display="";
				childCreate=true;
			}
		}else{
			//��ʼһ��div������һ��div�±ߣ���options�����?
			var cDiv = document.createElement("div");
			cDiv.id="selectchild" + obj.name;
			cDiv.style.position = "absolute";
			cDiv.style.width=offset.width + "px";
			cDiv.style.height=obj.options.length *20 + "px";
			cDiv.style.top=(offset.top+offset.height+2) + "px";
			cDiv.style.left=offset.left + "px";
			cDiv.style.background="#f7f7f7";
			cDiv.style.border="1px solid silver";

			var uUl = document.createElement("ul");
			uUl.id="uUlchild" + obj.name;
			uUl.style.listStyle="none";
			uUl.style.margin="0";
			uUl.style.padding="0";
			uUl.style.fontSize="12px";
			cDiv.appendChild(uUl);
			document.body.appendChild(cDiv);		
			childCreate=true;
			for (var i=0;i<obj.options.length;i++){
				//��ԭʼ��select��ǩ�е�options��ӵ�li��
				var lLi=document.createElement("li");
				lLi.id=obj.options[i].value;
				lLi.style.textIndent="4px";
				lLi.style.height="20px";
				lLi.style.lineHeight="20px";
				lLi.innerHTML=obj.options[i].innerHTML;
				uUl.appendChild(lLi);
			}
			var liObj=document.getElementById("uUlchild" + obj.name).getElementsByTagName("li");
			for (var j=0;j<obj.options.length;j++){
				//Ϊli��ǩ�������¼�
				liObj[j].onmouseover=function(){
					this.style.background="gray";
					this.style.color="white";
				}
				liObj[j].onmouseout=function(){
					this.style.background="white";
					this.style.color="black";
				}
				liObj[j].onclick=function(){
					//��}�����飬һ�ǽ��û�ѡ��ı��浽ԭʼselect��ǩ�У�Ҫ������ٺÿ��?�ݽ���Ҳ��ȡ����select��ֵ�ˡ�
					obj.options.length=0;
					obj.options[0]=new Option(this.innerHTML,this.id);
					//ͬʱ���ǰ���-�Ĺرյ�
					document.getElementById("selectchild" + obj.name).style.display="none";
					childCreate=false;
					iDiv.innerHTML=this.innerHTML;
				}
			}
		}
	}
}
function shrink(obj)
{
	shrink_div = obj.id + "_1"
	if(document.getElementById(shrink_div).style.display=="block")
	{
		document.getElementById(shrink_div).style.display="none"
		obj.src = "/images/icons/extract.gif"
	}else
	{
		document.getElementById(shrink_div).style.display="block"
		obj.src = "/images/icons/contract.gif"		
	}
}
//pop menu
function change_top_bak(obj){
	obj.style.background = "#000"
	obj.style.color = "#fff"
	obj.style.cursor = "pointer"
}
function change_top_bak2(obj){
	obj.style.background = "#fff"
	obj.style.color = "#000"
}
function clear_text(obj)
{
    if(document.getElementById(obj).value=="Write a broadcast message to all online users...")
        {
            document.getElementById(obj).value=""
        }
}
function link_to(url){
	window.location = url;
}
//on click key=enter  submit  
//onkeyup = submit_13(obj)
function submit_13(obj){
 try {
 if (event.keyCode ==13)
  {
    document.getElementById(obj).submit();
  }
  }catch(e){}
}
function displayDiv(div){
	try{
	$(div).style.display = "block"
	}catch(e){}
}
function hideDiv(div){
	try{
	$(div).style.display = "none"
	}catch(e){}
}
function selectAffiliation(e){
	if(e.checked)
		displayDiv(e.name + '_field');
	else
		hideDiv(e.name + '_field');
}
function close_div(){
	try{
	$("my_div_block").style.background = "#000"
	$("browse_div_block").style.background = "#000"
	$("my_div").style.display = "none"
	$("browse_div").style.display = "none"
	}catch(e){}
}
function change_location(e,obj,city){
        var city_list = ["beijing","shanghai","shenzhen","hongkong","all"]
	try{
            for (i=0; i<city_list.length; i++) {
                $("l_"+city_list[i]).style.background='#000';
                $("l_"+city_list[i]).style.padding='0';
            }
	}catch(e){}
	$(obj).href = "/magazine?city=" + city;
        e.style.background='#272727';
        e.style.padding='4px 10px';
        switch(city) {
                case "Beijing": {
                        SetCookie('city_content','1');
                        SetCookie('city_people','1');
                        new Ajax.Updater('temp_div', '/magazine/change_default_userpic?city_id=1', {asynchronous:true, evalScripts:true});
                        break;
                        }
                case "Shanghai": {
                        SetCookie('city_content','2');
                        SetCookie('city_people','2');
                        new Ajax.Updater('temp_div', '/magazine/change_default_userpic?city_id=2', {asynchronous:true, evalScripts:true});
                        break;
                        }
                case "Shenzhen": {
                        SetCookie('city_content','3');
                        SetCookie('city_people','3');
                        new Ajax.Updater('temp_div', '/magazine/change_default_userpic?city_id=3', {asynchronous:true, evalScripts:true});
                        break;
                        }
                case "Guangzhou": {
                        SetCookie('city_content','4');
                        SetCookie('city_people','4');
                        new Ajax.Updater('temp_div', '/magazine/change_default_userpic?city_id=4', {asynchronous:true, evalScripts:true});
                        break;
                        }
                case "Hongkong": {
                        SetCookie('city_content','5');
                        SetCookie('city_people','5');
                        new Ajax.Updater('temp_div', '/magazine/change_default_userpic?city_id=5', {asynchronous:true, evalScripts:true});
                        break;
                        }
                case "All": {
                        SetCookie('city_content','0');
                        SetCookie('city_people','0');
                        new Ajax.Updater('temp_div', '/magazine/change_default_userpic?city_id=0', {asynchronous:true, evalScripts:true});
                        break;
                        }
                default:;
        }         
}
function change_gray(obj)
{
        if(obj.value=="Quick search")
            {
                obj.className=""
                obj.value=""              
            }
}

function ajaxGet(placeholder,url){
	new Ajax.Updater(placeholder, url, {method:'get', 
		asynchronous:true,  
		evalScripts:true, 
		onLoading:function(){$(placeholder).innerHTML="<img src='/images/icons/p1_loading.gif'/>"}, 
		onComplete:function(){}});
}

function selectTag(field,tag){
	var text_field = $(field);
	tag = tag.strip();
	// split the tag list string into array
	var tags = text_field.value.strip().split(',').map(function(s){ return s.strip() });
	if (tags.length > 0) {
		if (tags.include(tag)) {
			tags = tags.without(tag);
		} else {
			tags.push(tag);
		}
	} else {
		tags = [tag];
	}
	text_field.value = tags.without('').join(', ');
}

var w3c=(document.getElementById)? true: false;
var agt=navigator.userAgent.toLowerCase();
var ie = ((agt.indexOf("msie") != -1) && (agt.indexOf("opera") == -1) && (agt.indexOf("omniweb") == -1));

function IeTrueBody(){
return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body;
}

function GetScrollTop(){
 return ie ? IeTrueBody().scrollTop : window.pageYOffset;
}
function getPageScroll(){ 
  var yScroll; 
  if (self.pageYOffset) { 
    yScroll = self.pageYOffset; 
  } else if (document.documentElement && document.documentElement.scrollTop){   // Explorer 6 Strict 
    yScroll = document.documentElement.scrollTop; 
  } else if (document.body) {// all other Explorers 
    yScroll = document.body.scrollTop; 
  } 
  arrayPageScroll = new Array('',yScroll)  
  return arrayPageScroll; 
} 
function getPageSize(){   
  var xScroll, yScroll;   
  if (window.innerHeight && window.scrollMaxY) {   
    xScroll = document.body.scrollWidth; 
    yScroll = window.innerHeight + window.scrollMaxY; 
  } else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac 
    xScroll = document.body.scrollWidth; 
    yScroll = document.body.scrollHeight; 
  } else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari 
    xScroll = document.body.offsetWidth; 
    yScroll = document.body.offsetHeight; 
  } 
  var windowWidth, windowHeight; 
  if (self.innerHeight) {  // all except Explorer 
    windowWidth = self.innerWidth; 
    windowHeight = self.innerHeight; 
  } else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode 
    windowWidth = document.documentElement.clientWidth; 
    windowHeight = document.documentElement.clientHeight; 
  } else if (document.body) { // other Explorers 
    windowWidth = document.body.clientWidth; 
    windowHeight = document.body.clientHeight; 
  }   
  // for small pages with total height less then height of the viewport 
  if(yScroll < windowHeight){ 
    pageHeight = windowHeight; 
  } else {  
    pageHeight = yScroll; 
  } 
  if(xScroll < windowWidth){   
    pageWidth = windowWidth; 
  } else { 
    pageWidth = xScroll; 
  } 
  arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight)  
  return arrayPageSize; 
	//return pageHeight;
}
function getrandom(len)
{
 var seed = new Array(
    'abcdefghijklmnopqrstuvwxyz',
    'ABCDEFGHIJKLMNOPQRSTUVWXYZ',
    '0123456789'
   );
 
 var idx,i;
 var result = '';
 for (i=0; i<len; i++)
 {
  idx = Math.floor(Math.random()*3);
  result += seed[idx].substr(Math.floor(Math.random()*(seed[idx].length)), 1);
 }

 return result;
} 

function show_default_img(obj){
     obj.src = "/images/gfx/avatar40x50.jpg";
}

function show_nothing(obj) {
    obj.setStyle({display:'none'});
}


/***********************************************
* Different CSS depending on OS (mac/pc)- © Dynamic Drive (www.dynamicdrive.com)
* This notice must stay intact for use
* Visit http://www.dynamicdrive.com/ for full source code
***********************************************/
// var mac_externalcss='/css/macstyle.css' //if "external", specify Mac css file here
// var mactest=navigator.userAgent.indexOf("Mac")!=-1
// if (mactest)
// document.write('<link rel="stylesheet" type="text/css" href="'+ mac_externalcss +'">')