/*
	文件名：	shoppingcart.js
	说明：		购物车javascript函数集

*/

//构建隐藏页框
document.write("<iframe src='about:blank' name='shoppingcartframe' id='shoppingcartframe' style='display:none'></iframe>");


/*
	添加到购物车
*/
function new_cart( bid,url,sub )
{
	if( typeof(url)=="undefined" )
	{
		url=2;
	}
	if( typeof(sub)=="undefined" )
	{
		sub='b';
	}

	tttt	= document.createElement('DIV');
	tttt.style.cssText 	= "display:none;width:400px;height:200px;border:1px solid #6666cc;position:absolute;padding:0";
	document.body.appendChild(tttt);

	tttt.style.left=document.documentElement.scrollLeft+document.documentElement.clientWidth+300;
	
	if( event.clientY<600 )
	{
		tttt.style.top=300
	}
	else if( document.documentElement.clientHeight-event.clientY )
	{
		tttt.style.top=document.documentElement.clientHeight;
	}
	else
	{
		tttt.style.top=event.clientY-600;
	}
	
	tttt.style.display="";
	html		= "<table width='100%' border='0' cellpadding='0' cellspacing='0' style='border:1px outset' bgcolor='#ffffff'>";
	html		+= "<tr height='25'><td bgcolor='#6666cc' style='color:white'>";
	html		+= "　　☆&nbsp;Please fill it into the cart!";
	html		+= "</td><td align='right' bgcolor='#6666cc' style='color:white'>";
	html		+= "<a href='#' onclick='javascript:new_cart_close();return false' style='color:white'>Close</a>&nbsp;&nbsp;";
	html		+= "</td></tr>";
	html		+= "<tr><td colspan='2' height='175' align='center' valign='middle'>";
	html		+= "Type the quantity： <input type='text' name='num' value='1' size='4' style='border:1px solid #cccccc'/><br><br>";
	html		+= "<input type='button' value='Ok' onclick='return new_cart_do(\""+sub+"\",\""+bid+"\",\""+url+"\",num.value)'/> <input type='button' value='Close' onclick='new_cart_close()'>";
	html		+= "</td></tr></table>";
	tttt.innerHTML	= html;
	return false;
}

function new_cart_do( sub,bid,url,n)
{
	var regexp=/^[0-9]*$/g;
    if(!regexp.test(n))
	{
		alert("·Plese put a integer!");
		return false;
	}
	else
	{
		new_cart_close();
		
		if(url==1)
		{
			framesrc	 = "cart_new.php?sub="+sub+"&bid="+bid+"&num="+n;
		}
		else if(url==2)
		{
			framesrc	 = "php/cart_new.php?sub="+sub+"&bid="+bid+"&num="+n;	
		}
		document.all.shoppingcartframe.src=framesrc;
		
		return false;
	}
}

/*
	关闭窗体
*/
function new_cart_close()
{
	tttt.innerHTML = '';
	tttt.style.display="none";
}