function updatechannel(id,rid) {
    for(i=0;i<=14;i++)
	{
	    var clear = 'search'+i;
		if(document.getElementById(clear) == null)
			continue;

		if(i == id)
			document.getElementById(clear).className = "tag now";
		else
			document.getElementById(clear).className = "tag";
	}
    document.getElementById('channel').value = rid;
    if(id == 0){
    	document.getElementById('searchform').action = 'http://search.mamasgoodbaby.com/search.shtml';
    }else{
    	document.getElementById('searchform').action = 'http://search.goodbaby.com/search.shtml';
    }
}

//search change
function search_morechange(obj,hid,changedid)
{
	var changetext = document.getElementById('search'+changedid).innerHTML;
	document.getElementById('search'+changedid).innerHTML = obj.innerHTML;
	obj.innerHTML = changetext;
	document.getElementById('search_more0').style.display = 'none';
	var changevalue = document.getElementById(hid).value;
	document.getElementById(hid).value = document.getElementById('hid'+changedid).value;
	document.getElementById('hid'+changedid).value = changevalue;
	updatechannel(changedid,changevalue);
}

//new search
function gb_common_search_select(){
	var sflist = document.getElementById('selectfocuslist');
	var select1 = document.getElementById('searchselect1');

	if(sflist.style.display == 'none') {
		sflist.style.display = '';
		select1.className = 'selcetop focus';
	} else {
		sflist.style.display = 'none';
		select1.className = 'selcetop';
	}
}

//new search list
function gb_common_search_list(obj,curid){
	var channel = document.getElementById('channel');
	var select = document.getElementById('searchselect');
	var select2 = document.getElementById('searchselect2');

	channel.value = curid;
	var changevalue = select2.innerHTML;
	select.innerHTML = obj.innerHTML;
	select2.innerHTML = obj.parentNode.innerHTML;
	obj.parentNode.innerHTML = changevalue;
	gb_common_search_select();
}
//new search from check
function gb_common_searchchk(keydefault) {
	var channelv = document.getElementById('channel').value;
	if(document.getElementById('keyword_gbk') != null) {
		document.getElementById('keyword_gbk').value = document.getElementById('keyword_gbk').value.Trim();
		if(document.getElementById('keyword_gbk').value == '' || document.getElementById('keyword_gbk').value == keydefault) {
			//location.href = 'http://search.goodbaby.com/index.jsp?channel='+channelv;
			return false;
		} else {
			document.getElementById('keyword').value = encodeURIComponent(document.getElementById('keyword_gbk').value);
			return true;
		}
	}
	document.getElementById('keyword').value = document.getElementById('keyword').value.Trim();
	if(document.getElementById('keyword').value == '' || document.getElementById('keyword').value == keydefault) {
		//location.href = 'http://search.goodbaby.com/index.jsp?channel='+channelv;
		return false;
	} else {
		return true;
	}
}
// ten years daojishi
function ten_years_djs(){
	var current_date = Date.parse(new Date().getFullYear()+'/'+(new Date().getMonth()+1)+'/'+new Date().getDate());
	if(current_date>=Date.parse('2009/12/10')) {
		var ceildays=Math.ceil((parseInt(new Date(2010,06,19,0,0,0).getTime())-parseInt(new Date().getTime()))/(24*3600000));
		if(ceildays>0 && current_date>=Date.parse('2009/7/19')) {ceildays = '<div class="yeardate"><a href="http://event.goodbaby.com/201003/zhuanjia/index.php" target="_blank"><b>'+ceildays+'</b></a></div>';document.write(ceildays);}
	} else {
		var ceildays=Math.ceil((parseInt(new Date(2009,11,10,0,0,0).getTime())-parseInt(new Date().getTime()))/(24*3600000));
		if(ceildays>0 && current_date>=Date.parse('2009/7/19')) {ceildays = '<div class="yeardate20"><b>'+ceildays+'</b></div>';document.write(ceildays);}
	}
}
//obj show or unshow
function obj_show(obj)
{
	var showobj =  document.getElementById(obj);
	if(showobj.style.display == '')
		showobj.style.display = 'none';
	else
		showobj.style.display = '';
}

