//window.onerror=function(){window.status="完成!"; return true;}

var lang;
if(navigator.product == 'Gecko'){lang = navigator.language}else{lang = navigator.browserLanguage}
lang = lang.toLowerCase();
var str = "en";
var charset = "charset=UTF-8";
if(lang == 'zh-cn'){
  str = "zh-cn";
  charset = "charset='gb2312'";
}
else if( lang =='zh-tw'){
  str = "zh-tw";
  charset = "charset=GBK";
}

String.prototype.Ltrim=function(){return this.replace(/^\s/ig,"");}
String.prototype.Rtrim=function(){return this.replace(/\s$/ig,"");}
String.prototype.Trim=function(){return this.Ltrim().Rtrim();}
String.prototype.trim=String.prototype.Trim;
String.prototype.isNumeric=function(){
	if(this.length<=0)return false;
	var spos = this.search("[^0-9]");
	return (spos>=0) ? false : true;
	//var reg=/^[0-9]+(\.?)[0-9]*$/ig;
	//return reg.test(this);
}
String.prototype.isPostCode=function(){return this.isNumeric()&&this.length==6;}
String.prototype.isEmail=function(){var reg=/\w+@\w+\.\w+/ig;return reg.test(this);}
String.prototype.isUrl=function(){var reg=/\w+:\/\/\w+\.\w+/ig;return reg.test(this);}
String.prototype.isSet=function(){return this.length>0;}
String.prototype.isNull=function(){return this.Trim().length<=0;}
String.prototype.isMobile=function(){var reg=/^0?1\d{10,10}$/ig;return reg.test(this);}
String.prototype.isDomain=function(){
	var reg=/^([a-z\.\-])+\.\w{2,3}$/ig;
	return reg.test(this);
}
String.prototype.isPhone=function()
{
	var reg=/^(\+86\-)?\d{3,3}\-\d{8,8}$/ig;
	var reg2=/^(\+86\-)?\d{4,4}\-\d{7,7}$/ig;
	return reg.test(this)||reg2.test(this);
}
String.prototype.test=function(reg)
{
	if(typeof(reg)=="string"||typeof(reg)=="undefined"){return false;}
	var str=this;return reg.test(str);
}
function showOrHidd(objId,isShow){
	var obj;
	try{
		obj = document.getElementById(objId);
		if(obj==null) obj = parent.document.getElementById(objId);
	}catch(e){}
	if(typeof(isShow)=="undefined"){ isShow=(obj.style.display == "none");	}
	if(!isShow)	obj.style.display = "none";
	else obj.style.display = "";
}

function resizePic(obj,maxWidth,maxHeight){
	var rate=parseFloat(obj.height)/parseFloat(obj.width);
	var width=parseInt(obj.width);
	var height=rate*width;
	while(width>maxWidth||height>maxHeight){
		width*=0.95;
		height=rate*width;
	}	
	obj.width=width;obj.height=height;
	
	var marginTop=Math.ceil((maxHeight-obj.height)/2);
	//alert(marginTop);
	if(marginTop<=0)
		marginTop=1;
	obj.style.marginTop=marginTop+"px";
}

//文件上传后缀名验证
//if(checkUploadFileExt($("flashPic").value,"gif,png,jpg")==false)
//	alert("请选择正确的文件,只支持[gif,png,jpg]格式!");
function checkUploadFileExt(fileValue,extValue){
	var allowExt=extValue.trim().toLowerCase().split(",");
	var temp=fileValue.trim().toLowerCase().split(".");
	var ext=temp[temp.length-1];
	for(var i=0;i<allowExt.length;i++){
		if(ext==allowExt[i])
			return true;
	}
	return false;
}
function changeBorder(allTitle,allFrame,curTitle,curFrame,defaultTitleClassName,curTitleClassName){
	allTitle=allTitle.split(",");allFrame=allFrame.split(",");
	for(var item in allTitle){
		$(allTitle[item]).className=defaultTitleClassName;
	}
	for(var item in allFrame){
		$(allFrame[item]).style.display='none';
	}
	$(curTitle).className=curTitleClassName;
	$(curFrame).style.display='block';
}

