// JavaScript Document
//判断用户是否已经登录
var isLogin = 0;//=1时，用户已经登录；=0时，用户未登录
function checkUserLogined(){
  if(document.cookie.length > 0)
  { 
	//alert(document.cookie);
	var cookieString = document.cookie;
	var cookieName='cookie_userid';
	start = cookieString.indexOf(cookieName+'=');
    if (start != -1)
    {
	  start += cookieName.length + 1;
	  var end = cookieString.indexOf(';',start);
	  if (end == -1){
		  //alert(cookieString.substring(start));
		  return unescape(cookieString.substring(start));
	  }
	  else{
		  return unescape(cookieString.substring(start,end));
	  }
    }
  }
  else{
  	return null;
  }
}

//产品库页面头（登录）
function LoginDiv(){
	var userName = '';
	if(isLogin==0){
		userName = checkUserLogined();
	}
	if(userName!='' && userName!=null){
		isLogin = 1;
	}
	if(isLogin==1){//已经登录
		document.getElementById('user_login_div').innerHTML = '	&nbsp; 欢迎访问MyPrice价格网，'+userName+'：<a href="http://login.myprice.com.cn/index.php?con_param=login_succeed"><span class="c03c">我的通行证</span></a>&nbsp; <a href="http://login.myprice.com.cn/index.php?con_param=logout" class="one5">退出</a>';
	}
	else{//未登录
		document.getElementById('user_login_div').innerHTML = '<span class="c03c">通行证</span>'+
		'	用户名：<input type="text" name="userid" size="11" />&nbsp;'+
		'	密码：<input type="password" name="password" size="11" />&nbsp'+
		'	<input name="提交" type="submit" class="log" value="" />'+
		'	<a href="http://login.myprice.com.cn/index.php?con_param=item" target=_blank><input type="button" value="" class="reg" onclick="location.href=\'http://login.myprice.com.cn/index.php?con_param=item\'"></a>';
	}
}

//显示“我的MyPrice”div
function selfService(){
	var userName = '';
	if(isLogin==0){
		userName = checkUserLogined();
	}
	if(userName!='' && userName!=null){
		isLogin = 1;
	}
	if(isLogin==1){//已经登录
		document.getElementById('myself_tip').innerHTML = '<div class="div1"><a href="http://login.myprice.com.cn/index.php?con_param=login_succeed">个性IT</a><a href="http://login.myprice.com.cn/index.php?con_param=favorite_product">点击查看</a>&nbsp;<img align="absmiddle" src="images/icon35.gif" />			</div><div class="tc"><img class="img1" src="images/icon34.gif" width="33" height="31" />			</div><p class="tc black">欢迎登录Myprice通行证			</p><p class="div2"><a href="http://login.myprice.com.cn/index.php?con_param=price_alert">·产品收藏、价格提醒</a><br /><a href="http://login.myprice.com.cn/index.php?con_param=user_comments">·专业IT问答平台服务</a><br /><a href="http://flea.myprice.com.cn/user_secondhand.php">·二手产品发布</a>			</p><div class="tc"><a href="http://login.myprice.com.cn/index.php?con_param=login_succeed" class="button06" >我的通行证</a></div>';
	}
	else{//未登录
		document.getElementById('myself_tip').innerHTML = '<div class="div1"><a href="http://login.myprice.com.cn/index.php?con_param=login_succeed">个性IT</a><a href="http://login.myprice.com.cn/index.php?con_param=favorite_product">点击查看</a>&nbsp;<img align="absmiddle" src="images/icon35.gif" />			</div><div class="tc"><img class="img1" src="images/icon34.gif" width="33" height="31" />			</div><p class="tc black">注册Myprice通行证<br />立即拥有个性IT生活		</p><p class="div2"><a href="http://login.myprice.com.cn/index.php?con_param=price_alert">·产品收藏、价格提醒</a><br /><a href="http://login.myprice.com.cn/index.php?con_param=user_comments">·专业IT问答平台服务</a><br /><a href="http://flea.myprice.com.cn/">·二手产品发布</a>			</p><div class="tc"><a href="http://login.myprice.com.cn/index.php?con_param=login_succeed" class="button06" >更多精彩，点击查看</a></div>';
	}
}

//时间延迟隐藏div
var tim = null;
function hidden_div(divId,interval_time){
	if(interval_time==null || interval_time==''){
		interval_time = 500;//毫秒
	}
	if(document.getElementById(divId).style.display=='block'){
		tim = setTimeout("clear_hidden_time('"+divId+"')",interval_time);
	}
	return false;
}

function clear_hidden_time(divId){
	hidden(divId);
	window.clearTimeout(tim);
	tim = null;
}

//显示MyPrice通行证
function display_myself_div(divId){
	if(tim!=null){
		window.clearTimeout(tim);
		tim = null;
	}
	if(document.getElementById(divId).style.display=='none'){
		selfService();
		display(divId);
	}
}

