function checkemail(email) {
    if (email.value.length < 5 || email.value.length > 50) {
        document.getElementById('error_msg').innerHTML = "Your email can't be less than 5 characters or more than 50 characters.";
        document.getElementById('emailcheck').src = "http://i58.photobucket.com/albums/g271/jokim1/openweb/icon_check.png";
        return false;
    }
    var patterns = /^[a-zA-Z0-9_-]+([\.][a-zA-Z0-9_-]*)*@[a-zA-Z0-9_-]+(\.[a-zA-Z0-9_-]+)+$/;
   if(!patterns.test(email.value))
    {
        document.getElementById('error_msg').innerHTML = "Your email address is wrong.";
        document.getElementById('emailcheck').src = "http://i58.photobucket.com/albums/g271/jokim1/openweb/icon_check.png";
        return false;
    }

	var xmlHttp = createxmlHttp();
	xmlHttp.onreadystatechange=function() {
		if(xmlHttp.readyState == 4){
			if(xmlHttp.status == 200) {
				var str=new String();
				str=xmlHttp.responseText;
            	if (str == 'no') {
				    document.getElementById('error_msg').innerHTML = "This email address has been registered already.";
				    document.getElementById('emailcheck').src = "http://i58.photobucket.com/albums/g271/jokim1/openweb/icon_check.png";
                	return false;
                }
                else {
                	document.getElementById('error_msg').innerHTML = '';
                	document.getElementById('emailcheck').src = "http://i58.photobucket.com/albums/g271/jokim1/openweb/icon_checked.png";
                }
			}
		}
  	};
	xmlHttp.open("get",facebookurl + "register.php?checkemail=1&email="+email.value+"&ts=[var.url_ts;noerr]",true);
	xmlHttp.send(null);
    return true;
}

function checkpwd(pwd) {
    if (pwd.value.length < 6 || pwd.value.length > 12) {
        document.getElementById('error_msg').innerHTML = "Your password can't be less than 6 characters or more than 12 characters.";
        document.getElementById('pwdcheck').src = "http://i58.photobucket.com/albums/g271/jokim1/openweb/icon_check.png";
        return false;
    }
    
    document.getElementById('pwdcheck').src = "http://i58.photobucket.com/albums/g271/jokim1/openweb/icon_checked.png";
    document.getElementById('error_msg').innerHTML = '';
    return true;
}
function checkrppwd(rppwd) {
    if (rppwd.value != document.getElementById('pwd').value || rppwd.value == '') {
        document.getElementById('error_msg').innerHTML = "Your repeated password is not equal to password.";
        document.getElementById('rppwdcheck').src = "http://i58.photobucket.com/albums/g271/jokim1/openweb/icon_check.png";
        return false;
    }
    
    document.getElementById('rppwdcheck').src = "http://i58.photobucket.com/albums/g271/jokim1/openweb/icon_checked.png";
    document.getElementById('error_msg').innerHTML = '';
    return true;
}

function checkcode(code) {
    var xmlHttp = createxmlHttp();
	xmlHttp.onreadystatechange=function() {
			if(xmlHttp.readyState == 4){
				if(xmlHttp.status == 200) {
					var str=new String();
					str=xmlHttp.responseText;
                	if (str == 'no') {
						document.getElementById('error_msg').innerHTML = "Word Verification Wrong!";
						document.getElementById('codecheck').src = "http://i58.photobucket.com/albums/g271/jokim1/openweb/icon_check.png";
	                    return false;
                    }
                    else {
                    	document.getElementById('codecheck').src = "http://i58.photobucket.com/albums/g271/jokim1/openweb/icon_checked.png";
                    	document.getElementById('error_msg').innerHTML = '';
                    }
				}
			}
  	};
	xmlHttp.open("get",facebookurl + "register.php?checkcode=1&code="+code.value+"&ts=[var.url_ts;noerr]",true);
	xmlHttp.send(null);
    return true;
}

function createxmlHttp() {
	try {
	  // Mozilla / Safari / IE7
		xmlHttp = new XMLHttpRequest();
	} catch (e) {
		// IE
		var XMLHTTP_IDS = new Array('MSXML2.XMLHTTP.5.0',
		'MSXML2.XMLHTTP.4.0',
		'MSXML2.XMLHTTP.3.0',
		'MSXML2.XMLHTTP',
		'Microsoft.XMLHTTP' );
		var success = false;
		for (var i=0;i < XMLHTTP_IDS.length && !success; i++) {
			try {
			 xmlHttp = new ActiveXObject(XMLHTTP_IDS[i]);
			 success = true;
			} catch (e) {}
		}
		if (!success) {
			throw new Error('Unable to create XMLHttpRequest.');
		}
	}
	return xmlHttp;
}

function checkbox_choose(id) {
	var input_var = document.getElementById('use_' + id);
	if (input_var.value == 1) {
		input_var.value = 0;
		document.getElementById('choose_' + id).style.display = "none";
		document.getElementById('nochoose_' + id).style.display = "inline";
	}
	else {
		input_var.value = 1;
		document.getElementById('choose_' + id).style.display = "inline";
		document.getElementById('nochoose_' + id).style.display = "none";
	}
	return false;
}

