function BaseTrim(str){
	  lIdx=0;rIdx=str.length;
	  if (BaseTrim.arguments.length==2)
	    act=BaseTrim.arguments[1].toLowerCase()
	  else
	    act="all"
      for(var i=0;i<str.length;i++){
	  	thelStr=str.substring(lIdx,lIdx+1)
		therStr=str.substring(rIdx,rIdx-1)
        if ((act=="all" || act=="left") && thelStr==" "){
			lIdx++
        }
        if ((act=="all" || act=="right") && therStr==" "){
			rIdx--
        }
      }
	  str=str.slice(lIdx,rIdx)
      return str
}

function BaseAlert(theText,notice){
	alert(notice);
	theText.focus();
	theText.select();
	return false;
}


function HighLightOver(){
	HighLightList("#E0E6F7");
}
function HighLightOut(){
	HighLightList("");
}

function HighLightList(color){
	var el=event.srcElement;
	var b=false;
	var tabElement=null;
	while (!b){
		el=GetParentElement(el, "TR")
		if (el){
			tabElement=GetParentElement(el, "TABLE");
			if (tabElement!=null && tabElement.className.toUpperCase()=="LIST"){
				break;
			}
			el=tabElement;
		}else{
			return;
		}
	}
	
	for (var i=0;i<el.children.length;i++){
		if (el.children[i].tagName=="TD"){
			el.children[i].style.backgroundColor=color;
		}
	}
}

function GetParentElement(obj, tag){
	while(obj!=null && obj.tagName!=tag)
		obj=obj.parentElement;
	return obj;
}

document.onmouseover=HighLightOver
document.onmouseout=HighLightOut

function checkForm(elements){
	if(elements="content"){		
		if(checkContent()==false)return false;
	}else{		
		if(checkNewusr()==false||checkPwd()==false||checkChoice())return false;
	}
}	
function checkContent(){
		var obj=document.form.content;
		if(obj.value==""){
			obj.focus();
			alert("内容不能为空！\n")
		}
}
function checkNewusr(){
	var	obj=document.form.newusr;
		obj.value=BaseTrim(obj.value);
	if(obj.value==""){
		alert("用户名不能为空！\n");
		return false;
		}
}
function checkPwd(){
	var	obj=document.form.newpwd1;
		obj.value=BaseTrim(obj.value);
	if (obj.value=="") {
		BaseAlert(obj, "密码不能为空！");
		return false;
	}
	if (document.form.newpwd1.value!=document.form.newpwd2.value){
		BaseAlert(document.form.newpwd1, "密码和确认密码不相同！");
		return false;
	}
}

function checkEmail(){
	var theEmail=document.form.email.value;	
	if(theEmail.charAt(0)=="*"||theEmail.indexOf("@")==-1||theEmail.lastIndexOf(".")==-1){
		alert("Email输入格式不正确！输入请按照以下格式及字符：\"*@*.*\"且\"*\"只能为大小写字母，数字及某些符号，其中符号不能在首位和末位|例如：searchermy@gmail.com");
		return false;
	}
}
function checkZcsj(){
	var theZcsjn=document.form.zcsjn.value;
	var theZcsjy=document.form.zcsjy.value;
	var theZcsjr=document.form.zcsjr.value;
	if(theZcsjn==""||theZcsjy==""||theZcsjr==""){
		alert("请正确输入时间！");
		return false;
		}	
}

function choiceBox(choice){
	var inputs = document.getElementsByTagName("input");   
	for(var i =0;i<inputs.length;i++)   
	{   
		if(inputs[i].type == "checkbox")   
		{   
			if(choice=='all')inputs[i].checked = true;
			
			if(choice=='reverse'){
				if(inputs[i].checked == true)inputs[i].checked = false
				else inputs[i].checked = true;				
			}
			if(choice=='no')inputs[i].checked = false;
		}  
	} 	
}

