// JavaScript Document
function menuOver(id) {
	if (parseInt(id) > 0) {
		$("#menuSub" + id).css("display", "none");
		var menuObj = $("#menuSub" + id);
		switch (id) {
			case 1 :
				menuObj.css("left", "-30px");
				break;
			case 2 :
				menuObj.css("left", "-30px");
				break;
			case 3 :
				menuObj.css("left", "-30px");
				break;
		}
		menuObj.show(700);
	}
}
function menuItemHiden() {
	$("#menuSub").hide();

}
function bgm() {
}
function imgEffect(id) {
	var imgObj = $("#" + id);
	imgObj.fadeTo(200, 0.16);
	imgObj.fadeTo(200, 0.98);
}

String.prototype.Trim = function() {
	return this.replace(/(^\s*)|(\s*$)/g, "");
}

// 搜索查询
function search() {
	var key = document.getElementById("proSearch").value;
	if (key.Trim() != '') {
		window.location.href = "search_" + key.Trim();
	} else {
		alert("請輸入需要查找的關鍵字");
	}
}

// 搜索回車執行
function keypressSearch(e) {
	e = e || event;
	if (e.keyCode == 13) {
		search();
	}
}

// 登錄自助平台回車執行
function keypressLogin(e) {
	e = e || event;
	if (e.keyCode == 13) {
		login();
	}
}

// 登录自助平台
function login() {
	document.getElementById("wrongText").innerHTML = "<img src='images/ajax-loader1.gif'/>";
	var userName = document.getElementById("username");
	var pwd = document.getElementById("userpwd");
	if (userName.value.Trim() != '' && pwd.value.Trim() != '') {
		$("#username").attr("disabled", "disabled");
		$("#userpwd").attr("disabled", "disabled");
		$
				.ajax( {
					type : "POST",
					url : "login.action",
					data : {
						username : userName.value.Trim(),
						userpwd : pwd.value.Trim()
					},
					dataType : "json",
					success : function(data) {
						if (data) {
							if (data.succeedflag == 0) {
								$("#username").removeAttr("disabled");
								$("#userpwd").removeAttr("disabled");
								document.getElementById("wrongText").innerHTML = "";
								document.getElementById("wrongText").innerHTML = data.errormsg;
								userName.value = "";
								pwd.value = "";
							} else if (data.succeedflag == 1) {
								document.getElementById("topNav").innerHTML = "<ul><li> 歡迎您【"
										+ userName.value
										+ "】 &nbsp; <a href='javaScript:reLogin(\""
										+ data.logid
										+ "\")'><strong>登出</strong></a> | <a href='javaScript:toCustomer()'><strong>進入自助平台</strong></a> </li></ul>";
								reLoadPrice('http://customer.e-print.com.hk/price.jsp?loginid="'+data.logid+'"');
							}
						} else {
							document.getElementById("wrongText").innerHTML = "登錄失敗！";
							$("#username").removeAttr("disabled");
							$("#userpwd").removeAttr("disabled");
						}
					}
				});
	} else {
		document.getElementById("wrongText").innerHTML = "用戶名或密碼為空";
	}

}

/* 自助品台登出 */
function reLogin(loginid) {
	$.ajax( {
		type : "POST",// 提交类型
			url : "reLogin.action",// 链接
			data : {
				loginid : loginid
			},// 参数
			dataType : "json",// 返回数据格式
			success : function(data) {// 回调函数
				if (data != null && data == true) {
					document.getElementById("topNav").innerHTML = "<ul><li id='wrongText'></li><li>用戶名:</li><li><input type='text' id='username' size='6' maxlength='16' /></li><li>密碼:</li><li><input type='password' id='userpwd' size='6' maxlength='16' onkeypress='keypressLogin(event)'/></li><li><img class='topnavImg' src='images/loginbutton.gif' width='44' height='20' onclick='login()'  alt='登錄' /></li><li><img class='topnavImg' src='images/zhecebutton.gif' width='44' height='20' alt='註冊' /></li></ul>";
					reLoadPrice('http://customer.e-print.com.hk/price2.jsp');
					
				} else {
					alert("登出錯誤");
				}
			}
		});
}

/*加载快速报价*/
function reLoadPrice(src){
	document.getElementById("loadImg").style.display="block";
	var iframe=document.getElementById("price");
	iframe.src = src;
	iframe.style.display = 'none';
	iframe.scrolling="no";
	iframe.id="price";
	iframe.style.margin=0;
	iframe.style.padding=0;
	iframe.setAttribute("frameborder", "0", 0);
	iframe.height=95;
	iframe.width=764;
	document.getElementById("baojia").appendChild(iframe);
	
		if (iframe.attachEvent){
		    iframe.attachEvent("onload", function(){
		    	document.getElementById("loadImg").style.display="none";
				iframe.style.display="block";
		    });
		} else {
		    iframe.onload = function(){
		    	document.getElementById("loadImg").style.display="none";
		        iframe.style.display="block";
		    };
		}
}

/* 進入自助平台 */
function toCustomer() {
	$.ajax( {
		type : "POST",// 提交方式
			url : "getUser.action",// 进入的action
			dataType : "json",// 数据类型
			success : function(data) {
				if (data && data.succeedflag == 1) {
					/*
					 * window
					 * .open("http://customer.e-print.com.hk/epsf.do?method=login&pid=0&logid=" +
					 * data.logid + "&language=us");
					 */
					window.location.href = "http://customer.e-print.com.hk/epsf.do?method=login&pid=0&logid="
							+ data.logid + "&language=us";
				} else {
					// window.open("http://customer.e-print.com.hk/");
					window.location.href = "http://customer.e-print.com.hk/main.jsp";
				}
			}
		});
}

/* 注册自助平台 */
function enrol() {
	window.open("http://customer.e-print.com.hk/public.do?method=showReg");
}
// 判斷是否有用戶登錄
$
		.ajax( {
			type : "POST",
			url : "getUser.action",
			dataType : "json",
			success : function(data) {
				if (data && data.logid != null) {
					document.getElementById("topNav").innerHTML = "<ul><li>歡迎您【"
							+ data.username
							+ "】 &nbsp; <a href='javaScript:reLogin(\""
							+ data.logid
							+ "\")'><strong>登出</strong></a> | <a href='javaScript:toCustomer()'><strong>進入自助平台</strong></a> </li></ul>";
				}
			}
		});

/* 去自助平台订购或报价咨询 */
function speakFor(pid, flag) {
	$.ajax( {
		type : "POST",
		url : "getUser.action",
		dataType : "json",
		success : function(data) {
			if (data && data.logid != null) {
				// window.open("http://customer.e-print.com.hk/epsf.do?method=login&pid="
				// +
			// pid + "&logid=" + data.logid + "&flag=" + flag);
			window.location.href = "http://customer.e-print.com.hk/epsf.do?method=login&pid="
					+ pid + "&logid=" + data.logid + "&flag=" + flag;
		} else {
			// window.open("http://customer.e-print.com.hk/main.jsp","name","");
			window.location.href = "http://customer.e-print.com.hk/main.jsp";
		}
	}
})	;
}

function toPhotobook(){
	window.open('http://www.photobook1010.com');
}

