// JavaScript Document
/*
*Author JHG
*Date: 2008-12-20 Copyright (c) 2008 CECQ.COM | ChongErUU.CN
*/
	var widths=795; 
	if (navigator.appName=='Microsoft Internet Explorer'){var heights=309;}else{var heights=306;};	
	var counts=5; 
	//img1=new Image ();img1.src="/img/b1.jpg"; img1.url="http://mall.meiling.com";
	img1=new Image ();img1.src="/img/b1.jpg"; img1.url="/";
	img2=new Image ();img2.src="/img/b2.jpg"; img2.url="/";
	img3=new Image ();img3.src="/img/b3.jpg"; img3.url="/";
	img4=new Image ();img4.src="/img/b4.jpg"; img4.url="/";
	img5=new Image ();img5.src="/img/b5.jpg"; img5.url="/";
	var nn=1; 
	var key=0; 
	function change_img() 
	{if(key==0){key=1;} 
	else if(document.all) 
	{document.getElementById("pic").filters[0].Apply();document.getElementById("pic").filters[0].Play(duration=2);} 
	eval('document.getElementById("pic").src=img'+nn+'.src'); 
	eval('document.getElementById("url").href=img'+nn+'.url'); 
	//eval('document.getElementById("url").href=url'+nn+'.src'); 
	for (var i=1;i<=counts;i++){document.getElementById("li"+i).className='lightoff';eval('document.getElementById("li'+i+'").src=img'+i+'.src'); } 
	document.getElementById("li"+nn).className='lighton'; 
	eval('document.getElementById("li'+nn+'").src=img'+nn+'.src'); 
	nn++;if(nn>counts){nn=1;} 
	tt=setTimeout('change_img()',6000);} 
	
	function changeimg(n){nn=n;window.clearInterval(tt);change_img();} 
	
	function ppt(){
	document.write("<style>");
	document.write("* {margin:0px 0px 0px 0px; padding:0px 0px 0px 0px; list-style:none;}");	
	
	if (navigator.appName=='Microsoft Internet Explorer'){
	document.write("#href { z-index:1000;position:absolute; widows:795px; width:795px; background:#ffffff; filter:Alpha(opacity=0);}");
	document.write("#content .left{width:785px;height:317px;overflow:hidden;float:left; position:relative; margin:0px 5px 0px 2px; clear:right; }");
	document.write("#content .right li {padding:0px 0px 2px 0px;	height:57px!important;height:57px;overflow:hidden;}");
	document.write("#content .right li img {height:58px; filter:progid:DXImageTransform.Microsoft.Alpha(opacity=30);-moz-opacity:0.5; border:0px;}");}
	else if (navigator.appName=='Netscape'){
	document.write("#href { z-index:1000;position:absolute; widows:795px; width:795px;}");
	document.write("#content .left{width:785px;height:304px;overflow:hidden;float:left;position:relative; margin:0px 5px 0px 5px; clear:right;}");
	document.write("#content .right li {padding:0px 0px 2px 0px;	height:59px!important;height:60px;overflow:hidden;}");
	document.write("#content .right li img {height:60px; filter:progid:DXImageTransform.Microsoft.Alpha(opacity=30);-moz-opacity:0.5; border:0px;}");}
	
	document.write("#content {width:930px; height:305px; margin:0px 0px 0px 0px; padding:0px 0px 6px 0px;overflow:hidden;}");	
	document.write("#href a{height:305px;widows:785px; display:block; width:785px; z-index:1000}");
	document.write("#picarea {position:relative; z-index:900; top:0px; left:0px; overflow:hidden; height:306px;}");
	document.write("#content .right{width:130px;	height:auto;overflow:hidden;float:left; text-align:left;}");
	document.write("#content .right ul{margin:0px 0px 5px 0px;padding:0px;list-style:none;height:auto;overflow:hidden;}");	
	document.write("#content .right li:hover img {filter:progid:DXImageTransform.Microsoft.Alpha(opacity=100);-moz-opacity:1;}");
	document.write("#content .lighton {filter:progid:DXImageTransform.Microsoft.Alpha(opacity=100) !important;	-moz-opacity:1 !important;}");
	document.write("#content .lightoff {filter:progid:DXImageTransform.Microsoft.Alpha(opacity=30);	-moz-opacity:0.3;}");
	document.write("</style>");
	
	document.write("<div id='content'>");
	document.write("<div class='left'><div id='href'><a id=url target='_blank'></a></div><div id='picarea'><img id='pic' style='border:0px;filter:progid:dximagetransform.microsoft.wipe(gradientsize=1.0,wipestyle=4, motion=forward)' width='"+widths+"' height='"+heights+"'></div></div>");
	document.write("<div class='right'><ul>");
	for(var i=1;i<counts+1;i++){document.write('<li><a href="javascript:" class="lighton" target="_self"><img id="li'+i+'" onClick="changeimg('+i+');"></a>');}
	document.write("</ul></div>");
	document.write("</div>");
	change_img(); 
	}

