function OpenWin(url,target,w,h){
	newWin=window.open(url,target,"toolbar=no,menubar=no,status=no,location=no,scrollbars=yes,resizable=no,copyhistory=yes,width="+w+",height="+h);
	if(newWin)
		newWin.focus();
	else
		alert("Your IE has blocked all popup pages. Please press Ctrl at the same time when clicking the link.")
}
function GetRadioValue(ObjectName){//检验单选按钮
	var Object=document.getElementsByName(ObjectName);	
	for(iIndex=0;iIndex<Object.length;iIndex++)
	{
		if(Object[iIndex].checked==true)
		{
			return true;
		}
	}
	return false;
}
function textCounter(field, countfield, maxlimit) {//限制字数
	if (field.value.length > maxlimit) 
		field.value = field.value.substring(0,maxlimit);
	else 
		countfield.value = maxlimit - field.value.length;		
	
}
function havenoChar(theelement){//含有非法字符 返回 true
   text="'%\"";
   for(i=0;i<=theelement.length-1;i++)
   {
      char1=theelement.charAt(i);
      index=text.indexOf(char1);
      if(index!=-1)
      {
        return true;
      }
   }
   return false;
}

function NotNumber(theelement,flag){//是否数字,flag=1为整数
    if(theelement==""||theelement=="."){
        return true;
    }	
    if(flag){  
	text="1234567890";
	}
    else{
	text="1234567890.";
	}
   for(i=0;i<=theelement.length-1;i++)
   {
      char1=theelement.charAt(i);
      index=text.indexOf(char1);
      if(index==-1)
      {
        return true;
      }
   }
   return false;
}

function checknum(targ,flag)
{//检查输入是否数字
	var num=num;	
	if(targ.value==""){
		alert("Please enter the right number.");
		targ.value=targ.defaultValue;
		targ.focus();
		return;
	}
	if(flag){
		if(NotNumber(targ.value,1)){
			alert("Please enter the right number (integer).");
			targ.value=targ.defaultValue;
			targ.focus();
			return;
		}
	}
	else{
		if(NotNumber(targ.value,0)){
			alert("Please enter the right number.");
			targ.value=targ.defaultValue;
			targ.focus();
			return;
		}		
	}
}

function whichItem(flag){//选择操作对象
	var e = event.srcElement
	while (e.tagName != flag)
		e = e.parentElement
	return e
}

function CheckAll(targ){//全部选中
	if (targ.sel.length==null)
		{//只有一条记录的情况
			targ.sel.checked=targ.selall.checked;
			cca(targ.sel);
		}else{
			for (var i=0;i<targ.sel.length;i++){
			targ.sel[i].checked=targ.selall.checked;
			cca(targ.sel[i]);
			if(targ.selall2!=null)
			targ.selall2.checked=targ.selall.checked;
			}
		}
}


function CheckAll2(targ){//全部选中
	if (targ.sel.length==null)
		{//只有一条记录的情况
			targ.sel.checked=targ.selall2.checked;
			cca1(targ.sel);
		}else{
			for (var i=0;i<targ.sel.length;i++){
			targ.sel[i].checked=targ.selall2.checked;
			cca1(targ.sel[i]);
			if(targ.selall!=null)
			targ.selall.checked=targ.selall2.checked;
			}
		}
}


function CheckSelect(targ){//是否选中，返回选中的记录数目
	var num=0;
	if (targ.sel.length==null)
		{//只有一条记录的情况
			if (targ.sel.checked==true){
				num=1;
			}			
		}else{
			for (var i=0;i<targ.sel.length;i++){
			if(targ.sel[i].checked)
			num+=1;
			}
		}
	if(num==0){
		alert("Please select at least one record.");
		}
	return num;
}

