// 2006-08-14, ajax for signup.htm
function ajax_checkEmailExist() {
    //var xmlHttp = AjaxObject.getXMLHTTP();
    var xmlHttp = AjaxObject.prototype.getXMLHTTP();

    if (!xmlHttp) {
        alert('Give up :( Cannot create an XMLHTTP instance');
        return false;
    }

    // build param here
    szEmail = document.frmEdit.cust_email.value;
    if (szEmail == "") return;
    szURL = "ajaxentry.php?action=checkEmailExist&cust_email="+ szEmail;

    xmlHttp.onreadystatechange = function() { ajax_showEmailExist(xmlHttp); };
    xmlHttp.open('GET', szURL, true);
    xmlHttp.send(null);

} //end function

// 2006-08-14, ajax for signup.htm
function ajax_showEmailExist(xmlHttp) {
    if (xmlHttp.readyState == 4) {
        if (xmlHttp.status == 200) {
            //alert(xmlHttp.responseText);
            if (xmlHttp.responseText == "OK") {
                document.getElementById('err_report').innerHTML = "Contratulations! Your username is available.";
                //Contratulations! wwwwwwwww is available for you to use.
            } else {
                document.getElementById('err_report').innerHTML = "Sorry, your username is already taken. Please try a different one.";
                document.getElementById('err_report').style.color = "#FF0000";
                //Sorry, Sithlet is already taken. Please try a different one.
            } //end if
        } else {
            alert('There was a problem with the request.');
        } //end if
    } //end if
} //end function


function ajax_getGroupRate() {
    var xmlHttp = AjaxObject.prototype.getXMLHTTP();

    if (!xmlHttp) {
        alert('Give up :( Cannot create an XMLHTTP instance');
        return false;
    }

    // build param here
    szID = document.frmEdit.cust_group.value;
    if (szID == "") szID =1;
    szURL = "ajaxentry.php?action=getGroupRate&cgrp_id="+ szID;

    xmlHttp.onreadystatechange = function() { ajax_showGroupRate(xmlHttp); };
    xmlHttp.open('GET', szURL, true);
    xmlHttp.send(null);
}

// 2006-11-30, ajax for admin/cust_edit.htm
function ajax_showGroupRate(xmlHttp) {
    if (xmlHttp.readyState == 4) {
        if (xmlHttp.status == 200) {
            //alert(xmlHttp.responseText);
            document.getElementById('rate_report').innerHTML = xmlHttp.responseText;
        } else {
            alert('There was a problem with the AJAX request.');
        } //end if
    } //end if
} //end function


//2007-10-31
function ajax_newsletter_add() {
    var xmlHttp = AjaxObject.prototype.getXMLHTTP();

    if (!xmlHttp) {
        alert('Give up :( Cannot create an XMLHTTP instance');
        return false;
    }

    // build param here
    szEmail = document.getElementById("news_email").value;
    szName = document.getElementById("news_name").value;
    objRet = document.getElementById("newsletter_return");

    szURL = "ajaxentry.php?action=newsletter_add&news_email="+ szEmail +"&news_name="+ szName;

    xmlHttp.onreadystatechange = function() { ajax_ShowNewsletterResult(xmlHttp); };
    xmlHttp.open('GET', szURL, true);
    xmlHttp.send(null);
} //end function


function ajax_ShowNewsletterResult(xmlHttp) {
    if (xmlHttp.readyState == 4) {
        if (xmlHttp.status == 200) {
            //document.getElementById('newsletter_return').innerHTML = xmlHttp.responseText;
            if (xmlHttp.responseText == "OK") {
                document.getElementById('newsletter_return').innerHTML = "Contratulations! Your email is added into our newsletter.";
                //Contratulations! wwwwwwwww is available for you to use.
            } else {
                document.getElementById('newsletter_return').innerHTML = xmlHttp.responseText;
                document.getElementById('newsletter_return').style.color = "#FF0000";
            } //end if
        } else {
            alert('There was a problem with the AJAX request.');
        } //end if
    } //end if
} //end function

function ajax_update_cart() {
    var xmlHttp = AjaxObject.prototype.getXMLHTTP();

    if (!xmlHttp) {
        alert('Give up :( Cannot create an XMLHTTP instance');
        return false;
    }

    // build param here
    szEmail = document.frmEdit.cust_email.value;
    if (szEmail == "") return;
    szURL = "ajaxentry.php?action=checkEmailExist&cust_email="+ szEmail;

    xmlHttp.onreadystatechange = function() { ajax_showEmailExist(xmlHttp); };
    xmlHttp.open('GET', szURL, true);
    xmlHttp.send(null);
} //end function
