var http_request = false;
var replace_into='';
function makePOSTRequest(url, parameters,area) 
	{
	//alert(rr);
  	replace_into = area;
  	http_request = false;
  	if (window.XMLHttpRequest) 
		{ // Mozilla, Safari,...
	 	http_request = new XMLHttpRequest();
	 	if (http_request.overrideMimeType) 
			{
			// set type accordingly to anticipated content type
			//http_request.overrideMimeType('text/xml');
			http_request.overrideMimeType('text/html');
	 		}
		} 
 	else if (window.ActiveXObject)  // IE
		{
	 	try 
			{
			http_request = new ActiveXObject("Msxml2.XMLHTTP");
	 		}
		catch (e) 
			{
			try 
				{
			   	http_request = new ActiveXObject("Microsoft.XMLHTTP");
				} 
			catch (e) 
				{
				}
	 		}
  		}
  	if (!http_request) 
		{
	 	alert('Cannot create XMLHTTP instance');
	 	return false;
  		}
  
  http_request.onreadystatechange = alertContents;
  http_request.open('POST', url, false);
  http_request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
  http_request.setRequestHeader("Content-length", parameters.length);
  http_request.setRequestHeader("Connection", "close");
  http_request.send(parameters);
}

function alertContents() 
	{
  	if (http_request.readyState == 4) 
		{
	 	if (http_request.status == 200) 
			{
			//alert(http_request.responseText);
			result = http_request.responseText;
			document.getElementById(replace_into).innerHTML = result;            
	 		} 
		else 
			{
			alert('There was a problem with the request.');
	 		}
  		}
	}
   
function get_id_object(id)
	{
	alert(id);
	return document.getElementById(id);	
	}
function get_id_val(id)
	{
		if(document.getElementById(id)!=null)
			return document.getElementById(id).value;	
	}
function email_check(email_address)
{
	var emailchar = /^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i;
	if (emailchar.test(email_address)){
		return true
	}
	else
	{
		return false
	}
}
function openPopUp(URL) {
day = new Date();
id = day.getTime();
eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=1,scrollbars=1,location=0,statusbar=1,menubar=1,resizable=1,width=800,height=600,left = 50,top = 50');");
}
function loading_enable()
	{
	obj_loading=document.getElementById("loading");
	obj_loading.style.display="block";
	}
function loading_disable()
	{
	obj_loading=document.getElementById("loading");
	obj_loading.style.display="none";
	}
function logout()
	{
	loading_enable();
	makePOSTRequest('logout.php','','hmw_ltext1_user');
	loading_disable();
	}
function signin()
	{
	error=0;
	username=get_id_val('si_username');
	userpass=get_id_val('si_userpass');
	obj_err=document.getElementById("error_textid");
	loading_enable();
	if(username=="" || userpass=="")
		{
		error=1;
		html="<div class=\"error_text\">Required Field Marked With an asterisk(*)</div>";
		}
	if(error==1)obj_err.innerHTML=html;	
	else
		{
		post_param = 'username='+username+'&userpass='+userpass;
		makePOSTRequest('signin.php',post_param,'hmw_ltext1_user')
		}
	
	loading_disable();
	}
function delay()	
	{
	;
	}
function signup()
	{
	loading_enable();	
	makePOSTRequest('signup.php','','hmw_ltext1_user');
	loading_disable();
	}
function create()
	{
	name=get_id_val('su_name');
	username=get_id_val('su_username');
	email=get_id_val('su_email');
	pass1=get_id_val('su_pass1');
	pass2=get_id_val('su_pass2');
	obj_err=document.getElementById("error_textid");
	loading_enable();
	error=0;
	if(name=="" || username=="" || email=="" || pass1=="" || pass2=="" )
		{
		error=1;
		html='<div class="error_text">Required Field Marked With an asterisk(*)</div>';
		}
	else
		{
		html='<div class="error_text">';
		if(!email_check(email))
			{
			error=1;
			html= html+'Invalid Email Address.';
			}
		if(pass1!=pass2)
			{
			error=1;
			html = html + '<br/>Retype password missmatch.';
			}
		html= html + '</div>';	
		
		}
	
	if(error==1)obj_err.innerHTML=html;	
	else
		{
		post_param = 'name='+name+'&username='+username+'&email='+email+'&userpass='+pass1;
		makePOSTRequest('create_user.php',post_param,'hmw_ltext1_user');
		}	
		
	loading_disable();
	}

		
