﻿function s$(o) { return document.getElementById(o); }
function isUdf(o) { return typeof (o) == "undefined" }
String.prototype.trim = function() { return this.replace(/(^\s*)|(\s*$)/g, ""); }
Date.prototype.format = function() {
	var s = this.getFullYear() + "-";
	s += (this.getMonth() + 1) + "-";
	s += this.getDate() + " ";
	s += this.getHours() + ":";
	s += this.getMinutes() + ":";
	s += this.getSeconds();
	return s;
}

function setUrlParam(param, value, url) {
	var i, j, pt;
	if (!url) url = window.location.href.replace(/\#/g, "");
	pt = "&" + param + "="; i = url.indexOf(pt);
	if (i < 0) {
		pt = "?" + param + "="; i = url.indexOf(pt);
		if (i < 0) { if (url.indexOf("?") > 0) url += "&" + param + "=" + value; else url += "?" + param + "=" + value; return url; }
	}
	j = url.indexOf("&", i + 1);
	if (j > 0) url = url.substring(0, i) + pt + value + url.substring(j, url.length);
	else url = url.substring(0, i) + pt + value;
	return url;
}
function getUrlParam(param) {
	var url = window.location.href;
	var re = new RegExp("(\\\?|&)" + param + "=([^&#]+)(&|$|#)", "i");
	var m = url.match(re);
	if (m) return m[2];
	else return '';
}

jQuery.cookie = function(name, value, options) { if (typeof value != 'undefined') { options = options || {}; if (value === null) { value = ''; options.expires = -1; }; var expires = ''; if (options.expires && (typeof options.expires == 'number' || options.expires.toUTCString)) { var date; if (typeof options.expires == 'number') { date = new Date(); date.setTime(date.getTime() + (options.expires * 24 * 60 * 60 * 1000)); } else { date = options.expires; }; expires = '; expires=' + date.toUTCString(); }; var path = options.path ? '; path=' + (options.path) : ''; var domain = options.domain ? '; domain=' + (options.domain) : ''; var secure = options.secure ? '; secure' : ''; document.cookie = [name, '=', encodeURIComponent(value), expires, path, domain, secure].join(''); } else { var cookieValue = null; if (document.cookie && document.cookie != '') { var cookies = document.cookie.split(';'); for (var i = 0; i < cookies.length; i++) { var cookie = jQuery.trim(cookies[i]); if (cookie.substring(0, name.length + 1) == (name + '=')) { cookieValue = decodeURIComponent(cookie.substring(name.length + 1)); break; } } }; return cookieValue; } };

function pathLevel() {
	var dir = "";
	for (var i = 1; i < location.pathname.split("/").length - 1; i++) { dir += "../" }
	return dir;
}
function _replaceHF(full) {
	return full.replace(/０/g, '0').replace(/１/g, '1').replace(/２/g, '2').replace(/３/g, '3').replace(/４/g, '4').replace(/５/g, '5').replace(/６/g, '6').replace(/７/g, '7').replace(/８/g, '8').replace(/９/g, '9');
}

function AutoSize(width, height) {
	if (window.parent.Boxy) {
		var bx = window.parent.Boxy.iframeBoxy;
		bx.resize(width, height);
		bx.center();
	}
}
/*检验手机号码是否正确*/
function CheckMobileVali(strMobile) {
	var blVali = true;
	var re = /0755\d{8}/gi;
	if (strMobile.length == 11) { re = /01[^3\D]\d{8}|0[^1\D]\d{9}|13\d{9}|15\d{9}|18\d{9}/gi; }
	else if (strMobile.length == 12)
	{ re = /01[^3\D]\d{9}|0[^1\D]\d{10}/gi; }
	else return false;
	if (strMobile.match(re)) { blVali = true; }
	else { blVali = false; }
	return blVali;
}

function showcheckcode(divId, imgId, vId,prefix) {
	var odiv = s$(divId);
	if (odiv.className == "visible") return;
	odiv.className = "visible";
	newverifypic(imgId, vId,prefix);
}
function newverifypic(imgId, vId,prefix) {
	s$(imgId).src = (typeof(prefix)=="undefined" ? "":prefix) + 'vldcd.ashx?i=' + vId + '&t=' + (new Date().getTime());
}

function CheckAll(form) {
	for (var i = 0; i < form.elements.length; i++) {
		var e = form.elements[i];
		if (e.name != 'chkall' && e.type == 'checkbox')
			e.checked = form.chkall.checked;
	}
}

function McndSearch() {
	if (s$("SearchClassId").selectedIndex == 0) {
		var srchUrl = "../srchBidItem.aspx";
		srchUrl = setUrlParam("c", "0", srchUrl);
		srchUrl = setUrlParam("q", escape(s$("SearchKeyword2").value), srchUrl);
		var mode = getUrlParam("m");
		srchUrl = setUrlParam("m", mode, srchUrl);
		window.location.href = srchUrl;
	}
	else if (s$("SearchClassId").selectedIndex == 1) {
		var productUrl = "../srchproduct.aspx";
		productUrl = setUrlParam("c", "0", productUrl);
		productUrl = setUrlParam("q", escape(s$("SearchKeyword2").value), productUrl);
		window.location.href = productUrl;
	}
	else {
		var shopUrl = "../srchShop.aspx";
		shopUrl = setUrlParam("c", "0", shopUrl);
		shopUrl = setUrlParam("q", escape(s$("SearchKeyword2").value), shopUrl);
		window.location.href = shopUrl;
	}
}
function HotSearch(q) {
	s$("SearchKeyword2").value = q;
	McndSearch();
}
function EnterSearch() {
	if (event.keyCode == 13) McndSearch();
}

function log(p) { window.top.location = '../log' + p + '.aspx?ReturnUrl=' + escape(window.top.location); } //login|out
function tbLoginShow(prefix){
	if(typeof(prefix)=="undefined"){prefix="";}
	Boxy.iframeLoad(prefix+"login.aspx?close=1", { title: "登录白不拍" })
}
function CheckMobile(close) { Boxy.iframeLoad("../security/CheckMobile.aspx" + (close ? "?close=1" : ""), { title: '验证手机号' }) }
function NewMsg(msg, vldCode, pageTag, type, dstId, path) {
	if (msg.length < 1) { alert("请输入留言！"); return; }
	if (vldCode.length < 4) { alert("请注意，验证码长度为4位！"); return; }
	var url = (path) ? path + "/AddMsg.ashx" : "AddMsg.ashx";
	$.getJSON(url, { m: escape(msg), v: escape(vldCode), p: pageTag, t: type, d: dstId },
	function(data) {
		if (data.result == 0) {
			alert("留言成功！");
			location.reload();
		}
		else {
			if (data.result == 2) { tbLoginShow(); }
			else if (data.result == 4) {
				alert(data.msg);
				CheckMobile(1);
			}
			else alert(data.msg);
		}
	});
}

function AddRmk(vldCode, rmkString, type, DstId, f1, f2, f3, f4, f5, memo, PageTag) {
	if (vldCode.length < 4) { alert("请注意，验证码长度为4位！"); return; }
	if (rmkString.trim().length < 10) { alert("点评内容不到10个字哦，太短了，在写点吧。"); return; }
	if (f1 == "") { alert("请为" + s$("RemarkQuestion0").innerHTML + "打分"); return; }
	if (f2 == "") { alert("请为" + s$("RemarkQuestion1").innerHTML + "打分"); return; }
	if (f3 == "") { alert("请为" + s$("RemarkQuestion2").innerHTML + "打分"); return; }
	if (f4 == "") { alert("请为" + s$("RemarkQuestion3").innerHTML + "打分"); return; }
	var url = "../addRmk.ashx";
	$.getJSON(url, { v: escape(vldCode), r: escape(rmkString), p: PageTag, t: type, d: DstId,
		f1: f1, f2: f2, f3: f3, f4: f4, f5: f5, m: memo
	},
	function(data) {
		if (data.result == 0) {
			alert("点评成功！");
			location.reload();
		}
		else {
			if (data.result == 2) { tbLoginShow(); }
			else if (data.result == 3) {
				alert(data.msg);
				CheckMobile(1);
			}
			else alert(data.msg);
		}
	});
}

function Add2Cart(pid, qnt, book, earnest) {
	if (book) {
		if (!confirm("您选择预订后，系统将自动扣除您" + earnest + "两白金作为订金，您确定预订吗？")) return;
	}
	var AddCartBox = new Boxy("<div>正在处理，请稍后...<img src='../images/loading.gif' /></div>");
	var url = "/Add2Cart.ashx";
	$.getJSON(url, { p: pid, q: qnt, s: earnest }, function(rst) {
		AddCartBox.setContent("<div>" + rst.msg + "</div>");
		AddCartBox.center();
		if (s$("cartCount") && rst.count > 0) { $("#cartCount").html(rst.count); }
		setTimeout(function() { AddCartBox.hide() }, 4000);
		switch (rst.result) {
			case 6: setTimeout("tbLoginShow()", 2500); break;
			case 4: setTimeout("CheckMobile(true)", 2500); break;
			case 7: setTimeout("CheckMobile(true)", 2500); break;
			default: break;
		}
	});
}

function SwitchDiv(id) {
	var i = 0;
	while (i <= MaxTabCount) {
		s$("tab_" + i).className = "";
		i++;
	}
	s$("tab_" + id).className = "current";
	i = 0;
	if (id != 0) {
		while (i <= MaxTabCount) {
			s$("Title_" + i).className = "Hide";
			s$("TabDiv_" + i).className = "Hide";
			i++;
		}
		s$("TabDiv_" + id).className = "TabDiv";
	}
	if (id == 0) {
		while (i <= MaxTabCount) {
			s$("TabDiv_" + i).className = "TabDiv";
			s$("Title_" + i).className = "TabBar";
			s$("Title_" + id).className = "Hide";
			i++;
		}
	}
}

function gn(i) {//左侧菜单的收放效果
	if (s$("tb" + i).style.display == "none") {
		s$("ico" + i).src = "../images/ico_top1.gif";
		s$("tb" + i).style.display = "block";
	}
	else {
		s$("ico" + i).src = "../images/ico_top2.gif";
		s$("tb" + i).style.display = "none";
	}
}

function CloseMe() {
	if (window.parent.Boxy) {
		window.parent.Boxy.iframeBoxy.hide();
		if (parent.topbar) {
			parent.topbar.location.reload();
		}
	}
}

function checkLoginState(){
	return ($.cookie('dnt')!=null);
}

var rmkQst = [['性价比', '口感', '包装', '物流配送'],
['口味', '环境', '服务', '性价比'],
['服务', '质量', '环境', '性价比'],
['性价比', '质量', '功能', '外观'],
['口感', '包装', '功效', '性价比'],
['师资水准', '设备环境', '教学效果', '性价比'],
['音乐舞蹈', '杂技魔术', '服装道具', '性价比'],
['风光', '娱乐', '食宿', '性价比']
];

function serialize(_obj) {
	switch (typeof _obj) {
		case 'number':
		case 'boolean':
		case 'function': return _obj; break;
		case 'string': return '\'' + _obj + '\''; break;
		case 'object':
			var str;
			if (_obj.constructor === Array || typeof _obj.callee !== 'undefined') {
				str = '[';
				var i, len = _obj.length;
				for (i = 0; i < len - 1; i++) { str += serialize(_obj[i]) + ','; }
				str += serialize(_obj[i]) + ']';
			}
			else {
				str = '{';
				var key;
				for (key in _obj) { str += '\'' + key + '\'' + ':' + serialize(_obj[key]) + ','; }
				str = str.replace(/\,$/, '') + '}';
			}
			return str;
			break;
		default: return ''; break; //unknown
	}
}