/*************************************************************/
var $ = function (id) {
    return "string" == typeof id ? document.getElementById(id) : id;
};

function Event(e){
	var oEvent = document.all ? window.event : e;
	if (document.all) {
		if(oEvent.type == "mouseout") {
			oEvent.relatedTarget = oEvent.toElement;
		}else if(oEvent.type == "mouseover") {
			oEvent.relatedTarget = oEvent.fromElement;
		}
	}
	return oEvent;
}

function addEventHandler(oTarget, sEventType, fnHandler) {
	if (oTarget.addEventListener) {
		oTarget.addEventListener(sEventType, fnHandler, false);
	} else if (oTarget.attachEvent) {
		oTarget.attachEvent("on" + sEventType, fnHandler);
	} else {
		oTarget["on" + sEventType] = fnHandler;
	}
};

var Class = {
  create: function() {
    return function() {
      this.initialize.apply(this, arguments);
    }
  }
}

Object.extend = function(destination, source) {
    for (var property in source) {
        destination[property] = source[property];
    }
    return destination;
}


var GlideView = Class.create();
GlideView.prototype = {
  //容器对象 容器宽度 展示标签 展示宽度
  initialize: function(obj, iWidth, sTag, iMaxWidth, options) {
    var oContainer = $(obj), oThis=this, len = 0;
	
	this.SetOptions(options);
	
	this.Step = Math.abs(this.options.Step);
	this.Time = Math.abs(this.options.Time);
	this.Showtext = false;//是否显示说明文本
	
	this._list = oContainer.getElementsByTagName(sTag);
	len = this._list.length;
	this._count = len;
	this._width = parseInt(iWidth / len);
	this._width_max = parseInt(iMaxWidth);
	this._width_min = parseInt((iWidth - this._width_max) / (len - 1));
	this._timer = null;
	
	//有说明文本
	if(this.options.TextTag && this.options.TextHeight > 0){
		this.Showtext = true;
		this._text = oContainer.getElementsByTagName(this.options.TextTag);
		this._height_text = -parseInt(this.options.TextHeight);
	}
	
	this.Each(function(oList, oText, i){
		oList._target = this._width * i;//自定义一个属性放目标left
		oList.style.left = oList._target + "px";
		oList.style.position = "absolute";
		addEventHandler(oList, "mouseover", function(){ oThis.Set.call(oThis, i); });
		
		//有说明文本
		if(oText){
			oText._target = this._height_text;//自定义一个属性放目标bottom
			oText.style.bottom = oText._target + "px";
			oText.style.position = "absolute";
		}
	})
	
	//容器样式设置
	oContainer.style.width = iWidth + "px";
	oContainer.style.overflow = "hidden";
	oContainer.style.position = "relative";
	//移出容器时返回默认状态
	addEventHandler(oContainer, "mouseout", function(e){
		//变通防止执行oList的mouseout
		var o = Event(e).relatedTarget;
		if (oContainer.contains ? !oContainer.contains(o) : oContainer != o && !(oContainer.compareDocumentPosition(o) & 16)) oThis.Set.call(oThis, -1);
	})
  },
  //设置默认属性
  SetOptions: function(options) {
    this.options = {//默认值
		Step:			20,//滑动变化率
		Time:			20,//滑动延时
		TextTag:		"",//说明容器tag
		TextHeight:		0//说明容器高度
    };
    Object.extend(this.options, options || {});
  },
  //相关设置
  Set: function(index) {
	if (index < 0) {
		//鼠标移出容器返回默认状态
		this.Each(function(oList, oText, i){ oList._target = this._width * i; if(oText){ oText._target = this._height_text; } })
	} else {
		//鼠标移到某个滑动对象上
		this.Each(function(oList, oText, i){
			oList._target = (i <= index) ? this._width_min * i : this._width_min * (i - 1) + this._width_max;
			if(oText){ oText._target = (i == index) ? 0 : this._height_text; }
		})
	}
	this.Move();
  },
  //移动
  Move: function() {
	clearTimeout(this._timer);
	var bFinish = true;//是否全部到达目标地址
	this.Each(function(oList, oText, i){
		var iNow = parseInt(oList.style.left), iStep = this.GetStep(oList._target, iNow);
		if (iStep != 0) { bFinish = false; oList.style.left = (iNow + iStep) + "px"; }
		//有说明文本
		if (oText) {
			iNow = parseInt(oText.style.bottom), iStep = this.GetStep(oText._target, iNow);
			if (iStep != 0) { bFinish = false; oText.style.bottom = (iNow + iStep) + "px"; }
		}
	})
	//未到达目标继续移动
	if (!bFinish) { var oThis = this; this._timer = setTimeout(function(){ oThis.Move(); }, this.Time); }
  },
  //获取步长
  GetStep: function(iTarget, iNow) {
	var iStep = (iTarget - iNow) / this.Step;
	if (iStep == 0) return 0;
	if (Math.abs(iStep) < 1) return (iStep > 0 ? 1 : -1);
	return iStep;
  },
  Each:function(fun) {
	for (var i = 0; i < this._count; i++)
		fun.call(this, this._list[i], (this.Showtext ? this._text[i] : null), i);
  }
};
function TXPic(a,b,c,d,e){new GlideView(a, b, c, d, e);}
/*window.onload=function (){
	new GlideView("PImg", 300, "div", 200, { TextTag: "a", TextHeight: 0 });
}*/
/*时间控件*/
var controlid = null;
var currdate = null;
var startdate = null;
var enddate  = null;
var yy = null;
var mm = null;
var hh = null;
var ii = null;
var currday = null;
var addtime = false;
var nowtoday = null;
var lastcheckedyear = false;
var lastcheckedmonth = false;
var ie =navigator.appName=="Microsoft Internet Explorer"?true:false;
function _cancelBubble(event) {
	e = event ? event : window.event ;
	if(ie) {
		e.cancelBubble = true;
	} else {
		e.stopPropagation();
	}
}

