function clearSelect(id)
{
  var sObj=document.getElementById(id);
 if ((sObj == undefined) || (sObj.tagName.toUpperCase() != "SELECT"))
 {
	 return;
 }

  for(var i=sObj.length;i>=0;i--)
  {
    sObj.options[i]=null;
  }
}
function setSelect(id,v)
{
  var sObj=document.getElementById(id);
  if ((sObj == undefined) || (sObj.tagName.toUpperCase() != "SELECT"))
  {
  return;
  }

  for(var i=0; i<sObj.length; i++)
  {
  	  if(sObj.options[i].value==v)
  	  {
  	  	sObj.options[i].selected=true;
  	  }
  }
}
function addSelectItem(id,txt,val,selected)
{
 var sObj=document.getElementById(id);
 if ((sObj == undefined) || (sObj.tagName.toUpperCase() != "SELECT"))
 {
	 return;
 }
 if(selected == undefined)
 {
	 selected=false;
 }
  var opt=new Option(txt,val,false,false);
  sObj.options[sObj.options.length]=opt;
  opt.selected=selected;
}

function getSingleSelectValueById(id){
  var obj=document.getElementById(id);
 if (obj==undefined)
 {
	  return null;
 }
  return obj.options[obj.selectedIndex].value;
}
function setCity(sv)
{
   var v=parseInt(getSingleSelectValueById("province"));
   clearSelect("city");
 if (v==null)
 {
	 addSelectItem("city","不限","0");
	 return;
 }
  
 var v=parseInt(v);
    var subObj=sublocation_array[v];
 if(subObj==undefined)
 {
	 return;
 }

  for(key in subObj)
 {
 	if(sv!=undefined && sv==key)
 	{
 		addSelectItem("city",subObj[key],key,true);
 	}else{
	    addSelectItem("city",subObj[key],key);
 	}
 }
}
function setSelectState(name,v){
  var chks = document.getElementsByName(name);	
  if(chks==undefined || chks.length<=0)
  {
  	  return;
  }
  
  for(var i=0; i<chks.length;i++)
  {
  	 chks[i].checked = v;
  }
}
function getCurrentDate(separator)
{
    var now=new Date();
 var m=(now.getMonth()+1)+'';
 var d=now.getDate()+'';
 m=((m.length==1)?('0'+m):m);
 d=((d.length==1)?('0'+d):d);
 if(separator==undefined){
   return now.getYear()+m+d;
 }
 return now.getYear()+separator+m+separator+d;
}
function getNextDate(separator)
{
    var now=new Date();
 var tmp=new Date(now.getYear(),now.getMonth(),now.getDate());

    var t=tmp.getTime()+24*3600*1000;
    var next=new Date(t);
    
 var m=(next.getMonth()+1)+'';
 var d=next.getDate()+'';
 
 m=((m.length==1)?('0'+m):m);
 d=((d.length==1)?('0'+d):d);
 
 if(separator==undefined){
   return next.getYear()+m+d;
 }
 
 return next.getYear()+separator+m+separator+d;
}
function Cookie(document, name, hours, path, domain, secure)
{
    this.$document = document;
    this.$name = name;
    if (hours)
        this.$expiration = new Date((new Date()).getTime() + hours*3600000);
    else this.$expiration = null;
    if (path) this.$path = path; else this.$path = null;
    if (domain) this.$domain = domain; else this.$domain = null;
    if (secure) this.$secure = true; else this.$secure = false;
}
Cookie.prototype.store = function () {
    var cookieval = "";
    for(var prop in this) {
        if ((prop.charAt(0) == '$') || ((typeof this[prop]) == 'function')) 
            continue;
        if (cookieval != "") cookieval += '&';
        cookieval += prop + ':' + escape(this[prop]);
    }

    var cookie = this.$name + '=' + cookieval;
    if (this.$expiration)
        cookie += '; expires=' + this.$expiration.toGMTString();
    if (this.$path) cookie += '; path=' + this.$path;
    if (this.$domain) cookie += '; domain=' + this.$domain;
    if (this.$secure) cookie += '; secure';

    this.$document.cookie = cookie;
}
Cookie.prototype.load = function() { 
    var allcookies = this.$document.cookie;
    if (allcookies == "") return false;

    var start = allcookies.indexOf(this.$name + '=');
    if (start == -1) return false;   
    start += this.$name.length + 1;  
    var end = allcookies.indexOf(';', start);
    if (end == -1) end = allcookies.length;
    var cookieval = allcookies.substring(start, end);

    var a = cookieval.split('&');    
    for(var i=0; i < a.length; i++) 
        a[i] = a[i].split(':');
    
    for(var i = 0; i < a.length; i++) {
        this[a[i][0]] = unescape(a[i][1]);
    }
    return true;
}
Cookie.prototype.remove = function() {
    var cookie;
    cookie = this.$name + '=';
    if (this.$path) cookie += '; path=' + this.$path;
    if (this.$domain) cookie += '; domain=' + this.$domain;
    cookie += '; expires=Fri, 02-Jan-1970 00:00:00 GMT';
    this.$document.cookie = cookie;
}

