// JavaScript Document

//获得页面顶部FLASH的位置
function GetTopFlashPOS(){ return $("#TopFlash").position(); }

//项部LOGIN区的位置重置
function TopLoginAreaReset(moveSize){
	var tfXY = GetTopFlashPOS();
	var pw = pageWidth();
	if(pw>1400) {
		var lt = Math.floor(((pw-1400)/2)+580);
		$(".dgr_share_login").css("left", lt);
	} else {
		var lt = Math.floor(tfXY.left+580-moveSize);
		$(".dgr_share_login").css("left", lt);
	}
	//$(".dgr_share_login").fadeIn("slow");
	$(".dgr_share_login").show();
	$("#PageCJs").css("visibility","visible");
}
//自适应调整区块位置,此处请勿乱动
// kevin to 2011-6-10 1:20
function CurSetSize() {
	var pw = pageWidth();
	//分辨率小于flash的宽度，把flash移
	var moveSize = 0;
	var BMsize = 0;
	if($.browser.msie){}
	else { BMsize = 18; } 

	//主体
	if(pw<1000){
		$("#PageCJs").css("left","0px");
	} else {
		$("#PageCJs").css("left",Math.floor((pw-1000)/2)+"px");
	}
	
	//主体高度
	var ph = $("#PageCJs").height();
	var finaPH = 0;
	if($.browser.msie && $.browser.version=="6.0"){
		finaPH = ph-50;
	} else {
		finaPH = ph-30;
	}
	//var finaPH = ph+50;
	$("#PageBottom").css("top", finaPH+"px");
	
	//页尾背景自适应
	if(pw>1920){
		$("#PageBottom").css("left", ((pw-1920)/2)+"px");
		$("#PageBottom").css("width", "1920px");
	} else {
		var bp = Math.floor((1920-pw)/2);
		if($.browser.msie){
			if($.browser.version=="6.0"){
				$("#PageBottom").css("margin-left", "-"+bp+"px");
				var bp1 = (pw-1000)/2;
				$("#footerText").css("margin-left", bp+bp1+"px");
			} else {
				$("#PageBottom").css("background-position", "-"+bp+"px 0");
			}
			$("#PageBottom").css("width", (pw+BMsize)+"px");
		} else {
			$("#PageBottom").css("background-position", "-"+bp+"px 0");
			$("#PageBottom").css("width", (pw+BMsize)+"px");
		}
	}
	$("#PageBottom").css("visibility","visible");


	
	if(pw>1400) {
		$("#TopFlash").css("width", "1400px");
		$("#TopFlash").css("margin-left", ((pw-1400)/2)+"px");
	} else {
		//这里的0.373是根椐设计稿的1440布图空白比计算出来的，不要修改，以达到最好效果
		moveSize = Math.floor((1400-pw)*0.373);
		$("#TopFlash").css("margin-left", "-"+moveSize+"px");
		$("#TopFlash").css("width", (pw+moveSize+BMsize)+"px");
	}
	$("#TopFlash").css("visibility","visible");

	TopLoginAreaReset(moveSize);
}

function IndexSetSize()
{
	var pw = pageWidth();
	var ph = pageHeight();
	var fx = ((pw-1002)/2)+482-38;
	var lt = Math.floor(fx);
	/*if(curPg=="index" || curPg=="brand" || curPg=="class") {
		$(".dgr_share_login").hide();
	} else {*/
		$(".dgr_share_login").css("left", lt);
		$(".dgr_share_login").show();
	//}
	$("#Top").css("height",ph+"px");
	$("#Top #ok").height(ph);
}


//返回当前页面宽度
function pageWidth(){ 
	if($.browser.msie){ 
		return document.compatMode == "CSS1Compat"? document.documentElement.clientWidth : document.body.clientWidth; 
	}else{ 
		return self.innerWidth-17; 
	} 
}

//返回当前页面高度
function pageHeight(){ 
	if($.browser.msie){ 
		return document.compatMode == "CSS1Compat"? document.documentElement.clientHeight : document.body.clientHeight; 
	}else{ 
		return self.innerHeight; 
	} 
}