function HtmlEncode(text){
	return text.replace(/&/g, '&amp').replace(/\"/g, '&quot;').replace(/</g, '&lt;').replace(/>/g, '&gt;');
}

function doChange(objText, objDrop){
	if (!objDrop) return;
	var str = objText.value;
	var arr = str.split("|");
	objDrop.length=0;
	for (var i=0; i<arr.length; i++){
		objDrop.options[i] = new Option(arr[i], arr[i]);
	}
}

function changeInputState(){
	var obj=document.form1.theCharge;
	var theCharge_arr=document.form1.taxpayercode.value.split(",");
	obj.value=theCharge_arr[1];
	if(obj.value==0){	
		document.form1.tel.disabled="disabled";
	}else{
		document.form1.tel.disabled="";		
	}
}

function SubForm(url){
//	if(document.form1.identifynum.value.length<15 || document.form1.identifynum.value.length>20){
//		alert('纳税人识别号必须大于15位小于20位');
//		document.form1.identifynum.focus();
//		return false;
//	}else if(document.form1.taxpayername.value==""){
//		alert("纳税人名称不能为空！");
//		document.form1.taxpayername.focus();
//		return false;
//	}else if(document.form1.departmentcode.value==""){
//		alert("税务机关未选择！");
//		document.form1.departmentcode.focus();
//		return false;
//	}else if(document.form1.taxpayercode.value==""){
//		alert("纳税人类型未选择！");
//		document.form1.taxpayercode.focus();
//		return false;
//	}else if(document.form1.theCharge.value==1&&document.form1.tel.value==""){	
//		alert("纳税人类型为收费类型时绑定电话必须填写！");
//		document.form1.tel.focus();
//		return false;
//	}else if(document.form1.theCharge.value==1&&document.form1.tel.value.length!=7 && document.form1.tel.value.length!=11){	
//		alert("电话号码位数错误！");
//		document.form1.tel.focus();
//		return false;
//	}else if(document.form1.theCharge.value==1&&document.form1.num.value==""){	
//		alert("纳税人类型为收费类型时旗下需要付费的企业人员的手机数量必须填写！");
//		document.form1.num.focus();
//		return false;
//	}else if(document.form1.taxpayerstate.value==""){
//		alert("纳税人状态未选择！");
//		document.form1.taxpayerstate.focus();
//		return false;
//	}else if(document.form1.dredgeusername.value==""){
//		alert("开通人姓名不能为空！");
//		document.form1.dredgeusername.focus();
//		return false;
//	}
document.form1.action=url;
document.form1.submit();
}

function DrawImage(ImgD,w,h){ 
 var image=new Image(); 
 var width=w
 var height=h
 image.src=ImgD.src; 
 if(image.width>0 && image.height>0){ 
  flag=true; 
  if(image.width/image.height>= width/height){ 
   if(image.width>width){
    ImgD.width=width; 
    ImgD.height=(image.height*width)/image.width; 
   }else{ 
    ImgD.width=image.width;
    ImgD.height=image.height; 
   } 
   ImgD.alt=image.width+"x"+image.height; 
  } 
  else{ 
   if(image.height>height){
    ImgD.height=height; 
    ImgD.width=(image.width*height)/image.height; 
   }else{ 
    ImgD.width=image.width;
    ImgD.height=image.height; 
   } 
   ImgD.alt=image.width+"x"+image.height; 
  } 
 }
}

function Drawimage(ImgD,h){ 
 var image=new Image(); 
 
 var height=h;
 image.src=ImgD.src; 
 var width=image.width;
 if(image.width>0 && image.height>0){ 
  flag=true; 
  if(image.width/image.height>= width/height){ 
   if(image.width>width){
    ImgD.width=width; 
    ImgD.height=(image.height*width)/image.width; 
   }else{ 
    ImgD.width=image.width;
    ImgD.height=image.height; 
   } 
   ImgD.alt=image.width+"x"+image.height; 
  } 
  else{ 
   if(image.height>height){
    ImgD.height=height; 
    ImgD.width=(image.width*height)/image.height; 
   }else{ 
    ImgD.width=image.width;
    ImgD.height=image.height; 
   } 
   ImgD.alt=image.width+"x"+image.height; 
  } 
 }
}
