
function DrawImage(ImgD,iwidth,iheight){
 var flag=false;
 var image=new Image();
 image.src=ImgD.src;
 if(image.width>0 && image.height>0){
 flag=true;
 if(image.width/image.height>= iwidth/iheight){
 if(image.width>iwidth){ 
 ImgD.width=iwidth;
 ImgD.height=(image.height*iwidth)/image.width;
 }else{
 ImgD.width=image.width; 
 ImgD.height=image.height;
 }
 //ImgD.alt=image.width+"×"+image.height;
 }
 else{
 if(image.height>iheight){ 
 ImgD.height=iheight;
 ImgD.width=(image.width*iheight)/image.height; 
 }else{
 ImgD.width=image.width; 
 ImgD.height=image.height;
 }
 //ImgD.alt=image.width+"×"+image.height;
 }
 }
 /*else{
 ImgD.src="";
 ImgD.alt=""
 }*/
 } 
 
 //留言信息检测 
function changeimage()
{ 
	document.formwrite.GuestImages.value=document.formwrite.Image.value;
	document.formwrite.showimages.src="admin/images/guestbook/"+document.formwrite.Image.value+".gif";
}
function guestpreview()
{
document.preview.content.value=document.formwrite.GuestContent.value;
var popupWin = window.open('GuestPreview.asp', 'GuestPreview', 'scrollbars=yes,width=620,height=230');
document.preview.submit()
} 
function check(thisform)
{
   if(thisform.GuestName.value==""){
		alert("姓名不能为空！")
		 thisform.GuestName.focus()
		  return(false) 
	  }
	  if ( thisform.GuestName.value.length < 2 || thisform.GuestName.value.length > 20 ){
    alert("用户名长度在2-20个字符");
    thisform.GuestName.focus();
    return false;
  }
	  if (thisform.GuestName.value.indexOf("%") != -1 || thisform.GuestName.value.indexOf("'") != -1 || thisform.GuestName.value.indexOf('"') != -1 || thisform.GuestName.value.indexOf("=") != -1 || thisform.GuestName.value.indexOf("<") != -1 || thisform.GuestName.value.indexOf(">") != -1) {
			alert("真实姓名中不能有%、'、=、<和>等非法字符！");
	    thisform.GuestName.focus();
		return false;
}
	  
	  if(thisform.tel.value==""){
		alert("联系电话不能为空！")
		thisform.tel.focus()
		return(false)
	  }
	
	  if ( thisform.tel.value !="" ){
      var ascii,i
    for ( i = 1 ; i <= thisform.tel.value.length ; i++ ) {
        charaa =thisform.tel.value.charAt(i-1);
        if  ( charaa != 0 && charaa != 1 && charaa != 2 && charaa != 3 && charaa != 4 && charaa != 5 && charaa != 6 && charaa != 7 && charaa != 8  && charaa != 9 && charaa != "-") {
        alert("电话号码格式错误");
        thisform.tel.focus(); 
        		return false;
         }
  }
  
  if ( thisform.tel.value.length < 5 || thisform.tel.value.length > 15 ){
    alert("电话号码长度在5-15个字符");
    thisform.tel.focus();
    return false;
  }
}

	  if(thisform.email.value==""){
		alert("E_amil不能为空！")
		thisform.email.focus()
		return(false)
	  }

	    if (thisform.email.value.indexOf("%") != -1 || thisform.email.value.indexOf("'") != -1 || thisform.email.value.indexOf('"') != -1 || thisform.email.value.indexOf("=") != -1 || thisform.email.value.indexOf("<") != -1 || thisform.email.value.indexOf(">") != -1) {
			alert("电子邮箱中不能有%、'、=、<和>等非法字符！");
	    thisform.email.focus();
		return false;
}


  if ( thisform.email.value.length < 6 || thisform.email.value.length > 30 ){
    alert("电子邮箱长度在6-30个字符");
    thisform.email.focus();
    return false;
  }

if ( thisform.email.value.indexOf(".") == -1 || thisform.email.value.indexOf("@") == -1 ) {
		alert("电子邮件地址的格式不正确，请重新填写！");
	    thisform.email.focus();
		return false;
}

   if(thisform.GuestTitle.value==""){
		alert("留言主题不能为空！")
		thisform.GuestTitle.focus()
		return(false)
	  }

   if(thisform.GuestContent.value==""){
		alert("留言内容不能为空！")
		thisform.GuestContent.focus()
		  return(false)
	  }

   if(thisform.GuestContent.value.length>500){
		alert("留言内容不能超过500字符！")
		thisform.GuestContent.focus()
		  return(false)
	  }
}
function gbcount(message,total,used,remain)
{
	var max;
	max = total.value;
	if (message.value.length > max) {
	message.value = message.value.substring(0,max);
	used.value = max;
	remain.value = 0;
	alert("留言不能超过 500 个字!");
	}
	else {
	used.value = message.value.length;
	remain.value = max - used.value;
	}
}

