﻿
 function SendListEmail(tag)
    {

        if(!ChekTextBox(tag)) return ;
      
        var firstName=$("#txtFirstName").val();
        var Lastname =$("#txtLastName").val();
        var useremail =$("#txtEmail").val();
        var userphone =$("#txtPhone").val();
        var Jojob=null;
        var SelectBuged =null;
        var TxtComments=null;
        if(tag !="title" && tag !="frtitle" && tag!="Subject" && tag !="frSubject" && tag !="cntitle" && tag !="cnSubject" )
        { 
                     TxtComments = $("#txtComment").val();
             Jojob=$("#txtJobTitle").val();
          
        }
        else
        { 

          SelectBuged=$("#SelectBuged option:selected").text();
          
        }
        //string , string Last, string Email, string phone, string about, string city, string lagnuage
         var pathUrl=null;
         if(tag=="en" || tag=="title" || tag=="Subject" || tag=="cn" || tag=="cntitle" || tag=="cnSubject")
         {
            pathUrl="../../../Service/SendEmail.asmx/ServiceSendEmail";
         }
         if(tag=="fr" || tag=="frtitle" ||tag=="frSubject")
         {
            pathUrl="../../Service/SendEmail.asmx/ServiceSendEmail";
         }
         
          $.ajax({
		        type: "POST",
		        url:pathUrl,
		        data:{First:firstName,Last:Lastname,Email:useremail,phone:userphone,Weabout:SelectBuged,Job:Jojob,Comments:TxtComments,lagnuage:tag },
                beforeSend: function(xhr) {
                },
                dataType: "xml",
                success: function(xml) {
                   var txt = $("string",xml).text(); 
                    if(txt=="Success")
                    {
                         if(tag=="en" || tag=="title" || tag=="Subject" )
                         {
                            alert("Your registration has been sent.");
                             cleared(tag);
                            
                         }
                         if(tag=="fr" || tag=="frtitle" ||tag=="frSubject")
                         {
                              alert("Votre inscription a été transmise.");
                               cleared(tag);
                         }
                         if(tag=="cn" || tag=="cntitle" || tag=="cnSubject")
                         {
                            alert("邮件发送成功.");
                            cleared(tag);
                         }
                    }
                    else
                    {
                          if(tag=="en" || tag=="title" || tag=="Subject" )
                         {
                            alert("Failure.");
                             cleared(tag);
                            
                         }
                         if(tag=="fr" || tag=="frtitle" ||tag=="frSubject")
                         {
                              alert("Insuccès.");
                               cleared(tag);
                         }
                         if(tag=="cn" || tag=="cntitle" || tag=="cnSubject")
                         {
                            alert("发送失败.");
                            cleared(tag);
                         }
                    }
                },
                error: function(xml) {
                        alert(xml.responseText);}

            });
    }
    function  cleared(tag)
    {
        $("#txtFirstName").val("");
        $("#txtLastName").val("");
        $("#txtEmail").val("");
        $("#txtPhone").val("");
        
        if(tag=="en" || tag=="fr" || tag=="cn")
        {
            $("#txtComment").val("");
           $("#txtJobTitle").val("");
            
           
        
        }else
        {
          $("#SelectBuged ").attr("value",'Please select one');
        }
    }
    function ChekTextBox(tag)
    {
    
        var firstName=$("#txtFirstName").val();
        var Lastname =$("#txtLastName").val();
        var email =$("#txtEmail").val();
        var phone =$("#txtPhone").val();
        var SelBuged=$("#SelectBuged").val();
        var isOk=true;
        if(firstName=="")
        {
            if(tag=="en" || tag=="title" || tag=="Subject")
            {
                alert("First name required");
            }
            if(tag=="fr" || tag=="frtitle" ||tag=="frSubject")
            {
                alert("Prénom requis");
            }
            if(tag=="cn" || tag=="cntitle" || tag=="cnSubject")
            {
                alert("姓必须填写");
            }
            isOk=false;
            return isOk;
        }
        if(Lastname=="")
        {
            if(tag=="en" || tag=="title" || tag=="Subject")
            {
                alert("Last name required");
            }
            if(tag=="fr" || tag=="frtitle" ||tag=="frSubject")
            {
                alert("Nom de famille requis");
            }
            if(tag=="cn" || tag=="cntitle" || tag=="cnSubject")
            {
                alert("名必须填写");
            }
            isOk=false;
            return isOk;
        }
        if(email=="")
        {
            if(tag=="en" || tag=="title" || tag=="Subject")
            {
                alert("Email required");
            }
            if(tag=="fr" || tag=="frtitle" ||tag=="frSubject")
            {
                alert("Courriel requis");
            }
            if(tag=="cn" || tag=="cntitle" || tag=="cnSubject")
            {
                alert("电子邮件必须填写");
            }
            isOk=false;
            return isOk;
        }
        if(!ismail(email))
        {
            if(tag=="en" || tag=="title" || tag=="Subject")
            {
                alert("Email format is invalid.");
            }
            if(tag=="fr" || tag=="frtitle" ||tag=="frSubject")
            {
                alert("Format du courriel est invalide.");
            }
            if(tag=="cn" || tag=="cntitle" || tag=="cnSubject")
            {
                alert("电子邮件格式不正确");
            }
            isOk=false;
            return isOk;
        }
        if(phone=="")
        {
            if(tag=="en" || tag=="title" || tag=="Subject")
            {
                alert("Phone number required");
            }
            if(tag=="fr" || tag=="frtitle" ||tag=="frSubject")
            {
                alert("Numéro de téléphone requis.");
            }
            if(tag=="cn" || tag=="cntitle" || tag=="cnSubject")
            {
                alert("电子邮件格式不正确");
            }
            isOk=false;
            return isOk;
        }
        if(SelBuged == "Please select one")
        {
                if(tag=="en" || tag=="title" || tag=="Subject")
                {
                    alert(" Please select one.");
                }
                if(tag=="fr" || tag=="frtitle" ||tag=="frSubject")
                {
                    alert("S.v.p. sélectionner une des options.	");
                }
                if(tag=="cn" || tag=="cntitle" || tag=="cnSubject")
                {
                    alert("从哪里得到我们的消息,请选择一项");
                }
            isOk=false;
            return isOk;

        }// end if 
        if(tag=="en" || tag=="fr" || tag=="cn")
        {
               var TxtComments=$("#txtComment").val();
               if(TxtComments == "The first")
               {
                        if(tag=="en")
                        {
                            alert("Questions/Comments. requis");
                        }
                        if(tag=="fr")
                        {
                             alert("Questions/Comments. requis");
                        }
                        if(tag=="cn")
                        {
                            alert("Questions/Comments. requis");
                        }
                  isOk=false;
                  return isOk;
               }
        
        }
    
        return isOk;
    }

function ismail(mail)
{
 return(new RegExp(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/).test(mail));
}
 
