﻿function dialog(){
	var titile = '';
	var width = 300;
	var height = 180;
	var src = "";
	var path = "/images/";
	var sFunc = '<input id="dialogOk" type="button" style="{width:62px;height:22px;border:0;background:url(\'/images/smb_btn_bg.gif\');line-height:20px;" value="确认" onclick="new dialog().reset();" /> <input id="dialogCancel" type="button" style="{width:62px;height:22px;border:0;background:url(\'/images/smb_btn_bg.gif\');line-height:20px;" value="取消" onclick="new dialog().reset();" />';
	var sClose = '<input type="image" id="dialogBoxClose" onclick="new dialog().reset();" src="' + path + 'dialogClose0.gif" border="0" width="17" height="17" onmouseover="this.src=\'' + path + 'dialogCloseF.gif\';" onmouseout="this.src=\'' + path + 'dialogClose0.gif\';" align="absmiddle" />';
	var sBody = '\
		<table id="dialogBodyBox" border="0" align="center" cellpadding="0" cellspacing="0">\
			<tr height="10"><td colspan="4"></td></tr>\
			<tr>\
				<td width="10"></td>\
				<td width="80" align="center" valign="absmiddle"><img id="dialogBoxFace" src="' + path + 'dialog3.gif" /></td>\
				<td id="dialogMsg" style="font-size:12px;"></td>\
				<td width="10"></td>\
			</tr>\
			<tr height="10"><td colspan="4" align="center"></td></tr>\
			<tr><td id="dialogFunc" colspan="4" align="center">' + sFunc + '</td></tr>\
			<tr height="10"><td colspan="4" align="center"></td></tr>\
		</table>\
	';
	var sBox = '\
		<table id="dialogBox" width="' + width + '" border="0" cellpadding="0" cellspacing="0" style="border:1px solid #888;display:none;z-index:10;">\
			<tr height="29">\
				<td style="background:url(/images/div_bg_r1_c3.gif) repeat-x #75B3E4;">\
					<table onselectstart="return false;" style="-moz-user-select:none;" width="100%" border="0" cellpadding="0" cellspacing="0">\
						<tr>\
							<td width="28" align=center><img src="/images/warning.gif" width="14" height="14" boder="0"></td>\
							<td id="dialogBoxTitle" onmousedown="new dialog().moveStart(event, \'dialogBox\')" style="color:#fff;cursor:move;font-size:14px;font-weight:bold;text-align:left;">&nbsp;</td>\
							<td id="dialogClose" width="25" align="right" valign="middle">\
								' + sClose + '\
							</td>\
							<td width="3"></td>\
						</tr>\
					</table>\
				</td>\
			</tr>\
			<tr id="dialogHeight" style="height:' + height + '">\
				<td id="dialogBody"  style="background-color:#ffffff; color:#000000"><font color="#000000">' + sBody + '</font></td>\
			</tr>\
		</table>\
		<div id="dialogBoxShadow" style="display:none;z-index:9;"></div>\
	';
	var sBG = '\
		<div id="dialogBoxBG" style="position:absolute;top:0px;left:0px;width:100%;height:100%;"></div>\
	';
	function $(_sId){return document.getElementById(_sId)}
	this.show = function(){
		this.shadow();
	}
	this.reset = function(){$('dialogBox').style.display='none';$('dialogBoxBG').style.display='none';$('dialogBoxShadow').style.display = "none";$('dialogBody').innerHTML = sBody;
    if($("testiframe"))
	 window.opener.location.href=window.opener.location.href;
	 
	}
	this.html = function(_sHtml){$("dialogBody").innerHTML = _sHtml;this.show();}
	this.init = function(){
		$('dialogCase') ? $('dialogCase').parentNode.removeChild($('dialogCase')) : function(){};
		var oDiv = document.createElement('div');
		oDiv.id = "dialogCase";
		oDiv.innerHTML = sBG + sBox;
		document.body.appendChild(oDiv);
		$('dialogBoxBG').style.height = document.body.scrollHeight;
	}
	this.button = function(_sId, _sFuc){
		if($(_sId)){
			$(_sId).style.display = '';
			if($(_sId).addEventListener){
				if($(_sId).act){$(_sId).removeEventListener('click', function(){eval($(_sId).act)}, false);}
				$(_sId).act = _sFuc;
				$(_sId).addEventListener('click', function(){eval(_sFuc)}, false);
			}else{
				if($(_sId).act){$(_sId).detachEvent('onclick', function(){eval($(_sId).act)});}
				$(_sId).act = _sFuc;
				$(_sId).attachEvent('onclick', function(){eval(_sFuc)});
			}
		}
	}
	this.shadow = function(){
		var oShadow = $('dialogBoxShadow');
		var oDialog = $('dialogBox');
		oShadow['style']['position'] = "absolute";
		oShadow['style']['background']	= "#444";
		oShadow['style']['display']	= "";
		oShadow['style']['opacity']	= "0.2";
		oShadow['style']['filter'] = "alpha(opacity=20)";
		oShadow['style']['top'] = oDialog.offsetTop + 2;
		oShadow['style']['left'] = oDialog.offsetLeft + 2;
		oShadow['style']['width'] = oDialog.offsetWidth;
		oShadow['style']['height'] = oDialog.offsetHeight;
	}
	this.open = function(_sUrl, _sMode){
		this.show();
		if(!_sMode || _sMode == "no" || _sMode == "yes"){
			$("dialogBody").innerHTML = "<iframe width='100%' id='testiframe' height='100%' src='" + _sUrl + "'    frameborder='0' scrolling='" + _sMode + "'></iframe>";
           $("testiframe").src=$("testiframe").src;
		}
		
	}
	this.showWindow = function(_sUrl, _iWidth, _iHeight, _sMode){
		var oWindow;
		var sLeft = (screen.width) ? (screen.width - _iWidth)/2 : 0;
		var iTop = -80 + (screen.height - _iHeight)/2;
		iTop = iTop > 0 ? iTop : (screen.height - _iHeight)/2;
		var sTop = (screen.height) ? iTop : 0;
		if(window.showModalDialog && _sMode == "m"){
			oWindow = window.showModalDialog(_sUrl,"","dialogWidth:" + _iWidth + "px;dialogheight:" + _iHeight + "px");
		} else {
			oWindow = window.open(_sUrl, '', 'height=' + _iHeight + ', width=' + _iWidth + ', top=' + sTop + ', left=' + sLeft + ', toolbar=no, menubar=no, scrollbars=' + _sMode + ', resizable=no,location=no, status=no');
			this.reset();
		}
	}
	this.event = function(_sMsg, _sOk, _sCancel, _sClose){
		$('dialogFunc').innerHTML = sFunc;
		$('dialogClose').innerHTML = sClose;
		$('dialogBodyBox') == null ? $('dialogBody').innerHTML = sBody : function(){};
		$('dialogMsg') ? $('dialogMsg').innerHTML = _sMsg  : function(){};
		_sOk && _sOk != "" ? this.button('dialogOk', _sOk) : $('dialogOk').style.display = 'none';
		_sCancel && _sCancel != "" ? this.button('dialogCancel', _sCancel) : $('dialogCancel').style.display = 'none';
		//_sOk ? this.button('dialogOk', _sOk) : _sOk == "" ? function(){} : $('dialogCancel').style.display = 'none';
		//_sCancel ? this.button('dialogCancel', _sCancel) : _sCancel == "" ? function(){} : $('dialogCancel').style.display = 'none';
		_sClose ? this.button('dialogBoxClose', _sClose) : function(){};
		this.show();
	}
	this.set = function(_oAttr, _sVal){
		var oShadow = $('dialogBoxShadow');
		var oDialog = $('dialogBox');
		var oHeight = $('dialogHeight');

		if(_sVal != ''){
			switch(_oAttr){
				case 'title':
					$('dialogBoxTitle').innerHTML = _sVal;
					title = _sVal;
					break;
				case 'width':
					oDialog['style']['width'] = _sVal;
					width = _sVal;
					break;
				case 'height':
					oHeight['style']['height'] = _sVal;
					height = _sVal;
					break;
				case 'src':
					if(parseInt(_sVal) > 0){
						$('dialogBoxFace') ? $('dialogBoxFace').src = path + 'dialog'+ _sVal + '.gif' : function(){};
					}else{
						$('dialogBoxFace') ? $('dialogBoxFace').src = _sVal : function(){};
					}
					src = _sVal;
					break;
			}
		}
		this.middle('dialogBox');
		oShadow['style']['top'] = oDialog.offsetTop + 2;
		oShadow['style']['left'] = oDialog.offsetLeft + 2;
		oShadow['style']['width'] = oDialog.offsetWidth;
		oShadow['style']['height'] = oDialog.offsetHeight;
	}
	this.moveStart = function (event, _sId){
		var oObj = $(_sId);
		oObj.onmousemove = mousemove;
		oObj.onmouseup = mouseup;
		oObj.setCapture ? oObj.setCapture() : function(){};
		oEvent = window.event ? window.event : event;
		var dragData = {x : oEvent.clientX, y : oEvent.clientY};
		var backData = {x : parseInt(oObj.style.top), y : parseInt(oObj.style.left)};
		function mousemove(){
			var oEvent = window.event ? window.event : event;
			var iLeft = oEvent.clientX - dragData["x"] + parseInt(oObj.style.left);
			var iTop = oEvent.clientY - dragData["y"] + parseInt(oObj.style.top);
			oObj.style.left = iLeft;
			oObj.style.top = iTop;
			$('dialogBoxShadow').style.left = iLeft + 2;
			$('dialogBoxShadow').style.top = iTop + 2;
			dragData = {x: oEvent.clientX, y: oEvent.clientY};
			
		}
		function mouseup(){
			var oEvent = window.event ? window.event : event;
			oObj.onmousemove = null;
			oObj.onmouseup = null;
			if(oEvent.clientX < 1 || oEvent.clientY < 1 || oEvent.clientX > document.body.clientWidth || oEvent.clientY > document.body.clientHeight){
				oObj.style.left = backData.y;
				oObj.style.top = backData.x;
				$('dialogBoxShadow').style.left = backData.y + 6;
				$('dialogBoxShadow').style.top = backData.x + 6; 
			}
			oObj.releaseCapture ? oObj.releaseCapture() : function(){};
		}
	}
	this.hideModule = function(_sType, _sDisplay){
		var aIframe = parent.document.getElementsByTagName("iframe");aIframe=0;
		var aType = document.getElementsByTagName(_sType);
		var iChildObj, iChildLen;
		for (var i = 0; i < aType.length; i++){
			aType[i].style.display	= _sDisplay;
		}
		for (var j = 0; j < aIframe.length; j++){
			iChildObj = document.frames ? document.frames[j] : aIframe[j].contentWindow;
			iChildLen = iChildObj.document.body.getElementsByTagName(_sType).length;
			for (var k = 0; k < iChildLen; k++){
				iChildObj.document.body.getElementsByTagName(_sType)[k].style.display = _sDisplay;
			}
		}
	}
	this.middle = function(_sId){
		var sClientWidth = parent ? parent.document.body.clientWidth : document.body.clientWidth;
		var sClientHeight = parent ? window.screen.height : document.body.clientHeight;
		var sScrollTop = parent ? parent.document.body.scrollTop : document.body.scrollTop;
		document.getElementById(_sId)['style']['display'] = '';
		document.getElementById(_sId)['style']['position'] = "absolute";
		document.getElementById(_sId)['style']['left'] = ((document.body.clientWidth / 2) - (document.getElementById(_sId).offsetWidth / 2))  +"px";
		var sTop = -160 + (sClientHeight / 2 + sScrollTop) - (document.getElementById(_sId).offsetHeight / 2);
		document.getElementById(_sId)['style']['top'] = sTop > 0 ? sTop +"px" : ((sClientHeight / 2 + sScrollTop) - (document.getElementById(_sId).offsetHeight / 2))  +"px";
	}
}