//防遮打印域
function ShowPrint()
{
	$("#pgBtnSpec129").html($("#NewPrint").html());
	$("#pgBtnSpec129").css("padding-right", "25px");
}

//显示隐藏问答
function showAnswer(ids)
{
	if($("#Answer"+ids).attr("rel")=="0"){
		$("#Answer"+ids).parent().prev().find("td").css("border-bottom", "0");
		//$("#Answer"+ids).slideDown("slow").attr("rel", "1");
		$("#Answer"+ids).show();
		$("#Answer"+ids).attr("rel", "1");
	} else {
		$("#Answer"+ids).parent().prev().find("td").css("border-bottom", "1px solid #ebebeb");
		$("#Answer"+ids).hide();
		$("#Answer"+ids).attr("rel", "0");
		/*
		$("#Answer"+ids).slideUp("slow", function(){
			$("#Answer"+ids).attr("rel", "0");
			$("#Answer"+ids).parent().prev().find("td").css("border-bottom", "1px solid #ebebeb");
			//$("#Answer"+ids).parent().css("border-bottom", "1px solid #ebebeb");
		});*/
	}
}

//问答TAB动作
function AskTabSwitch()
{
	$("#AskTab li").each(function(index, domEle){
		$(domEle).click(function(){
				$("#AskTab li").each(function(index, domEle){ $(domEle).removeClass().addClass(""); });
				$(domEle).addClass("over");
				var rel = $(domEle).attr("rel");
				$("#cid").val(rel);
				AjaxaskTabc();
		});
	})
}
function AjaxaskTabc(){
	var aid = $("#cid").val();
	if(aid=="") aid = 1;
	/*
	$.getJSON("./data/ask_"+aid+".js?rnd="+Math.random(), function(data){
		var htmlStr;
		if(data=="") {
			htmlStr = "<ul><li></li><li></li><li style=\"text-align:center;width:100%;color:#f00;\">暂无内容</li><li></li><li></li></ul>"; 
		} else {
			htmlStr = "<ul>";
			for (i in data) {
				var row = data[i];
				htmlStr += "<li><div class=\"l1\">";
				htmlStr += "<img src=\"images/"+row.img+"\" width=\"14\" height=\"15\" /></div>";
				if(row.isok=="yes") {
					htmlStr += "<div class=\"c1\"><span class=\"fnt9\">["+row.tip+"]</span>";
					htmlStr += "<a href=\"ask-list-"+row.aid+".html?id="+row.id+"\"><span class=\"fnt12\">"+row.question+"</span></a>";
				} else {
					htmlStr += "<div class=\"c1\"><span class=\"fnt8\">["+row.tip+"]</span>";
					htmlStr += "<a href=\"javascript:;\"><span class=\"fnt12\">"+row.question+"</span></a>";
				}
				htmlStr += "</div><div class=\"fr\"><span class=\"fnt13\">"+row.adate+"</span></div></li>";
			}
			htmlStr += "</ul>";
		}
		$("#askBdrConts").slideUp("fast",function(){$("#askBdrConts").html(htmlStr).slideDown("fast");});
	}); 
	*/
	$.get("./data/ask_"+aid+".php?rnd="+Math.random(), function(data){
		var htmlStr;
		if(data=="") {
			htmlStr = "<ul><li></li><li></li><li style=\"text-align:center;width:100%;color:#f00;\">暂无内容</li><li></li><li></li></ul>"; 
		} else {
			htmlStr = data;
		}
		$("#askBdrConts").slideUp("fast",function(){$("#askBdrConts").html(htmlStr).slideDown("fast");});
	}); 

}

//提交问题检查
function AskCheck()
{
	var question=$("#question").val();
	if(question=="") { alert("请输入您的问题"); $("#question").focus(); return false; }
/*
	var year = $("#year").val();
	if(year=="") { alert("请选择 \"宝宝生日 年份\""); $("#year").focus(); return false; }

	var month = $("#month").val();
	if(month=="") { alert("请选择 \"宝宝生日 月份\""); $("#month").focus(); return false; }

	var day = $("#day").val();
	if(day=="") { alert("请选择 \"宝宝生日 日份\""); $("#day").focus(); return false; }
*/	
	return true;
}

