/***************************************************************************
 Jupiter Portal @ Jupiterportal.com
 Copyright (C) 2006 Cosmin Flavius (highstrike@gmail.com)

 Attribution-NonCommercial-ShareAlike 2.5 of Creative Commons
 (http://creativecommons.org)

 You are free:

    * to copy, distribute, display, and perform the work
    * to make derivative works

 Under the following conditions:

 Attribution - You must attribute the work in the manner specified
 by the author or licensor.

 Noncommercial - You may not use this work for commercial purposes.

 Share Alike - If you alter, transform, or build upon this work, you may
 distribute the resulting work only under a license identical to this one.

    * For any reuse or distribution, you must make
	  clear to others the license terms of this work.
    * Any of these conditions can be waived if you get
      permission from the copyright holder.

 Your fair use and other rights are in no way affected by the above.

 This is a human-readable summary of the Legal Code (the full license).
 (http://creativecommons.org/licenses/by-nc-sa/2.5/legalcode)

****************************************************************************/

//-----------------------------------------------------------------
//  Take care of vars
//-----------------------------------------------------------------

var xmlhttp;

/*@cc_on @*/
/*@if (@_jscript_version >= 5)
	try { xmlhttp=new ActiveXObject("Msxml2.XMLHTTP") }
	catch (e)
	{
		try { xmlhttp=new ActiveXObject("Microsoft.XMLHTTP") }
		catch (E) { xmlhttp=false }
	}
@else xmlhttp=false
@end @*/

if (!xmlhttp && typeof XMLHttpRequest!='undefined')
{
	try { xmlhttp = new XMLHttpRequest(); }
	catch (e) { xmlhttp=false }
}

////////////////////////////////////////////////////////
// Function:         myXMLHttpRequest
// Description: Function to request HTTP

function myXMLHttpRequest()
{
	var xmlhttplocal;

	try { xmlhttplocal= new ActiveXObject("Msxml2.XMLHTTP") }
	catch (e)
	{
		try { xmlhttplocal= new ActiveXObject("Microsoft.XMLHTTP") }
		catch (E) { xmlhttplocal=false; }
	}

	if (!xmlhttplocal && typeof XMLHttpRequest!='undefined')
	{
		try { var xmlhttplocal = new XMLHttpRequest(); }
		catch (e) { var xmlhttplocal=false; alert('couldn\'t create xmlhttp object'); }
	}

return(xmlhttplocal);
}

////////////////////////////////////////////////////////
// Function:         sndReq
// Description: Function to send request

function sndReq(option_1, option_2, option_3, option_4)
{
	if (option_1 == 'rating' && option_3 >= 1 && option_3 <= 5) { var url = 'includes/ajax.php?&d='+option_2+'&x='+option_3+'&y='+option_4+'&z='+option_1; }
	if (option_1 == 'register') { var url = 'includes/ajax.php?&d='+option_2+'&x='+option_3+'&y='+option_4+'&z='+option_1; }
	if (option_1 == 'profile') { var url = 'includes/ajax.php?&d='+option_2+'&x='+option_3+'&y='+option_4+'&z='+option_1; }

	xmlhttp.open('put', url);

	xmlhttp.onreadystatechange = handleResponse;
	xmlhttp.send(null);
}

////////////////////////////////////////////////////////
// Function:         handleResponse
// Description: Function to handle the response

function handleResponse()
{
	if(xmlhttp.readyState == 4)
	{
		if (xmlhttp.status == 200)
		{
			var response = xmlhttp.responseText;
			var update = new Array();

			if(response.indexOf('|_+_|') != -1)
			{
				update = response.split('|_+_|');
				changeText(update[0], update[1]);
			}
		}
	}
}

////////////////////////////////////////////////////////
// Function:         changeText
// Description: Function to perform the changes

function changeText(div2show, text)
{
	var IE = (document.all) ? 1 : 0;
	var DOM = 0;

	if (parseInt(navigator.appVersion) >=5) DOM = 1;
	if (DOM)
	{
		var viewer = document.getElementById(div2show)
		viewer.innerHTML=text
	}
	else if(IE) document.all[div2show].innerHTML=text
}

////////////////////////////////////////////////////////
// Function:         changeFlag
// Description: Used on the profile and on the register

function changeFlag(id)
{
	var flag = id.value;

	document.getElementById('regflag').style.background = '#FFF url(images/flags/'+flag+'.png) no-repeat';
	document.getElementById('regflag').style.backgroundPosition = 'bottom left';
}