// JavaScript Document

var $div,$p,$div,$div_ship, gcd_div,popreg,$cdiv;

function add_Dom(){
	$div	= document.createElement('div');
	$div.id	= "noticeBox";
	$p	= document.createElement('p');
	$p.id	= 'noticeText';
	$p.className	= 'top';
	$div.appendChild($p);
	$p	= document.createElement('p'); 
	$p.className	= 'bottom';
	$div.appendChild($p);
	document.body.appendChild($div);  
	$div	= document.createElement('div');
	$div.id		= 'box_select';
	document.body.appendChild($div);
	$cdiv	= document.createElement('div');
 	$cdiv.style.cssText	= 'background:#000; position:absolute; z-index:2234;display:none;left:0;top:0;';
	document.body.appendChild($cdiv);
	 
	$div_ship	= document.createElement('div');
	$div_ship.id		= 'updatepay';
	$div_ship.style.cssText	= 'background:#FFF;width:630px; visibility:hidden;position:absolute; left:0px; top:0px;';
	document.body.appendChild($div_ship);
	 
	gcd_div	= document.createElement('div');
	gcd_div.style.cssText	= "position:absolute; z-index:1000;visibility:hidden; left:0px; top:0px; background:#FFEFF5; border:1px solid #FFBFEA;  width:360px; height:155px;";
	gcd_div.id	= "box_dialog";
	gcd_div.innerHTML	= '<div id="collection_div" style="z-index:1002;"  ><p class="p1 clearfix"><input type="button" value="" id="a_close"/><span  >收藏</span> </p><p class="p2 clearfix" style="display:none;"><span  >选择分类:</span> <input type="text" id="select_cat_text" value="默认分类" ><input type="button" id="select_btn" value=""> </p>  <p class="p2 clearfix"><span>我要收藏:</span><b id="collect_title"> </b></p><p class="p3 clreafix"><span >我的备注:</span> <input type="text" id="collectName" notice="可以输入您的备注 以方便以后查找" width="100" value="" /> </p><p class="p4"> <input type="button" class="submitBtn" style="cursor:pointer;" onclick="submitCollection();" value="" />  </p></div>';
	document.body.appendChild(gcd_div);
	popreg	= document.createElement('div'); ;
	popreg.id	= 'loginDiv';popreg.className	= 'clearfix';
	popreg.style.cssText	= 'background:#FFF; position:absolute; z-index:3000; display:none;width:704px; height:417px; overflow:hidden; border:#D43F73 solid 2px;padding:4px;';
	if(loginFlag!=null&&loginFlag=='tt') popreg.style.width='649px';
	document.body.appendChild(popreg);
	if(typeof loginHTML!='undefined'){popreg.innerHTML	= loginHTML;loginInput();}
	$$("input").set({
		  "events":{
			  "focus":function(){
				  if(this.get('notice')){
					 $('noticeText').innerHTML = this.get('notice'); 
					 f_notice(getOffset(this));
				  }
			  },
			  "blur":function(){
				  $('noticeBox').style.visibility	= 'hidden';
			  }
		  }
		});

}
function DomMid(id){
	var pos	= getPos();
	$(id).style.top		= (pos.h-$(id).offsetHeight)/2+pos.y +'px';
	$(id).style.left	= (pos.w-$(id).offsetWidth)/2+pos.x +'px';
}
function f_notice(pos){
	var box	= $('noticeBox'); 
	box.style.left	= pos.left+pos.width-40 +'px';
	box.style.top	= pos.top-box.offsetHeight + 'px';	
	box.style.visibility	= 'visible';
	setOpacity(box,80);	
}
 

var mkpayDialog	= null;
var oid	= 0;
var boi	= 100;
function mkpay(elem,orderid,price){
	oid	= orderid;boi++;
	if(mkpayDialog!=null){ mkpayDialog.CloseBox(); }
	mkpayDialog	= null;
	if( mkpayDialog==null||mkpayDialog._box.style.visibility == 'hidden'){	
		
		$('pay_amount').value	= price;
		
		mkpayDialog		= new Dialog({'_src':elem, '_dst':'mkpay','_boxstyle':'border:1px dashed #C09;overflow:hidden;background:#FFCCFF;width:120px;' ,'flag':boi, '_closeObj':'a_close'});
		mkpayDialog._box.style.display	= 'block';
    	mkpayDialog.Run();
	} 
	 
} 
	 