//链接动态跳转
function JumpAskList(){
	window.location.href="ask-list-"+$("#cid").val()+".html";
}

//动态显示问答
function AnswerShow()
{
	var urlid = $.query.get("id"); 
	if(urlid!="") {
		if($("#Answer"+urlid)){showAnswer(urlid)}
	}
}


//充积分
function EnterJf()
{
	var jfnum = $("#jfnum").val();
	if(jfnum=="") {
		alert("请输入产品防伪码！");
		$("#jfnum").focus();
		return false;
	}
	
	$.ajax({
		type: "POST",
		url: "Ajax.php",
		data: "act=cjf&jfnum="+jfnum,
		success: function(msg){
			msg = $.trim(msg);
			if(msg=="nologin") {
				alert("您还没有登录，请登录后再进行充积分操作");	
			} else if(msg=="ok") {
				alert("充积分成功，感谢您的参与");
			} else if(msg=="exists"){
				alert("您输入的产品防伪码已经使用过，请换个产品防伪码再试");
			} else if(msg=="empty"){
				alert("产品防伪码为空，请输入产品防伪码再试");
			} else if(msg=="fail"){
				alert("产品防伪码无效，请输入正确的产品防伪码");
			} else {
				alert("充积分失败，请检查您的操作");
			}
			$("#jfnum").val("");
		}
	}); 
	
}
var email_str = /^[\w\-\.]+@[\w\-\.]+(\.\w+)+$/;
//验ID
function CheckUID()
{
	var uid = $("#UID").val();
	if(uid!="") {
		if(!email_str.test(uid)){alert("请输入正确的通行证--Email格式");$("#UID").focus();return false;}

		$("#uidImg").attr("src", "images/loading3.gif");
		$.ajax({
			type: "POST",
			url: "Ajax.php",
			data: "act=checkuid&uid="+uid,
			success: function(msg){
				if(msg=="ok"){
					$("#uidImg").attr("src", "images/right1.gif");	
					$("#uidImg").show();
					$("#uidText").html("<font color=green>可以注册</font>");
				} else if(msg=="empty"){
					$("#uidImg").attr("src", "images/blank.gif");	
					$("#uidImg").hide();
					$("#uidText").html("<font color=green>请输入通行证</font>");
				} else {
					$("#uidImg").attr("src", "images/blank.gif");	
					$("#uidImg").hide();
					$("#uidText").html("<font color=red>您要注册的通行证不可用，请进行更换</font>");
				}
			}
		}); 
	} else {
		$("#uidImg").attr("src", "images/blank.gif");	
		$("#uidImg").hide();
		$("#uidText").html("<font color=green>请输入通行证</font>");
	}
}
//注册一
function CheckReg1()
{
	var uid = $("#UID").val();
	if(uid=="") {alert("请输入通行证");$("#UID").focus();return false;}
	if(!email_str.test(uid)){alert("请输入正确的通行证--Email格式");$("#UID").focus();return false;}
	
	var regpass = $("#regpass").val();
	if(regpass=="") { alert("请输入密码"); $("#regpass").focus(); return false;}
	
	var confirmpass = $("#confirmpass").val();
	if(confirmpass=="") { alert("请输入确认密码"); $("#confirmpass").focus(); return false;}
	if(regpass!=confirmpass) { alert("密码与确认密码不一致"); $("#confirmpass").focus(); return false;}


	if($("#isok").attr("checked")){}
	else{ alert("请选择同意 “服务条款”"); $("#isok").focus(); return false;	}
	
	return true;
}
//注册二
function CheckReg2()
{
	var nickname = $("#nickname").val();
	if(nickname=="") {alert("请输入呢称");$("#nickname").focus();return false;}
	
	var mobile = $("#mobile").val();
	if(mobile=="") {alert("请输入手机号码");$("#mobile").focus();return false;}

	if(!isMobel(mobile)){alert("请输入正确的手机号码");$("#mobile").focus();return false;}

/*
	var province = $("#province").val();
	var city = $("#city").val();
	if(province=="0"){alert("省份没有选择");return false;}
	if(city=="0"){alert("城市没有选择");return false;}
*/
	return true;
}