function _error_msg_show(msg, click, icon, title)
{
    click = click ? click : ' ';
    icon = icon ? icon : '';
    title = title ? title : '系统提示信息';

    switch (icon)
    {
    case 'forbid':
        icon = 1;
        break;

    case 'succ':
        icon = 2;
        break;

    case 'smile':
        icon = 3;
        break;

    case 'forget':
        icon = 4;
        break;

    case 'sorry':
        icon = 5;
        break;

    case 'care':
        icon = 6;
        break;

    case '':
        icon = 5;
        break;
    }

    dg=new dialog();
    dg.init();
    dg.set('src', icon);
    dg.set('title', title);
    dg.event(msg, click, '', click);
}

function _win_error_msg_show(msg, click, icon, top, left, width, height)
{
    click = click ? click : ' ';
    icon = icon ? icon : '';
    title = '系统提示信息';
    top = top ? top : 80;
    switch (icon)
    {
    case 'forbid':
        icon = 1;
        break;

    case 'succ':
        icon = 2;
        break;

    case 'smile':
        icon = 3;
        break;

    case 'forget':
        icon = 4;
        break;

    case 'sorry':
        icon = 5;
        break;

    case 'care':
        icon = 6;
        break;

    case '':
        icon = 5;
        break;
    }
    dg=new dialog();
    dg.init();

    dg.set('src', icon);

    dg.set('title', title);
	
    if (width)
    {
        dg.set('width', width);
    }
    if (height)
    {
        dg.set('height', height);
    }

    dg.event(msg, click, '', click);

	
    if (left)
    {
         document.getElementById('dialogBox')['style']['left'] = left;
         document.getElementById('dialogBoxShadow')['style']['left'] = left;
    }
    if (top)
    {
	 document.getElementById('dialogBox')['style']['top'] = top;
	 document.getElementById('dialogBoxShadow')['style']['top'] = top;
    }

}