function GetContacts(targ,act,flag){//提交表单,flag非零则每次只能处理一条记录
	if (CheckSelect(targ)) {
		if(flag && CheckSelect(targ)>1){
			alert("Only one record can be executed at one time for this fuction.")
			return;
		}
		if(confirm("Get Contacts will cost your point. Are you sure you want to Get it? ")){
			targ.action=act;
			targ.submit();
		}
	}
}

function Contacts(targ,act)
        {
		if(confirm("Get Contacts will cost your point. Are you sure you want to Get it? "))
		{
			targ.action=act;
			targ.submit();
		}
		}

function AddContacts(targ,act,flag){//提交表单,flag非零则每次只能处理一条记录
	if (CheckSelect(targ)) {
		if(flag && CheckSelect(targ)>1){
			alert("Only one record can be executed at one time for this fuction.")
			return;
		}
			targ.action=act;
			targ.submit();
	}
}

function DeleteAlert(targ,act,flag){//删除警告,flag非零则每次只能处理一条记录
	if (CheckSelect(targ)) {
		if(flag && CheckSelect(targ)>1){
			alert("Only one record can be executed at one time for this fuction.")
			return;
		}
		if(confirm("This information, once deleted, could not be recovered.\Are you sure you want to delete this?")){
			targ.action=act;
			targ.submit();
		}
	}
}

function DoSubmit(targ,act,flag){//提交表单,flag非零则每次只能处理一条记录
	if (CheckSelect(targ)) {
		if(flag && CheckSelect(targ)>1){
			alert("Only one record can be executed at one time for this fuction.")
			return;
		}
		targ.action=act;
		targ.submit();
	}
}

function DoSubmitone(targ,act,flag){//提交表单,flag非零则每次只能处理一条记录
	if (CheckSelect(targ)) {
		if(flag && CheckSelect(targ)>1){
			alert("Only one record can be executed at one time for this fuction.")
			return;
		}
		act;
		targ.submit();
	}
}

function DelAlert(act){//警告
if (confirm("This information, once deleted, could not be recovered.\Are you sure you want to delete this?"))
window.location=act;
return;
}

function cca1(s){//选择后变颜色
	var e=s
	while (e.tagName != "TR")
		e = e.parentElement;	
	if(s.checked)
		e.style.backgroundColor="#C1CDD8";
	else
		e.style.backgroundColor="#e8eef7";
}


function CheckAlert(targ,act,flag){//删除警告,flag非零则每次只能处理一条记录
	if (CheckSelect(targ)) {
		if(flag && CheckSelect(targ)>1){
			alert("Only one record can be executed at one time for this fuction.")
			return;
		}
		if (confirm("警告是否要执行审核相关操作！！\r确认审核/销审所选信息？")){
			targ.action=act;
			targ.submit();
		}
	}
}


function cca(s){//选择后变颜色
	var e=s
	while (e.tagName != "TR")
		e = e.parentElement;	
	if(s.checked)
		e.style.backgroundColor="#C1CDD8";
	else
		e.style.backgroundColor="#FFFFFF";
}






function CheckPage(targ){//检测页码
	if(NotNumber(targ.page.value)){
		alert("Please enter the right page number. Thank you.");
		targ.page.value=targ.page.defaultValue;
		targ.page.focus();
		return false;
	}
	return true;
}
function ChangePage(newpage){//换页
	var newpage=newpage;
	targ=document.pageform;
	targ.page.value=newpage;
	targ.submit();
}
function displayCtl(t_id){//显示或隐藏层
	if (t_id.style.display == "none"){ //如果为隐藏状态切换为显示状态
		t_id.style.display="";      
	}
	else{//否则
		t_id.style.display="none";  //切换为隐藏状态
	}
}

function SelectOption(targ,sv){//根据选定值定位下拉菜单 targ:目标下拉菜单，sv选中的数值
	if(sv=="")return;
	for(i=0;i<=targ.length;i++){
		if(targ.options[i].value==sv){
			targ.selectedIndex=i;
			break;
		}
	}	
}