function qq_input(id,is_focus)
{
	var qq = document.getElementById(id);
	if(is_focus){
		qq.value = "";
	}else{
		if(qq.value == "")
		{
			qq.value = "请输入QQ号码";
		}
	}
}

function checkQQ(id)
{
  var qq = document.getElementById(id);
  var reQQ= /^[1-9]\d{4,8}$/;
  if(!reQQ.test(qq.value)){
  	alert("请输入正确的QQ号码!");
  	return false;
  }
  return true;
}

function switch_tab(d)
{
	var index=parseInt(d);
	if(index < 0 && index > 5)
	{
      index = 0;
	}
	
	for(var ti=0;ti<=5;ti++)
	{
		if(index==ti){
	    document.getElementById("p"+ti).style.display = "block";
			document.getElementById("lbl_p"+ti).className = "nonce";	
		}else{
			document.getElementById("p"+ti).style.display = "none";
			document.getElementById("lbl_p"+ti).className = "";	
		}
	}
}

var isPollOne = true;
var pollVarOne = Math.floor(Math.random()*10)%6+1;
function setPollOne(v)
{
  isPollOne=v;
}

function pollPlayOne()
{
  if (isPollOne)
  {
	pollVarOne=pollVarOne%6;
	switch_tab(pollVarOne);
	pollVarOne++;
  }
  if ((pollVarOne%6) == 1)
  {
   setTimeout("pollPlayOne()",5000);
  }else{
   setTimeout("pollPlayOne()",4000);
  }
}

// ------- photo Roll(Roll 2) --------
var isPollTwo = true;
var pollVarTwo = Math.floor(Math.random()*10)%4 + 1;

function switch_tab_two(d)
{
	var index=parseInt(d);
	if(index < 0 && index > 3)
	{
      index = 0;
	}
	
	for(var ti=0;ti<=3;ti++)
	{
		if(index==ti){
	    document.getElementById("photo"+ti).style.display = "block";
			document.getElementById("photo_menu"+ti).className = "nonce";	
		}else{
			document.getElementById("photo"+ti).style.display = "none";
			document.getElementById("photo_menu"+ti).className = "";	
		}
	}
}

function setPollTwo(v)
{
  isPollTwo=v;
}

function pollPlayTwo()
{
  if (isPollTwo)
  {
	pollVarTwo=pollVarTwo%4;
	switch_tab_two(pollVarTwo);
	pollVarTwo++;
  }
  
  setTimeout("pollPlayTwo()", 3500);
}


var isPollThree = true;
var pollVarThree = Math.floor(Math.random()*10)%5+1;

function setPollThree(v)
{
  isPollThree=v;
}

function pollPlayThree()
{
  if (isPollThree)
  {
	pollVarThree=pollVarThree%5 + 1;
	advShowNum(pollVarThree);
  }
  setTimeout("pollPlayThree()",3000);
}