function _confirm_msg_show(msg, click_ok, click_no, title)
{
    click_ok = click_ok ? click_ok : ' ';
    click_no = click_no ? click_no : ' ';
    title = title ? title : '系统提示信息';

    dg=new dialog();
    dg.init();
    dg.set('src', 3);	// smile
    dg.set('title', title);
    dg.event(msg, click_ok, click_no, click_no);
}

function _win_confirm_msg_show(msg, click_ok, click_no, top, left, width, height)
{
    click_ok = click_ok ? click_ok : ' ';
    click_no = click_no ? click_no : ' ';
    title = '系统提示信息';
    top = top ? top : 80;

    dg=new dialog();
    dg.init();
    dg.set('src', 3);   // smile
    dg.set('title', title);

    if (width)
    {
        dg.set('width', width);
    }
    if (height)
    {
        dg.set('height', height);
    }

    dg.event(msg, click_ok, click_no, click_no);

    if (left)
    {
         document.getElementById('dialogBox')['style']['left'] = left;
         document.getElementById('dialogBoxShadow')['style']['left'] = left;
    }
    if (top)
    {
         document.getElementById('dialogBox')['style']['top'] = top;
         document.getElementById('dialogBoxShadow')['style']['top'] = top;
    }
}


var mainrooturl = "http://www.buy007.com";
try { if (ShopMainHostUrl) mainrooturl = ShopMainHostUrl; } catch (e) { }

