
	//Login/Register fields
	var xmlhttp;
	var pwdtxt;
	var count = 0;
	
	//Body
	function sendBodyRequest(pn)
	{
		xmlhttp=GetXmlHttpObject();
		if (xmlhttp==null)
		{
			alert ("Your browser does not support AJAX!");
			return;
		}
		var url="body.php";
			url=url+"?page="+pn;
		xmlhttp.onreadystatechange=stateBodyChanged;
		xmlhttp.open("GET",url,true);
		xmlhttp.send(null);
	}

	function stateBodyChanged()
	{
		if (xmlhttp.readyState==4)
		{
			document.getElementById("body").innerHTML=xmlhttp.responseText;
		}
	}
	//Send ajax request
	function sendLoginRequest(pn)
	{
		xmlhttp=GetXmlHttpObject();
		if (xmlhttp==null)
		{
			alert ("Your browser does not support AJAX!");
			return;
		}
		var url="server.php";
			url=url+"?login="+pn;
		xmlhttp.onreadystatechange=stateLoginChanged;
		xmlhttp.open("GET",url,true);
		xmlhttp.send(null);
	}

	function stateLoginChanged()
	{
		if (xmlhttp.readyState==4)
		{
			document.getElementById("login").innerHTML=xmlhttp.responseText;
		}
	}
	
	//check UserName availablity
	function sendCheckIDRequest(pn)
	{
		xmlhttp=GetXmlHttpObject();
		if (xmlhttp==null)
		{
			alert ("Your browser does not support AJAX!");
			return;
		}
		var url="checkavail.php";
			url=url+"?username="+pn;
		xmlhttp.onreadystatechange=stateCheckIDChanged;
		xmlhttp.open("GET",url,true);
		xmlhttp.send(null);
	}

	function stateCheckIDChanged()
	{
		if (xmlhttp.readyState==4)
		{
			document.getElementById("idavail").innerHTML=xmlhttp.responseText;
		}
	}
	
	//Check Email Availability
	function sendCheckEmailRequest(pn)
	{
		xmlhttp=GetXmlHttpObject();
		if (xmlhttp==null)
		{
			alert ("Your browser does not support AJAX!");
			return;
		}
		var url="checkavail.php";
			url=url+"?email="+pn;
		xmlhttp.onreadystatechange=stateCheckEmailChanged;
		xmlhttp.open("GET",url,true);
		xmlhttp.send(null);
	}

	function stateCheckEmailChanged()
	{
		if (xmlhttp.readyState==4)
		{
			document.getElementById("emailavail").innerHTML=xmlhttp.responseText;
		}
	}

	//Get the object
	function GetXmlHttpObject()
	{
		if (window.XMLHttpRequest)
		{
			// code for IE7+, Firefox, Chrome, Opera, Safari
			return new XMLHttpRequest();
		}
		if (window.ActiveXObject)
		{
			// code for IE6, IE5
			return new ActiveXObject("Microsoft.XMLHTTP");
		}
		return null;
	}
	
	
