﻿function $(id){return document.getElementById?document.getElementById(id):null;}
function setHome(){try{window.external.AddFavorite(window.document.location,window.document.title)}catch(e){};}
function DeleteCookie( name, path, ec ) {
	var expdate = new Date(); 
	expdate.setTime(expdate.getTime() - (86400 * 1000 * 1)); 
	setCookie(name, "", expdate); 
}

function setCookie (name, value, expires) { 
	document.cookie = name + "=" + escape(value) + "; expires=" + expires.toGMTString()+ "; path=/"; 
} 


function GetCookie( name )
{
	var start = 0;
	var equal = document.cookie.indexOf('=', start);
	while(equal > start)
	{
		while(document.cookie.charAt(start) == ' ')
		start++;
		if(name == document.cookie.substring(start, equal))
		{
		var end = document.cookie.indexOf(';', equal);
		if(end == -1)
		end = document.cookie.length;
		if(end > equal)
		{
		return document.cookie.substring(equal+1, end);
		} 
		break;
		}
		else
		{
		var end = document.cookie.indexOf(';', equal);
		if(end > equal)
		{
		end++;
		while(document.cookie.charAt(end) == ' ')
		end++;
		start = end;
		equal = document.cookie.indexOf('=', start);
		}
		else break;
		}
	}
	return null;
}

/*-- 页楣 --*/
var islogin = false;
var userID = 0;
var userName = "";//用户名
var userEmail = "";
var usertype = 1;
var shopkey= 0 ;

var jifen = 0;
var shouyi = 0;
var cartcount = 0;
var menuitem = '';
var pageTab = 0;

var cartDate = '';
var cartID = '';
var cartcount = 0;

if(GetCookie('cartID')!=null){
    cartID = GetCookie('cartID');
    cartDate = GetCookie('cartDate');
    if(GetCookie('cartcount')!=null)
    cartcount = GetCookie( "cartcount" );
}
 
	 
if(GetCookie( "budingID" )!=null){
	userID = GetCookie( "budingID" );
	
	if(userID!=0){
	   
	    userName = GetCookie( "userName" );
	    userEmail = GetCookie( "userEmail" );
	    
	    usertype = GetCookie( "usertype" );
	    shopkey = GetCookie( "shopkey" );
	    
	    islogin=true;
	}
}

var userinfo = [
	["http://my.buding.com/", "个人中心"],
	["http://www.buding.com/cart/cart.htm", "购物车"],
	["http://www.buding.com/my/logout.aspx", "注销"]
];

var dspl = "visible";
var loginarea = '&nbsp;';
if(!islogin){
	dspl = "hidden";
	loginarea = '欢迎光临布丁网，您尚未[<a href="http://www.buding.com/my/login.htm" class="h_link">登陆</a>]或[<a href="http://www.buding.com/my/reg.htm"  class="h_link">注册</a>]';
}
else{
	loginarea = '您好, '+userName;
}

var navigation = [
	["50", "http://www.buding.com", "首页","a", "_self"],
	["78", "http://diy.buding.com", "自己定做","b", "_self"],
	["64", "http://www.buding.com/product/design_index.aspx", "找素材","c", "_self"],
	["64", "http://www.buding.com/product/index.aspx", "挑礼物","d", "_self"],
	["78", "http://yc.buding.com", "原创达人","e", "_self"],
	["78", "http://tuangou.buding.com/", "团队定制","f", "_self"],
	["50", "http://bbs.buding.com/", "论坛","g", "_blank"]
];
	
