// JavaScript Document
var xmlhttp = null; //xmlhttp obj for add gallery thumnail

function ajax_validate(type,str)
{
if (xmlhttp==null)
  {
  xmlhttp=GetXmlHttpObject();
  if(xmlhttp==null){
  alert ("Browser does not support HTTP Request");
  return false;
  }
  }
  
var url="user/check_database.php";
var params ="";
if(type == "user_name"){
	params = "checkdata=" + str + "&checktype=user_name";
	
}else if(type == "user_email"){
	params = "checkdata="+str+"&checktype=user_email";
	
}

//xmlhttp.onreadystatechange=stateChanged;
//Funny Open("POST",url,true) bug...could not understand.
xmlhttp.open("POST", url, false);

//Send the proper header information along with the request
xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
xmlhttp.setRequestHeader("Content-length", params.length);
xmlhttp.setRequestHeader("Connection", "close");
xmlhttp.send(params);
//need put into a function wrapper.
if(type == "user_name"){
	document.getElementById("div_check_user_name").innerHTML=xmlhttp.responseText;
}else if(type == "user_email"){
	document.getElementById("div_check_user_email").innerHTML=xmlhttp.responseText;
}
}

function GetXmlHttpObject()
{ 
var xmlHttp=null; 
try 
{ 
// Firefox, Opera 8.0+, Safari 
xmlHttp=new XMLHttpRequest(); 
} 
catch (e) 
{ 
// Internet Explorer 
try 
{ 
xmlHttp=new ActiveXObject("Msxml2.XMLHTTP"); 
} 
catch (e) 
{ 
xmlHttp=new ActiveXObject("Microsoft.XMLHTTP"); 
} 
} 
return xmlHttp; 
} 

function ajax_post(url,arr_obj,f){
//need the following URL, associative array passed as object, function call

if (xmlhttp==null){
 	xmlhttp=GetXmlHttpObject();
	if(xmlhttp==null){
		alert ("Browser does not support HTTP Request");
		return false;
	}
}
//var url="delete_comment.php";
var params="type=ajax";
for(var i in arr_obj){
params = [params,"&",i ,"=", arr_obj[i]].join('');
}

xmlhttp.open("POST", url, false);
//Send the proper header information along with the request
xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
xmlhttp.setRequestHeader("Content-length", params.length);
xmlhttp.setRequestHeader("Connection", "close");
xmlhttp.send(params);
eval(f+"(xmlhttp.responseText)");
}