function AddFavority(title, url){ 
	if (document.all) 
		window.external.AddFavorite(url, title); 
	else if (window.sidebar) 
		window.sidebar.addPanel(title, url, "") 
} 

function AddBrowerIndexPage(url, obj){
	if( isIE ){
		obj.style.behavior = "url(#default#homepage)";
		obj.setHomePage(url);
	}else{
		var txt = "1. 将鼠标移至网址列后，拖曳网址列上的图片至浏览器\"房屋\"图示上.\n";
		txt += "2. 从弹跳的视窗中，选择 \"是\"\n";
		txt += "3. 恭喜，你已完成设定！";
		alert(txt);
	}
}  

function show_banner_ad(){
	if( typeof(M_BNR) == "undefined" ){
		return false;
	}
	var n, t, obj;
	if( M_BNR.length <= 0){
		return false;
	}
	for( var i=0; i < M_BNR.length; i++){
		n = M_BNR[i][0];
		obj = document.getElementById(n);
		if( obj ){
			if( i == M_now ){
				obj.style.display = "";
				t = M_BNR[i][1];
			}else{
				obj.style.display = "none";
			}
		}
	}
	if( t > 0 && M_BNR.length > 1){
		M_now ++;
		if( M_now >= M_BNR.length )
			M_now = 0;
		
		banner_timer = window.setTimeout('show_banner_ad()', t);
	}
}

function set_banner_ad(f){
	if( typeof(banner_timer) == "undefined"){
		banner_timer = false;
	}

	if( f < 0 ){
		if( M_now > 0 )
			M_now = M_now - 2;
		else
			M_now = (M_BNR.length - 2)
	}

	if( M_now < 0 )
		M_now = (M_BNR.length - 1 );

	window.clearTimeout(banner_timer);
	show_banner_ad();
}
/*
function stop_banner_ad(){
	if( typeof(banner_timer) == "undefined"){
		banner_timer = false;
	}
	if( banner_timer > 0 )
		window.clearTimeout(banner_timer);
}

function restart_banner_ad(){
	
}
*/
// ********** 启动店长推荐
var push_stop = false;
var push_now = 0;
function ProdPush_Play(){
	if( typeof(ProdHotImg) != "undefined" ){
		if( ProdHotImg.length > 0 ){

			if( push_now >= ProdHotImg.length ){
				push_now = 0;
			}
			var I,T;
			I = document.getElementById("PushImg");
			T = document.getElementById("PushTxt");

			I.innerHTML = ProdHotImg[push_now];
			T.innerHTML = ProdHotTxt[push_now];

			push_now ++;
			window.clearTimeout(push_stop);
			push_stop = window.setTimeout("ProdPush_Play()", 3000);
		}
	}
}
function DoStopPush(){
	window.clearTimeout(push_stop);
}
function DoStartPush(){
	window.clearTimeout(push_stop);
	push_stop = window.setTimeout("ProdPush_Play()", 1000);
}
function PushProd_Previous(){
	window.clearTimeout(push_stop);
	push_now -= 2;
	push_now = (push_now < 0)? (ProdHotImg.length -1) : push_now;
	ProdPush_Play();
}
function PushProd_Next(){
	window.clearTimeout(push_stop);
	ProdPush_Play();
}
// 启动店长推荐 ********** //


/* 打字跑马灯 */
function show_marquee(){
	if( typeof(mqTXT) == "undefined" ){
		return false;
	}
	if( mqTXT.length <= 0 ){
		return false;
	}

	var now = 0;
	marquee_write(now, 0);
}
function marquee_write(n, g){
	var move = ( typeof(mq_range) != "undefined" )? mq_range : 15;
	var delay = ( typeof(mq_speed) != "undefined" )? mq_speed : 300; 
	var area = document.getElementById("MarqueeArea");
	var obj = document.getElementById("MarqueeWrite");
	var max_width = area.offsetWidth;

	if(!obj) return false;

	if( typeof(mqflag) == "undefined" ){
		mqflag = true;
	}
	if( mqflag ){
		if( n >= mqTXT.length )
			n = 0;
		var info = mqTXT[n];
		var txt = info[0];

		if( info[3] != "" )
			color = "color:#" + info[3] + ";";
		else
			color = "color:normal;";

		if( info[4] != 0 )
			size = "font-size:" + info[4] + "pt;";
		else
			size = "font-size:normal;";

		txt = "<span style=\"" + color + size + "\">" + txt + "</span>";

		if( info[1] != "" ){
			var target = "";
			var color = "";
			var size = "";

			if(info[2] == 1 )
				target = "target='_blank'";

			if(txt != "" )
				txt = "<a href=\"" + info[1] + "\" " + target + ">" + txt + "</a>";
		}

		obj.innerHTML = txt;

		var now_position = (0 - obj.offsetWidth) + (g * move);
		obj.style.right = now_position + "px";
		if( now_position < (max_width) ){
			mqflag = setTimeout("marquee_write(" + n + ", " + (g+1) + ")", delay);
		}else{
			mqflag = setTimeout("marquee_write(" + (n+1) + ", 0)", (delay * 2) );
		}
	}else{
		setTimeout( function(){marquee_write(n, g);}, 10);
	}
}
function marquee_stop(){
	mqflag = false;
}
function marquee_start(){
	mqflag = true;
}

