//TAB切换
var ROOT="";

function setcookie(name,value){   
    var Days = 30;   
    var exp  = new Date();   
    exp.setTime(exp.getTime() + Days*24*60*60*1000);   
    document.cookie = name + "="+ escape (value) + ";expires=" + exp.toGMTString();   
}


  
function delcookie(name){   
    var exp = new Date();    
    exp.setTime(exp.getTime() - 1);   
    var cval=getCookie(name);   
    if(cval!=null) document.cookie= name + "="+cval+";expires="+exp.toGMTString();   
}



function resetVerifyCode(){
	var timenow = new Date().getTime();
	document.getElementById('verifyImage').src= ROOT+'/index.php?g=home&m=index&a=verify#'+timenow;
}

function donghua(obj){
	  var speed=20;
	  var demoh  =  document.getElementById(obj);
	  var demoh1 =  document.getElementById(obj+'_1');
	  var demoh2 =  document.getElementById(obj+'_2');
	  demoh2.innerHTML=demoh1.innerHTML;
	  function wfdh(){
		  if(demoh2.offsetWidth-demoh.scrollLeft<=0){demoh.scrollLeft-=demoh1.offsetWidth;}
		  if(demoh2.offsetWidth-demoh.scrollLeft>0){demoh.scrollLeft++;}
	  }
	  var MyMarh=setInterval(wfdh,speed);
	  demoh.onmouseover=function() {clearInterval(MyMarh);}
	  demoh.onmouseout=function() {MyMarh=setInterval(wfdh,speed);}
}

function showon(obj,onobj,id){
	$(obj+' '+ onobj).click(function(){
 		//$(this).parent().addClass('on').siblings().removeClass('on');
		if($(this).parent().hasClass('on')){
			$(this).parent().removeClass('on');
		}else{
			$(this).parent().addClass('on');
		}
	});
	if(id){
		$('#catlist_'+id).parent().parent().addClass('on');	
	}
}

function Floaters() {
		this.delta=0.15;
		this.playid =null;
		this.items	= [];
		this.addItem	= function(id,x,y,content) {
			var newItem = {};
			newItem.object = document.getElementById(id);

			if(x==0){
				objw= newItem.object.offsetWidth;
				var body = (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body;
				newItem.x = x = body.scrollLeft + (body.clientWidth - objw)/2;
				newItem.y = y;
			}else{
				newItem.x = x;
				newItem.y = y;
			}

			this.items[this.items.length]		= newItem;
		}
		this.play =function(varname){
			this.playid = setInterval(varname+'.plays()',30);
		}
		this.close = function(obj){
			document.getElementById(obj).style.display='none';
			 clearInterval(this.playid);
		}
}
Floaters.prototype.plays = function(){
	var diffY;
	if (document.documentElement && document.documentElement.scrollTop)
	{
		diffY = document.documentElement.scrollTop;
	}
	else if (document.body)
	{
		diffY = document.body.scrollTop;
	}else{}

	for(var i=0;i<this.items.length;i++) {
		var obj = this.items[i].object;
		var followObj_y = this.items[i].y;
		var total = diffY + followObj_y;
		if(this.items[i].x >= 0){
			obj.style['left'] = this.items[i].x+ 'px';
		}else{
			obj.style['right'] = Math.abs(this.items[i].x)+ 'px';
		}
		if( obj.offsetTop != total)
		{
			var oldy = (total - obj.offsetTop) * this.delta;
				newtop = obj.offsetTop + ( oldy>0?1:-1 ) * Math.ceil( Math.abs(oldy) );
			obj.style['top'] = newtop + 'px';
		}
	}
}


function changeorder(obj,moduleid,id,doit,ordercall){
	
	var objs  =  document.getElementById(obj);
	var datas={'moduleid':moduleid,'id': id,'num':objs.value};
	$.ajax({
		type:"POST",
		url:"/index.php?m=Order&a=ajax&do="+doit,
		data: datas,
		timeout:"4000",
		dataType:"JSON",
		success: function(data){
			if(data.data==1){
				ordercall.call(this,obj,moduleid,id,doit,data);
			}else{
				alert(doit + ' error'+data.msg);
			}
			
		},
		error:function(){
			alert("time out,try it");
		}
	});
}


function area_change(id,level,province,city,area,provinceid,cityid,areaid){
	var datas={'level':level,'provinceid':provinceid,'cityid':cityid,'areaid':areaid};
	$.ajax({
		type:"POST",
		url:"/index.php?m=ajax&a=area&id="+id,
		data: datas,
		timeout:"4000",
		dataType:"JSON",
		success: function(data){
			if(level==0){
			$('#'+province).html(data.province);
			$('#'+city).html(data.city);
			$('#'+area).html(data.area);
			}else if(level==1){
			$('#'+city).html(data.city);
			$('#'+area).html(data.area);
			}else if(level==2){
				$('#'+area).html(data.area);
			}
		},
		error:function(){
			alert("time out,try it");
		}
	}); 
}
