var lots = {
	'sfc': {
		name: '胜负彩'
	},
	'jq4': {
		name: '四场进球'
	},
	'zc6': {
		name: '半全场'
	},
	'syxq': {
		name: '31选7'
	},
	'ssq': {
		name: '双色球'
	},
	'sd': {
		name: '福彩3D'
	},
	'qlc': {
		name: '七乐彩'
	},
	'eexw': {
		name: '22选5'
	},
	'dlt': {
		name: '大乐透'
	},
	'pls': {
		name: '排列三'
	},
	'qxc': {
		name: '七星彩'
	},
	'plw': {
		name: '排列五'
	}
};
var el = fm.get('#lotTypeSelect', 0);
var list = fm.get('#selectLotQuery', 0);
function addLotType() {
	for (var key in lots) {
		el.options.add(new Option(lots[key].name, key, 0, 0));
	};
	fm.on(el, 'change', loadExpect);
};
function loadExpect() {
	var lot = lots[this.value];
	list.length = 0;
	if (!lot) {
		return list.options.add(new Option('选择期号', 0, 0, 0));
	} else {
		list.options.add(new Option('选择期号', 0, 0, 0));
	};
	var opts = {
		from: 'http://'+location.host+'/static/info/kaijiang/xml/' + this.value + '/list.xml',
		load: function(h, x) {
			list.length = 0;
			fm.xml(x).get('//row',
			function() {
				var ex = this.attr('expect');
				list.options.add(new Option(ex, ex, 0, 0))
			})
		},
		error: function() {
			list.length = 0;
			list.options.add(new Option('-----', 0, 0, 0))
		}
	};
	fm.Ajax(opts);
};

