function $$$(o)
{
	return document.getElementById(o);
}
function hasSelectCheckBox(form) {
    var hasData = false;
    var len = form.elements.length;
    var elements = form.elements;
    for (var i=0;i<len;i++) {
        if (elements[i].type == 'checkbox' && elements[i].checked) {
            hasData = true;
            break;
        }
    }
    return hasData;
}
function checkallitem(e,itemName)
{
	var aa = document.getElementsByName( itemName );
	for (var i=0; i<aa.length; i++)
	aa[i].checked = e.checked;

}

function addToCart(gid)
{
	$.post('/cart/add',{'game_id':gid},function(data){
		var tmp=data.split('|||');
		alert(tmp[0]);
		$('#buy_'+tmp[2]).attr('src','/img/ordered.png');
		$('#u_cart_check').html(tmp[1]);
		$('#AddtoCartBtn1').val('已 加 入');
        $('#AddtoCartBtn2').val('已 加 入');
	})
}

function trash(gid)
{
	$.post('/cart/del',{'game_id':gid},function(data){
		alert(data);
		document.location="/cart/view";
	})
}


function gotocount()
{
	/*
	if(cart_fee < min_buy){
		alert(not_enought);
		return false;
	}else{
		//document.location="/cart/counter";
		if(cart_fee<sys_free_fee){
			var vstring=free_shipping_string+'<br/><button onclick="gobuy();" style="margin-right: 5px"><b style="color: #CC0000; font-family: Tahoma, Verdana">OK</b> 繼續選購</button><button onclick="gocount();"><b style="color: #008800; font-family: Tahoma, Verdana">NO</b> 直接結帳</button>';
			sAlert(vstring,'站長提示您！！',  180,300);
		}else
			document.location="/cart/pay";
	}
	*/
}
function gocount()
{
			document.location="/cart/pay";
}
function gobuy()
{
			document.location="/";
}

var bgObj=document.createElement("div");
var title=document.createElement("h4");
var msgObj=document.createElement("div")
var txt=document.createElement("p");


function sAlert(str,window_title,height,width,s_top,s_left){
	var msgw,msgh,bordercolor;
	msgw=typeof(width) == 'undefined' ? 400 : width;	//提示窗口的宽度
	msgh=typeof(height) == 'undefined' ? 150 : height;	//提示窗口的高度
	window_title=typeof(window_title) == 'undefined' ? '提示信息' : window_title;	
	titleheight="25px" //提示窗口标题高度
	title_size="15px"; //提示窗口标题高度
	bordercolor="#000000";//提示窗口的边框颜色
	titlecolor="#FFFFFF";//提示窗口的标题颜色
	titlebgcolor = "#486CAE";
	var sWidth,sHeight;
	sWidth=screen.width;
	sHeight=document.body.scrollHeight + screen.height;
	scroll_h =document.body.scrollTop;

	bgObj.setAttribute('id','bgDiv');
	bgObj.style.position="absolute";
	bgObj.style.top="0";
	bgObj.style.background="#cccccc";
	bgObj.style.filter="progid:DXImageTransform.Microsoft.Alpha(style=3,opacity=25,finishOpacity=75";
	bgObj.style.opacity="0.6";
	bgObj.style.left="0";
	bgObj.style.width=sWidth + "px";
	bgObj.style.height=sHeight + "px";
	bgObj.style.zIndex = "10000";
	document.body.appendChild(bgObj);

	msgObj.setAttribute("id","msgDiv");
	msgObj.setAttribute("align","center");
	msgObj.style.background="white";
	msgObj.style.border="1px solid " + bordercolor;
	msgObj.style.position = "absolute";
	msgObj.style.left = typeof(s_left) == 'undefined' ? "50%" : s_left+"px";
	msgObj.style.top = typeof(s_top) == 'undefined' ? (screen.height/2 - msgh/2) + 'px'  : s_top+"px";
	msgObj.style.font="12px/1.6em Verdana, Geneva, Arial, Helvetica, sans-serif";
	msgObj.style.marginLeft = "-225px" ;
	msgObj.style.marginTop = -75+document.documentElement.scrollTop+"px";
	msgObj.style.width = msgw + "px";
	msgObj.style.height =msgh + "px";
	msgObj.style.textAlign = "center";
	msgObj.style.lineHeight ="25px";
	msgObj.style.zIndex = "10001";

	title.setAttribute("id","msgTitle");
	title.setAttribute("align","center");
	title.style.margin="0";
	title.style.padding="3px";
	title.style.background=titlebgcolor;
	title.style.filter="progid:DXImageTransform.Microsoft.Alpha(startX=20, startY=20, finishX=100, finishY=100,style=1,opacity=75,finishOpacity=100);";
	title.style.opacity="0.75";
	title.style.height=titleheight;
	title.style.font=title_size+" Verdana, Geneva, Arial, Helvetica, sans-serif";
	title.style.color=titlecolor;
	title.style.cursor="pointer";
	title.innerHTML="<input type='image'  onclick='closeAlert();' src='/img/close.gif' title='Close' alt='[Close]' style='float:right;'/>&nbsp;&nbsp;&nbsp;"+window_title ;
	/*title.onclick=function(){
		document.body.removeChild(bgObj);
		document.getElementById("msgDiv").removeChild(title);
		document.getElementById("msgDiv").removeChild(txt);
		document.body.removeChild(msgObj);
	}*/

	document.body.appendChild(msgObj);
	document.getElementById("msgDiv").appendChild(title);
	txt.style.margin="1em 0";
	txt.style.padding ="20px";
	txt.setAttribute("id","msgTxt");
	txt.setAttribute('align','left');
	txt.innerHTML=str;
	document.getElementById("msgDiv").appendChild(txt);
}

