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

  Copyright (C) 2008  Pangya-FR (hika@bsdmon.com)

  This file is part of PunBB :: Pangya-FR.

  PunBB :: Pangya-FR is free software; you can redistribute it and/or modify it
  under the terms of the GNU General Public License as published
  by the Free Software Foundation; either version 2 of the License,
  or (at your option) any later version.

  PunBB :: Pangya-FR is distributed in the hope that it will be useful, but
  WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  GNU General Public License for more details.

  You should have received a copy of the GNU General Public License
  along with this program; if not, write to the Free Software
  Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  MA  02111-1307  USA

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

	function generateUserBar(user_id) {
		createXhr();
		if (xhr) {
			xhr.onreadystatechange = function() { 
				if (xhr.readyState == 4) {
					if (xhr.status == 200) {
						var o = document.getElementById('userbar');
						if (o) {
							o.src = xhr.responseText;
						}
					}
				}
			};

			xhr.open("GET", "pangya_plugin/gen_userbar.ajax.php&id=" + escape(user_id));
			xhr.send(null);
		}
	}

	function refreshCR() {
		var o;
		var cr = 0;

		o = document.getElementById('pink_wind_score');
		if (o && o.value != '' && !isNaN(o.value)) cr += parseInt(o.value);
		o = document.getElementById('blue_lagoon_score');
		if (o && o.value != '' && !isNaN(o.value)) cr += parseInt(o.value);
		o = document.getElementById('north_wiz_score');
		if (o && o.value != '' && !isNaN(o.value)) cr += parseInt(o.value);
		o = document.getElementById('west_wiz_score');
		if (o && o.value != '' && !isNaN(o.value)) cr += parseInt(o.value);
		o = document.getElementById('shining_sand_score');
		if (o && o.value != '' && !isNaN(o.value)) cr += parseInt(o.value);
		o = document.getElementById('blue_water_score');
		if (o && o.value != '' && !isNaN(o.value)) cr += parseInt(o.value);
		o = document.getElementById('blue_moon_score');
		if (o && o.value != '' && !isNaN(o.value)) cr += parseInt(o.value);
		o = document.getElementById('ice_cannon_score');
		if (o && o.value != '' && !isNaN(o.value)) cr += parseInt(o.value);
		o = document.getElementById('sepia_wind_score');
		if (o && o.value != '' && !isNaN(o.value)) cr += parseInt(o.value);
		o = document.getElementById('wiz_wiz_score');
		if (o && o.value != '' && !isNaN(o.value)) cr += parseInt(o.value);
		o = document.getElementById('silvia_cannon_score');
		if (o && o.value != '' && !isNaN(o.value)) cr += parseInt(o.value);
		o = document.getElementById('wind_hill_score');
		if (o && o.value != '' && !isNaN(o.value)) cr += parseInt(o.value);
		o = document.getElementById('deep_inferno_score');
		if (o && o.value != '' && !isNaN(o.value)) cr += parseInt(o.value);
		o = document.getElementById('ice_spa_score');
		if (o && o.value != '' && !isNaN(o.value)) cr += parseInt(o.value);
		o = document.getElementById('lost_seaway_score');
		if (o && o.value != '' && !isNaN(o.value)) cr += parseInt(o.value);

		o = document.getElementById('total_cr');
		if (o) o.value = cr;
	}

	function putScore(o, tag, score, platform_id, user_id) {
		createXhr();
		if (xhr) {
			xhr.onreadystatechange = function() { 
				if (xhr.readyState == 4) {
					if (xhr.status == 200) {
						o.value = xhr.responseText;
						refreshCR();
						// alert(xhr.responseText);
					}
				}
			};

			var data = "tag=" + escape(tag) + "&score=" + escape(score) + "&platform_id=" + escape(platform_id) + "&id=" + escape(user_id);
			xhr.open("POST", "pangya_plugin/editcr.ajax.php");
			xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
			xhr.send(data);
		}
	}

	function putPangs(o, tag, pang, platform_id, user_id) {
		createXhr();
		if (xhr) {
			xhr.onreadystatechange = function() { 
				if (xhr.readyState == 4) {
					if (xhr.status == 200) {
						o.value = xhr.responseText;
					}
				}
			};

			var data = "tag=" + escape(tag) + "&pang=" + escape(pang) + "&platform_id=" + escape(platform_id) + "&id=" + escape(user_id);;
			xhr.open("POST", "pangya_plugin/editcr.ajax.php");
			xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
			xhr.send(data);
		}
	}
	
	function putUserValue(o, col, value, platform_id, user_id) {
		createXhr();
		if (xhr) {
			xhr.onreadystatechange = function() { 
				if (xhr.readyState == 4) {
					if (xhr.status == 200) {
						if (col != 'lvl') // Except Pangya level
							o.value = xhr.responseText;
						//alert(xhr.responseText);
					}
				}
			};

			var data = "col=" + escape(col) + "&value=" + escape(value) + "&platform_id=" + escape(platform_id) + "&id=" + escape(user_id);;
			xhr.open("POST", "pangya_plugin/editfield.ajax.php");
			xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
			xhr.send(data);
		}
	}

	function reloadIGN() {
		var o1 = document.getElementById('ign_preview');
		var o2 = document.getElementById('ign');
		if (o1 && o2) {
			createXhr();
			if (xhr) {
				xhr.onreadystatechange = function() { 
					if (xhr.readyState == 4) {
						if (xhr.status == 200) {
							o1.innerHTML = xhr.responseText;
						}
					}
				};

				var data = "ign=" + escape(o2.value);

				xhr.open("GET", "pangya_plugin/gethtml_ign.ajax.php?" + data);
				xhr.send(null);
			}
		}
	}

	function reloadGuildImage(platform_id) {
		var o1 = document.getElementById('guild_preview');
		var o2 = document.getElementById('guild_id');
		if (o1 && o2) {
			createXhr();
			if (xhr) {
				xhr.onreadystatechange = function() { 
					if (xhr.readyState == 4) {
						if (xhr.status == 200) {
							o1.innerHTML = xhr.responseText;
						}
					}
				};

				var data = "guild_id=" + escape(o2.value) + "&platform_id=" + escape(platform_id);

				xhr.open("GET", "pangya_plugin/geturl_guildimg.ajax.php?" + data);
				xhr.send(null);
			}
		}
	}

