﻿// JScript File

function SendEmail()
{    

    if(CheckSendMailForm())
    {       
        var data = "textUserName=" + encodeURI(document.form1.textName.value) + 
            "&textUserEmail=" + encodeURI(document.form1.textEmail.value) + 
            "&textUserMessage=" + encodeURI(document.form1.textMessage.value);
        
        StartRequestPost("AJAX/SendContactUsEmail.aspx", data,  handleStateChange);
    }
}

function CheckSendMailForm()
{
    with(document.form1)
    {   
        if(!CheckMandatory(textName, "Please input your name"))
        {
            KillEvent(event);
            return false;
        }
 
        if(!CheckMandatory(textEmail, "Please input your email"))
        {
            KillEvent(event);
            return false;
        }
        
        if(!CheckEmail(textEmail, "Your email has incorrect format"))
        {
            KillEvent(event);
            return false;
        }
        
        if(!CheckMandatory(textMessage, "Please input your message"))
        {
            KillEvent(event);
            return false;
        }
    }
    
    return true;
}

function handleStateChange()
{

    if(xmlHttp.readyState == 4)
    {
		  //alert(xmlHttp.status);
        if(xmlHttp.status == 200)
        {
            OutputMailResponse(xmlHttp.responseText);
				return false;
        }
    }
}

function OutputMailResponse(text)
{
    alert(text);
}