function showBigImagePart(obj,event,bigPicWidth,bigPicHeight){
  var pos=getPosition(obj);
  this.pos=pos;
  if($('imageEnlarge')==null)
	obj.parentNode.innerHTML+='<div style="background:#FFF;position:absolute;width:'+bigPicWidth+'px;height:'+bigPicHeight+'px;border:solid 1px #000000;display:none;overflow:hidden;padding:2px" id="imageEnlargeDiv"><img id="imageEnlarge" style="position:relative;"></div>';
	var source=this;
	this.imgPic=obj;
	this.bigPicWidth=bigPicWidth;
	this.bigPicHeight=bigPicHeight;
	var enlargeImage=new Image();
	enlargeImage.onload=function(){
		$('imageEnlargeDiv').style.left=(pos.x+source.imgPic.width+10)+"px";
		$('imageEnlargeDiv').style.top=(pos.y-(pos.y>10?10:0))+"px";
		$('imageEnlargeDiv').style.display='';
		$('imageEnlarge').src=obj.src;
	}
	enlargeImage.src=obj.src;		
	obj.style.cursor="crosshair";
	
	obj.onmouseout=function(){
		setTimeout(function(){
			$('imageEnlargeDiv').style.display="none";
			},100);
			enlargeImage=null;
	}
	obj.onmousemove=function(event){
		var e=event?event:window.event;	
		var enlargeImage=$('imageEnlarge');
		var rate=enlargeImage.height/obj.height;	
		var scrollTop=(document.body.scrollTop==0?document.documentElement.scrollTop:document.body.scrollTop);
		if(scrollTop>5)scrollTop-=5;
		var x=e.x?e.x:e.pageX;
		var y=e.y?e.y:e.pageY;
		//window.status=scrollTop+"px";
		//alert(scrollTop);
		enlargeImage.style.left=(source.bigPicWidth/2+(source.pos.x-x)*rate)+"px";
		enlargeImage.style.top=(source.bigPicHeight/2+(source.pos.y-y-scrollTop)*rate)+"px";
	}
}

function Stack(){
	this.data=new Array();
	this.index=-1;
	this.push=function(value){
		this.data[++this.index]=value;
	}
	this.pop=function(){
		if(this.index==0)return null;
		return this.data[--this.index];
	}
	this.isEmpty=function(){
		return this.index<=0;
	}
}

function Queue(){
	this.data=new Array();
	this.index=-1;
	this.head=-1;
	this.push=function(value){
		this.data[++this.index]=value;
	}
	this.pop=function(){
		if(this.head==this.index)return null;
		return this.data[++this.head];
	}
	this.isEmpty=function(){
		return this.head==this.index;
	}
}

