﻿/***************************/
//@Author: Adrian "yEnS" Mato Gondelle
//@website: www.yensdesign.com
//@email: yensamg@gmail.com
//@license: Feel free to use it, but keep this credits please!					
/***************************/

//SETTING UP OUR POPUP
//0 means disabled; 1 means enabled;
var popupStatus = 0;

//loading popup with jQuery magic!
function loadPopup(){
	//loads popup only if it is disabled
	if(popupStatus==0){
		$("#backgroundPopup").css({
			"opacity": "0.7"
		});
		$("#backgroundPopup").fadeIn("slow");
		$("#popupContact").fadeIn("slow");
		popupStatus = 1;
	}
}

//disabling popup with jQuery magic!
function disablePopup(){
	//disables popup only if it is enabled
	if(popupStatus==1){
		$("#backgroundPopup").fadeOut("slow");
		$("#popupContact").fadeOut("slow");
		$("#popupFavor").fadeOut("slow");
		$("#popupCartSubmit").fadeOut("slow");
		popupStatus = 0;
	}
}

//centering popup
function centerPopup(){
	//request data for centering
	var popUp = document.getElementById("popupContact");
	popUp.style.visibility="visible";
	var backGroup = document.getElementById("backgroundPopup");
	backGroup.style.visibility="visible";
	
	var windowWidth = document.documentElement.clientWidth;
	var windowHeight = document.body.clientHeight;
	var popupHeight = $("#popupContact").height();
	var popupWidth = $("#popupContact").width();
	//centering
	$("#popupContact").css({
		"position": "absolute",
		"top": 250,
		"left": 350
	});
	//only need force for IE6
	
	$("#backgroundPopup").css({
		"height": windowHeight
	});
	
}
function getPopWindow(){
	window.scroll(0,0);
	centerPopup();
	loadPopup();
	$("#popupContactClose").click(function(){
		disablePopup();
	});
	
	//Press Escape event!
	$(document).keypress(function(e){
		if(e.keyCode==27 && popupStatus==1){
			disablePopup();
		}
	});
}
function getPopWindow2(goodsId,goodsNum){
	document.getElementById("firstExperienceGoodsId").value=goodsId;
	document.getElementById("firstExperienceGoodsNum").value=goodsNum;
	window.scroll(0,0);
	centerPopup();
	loadPopup();
	$("#popupContactClose").click(function(){
		disablePopup();
	});
	
	//Press Escape event!
	$(document).keypress(function(e){
		if(e.keyCode==27 && popupStatus==1){
			disablePopup();
		}
	});
}
//当用户提交购物车时，如果未登陆则将DIV显示让用户登陆
function getPopWindow_CartSumit(){
	var popUp = document.getElementById("popupCartSubmit");
	popUp.style.visibility="visible";
	var backGroup = document.getElementById("backgroundPopup");
	backGroup.style.visibility="visible";
	
	var windowWidth = document.documentElement.clientWidth;
	var windowHeight = document.body.clientHeight;
	var popupHeight = $("#popupCartSubmit").height();
	var popupWidth = $("#popupCartSubmit").width();
	//centering
	$("#popupCartSubmit").css({
		"position": "absolute",
		"top": 250,
		"left": windowWidth/2-popupWidth/2
	});
	//only need force for IE6
	
	$("#backgroundPopup").css({
		"height": windowHeight
	});
	if(popupStatus==0){
		$("#backgroundPopup").css({
			"opacity": "0.7"
		});
		$("#backgroundPopup").fadeIn("slow");
		$("#popupCartSubmit").fadeIn("slow");
		popupStatus = 1;
	}
	$("#popupContactClose").click(function(){
		disablePopup();
	});
	
	//Press Escape event!
	$(document).keypress(function(e){
		if(e.keyCode==27 && popupStatus==1){
			disablePopup();
		}
	});
}
//当用户收藏商品时，如果未登陆则将DIV显示让用户登陆
function getPopWindow_Fov(){
	window.scroll(0,0);
	var popUpFavors = document.getElementById("popupFavor");
	popUpFavors.style.visibility="visible";
	var backGroup = document.getElementById("backgroundPopup");
	backGroup.style.visibility="visible";
	
	var windowWidth = document.documentElement.clientWidth;
	var windowHeight = document.body.clientHeight;
	var popupHeight = $("#popupFavor").height();
	var popupWidth = $("#popupFavor").width();
	//centering
	$("#popupFavor").css({
		"position": "absolute",
		"top": 250,
		"left": windowWidth/2-popupWidth/2
	});
	//only need force for IE6
	
	$("#backgroundPopup").css({
		"height": windowHeight
	});
	if(popupStatus==0){
		$("#backgroundPopup").css({
			"opacity": "0.7"
		});
		$("#backgroundPopup").fadeIn("slow");
		$("#popupFavor").fadeIn("slow");
		popupStatus = 1;
	}
	$("#popupContactClose").click(function(){
		disablePopup();
	});
	
	//Press Escape event!
	$(document).keypress(function(e){
		if(e.keyCode==27 && popupStatus==1){
			disablePopup();
		}
	});
}
//当用户购买一件礼品时，如果未登陆则将DIV显示让用户登陆
function getPopWindow1(){
	var popUp = document.getElementById("boxPopup");
	popUp.style.visibility="visible";
	var backGroup = document.getElementById("backgroundPopup");
	backGroup.style.visibility="visible";
	
	var windowWidth = document.body.clientWidth;
	var windowHeight = document.documentElement.clientHeight;
	var popupHeight = $("#boxPopup").height();
	var popupWidth = $("#boxPopup").width();
	//centering
	$("#boxPopup").css({
		"position": "absolute",
		"top": 250,
		"left": windowWidth/2-popupWidth/2
	});
	//only need force for IE6
	
	$("#backgroundPopup").css({
		"height": windowHeight
	});
	if(popupStatus==0){
		$("#backgroundPopup").css({
			"opacity": "0.7"
		});
		$("#backgroundPopup").fadeIn("slow");
		$("#boxPopup").fadeIn("slow");
		popupStatus = 1;
	}
	$("#popupContactClose").click(function(){
		disablePopup();
	});
	
	//Press Escape event!
	$(document).keypress(function(e){
		if(e.keyCode==27 && popupStatus==1){
			disablePopup();
		}
	});
}