try {
    //购物车浮动显示
    $(document).ready(function() {
        $("#msgbox").hover(function() { }, function() { $("#msgbox").fadeOut('slow') });
     $("#msgbox1").hover(function() { }, function() { $("#msgbox1").fadeOut('slow') });
        var a = $('#right_button .s_btn2');
        var alink = $('#right_button .s_btn2 a').attr('href');
        a.bind("mouseover", function() { //绑定鼠标移上的事件
            try { //加载数据
                jQuery.getJSON('/NewMember/ShopCarJson.aspx?action=getcar&jsoncallback=?', null, function(a, data) { bindcar(a, data); }); //callback
            }
            catch (e) { } 
            $("#msgbox").show();    
            return false;
        }); //mouseover        
    });//ready
}
catch (e) { }

function bindcar(data) 
{
    if (data == null || data.length == 0) {
        $('#msg_page').html('<div class="nogoodsdata">您的购物车中暂无商品，赶快去选购吧！</div>'); 
        return false;
    }
    
    var car = [];
    var totalprice = 0;
    var totalcount =0;
    var more = '';
    var alink = $('#right_button .s_btn2 a').attr('href');
    car.push('<div class="MyCart_List"><ul>');
    $(data).each(function(i) {
        //GoodsID   GoodsTitle DiscountInfo PriceType UnitPrice pic OrderSize Quantity
    car.push('<li><dl><dt><a href="' + mainrooturl + '/show/' + this.GoodsID + '.html" target="_blank">');
    car.push('<img src="http://www.buy007.com/Files/GoodsImg/' + this.pic + '_mini.jpg" width="60" height="45" border="0" /></a></dt>');
    car.push('<dd class="p_Name"><a href="' + mainrooturl + '/show/' + this.GoodsID + '.html">' + this.GoodsTitle + '</a> <span style="color:#999999;">' + (this.OrderSize == "件" ? "" : ("(" + this.OrderSize + '码)')) + '</span></dd>');
        car.push('<dd class="p_Price"><strong>￥' + this.UnitPrice + '</strong> ×' + this.Quantity + '<br />');
        car.push('(' + this.DiscountInfo + '折)');
        car.push('</dd></dl></li>');

        totalprice += (parseInt(this.Quantity) * parseFloat(this.UnitPrice));
        totalcount+= parseInt(this.Quantity);
/*        if (i > 2) {
            more = '<a href="' + alink + '">更多</a>';
            return false;
        }*/
    });
    car.push('</ul></div>');
    
    $('#msg_page').html(
	'    <table id="msgtable" width="100%" border="0" cellpadding="0" cellspacing="0"><tr><td align="right" valign="top" colspan="3"><span id="close" onclick="$(\'#msgbox\').fadeOut(\'slow\');"><img src="/images/Bata/msgbox/close.gif" /></span></td></tr><tr><td colspan="3">' +
            car.join('') +
     '     </td><tr>' +
     '       <td height="35" align="right" valign="top" width="30">&nbsp;' + more + '</td>' +
     '       <td height="35" align="right" valign="middle">&nbsp;共<span class="redlight">' + totalcount + '</span>件商品，金额总计：<span class="redlight">' + parseFloat(totalprice).toFixed(2) + '</span>元 <span style="color:#999999;">(免运费)</span> <a href="' + $('#right_button .s_btn2 a').attr('href') + '"><img src="/images/Bata/msgbox/msgbox_linkbutton.gif" alt="确认去付款"  border="0" align="absmiddle" class="imga" /></a></td>' +
     '       <td height="35" align="right" valign="bottom">&nbsp;</td>' +
     '     </tr>' +
     '   </table>'); 
}