function setClass(objId,className){$(objId).className=className;}
function addClass(objId,className){$(objId).className+=" "+className;}
function removeClass(objId,className){$(objId).className=$(objId).className.replace(className,"");}
function setStyle(objId,styleName,styleValue){
	styleName=styleName.toLowerCase().replace(/\-/ig,"");
	for(var item in $(objId).style){
		if(item.toLowerCase()==styleName){eval("$('"+objId+"').style."+item+"='"+styleValue+"'");return true;}
	}return false;
}
function getStyle(objId,styleName){
	var oriStyleName=styleName;
	styleName=styleName.toLowerCase().replace(/\-/ig,"");var t;
	for(var item in $(objId).style){	
		if(item.toLowerCase()==styleName){
			eval("t=$('"+objId+"').style."+item);
			if($(objId).currentStyle)
				eval("t=$('"+objId+"').currentStyle."+item);
			if(document.defaultView)
				eval("t=document.defaultView.getComputedStyle($(objId),null)."+item);
			if(t=="auto")	
				eval("t=$('"+objId+"').offset"+oriStyleName);
			return t;
		}
	}return false;
}
/******取得对象函数集**********/
function getObjectById(id){return $(id);}
function getChildNodes(parent){
	var objs=parent.childNodes;
	var k=new Array();
	var index=0;
	for(var i=0;i<objs.length;i++){
		if(typeof(objs[i].tagName)!="undefined")
			k[index++]=objs[i];
	}
	return k;
}
function getObjectByName(name){return document.getElementsByName(name)}	//闁告瑦鐗曠欢杈┾偓鐢殿攰閽?By Name
function getObjectByTagName(tagName){return document.getElementsByTagName(tagName)}	//闁告瑦鐗曠欢杈┾偓鐢殿攰閽栧嚉y TagName
function $(id){
	//根据对象ID返回该对象
	if(typeof(id)=="object") return id;
	else{
		var obj = document.getElementById(id);
		if(typeof(obj)=="undefined") obj=parent.document.getElementById(id);
		return obj;
	}
}
function getPosition(obj) 	//得到网页对象的屏幕坐标bj.x||obj.y
{
	var r = {x:0,y:0};r['x'] = obj.offsetLeft;r['y'] = obj.offsetTop;
	while(obj = obj.offsetParent) {	r['x'] += obj.offsetLeft;r['y'] += obj.offsetTop;}
	return r;
}
/***************Cookie相关函数******************/
function getCookie(name) 
{
	var cookie_start = document.cookie.indexOf(name);
	var cookie_end = document.cookie.indexOf(";", cookie_start);
	return cookie_start == -1 ? '' : unescape(document.cookie.substring(cookie_start + name.length + 1,(cookie_end > cookie_start ? cookie_end : document.cookie.length)));
}

function setCookie(name, value, hours)
{
  var expire = "";
  if(hours != null)
  {
    expire = new Date((new Date()).getTime() + hours * 3600000);
    expire = "; expires=" + expire.toGMTString();
  }
  document.cookie = name + "=" + escape(value) + expire;
}

/*
 * 表单处理函数集
*/
function submitForm(formId){$(formId).submit();}
function $FV(id)
{
	var value=new Array(),valueIndex=0,temp=$(id),returnType=0;

	if(temp.type=="checkbox")
	{
		temp=getObjectByName(id);
		for(var i=0;i<temp.length;i++)
			if(temp[i].checked==true)value[valueIndex++]=temp[i].value;
		return value;
	}
	if(temp.tagName.toLowerCase()=="select"&&temp.multiple==true)
	{
		for(var i=0;i<temp.options.length;i++)
			if(temp.options[i].selected==true)value[valueIndex++]=temp.options[i].value;
		return value;
	}
	if(temp.type=="radio")
	{
		temp=getObjectByName(id);
		for(var i=0;i<temp.length;i++)
			if(temp[i].checked==true)return temp[i].value;
		return "";
	}
	return temp.value;	
}

function setSelectIndexByValue(id,value){
	var temp=$(id);
	if(!temp)return ;
	for(var i=0;i<temp.options.length;i++)
		if(temp.options[i].value.toString()==value.toString())
			temp.options[i].selected=true;
}
function setRadioCheckedByValue(name,value){
	var temp=getObjectByName(name);
	for(var i=0;i<temp.length;i++)
	{
		if(temp[i].value.toString()==value.toString())
			temp[i].checked=true;
	}
}
function setSelectIndexByText(id,value){
	var temp=$(id);
	for(var i=0;i<temp.options.length;i++){
		if(temp.options[i].text.toString()==value.toString()){
			temp.options[i].selected=true;return true;
		}
	}
	return false;
}
function setCheckBoxCheckedByValue(name,values){
	var value=new Array();
	if(!values[0]){value[0]=values;}else value=values;
	var temp=getObjectByName(name);
	for(var i=0;i<temp.length;i++)
	{
		for(var j=0;j<value.length;j++)
			if(temp[i].value.toString()==value[j].toString())
				temp[i].checked=true;
			else
        temp[i].checked=false;
	}	
}
function selectAll(name,selected){
	var temp=getObjectByName(name);
	for(var i=0;i<temp.length;i++){
		if(!temp[i].disabled)	//禁用则不选中
			temp[i].checked=selected;
	}
}
function selectUnAll(name){
	var temp=getObjectByName(name);
	for(var i=0;i<temp.length;i++)
		temp[i].checked=!temp[i].checked;
}
function selectAddOption(objectId,value,text,index){
	var temp=$(objectId);
	if(!temp){document.status=objectId+" object not exists!";return false;}
	if(typeof(index)=="undefined"){var index=temp.options.length};
	var op=document.createElement("option");
	op.value=value;	op.text=text;temp.options.add(op,index);return true;
}
function selectRemoveOption(objectId,optionIndex){
	var obj=$(objectId);
	if(typeof(index)=="undefined"){var optionIndex=obj.options.length};
	obj.options.remove(optionIndex);
}
function selectRemoveAllOptions(objectId){
	var obj=$(objectId);var length=obj.options.length;
	for(var i=0;i<length;i++)
		obj.remove(0);
}
function selectRemoeOptionByValue(objectId,value){	
	var obj=$(objectId);var length=obj.options.length;
	for(var i=0;i<length;i++)
		if(obj.options[i].value.toString()==value.toString())
			obj.options.remove(i);			
}
function selectOptionExist(objectId,value,isText){	
	var obj=$(objectId);var length=obj.options.length;
	if(typeof(isText)=="undefined"){var isText=false};
	for(var i=0;i<length;i++){		
		if(!isText){
			if(obj.options[i].value.toString()==value.toString()){ return true };
		}else{
			if(obj.options[i].text.toString()==value.toString()) { return true };
		}
	}
	return false;
}