function hidePopup_Fov(){
	var popUp = document.getElementById("popupFavor");
	popUp.style.visibility="hidden";
	var backGroup = document.getElementById("backgroundPopup");
	backGroup.style.visibility="hidden";
}
function hidePopup1(){
	var popUp = document.getElementById("boxPopup");
	popUp.style.visibility="hidden";
	var backGroup = document.getElementById("backgroundPopup");
	backGroup.style.visibility="hidden";
	
	$.ajax({
			   type: "POST",
			   url: "/portal/load-goods-num.jspa",
			   success: function(msg){
			       $("#goodsNum").html(msg);
			   }
	});
}

function hidePopup(){
	if(window.location.href.indexOf("njtck.jsp")<0){
		parent.location.reload();
	}
	var popUp = document.getElementById("popupContact");
	popUp.style.visibility="hidden";
	var backGroup = document.getElementById("backgroundPopup");
	backGroup.style.visibility="hidden";
	$.ajax({
		type: "POST",
		url: "/portal/load-goods-num.jspa",
		success: function(msg){
		   if($("#goodsNum") != "undefinded"){
			   $("#goodsNum").html(msg);
		   }
	    }
	});
	if(window.location.href.indexOf("njtck.jsp")>=0){
		window.history.back();
		window.location.reload();
	}
}

//CONTROLLING EVENTS IN jQuery
$(document).ready(function(){
	//LOADING POPUP
	//Click the button event!
	$("#cbutton").click(function(){
		//centering with css
		centerPopup();
		//load popup
		loadPopup();
	});
				
	//CLOSING POPUP
	//Click the x event!
	$("#popupContactClose").click(function(){
		disablePopup();
	});
	
	//Press Escape event!
	$(document).keypress(function(e){
		if(e.keyCode==27 && popupStatus==1){
			disablePopup();
		}
	});

});