function advShowNum(num)
{
  var adv_td = document.getElementById("flashpop");
  try{
   adv_td.filters[0].Apply();
  }catch(e)
  {}
  for(var j=1; j<=5; j++)
  {
      
    var adv_tmp = document.getElementById("adv_"+j);
	var adv_num_tmp = document.getElementById("adv_num"+j);

     if (navigator.appName == "Netscape")
	 {
		 adv_tmp.style.visibility = ((j == num) ? "visible" : "hidden");
	 }else
	 {
		 adv_tmp.style.display = ((j == num)? "block" : "none");
	    
	 }
	 adv_num_tmp.style.backgroundColor=((j == num)?"#f60":"#000");
  }
 try{
 adv_td.filters[0].play();
 }catch(e){}
}
function getPageOffset(element){
	var left=0,top=0;
	 do{ 
      top+=element.offsetTop || 0; 
      left+=element.offsetLeft || 0; 
      element=element.offsetParent; 
    }while(element); 

	return {x:left,y:top};
}

// ----------------------- v2.0 js standard ----------------------- // 

// the new version of setCookie() after V2.0
function setQzoneCookie(name,value)
{
	document.cookie = name + "=" + value + "; path=/; domain=qzone.qq.com";
}

// the new version of getCookie() after V2.0
function getQzoneCookie(name){
	var search;
	search = name + "=";
	offset = document.cookie.indexOf(search);
	if (offset != -1) {
		offset += search.length;
		end = document.cookie.indexOf(";", offset);
		if (end == -1)
			end = document.cookie.length;
		return unescape(document.cookie.substring(offset, end));
	}
	else
	{
		return "";
	}
}

// the new version of getQQNum() after V2.0
function getUserQQ()
{
	var zzpaneluin = parseInt(getQzoneCookie("zzpaneluin"));
	
	if (zzpaneluin >10000 && zzpaneluin < zzpaneluin)
	{
    	return zzpaneluin;
	}

	var suin = getQzoneCookie("uin");
	var re = /^o(0)*/;
	var tmp_suin = suin.replace(re,'');
	var qq = parseInt(tmp_suin);
	if (qq > 10000 && qq < 1000000000)
	{
		return qq;
	}

	return 0;
}

function logoffQzone()
{
	document.cookie = "uin=; expires=Thu, 01-Jan-1970 00:00:01 GMT; path=/; domain=qq.com";
	document.cookie = "skey=; expires=Thu, 01-Jan-1970 00:00:01 GMT; path=/; domain=qq.com";
	document.cookie = "zzpaneluin=; expires=Thu, 01-Jan-1970 00:00:01 GMT; path=/; domain=qq.com";
	document.cookie = "zzpanelkey=; expires=Thu, 01-Jan-1970 00:00:01 GMT; path=/; domain=qq.com";
	document.cookie = "URL_PTLOGIN=; expires=Thu, 01-Jan-1970 00:00:01 GMT; path=/; domain=qq.com";
	document.cookie = "verifysession=; expires=Thu, 01-Jan-1970 00:00:01 GMT; path=/; domain=qq.com";
	document.cookie = "nick=; expires=Thu, 01-Jan-1970 00:00:01 GMT; path=/; domain=qq.com";
	document.cookie = "logon_cookie=; expires=Thu, 01-Jan-1970 00:00:01 GMT; path=/; domain=qzone.qq.com";
	document.cookie = "PortalInfo=; expires=Thu, 01-Jan-1970 00:00:01 GMT; path=/; domain=qzone.qq.com";
	location.href	= 'http://qzone.qq.com';
}

function encode_update(){
	var iptEncode;
	try{
		iptEncode = document.createElement('<input name="ie" />');
	}catch(e){
		iptEncode = document.createElement('input');
		iptEncode.name = 'ie';
	}
	iptEncode.type = 'hidden';
	iptEncode.value = 'utf8';
	document.getElementById('qzone_search_form').appendChild(iptEncode);
	if(document.getElementsByName('cid').length)document.getElementsByName('cid')[0].value = 'qz.club.idx';
}