function mkship(elem,orderid){
	
	 	if(confirm("您要确定收货吗？")){ 
	 	  	
	    	var form = { };
			var jsonRequest = new Request.JSON({
				url			: "myleftlady.php?act=mkship&orderid="+orderid,
				async		: true,
				onComplete	: function(res, text){
		  			 if(res.err!=0)alert(res.content);
		  			 else{ 
		  	  			  window.location.href	= window.location.href+'&time='+$time(); 
		  			 }		  
				}
			}).post(form );
	    }
	
}
function ajaxmkpay(){
	var form = {'amount':$('pay_amount').value.trim(),'orderid':oid};
	var jsonRequest = new Request.JSON({
		url			: 'orderview.php?act=mkpayamount',
		async		: true,
		onComplete	: function(res, text){
  			 if(res.err!=0)alert(res.content);
  			 else{ 
  	  			  window.location.href	= window.location.href+'&time='+$time(); 
  			 }		  
		}
	}).post(form );	
} 
 
function getEvent(e){if (typeof e == "undefined") e = window.event; return e;};
function trim(str){return str.replace(/^\s*|\s*$/g,'');}
function getkey(e){
	e	= getEvent(e);
	if(isFF)
		return e.which;
	else
		return e.keyCode;
}
function srcElement(e){
  if (typeof e == "undefined") e = window.event;
  var src = document.all ? e.srcElement : e.target;
  return src;
}

function submitCollection( ){
	var _catName		= $('select_cat_text');
	var _collectName	= $('collectName');
	var form	= {'catName':trim($('select_cat_text').value),'collectName':trim($('collectName').value), 'collectID':collectid,'type':collecttype};
	
	var jsonRequest = new Request.JSON({
		url			: 'collection.php?act=insert',
		async		: true,
		onComplete	: function(res, text){
  			 if(res.err!=0)alert(res.content);
  			 else alert('已经收藏成功');
  			 _Dialog.Close();	  
		}
	}).post(form );
}
var _Select=null; var _Dialog	=null;

 
	
var collectid,collecttype;
function collect(elem,userID,c_id,c_name,type){ 
	collectid	= c_id;
	collecttype	= type;
	$('collect_title').innerHTML	= c_name;
	if(userID==0){
		// 当登录时的处理
		alert('请登录后收藏该内容');return false;
	}
	
	var form = {'collectid':collectid,'type':collecttype,'userid':userID};
	var jsonRequest = new Request.JSON({
		url			: 'collection.php?act=iscollected',
		async		: true,
		onComplete	: function(res, text){
  			 if(res.err!=0)  alert(res.content);
  			 else{
  			 		if(_Dialog==null || _Dialog._box.style.visibility == 'hidden'){
		if(_Dialog!=null){ _Dialog.CloseBox(); }
		_Dialog		= new Dialog({'_src':elem,'_dst':'box_dialog','_boxstyle':'border:1px dashed #C09;overflow:hidden;background:#FFCCFF;width:140px;','_closeObj':'a_close'});
		_Dialog._box.style.display	= 'block';
		_Dialog.Run();
	
	}
  			 }  
		}
	}).post(form );
	
//	var form = { };
//	var jsonRequest = new Request.JSON({
//		url			: 'collection.php?act=catList',
//		async		: true,
//		onComplete	: function(res, text){
//  			 if(res.err!=0)alert(res.content);
//  			 else{ 
//  			 	if(res.list!=null){
//					$('box_select').innerHTML	= '';
//					var p	= document.createElement('p');
//  			 		p.innerHTML	= "默认分类";
//					$('box_select').appendChild(p)
//  			 		for(var i=0;i<res.list.length;i++){
//  			 			var p	= document.createElement('p');
//  			 			p.innerHTML	= res.list[i].name;
//						
//  			 			$('box_select').appendChild(p);	
//  			 		}				 
//  			 	}			 
//  			    _Select	= new Select({'_pBox':'box_select','_text':'select_cat_text','_showBtn':'select_btn'});
//  			 }		  
//		}
//	}).post(form );
 
}
function SetShiptype(obj,s){
 	 	$('shiptype').value=s; 	 	
 
		 obj.getElementsByTagName('input')[0].checked	= true;
 }
 
 var _elem = null;var _orderID;
 function ChangeMyShipType(viewtype,elem,orderid){
	 _elem = elem; _orderID	= orderid;
		if( _Dialog==null||_Dialog._box.style.visibility == 'hidden'){
 			var url="orderinfo2.php?act=ajaxchangeshiptype&orderid="+orderid+'&viewtype='+viewtype;
 			//AjaxExtend('get',url,null,null,onmyupdatepay);
 			ajaxCall({},url,'get', onmyupdatepay,false);
 			
		}
 }
 	function	onmyupdatepay(res){
 		if(3==parseInt(res)) {
 			alert('不能修改支付方式');return false;	
 		}
		$('updatepay').innerHTML	= res.OrderPaySetting;
		$('updatepay').style.visibility	= 'hidden';
		var p = $('updatepay').getElementsByTagName('p');
		for(var i=0;i<p.length;i++){
			if(p[i].className=='h_o_p1'){
				p[i].innerHTML = ' <a class="h_o_a2" href="javascript:void(0);" id="closepay" >关闭</a>更改支付方式 ';
			}
		}
		var h6 = $('updatepay').getElementsByTagName('h6');
		h6[0].innerHTML	= '<a href="javascript:void(0);" onclick="javascript:SaveShipType();"><b>保存支付方式</b><i></i></a>';
		_Dialog		= new Dialog({'_src':_elem ,'_dst':'updatepay','_step':'27','_time':'2','_boxstyle':' overflow:hidden;background:#FFCCFF; border :1px solid #CCC;border-left:none;', '_closeObj':'closepay'});
		_Dialog.Run();
	}
 	function SaveShipType(){	 
 		if(ChkPayinfo()==false)return;
 		var url="orderinfo2.php?act=ajaxsaveshiptype";
 		var orderid=_orderID;
 		var postdata="";
 		postdata+="&type_flag=1&orderid="+orderid+"&shiptype="+$('shiptype').value;
 		postdata+="&paytype="+GetRadioValue('paytype');
 		postdata+="&deliverydatetype="+GetRadioValue('deliverydatetype');
 		postdata+="&deliverydatenote="+$('deliverydatenote').value;
 		AjaxExtend('post',url, null,postdata,alert_res);
 		//window.location.href='#APayInfo'; 
  		
	}
	function alert_res(res){
		if(res=='ok' )
			alert('修改支付方式成功');
		else 
			alert(res);
		window.location.href='myleftlady.php?act=myorder'+'&time='+$time();
	}	
