var xmlHttp = new Array();
var url

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;
}

/* getElementByClass
/**********************/

var allHTMLTags = new Array();

function getElementByClass(theClass, displayType) {

//Create Array of All HTML Tags
var allHTMLTags=document.getElementsByTagName("*");

//Loop through all tags using a for loop
for (i=0; i<allHTMLTags.length; i++) {

//Get all tags with the specified class name.
if (allHTMLTags[i].className==theClass) {

//Place any code you want to apply to all
//pages with the class specified.
//In this example is to “display:none;” them
//Making them all dissapear on the page.

allHTMLTags[i].style.display=displayType;

}
}
}

function StripTags(strMod){
    if(arguments.length<3) strMod=strMod.replace(/<\/?(?!\!)[^>]*>/gi, '');
    else{
        var IsAllowed=arguments[1];
        var Specified=eval("["+arguments[2]+"]");
        if(IsAllowed){
            var strRegExp='</?(?!(' + Specified.join('|') + '))\b[^>]*>';
            strMod=strMod.replace(new RegExp(strRegExp, 'gi'), '');
        }else{
            var strRegExp='</?(' + Specified.join('|') + ')\b[^>]*>';
            strMod=strMod.replace(new RegExp(strRegExp, 'gi'), '');
        }
    }
    return strMod;
}


function stateChanged(id){
	if (xmlHttp[id].readyState<4){
		document.getElementById("user").innerHTML='<img src="images/ajax-loader.gif"> Va rugam asteptati..<br />Se verifica daca numele de utilizator este disponibil.';
	}
	if (xmlHttp[id].readyState==4) { 
		var responseText = StripTags(xmlHttp[id].responseText);
		responseText = responseText.replace('&nbsp;','');
		
		document.getElementById("user").innerHTML=xmlHttp[id].responseText;
		
		var responseCheck = 'Nume de utilizator liber.';
		
		if(StripTags(responseText) == responseCheck)
		{ getElementByClass('hideClass','table-row'); }
		else
		{ getElementByClass('hideClass','none'); }
	}
}

function checkUser(user){

	xmlHttp[1]=GetXmlHttpObject(); 
	
	url="include/check_user.php";
	url=url+"?user="+user;
	
	xmlHttp[1].onreadystatechange=function () { stateChanged('1'); };
	xmlHttp[1].open("GET",url,true);
	xmlHttp[1].send(null);	
}