function inithead( cur ){

	var navigater = '';
	
	navigater += '<table width="100%" border="0" cellpadding="0" cellspacing="0" bgcolor="#FFFFFF" style="margin-bottom:10px;">\
			<tr>\
				<td height="22"></td>\
			</tr>\
			<tr>\
				<td height="36" align="center" valign="middle"><table width="905" height="36" border="0" align="center" cellpadding="0" cellspacing="0">\
						<tr>\
							<td width="12"><table width="12" border="0" cellspacing="0" cellpadding="0">\
									<tr>\
										<td width="12" height="13"></td>\
									</tr>\
									<tr>\
										<td height="9"><table width="12" height="9" border="0" cellpadding="0" cellspacing="0">\
												<tr>\
													<td width="3" height="9" background="http://www.buding.com/image/head/top_01.GIF"></td>\
													<td width="9" background="http://www.buding.com/image/head/top_03.gif"></td>\
												</tr>\
											</table>\
										</td>\
									</tr>\
									<tr>\
										<td height="14"></td>\
									</tr>\
								</table>\
							</td>\
							<td width="257" align="center" valign="middle"><a href="http://www.buding.com/"><img src="http://www.buding.com/image/head/logo.JPG" title="布丁网——个性礼品定制专家" width="247" height="36" /></a></td>\
							<td width="115"><table width="115" border="0" cellspacing="0" cellpadding="0">\
									<tr>\
										<td width="115" height="11"></td>\
									</tr>\
									<tr>\
										<td height="9"><table width="115" height="9" border="0" cellpadding="0" cellspacing="0">\
												<tr>\
													<td width="112" height="9" background="http://www.buding.com/image/head/top_03.GIF"></td>\
													<td width="3" background="http://www.buding.com/image/head/top_02.gif"></td>\
												</tr>\
											</table>\
										</td>\
									</tr>\
									<tr>\
										<td height="16"></td>\
									</tr>\
								</table>\
							</td>\
							<td width="15"></td>';
							
	if(islogin){
		navigater +=			 '<td width="375" align="left" valign="middle" class="ziti-12-song">您好, '+userName+'\
									<a class="hsb" href="'+userinfo[0][0]+'" target="_blank">'+userinfo[0][1]+'</a>\
									<a class="hsb" href="'+userinfo[1][0]+'" target="_blank">'+userinfo[1][1]+'</a>（<strong>'+cartcount+'</strong>）\
									<a class="hsb" href="'+userinfo[2][0]+'" target="_blank">'+userinfo[2][1]+'</a></td>';
	}else{
		navigater +=			 '<td width="375" align="left" valign="middle" class="ziti-12-song">欢迎光临布丁网，您尚未登陆，请\
									<a href="http://www.buding.com/my/login.htm"  target="_blank" class="hsb">登陆</a>\
									或\
									<a href="http://www.buding.com/my/reg.htm"    target="_blank" class="hsb">注册</a>\
									|\
									<a href="http://www.buding.com/cart/cart.htm"   target="_blank"  class="hsb">购物车</a>（<strong>'+cartcount+'</strong>）</td>';
	}
	navigater +=			 '<td width="131" align="right" valign="middle" class="ziti-12-song"><a class="hgray" target=_blank href="http://help.buding.com/">帮助</a> | <a class="hgray" onclick="setHome();" href="javascript:void(0);">收藏</a></td>\
						</tr>\
					</table>\
				</td>\
			</tr>\
			<tr>\
				<td height="12"></td>\
			</tr>\
			<tr>\
				<td height="53" align="center" valign="middle"><table width="905" height="53" border="0" align="center" cellpadding="0" cellspacing="0">\
						<tr>\
							<td width="3" height="53" background="http://www.buding.com/image/head/top_04.gif"></td>\
							<td width="899" background="http://www.buding.com/image/head/top_06.gif"><table width="899" height="53" border="0" cellpadding="0" cellspacing="0">\
									<tr>\
										<td height="12"></td>\
									</tr>\
									<tr>\
										<td height="27"><table width="899" height="27" border="0" cellpadding="0" cellspacing="0">\
												<tr>\
													<td width="3" height="27"></td>';

	for(var i=0; i<navigation.length; i++){
		navigater += '<td width="10"></td>';
		if(i==cur){
			navigater += '<td width="'+navigation[i][0]+'"><a href="'+navigation[i][1]+'" target="'+navigation[i][4]+'" onmouseover="changebgurl(this,2);" onmouseout="changebgurl(this,3);"><img src="http://www.buding.com/image/head/'+navigation[i][3]+'_03.gif" title="'+navigation[i][2]+'" width="'+navigation[i][0]+'" height="27" /></a></td>';
		}else{
			navigater += '<td width="'+navigation[i][0]+'"><a href="'+navigation[i][1]+'" target="'+navigation[i][4]+'" onmouseover="changebgurl(this,2);" onmouseout="changebgurl(this,1);"><img src="http://www.buding.com/image/head/'+navigation[i][3]+'_01.gif" title="'+navigation[i][2]+'" width="'+navigation[i][0]+'" height="27" /></a></td>';
		}
	}
	
	navigater += '									<td width="107"></td>\
													<td width="39" align="center" valign="middle"><img src="http://www.buding.com/image/head/top_07.jpg" title="客服电话" width="27" height="27" /></td>\
													<td width="206" align="center" valign="middle" class="ziti-12-song hSTYLE2">客户服务热线： \
														（010）67727277</td>\
												</tr>\
											</table>\
										</td>\
									</tr>\
									<tr>\
										<td height="14"></td>\
									</tr>\
								</table>\
							</td>\
							<td width="3" background="http://www.buding.com/image/head/top_05.gif"></td>\
						</tr>\
					</table>\
				</td>\
			</tr>\
		</table>';
	
	$('headarea').innerHTML = navigater;
}

function changebgurl( _obj, type ){
	var imgname = _obj.childNodes[0].src;
	var pos = imgname.lastIndexOf('/')+1;
	_obj.childNodes[0].src = "http://www.buding.com/image/head/"+imgname.substr(pos,3)+type+".gif";
}
