// JavaScript Document
//此处为独立函数
function LTrim(str)
{
    var i;
    for(i=0;i<str.length;i++)
    {
        if(str.charAt(i)!=" "&&str.charAt(i)!=" ")break;
    }
    str=str.substring(i,str.length);
    return str;
}
function RTrim(str)
{
    var i;
    for(i=str.length-1;i>=0;i--)
    {
        if(str.charAt(i)!=" "&&str.charAt(i)!=" ")break;
    }
    str=str.substring(0,i+1);
    return str;
}
function Trim(str)
{
    return LTrim(RTrim(str));
}

function f_freeorder(f){
	if(f.name.value==""){
		alert("请填写姓名");
		f.name.focus();
		return false;
	}
	if(f.address.value==""){
		alert("请填写地址");
		f.address.focus();
		return false;
	}
	/*if(f.zip.value==""){
		alert("请填写邮编");
		f.zip.focus();
		return false;
	}*/
	if(f.mobile.value=="" && f.tel.value==""){
		alert("请填写手机或者固定电话");
		return false;
	}
	f.action="index.php";
	f.submit();
}
function f_order(f){
	if(f.name.value==""){
		alert("请填写姓名");
		f.name.focus();
		return false;
	}
	if (f.age.value!="" && isNaN(f.age.value)){
		alert("年龄必须是数字");
		f.age.focus();
		return false;
	}
	if (f.weight.value!="" && isNaN(f.weight.value)){
		alert("体重必须是数字");
		f.weight.focus();
		return false;
	}
	if (f.tall.value!="" && isNaN(f.tall.value)){
		alert("身高必须是数字");
		f.tall.focus();
		return false;
	}
	if(f.address.value==""){
		alert("请填写地址");
		f.address.focus();
		return false;
	}
	if(f.zip.value==""){
		alert("请填写邮编");
		f.zip.focus();
		return false;
	}
	if(f.zip.value!="" && isNaN(f.zip.value)){
		alert("邮编必须是数字");
		f.zip.focus();
		return false;
	}
	if(f.mobile.value==""){
		alert("请填写手机");
		f.mobile.focus();
		return false;
	}	
	if(f.mobile.value!="" && isNaN(f.mobile.value)){
		alert("手机必须是数字");
		f.mobile.focus();
		return false;
	}
	if(f.tel.value!="" && isNaN(f.tel.value)){
		alert("电话必须是数字");
		f.tel.focus();
		return false;
	}
	f.action="buy.php";
	f.submit();
}
function f_comment_reply(id,act){
	//JQ("#replybox").dialog();
	if(act=='ok'){
		document.replyform.submit();
	}else if(act=='cancel'){
		JQ("#replybox").hide();
		//alert(JQ("#replybox").outerHeight());
	}else{
		JQ("#replybox").show();
		JQ("input[name=replyid]").val(id);
		//alert(JQ("input[name@replyid]").val());
	}
}
function f_comment(f){
	if(f.username.value==""){
		alert("请填写姓名");
		f.username.focus();
		return false;
	}
	if(f.content.value==""){
		alert("请填写留言内容");
		f.content.focus();
		return false;
	}	
	f.action="comment.php";
	f.submit();
}
/*comments*/
// 插入表情到评论框
function Insertbq(img)
{
	var text=JQ("#review").val();
	text +="["+img+"]";
	JQ("#review").val(text);	
}
/*shop*/
function f_W_shopviews(shopid)
{
	//alert(websiteid);
	//alert(ifshow);
	if(!shopid) return false;
	JQ.post('/misc/ajax_php/ajax_shopviews.php',{
										shopid: shopid
										});	
	
}