/* 登入 */
function CheckLogin(x){
	if( x.LoginName.value == '请输入帐号' || x.LoginName.value == '' ){
		alert('请输入帐号！');
		x.LoginName.value = '';
		x.LoginName.focus();
		return false;
	}
	if( x.LoginPass.value == '' ){
		alert('请输入密码！');
		x.LoginPass.style.display = '';
		x.tmp.style.display = 'none';
		x.LoginPass.focus();
		return false;
	}
	return true;
}


/* 产品分类开关 */
function SetClsChild(id){
	var obj = document.getElementById("ClsChild" + id);

	if( obj ){
		if( obj.style.display == "" ){
			obj.style.display = "none";
		}else{
			obj.style.display = "";
		}
	}
}


function WindowInnerHeight(){
	var viewportheight; 

	if (typeof window.innerWidth != 'undefined'){ 
		viewportheight = window.innerHeight 
	} 
	// IE6 in standards compliant mode (i.e. with a valid doctype as the first line in the document) 
	else if (typeof document.documentElement != 'undefined' 
		 && typeof document.documentElement.clientWidth != 
		 'undefined' && document.documentElement.clientWidth != 0) 
	{ 
		viewportheight = document.documentElement.clientHeight 
	} 

	// older versions of IE 

	else 
	{ 
		viewportheight = document.getElementsByTagName('body')[0].clientHeight 
	} 
	return viewportheight;
}


/**** 显示次选单 ****/
function display_menu(f){
	var menu = document.getElementById("menu1");
	if( f )
		menu.style.display = "block";
	else
		menu.style.display = "none";
}

/*********************************************************************************************************/
var NowDIV = new Array();
function MoveProdInfo(div, f){
	var max = eval("Max" + div);

	if( typeof( NowDIV[div] ) == "undefined" ){
		NowDIV[div] = 0;
	}

	if( f > 0 ){
		NowDIV[div]++;
	}else{
		NowDIV[div]--;
	}

	if( NowDIV[div] < 0 )
		NowDIV[div] = max-1;
	else if( NowDIV[div] >= max )
		NowDIV[div] = 0;

	if( max > 0){
		for(var i=0; i < max; i++){
			var obj = document.getElementById(div + i);
			if( NowDIV[div] == i )
				obj.style.display = "";
			else
				obj.style.display = "none";
		}
	}
}


/* 浮動廣告*/
function doFloatAD(source){
	var obj = document.getElementById(source);
	if( obj ){
		window.setInterval( function(){ FloatMenu(source); }, 1);
	}
}

var Xpos = 0;
var Ypos = 0;
var Ygravity = 0.85;
var scrollPos = 0;
var oldScrollPos = 0;
var Yboundary = 0;

function FloatMenu(source) {
	var fp = document.getElementById(source);

	docWidth = document.body.clientWidth; // Update document width
	docHeight = WindowInnerHeight(); // Update document height
	oldScrollPos = scrollPos;

	if( document.documentElement )
		scrollPos = document.documentElement.scrollTop; // Update scrollbar position
	else
		scrollPos = document.body.scrollTop;

	//Xpos = 764;
	if( docWidth > 1024 ){
		Xpos = (docWidth - fp.offsetWidth) - 10;
		Xpos = (docWidth / 2) + 460;
	}else
		Xpos = docWidth - fp.offsetWidth;

	Yboundary = ((scrollPos + docHeight) - fp.offsetHeight) - 100;

	if (fp.offsetTop < Yboundary - 1) // Object is behind boundary
	Ypos += 2;

	if (fp.offsetTop > Yboundary + 1) // Object is past boundary
	Ypos -= 1;

	Ypos *= Ygravity; // Slow object down

	fp.style.left = Xpos + "px";
	fp.style.top = parseInt( parseInt(fp.offsetTop, 10) + Ypos ) + "px";
}