function execUrl(url,ctlName){
	var temp=getObjectByName(ctlName);
	var strId = "";
	var isCheck=true;
	var target = "";
	if(typeof(arguments[2])!='undefined') { isCheck=arguments[2]; }
	if(typeof(arguments[3])!='undefined') { target=arguments[3]; }
		
	for(var i=0;i<temp.length;i++){
		if(temp[i].checked){
			strId += temp[i].value + ",";
		}
	}
	strId = strId.substr(0,strId.length-1);
	
	if(isCheck && strId==""){ alert('对不起，你还没有选择!'); return false; }
	if(!confirm("确认操作?")){ return false;}
	
	if(url.substr(0,1)=='?') {
		var s=document.location.href;
		s=s.slice(s.lastIndexOf("/")+1,s.length);
		if(s.indexOf("?")!=-1) s=s.slice(0,s.indexOf("?"));
		url = s + url;
	}
	url += strId + "&"+Date();
	AjaxObj.Request({spanId:"divinfo",message:"<font color='#cccccc'>正在提交数据</font>"},"get",url,null,function(){
		if(this.responseText=="succeed"){ 
			alert("恭喜，操作成功！");
			if(target=="parent") { parent.location.reload(); }
			else{ window.location.reload();}
		}
		else alert(this.responseText);
	});
}

function showSmallPic(obj){
	exName = obj.src.substr(obj.src.lastIndexOf('.'));
	obj.src = obj.src+"_small"+exName;
}

function redirect(url,target){
	if(url.substr(0,1)=='?') {
		var s=document.location.href;
		s=s.slice(s.lastIndexOf("/")+1,s.length);
		if(s.indexOf("?")!=-1) s=s.slice(0,s.indexOf("?"));
		url = s + url;
	}
	if(typeof(target)=="undefined") window.location.href=url;
	else target.location.href=url;
}

function orderby(cur,order){
	urlstr = window.location.href;
	query = window.location.search.toString();
	if(query=="") urlstr += "?";
	if(urlstr.indexOf('&od=')==-1) urlstr+="&od=";
	searchstr = urlstr.substr(urlstr.indexOf('&od='));
	urlstr = urlstr.substr(0,urlstr.indexOf('&od=')+4);	//只启用单一排序
	oldOrder = cur+":"+order;
	newOrder = cur+":"+Math.abs(parseInt(order)-1);
	if(searchstr.indexOf(oldOrder)>-1)
		urlstr = urlstr.replace('&od=', '&od='+newOrder);
	else
		urlstr = urlstr.replace('&od=', '&od='+newOrder);
	window.location.href=urlstr;
}

