﻿var dotype="";
var xmlhttp=false;

function getHttpRequestObject()
{
	try
	{
		//首先尝试遗留对象
		xmlhttp=new ActiveXObject("Msxml2.XMLHTTP");
	}
	catch(e)
	{
		try
		{
			//现在尝试IE实现
			xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
		}		
		catch(E)
		{
			xmlhttp=false;
		}
	}
	if(!xmlhttp&&typeof XMLHttpRequest!='undefined')
	{
		//因为我们必须使用基于Mozilla的浏览器，所以现在创建一个本地请求对象
		xmlhttp=new XMLHttpRequest();
	}
}

function dosavemymy(url,content,type)
{  
    dotype=type;
	getHttpRequestObject();
	if(xmlhttp)
	{
	xmlhttp.open("POST",url,true);
	xmlhttp.setRequestHeader("Content-Length",content.length); 
	xmlhttp.setRequestHeader("CONTENT-TYPE","application/x-www-form-urlencoded");

	xmlhttp.onreadystatechange=callback;
	xmlhttp.send(content);
	}
	else
	{
	alert("本站使用了AJAX技术，而您的浏览器不支持。");
	}
}


function callback()
{
 if(dotype=="SendStory")
	{
	if(xmlhttp.readyState==4)
	{
		if(xmlhttp.status==200)
		{
     		var result=xmlhttp.responseText;
     		if(result==1)
     		{
     		   alert("谢谢!您的成功分享已经成功提交. ");
     		   	$id("t_mid").value="";
     		   		$id("t_email").value="";
     		   			$id("t_name").value="";
     		   				$id("r_remark").value="";
     		}
     		else
     		{
     		alert("提交失败，请稍后重试。");
     		}
		}
		else{alert("发生意外错误，请稍后重试。");}
	}}
	else if(dotype=="CheckMember")
	{
	if(xmlhttp.readyState==4)
	{
		if(xmlhttp.status==200)
		{
     		var result=xmlhttp.responseText;
     		if(result==1)
     		{
     		   $id("Yest_mid").style.display="";
     	       $id("Not_mid").style.display="none";
     		}
     		else
     		{
     	    	$id("Not_mid").style.display="";
     	    	$id("Yest_mid").style.display="none";
     	    	$id("t_mid").value="";
     		}
		}
		else{alert("发生意外错误，请稍后重试。");}
	}}
}
	
	
//获取指定标签的ID
var $id=function(id)
{return document.getElementById(id);}

function SendStory(uid,email,name,detail)
{
if(trim(uid).length<=0)
{
alert("请填写你的MemberID");
return;
}
if(trim(email).length<=0)
{
alert("邮箱不能为空");
return;
}

if(!email.match(/^[\w-]+(\.[\w-]+)*@[\w-]+(\.[\w-]+)+$/))
{
$id("Not_email").style.display="";
$id("Yest_email").style.display="none";
alert("请填写正确的E-mail");
return;
}

 if(detail.length==0)
{
alert("请告诉我们你的成功分享")
return;
}  

if(detail.length<200)
{
alert("你的成功分享不能少于200字")
return;
}
if(detail.length>800)
{
alert("你的成功分享不能多于200字")
return;
}
 var content="uid="+uid+"&email="+email+"&name="+name+"&detail="+detail+"&dotype=SendStory";

 dosavemymy("/AjaxValidate/SuccessStory.ashx",content,"SendStory");
}


function check(obj)
{
   if(obj.id=="t_mid")
   {
       if(trim(obj.value).length>0)
 	    {
 		   $id("Yest_mid").style.display="";
 	       $id("Not_mid").style.display="none";
 		}
 		else
 		{
 	    	$id("Not_mid").style.display="";
 	    	$id("Yest_mid").style.display="none";
 		}
//     var content="uid="+obj.value+"&dotype=CheckMember";
//     dosavemymy("/AjaxValidate/SuccessStory.ashx",content,"CheckMember");
   }
   else if(obj.id=="t_email")
   {
    if(!obj.value.match(/^[\w-]+(\.[\w-]+)*@[\w-]+(\.[\w-]+)+$/))
    {
       $id("Not_email").style.display="";
      $id("Yest_email").style.display="none";
    }
    else{
       $id("Not_email").style.display="none";
      $id("Yest_email").style.display="";
      }
   }
}
function CheckSite(obj)
{
    $id('Count').innerHTML=obj.value.length;
    if(obj.value.length+1>800)
    {
        obj.value=obj.value.substring(0,800);
    }
}

//去左空格; 
function ltrim(s){ 
return s.replace( /^\s*/, ""); 
} 
//去右空格; 
function rtrim(s){ 
return s.replace( /\s*$/, ""); 
} 
//去左右空格; 
function trim(s){ 
return rtrim(ltrim(s)); 
}