﻿<!--
/*ͳһTAB*/
function setTab(name,cursel,n){
 for(i=1;i<=n;i++){
  var menu=document.getElementById(name+i);
  var con=document.getElementById("con_"+name+"_"+i);
  menu.className=i==cursel?"hover":"";
  con.style.display=i==cursel?"block":"none";
 }
}
//-->


/**
 * 全站公用JS
 */
try {
	document.domain = '';
	if (top.location != location) {
		typeof stop == 'undefined' ? document.execCommand('stop') : stop();
		top.location.replace(location.href);
	}
	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.functions != 'undefined') {
		for (var i in window.functions) {
			window.functions[i].apply(window);
		}
	}
}

// 导航下拉菜单
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 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();
}