function closeAlert()
{
	try
	{
		document.body.removeChild(bgObj);
		document.getElementById("msgDiv").removeChild(title);
		document.getElementById("msgDiv").removeChild(txt);
		document.body.removeChild(msgObj);
	}
	catch (e)
	{
	}
}



function initPopUp() {
	// Add the HTML to the body
	theBody = document.getElementsByTagName('BODY')[0];
	popmask = document.createElement('div');
	popmask.id = 'popupMask';
	popcont = document.createElement('div');
	popcont.id = 'popupContainer';
	popcont.innerHTML = '' +
		'<div id="popupInner">' +
			'<div id="popupTitleBar">' +
				'<div id="popupTitle">©±ªø´£¥Ü±z!!</div>' +
				'<div id="popupControls">' +
					'<img src="close.gif" onclick="hidePopWin(false);" id="popCloseBox" />' +
				'</div>' +
			'</div>' +
			'<iframe src="'+ gDefaultPage +'" style="width:100%;height:100%;background-color:transparent;" scrolling="auto" frameborder="0" allowtransparency="true" id="popupFrame" name="popupFrame" width="100%" height="100%"></iframe>' +
		'</div>';
	theBody.appendChild(popmask);
	theBody.appendChild(popcont);
	
	gPopupMask = document.getElementById("popupMask");
	gPopupContainer = document.getElementById("popupContainer");
	gPopFrame = document.getElementById("popupFrame");	
	
	// check to see if this is IE version 6 or lower. hide select boxes if so
	// maybe they'll fix this in version 7?
	var brsVersion = parseInt(window.navigator.appVersion.charAt(0), 10);
	if (brsVersion <= 6 && window.navigator.userAgent.indexOf("MSIE") > -1) {
		gHideSelects = true;
	}
	
	// Add onclick handlers to 'a' elements of class submodal or submodal-width-height
	var elms = document.getElementsByTagName('a');
	for (i = 0; i < elms.length; i++) {
		if (elms[i].className.indexOf("submodal") == 0) { 
			// var onclick = 'function (){showPopWin(\''+elms[i].href+'\','+width+', '+height+', null);return false;};';
			// elms[i].onclick = eval(onclick);
			elms[i].onclick = function(){
				// default width and height
				var width = 400;
				var height = 200;
				// Parse out optional width and height from className
				params = this.className.split('-');
				if (params.length == 3) {
					width = parseInt(params[1]);
					height = parseInt(params[2]);
				}
				showPopWin(this.href,width,height,null); return false;
			}
		}
	}
}

