// JScript 文件

$(document).ready(function(){
	save();
});

function save(){
	var options = { 
		//target:        '#output1',   // target element(s) to be updated with server response 
		url:           'http://'+top.location.host+'/Control/Ajax.ashx',   //
		beforeSubmit:  showRequest,  // pre-submit callback 
		success:       showResponse , // post-submit callback
		error:         showError 
	}
	$('#myForm').ajaxForm(options);
}
function showRequest(formData, jqForm, options) { 
	return Checkvalue();
}
// post-submit callback 
function showResponse(responseText, statusText)  { 
    alert('提交成功！' ); 
    //$("#div1").hide() 
}

function showError (XMLHttpRequest, textStatus, errorThrown){
	alert('提交失败！');
}

function Checkvalue(){
    var str="";
    if( $("#id").attr("value")==""){
        alert("该产品不存在！");
        return false;
    } 
    if($("#myForm input:eq(2)").attr("value")==""){
		alert("用户名不能为空！");
		return false;
    }
	if($("#myForm input:eq(3)").attr("value")==""){
		alert("手机号不能为空！");
		return false;
	}else{
		if(!checkMobile($("#myForm input:eq(3)").attr("value"))){
			alert("手机格式不正确！");
			return false;
		}	
	}
	if($("#myForm textarea").attr("value")==""){
		alert("留言内容不能为空！");
		return false;
	}
	return true;
}

function checkMobile(s){   
   var regu =/^[1][3|5][0-9]{9}$/;
   return regu.exec(s)
}