var City = new Array();
City[0] = "Hồ Chí Minh";
City[1] = "Hà Nội";
City[2] = "Hải Phòng";
City[3] = "Cần Thơ";
City[4] = "Đà Nẵng";
City[5] = "Biên Hòa";
City[6] = "Nha Trang";
City[7] = "Huế";
City[8] = "Vũng Tàu";
City[9] = "Quy Nhơn";
City[10] = "Long Xuyên";
City[11] = "Thái Nguyên";
City[12] = "Nam Định";
City[13] = "Buôn Ma Thuột";
City[14] = "Vinh";
City[15] = "Hạ Long";
City[16] = "Cà Mau";
City[17] = "Rạch Giá";
City[18] = "Phan Thiết";
City[19] = "Thủ Dầu Một";
var catchText3;
var promoCount;
function showHydeWin(mode, vell){
var showVell = vell;
var theWindow = document.getElementById("popWindow");
var opStart;
var opEnd;
if(mode === "+"){
opStart = 0;
opEnd = 1;
}else if(mode === "-"){
opStart = 1;
opEnd = 0;
showVell = -vell;
}else{
return;
}
var count = opStart;
var showLoop = setInterval(function(){
theWindow.style.opacity = count;
count += showVell;
if(mode === "+"){
if(count > opEnd){
theWindow.style.opacity = opEnd;
clearInterval(showLoop);
}
}else if(mode === "-"){
if(count < opEnd){
theWindow.style.opacity = opEnd;
clearInterval(showLoop);
return;
}
}
},17);
};
function genRandNum(min, max){
var count = Math.floor((Math.random() * (max-min)) + min);
return count;
};
function showBoxTime(sec, vell){
showHydeWin("+", vell);
var n = 0;
var showLoop = setInterval(function(){
if(n > sec){
showHydeWin("-", vell);
clearInterval(showLoop);
return;
}
n ++;
},1000);
};
function setBoxText(num){
switch(num){
case 1:
var text = "Hiện tại đang có 100 khách đang truy cập trang web này.";
var count = genRandNum(150, 250);
document.getElementById("popWindow").innerHTML = text.replace("100", ""+count+"");
break;
case 2:
var text = "Đơn hàng mới vừa được đặt tại CITY.";
var city = City[Math.floor(Math.random()*City.length)];
document.getElementById("popWindow").innerHTML = text.replace("CITY", ""+city+"");
break;
case 3:
var text = "Còn lại 15 hộp khuyến mại !";
var count = genRandNum(4, 10);
catchText3 = count;
document.getElementById("popWindow").innerHTML = text.replace("15", ""+count+"");
break;
default:
return;
}
return;
};
function welcomeUser(){
var time = 0;
var custTime = genRandNum(9, 12);
var userLoop = setInterval(function(){
if(time === 0){
setBoxText(1);
showBoxTime(4, 0.05);
}
if(time === custTime){
setBoxText(2);
showBoxTime(4, 1);
}
if(time === custTime+7){
setBoxText(3);
promoCount = catchText3;
showBoxTime(5, 0.01);
clearInterval(userLoop);
customLead(genRandNum(7, 20));
}
time ++;
},1000);
};
function customLead(sec){
setTimeout(function(){
var time = 0;
var leadLoop = setInterval(function(){
if(time === 0){
setBoxText(2);
showBoxTime(4, 1);
}
if(time === 7){
promoCount --;
if(promoCount > 0){
document.getElementById("popWindow").innerHTML = "Chỉ còn lại: "+promoCount+" hộp khuyến mại.";
}else{
document.getElementById("popWindow").innerHTML = "Nếu bạn đặt ngay bây giờ, bạn sẽ mua được sản phẩm theo giá kuyến mãi!!!!";
}
showBoxTime(5, 0.01);
}
if(time === 14){
clearInterval(leadLoop);
if(promoCount > 0){
customLead(genRandNum(2, 20));
}
}
time ++;
},1000);
},sec*1000);
};
window.onload = welcomeUser;