/*
 * 显示隐藏指定的div
 * contentFun 为装填div内容的函数名
*/
function display(divId){
	document.getElementById(divId).style.visibility = 'visible';
	document.getElementById(divId).style.display = 'block';
}
function hidden(divId){
	document.getElementById(divId).style.visibility = 'hidden';
	document.getElementById(divId).style.display = 'none';
}

function updateseccode(width, height) {
	$('seccodeimage').innerHTML = '<img id="seccode" onclick="updateseccode(' + width + ', '+ height + ')" width="' + width + '" height="' + height + '" src="seccode.php?update=' + Math.random() + '" class="absmiddle" alt="" />';
}
//获取当前时间
function date_day(){

	TD=new Date();

	date=TD.getDate();

	month=TD.getMonth()+1;

	year=TD.getYear();

	document.write(year);

	document.write("年");

	document.write(month);

	document.write("月");

	document.write(date);

	document.write("日");

}

function display_string(dot_str,source){
	document.getElementById(dot_str).style.display = 'block';
	document.getElementById(dot_str).style.visibility = 'visible';
	if(document.getElementById(source)!=null && document.getElementById(source)!='undefinde'){
		document.getElementById(dot_str).innerHTML = document.getElementById(source).innerHTML;
	}
	return false;
}
function updateseccode(seccodeimage,width, height) {
	document.getElementById(seccodeimage).innerHTML = '<img id="seccode" onclick="updateseccode(\''+seccodeimage+'\',' + width + ', '+ height + ')" width="' + width + '" height="' + height + '" src="display_verify_code.php?act=' + Math.random() + '" class="absmiddle" alt="" />';
}
//判断用户是否已经登录
//登录返回用户名否则返回null
function user_login_check_null(){
  if(document.cookie.length > 0)
  { 
	//alert(document.cookie);
	var cookieString = document.cookie;
	var cookieName='cookie_userid';
	start = cookieString.indexOf(cookieName+'=');
    if (start != -1)
    {
	  start += cookieName.length + 1;
	  var end = cookieString.indexOf(';',start);
	  if (end == -1){
		  //alert(cookieString.substring(start));
		  return unescape(cookieString.substring(start));
	  }
	  else{
		  return unescape(cookieString.substring(start,end));
	  }
    }
  }
  else{
  	return null;
  }
}
arr_category_id =new Array();


function subcategory_by_category(dot_str,source,category_id,category_str_id){
	if(category_str_id==null){
		category_str_id = 'category_dot_div_';
	}
	if(arr_category_id.length!=null && arr_category_id.length>1){
		for(i=0;i<arr_category_id.length;i++){
			if(arr_category_id[i]!=category_id){
				if(i==0){
					document.getElementById(category_str_id+'_'+arr_category_id[i]).className = 'one2';
				}
				else{
					document.getElementById(category_str_id+'_'+arr_category_id[i]).className = 'one';
				}
			}
			else{
				document.getElementById(category_str_id+'_'+arr_category_id[i]).className = 'here';
				display_string(dot_str,source+'_'+category_id);
			}
		}
	}
	return false;
}



function ScrollableList(elementID) {

  this.elementID = elementID;
  this.scrollableArea = document.getElementById(elementID);
  
  this.time = 0;
  this.distance = 44;
  this.timeHandle = 0;
  this.isNext = true;
	
  this.left = 0;
  this.left2 = 880;
	this.obj = elementID + "Object";
	eval(this.obj + "=this");

 this.set_back = function() {
	this.isNext = false;
	this.left = -880;
	this.left2 = 0;
 }
 
 this.set_next = function() {
	this.isNext = false;
	this.left = -880;
	this.left2 = 0;
 }
  
 this.toggle = function() {
		if(this.isNext == true){
			this.move('next');
		}
		else{
			this.move('back');
		}
		return false;
  }
  
  this.move = function() {
		if(this.isNext == true){//下一组产品导航
			this.scrollNext();
		}
		else{//上一组产品导航
			this.scrollBack();
		}
  }
  
	this.scrollNext = function ()
	{
		if (this.keepScrolling()) {
			this.left -= this.distance;
			this.left2 -= this.distance;
			this.scrollableArea.style.marginLeft = this.left + "px";
			this.timeHandle = setTimeout(this.obj + '.scrollNext()',this.time);
		} else {
			this.isNext = false;
			clearTimeout(this.timeHandle);
		}
	}
	
	this.scrollBack = function ()
	{
		if (this.keepScrolling()) {
			this.left += this.distance;
			this.left2 += this.distance;
			this.scrollableArea.style.marginLeft = this.left + "px";
			this.timeHandle = setTimeout(this.obj + '.scrollBack()',this.time);
		} else {
			this.isNext = true;
			clearTimeout(this.timeHandle);
		}
	}
	
	/**
	 * returns true if we should continue to scroll the nav bar
	 */
	this.keepScrolling = function() {
		if (this.isNext == true) {			//scrolling left
			if (this.left2 <= 0)
				return false;
		} else {							//scrolling right
			if (this.left >=0)
				return false;
		}
		return true;
	}
	
}