//close errors

function KillErrors() { 
	//return true; 
} 
window.onerror = KillErrors;

function _doFormHandle(task){
var __handle=true;
document.adminform._task.value=task;
document.adminform.target = '_self';
__handle=formhandle(document.adminform);

if(__handle){
	document.adminform.submit();
}
}

function _doPost(task,hasUserMethod,message,action,target)
{
	
	
	if(window.document.getElementById('promptlayer')){
	  window.document.getElementById('promptlayer').style.visibility="visible";	
	}
	
	
	
	try{
	document.adminform._task.value=task;
	if(!target){
	document.adminform.target = '_self';
	}else{
	document.adminform.target = target;
	}

	
	if(!action){
	document.adminform.action = "";
	}else{
	document.adminform.action = action;
	}
		//document.adminForm.onsubmit();
	
	
		var __UserMethod = true
		if(hasUserMethod)
			__UserMethod = _UserMethod();	
	

	if(message){
		if(!confirm(message)) {
			return;
		}
	}else{
		
		if(task == 'remove') {
			if(!confirm("删除操作确认?")) {
				return;
			}
		}
	}

	if(__UserMethod)
		document.adminform.submit();
	}catch(e){alert("_doPost::" +"\n"+ ex.number+"\n"+ex.description);}
}

function _doPostNoWait(task,hasUserMethod,message,action,target)
{
	
	try{
	document.adminform._task.value=task;
	if(!target){
	document.adminform.target = '_self';
	}else{
	document.adminform.target = target;
	}


	if(!action){
	document.adminform.action = "";
	}else{
	document.adminform.action = action;
	}
		//document.adminForm.onsubmit();
	
	
		var __UserMethod = true
		if(hasUserMethod)
			__UserMethod = _UserMethod();	
	

	if(message){
		if(!confirm(message)) {
			return;
		}
	}else{
		
		if(task == 'remove') {
			if(!confirm("删除操作确认?")) {
				return;
			}
		}
	}

	
	if(__UserMethod)
		document.adminform.submit();
	}catch(e){alert("_doPost::" +"\n"+ ex.number+"\n"+ex.description);}
}

function _do(_id,task,message)
{
	try {
		var theForm = document.adminform;
		theForm.chkall.checked = false;
		CheckAll();
		var _chkbox = theForm.elements['cid[]'];
		
		theForm._task.value = task;
		
		if(!_chkbox.length) {
			_chkbox.checked = true;
		} else {
			_chkbox[_id].checked = true;
		}
		
		if(message){
			if(!confirm(message)) {
				return;
			}
		}else{
	
			if(task == 'remove') {
				if(!confirm("删除操作确认?")) {
					return;
				}
			}
		
		}
		
		
		
		theForm.submit();
	} catch(ex) {
		alert("_do::" +"\n"+ ex.number+"\n"+ex.description);
	}
}

function _doSite(frm){

	frm.submit();
}

function _doPage(page,task)
{
	if(!task) task = 'page';
	document.adminform._page.value=page;
	document.adminform._task.value=task;
	document.adminform.target = '_self'
	document.adminform.action = ""
	try {
		document.adminForm.onsubmit();
		}
	catch(e){}
	
	
	document.adminform.submit();
}

function checkSelected() {

	frmName = 'adminform';
	srcGroupName = 'cid[]';
	chk = getSelectedRadio( frmName, srcGroupName );
	return chk;
}

function getSelectedRadio( frmName, srcGroupName ) {

	var form = eval( 'document.' + frmName );
	var srcGroup = form.elements[srcGroupName];

	if (srcGroup[0]) {
		for (var i=0, n=srcGroup.length; i < n; i++) {
			if (srcGroup[i].checked) {
				return srcGroup[i].value;
			}
		}
	} else {
		if (srcGroup.checked) {
			//alert(srcGroup.value);
			return srcGroup.value;
		} // if the one button is checked, return zero
	}
   // if we get to this point, no radio button is selected
   return null;
}

function CheckAll(form)
{
	if(!form)
		form = document.adminform
	for (var i=0;i<form.elements.length;i++)
	{
		var e = form.elements[i];
		if (e.name != 'chkall')
			e.checked = form.chkall.checked;
	}
}

function GroupAll(form,status,tag)
{
	for (var i=0;i<form.elements.length;i++)
	{
		var e = form.elements[i];
		if (e.name.indexOf(tag) != -1)
			e.checked = status;
    }
}

function ForbidEnter(){
	try{
		if(event.keyCode == 13)
		{
			return false;
		}
	} catch(ex) {}
}

function AddOption(obj,_text,_value){ 

	var _option = document.createElement("option");
	obj.add(_option,0);
	_option.value	= _value;
	_option.text	= _text;
	obj.selectedIndex = 0;
}

function RemoveOption(obj){
	obj.options.removeChild(obj.options[obj.options.selectedIndex]); 
}

