﻿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 topfindType = 1;

function topFind(){

	var topfindLink = "";
	var key = $('topfindkey').value;
	
	switch(topfindType){
		case 1:
			topfindLink = "http://www.buding.com/product/0-a----0-"+key+"--"
		break;
		case 2:
			topfindLink = "http://www.buding.com/design/0-a----0-"+key+"--"
		break;
		case 3:
			topfindLink = "http://www.buding.com/designer/find.aspx?type=0&tvalue="+key;
		break;
		default:
			topfindLink = "http://www.buding.com/product/0-a----0-"+key+"--"
	}

	window.location.href = topfindLink;
}



function mousecover( obj, type )
{
	topfindType = type;
	
	for(var i = 1; i <=3; i++ )
	{
		var num = obj.id.substring(6,7);
		if( parseInt( num ) == i )
		{
			obj.className = "top-4F7409";
			obj.style.backgroundImage = "url('http://www.buding.com/image/head//t-f_31.gif')";
		}
		else
		{
			$('search'+i).className = "top-838383";
			$('search'+i).style.backgroundImage = "";
		}
	}
}

var userinfo = [
	["73px", "http://my.buding.com/", "t-f_05.gif", "个人中心"],
	["83px", "http://www.buding.com/cart/cart.htm", "t-f_07.gif", "我的购物车"],
	["73px", "http://my.buding.com/?op=13", "t-f_09.gif", "发布原创"],
	["73px", "http://my.buding.com/?op=20", "t-f_11.gif", "分享素材"]
];

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 = [
	["40px", "http://www.buding.com", "首页", "44"],
	["66px", "http://diy.buding.com", "产品列表", "46"],
	["66px", "http://yc.buding.com", "原创达人", "46"],
	["66px", "http://www.buding.com/product/index.aspx", "购买成品", "46"],
	["66px", "http://www.buding.com/product/design_index.aspx", "共享素材", "46"],
	["40px", "http://tuangou.buding.com/", "团购", "44"],
	["40px", "http://bbs.buding.com/", "社区", "44"]
];



	var userdiv = '<table width="100%" border="0" cellspacing="0" cellpadding="0">\
						<tr>\
							<td height="31" background="http://www.buding.com/image/head//t-f_02.gif">\
								<table width="905" height="19" border="0" align="center" cellpadding="0" cellspacing="0">\
									<tr>\
										<td>\
											<table width="100%" border="0" cellspacing="0" cellpadding="0" >\
												<tr>\
													<td width="280" class="top-danhang-zhong-fff">' +  loginarea + '</td>';
													