function getposition(obj) {
	var r = new Array();
	r['x'] = obj.offsetLeft;
	r['y'] = obj.offsetTop;
	while(obj = obj.offsetParent) {
		r['x'] += obj.offsetLeft;
		r['y'] += obj.offsetTop;
	}
	return r;
}
function loadcalendar() {
	s = '';
	s += '<div id="calendar" style="display:none; position:absolute; z-index:1003;font: 11px Arial, Tahoma;font-size=:12px" onclick="_cancelBubble(event)">';
	if (ie)
	{
		s += '<iframe width="180" height="160" src="about:blank" style="position: absolute;z-index:-1;"></iframe>';
	}
	s += '<div style="width:180px;"><table style="background: white; border: 1px solid #86B9D6;" cellspacing="0" cellpadding="0" width="100%" style="text-align: center">';
	s += '<tr align="center" style="font: 12px Arial, Tahoma !important;font-weight: bold !important;font: 11px Arial, Tahoma;font-weight: bold;color: #154BA0;background: #C2DEED;height: 25px;padding-left: 10px;">';
	s += '<td style="padding-left: 10px;">'
	s += '<a style="color:#154BA0;text-decoration: none;" href="#" onclick="refreshcalendar(yy, mm-1);return false" title="pre month">&lt;&lt;</a></td>';
	s += '<td colspan="5" style="text-align: center" style="padding-left: 10px;">';
	s += '<a href="#" onclick="showdiv(\'year\');_cancelBubble(event);return false" title="choose year" id="year" style="padding-right: 10px;background: url(onbottom.gif) no-repeat center right;text-decoration: none;color:blue">';
	s += '</a>&nbsp; - &nbsp;<a id="month" style="color:blue;text-decoration: none;padding-right: 10px;background: url(onbottom.gif) no-repeat center right;" title="choose month" href="#" onclick="showdiv(\'month\');_cancelBubble(event);return false"></a></td>';
	s += '<td style="padding-left: 10px;"><A style="color: #154BA0;text-decoration: none;" href="#" onclick="refreshcalendar(yy, mm+1);return false" title="next month">&gt;&gt;</A></td></tr>';
	s += '<tr align="center" style="font:12px Arial, Tahoma !important;font:11px Arial, Tahoma;color: #92A05A;height: 20px;background-color: #FFFFD9;">';
	s += '<td width="26px" style="border-bottom: 1px solid #DEDEB8;" align="center">Sun</td>';
	s += '<td width="26px" style="border-bottom: 1px solid #DEDEB8;" align="center">Mon</td>';
	s += '<td width="26px" style="border-bottom: 1px solid #DEDEB8;" align="center">Tur</td>';
	s += '<td width="26px" style="border-bottom: 1px solid #DEDEB8;" align="center">Web</td>';
	s += '<td width="26px" style="border-bottom: 1px solid #DEDEB8;" align="center">Thu</td>';
	s += '<td width="26px" style="border-bottom: 1px solid #DEDEB8;" align="center">Fri</td>';
	s += '<td width="26px" style="border-bottom: 1px solid #DEDEB8;" align="center">Sat</td></tr>';
	for(var i = 0; i < 6; i++) {
		s += '<tr style="font-size:12px;" align="center">';
		for(var j = 1; j <= 7; j++)
			s += "<td id=d" + (i * 7 + j) + " height=\"19\" style=\"font-size:12px\">0</td>";
		s += "</tr>";
	}
	s += '<tr style="font-size:12px"><td height=\"19\" colspan="7" align="center" style="margin:auto"><a href="#" style="color:#86B9D6;text-decoration:none" onclick="getNow()" title="select today">Today</a>&nbsp;&nbsp;';
	s += '<a href="#" onclick="clearDay()" style="color:#86B9D6;text-decoration:none" title="clear">Clear</a>';
	s += '&nbsp;&nbsp;<a href="#" onclick="closeDay()" style="color:#86B9D6;text-decoration:none" title="close">Close</a></td></tr>';
	s += '<tr id="hourminute"><td colspan="7" align="center"><input type="text" size="1" value="" id="hour" onKeyUp=\'this.value=this.value > 23 ? 23 : zerofill(this.value);controlid.value=controlid.value.replace(/\\d+(\:\\d+)/ig, this.value+"$1")\'> hour <input type="text" size="1" value="" id="minute" onKeyUp=\'this.value=this.value > 59 ? 59 : zerofill(this.value);controlid.value=controlid.value.replace(/(\\d+\:)\\d+/ig, "$1"+this.value)\'> minute</td></tr>';
	s += '</table></div></div>';
	s += '<div id="calendar_year" style="display: none;line-height: 130%;background: #FFFFFF;position: absolute;z-index: 10;" onclick="_cancelBubble(event)"><div style="float: left;background: #FFFFFF;margin-left: 1px;border: 1px solid #86B9D6;padding: 4px; font-size:12px;color:blue">';
	for(var k = 2000; k <= 2029; k++) {
		s += k != 2000 && k % 10 == 0 ? '</div><div style="float: left;background: #FFFFFF;margin-left: 1px;border: 1px solid #86B9D6;padding: 4px; font-size:12px;color:blue;">' : '';
		s += '<a style="color:blue;text-decoration: none;" href="#" onclick="refreshcalendar(' + k + ', mm);document.getElementById(\'calendar_year\').style.display=\'none\';document.getElementById(\'calendar_month\').style.display=\'none\';return false">';
		s += '<span' + (nowtoday.getFullYear() == k ? ' style="color:#00BB00;"' : '') + ' id="calendar_year_' + k + '">' + k + '</span></a><br />';
	}
	s += '</div></div>';
	s += '<div id="calendar_month" style="display: none;background: #FFFFFF;line-height: 130%;border: 1px solid #86B9D6;padding: 4px;position: absolute;z-index: 11; font-size:12px;color:blue" onclick="_cancelBubble(event)">';
	for(var k = 1; k <= 12; k++) {
		s += '<a style="color:blue;text-decoration: none;" href="#" style="font-size=12px; color:blue" onclick="refreshcalendar(yy, ' + (k - 1) + ');document.getElementById(\'calendar_month\').style.display=\'none\';document.getElementById(\'calendar_year\').style.display=\'none\';return false">';
		s += '<span' + (nowtoday.getMonth()+1 == k ? ' style="color:#00BB00;"' : '') + ' id="calendar_month_' + k + '">' + k + ( k < 10 ? '&nbsp;' : '') + '</span></a><br />';
	}
	s += '</div>';

	var nElement = document.createElement("div");
	nElement.innerHTML=s;
	document.getElementsByTagName("body")[0].appendChild(nElement);

//	document.write(s);
	document.onclick = function(event) {
		document.getElementById('calendar').style.display = 'none';
		document.getElementById('calendar_year').style.display = 'none';
		document.getElementById('calendar_month').style.display = 'none';
	}
	document.getElementById('calendar').onclick = function(event) {
		_cancelBubble(event);
		document.getElementById('calendar_year').style.display = 'none';
		document.getElementById('calendar_month').style.display = 'none';
	}
}

