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;
}

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;
}

/* 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 stateChanged(lang, id){
	if(lang == 'ro')
	{
		var waitingTxt = 'Va rugam asteptati..<br />Se verifica daca numele de utilizator este disponibil.';
		var responseCheck = 'Nume de utilizator liber.';
	}
	else if(lang == 'en')
	{ 
		var waitingTxt = 'Please wait..<br />System is checking if the username is available.';
		var responseCheck = 'Username available.';
	}
	else if(lang == 'it')
	{ 
		var waitingTxt = 'Attendere prego .. <br /> sistema e controllare se il nome utente e disponibile.';
		var responseCheck = 'Nome utente disponibile.';
	}
	
	
	if (xmlHttp[id].readyState<4){
		
		document.getElementById("user").innerHTML='<img src="images/ajax-loader.gif"> '+waitingTxt;
	}
	if (xmlHttp[id].readyState==4) { 
		var responseText = StripTags(xmlHttp[id].responseText);
		responseText = responseText.replace('&nbsp;','');
		
		document.getElementById("user").innerHTML=xmlHttp[id].responseText;
		
		if(StripTags(responseText) == responseCheck)
		{ getElementByClass('hideClass','table-row'); }
		else
		{ getElementByClass('hideClass','none'); }
	}
}

function checkUser(lang, user){

	xmlHttp[1]=GetXmlHttpObject(); 
	
	url="include/check_user.php";
	url=url+"?lang="+lang+"&user="+user;
	
	xmlHttp[1].onreadystatechange=function () { stateChanged(lang, 1); };
	xmlHttp[1].open("GET",url,true);
	xmlHttp[1].send(null);	
}

function check_form(form){
	
	var x= form;
	
	if(x.nume.value.length < 3) {
		alert("Completati numele si prenumele!");
		x.nume.focus();
		return false;
	}
	
	if(x.user.value.length < 3) {
		alert("Completati user!");
		x.user.focus();
		return false;
	}
	
	if(x.pass.value.length < 3) {
		alert("Completati parola!");
		x.pass.focus();
		return false;
	}
	
	if(x.telefon.value.length < 10) {
		alert("Completati telefonul!");
		x.telefon.focus();
		return false;
	}
	
	if(x.descriere_ro.value.length < 3) {
		alert("Completati descriere!");
		x.descriere_ro.focus();
		return false;
	}

	if(x.email.value.length < 3) {
		alert("Completati email!");
		x.email.focus();
		return false;
	}
	
	if(x.inaltime.value.length < 3) {
		alert("Completati inaltimea!");
		x.inaltime.focus();
		return false;
	}
	
	if(x.dimensiuni.value.length < 3) {
		alert("Completati dimensiuni!");
		x.dimensiuni.focus();
		return false;
	}
	
	if(x.ochi.value.length < 3) {
		alert("Completati culoarea ochilor!");
		x.ochi.focus();
		return false;
	}
	
	if(x.varsta.value.length < 1) {
		alert("Completati varsta!");
		x.varsta.focus();
		return false;
	}
	
	if(x.zodie_ro.value.length < 3) {
		alert("Completati zodia!");
		x.zodie_ro.focus();
		return false;
	}
	
	if(x.pret_ro.value.length < 3) {
		alert("Completati pretul!");
		x.pret_ro.focus();
		return false;
	}
	
	
	
	
	return true;
}


