/**
  *  PassBay Script Library v1.0
  *  Copyright 2006 AEware company
  *  http://www.passbay.com
  *  author: hawk
  **/
var showdebug = false;
var PBLib = { 

	       version: '1.0',
           debug:function(str){   //自动生成 debug 输出框
		       if(!showdebug) return;
		       var repflag = arguments[1]?arguments[1]:'';
		       var br='\n\n';
			   if(!$('debug')){
				   var d=document.createElement('textarea');
				       d.id='debug';
					   d.style.position='absolute';
					   d.style.zIndex='100002';
					   d.style.display='';
					   d.rows=10;
					   d.cols=50;
					   d.style.right=((document.body.clientWidth / 2) - d.cols * 3)+'px';
					   d.style.top=((document.body.clientHeight / 2)  - d.rows * 2)+'px';
					   d.value='************* PBLib debug '+this.version+' ***************';
					   d.ondblclick=function(){
						   d.style.display = (d.style.display=='')?'none':'';
					   }
				   document.body.appendChild(d);
				   if(repflag){
					   d.value=br+str; 
				   } else {
					   d.value+=br+str;
				   }
			   }else{
				   var d = $('debug');
				   d.value+=br+str;
				   (d.style.display=='none')?d.style.display='':'';
			   }
		   },
           loading:function(key){   //自动生成Loading状态条
   			   if(!$('loading')){ 
				    var d=document.createElement('span');
				       d.id='loading';
				    with(d){
					   style.position='absolute';
					   style.left='12px';
					   style.top='52px';
					  // style.width='150px';
					  // style.height='20px';
					   style.fontSize='12px';
					   style.color='#536851';
					   style.border='1px solid #A6C16A';
					   style.background='#FFFFE0';
					   style.textAlign='left';
					   style.display='';
					   style.padding='0 4px 0 0';
					   style.zIndex='100001';
					}

				   var dimg = document.createElement('img');
						dimg.src = '/img/loadding.gif';
						dimg.align = 'absmiddle';
					d.appendChild(dimg);
					d.appendChild(document.createTextNode(' '+ lang.web_loadding));
				   document.body.appendChild(d);
			//$('loading').style.left =((document.body.clientWidth / 2) - ($('loading').offsetWidth / 2)) + 'px';
			//$('loading').style.top = ((document.body.clientHeight / 2 + document.body.scrollTop) - ($('loading').offsetHeight / 2)) +'px';
			//alert($('loading').style.top)
				   this.chkKey(key);
			   }else{
				   this.chkKey(key);
			   }
		   },
           chkKey:function(key){   //根据key显示Loading状态
		        var lobj = $('loading');
				if(key!=undefined){
				    lobj.style.display=(key)?'':'none';
				 }else{
				    lobj.style.display=(lobj.style.display=='none')?'':'none';
				}
				//lobj.style.top = document.body.scrollTop + 'px';
		   },
           inArr:function(sorce,arr){   //判断源数据是否包含数组里的内容
			   for (var i=0; i<arr.length; i++){
				   if(sorce.indexOf(arr[i])!=-1) return true;
			   }
			   return false;
		   },
           isNull:function(str){   //判断参数是否为空
			   return str==undefined || str==null || str=='';
		   }
};

/* PBAjax Control */

function PBAjax() {
   //提交xmlHttpRequest请求 (get方式)
   this.getRequest = function( url, callback){
	        if(!callback)var callback=new Function();
			var args={
				    'onLoading':function(){PBLib.loading(true)},
				    'onComplete':function(){PBLib.loading(false)},
				    'url':url,
					'onSuccess':callback, 
					'onError':this.debug
   			    }
			 AjaxRequest.get(args);
   }
   //提交xmlHttpRequest请求 (post方式)
   this.postRequest = function( url, postData, callback){
	        if(!callback)var callback=new Function();
			var args = {
				    'onLoading':function(){PBLib.loading(true)},
				    'onComplete':function(){PBLib.loading(false)},
				    'parameters':this.r2o(postData),
				    'url':url,
					'onSuccess':callback, 
					'onError':this.debug
   			    }
			 AjaxRequest.post(args);
   }

   //将request转换成对象形式
   this.r2o = function(qstr){
		var req = qstr.split('&');
		var o = {};
		for (var i=0;i<req.length ;i++ )
		{
			var t = req[i].split('=');
			    o[t[0]]=t[1];
		}
		return o;
   }
   this.debug = function(req){
	   var errstr = 'Error!\nStatusText='+req.statusText+'\nContents='+req.responseText;
	   PBLib.debug(errstr);
   }

}


var stoptime ;

function PBClewClose(){
	window.clearTimeout( stoptime );
	Element.hide(SelectObj);
}

function PBClew(obj,id,type){

	var SelectObj = obj.nextSibling;
	var clewspan = document.createElement("span");
	clewspan.className = 'clewinfo';
	clewspan.style.display = 'none';
	//clewspan.onmouseover = mouseover;
	clewspan.onblur = function(){Element.hide(SelectObj);};
	//clewspan.onfocus = function(){alert('a');};
	if (SelectObj)
	{
		if (SelectObj.className!='clewinfo')
		{
			obj.parentNode.insertBefore(clewspan,SelectObj);
			SelectObj = obj.nextSibling;
		}
	}
	else 
	{
		obj.parentNode.appendChild(clewspan);
		SelectObj = obj.nextSibling;
	}
	
	if (type==0)
	{
		stoptime = window.setTimeout(function(){
			if (SelectObj.innerHTML == '')
			{
				var cb = function (o){
					SelectObj.innerHTML = '<a href="javascript:void(0)" onclick="Element.hide(this.parentNode);"><img src="/img/close.gif" align=right border=0></a>'+o.responseText;
				}
				nAjax.getRequest('/rq/getclew.asp?c='+id,cb);
				
			}
			Element.show(SelectObj);
			SelectObj.focus();
		},800);
	}
	else 
	{
		window.clearTimeout( stoptime );
		//Element.hide(SelectObj);
	}
}

function writeCookie (name, value,expdate) { 
	//exp = new Date(); 
	//exp.setTime(exp.getTime() + (86400 * 1000 * 30));
	//cookie_exp = expdate;
	document.cookie = name + "=" + escape(value) + "; expires=" + expdate.toGMTString() + "; path=/"; 
} 
function readCookie(name) { 
	var search; 
	search = name + "="; 
	offset = document.cookie.indexOf(search); 
	if (offset != -1) { 
		offset += search.length; 
		end = document.cookie.indexOf(";", offset); 
		if (end == -1){
			end = document.cookie.length;
		}
		return unescape(document.cookie.substring(offset, end)); 
	}else{
		return "";
	}
}
function deleteCookie(name) {
	var expdate = new Date(); 
	expdate.setTime(expdate.getTime() - (86400 * 1000 * 1)); 
	writeCookie(name, "", expdate); 
}

function killErrors() {
return true;
}
window.onerror = killErrors;