function parsedate(s) {
	/(\d+)\-(\d+)\-(\d+)\s*(\d*):?(\d*)/.exec(s);
	var m1 = (RegExp.$1 && RegExp.$1 > 1899 && RegExp.$1 < 2101) ? parseFloat(RegExp.$1) : nowtoday.getFullYear();
	var m2 = (RegExp.$2 && (RegExp.$2 > 0 && RegExp.$2 < 13)) ? parseFloat(RegExp.$2) : nowtoday.getMonth() + 1;
	var m3 = (RegExp.$3 && (RegExp.$3 > 0 && RegExp.$3 < 32)) ? parseFloat(RegExp.$3) : nowtoday.getDate();
	var m4 = (RegExp.$4 && (RegExp.$4 > -1 && RegExp.$4 < 24)) ? parseFloat(RegExp.$4) : 0;
	var m5 = (RegExp.$5 && (RegExp.$5 > -1 && RegExp.$5 < 60)) ? parseFloat(RegExp.$5) : 0;
	/(\d+)\-(\d+)\-(\d+)\s*(\d*):?(\d*)/.exec("0000-00-00 00\:00");
	return new Date(m1, m2 - 1, m3, m4, m5);
}

function settime(d) {
	document.getElementById('calendar').style.display = 'none';
	controlid.value = yy + "-" + zerofill(mm + 1) + "-" + zerofill(d) + (addtime ? ' ' + zerofill(document.getElementById('hour').value) + ':' + zerofill(document.getElementById('minute').value) : '');
}

