function checkemail(emailid, msgdiv)
{
	var y=document.getElementById(emailid).value;
	var patt1 = /[A-z0-9.-]+@[A-z0-9.-]+.[A-z0-9]/g;
	elm=document.getElementById(msgdiv);

	if (y.match(patt1) != y)
	{
	    elm.innerHTML = "<span style='color:red'>Wrong email fmt</span>";
	    return false;
	}
	else
	{
	    elm.innerHTML = "<span style='color:green'>Ok fmt</span>";
	    return true;
	}
}
function checkcoupon(codeid, msg_id) {
    code = document.getElementById(codeid).value;
    //use ajax to check if the email address exists in the account
    if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari
        xmlhttp = new XMLHttpRequest();
    }
    else {// code for IE6, IE5
        xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
    }

    xmlhttp.onreadystatechange = function() {
        if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
                document.getElementById(msg_id).innerHTML = xmlhttp.responseText;
        }
    }
    xmlhttp.open("GET", "./couponman.php?checkcode=" + code, true);
    xmlhttp.send();
    return false;
}
function checkusername(usernameid, msg_id) {
    username = document.getElementById(usernameid).value;
    //use ajax to check if the email address exists in the account
    if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari
        xmlhttp = new XMLHttpRequest();
    }
    else {// code for IE6, IE5
        xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
    }

    xmlhttp.onreadystatechange = function() {
        if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
            document.getElementById(msg_id).innerHTML = xmlhttp.responseText;
        }
    }
    xmlhttp.open("GET", "./userman.php?checkuser=" + username, true);
    xmlhttp.send();
    return false;
}
function checkuseremail(useremailid, msg_id) {
    useremail = document.getElementById(useremailid).value;
    //use ajax to check if the email address exists in the account
    if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari
        xmlhttp = new XMLHttpRequest();
    }
    else {// code for IE6, IE5
        xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
    }

    xmlhttp.onreadystatechange = function() {
        if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
            document.getElementById(msg_id).innerHTML = xmlhttp.responseText;
        }
    }
    xmlhttp.open("GET", "./userman.php?checkuseremail=" + useremail, true);
    xmlhttp.send();
    return false;
}
function invitecheck(friend_email_id, msg_place_id) {
    email = document.getElementById(friend_email_id).value;
    if (checkemail(friend_email_id, msg_place_id) == false) 
    {
        document.getElementById('invite_submit').disabled = true;
        return false;
    }
    //use ajax to check if the email address exists in the account
    if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari
        xmlhttp = new XMLHttpRequest();
    }
    else {// code for IE6, IE5
        xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
    }

    xmlhttp.onreadystatechange = function() {
        if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
            if (xmlhttp.responseText == 'exist') {
                document.getElementById(msg_place_id).innerHTML = '<span style="color:red">user already exists!</span>';
                
                document.getElementById('invite_submit').disabled = true;
            }
            else {
                document.getElementById(msg_place_id).innerHTML = '<span style="color:green">ok!</span>';
                
                document.getElementById('invite_submit').disabled = false;
            }
        }
    }

    xmlhttp.open("GET", "acclib.php?checkemail=" + email, true);
    xmlhttp.send();

}


