	var loginFree = false;	
	
	function validEmail (mail) { 
		 return (new RegExp ("^[_.0-9a-z-]+@([0-9a-z][0-9a-z_-]+.)+[a-z]{2,4}$").test(mail) ? 1 : 0);
	}
	
	function reg(){					
		with(document.forms['register']){
			if(firstName.value != '' && userLoginId.value != '' && currentPassword.value != '' && currentPasswordConfirm.value != '' && companyName.value != '' && email.value != '' && phone.value != ''){
				if(currentPassword.value == currentPasswordConfirm.value){
					if (loginFree) {									
						if (validEmail(email.value)){
							submit();
						} else {
							alert('Email is not valid.');
						}
					} else {
						alert('Sorry, this login id already exists in the system.');
					}
				}else if(currentPassword.value != currentPasswordConfirm.value)
					alert('Passwords do not match.');	
				}else
					alert('Some mandatory fields are not filled.');
			}
	}
	
	function getelem(id) {
		return document.getElementById(id);
	}

	var xmlHttp = createXmlHttpRequestObject();
	
	function createXmlHttpRequestObject() {
		var xmlHttp;
  		// this should work for all browsers except IE6 and older
  		try {
    		// try to create XMLHttpRequest object
    		xmlHttp = new XMLHttpRequest();
  		} catch(e) {
    		// assume IE6 or older
    		var XmlHttpVersions = new Array("MSXML2.XMLHTTP.6.0",
            	            	            "MSXML2.XMLHTTP.5.0",
                	            	        "MSXML2.XMLHTTP.4.0",
                    	            	    "MSXML2.XMLHTTP.3.0",
                        	            	"MSXML2.XMLHTTP",
                                    		"Microsoft.XMLHTTP");
    		// try every prog id until one works
    		for (var i=0; i<XmlHttpVersions.length && !xmlHttp; i++) {
      			try {
        			// try to create XMLHttpRequest object
        			xmlHttp = new ActiveXObject(XmlHttpVersions[i]);
 				} catch (e) {}
    		}
  		}
  		// return the created object or display an error message
  		if (!xmlHttp)
    		alert("Error creating the XMLHttpRequest object.");
  		else
    		return xmlHttp;
	} 
	

	var count = 0;

	function checkName() {
		if (xmlHttp) {
			count = count+1		
			setTimeout("checkUserName("+count+")",500);
		}		
	}
	
	function checkUserName(currCount) {
		if (xmlHttp) {
			if(currCount == count) {
				// try to connect to the server
		    	try {    		
		      		var userName=encodeURIComponent(getelem("userLoginId").value);
		      		var path = "/shared/activecomponents/download/loginCheck.jsp?loginId=" + userName;
		      		var url = "/wp-content/plugins/wp-forum/ajax_proxy.php?ajax_path=" + path;
		      		// initiate reading a file from the server
		      		xmlHttp.open("GET", url, true);
		      		xmlHttp.onreadystatechange = handleResponse;
		      		xmlHttp.send(null);
		    	} catch (e) {
		      		alert("Can't connect to server:\n" + e.toString());
		    	}
			} else {
				getelem("checkExists").innerHTML="<font color=green>Checking...</font>";
			}
		}
  	} 

  	function handleResponse() {		
		if(xmlHttp.readyState==4) {
			if(xmlHttp.status==200) {				
				xmlResponse=xmlHttp.responseXML;				
				xmlElement=xmlResponse.documentElement;
				res=xmlElement.firstChild.data;				
				var checkExists=getelem("checkExists");
				if(res=='true') {
						checkExists.innerHTML="<font color=green>Login Id is available.</font>";
						loginFree = true;
				} else {					
						checkExists.innerHTML="<font color=red>This login Id is already taken.<br>Please try again.</font>";
						loginFree = false;
				}
				if (getelem("userLoginId").value == "") {
					checkExists.innerHTML="";
				}
			} 
		}
	}