//var t1=new createInnerWindow(contentId,newWindowId,width,height,top,left,zIndex,display,showLoading,title,closeFunction)
function createInnerWindow(contentId,newWindowId,width,height,top,left,zIndex,display,showLoading,title,closeFunction){
	if(typeof(display)=="undefined")	var display=false;
	if(typeof(zIndex)=="undefined")	var zIndex=10;
	if(typeof(left)=="undefined")	var left=10;
	if(typeof(top)=="undefined")	var top=10;
	if(typeof(height)=="undefined")	var height=300;
	if(typeof(width)=="undefined")	var width=500;
	if(typeof(showLoading)=="undefined")	var showLoading=false;
	if(typeof(title)=="undefined")	var title=null;
	if(typeof(closeFunction)=="undefined")var closeFunction=null;
	
	var target = null;
	if(newWindowId.indexOf('.')!=-1){
		var tmp = newWindowId.split('.');
		newWindowId = tmp[1];
		target = tmp[0];
	}
	
	if(target==null){
		if($(newWindowId)==null){
			this.nWindow=document.createElement("div");
			this.nWindow.id=newWindowId+"_small";
		}else{
			$(newWindowId).id=newWindowId+"_small";
			this.nWindow=$(newWindowId+"_small");
		}
	}
	
	this.body1=document.getElementsByTagName('body');
	this.fullscreen=document.createElement("div");
	this.fullscreen.id=newWindowId;	//+"_fullscreen";
	this.fullscreen.style.cssText="left:0px;top:0px;position:absolute;z-index:"+zIndex+";";
	this.fullscreen.style.width=(document.documentElement.clientWidth-5)+"px";
	//alert(document.body.scrollHeight);
	this.fullscreen.style.height=(document.documentElement.clientHeight-5)+"px";
	var objFull=this.fullscreen;
	this.closeFunction=closeFunction;
	
	objFull.innerHTML="<iframe src='' width=100% height=100% frameborder='0' id='"+newWindowId+"_iframeBG' style='filter: Alpha(Opacity=60);'></iframe>";

	this.fullscreen.appendChild(this.nWindow);
	
	if(!this.body1.length>0){
		alert("f");return false;
	}else
		this.body1[0].appendChild(this.fullscreen);
	//$(newWindowId+'_iframeBG').document.onselectstart=function(){return false;};
	
	$(newWindowId+"_small").style.cssText="position:absolute;z-index:"+(zIndex+1)+";left:"+left+"px;top:"+top+"px;width:"+width+"px;height:"+height+"px;border:solid 1px #656565;background:#FFFFFF;"
	var titleHtml="";
	titleHtml='<div id="'+newWindowId+'_title" style="height:30px; line-height:30px; background:url(/public/images/titlebg.gif); text-align:right;margin:0 0 5px 0;border-bottom:solid 1px #e1e1e1"><div style="float:left;margin:0 0 0 5px;border:text-align:left;font-size:14px;font-weight:600;color:#5e5e5e; ">';
	if(title!=null)
		titleHtml=titleHtml+title;		
	titleHtml+='</div><div style="float:right;width:50px"><a href="#" id="'+newWindowId+'_close" ';
	if(closeFunction==null)
		titleHtml+='onclick="$(\''+newWindowId+'\').style.display=\'none\'"';
	else
	{
		closeFunction=closeFunction.toString();
		if(closeFunction.indexOf("(")==-1)
			closeFunction+="()";
		titleHtml+=' onclick="'+closeFunction+';$(\''+newWindowId+'\').style.display=\'none\'" ';
	}
	titleHtml+=' style="font-size:16px;font-weight:600;margin:0 5px 0  0">关闭</a></div></div>';
	$(newWindowId+"_small").innerHTML=titleHtml;
	if(showLoading==true){
		if($(newWindowId+"_loading")==null)
			$(newWindowId+"_small").innerHTML+="<img src='/public/images/loading.gif' id='"+newWindowId+"_loading'/>";		
	}
	///////////
	if(typeof(contentId)=="object")
	{
		try{
			contentId.parentNode.removeChild(contentId);
			$(newWindowId+"_small").appendChild(contentId);	//+=contentId.innerHTML;		
		}catch(e){}
	}else
		$(newWindowId+"_small").innerHTML+=contentId;
	if(typeof(display)!="undefined"){
		if(display==true){
			$(newWindowId).style.display="";
		}else
			$(newWindowId).style.display="none";
	}
	try{
		this.t1=new moveObj(newWindowId+'_title',newWindowId+"_small");
	}catch(e){}
}