// 得到一个文本框控件的当前光标位置
　　function getPos(obj)
　　{
　　obj.focus();
　　var workRange=document.selection.createRange();
　　obj.select();
　　var allRange=document.selection.createRange();
　　workRange.setEndPoint("StartToStart",allRange);
　　var len=workRange.text.length;
　　workRange.collapse(false);
　　workRange.select();
　　return len;
　　}
 

 

 　　// 设置一个文本框控件的当前光标位置
　　function setCursor(obj,num){
　　range=obj.createTextRange(); 
　　range.collapse(true); 
　　range.moveStart('character',num); 
　　range.select();
　　}

//　　其主要就是把系统的键盘消息替换成自己的处理，屏蔽掉系统的，这样就可以获得最大的操控。
//　　如此就完成了一个对指定的正则表达式进行格式限制的TEXTBOX就诞生了。
//
//　　附完整代码:


 　　// 根据指定正表达式，来控制OBJ表示
　　function mask(objTextBox,mask) 
　　{
　　// 掩码
　　expMask = new RegExp(mask);
　　// 当前文本框中的文本
　　var strText =objTextBox.value;
　　// 文本长度
　　var nTextLen=strText.length;

　　// 当前光标位置
　　var nCursorPos=getPos(objTextBox);

　　// 按下的键码
　　var nKeyCode = window.event.keyCode;
　　if (nKeyCode > 95) nKeyCode -= (95-47);

　　// 封住传统处理
　　window.event.returnValue = false;
 
　　// 自行处理按钮
　　switch (nKeyCode)
　　{
　　case 8:// 如果动作是退格[<-]
　　{
　　strText =  strText.substr(0,nCursorPos-1) + strText.substr(nCursorPos, nTextLen-nCursorPos);
　　nCursorPos--;
　　break;
　　}
　　case 46:// 如果动作是del[del]
　　{
　　strText =  strText.substr(0,nCursorPos) + strText.substr(nCursorPos+1,nTextLen-nCursorPos-1);
　　nCursorPos--;
　　break;
　　}
　　case 38:// 如果动作是方向键[上]
　　case 39:// 如果动作是方向键[右]
　　{
　　nCursorPos++;
　　break;
　　}
　　case 37:// 如果动作是方向键[左]
　　case 40:// 如果动作是方向键[下]
　　{
　　nCursorPos--;
　　break;
　　}
　　default :
　　{
　　strText =  strText.substr(0,nCursorPos) + String.fromCharCode(nKeyCode) + strText.substr(nCursorPos,nTextLen);
　　nCursorPos++;
　　if (nCursorPos>strText.length)
　　{
　　nCursorPos=strText.length;
　　}
　　break;
　　}

　　}

　　if (strText.match(expMask))
　　{
　　// 输入格式正确
　　objTextBox.value = strText;
　　}

　　// 移动光标
　　setCursor(objTextBox,nCursorPos);
　　}

　　// 得到一个文本框控件的当前光标位置
　　function getPos(obj)
　　{

 　　obj.focus();
　　var workRange=document.selection.createRange();
　　obj.select();
　　var allRange=document.selection.createRange();
　　workRange.setEndPoint("StartToStart",allRange);
　　var len=workRange.text.length;
　　workRange.collapse(false);
　　workRange.select();
　　return len;
　　}

　　// 设置一个文本框控件的当前光标位置
　　function setCursor(obj,num){
　　range=obj.createTextRange(); 
　　range.collapse(true); 
　　range.moveStart('character',num); 

　　range.select();
　　}

/*<input name="i_etmend" type="text" id="i_etmend" value="{I_ETMEND}" maxlength="19"  onkeydown="mask(i_etmend, '^(([0-9]{0,4})\-([0-9]{0,2})\-([0-9]{0,2}) ([0-9]{0,2}):([0-9]{0,2}):([0-9]{0,2}))$')"> */