function showcalendar(event, controlid1, addtime1, startdate1, enddate1) {
	nowtoday = new Date();
	loadcalendar();
	controlid = controlid1;
	addtime = addtime1;
	startdate = startdate1 ? parsedate(startdate1) : false;
	enddate = enddate1 ? parsedate(enddate1) : false;
	currday = controlid.value ? parsedate(controlid.value) : nowtoday;
	hh = currday.getHours();
	ii = currday.getMinutes();
	var p = getposition(controlid);
	document.getElementById('calendar').style.display = 'block';
	document.getElementById('calendar').style.left = p['x']+'px';
	document.getElementById('calendar').style.top	= (p['y'] + 20)+'px';
	_cancelBubble(event);
	refreshcalendar(currday.getFullYear(), currday.getMonth());
	if(lastcheckedyear != false) {
		document.getElementById('calendar_year_' + lastcheckedyear).style.backgroundColor = '#ffffff';
		document.getElementById('calendar_year_' + nowtoday.getFullYear()).style.backgroundColor = '#00BB00';
	}
	if(lastcheckedmonth != false) {
		document.getElementById('calendar_month_' + lastcheckedmonth).style.backgroundColor = '#ffffff';
		document.getElementById('calendar_month_' + (nowtoday.getMonth() + 1)).style.backgroundColor = '#00BB00';
	}
	document.getElementById('calendar_year_' + currday.getFullYear()).style.backgroundColor = '#FF0000';
	document.getElementById('calendar_month_' + (currday.getMonth() + 1)).style.backgroundColor = '#FF0000';
	document.getElementById('hourminute').style.display = addtime ? '' : 'none';
	lastcheckedyear = currday.getFullYear();
	lastcheckedmonth = currday.getMonth() + 1;
}

