function bind(o,ev,fn){
		if (document.all)o.attachEvent('on'+ev,fn);
		else o.addEventListener(ev,fn,false);
}
function setCookie(name,value,time){
		var exp = new Date();
		exp.setTime(exp.getTime() + 30*24*60*60*1000);
		document.cookie = name + "="+ escape (value) + ";expires=" + exp.toGMTString();
}
function getCookie(name){
		var arr,reg=new RegExp("(^| )"+name+"=([^;]*)(;|$)");
		if(arr=document.cookie.match(reg)) return unescape(arr[2]);
		else return null;
}



//modified by dapeng--------------------------------------------------------------------------------------------
function setDHP (intHours) {
		var hours = parseInt(intHours) + 1;
		var d = h = p = 0;
		if (hours >= 1 && hours <= 5) {
				p = 6;
		} else if (hours >= 6 && hours <= 8) {
		    p = hours + 1;	
		} else if (hours >= 9 && hours <= 24) {
			  p = hours + 2;
		}
		if (hours == 24) {
			  d = 1;
				h = 0;
		} else {
			  d = 0;
				h = hours;
		}
		var exchangeRate = document.getElementById('exchangeRate').value;
		p *= exchangeRate;
		p = Math.round(p) + 0.99;
		document.getElementById('price').value = p;
		document.getElementById('days').value = d;
		document.getElementById('hours').value = h;
}
//------------------------------------------------------------------------------------------------------------



function Move_autosetdef(moveobj){
		var logintit = new Array("1 hour","2 hours","3 hours","4 hours","5 hours","6 hours","7 hours","8 hours","9 hours","10 hours","11 hours","12 hours","13 hours","14 hours","15 hours","16 hours","17 hours","18 hours","19 hours","20 hours","21 hours","22 hours","23 hours","24 hours");
		var bNum =13 ,mNum =22 , iNum = 24 , icolength = 6;
		//分别 bNum 起始距离距moveobj内侧左部的长度 ，mNum 单位长度，iNum 单位数 0-1-2-3，icolength 图标距离的1/2。
		
		var eNum = bNum + mNum * (iNum-1);
		var $D = new Function('str','return document.getElementById(str);');
		var $event = new Function('e','return (!e)?window.event:e;');
		var checknowleft = function(z){
			  return ((z<bNum)?bNum:((z>eNum)?eNum:(((z-bNum)%mNum>11)?z+mNum-(z-bNum)%mNum:z-(z-bNum)%mNum)));
		}
		var nowseat = 0,drag_=false;
		var Move_autoset = function(iNum){
				$D(moveobj).getElementsByTagName("div")[0].style.left = iNum*mNum+bNum+"px";
				$D("login-tit").innerHTML = logintit[iNum];
				$D("login-type").value = iNum;//向hidden的login-type里添加参数值
    } 

		nowseat = (getCookie("nowseat")==null)?0:getCookie("nowseat");
		
		
		
		//modified by dapeng----------------------------
		setDHP(nowseat);
		//----------------------------------------------
		
		
		
		Move_autoset(nowseat);
		$D(moveobj).getElementsByTagName("div")[0].onmouseover = function(){
				var x,y,z;
				this.onmousedown=function(e){
						drag_=true;
						with(this){
								var temp0=style.left.replace("px","")*1,temp1=offsetLeft,temp2=offsetTop;
								x=$event(e).clientX;
								y=$event(e).clientY;
								z=temp0;
								document.onmousemove=function(e){
										//this.selection.empty();
										if(!drag_)return false;
										with(this){
												z = temp0 + $event(e).clientX-x;
												z = (z<bNum)?bNum:((z>eNum)?eNum:z);
												style.left=z+"px";
										}
								}
								document.onmouseup=function(e){
										drag_ = false;
										var nowleft = checknowleft(z);
										nowseat = (nowleft-bNum)/mNum;
										Move_autoset(nowseat);
										setCookie('nowseat',(nowleft-bNum)/mNum);
										
										
										
										//modified by dapeng----------------------------
										setDHP(nowseat);
										//----------------------------------------------
										
										
										
								}
						}
				}
		}
		$D(moveobj).onmouseover = function(){
				this.onmousedown=function(e){
						if(drag_)return false;
						with(this){
								var icoobj = getElementsByTagName("div")[0];
								var temp0 = icoobj.offsetLeft;
								var x=$event(e).clientX;
								var nowleft = checknowleft(bNum+mNum*nowseat+(x-temp0)-icolength);
								document.onmouseup=function(e){
										nowseat = (nowleft-bNum)/mNum;
										Move_autoset(nowseat);
										setCookie('nowseat',(nowleft-bNum)/mNum);
										
										
										
										//modified by dapeng----------------------------
										setDHP(nowseat);
										//----------------------------------------------
										
										
										
								}
						}
				}
		}
}

bind(window,"load",new Function('Move_autosetdef("moveico")'));