function OpenBrowser(url, width, height )
{
	var iLeft = (FCKConfig.ScreenWidth  - width) / 2 ;
	var iTop  = (FCKConfig.ScreenHeight - height) / 2 ;

	var sOptions = "toolbar=no,status=no,resizable=yes,dependent=yes" ;
	sOptions += ",width=" + width ;
	sOptions += ",height=" + height ;
	sOptions += ",left=" + iLeft ;
	sOptions += ",top=" + iTop ;
	window.open( url, "FileManage", sOptions ) ;
}
/*
function OpenFtpBrowser(files,width, height){
	var iLeft = 0;
	var iTop  = 0;
	
	var sOptions = "toolbar=no,status=no,resizable=yes,dependent=yes" ;
	sOptions += ",width=" + width ;
	sOptions += ",height=" + height ;
	sOptions += ",left=" + iLeft ;
	sOptions += ",top=" + iTop ;
	window.open( ftpUrl, "Ftp", sOptions ) ;

}
*/
function ShowFileManage(){
	arr=window.showModalDialog(filemanageUrl,"0","dialogHeight:480px;dialogWidth:500px;help: no; status: no; scroll: no;");
	return unescape(arr)
	//alert(arr);
}
/*
function ShowBandParam(){
	var bandParamUrl="../tmpband.php";
	arr=window.showModalDialog(bandParamUrl,"0","dialogHeight:480px;dialogWidth:500px;help: no; status: no; scroll: no;");
	//return unescape(arr)
}
*/
function ShowBandParam(id,type){
	var bandParamUrl="../band.php?st=1&blocktype="+type;
	if(id!=0) bandParamUrl+="&id="+id;
	var width=600;
	var height=400;
	var sOptions = "toolbar=no,status=no" ;
	sOptions += ",width=" + width ;
	sOptions += ",height=" + height ;
	window.open( bandParamUrl, "BandManage", sOptions ) ;
	
	//arr=window.showModalDialog(bandParamUrl,"0","dialogHeight:480px;dialogWidth:500px;help: no; status: no; scroll: no;");
	//return unescape(arr)
}

function ShowCardinfo(){
	var bandParamUrl="./cardinfo.php";
	var width=600;
	var height=450;
	var sOptions = "toolbar=no,status=no" ;
	sOptions += ",width=" + width ;
	sOptions += ",height=" + height ;
	window.open( bandParamUrl, "CardManage", sOptions ) ;
}

function cardreload(id){

	var newlink='';
	var newparamStr='';
	var paramStr=window.opener.location.search; 

	var params=paramStr.split('&'); 
	for(var i=0;i<params.length;i++) 
	{ 
		var parts=params[i].split('=',2); 
		if(parts[0]!='member_id'){
			if(newparamStr!=''){
				newparamStr+='&'+params[i];
			}else{
				newparamStr=params[i];
			}
		}	 
	} 
	

	newlink="index.php"+newparamStr+"&member_id="+id;
//alert(newlink);
	window.opener.location.href=newlink;
	window.close();
}



function _UserMethod()
{
 try {
	var theForm = document.adminform;
  var _elements = theForm.elements;
  //alert(_elements.length);
  for(var i=0; i<_elements.length; i++)
  {
   var _element = _elements[i];
   //alert(i +":"+ _elements[i].name)
   if(_element.type == 'radio') { //&#1121;&#1462;
    var _radio = theForm[_element.name];
    if(typeof(_radio.length) == 'undefined') {
     if(_radio.title !='') {
      if(_radio.checked == false) {
       alert(_radio.title);
       return false;
      }
     }
    } else {
     if(_radio[0].title !='') {
       
      for(var j=0; j<_radio.length; j++)
      {
       if(_radio[j].checked == true) {
        var _check = 1
       }
      }
      i = i + j -1;
      if(_check != 1) {
       alert(_radio[0].title);
       return false;
      }
     } else {
      i = i + _radio.length-1;
     }
    }
   } else if (_element.type == 'checkbox'){ //&#1121;&#1462;
    var _checkbox = theForm[_element.name];
    //alert(typeof(_checkbox.length))
    if(typeof(_checkbox.length) == 'undefined') {
     if(_checkbox.title !='') {
      if(_checkbox.checked == false) {
       alert(_checkbox.title);
       return false;
      }
     }
    } else {
     if(_checkbox[0].title !='') {
      var _check = null;
      for(var j=0; j<_checkbox.length; j++)
      {
       if(_checkbox[j].checked == true) {
        var _check = 1
       }
      }
      i = i + j -1;
      if(_check != 1) {
       alert(_checkbox[0].title);
       return false;
      }
     } else {
      i = i + _checkbox.length-1;
     }
    }
   } else {
    if(_element.title !='') {
     if(_element.value == '')
     {
      alert(_element.title);
      _element.focus()
      return false;
     }
    }
   }
  }
 }
 catch(ex){
  //alert(ex.number+"\n"+ex.description);
  return false;
 }
 return true
}

function selectlist()
{	
	var SelectedList = "";
	for(var i = 0; i < document.adminform.sltcitytarget.length; i++) 
	{
	SelectedList += (document.adminform.sltcitytarget[i].value + "|");		
	}
	SelectedList = SelectedList.substring(0, SelectedList.length-1);
	document.adminform.strings.value = SelectedList;

	//document.frmjob.submit();
}

function _doReset()
{
	document.adminform.reset();
}

function setImg(obj,value)
{
	files=Array('jpg','gif','png');
	tmp=value.substr(value.length-3,3);
	tmp=tmp.toLowerCase();
	if(in_array(tmp,files))
		obj.src=value;
	else
		obj.src="./images/nophoto.gif";
	}
String.prototype.getRealLength=function(){return this.replace(/[^\x00-\xff]/g,"aa").length;};
String.prototype.trim=function(){return this.replace(/^\s+|\s+$/g,"");}
function in_array(needle,haystack)
{
	type=typeof needle;
	if(type=='string'|| type =='number'){
	for(var i in haystack) {
		if(haystack[i]==needle)
		 return true;
   }
  }
 return false;
}
function SetFileNums(nums,Count){
	
	for(i=1;i<=Count;i++){
		var titleObj = document.getElementById("content_title_" + i);
		var imgObj = document.getElementById("content_img_" + i);
		if(i<=nums){
			titleObj.style.display="block";
			imgObj.style.display="block";
			
		}else{
			titleObj.style.display="none";
			imgObj.style.display="none";
		}

	}
}