function MM_jumpMenu(targ,selObj,restore){ //v3.0
	window.open(selObj.options[selObj.selectedIndex].value,targ,"")
  if (restore) selObj.selectedIndex=0;
}
//main_menu change
function indexmenu_display(obj,num,menu_baby)
{
		if(menu_baby == '')
		{
			document.getElementById('yuerbaike').style.display = 'none';
			document.getElementById('yuershequ').style.display = 'none';
		}
		else if(menu_baby == 'yuerbaike')
		{
			document.getElementById(menu_baby).style.display = '';
			document.getElementById('yuershequ').style.display = 'none';
		}
		else
		{
			document.getElementById('yuerbaike').style.display = 'none';
			document.getElementById(menu_baby).style.display = '';
		}
}

//xmlhttp object
function initxmlhttp()
{
	var xmlhttp;
	if(window.XMLHttpRequest){
		xmlhttp= new XMLHttpRequest();
	}else if(window.ActiveXObject){
		try{
			xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
		}catch(e){
			try{
				xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
			}catch(e){
				xmlhttp=false;
			}
		}
	}
  return xmlhttp;
}

var host_name = window.location.hostname;

//list param to htmlcode
function readcontent(catid,secid,count,contentstr,action,url,mid)
{
  var xmlhttp=initxmlhttp();
  var showcontent=document.getElementById(contentstr);
  var url="http://" + host_name + "/common/lib/ajax_cms_content.php?catid="+catid+"&secid="+secid+"&count="+count+"&action="+action+"&url="+encodeURI(url)+"&mid="+mid;
  xmlhttp.open("GET",url,true);
  xmlhttp.setRequestHeader("Cache-Control","no-cache,must-revalidate");
  xmlhttp.setRequestHeader("If-Modified-Since","0");
  xmlhttp.onreadystatechange=function(){
		if(xmlhttp.readyState==4 && xmlhttp.status==200)
		{
			showcontent.innerHTML=xmlhttp.responseText;
		}
	}
  xmlhttp.send(null);
}

function loadcommon()
{
	window.setTimeout('',10);
	if(document.cookie.indexOf("goodbabyuumsid=") != -1)
	{
		if(document.getElementById('logindiv') != null)
			readcontent('','','','logindiv','login','','');
		//if(document.getElementById('yershequ') != null)
			//readcontent('','','','yuershequ','yuershequ','','');
		if(document.getElementById('myspace') != null)
			readcontent('','','','myspace','myspace','','');
		if(document.getElementById('mybbs') != null)
			readcontent('','','','mybbs','mybbs','','');
		if(document.getElementById('my2hand') != null)
			readcontent('','','','my2hand','my2hand','','');
		if(document.getElementById('myask') != null)
			readcontent('','','','myask','myask','','');
		if(document.getElementById('combbs') != null)
			readcontent('','','','combbs','combbs','','');
		if(document.getElementById('comblog') != null)
			readcontent('','','','comblog','comblog','','');
		if(document.getElementById('comqinzi') != null )
			readcontent('','','','comqinzi','comqinzi','','');
		if(document.getElementById('comershou') != null)
			readcontent('','','','comershou','comershou','','');
		if(document.getElementById('comask') != null)
			readcontent('','','','comask','comask','','');
	}

	if(document.getElementById('left_adv1') != null && document.getElementById('left_adv2') != null && document.getElementById('left_adv3') != null && host_name == 'www.goodbaby.com')
		window.setInterval(changeImg,3000);
        
    if(document.getElementById('topwebsite2') != null) {
        document.getElementById('topwebsite2').onmouseout = function(){
            gb_topwebsite_mouseevent('none');
        };
        document.getElementById('topwebsite2').onmouseover = function(){
            gb_topwebsite_mouseevent('');
        };
    }
    if(document.getElementById('topwebsite0') != null) {
        document.getElementById('topwebsite0').onclick = function(){
            gb_topwebsite_fun();
        }
    }
}

function blog_searchchk(obj) {
	obj.keyword.value = encodeURIComponent(obj.keyword_gbk.value);
	return true;
}

String.prototype.Trim = function()
{
    return this.replace(/(^\s*)|(\s*$)/g, "");
}
//去左空格
String.prototype.LTrim = function()
{
    return this.replace(/(^\s*)/g, "");
}
//去右空格
String.prototype.RTrim = function()
{
    return this.replace(/(\s*$)/g, "");
}

function gb_topwebsite_fun() {
    var gb_topwebsite1 = document.getElementById('topwebsite1');
    if(gb_topwebsite1.style.display == 'none') {
        gb_topwebsite_mouseevent('');
    } else {
        gb_topwebsite_mouseevent('none');
    }
}

function gb_topwebsite_mouseevent(value){
    document.getElementById('topwebsite2').style.display = value;
    document.getElementById('topwebsite1').style.display = value;
}