var oInputField;	//考虑到很多函数中都要使用
var oPopDiv;		//因此采用全局变量的形式
var oColorsUl;
var ajaxIndex=0;
function initVars(){

	//初始化变量
	oInputField = $("#SearchKey");	
	oKeywordUl = $("#keyword_ul");
	ajaxIndex=0;
}
function clearKeywords(){
	//清除提示内容
	oKeywordUl.empty();
	$("#msgbox1").hide();
	
}
function getObj(id) {
	if (document.getElementById) return document.getElementById(id);
	else if (document.all) return document.all[id];	
	else if (document.layers) return document.layers[id];
	else {return document.all[id];}
}
function movesugg(k){
		var list=getObj('keyword_ul');
	    if(list.cnt > 0){	
	    var o=$("#msgbox1");
		if(o && o.style.display!='block')o.style.display='block';
		var cur = (list==99)?-1:list.cur;
		if(k == 40)cur ++;
		if(k == 38)cur --;
		if(cur>list.cnt-1)cur = 0;
		else if(cur<0)cur = list.cnt-1;
		list.cur = cur;
		keyfocus(cur);
		 oInputField.val(list.childNodes[cur].word);	   
		
		return;
	}else{
		return;
	}		

}

function keyfocus(idx){
	var list=$("msg_page1");
	for(var j=0;j<list.childNodes.length;j++){
		list.childNodes[j].className = '';
	}
	if(typeof list.childNodes[idx] == 'object')
	list.childNodes[idx].className = 'mouseOver';
}

