// JavaScript Document

//================================================================================

function GetPortofoliu(id, lang) {
	if (xmlHttp.readyState == 4 || xmlHttp.readyState == 0)	{
		SetWaitState();
		language = lang;
		var getul = "id=" + id;
		xmlHttp.open("GET", URL_BASE + "AJAX/get_porto.php?"+getul, true);
		xmlHttp.onreadystatechange = hSRPorto;
		xmlHttp.send(null);
	} else
		setTimeout('GetPortofoliu(' + id + ')', 1000);
}

//================================================================================

function hSRPorto() {
	if (xmlHttp.readyState == 4) {
		SetIdleState();
		if (xmlHttp.status == 200) {
			xmlResponse = xmlHttp.responseXML;
			document.getElementById("divMessage").innerHTML = '<i>' + unescape(xmlResponse.getElementsByTagName("response")[0].childNodes[0].nodeValue) + '</i>';
			if_error = xmlResponse.getElementsByTagName("error");
			if(if_error[0].childNodes[0].nodeValue == "0") {
				divul = document.getElementById("ShowPorto");
				divul.innerHTML = "";
				var divt = document.createElement("div");
				divt.style.backgroundColor = "#003366";
				divt.style.color = "#ffffff";
				divt.style.width = "310px";
				divt.style.padding = "5px";
				divt.style.textAlign = "center";
				divt.innerHTML = "<strong>" + unescape(xmlResponse.getElementsByTagName("nume")[0].childNodes[0].nodeValue) + "</strong>";
				divul.appendChild(divt);
				var divp = document.createElement("div");
				divp.style.border = "#003366 solid 1px";
				divp.style.width = "308px";
				divp.style.padding = "5px";
				divp.style.background = "url(" + URL_BASE + "images/BSEWait.gif)";
				divp.style.backgroundPosition = "50% 5%";
				divp.style.backgroundRepeat = "no-repeat";
				divp.align = "center";
				var imgp = document.createElement("img");
				imgp.src = URL_BASE + "imgdb/" + unescape(xmlResponse.getElementsByTagName("icon")[0].childNodes[0].nodeValue);
				imgp.border = 0;
				divp.appendChild(imgp);
				divp.appendChild(document.createElement("p"));
				var bqp = document.createElement("blockquote");
				bqp.background = "#003399";
				bqp.color = "#ffffff";
				colab = unescape(xmlResponse.getElementsByTagName("colaborator")[0].childNodes[0].nodeValue);
				if(colab == '&nbsp;')
					colab = "none";
				tinta = eval(unescape(xmlResponse.getElementsByTagName("tip")[0].childNodes[0].nodeValue));
				switch(tinta) {
					case 1: ttinta = "Web";
					break;
					case 2: ttinta = "Win32";
					break;
				}
				if(language == 1) {
					bqp.innerHTML = "<p align='left'>Project: <strong>" + unescape(xmlResponse.getElementsByTagName("proiect")[0].childNodes[0].nodeValue) + "</strong></p>";
					bqp.innerHTML += "<p align='left'>Target: " + ttinta + "</p>";
					bqp.innerHTML += "<p align='left'>Collaborators: " + colab + "</p>";
					if(eval(xmlResponse.getElementsByTagName("online")[0].childNodes[0].nodeValue) > 0) {
						bqp.innerHTML += "<p align='left'>Link: <a href='http://" + unescape(xmlResponse.getElementsByTagName("website")[0].childNodes[0].nodeValue) + "' target='_blank'>" + unescape(xmlResponse.getElementsByTagName("website")[0].childNodes[0].nodeValue)+"</a></p>";
					}
				} else {
					bqp.innerHTML = "<p align='left'>Proiect: <strong>" + unescape(xmlResponse.getElementsByTagName("proiect")[0].childNodes[0].nodeValue) + "</strong></p>";
					bqp.innerHTML += "<p align='left'>Platforma: " + ttinta + "</p>";
					bqp.innerHTML += "<p align='left'>Colaboratori: " + colab + "</p>";
					if(eval(xmlResponse.getElementsByTagName("online")[0].childNodes[0].nodeValue) > 0) {
						bqp.innerHTML += "<p align='left'>Link: <a href='http://" + unescape(xmlResponse.getElementsByTagName("website")[0].childNodes[0].nodeValue) + "' target='_blank'>" + unescape(xmlResponse.getElementsByTagName("website")[0].childNodes[0].nodeValue)+"</a></p>";
					}
				}				
				divp.appendChild(bqp);				
				
				divul.appendChild(divp);				
				
			}
			
		} else {
			alert("There was a problem accessing the server: " + xmlHttp.statusText);
		}
	} else {
		if(xmlHttp.readyState > 0 && xmlHttp.readyState < 4) {
			SetWaitState();	
		}	
	}
}