//结束

//人才信息检测
function CheckForm() {
 var errorMsg = "";

if(this.myform.yourname.value=="")
{
errorMsg += "\n\t真实姓名 \t- 真实姓名不能为空！请键入真实姓名; \n"
}
if ( this.myform.yourname.value!="" && (this.myform.yourname.value.length < 2 || this.myform.yourname.value.length > 20) ){
   	errorMsg += "\n\t真实姓名 \t- 真实姓名长度在2-20个字符; \n"
  }
if (this.myform.yourname.value.indexOf("&") != -1 || this.myform.yourname.value.indexOf("%") != -1 || this.myform.yourname.value.indexOf("'") != -1 || this.myform.yourname.value.indexOf('"') != -1 || this.myform.yourname.value.indexOf("=") != -1 || this.myform.yourname.value.indexOf("<") != -1 || this.myform.yourname.value.indexOf(">") != -1) {
	errorMsg += "\n\t真实姓名 \t- 真实姓名中不能有&、%、'、=、<和>等非法字符！ \n"
}

if(this.myform.birthday.value=="")
{
errorMsg += "\n\t出生年月 \t- 出生年月不能为空！请键入出生年月; \n"
}

if (this.myform.birthday.value.indexOf("&") != -1 || this.myform.birthday.value.indexOf("%") != -1 || this.myform.birthday.value.indexOf("'") != -1 || this.myform.birthday.value.indexOf('"') != -1 || this.myform.birthday.value.indexOf("=") != -1 || this.myform.birthday.value.indexOf("<") != -1 || this.myform.birthday.value.indexOf(">") != -1) {
	errorMsg += "\n\t出生年月 \t- 出生年月中不能有&、%、'、=、<和>等非法字符！ \n"
}

if(this.myform.school.value=="")
{
errorMsg += "\n\t毕业院校 \t- 毕业院校不能为空！请键入毕业院校; \n"
}
if(this.myform.zhuanye.value=="")
{
errorMsg += "\n\t专业 \t\t- 专业不能为空！请键入您的专业; \n"
}
if(this.myform.xueli.value=="")
{
errorMsg += "\n\t最高学历 \t- 最高学历不能为空！请键入最高学历; \n"
}
//---------------------------------------------------------
if(checkspace(this.myform.phone.value)) {
    errorMsg += "\n\t电话号码 \t- 电话号码不能为空！请键入电话号码; \n"
  }
    for ( iii = 1 ; iii <= myform.phone.value.length ; iii++ ) {
        chara =myform.phone.value.charAt(iii-1);
        if  ( chara != 0 && chara != 1 && chara != 2 && chara != 3 && chara != 4 && chara != 5 && chara != 6 && chara != 7 && chara != 8  && chara != 9 ) {
        errorMsg += "\n\t电话号码 \t- 电话号码格式有误！请重新填写; \n"
         }
	}
//---------------------------------------------------------
if (this.myform.email.value.indexOf("%") != -1 || this.myform.email.value.indexOf("'") != -1 || this.myform.email.value.indexOf('"') != -1 || this.myform.email.value.indexOf("=") != -1 || this.myform.email.value.indexOf("<") != -1 || this.myform.email.value.indexOf(">") != -1) {
		errorMsg += "\n\t电子邮箱 \t- 电子邮箱中不能有&、%、'、=、<和>等非法字符！ \n"
}


  if ( this.myform.email.value!="" && (this.myform.email.value.length < 6 || this.myform.email.value.length > 30) ){
       errorMsg += "\n\t电子邮箱 \t- 电子邮箱长度在6-30个字符！ \n"
  }

if (this.myform.email.value!="" && (this.myform.email.value.indexOf(".") == -1 || this.myform.email.value.indexOf("@") == -1) ) {
		errorMsg += "\n\t电子邮箱 \t- 电子邮件地址的格式不正确，请重新填写！ \n"
}

if (errorMsg != ""){
		msg = "_____________________________________________________________________\n\n";
		msg += "提交失败。\n";
		msg += "请修正错误后重新提交。\n";
		msg += "_____________________________________________________________________\n\n";
		msg += "如下项目需要更正: -\n";
		
		errorMsg += alert(msg + errorMsg + "\n\n");
		return false;
	}
	
	return true;
}
	
 function regInput(obj, reg, inputStr)
 {
  var docSel = document.selection.createRange()
  if (docSel.parentElement().tagName != "INPUT") return false
  oSel = docSel.duplicate()
  oSel.text = ""
  var srcRange = obj.createTextRange()
  oSel.setEndPoint("StartToStart", srcRange)
  var str = oSel.text + inputStr + srcRange.text.substr(oSel.text.length)
  return reg.test(str)
 }
 function checkspace(checkstr) {
  var str = '';
  for(i = 0; i < checkstr.length; i++) {
    str = str + ' ';
  }
  return (str == checkstr);
}