function	onupdatepay(res){
		$('updatepay').innerHTML	= res;
		var p = $('updatepay').getElementsByTagName('p');
		for(var i=0;i<p.length;i++){
			if(p[i].className=='h_o_p1'){
				p[i].innerHTML = ' <a class="h_o_a2" href="javascript:void(0);" id="closepay" >关闭</a>更改支付方式 ';
			}
		}
		var h6 = $('updatepay').getElementsByTagName('h6');
		h6[0].innerHTML	= '<a href="javascript:void(0);" onclick="javascript:SaveShipType();"><b>保存支付方式</b><i></i></a>';
		_Dialog		= new Dialog({'_src':'updatepay_btn','_dst':'updatepay','_step':'30','_time':'1','_boxstyle':' overflow:hidden;background:#FFCCFF;width:560px;border :1px solid #CCC;border-left:none;', '_closeObj':'closepay'});
		
		_Dialog.Run();
	}
var box = null;
var src	= null; var count = 0;
try{
var Dialog  	= new Class({
    Implements: [Options, Events],
    options: {
		_src	: null,
		_dst	: null,
		_box	: null,
		_time	:  10,
		_step	:40,	
	 	_closeObj	: null,
		_opacity	: 30,
		_timeout	: 0,
		_boxstyle	: '',
		_zindex:2000,
		flag:1
	},
    initialize: function(options){
       this.setOptions(options);
       this._count = 0;
	   this.Start();
    },
    
	Start	: function(){
		 
		this._src	= $(this.options._src);
		src	= this._src;
		this._dst	= $(this.options._dst);
		this._closeObj	= $(this.options._closeObj);
		this._Close	= this.Close.bind(this);
		this._closeObj.addEvent('click',this._Close);
		this._box	= document.createElement('div');
		this._box.id	= 'flag'+this.options.flag;
		this._box.style.cssText		= this.options._boxstyle;
		this._box.style.visibility	= 'hidden';
		this._box.style.position	= 'absolute';
		this._box.style.zIndex		= this.options._zindex; 
		document.body.appendChild(this._box);	
		this._srcPos	= getOffset(this._src);
		box = this._box;
		this._dstPos	= getOffset(this._dst);	
		this._box.appendChild(this._dst);
		setOpacity(this._box,this.options._opacity); 
		 
		 
	},
	Run		: function(){	
	
		this.isShow	= false;
		this.GetBoxPos();
 	 
		this.GetSteps();
	 
		this._box.style.visibility = 'visible';	
		this.SetTimeout(); 
	},
	Move	: function(){
		clearTimeout(this.__timer);
	  	clearTimeout(this._timer);
		this.SetElemPos(this._box,this._stepPos);  
		 count++; 	  
		if( count < this.options._step){ 
		//if(this._box.offsetHeight>this._src.offsetHeight && this._box.offsetHeight<this._dst.offsetHeight){ 	
			this.SetTimeout();
		} else {
			this.Show(); 
		  count = 0;
		}	
	},
	GetSteps	: function(){
 		this._stepPos	= {};
		this._stepPos.left	= parseInt((this._pos.left - this._srcPos.left )/this.options._step);
		this._stepPos.top	= parseInt((this._pos.top - this._srcPos.top )/this.options._step); 	
	 	this._stepPos.width	= parseInt((this._dstPos.width - this._srcPos.width)/this.options._step);
	 	this._stepPos.height	= parseInt((this._dstPos.height - this._srcPos.height)/this.options._step);
	},
	SetTimeout	: function(){
	 
	    var __obj	= this;  
		this.__timer = setTimeout(function(){__obj.Move();},this.options._time);
	},
	GetBoxPos	: function(){
		var _pos	= {};this._pos = {};
		_pos	= getPos();
		this._pos.left	= ((_pos.w - this._dstPos.width)/2 + _pos.x);
		this._pos.top	= ((_pos.h - this._dstPos.height)/2 + _pos.y);
		this._box.style.width	= this._srcPos.width+'px';
		this._box.style.height	= this._srcPos.height+'px';
		this._box.style.left	= this._srcPos.left+'px';
		this._box.style.top 	= this._srcPos.top+'px';
	},
	SetElemPos	: function(elem,pos){	
		try{
		elem.style.left	 = parseInt(elem.style.left) + parseInt(this.isShow?-pos.left:pos.left)+'px';
		elem.style.top 	 = parseInt(elem.style.top) +parseInt(this.isShow?-pos.top:pos.top)+'px';	
	 	elem.style.height	 = parseInt(elem.style.height) +parseInt( this.isShow?-pos.height:pos.height )+'px';
	 	elem.style.width	 = parseInt(elem.style.width) +parseInt(this.isShow?-pos.width:pos.width)+'px';  
		}catch(err){ }
		
	},
	Show	: function(){	
	
		if(!this.isShow) {
			setOpacity(this._box,100);
			this._box.style.width	= this._dst.offsetWidth	+ 'px';
			this._box.style.height	= this._dst.offsetHeight +'px';
			this._dst.style.visibility	= 'visible';
			
		} else {
			this._box.style.visibility	= 'hidden';
			this._box.style.display		= 'none';
		
		}
	   	
	},
	Close	: function(){
		 	this._box	= box;  
		 	this._src	= src;
		  
 	 
		this.GetSteps();
		this.isShow 	= true;
		setOpacity(this._box,40); 
		this._dst.style.visibility	= 'hidden'; 
		if(_Select!=null) _Select._pBox.style.display = 'none';	
   	  	this._box.style.visibility	= 'hidden'; 
	},
		
		
	CloseBox	: function(){
		document.body.appendChild(this._dst);
		this._box.style.display	= 'none';
		this._box.parentNode.removeChild(this._box);
		 
	}

});
var Select  	= new Class({
    Implements: [Options, Events],
    options: {
		_pBox	: null,
		_text	: null,
		_showBtn: null
	},
    initialize: function(options){
       this.setOptions(options);
	   this.Start();
    },
    
	Start	: function(){
		this._showBtn	= $(this.options._showBtn);
		this._text		= $(this.options._text);
		this._pBox		= $(this.options._pBox);
		this._Show		= this.Show.bind(this);
		this._Selected	= this.Selected.bind(this);
		this._SetText	= this.SetText.bind(this);
		this._Show		= this.Show.bind(this);
		this.GetItems();
		this._showBtn.addEvent('click',this._Show);
	  
	},
 
	Show	: function(){
		var pos		= getOffset(this._text);
		this._pBox.style.left	= pos.left+3+'px';
		this._pBox.style.top	= pos.top+pos.height+'px';
	 	this._pBox.style.width	= pos.width+this._showBtn.offsetWidth-3+'px';
		 
	 	this._pBox.style.display	= 'block'; 
	 	return false;
	},
	GetItems	: function(){
		this._items = [];		
		this._items = this._pBox.getElementsByTagName('p');
	    this.SetItemEvent();
	},
	SetItemEvent: function(){
 	 	 
		 addEventHandler(document,"click",this._SetText);
		for(var i=0;i<this._items.length;i++){
		    
		  	addEventHandler(this._items[i],'mouseover',this._Selected);
			addEventHandler(this._items[i],'click',this._SetText);
			
		}
	},
	Selected		: function(e){
		e = e?e:window.event;
		var elem 	= srcElement(e);
		 
		for(var i=0;i<this._items.length;i++){
			this._items[i].style.backgroundColor	= '#FFF';
		}
		elem.style.backgroundColor	= '#E6F2FF';
	},
	SetText		: function(e){
		e = e?e:window.event;
		var elem 	= srcElement(e);
		 
		// alert(this._text.id+'  '+elem.innerHTML); 
		for(var i=0;i<this._items.length;i++){
			if(elem==this._items[i]){
				this._text.value	= elem.innerHTML;
				
				this._pBox.style.display	= 'none';
				return false;
			}	
		}
		 
		if(!(elem==this._text||elem==this._showBtn))  	this._pBox.style.display	= 'none';
	}
});
 
}catch(err){ }
 
