﻿
/**
 * 全站公用JS
 */
try {
	document.domain = 'seeyoo.cc';
	if (top.location != location) {
		typeof stop == 'undefined' ? document.execCommand('stop') : stop();
		top.location.replace(location.href);
	}
	preload();
	register_func(init_dropdown);
	register_func(init_iepngfix);
	$(document).ready(function() {
		if (!window.register_called) {
			register_call();
		}
	});
} catch(err) {}


// 注册加载函数
function register_func(func) {
	if (typeof window.functions == 'undefined') {
		window.functions = new Array;
	}
	window.functions.push(func);
}

// 调用注册函数
function register_call() {
	if (typeof window.register_called != 'undefined') {
		return false;
	}
	if (typeof window.functions != 'undefined') {
		window.register_called = true;
		try {
			for (var i in window.functions) {
				window.functions[i].apply(window);
			}
		} catch(err) {
			alert('页面初始化失败：' + err.description);
		}
	}
}

// 导航下拉菜单
function init_dropdown() {
	this.timer = null;
	this.alias = this;
	this.show_dropdown = function() {
		clearTimeout(alias.timer);
		$('#dropdown_div').show();
	}
	this.hide_dropdown = function() {
		alias.timer = setTimeout(function() {
			$('#dropdown_div').hide();
		}, 200);
	}
	$('#dropdown').bind('mouseleave', hide_dropdown);
	$('#dropdown, #dropdown_div').bind('mouseenter', show_dropdown);
}

// IE6 PNG修正
function init_iepngfix() {
	if ($.browser.msie && $.browser.version < 7) {
		$('img[src$=.png]').addClass('png');
	}
}

// 页面内容预加载
function preload() {
	var files = [
		'http://pic.seeyoo.cc/js/calendar/My97DatePicker.htm'
	];
	var buffer = [];
	for (var i in files) {
		buffer[i] = new Image;
		buffer[i].src = files[i];
	}
}

// 酒店区域选项
function hotel_area_opts(city_name, selected) {
	var tmp, html = new Array;
	html.push('<option value="">选择区域</option>');
	for (var i in HA) {
		if (HA[i].city_name == city_name) {
			if (HA[i].area_name == selected) {
				tmp = '<option value="' + HA[i].area_name + '" selected="selected">' + HA[i].area_name + '</option>';
			} else {
				tmp = '<option value="' + HA[i].area_name + '">' + HA[i].area_name + '</option>';
			}
			html.push(tmp);
		}
	}
	return html.join('\n');
}

// 拼凑字段对象
function form_fields(fields) {
	var obj = {};
	$.each(fields, function() {
		eval('obj.' + this + ' = "' + $('#' + this).val() + '";');
	});
	return obj;
}

// 创建TAB组
function init_tab_set(option) {
	var params = {id:null, selected:0, event:'mouseover', cookie:false};
	for (var i in params) {
		if (typeof eval('option.' + i) == 'undefined') {
			eval('option.' + i + ' = params.' + i + ';');
		}
	}
	if (option.id == null) {
		return false;
	}
	var links = $('#' + option.id + ' a');
	links.bind(option.event, function() {
		links.map(function() {
			$('#' + $(this).attr('tab')).hide();
			$(this).parents('li').removeClass('current');
		});
		$('#' + $(this).attr('tab')).show();
		$(this).parents('li').addClass('current');
		return false;
	});
	option.selected = Math.abs(option.selected);
	if (option.selected > links.get().length - 1) {
		option.selected = 0;
	}
	links.eq(option.selected).trigger(option.event);
}

// 数字千位分割
Number.prototype.toThousand = function() {
	var str = '' + this;
	var tmp = '';
	for (var i = 1; i <= str.length; i++) {
		tmp = '' + str.charAt(str.length - i) + tmp;
		if (i != str.length && i % 3 == 0) {
			tmp = ',' + tmp;
		}
	}
	return tmp;
};

// 字符串转日期
function strtotime(str) {
	var arr = str.split('-');
	if (arr.length != 3) {
		return new Date();
	}
	return new Date(arr[0], arr[1] - 1, arr[2]);
}

// 比较日期差值
function datediff(date1, date2, type) {
	var d1 = strtotime(date1);
	var d2 = strtotime(date2);
	var diff = (d1 - d2) / 1000;
	if (type == 1) {
		return Math.round(diff / 60 / 60 / 24);
	}
	return diff;
}

// 加入收藏
function doAddFav(url, title) {
	try {
		window.external.AddFavorite(url, title);
	} catch(err) {
		alert('请按 Ctrl + D 键收藏当前页面!');
	}
}

// 复制链接
function doCopyTxt(txt, msg) {
	if (window.clipboardData && window.clipboardData.setData('TEXT', txt)) {
		if (typeof msg != 'undefined' && msg.length > 0) {
			alert(msg);
		}
		return;
	}
	alert('操作被浏览器禁止, 请修改浏览器设置或手动复制地址栏中的地址!');
}

// 打印窗口
function doPrint() {
	try {
		window.print();
	} catch(err) {}
}