//Form Validation
	function validate_email(field,alerttxt)
	{
		with (field)
		{
			apos=value.indexOf("@");
			dotpos=value.lastIndexOf(".");
			if (apos<1||dotpos-apos<2)
			{
				alert(alerttxt);return false;
			}
			else {return true;}
		}
	}	
	function validate_required(field,alerttxt,defaulttxt)
	{
		with (field)
		{
			if (value==null||value==""||value==defaulttxt)
			{
				alert(alerttxt);return false;
			}
			else
			{
				return true;
			}
		}
	}
	
	function confirm_password(p1, p2, alerttxt)
	{
		if(p1.value != p2.value)
		{
			alert(alerttxt); return false;
		}
		else
		{
			return true;
		}
	}

	function validate_form(thisform)
	{
		with (thisform)
		{
			if (validate_required(username,"Username must be filled out!", username.defaultValue)==false)
			{
				username.focus();return false;
			}
			if (validate_required(password,"Password must be filled out!", password.defaultValue)==false)
			{
				password.focus();return false;
			}
			if (validate_required(password2,"Password must be confirmed!", password2.defaultValue)==false)
			{
				password2.focus();return false;
			}
			if (confirm_password(password, password2, "Passwords do not match!") ==false)
			{
				password.focus();return false;
			}
			if (validate_required(firstname,"Firstname must be filled out!", firstname.defaultValue)==false)
			{
				firstname.focus();return false;
			}
			if (validate_required(lastname,"Lastname must be filled out!", lastname.defaultValue)==false)
			{
				lastname.focus();return false;
			}
			if (validate_required(email,"Email must be filled out!", email.defaultValue)==false)
			{
				email.focus();return false;
			}
			if (validate_email(email,"Not a valid e-mail address!")==false)
			{
				email.focus();return false;
			}
			
		}	
	}
	
	function validate_login(thisform)
	{
		with (thisform)
		{
			if (validate_required(username,"Username must be filled out!", username.defaultValue)==false)
			{
				username.focus();return false;
			}
			if (validate_required(password,"Password must be filled out!", password.defaultValue)==false)
			{
				password.focus();return false;
			}
		}
	}
	
	//Form field switch between Password - Text 
	function clearText(thefield, fieldid)
	{
		if(thefield.defaultValue != '')
		{
			pwdtxt = thefield.defaultValue;
		}
		var pswrd=document.getElementById(fieldid);
		try // Works on all browsers other than IE
		{
			pswrd.setAttribute('type','password');
			if (thefield.defaultValue==thefield.value)
				thefield.value = "";
		}
		catch(e) // Fix for IE
		{
			var inp=document.createElement('input');
			inp.setAttribute('name','password');
			inp.setAttribute('type','password');
			inp.className='field';
			inp.value=(thefield.value===pwdtxt)?'':thefield.value;
			inp.onfocus=function()
			{
				clearText(this, fieldid);
			};
			inp.onblur=function()
			{
				resetText(this, fieldid);
			};
			inp.setAttribute('id',fieldid);
			
			pswrd.parentNode.insertBefore(inp,pswrd);
			pswrd.parentNode.removeChild(pswrd);
			inp.focus();
		}
	}
	function resetText(thefield, fieldid)
	{
		var pswrd=document.getElementById(fieldid);
		try // Works on all browsers other than IE
		{
			pswrd.setAttribute('type','password');
			if (thefield.value=="")
			{
				pswrd.setAttribute('type','text');
				thefield.value = thefield.defaultValue;
			}
		}
		catch(e) // Fix for IE
		{
			var inp=document.createElement('input');
			inp.setAttribute('name','password');
			if(thefield.value == '')
			{
				inp.setAttribute('type','text');
			}
			else
			{
				inp.setAttribute('type','password');
			}
			inp.className='field';
			inp.value=(thefield.value==='')?pwdtxt:thefield.value;
			inp.onfocus=function()
			{
				clearText(this, fieldid);
			};
			inp.onblur=function()
			{
				resetText(this, fieldid);
			};
			inp.setAttribute('id',fieldid);
			pswrd.parentNode.insertBefore(inp,pswrd);
			pswrd.parentNode.removeChild(pswrd);
		}
	}
	function clearTextConfirm(thefield, fieldid)
	{
		if(thefield.defaultValue != '')
		{
			pwdConfirmTxt = thefield.defaultValue;
		}
		var pswrd=document.getElementById(fieldid);
		try // Works on all browsers other than IE
		{
			pswrd.setAttribute('type','password');
			if (thefield.defaultValue==thefield.value)
				thefield.value = "";
		}
		catch(e) // Fix for IE
		{
			var inp=document.createElement('input');
			inp.setAttribute('name','password');
			inp.setAttribute('type','password');
			inp.className='field';
			inp.value=(thefield.value===pwdConfirmTxt)?'':thefield.value;
			inp.onfocus=function()
			{
				clearTextConfirm(this, fieldid);
			};
			inp.onblur=function()
			{
				resetTextConfirm(this, fieldid);
			};
			inp.setAttribute('id',fieldid);
			
			pswrd.parentNode.insertBefore(inp,pswrd);
			pswrd.parentNode.removeChild(pswrd);
			inp.focus();
		}
	}
	function resetTextConfirm(thefield, fieldid)
	{
		var pswrd=document.getElementById(fieldid);
		try // Works on all browsers other than IE
		{
			pswrd.setAttribute('type','password');
			if (thefield.value=="")
			{
				pswrd.setAttribute('type','text');
				thefield.value = thefield.defaultValue;
			}
		}
		catch(e) // Fix for IE
		{
			var inp=document.createElement('input');
			inp.setAttribute('name','password');
			if(thefield.value == '')
			{
				inp.setAttribute('type','text');
			}
			else
			{
				inp.setAttribute('type','password');
			}
			inp.className='field';
			inp.value=(thefield.value==='')?pwdConfirmTxt:thefield.value;
			inp.onfocus=function()
			{
				clearTextConfirm(this, fieldid);
			};
			inp.onblur=function()
			{
				resetTextConfirm(this, fieldid);
			};
			inp.setAttribute('id',fieldid);
			pswrd.parentNode.insertBefore(inp,pswrd);
			pswrd.parentNode.removeChild(pswrd);
		}
	}
	
