// JavaScript Document
function check_info(id)
{
 var str=$("#"+id).attr("value");
 var isright=false;
 var msg="";
 switch(id)
 {
   case "email":
      if(str.length>0)
	  {
        if(str.search(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/) != -1)
          isright=true;//email格式正确
		else
	     msg="Email格式不正确";
	  }
	  else
	  isright=true;//email格式正确
	  break;
   case "username":
      if(str.length<20&&str.length>0)
	   isright=true;
	  else if(str.length>20)
	    msg="称呼太长了";
	  else
	    msg="请填写您的姓名(称呼)";
	  break;
   case "address":
      if(str.length<100)
	   isright=true;
	  else
	    msg="地址似乎太长了";
	  break;
   case "phone":
      if(str.length<100&&str.length>0)
	   isright=true;
	  else if(str.length>100)
	    msg="联系电话视乎太长了";
	  else
	    msg="请填写联系电话，方便我们与您联系";
	  break;
   case "device":
       if(str.length<50&str.length>0)
	     isright=true;
	   else
	    msg="请正确填写电器名称";
	  break;
   case "baoxiu_content":
	     if(str.length<300)
		  isright=true;
	   else
	      msg="具体内容请缩短在300字以内";
	   break;
       
 }
 //alert(msg);
 if(isright==false)
 {
  $("#"+id+"_check").html(msg);
  $("#"+id+"_check").css("visibility","visible");
  $("#"+id).css("border-color","#ff3300");
 }
 else
 {
   $("#"+id+"_check").html("");
  $("#"+id+"_check").css("visibility","hidden");
  $("#"+id).css("border-color","#00cc33");
 }
}

function changechecknum()
{
  $("#checkpic").attr("src","checkNum.php?sid="+Math.random())	;
}

function checkform()
{
  if($("#username").attr("value")==""||$("#phone").attr("value")==""||$("#device").attr("value")=="")
  {
	alert("请谢谢必要的信息")
   return false;
  }
  else if($("#checknum").attr("value")=="")
  {
	  alert("请填写验证码")
   return false;
	}
  else if($("#username_check").css("visibility")=="visible"||$("#phone_check").css("visibility")=="visible"||$("#device_check").css("visibility")=="visible"
   ||$("#address_check").css("visibility")=="visible"||$("#baoxiu_content_check").css("visibility")=="visible"||$("#email_check").css("visibility")=="visible")
  {
	  alert("信息没有正确填写");
      return false;
  }
  else
  {
	 post_baoxiu();
  }
 
}

function post_baoxiu()
{
	 
	 username2=$("#username").attr("value");
	 phone2=$("#phone").attr("value");
	 device2=$("#device").attr("value");
	 email2=$("#email").attr("value");
	 baoxiu_content=$("#baoxiu_content").attr("value");
	 address2=$("#address").attr("value");
	 checknum2=$("#checknum").attr("value");
	 $.ajax({
		type: "post",
		data: {username:username2,phone:phone2,device:device2,address:address2,email:email2,content:baoxiu_content,checknum:checknum2},
		url: "ajaxzhengli.php?type=baoxiu&sid="+Math.random(),
		dataType: "html",
		beforeSend: function(XMLHttpRequest){
			show_touming();
			//$("#wen").html("");
			//ShowLoading("#wenloading");
			
		},
		success: function(data, textStatus){
			//$("#wen").html(data);
            //j_height();
			//alert(data)
			$("#mesWindow").html("");
			if(data=='0')
			{
				alert("验证码不正确");
		    }
			else if(data=='1')
			{
				document.baoxiuform.reset();
				alert("您的报修信息已经发送，我们会尽快与您联系");
		    }
			else
			{
				 alert("数据发送错误，请重新提交");
			}
			//closeWindow()
		},
		complete: function(XMLHttpRequest, textStatus){
			//HideLoading("#wenloading");
			closeWindow()
		},
		error: function(){
			//$("#wen").html("<span style='font-size:12px; color:#666666'>数据读取失败！</span>");//请求出错
		    alert("数据发送错误，请重新提交");
			closeWindow()
		}
});
}

var isIe=(document.all)?true:false;

function show_touming(){
	  closeWindow();
	  var bWidth=parseInt(document.documentElement.scrollWidth);//全屏幕宽度
      var bHeight=parseInt(document.documentElement.scrollHeight);//全屏幕高度
      var back=document.createElement("div");//背景透明层
      back.id="back";
      var styleStr="top:0px;left:0px;position:absolute;background:#666;width:"+bWidth+"px;height:"+bHeight+"px;";
      styleStr+=(isIe)?"filter:alpha(opacity=40);":"opacity:0.40;";
      back.style.cssText=styleStr;
      document.body.appendChild(back);
	  //设置主框
      var mesW=document.createElement("div");
      mesW.id="mesWindow";
      mesW.className="mesWindow";//主框样式
	  //主框内容
      mesW.innerHTML="<div><strong>正在发送您的报修信息，请稍后</strong> <img src=\"images/progressbar_microsoft.gif\" /></div>";
      styleStr="left:60%;top:75%;position:absolute;width:400px; height:40px; font-size:12px; color:#ffffff; margin:0 0 0 -200px";
      mesW.style.cssText=styleStr;
      document.body.appendChild(mesW);
	}

function closeWindow()
     {
	  
      if(document.getElementById('back')!=null)
       {
        document.getElementById('back').parentNode.removeChild(document.getElementById('back'));
        }
      if(document.getElementById('mesWindow')!=null)
      {
       document.getElementById('mesWindow').parentNode.removeChild(document.getElementById('mesWindow'));
      }
	
}