/*
* location
*/
var names = [
'group-华东六省',
'东方6+1&df6j1',
'福彩15选5&hdswxw',
'group-北京',
'福彩两步彩&bjebc',
'体彩33选7&bjssxq',
'体彩36选7&bjslxq',
'group-上海',
'福彩天天彩选4&ttcx4',
'福彩15选5&hdswxw',
'group-天津',
'福彩15选5&hdswxw',
'体彩6+1&tjljy',
//'group-重庆',
//'福彩20选5&cqesxw',
'group-江苏',
'体彩7位数&zjsyxq',
'福彩15选5&hdswxw',
'体彩5+1&js5j1',
'group-浙江',
'体彩20选5&zjesxw',
'体彩31选7&zjsyxq',
'体彩6+1&zj6j1',
'福彩15选5&hdswxw',
'group-福建',
'福建36选7&fjslxq',
'体彩22选5&fjeexw',
'体彩31选7&fjsyxq',
'福彩15选5&hdswxw',
'group-广东',
'福彩好彩1&gdhc1',
'体彩36选7&gdtcslxq',
'福彩26选5&gdelxw',
'福彩36选7&gdslxq',
'group-深圳',
'深圳风采&szfc',
'group-黑龙江',
'福彩P62&hljp62',
'体彩6+1&hlj6j1',
'福彩22选5&hljeexw',
'福彩36选7&hljslxq',
'group-四川',
'福彩22选5&ygcttl',
'group-辽宁',
'福彩35选7&lnswxq',
'group-河北',
'福彩排列5&hbplw',
'福彩20选5&hbesxw',
'福彩好运2&hbhy2',
'福彩好运3&hbhy3',
'福彩排列7&hbplq',
'group-河南',
'福彩22选5&zyeexw',
'group-湖北',
'福彩22选5&cteexw',
'group-山东',
'福彩23选5&sdesxw',
'group-山西',
'福彩21选5&sxeyxw',
'group-云南',
'福彩21选5&ynttl',
'group-内蒙古',
'福彩22选5&nmeexw',
'group-新疆',
'福彩35选7&xjswxq',
'福彩偶数10选7&xjsxq',
'福彩25选7&xjewxq',
'福彩18选7&xjsbxq',
'group-广西',
'福彩快乐双彩&klsc',
'group-湖南',
'福彩22选5&hneexw',
'group-江西',
'福彩15选5&hdswxw',
'group-安徽',
'福彩25选5&ahewxw',
'福彩15选5&hdswxw',
'group-贵州',
'福彩天天乐&ygcttl'
];
function addLotType2() {
	var el = fm.get('#lotTypeSelect2', 0);
	names.each(function(i) {
		if(/group-/.test(this)){
			var g=document.createElement('OPTGROUP');
			g.label=this.split('-')[1];
			el.appendChild(g);
		}else{
			var d=this.split('&');
			el.options.add(new Option(d[0], d[1], 0, 0));
		};
	});
	fm.on(el, 'change', loadExpect2);
};
function loadExpect2() {
	var list = fm.get('#selectLotQuery2', 0);
	var lot = this.value;
	list.length = 0;
	if (!lot) {
		return list.options.add(new Option('选择期号', 0, 0, 0));
	} else {
		list.options.add(new Option('选择期号', 0, 0, 0));
	};
	var opts = {
		from: 'http://'+location.host+'/static/info/kaijiang/xml/' + this.value + '/list.xml',
		load: function(h, x) {
			list.length = 0;
			fm.xml(x).get('//row',
			function() {
				var ex = this.attr('expect');
				list.options.add(new Option(ex, ex, 0, 0))
			})
		},
		error: function() {
			list.length = 0;
			list.options.add(new Option('-----', 0, 0, 0))
		}
	};
	fm.Ajax(opts);
};
/*
* gao pin
*/
var prevType = false; //彩种信息
var lots3 = {
	'ssl': {
		area: '上海',
		lotname: '时时乐',
		date: '2006/08/30',
		file: '/static/public/ssl/xml/opencode.xml',
		infourl: 'kj_ssl.shtml',
		count:23,
		fq:30
	},
	'ssc': {
		area: '重庆',
		lotname: '时时彩',
		date: '2007/05/21',
		file: '/static/public/ssc/xml/newlyopen.xml',
		infourl: 'kj_ssc.shtml',
		count:120//,
		//fq:10
	},
	'qyh': {
		area: '山东',
		lotname: '群英会',
		//file: '/static/public/syydj/xml/historyopen.xml',
		file: '/static/info/kaijiang/xml/qyh/newlyopen.xml',
		infourl: 'kj_qyh.shtml',
		count:40,
		fq:15
	},
	'syydj': {
		area: '山东',
		lotname: '十一运夺金',
		date: '2009/11/18',
		//file: '/static/public/syydj/xml/historyopen.xml',
		file: '/static/info/kaijiang/xml/syydj/newlyopen.xml',
		infourl: 'kj_syydj.shtml',
		count:52,
		fq:10
	},
	'dlc': {
		area: '江西',
		lotname: '11选5',
		file: '/static/public/dlc/xml/historyopen.xml',
		infourl: 'kj_dlc.shtml',
		count:65,
		fq:12
	},
	'kl8': {
		area: '北京',
		lotname: '快乐8',
		date: '2009/08/09',
		file: '/static/info/kaijiang/xml/kl8/newlyopen.xml',
		infourl: 'kj_kl8.shtml',
		count:179,
		fq:5
	},/*
	'kl123': {
		area: '重庆',
		lotname: '快乐123',
		date: '2009/03/14',
		file: '/static/info/kaijiang/xml/kl123/newlyopen.xml',
		infourl: 'kj_kl123.shtml',
		count:72,
		fq:10
	},*/
	'ytdj': {
		area: '山西',
		lotname: '泳坛夺金',
		date: '2009/04/19',
		file: '/static/info/kaijiang/xml/ytdj/newlyopen.xml',
		infourl: 'kj_ytdj.shtml',
		count:79,
		fq:10
	},
	'gdklsf': {
		area: '广东',
		lotname: '快乐十分',
		date: '2009/06/27',
		file: '/static/info/kaijiang/xml/gdklsf/newlyopen.xml',
		infourl: 'kj_gdklsf.shtml',
		count:78,
		fq:10
	},
	'gxklsf': {
		area: '广西',
		lotname: '快乐十分',
		date: '2009/08/17',
		file: '/static/info/kaijiang/xml/gxklsf/newlyopen.xml',
		infourl: 'kj_gxklsf.shtml',
		count:50,
		fq:10
	},
	'klpk': {
		area: '安徽',
		lotname: '快乐扑克',
		date: '2009/08/09',
		file: '/static/info/kaijiang/xml/klpk/newlyopen.xml',
		infourl: 'kj_klpk.shtml',
		count:48,
		fq:15
	},
	'scpkc': {
		area: '四川',
		lotname: '扑克彩?十分乐',
		date: '2009/08/17',
		file: '/static/info/kaijiang/xml/pkcsfl/newlyopen.xml',
		infourl: 'kj_scpkc.shtml',
		count:52,
		fq:12
	}
};
var list1 = fm.get('#selectLotType3', 0);
var list2 = fm.get('#selectLotQuery3', 0); //填充查询彩种
var addSelectType = function() {
	var sel = list1;
	var list = sel.options;
	for (var Id in lots3) {
		var lot = lots3[Id];
		list.add(new Option(lot.area+lot.lotname, Id, 0, 0))
	};
	fm.on(sel, 'change', fullQueryList);
};
function getBackTime(back) {
	var now = new Date;
	now.setDate(now.getDate() + back);
	return now.get('YY/MM/DD');
}; //填充查询日期
function fullQueryList() {
	var lotId = this.value;
	if (prevType == lotId) return;
	var el = list2;
	el.innerHTML = '';
	if (lotId == 'null') return el.options.add(new Option('选择日期', '', 0, 0)),
	prevType = null;
	el.options.add(new Option('选择期号', '', 0, 0));
	if (/qyh|dlc/.test(lotId)) {//按xml表
		var lot = lots3[lotId];
		fm.Ajax('http://'+location.host+lot.file,
		function(h, x) {
			el.innerHTML = '';
			var only = [],
			opts = [];
			fm.xml(x).get('//row',
			function() {
				var d = this.attr('abbdate');
				if (!only[d]) {
					only[d] = true;
					opts.push(new Option(d, d, 0, 0));
				}
			});
			opts.reverse().each(function() {
				el.options.add(this);
			});
		});
	} else {//按起始时间生成期号
		var begin = new Date(lots3[lotId].date || getBackTime( - 7));
		var now = new Date;
		/*if(lotId=='syydj'){// syydj not found data in today.
			now.setDate(now.getDate() - 1);
		};*/
		setTimeout(function() {
			el.innerHTML = '';
			if(begin >= now){
				return el.options.add(new Option('--------', '--------', 0, 0));
			};
			while (begin < now) {
				var time = now.get();
				el.options.add(new Option(time.replace(/-/g, ''), time, 0, 0));
				now.setDate(now.getDate() - 1);
			};
		},
		1);
	};
	prevType = lotId;
	fm.get('#searchBtn3', 0).onclick = function() {
        var list = fm.get('#selectLotQuery3', 0);
	     var el = fm.get('#lotTypeSelect3', 0);
		//var url = 'kj_' + list1.value + '.shtml?expect=' + list2.value.replace(/-/g, '');
	    var url = 'http://kaijiang.500wan.com/'+list1.value+'.shtml?expect=' + list2.value.replace(/-/g, '');
		window.open(url);
		return false;
	};
};
/*
* run here
*/
addLotType();
addLotType2();
addSelectType();
fm.on('#searchBtn', 'click',function() {

    var list = fm.get('#selectLotQuery', 0);
	var el = fm.get('#lotTypeSelect', 0);
	if (list.value == '0' || list.value == undefined || list.value == '') return;
	window.open('http://kaijiang.500wan.com/shtml/'+el.value+'/'+list.value+'.shtml');
	return false;

});
fm.on('#searchBtn2', 'click',function() {

	var list = fm.get('#selectLotQuery2', 0);
	var el = fm.get('#lotTypeSelect2', 0);
	if (list.value == '0' || list.value == undefined || list.value == '') return;
	window.open('http://kaijiang.500wan.com/shtml/'+el.value+'/'+list.value+'.shtml');
	return false;
});
/*
* menu nav
*/
var allContent=fm.get('#content1,#content2,#content3');
var allNav=fm.get('#title1,#title2,#title3');
allNav.each(function(i){
	fm.on(this,'mouseover',function(){
		allContent.each(function(){this.style.display='none'});
		allContent[i].style.display='';
		allNav.each(function(){this.className='nav2'});
		this.className='nav1';
	})
});



function _autoFitHeight(){
	if (self==top) return;
	var iframe = document.getElementById("hiddenIframe");
	if (!iframe){
		var div = document.createElement("div");
		div.innerHTML = '<iframe id="hiddenIframe" width="0" height="0" style="display:none;"></iframe>';
		document.body.appendChild(div);
		iframe = div.firstChild;
	}
	if(window.opera){
		var hh=document.documentElement.clientHeight+8;
	}else{
		var hh=document.body.clientHeight+8;
	}
	iframe.src = 'http://tool.115.com/static/cp/proxy.html?height='+hh;

}

function autoFitHeight(){
	window.setTimeout("_autoFitHeight()", 400);
}

autoFitHeight();