function setLeaveValidcode() {
	var rnd = Math.round( ( Math.random() ) * 100000000 );
	var img = document.getElementById( "validcode" );
	//img.src = "leavevalidcode.php?t=" + rnd;
	img.setAttribute( "src", "leavevalidcode.php?t=" + rnd );
	img.style.display = "";
}
function orderformValid( groupNum ) {
	var result = { "code" : 0, "msg" : [] }, forindex = 0, forcount = 0;

	var colorValid = 0, nameValid = 0, provinceValid, cityValid, addressValid, postValid, telcodeValid, telnumValid, leavemsgValid;
	radioColors = document.getElementsByName( "color" );
	for( forindex = 0, forcount = radioColors.length; forindex < forcount; forindex++ ) {
		if ( radioColors[forindex].checked ) {
			colorValid = 1;
			break;
		}
	}
	nameValid = orderform.name.value.length >= 2;
	mobileValid = /^\d{11}$/.test( orderform.mobile.value );
	//s1Valid = orderform.s1.selectedIndex > 0;
	//s2Valid = orderform.s2.selectedIndex > 0;
	//s3Valid = orderform.s3.selectedIndex > 0;
	//addressValid = orderform.address.value.length > 5;
	//postValid = orderform.post.value == "" || /^\d{6}$/.test( orderform.post.value );
	numValid = /^\d{1,3}$/.test( orderform.num.value );
	//telcodeValid = /^\d{3,7}$/.test( orderform.telcode.value );
	//telnumValid = /^\d{7,8}$/.test( orderform.telnum.value );
	//telValid = ( telcodeValid == "" && telnumValid == "" ) || ( telcodeValid && telnumValid );
	//leavemsgValid = orderform.leavemsg.value.length >= 5 && orderform.leavemsg.value.length <= 100;

	if ( ! colorValid ) { result.msg[result.msg.length] = "请选择颜色"; }
	if ( ! nameValid ) { result.msg[result.msg.length] = "请输入收货人姓名"; }
	if ( ! mobileValid ) { result.msg[result.msg.length] = "请输入手机号码"; }
	//if ( ! s1Valid ) { result.msg[result.msg.length] = "请选择省份"; }
	//if ( ! s2Valid ) { result.msg[result.msg.length] = "请选择城市"; }
	//if ( ! s3Valid ) { result.msg[result.msg.length] = "请选择地区"; }
	//if ( ! addressValid ) { result.msg[result.msg.length] = "请输入详细地址"; }
	//if ( ! postValid ) { result.msg[result.msg.length] = "请输入正确的邮编"; }
	if ( ! numValid ) { result.msg[result.msg.length] = "请输入正确的订购数量"; }
	//if ( ! telValid ) { result.msg[result.msg.length] = "请输入正确的固定电话"; }
	//if ( ! leavemsgValid ) { result.msg[result.msg.length] = "请输入5-100字的附言"; }
	if ( numValid && document.getElementById( "price2" ).checked && buyNumChange.getInputNum().value < groupNum ) { result.msg[result.msg.length] = "团购数量不能小于 " + groupNum + " 部"; };

	result.code = result.msg.length ? 1 : 0;
	if ( result.code !== 0 ) {
		alert( result.msg.join("；\n") + "。");
	}
	
	return result.code === 0;
}
function leaveformvalid() {
	var result = { "code" : 0, "msg" : [] };

	var nameValid = 0, contentValid = 0, validcodeValid;
	nameValid = leaveform.name.value.length >= 2;
	contentValid = leaveform.content.value.length >= 5;
	validcodeValid = /^\d{4}$/.test( leaveform.validcode.value );

	if ( ! nameValid ) { result.msg[result.msg.length] = "请输入姓名"; }
	if ( ! contentValid ) { result.msg[result.msg.length] = "请输入留言内容"; }
	if ( ! validcodeValid ) { result.msg[result.msg.length] = "请输入4位数字验证码"; }

	result.code = result.msg.length ? 1 : 0;
	if ( result.code !== 0 ) {
		alert( result.msg.join("；\n") + "。");
	}
	
	return result.code === 0;
}
var buyNumChange = {
	onlyone : function() {
		this.oldNum = this.getInputNum().value;
		this.getInputNum().parentNode.parentNode.style.display = "none";
		this.getInputNum().value = 1;
	},
	groupbuy : function( minnum ) {
		this.getInputNum().parentNode.parentNode.style.display = "";
		this.getInputNum().value = this.oldNum || minnum;
	},
	getInputNum : function() {
		if ( ! this.inputNum ) {
			this.inputNum = document.getElementById( "inputNum" );
		}
		return this.inputNum;
	}
};
var delta=0.15
var collection;
function floaters() {
	this.items = [];
	this.addItem = function(id,x,y,content) {
		document.write('<DIV id='+id+' style="Z-INDEX: 10; POSITION: absolute;  width:80px; height:60px;left:'+(typeof(x)=='string'?eval(x):x)+';top:'+(typeof(y)=='string'?eval(y):y)+'">'+content+'</DIV>');
		var newItem = {};
		newItem.object = document.getElementById(id);
		newItem.x = x;
		newItem.y = y;
		this.items[this.items.length] = newItem;
	};
	this.play = function() {
		collection = this.items;
		setInterval('play()',10);
	}
}
function play() {
	if(screen.width <= 800) {
		for(var i=0;i<collection.length;i++) {
			collection[i].object.style.display = 'none';
		}
		return;
	}
	for( var i=0; i < collection.length; i++ ) {
		var followObj = collection[i].object;
		var followObj_x = (typeof(collection[i].x)=='string'?eval(collection[i].x):collection[i].x);
		var followObj_y = (typeof(collection[i].y)=='string'?eval(collection[i].y):collection[i].y);
		if(followObj.offsetLeft!=( ( document.body.scrollLeft || document.documentElement.scrollLeft ) + followObj_x)) {
			var dx=(( document.body.scrollLeft || document.documentElement.scrollLeft )+followObj_x-followObj.offsetLeft)*delta;
			dx=(dx>0?1:-1)*Math.ceil(Math.abs(dx));
			followObj.style.left=followObj.offsetLeft+dx;
		}
		if(followObj.offsetTop!=(( document.body.scrollTop || document.documentElement.scrollTop )+followObj_y)) {
			var dy=(( document.body.scrollTop || document.documentElement.scrollTop )+followObj_y-followObj.offsetTop)*delta;
			dy=(dy>0?1:-1)*Math.ceil(Math.abs(dy));
			followObj.style.top=followObj.offsetTop+dy;
		}
		followObj.style.display = '';
	}
}