//隐藏菜单
function hiddenMenu(curId,num){
	var id = curId.substr(0,curId.length-1);
	var cur = parseInt(curId.substr(curId.length-1));
	for(var i=1;i<=num;i++)
		if(i!=cur){ $(id+i).style.display = "none";}
}

function formatNumber(number,pattern){   
    var str            = number.toString();   
    var strInt;   
    var strFloat;   
    var formatInt;   
    var formatFloat;   
    if(/\./g.test(pattern)){   
        formatInt        = pattern.split('.')[0];   
        formatFloat        = pattern.split('.')[1];   
    }else{   
        formatInt        = pattern;   
        formatFloat        = null;   
    }   
  
    if(/\./g.test(str)){   
        if(formatFloat!=null){   
            var tempFloat    = Math.round(parseFloat('0.'+str.split('.')[1])*Math.pow(10,formatFloat.length))/Math.pow(10,formatFloat.length);   
            strInt        = (Math.floor(number)+Math.floor(tempFloat)).toString();                  
            strFloat    = /\./g.test(tempFloat.toString())?tempFloat.toString().split('.')[1]:'0';              
        }else{   
            strInt        = Math.round(number).toString();   
            strFloat    = '0';   
        }   
    }else{   
        strInt        = str;   
        strFloat    = '0';   
    }   
    if(formatInt!=null){   
        var outputInt    = '';   
        var zero        = formatInt.match(/0*$/)[0].length;   
        var comma        = null;   
        if(/,/g.test(formatInt)){   
            comma        = formatInt.match(/,[^,]*/)[0].length-1;   
        }   
        var newReg        = new RegExp('(\\d{'+comma+'})','g');   
  
        if(strInt.length<zero){   
            outputInt        = new Array(zero+1).join('0')+strInt;   
            outputInt        = outputInt.substr(outputInt.length-zero,zero)   
        }else{   
            outputInt        = strInt;   
        }   
  
        var   
        outputInt            = outputInt.substr(0,outputInt.length%comma)+outputInt.substring(outputInt.length%comma).replace(newReg,(comma!=null?',':'')+'$1')   
        outputInt            = outputInt.replace(/^,/,'');   
  
        strInt    = outputInt;   
    }   
  
    if(formatFloat!=null){   
        var outputFloat    = '';   
        var zero        = formatFloat.match(/^0*/)[0].length;   
  
        if(strFloat.length<zero){   
            outputFloat        = strFloat+new Array(zero+1).join('0');   
            var outputFloat1    = outputFloat.substring(0,zero);   
            var outputFloat2    = outputFloat.substring(zero,formatFloat.length);   
            outputFloat        = outputFloat1+outputFloat2.replace(/0*$/,'');   
        }else{   
            outputFloat        = strFloat.substring(0,formatFloat.length);   
        }   
  
        strFloat    = outputFloat;   
    }else{   
        if(pattern!='' || (pattern=='' && strFloat=='0')){   
            strFloat    = '';   
        }   
    }   
  
    return strInt+(strFloat==''?'':'.'+strFloat);   
}


function Sleep(obj,iMinSecond) 
{ 
if (window.eventList==null) 
window.eventList=new Array(); 
var ind=-1; 
for (var i=0;i<window.eventList.length;i++) 
{ 
if (window.eventList[i]==null) 
{ 
window.eventList[i]=obj; 
ind=i; 
break; 
} 
} 
if (ind==-1) 
{ 
ind=window.eventList.length; 
window.eventList[ind]=obj; 
} 
setTimeout("GoOn(" + ind + ")",iMinSecond); 
} 
function GoOn(ind) 
{ 
var obj=window.eventList[ind]; 
window.eventList[ind]=null; 
if (obj.NextStep) obj.NextStep(); 
else obj(); 
}