/*site*/
function f_W_siteviews(websiteid,ifshow)
{
	//alert(websiteid);
	//alert(ifshow);
	if(!websiteid) return false;
	if(ifshow){
		JQ.post('/misc/ajax_php/ajax_websiteviews.php',{
										websiteid: websiteid,
										ifshow: ifshow
										},function(data){
											//alert(data);
											JQ("#"+ifshow).html(data);
										});
		
	}else{
		JQ.post('/misc/ajax_php/ajax_websiteviews.php',{
										websiteid: websiteid
										});	
	}
	
}
function f_W_sitecomment(f)
{
	//alert(websiteid);
	//alert(ifshow);
	var websiteid=f.websiteid.value;
	var username=f.username.value;
	var content=f.review.value;
	if(websiteid=="") return false;
	if(Trim(username).length==0){
		alert("haha！雁过拔毛，人过留名哦！");
		f.username.focus();
		return false;
	}
	if(content.length==0){
		alert("是不是该写点什么呢！");
		f.review.focus();
		return false;
	}
	f.username.value="";
	f.review.value="";
		JQ.post('/misc/ajax_php/ajax_websitecomment.php',{
										websiteid: websiteid,
										username:username,
										content: content
										},function(data){
											//alert(data);
											//JQ("#sitecommentsubmitmsg").html(data);
										});
	alert("您的评论提交成功！请等待审核！");
}
function f_W_subscribe(f)
{
	//alert(websiteid);
	//alert(ifshow);
	var email=f.email.value;
	if(Trim(email).length==0){
		alert("请留下正确的email地址！");
		f.email.focus();
		return false;
	}
	var search_str = /^[\w\-\.]+@[\w\-\.]+(\.\w+)+$/;
 	if(!search_str.test(email)){        
 		alert("请留下正确的email地址！");
 		f.email.focus();
 		return false;
 	}
 	f.email.value="";
		JQ.post('/misc/ajax_php/ajax_subscribe.php',{
										email: email
										},function(data){
											
											alert(data);
											//JQ("#sitecommentsubmitmsg").html(data);
										});
	//alert("团购活动订阅提交成功！请等待审核！");
}
/*goods*/
/*site*/
function f_W_goodsviews(gid,ifshow)
{
	//alert(websiteid);
	//alert(ifshow);
	if(!gid) return false;
	if(ifshow){
		JQ.post('/misc/ajax_php/ajax_goodsviews.php',{
										gid: gid,
										ifshow: ifshow
										},function(data){
											//alert(data);
											JQ("#"+ifshow).html(data);
										});
		
	}else{
		JQ.post('/misc/ajax_php/ajax_goodsviews.php',{
										gid: gid
										},function(data){
											//alert(data);
											
										});	
	}
	
}
function f_W_goodscomment(f)
{
	//alert(websiteid);
	//alert(ifshow);
	var gid=f.gid.value;
	var username=f.username.value;
	var content=f.review.value;
	if(gid=="") return false;
	if(Trim(username).length==0){
		alert("haha！雁过拔毛，人过留名哦！");
		f.username.focus();
		return false;
	}
	if(content.length==0){
		alert("是不是该写点什么呢！");
		f.review.focus();
		return false;
	}
	f.username.value="";
	f.review.value="";
		JQ.post('/misc/ajax_php/ajax_goodscomment.php',{
										gid: gid,
										username:username,
										content: content
										},function(data){
											//alert(data);
											//JQ("#sitecommentsubmitmsg").html(data);
										});
	alert("您的评论提交成功！请等待审核！");
}
function countDown(){
	var i;
	var objArray =document.getElementsByTagName("label");
	//alert(objArray.length);
	for (i=0;i<(objArray.length);i++)
	{
		if (objArray[i].id.indexOf("g_")>-1) 
		{
			objHid = document.getElementById("hid_g_" + objArray[i].id.substring(objArray[i].id.indexOf("_")+1)); 
			//objHid.value就是对应的时间值，然后改下面就行了
			var d=Date.parse(objHid.value);
			var today=new Date();
			var time=d-today;
			var 时间=objArray[i];
			if(Math.floor(time)<=0){
				时间.innerHTML='抢购时间已过，谢谢您的关注!';
			}
			else
			{
				var 天=Math.floor(time/(1000*60*60*24));
				var 小时=Math.floor(time/(1000*60*60))%24;
				var 分=Math.floor(time/(1000*60))%60;
				var 秒=Math.floor(time/1000)%60;
				时间.innerHTML='<b>'+天+'</b> 天 <b>'+小时+'</b> 小时 <b>'+分+'</b> 分 <b>'+秒+'</b> 秒';
			} 
		}
	}
	setTimeout('countDown()',1000);
}
countDown();