if(!islogin){
   userdiv += '<td style="width:6px"></td>';
		userdiv += '<td style="width:'+ userinfo[1][0]+';visibility:visible;" ><a href="' + userinfo[1][1] + '" target="_blank"><img src="http://www.buding.com/image/head//' + userinfo[1][2] + '"  height="19" alt="' + userinfo[1][3] + '" /></a></td>';
}
else{
	for( var i = 0; i < userinfo.length; i++ )
	{
		userdiv += '<td style="width:6px"></td>';
		userdiv += '<td style="width:'+ userinfo[i][0]+';visibility:visible;" ><a href="' + userinfo[i][1] + '" target="_blank"><img src="http://www.buding.com/image/head//' + userinfo[i][2] + '"  height="19" alt="' + userinfo[i][3] + '" /></a></td>';
	}
}

													
										
										userdiv += '<td width="6px"></td>\
													<td align="right" style="visibility:' + dspl + ';" class="top-danhang-zhong-fff"><a class="top-link" href="http://www.buding.com/my/logout.aspx">注销</a>&nbsp;&nbsp;</td><td width=80 align="right" class="top-danhang-zhong-fff"><a  class="top-link" target=_blank href="http://help.buding.com/" >帮助</a>&nbsp;&nbsp; <a href="javascript:void(0);" onclick="setHome();" class="top-link" >收藏</a></td>\
												</tr>\
											</table>\
										</td>\
									</tr>\
								</table>\
							</td>\
						</tr>\
					</table>';
					
	var body = '<table width="905" border="0" align="center" cellpadding="0" cellspacing="0">\
					<tr>\
						<td height="5"></td>\
					</tr>\
					<tr>\
						<td height="83">\
							<table width="905" height="83" border="0" cellpadding="0" cellspacing="0">\
								<tr>\
									<td width="4" background="http://www.buding.com/image/head//t-f_19.gif"></td>\
									<td width="897">\
										<table width="897" border="0" cellspacing="0" cellpadding="0">\
											<tr>\
												<td height="13" background="http://www.buding.com/image/head//t-f_20.gif"></td>\
											</tr>\
											<tr>\
												<td height="70">\
													<table width="897" height="70" border="0" cellpadding="0" cellspacing="0">\
														<tr>\
															<td width="402"><a href="http://www.buding.com" target="_self"><img src="http://www.buding.com/image/head/t-f_25.gif" width="402" height="70" alt="布丁网 个性化定制专家" /></a></td>\
															<td width="269" height="70" background="http://www.buding.com/image/head//t-f_26.gif"></td>\
															<td width="214">\
																<table width="214" border="0" cellspacing="0" cellpadding="0">\
																	<tr>\
																		<td height="60" background="http://www.buding.com/image/head//t-f_27.gif">\
																			<table width="202" border="0" align="center" cellpadding="0" cellspacing="0">\
																				<tr>\
																					<td height="8"></td>\
																				</tr>\
																				<tr>\
																					<td height="17">\
																						<table height="17" border="0" cellpadding="0" cellspacing="0">\
																							<tr>\
																								<td onclick="mousecover(this, 1);" style="cursor:pointer;" id=search1 width="31" align="center" valign="bottom" class="top-838383">成品</td>\
																								<td width="10" align="center"></td>\
																								<td onclick="mousecover(this, 2);" style="cursor:pointer;" id=search2 width="31" align="center" valign="bottom" class="top-838383">素材</td>\
																								<td width="10" align="center" valign="bottom"></td>\
																								<td onclick="mousecover(this, 3);" style="cursor:pointer;" id=search3 width="31" align="center" valign="bottom" class="top-838383">作者</td>\
																							</tr>\
																						</table>\
																					</td>\
																				</tr>\
																				<tr>\
																					<td height="4"></td>\
																				</tr>\
																				<tr>\
																					<td height="21" align="left" style="padding-left:2px;width:100%;"><input id=topfindkey type=text style="border:1px solid #4F7409;width:138px;height:21px!important;height:21px;border-right:0px;"><input type=button value=" " onclick="topFind();" style="position:relative;top:1px!important;top:0px;width:60px;height:21px;border:0px;background:url(http://www.buding.com/image/head//t-f_35-2.jpg);" onmousedown="this.style.background=\'url(http://www.buding.com/image/head//t-f_35.gif)\'" onmouseup="this.style.background=\'url(http://www.buding.com/image/head//t-f_35-2.jpg)\'"></td>\
																				</tr>\
																				<tr>\
																					<td height="5"></td>\
																				</tr>\
																			</table>\
																		</td>\
																	</tr>\
																	<tr>\
																		<td height="10" background="http://www.buding.com/image/head//t-f_34.gif"></td>\
																	</tr>\
																</table>\
															</td>\
															<td width="12" background="http://www.buding.com/image/head//t-f_29.gif"></td>\
														</tr>\
													</table>\
												</td>\
											</tr>\
										</table>\
									</td>\
									<td width="4" background="http://www.buding.com/image/head//t-f_23.gif"></td>\
								</tr>\
							</table>\
						</td>\
					</tr>\
				</table>';
				
						
function inithead( cur, htype ){

	var type = (htype)?htype:'1'; //1有body 2 无  3 无
	
	var navigater = '';
	
	if(type==3)
	navigater += '<div class=pnav>'
	
	navigater += '<table width="905" height="30" border="0" align="center" cellpadding="0" cellspacing="0">\
						<tr>\
							<td width="4" background="http://www.buding.com/image/head//t-f_l_'+type+'.gif"></td>\
							<td width="897" valign="middle" background="http://www.buding.com/image/head//t-f_40.gif">\
								<table height="21" border="0" cellpadding="0" cellspacing="0">\
									<tr>';
									
									for(var j = 0; j < navigation.length; j++ ){
										navigater += '<td width="13">&nbsp;</td>';
										if( (j+1) == cur ){
											navigater += '<td width="' + navigation[j][0] + '" style="padding-top:5px;text-align:center;" background="http://www.buding.com/image/head/t-f_'+ navigation[j][3] +'.gif" class="top-14-ff-b">' + navigation[j][2] + '</td>';
										}
										else{
											if(j==6){
												navigater += '<td width="' + navigation[j][0] + '" style="padding-top:5px;"><a class="greenA" href="' + navigation[j][1] + '" target="_blank">' + navigation[j][2] + '</a></td>';
											}
											else{
												navigater += '<td width="' + navigation[j][0] + '" style="padding-top:5px;"><a class="greenA" href="' + navigation[j][1] + '">' + navigation[j][2] + '</a></td>';
											}
											
										}
									}
									navigater += '<td>&nbsp;</td>';
									
						navigater += '</tr>\
								</table>\
							</td>\
							<td width="4" background="http://www.buding.com/image/head//t-f_r_'+type+'.gif"></td>\
						</tr>\
					</table>';
	
	
	if(type==3)
		navigater += '</div>'
	
	if(type==1){
		$('headarea').innerHTML = userdiv + body + navigater;
		mousecover( $('search1') );
	}
	else if(type==2||type==3){
		$('headarea').innerHTML = userdiv + navigater;
	}
	else if(type==4){
		$('headarea').innerHTML = userdiv;
	}
	
}