function refreshcalendar(y, m) {
	var x = new Date(y, m, 1);
	var mv = x.getDay();
	var d = x.getDate();
	var dd = null;
	yy = x.getFullYear();
	mm = x.getMonth();
	document.getElementById("year").innerHTML = yy;
	document.getElementById("month").innerHTML = mm + 1 > 9  ? (mm + 1) : '0' + (mm + 1);

	for(var i = 1; i <= mv; i++) {
		dd = document.getElementById("d" + i);
		dd.innerHTML = "&nbsp;";
		dd.style.backgroundColor = '#ffffff';
		dd.setAttribute("onmouseover","");
		dd.setAttribute("onmouseout","");
	}

	while(x.getMonth() == mm) {
		dd = document.getElementById("d" + (d + mv));
		dd.innerHTML = '<a href="###" style="text-decoration: none;color:#000;" onclick="settime(' + d + ');return false">' + d + '</a>';
		if(x.getTime() < nowtoday.getTime() || (enddate && x.getTime() > enddate.getTime()) || (startdate && x.getTime() < startdate.getTime())) {
			dd.style.backgroundColor = '#FFFAFA';
			dd.setAttribute("onmouseover","style.backgroundColor=\'#FFEBCD\'");
			dd.setAttribute("onmouseout","style.backgroundColor=\'#FFFAFA\'");
		} else {
			dd.style.backgroundColor = '#F0F8FF';
			dd.setAttribute("onmouseover","style.backgroundColor=\'#FFEBCD\'");
			dd.setAttribute("onmouseout","style.backgroundColor=\'#F0F8FF\'");
		}
		if(x.getFullYear() == nowtoday.getFullYear() && x.getMonth() == nowtoday.getMonth() && x.getDate() == nowtoday.getDate()) {
			dd.style.backgroundColor = "#00BB00";
			dd.firstChild.title = 'today';
		}
		if(x.getFullYear() == currday.getFullYear() && x.getMonth() == currday.getMonth() && x.getDate() == currday.getDate()) {
			dd.style.backgroundColor = '#FAEBD7';
		}
		x.setDate(++d);
	}

	while(d + mv <= 42) {
		dd = document.getElementById("d" + (d + mv));
		dd.innerHTML = "&nbsp;";
		dd.style.backgroundColor = '#ffffff';
		dd.setAttribute("onmouseover","");
		dd.setAttribute("onmouseout","");
		d++;
	}

	if(addtime) {
		document.getElementById('hour').value = zerofill(hh);
		document.getElementById('minute').value = zerofill(ii);
	}
}

function showdiv(id) {

	var p = getposition(document.getElementById(id));
	document.getElementById('calendar_' + id).style.left = p['x']+'px';
	document.getElementById('calendar_' + id).style.top = (p['y'] + 16)+'px';
	document.getElementById('calendar_' + id).style.display = 'block';
}

function zerofill(s) {
	var s = parseFloat(s.toString().replace(/(^[\s0]+)|(\s+$)/g, ''));
	s = isNaN(s) ? 0 : s;
	return (s < 10 ? '0' : '') + s.toString();
}

function getNow() {
	var nowDate = new Date();
	document.getElementById('calendar').style.display = 'none';
	controlid.value = nowDate.getFullYear() + "-" + (nowDate.getMonth()+1>9?nowDate.getMonth()+1:"0"+nowDate.getMonth()+1) + "-" + nowDate.getDate(); 
}
function clearDay() {
	document.getElementById('calendar').style.display = 'none';
	controlid.value="";
}
function closeDay() {
	document.getElementById('calendar').style.display = 'none';
}