function getKeyWordList(oq) 
{  

initVars();		//初始化变量


if(oInputField.length > 0)
    {
       
  try { //加载数据

        c_url = '/Special/KeyWordAjax.aspx?format=text&keyword='; 
        var keywordvalue=encodeURI(oInputField.val());
        c_url += encodeURI(keywordvalue);     
        //注意是getJSON 哦
        $.getJSON(c_url,  null, function(a, KeyWordList) { bindKeyWord(a, KeyWordList); }); 
    
        }
        
  catch (e) { }
    }
  else
  {
  
  clearKeywords();	//无输入时清除提示框（例如用户按del键）
  }
   
}

function bindKeyWord(KeyWordList) 
{ 
	clearKeywords();	//每输入一个字母就先清除原先的提示，再继续	
	
      if (KeyWordList.length > 0) 
      {        
        $("#msgbox1").show(); 
        var KeyWordArray = []; 
        $(KeyWordList).each(function(i) {
        oKeywordUl.append($('<li><p style="width:180px;overflow:hidden;text-overflow:ellipsis; white-space:nowrap">' + this.KeyWord + '</p><span>约' + this.WordCount + '条</span></li>'));   
      }) ;
             
	    oKeywordUl.find("li").click(function(){
		    oInputField.val($(this).find("p").text());
		    document.forms[0].submit();
	
	    }).hover(
		function(){$(this).addClass("mouseOver");},
		function(){$(this).removeClass("mouseOver");}
	    ); 
       }               
           
}
$(function(){
		   //导航弹框控制
	$("#left_menu > div,#left_menu ul > div").hover(function(){$(this).addClass('div_hover');$(this).children("span").show();},function(){$(this).children("span").hide();$(this).removeClass('div_hover');});
	//我的账户弹框
    $(".button").after("<div id=\"showmyidpage\" style=\"display:none;\">"+
    "<ul>"+
	  "<li><a href=\"" + mainrooturl + "/Member/?loadpage=1\"><img src=\"/images/Bata/pic.gif\"/></a></li>" +
      "<li><a href=\"" + mainrooturl + "/Member/Default.aspx?loadpage=16\">我的积分</a></li>" +
	  "<li><a href=\"" + mainrooturl + "/Member/Default.aspx?loadpage=25\">我的现金券</a></li>" +
	  "<li><a href=\"" + mainrooturl + "/Member/Default.aspx?loadpage=6\">在线充值</a></li>" +
	  "<li><a href=\"" + mainrooturl + "/Member/Default.aspx?loadpage=8\">收货地址</a></li>" +
	  "<li><a href=\"" + mainrooturl + "/Member/Default.aspx?loadpage=19\">汇款通知单</a></li>" +
   " </ul>"+
  "</div>");
	$('#size_click_btn').click(function(){$('#size_change_page').show();});
	$('#close_sizepage').click(function(){$('#size_change_page').hide();});
	
	$(".button").mouseover(function(){$("#showmyidpage").show();});
	$("#showmyidpage").hover(function(){},
	
	function(){	
	$("#showmyidpage").fadeOut('fast');
	});
	//footer_show
	try
	{
				if($('#news td:first').text() == "")
				{
					$('#f_link').hide();
				}
	}
	catch (e) { }

});

