function datosServidor() {
};
datosServidor.prototype.iniciar = function() {
	try {
		// Mozilla / Safari
		this._xh = new XMLHttpRequest();
	} catch (e) {
		// Explorer
		var _ieModelos = new Array(
		'MSXML2.XMLHTTP.5.0',
		'MSXML2.XMLHTTP.4.0',
		'MSXML2.XMLHTTP.3.0',
		'MSXML2.XMLHTTP',
		'Microsoft.XMLHTTP'
		);
		var success = false;
		for (var i=0;i < _ieModelos.length && !success; i++) {
			try {
				this._xh = new ActiveXObject(_ieModelos[i]);
				success = true;
			} catch (e) {
				// Implementar manejo de excepciones
			}
		}
		if ( !success ) {
			// Implementar manejo de excepciones, mientras alerta.
			return false;
		}
		return true;
	}
}

datosServidor.prototype.ocupado = function() {
	estadoActual = this._xh.readyState;
	return (estadoActual && (estadoActual < 4));
}

datosServidor.prototype.procesa = function() {
	if (this._xh.readyState == 4 && this._xh.status == 200) {
		this.procesado = true;
	}
}

datosServidor.prototype.enviar = function(urlget,datos) {
	if (!this._xh) {
		this.iniciar();
	}
	if (!this.ocupado()) {
		this._xh.open("GET","/"+urlget+"&unique="+datos,false);
		this._xh.send(null);
		if (this._xh.readyState == 4 && this._xh.status == 200) {
			return this._xh.responseText;
		}
		
	}
	return false;
}


function addView(newsID) {
		remotos = new datosServidor;
		nt = remotos.enviar('update.php?view=1&newsID='+newsID,unique_code);
}
function requestGroup(groupID,userID) {
		remotos = new datosServidor;
		nt = remotos.enviar('update.php?groupID='+groupID+'&userID='+userID,unique_code);
		getObject('grouprequest').innerHTML = nt; 
}

function joinEvent(eventID,userID) {
		remotos = new datosServidor;
		nt = remotos.enviar('update.php?m=add&eventID='+eventID+'&userID='+userID,unique_code);
		getObject('eventrequest').innerHTML = nt; 
}
function rateNews(rating,newsID)  {
		remotos = new datosServidor;
		nt = remotos.enviar('update.php?rating='+rating+'&newsID='+newsID,unique_code);
		rating = (rating * 25) - 8;
		getObject('current-rating').style.width = rating+'px';
		getObject('ratelinks').style.display = 'none';
		getObject('ratingtext').innerHTML = nt;
}


function rateUser(rating,userID,unique)  {
		remotos = new datosServidor;
		nt = remotos.enviar('update.php?rating='+rating+'&userID='+userID,unique_code);
		element = "rateuser"+unique;
		document.getElementById(element).innerHTML = nt;
}

function becomeGameManager(asin,userID)  {
		remotos = new datosServidor;
		nt = remotos.enviar('update.php?asin='+asin+'&l=game&userID='+userID,unique_code);
		if(nt)
			getObject('gameman').innerHTML = nt;
}

function becomeHardwareManager(asin,userID)  {
		remotos = new datosServidor;
		nt = remotos.enviar('update.php?asin='+asin+'&l=hardware&userID='+userID,unique_code);
		if(nt)
			getObject('hardwareman').innerHTML = nt;
}
function favGame(gameID,userID){
		remotos = new datosServidor;
		nt = remotos.enviar('update.php?m=add&gameID='+gameID+'&userID='+userID,unique_code);
		if(nt)
			getObject('gamefav').innerHTML = nt;
	
}
function favHardware(hardwareID,userID){
		remotos = new datosServidor;
		nt = remotos.enviar('update.php?m=add&hardwareID='+hardwareID+'&userID='+userID,unique_code);
		if(nt)
			getObject('hardwarefav').innerHTML = nt;
	
}
function addGroupUser(userID,groupID)  {
		remotos = new datosServidor;
		nt = remotos.enviar('update.php?m=add&groupID='+groupID+'&userID='+userID,unique_code);
		if(nt)
			alert(nt);
}

function removeGroupUser(userID,groupID)  {
		remotos = new datosServidor;
		nt = remotos.enviar('update.php?m=remove&groupID='+groupID+'&userID='+userID,unique_code);
		if(nt)
			alert(nt);
}

function deleteMedia(userID,mediaID)  {

		if (confirm ("Are you sure you want to delete this media?")) {
			remotos = new datosServidor;
			nt = remotos.enviar('update.php?m=remove&mediaID='+mediaID+'&userID='+userID,unique_code);
			if(nt)
				alert(nt);
		}else{
			alert ("Media not deleted.") 
		}
}

function deleteNews(userID,newsID)  {

		if (confirm ("Are you sure you want to delete this post?")) {
			remotos = new datosServidor;
			nt = remotos.enviar('update.php?m=remove&newsID='+newsID+'&userID='+userID,unique_code);
			if(nt){
				alert(nt);
				window.location='http://www.gaminglife.nl/news/';
			}
		}else{
			alert ("Post not deleted.") 
		}
}

function deleteComment(userID,commentID)  {

		if (confirm ("Are you sure you want to delete this comment?")) {
			remotos = new datosServidor;
			nt = remotos.enviar('update.php?m=remove&commentID='+commentID+'&userID='+userID,unique_code);
			if(nt){
				alert(nt);
			}
		}else{
			alert ("Comment not deleted.") 
		}
}


