 //select方法
 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;
   }
 }

  //设置select方法
 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;
 }

 //获得select的值
 function getSingleSelectValueById(id){
   var obj=document.getElementById(id);
	 if (obj==undefined)
	 {
		  return null;
	 }
   return obj.options[obj.selectedIndex].value;
 }


 function setCity(p,c,sv)
 {
    var v=parseInt(getSingleSelectValueById(p));
    clearSelect(c);
	 if (v==null)
	 {
		 addSelectItem(c,"请选择","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(c,subObj[key],key,true);
	 	}else{
		    addSelectItem(c,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;
   }
 }
//格式:2006-07-08或20060708
 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 getCookie(name){
	var r=new RegExp("(^|;|\\s+)"+name+"=([^;]*)(;|$)");
	var m=document.cookie.match(r);
	return(!m?"":m[2]);
}

function openCurrentUserInfo()
{
 var qq = getQQNum();
 if(qq!=0)
 {
		  window.location.href = "http://user.qzone.qq.com/"+qq+"/?url=/qzone/admin/user_infomation_main.html";
			return;
 }
	 window.location.href = "http://qzone.qq.com";
}

function setDay(y,m,d,selectIdex)
{
   var y_n = getSingleSelectValueById(y);
	 var m_n = getSingleSelectValueById(m);
   var m_d = new Array(31,28,31,30,31,30,31,31,30,31,30,31);
   var index = parseInt(m_n) - 1;
	 var max_d = m_d[index];

	 if( ( (y_n%100== 0) ? (y_n%400==0) : (y_n%4 ==0) ) && m_n == 2)
	 {
       max_d = 29;
	 }
	 clearSelect(d);
	 for(var i = 1; i <= max_d; i++)
	 {
		 if(selectIdex != undefined && i==selectIdex){
		   	addSelectItem(d,i,i,true);
		 }else{
  		  addSelectItem(d,i,i,false);
		 }
	 }
}

function DayChangeNew(monthID,dayID,astroID)
{
	var astroIndex = AstroChangeNew(monthID,dayID);
	document.getElementById(astroID).selectedIndex = astroIndex;
}

function AstroChangeNew(monthID,dayID)
{
	var nowMonth=parseInt(document.getElementById(monthID).value);
	var nowDay=parseInt(document.getElementById(dayID).value);
	var astroTemp = nowMonth*100 +nowDay;
  var astroTime = [119,218,320,420,520,621,722,822,922,1022,1121,1221];

	for(var i=0;i<astroTime.length-1;i++)
	{
		if(astroTemp>astroTime[i] && astroTemp <=astroTime[i+1])
		{
			if((i+11)%12)
			{
				return (i+11)%12;
			}
			else
			{
				return 12;
			}
		}
	}
	return 10;
}

function displayElement(id)
{
	document.getElementById(id).style.display="";
}

function hiddenElement(id)
{
	document.getElementById(id).style.display="none";
}

function changeImg(id,imgId){
	var img_url = document.getElementById(id).value;

	if (img_url != undefined || img_url.trim() != '')
	{
		document.getElementById(imgId).src=img_url;
	}

}

String.prototype.lTrim=function () {
	return this.replace(/^\s*/, "");
}

String.prototype.rTrim=function () {
	return this.replace(/\s*$/, "");
}

String.prototype.trim=function () {
	return this.rTrim().lTrim();
}

//取得字符串实际长度(汉字算两个字节,英文字母算一个字节)
String.prototype.getLength=function()
{
	return this.replace(/[^\x00-\xff]/gi,'xx').length;
}

function qq_input(id,is_focus)
{
	var qq = document.getElementById(id);
	qq.value = qq.value.trim();
	if(is_focus){
		qq.value = "";
	}else{
		if(qq.value == "")
		{
			qq.value = "请输入QQ号码";
		}else{
				if(!c_qq(qq.value)){
					alert("QQ号码不正确");
			    qq.value = "请输入QQ号码";
				}
		}
	}
}

/**
 * 获取URL上的参数
 *
 * @return object
 */
function getArgs() {
    var args = new Object();
    var query = location.search.substring(1);
    var pairs = query.split("&");
    for(var i = 0; i < pairs.length; i++) {
	var pos = pairs[i].indexOf('=');
	if (pos == -1) continue;
	var argname = pairs[i].substring(0,pos);
	var value = pairs[i].substring(pos+1);
	args[argname] = unescape(value);
    }
    return args;
}

/**
 * 较验QQ码码
 *
 * @param qq mixed
 * @return bool
 * @deprecate use validateCommon.js
 */
function c_qq(qq)
{
	var reQQ= /^[1-9]\d{4,9}$/;
	return reQQ.test(qq);
}

/**
 * 把原图缩成新的大小
 *
 * 通常在onload事件中调用
 *
 * @param img Image
 * @param dst_w int
 * @param dst_h int
 */
function zoom_out(img,dst_w,dst_h)
{
	if(img.width <= dst_w && img.height <= dst_h)
	{
		return;
	}
	if(img.width*dst_h == img.height*dst_w)
	{
		img.height = dst_h;
		img.width = dst_w;
	}
	//过宽,定宽,变高
	else if( img.width*dst_h > img.height*dst_w)
	{
		img.height = parseInt(img.height * dst_w / img.width);
		img.width = dst_w;
	}
	//过高,定高,变宽
	else
	{
		img.width = parseInt (img.width * dst_h / img.height);
		img.height = dst_h;
	}
}

/**
 * 设置，更换验证码
 *
 * @param img_id string 图片的ID
 * @param input_id string 输入的ID
 *
 */
function verify_img(img_id,input_id)
{
	//新
	var img = document.getElementById(img_id);
	var change_input = !!img.src;
	img.src = "http://ptlogin2.qq.com/getimage?aid=15000103&"+new Date().getTime();
	if(change_input)
	{
		try{
			var el = document.getElementById(input_id);
			el.value="";
			el.focus();
		}catch(ex){}
	}
}

/**
 * 退出登录
 *
 * @param href, 退出后的地址, 默认为top.location.href
 * @param href, 指定窗口, 默认为top
 */
function logout(href, win)
{
	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 = "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";
	if( ! win)
	{
		win = top;
	}
	if( ! href)
	{
		href = top.location.href;
	}
	win.location.href=href;
}

/**
 * 关闭空间里的页面
 *
 */
function close_in_qzone()
{
	if(top.guide)
	{
		top.guide(1);	
	}
	else
	{
		window.close();
	}
}


function act_login(url, err_url, target, css_url, drag, fix, module)
{
	qq_login_form(15000103, url, err_url, target, css_url, drag, fix, module);
}