// 显示加载
function showLoading() {
	hideLoading();
	$('body').append('<div id="loading-box"></div><div id="loading-img"></div>');
}

// 隐藏加载
function hideLoading() {
	$('#loading-box, #loading-img').remove();
}


/*
 * Date Format 1.2.3
 * (c) 2007-2009 Steven Levithan <stevenlevithan.com>
 * MIT license
 *
 * Includes enhancements by Scott Trenda <scott.trenda.net>
 * and Kris Kowal <cixar.com/~kris.kowal/>
 *
 * Accepts a date, a mask, or a date and a mask.
 * Returns a formatted version of the given date.
 * The date defaults to the current date/time.
 * The mask defaults to dateFormat.masks.default.
 */

var dateFormat = function () {
	var	token = /d{1,4}|m{1,4}|yy(?:yy)?|([HhMsTt])\1?|[LloSZ]|"[^"]*"|'[^']*'/g,
		timezone = /\b(?:[PMCEA][SDP]T|(?:Pacific|Mountain|Central|Eastern|Atlantic) (?:Standard|Daylight|Prevailing) Time|(?:GMT|UTC)(?:[-+]\d{4})?)\b/g,
		timezoneClip = /[^-+\dA-Z]/g,
		pad = function (val, len) {
			val = String(val);
			len = len || 2;
			while (val.length < len) val = "0" + val;
			return val;
		};

	// Regexes and supporting functions are cached through closure
	return function (date, mask, utc) {
		var dF = dateFormat;

		// You can't provide utc if you skip other args (use the "UTC:" mask prefix)
		if (arguments.length == 1 && Object.prototype.toString.call(date) == "[object String]" && !/\d/.test(date)) {
			mask = date;
			date = undefined;
		}

		// Passing date through Date applies Date.parse, if necessary
		date = date ? new Date(date) : new Date;
		if (isNaN(date)) throw SyntaxError("invalid date");

		mask = String(dF.masks[mask] || mask || dF.masks["default"]);

		// Allow setting the utc argument via the mask
		if (mask.slice(0, 4) == "UTC:") {
			mask = mask.slice(4);
			utc = true;
		}

		var	_ = utc ? "getUTC" : "get",
			d = date[_ + "Date"](),
			D = date[_ + "Day"](),
			m = date[_ + "Month"](),
			y = date[_ + "FullYear"](),
			H = date[_ + "Hours"](),
			M = date[_ + "Minutes"](),
			s = date[_ + "Seconds"](),
			L = date[_ + "Milliseconds"](),
			o = utc ? 0 : date.getTimezoneOffset(),
			flags = {
				d:    d,
				dd:   pad(d),
				ddd:  dF.i18n.dayNames[D],
				dddd: dF.i18n.dayNames[D + 7],
				m:    m + 1,
				mm:   pad(m + 1),
				mmm:  dF.i18n.monthNames[m],
				mmmm: dF.i18n.monthNames[m + 12],
				yy:   String(y).slice(2),
				yyyy: y,
				h:    H % 12 || 12,
				hh:   pad(H % 12 || 12),
				H:    H,
				HH:   pad(H),
				M:    M,
				MM:   pad(M),
				s:    s,
				ss:   pad(s),
				l:    pad(L, 3),
				L:    pad(L > 99 ? Math.round(L / 10) : L),
				t:    H < 12 ? "a"  : "p",
				tt:   H < 12 ? "am" : "pm",
				T:    H < 12 ? "A"  : "P",
				TT:   H < 12 ? "AM" : "PM",
				Z:    utc ? "UTC" : (String(date).match(timezone) || [""]).pop().replace(timezoneClip, ""),
				o:    (o > 0 ? "-" : "+") + pad(Math.floor(Math.abs(o) / 60) * 100 + Math.abs(o) % 60, 4),
				S:    ["th", "st", "nd", "rd"][d % 10 > 3 ? 0 : (d % 100 - d % 10 != 10) * d % 10]
			};

		return mask.replace(token, function ($0) {
			return $0 in flags ? flags[$0] : $0.slice(1, $0.length - 1);
		});
	};
}();

// Some common format strings
dateFormat.masks = {
	"default":      "ddd mmm dd yyyy HH:MM:ss",
	shortDate:      "m/d/yy",
	mediumDate:     "mmm d, yyyy",
	longDate:       "mmmm d, yyyy",
	fullDate:       "dddd, mmmm d, yyyy",
	shortTime:      "h:MM TT",
	mediumTime:     "h:MM:ss TT",
	longTime:       "h:MM:ss TT Z",
	isoDate:        "yyyy-mm-dd",
	isoTime:        "HH:MM:ss",
	isoDateTime:    "yyyy-mm-dd'T'HH:MM:ss",
	isoUtcDateTime: "UTC:yyyy-mm-dd'T'HH:MM:ss'Z'"
};

// Internationalization strings
dateFormat.i18n = {
	dayNames: [
		"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat",
		"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"
	],
	monthNames: [
		"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec",
		"January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"
	]
};

// For convenience...
Date.prototype.format = function (mask, utc) {
	return dateFormat(this, mask, utc);
};

/**
 * END dateFormat
 */