function editComment(userID,commentID)  {
			window.location = "http://www.gaminglife.nl/home/editcomment/?commentID="+commentID;
}

function addviews(mediaName)  {
		remotos = new datosServidor;
		nt = remotos.enviar('update.php?m=count&mediaName='+mediaName,unique_code);
}

function clickTab(content,divresult,tabimageid){
		url = "xml/tabs.php?tab="+content;
		if(tabimageid == "tab1"){
			getObject("tab1").src = "/img/tabs/tab1on.gif";			
		}else{
			getObject("tab1").src = "/img/tabs/tab1out.gif";			
		}
		if(tabimageid == "tab2"){
			getObject("tab2").src = "/img/tabs/tab2on.gif";			
		}else{
			getObject("tab2").src = "/img/tabs/tab2out.gif";			
		}
		if(tabimageid == "tab3"){
			getObject("tab3").src = "/img/tabs/tab3on.gif";			
		}else{
			getObject("tab3").src = "/img/tabs/tab3out.gif";			
		}
		remotos = new datosServidor;
		nt = remotos.enviar(url);
		divresultparse = document.getElementById(divresult)
		if(divresultparse){
			divresultparse.innerHTML = nt;	
		}
		
		if(tabtimer)
			clearTimeout(tabtimer);
}



function MouseOverTab(image)
{
		tabcurrentimg =image.src;
		tabimageid = image.id;
		if(tabcurrentimg != "http://www.gaminglife.nl/img/tabs/"+tabimageid+"on.gif"){
		 	document.tabcurrentimg = "http://www.gaminglife.nlimg/tabs/"+tabimageid+"over.gif";
		}
}

function MouseOutTab(image)
{
		tabcurrentimg =image.src;
		tabimageid = image.id;
		if(tabcurrentimg!="http://www.gaminglife.nl/img/tabs/"+tabimageid+"on.gif"){
		 	document.tabcurrentimg = "http://www.gaminglife.nlimg/tabs/"+tabimageid+"out.gif";
		}
}

function show(id){
	var showlayer = document.getElementById(id);

	if(showlayer.style.display == "block"){
		showlayer.style.display  = "none";
	} else{
		showlayer.style.display  = "block";
	}
}


function applyPro(){
	window.open('/applypro.php','applypro','width=200; height=200;');	
	
}


var zautopost;
var name;
var zform;

function searchQuick(form,wvalue,autopost,evt) {
	zautopost = autopost;
	searchfield = wvalue;
	keyword = wvalue.value;
	field = wvalue;
	zform = form;
	name = wvalue.id;// id van het zoekveld wordt de nieuwe naam
		
	if(!getObject(field)){

		var fillListing = document.createElement("select");
		fillListing.setAttribute('id',field);
		fillListing.setAttribute('name',name); //voor nu
		fillListing.setAttribute('size','3'); //voor nu
		fillListing.style.width = wvalue.style.width;
		fillListing.style.position = 'absolute';
		getObject('fillList').appendChild(fillListing); //fillist moet wel bestaan
		if(autopost){
			//fillListing.onchange = function () { form.submit(); return false;};
			fillListing.onclick = function () { form.submit(); return false;};
		}else{
			fillListing.onclick = function () { wvalue.value = this.options[this.selectedIndex].text; return false;};
			//fillListing.onchange = function () { wvalue.value = this.options[this.selectedIndex].text; return false;};
		}
		fillListing.onkeydown = function () { changeFocus(event); };

	}	
	if(keyword.length > 1){
		url = "xml/autofill.php?q="+keyword+"&w="+name;
		remotos = new datosServidor;
		nt = remotos.enviar(url);
        if(nt.length < 3)
              HideDiv(field);
        else
        {
			getObject(field).innerHTML = ""; //empty
			results = nt.split('|');
   			if (results.length > 2) {
	   			for(i=0;i < (results.length-1);i=i+2) {
	  				createBox(results[i],results[i+1]); 
	 			}
    		}
			ShowDiv(field);
				
			evt = (evt) ? evt : window.event;
			if(evt.keyCode == 40 || evt.keyCode == 38){ //this checks for up and down: if so focus, else.
					getObject(field).focus(); 
			}
			
			setTimeout("HideDiv(field);",60000);
          }

	
	}else{
		HideDiv(field);		
	}
}

function changeFocus(evt){
			evt = (evt) ? evt : window.event;
			if(evt.keyCode == 40 || evt.keyCode == 38){ //this checks for up, down.
				return false;
			}else if(evt.keyCode == 13){
				zform.submit();
			}else{
				getObject(name).focus();	
			}
}

function createBox(name,id){
		var optionList = document.createElement("option");
		optionList.value = id;
		optionList.text = name;
		try {
			getObject(field).add(optionList, null); // standards compliant; doesn't work in IE
		}
		catch(ex) {
			getObject(field).add(optionList); // IE only
		}
		if(keyword.toLowerCase == name.toLowerCase && zautopost)
			optionList.selected = true;
}


function getObject(name) {
   var ns4 = (document.layers) ? true : false;
   var w3c = (document.getElementById) ? true : false;
   var ie4 = (document.all) ? true : false;

   if (ns4) return eval('document.' + name);
   if (w3c) return document.getElementById(name);
   if (ie4) return eval('document.all.' + name);
   return false;
}

function ShowDiv(divid)
{
      getObject(divid).style.display="block";
}

function HideDiv(divid)
{
      getObject(divid).style.display="none";
}