//注册三
function CheckReg3()
{
	var year = $("#year").val();
	var month = $("#month").val();
	var day = $("#day").val();


}

//登录验证
function CheckLogin()
{
	var topemail = $("#topemail").val();
	if(topemail=="") {alert("请输入用户名");$("#topemail").focus();return false;}
	var toppass = $("#toppass").val();
	if(toppass=="") {alert("请输入密码");$("#toppass").focus();return false;}
	return true;
}
//登录验证
function CheckPGLogin()
{
	var loginemail = $("#loginemail").val();
	if(loginemail=="") {alert("请输入用户名");$("#loginemail").focus();return false;}
	var loginpass = $("#loginpass").val();
	if(loginpass=="") {alert("请输入密码");$("#loginpass").focus();return false;}
	return true;
}

//切换验证码
function SwitchVerifyImg()
{
	$("#verifyImg").attr("src","./include/verify.php?rnd="+Math.random());
}


//验证手机
function isMobel(value) {
	if(/^13\d{9}$/g.test(value)||(/^15[0-35-9]\d{8}$/g.test(value))|| (/^18[05-9]\d{8}$/g.test(value))) {
		return true;
	}else{
		return false;
	}
}



//取兑换奖品信息
function Uinfo(jf)
{
	$.ajax({
		type: "POST",
		url: "Ajax.php",
		data: "act=uinfo&jf="+jf,
		success: function(msg){
			$("#Uinfo").html(msg).show();
		}
	}); 
}

//取会员中心个人信息
function mcenterInfo()
{
	$.ajax({
		type: "POST",
		url: "Ajax.php",
		data: "act=mcenterinfo",
		success: function(msg){
			$("#McenterInfoArea").html(msg).fadeIn("slow");
		}
	}); 
}

function CheckModifyInfo()
{
	var nickname = $("#nickname").val();
	if(nickname=="") {alert("请输入呢称");$("#nickname").focus();return false;}
	
	var mobile = $("#mobile").val();
	if(mobile=="") {alert("请输入手机号码");$("#mobile").focus();return false;}

	if(!isMobel(mobile)){alert("请输入正确的手机号码");$("#mobile").focus();return false;}

/*
	var province = $("#province").val();
	var city = $("#city").val();
	if(province=="0"){alert("省份没有选择");return false;}
	if(city=="0"){alert("城市没有选择");return false;}
	
	var truename = $("#truename").val();
	if(truename=="") {alert("请输入收件人姓名");$("#truename").focus();return false;}
	
	var address = $("#address").val();
	if(address=="") {alert("请输入收货地址");$("#address").focus();return false;}
*/	
	return true;
}

//兑换产品
function Dhcp(id)
{
	if(parseInt(id)>0){
		$.ajax({
			type: "POST",
			url: "Ajax.php",
			data: "act=dhcp&id="+id,
			success: function(msg){
				msg = $.trim(msg);
				if(msg=="ok") {
					alert("积分兑换产品成功，我们会尽快发货，感谢您的操作");
				} else if(msg=="notdh") {
					alert("您的积分余额不足以兑换当前产品，请返回积分产品页重新选择");
				} else {
					alert("积分兑换产品出错，请与管理员联系");
				}
				self.location="/score.html";
			}
		}); 
	} else {
		alert("您需要兑换的产品ID无效，请返回积分产品页面进行选择");
		self.location="/score.html";
	}
}


function show(){
    var babypic=document.reg1.babypic;
    if(babypic.files){
        var imgsrc=babypic.files[0].getAsDataURL();
    }else{
        var imgsrc=babypic.value;
    }
   
    var imgobj=document.getElementById("reg3face");
    imgobj.setAttribute("src",imgsrc);
   
}



