function wsShowProduct(a_id)
{
	var myAjax = new Ajax.Request('/?scr=ajax_get_product', {method: 'post', parameters: 'c_id=' + a_id, onComplete: ajaxSetValues}); 
}

function wsShowStore(a_id)
{
	var myAjax = new Ajax.Request('/?scr=ajax_get_store', {method: 'post', parameters: 'c_id=' + a_id, onComplete: ajaxSetStoreValues}); 
}

function ajaxSetValues(a_request)
{
	var v_name, v_value;

	// Pega os dados do objeto AJAX
	var xml_doc = a_request.responseXML;

	if (!xml_doc)
	{
		alert('Produto não encontrado.');
		return;
	}
	var xml_entries	  = xml_doc.getElementsByTagName('entry');
	var v_sale_label  = document.getElementById('pro_xml_sale_label');
	var v_price_label = document.getElementById('pro_xml_price_label');
	var v_strike	  = false;

	v_sale_label.innerHTML = '&nbsp;';
	v_price_label.innerHTML = '<div>preço</div>';

	for (var i = 0, j = xml_entries.length; i < j; i++)
	{
		v_name	= xml_entries[i].getElementsByTagName('name')[0].firstChild.nodeValue;
		v_value = xml_entries[i].getElementsByTagName('value')[0];
		v_html	= document.getElementById('pro_xml_' + v_name);

		if (v_value.hasChildNodes())
		{
			switch (v_name)
			{
			case 'c_sale':

				if (v_value.firstChild.nodeValue != '')
				{
					v_sale_label.innerHTML = 'por';
					v_price_label.innerHTML = '<div>de</div>';
					v_strike = true;
					v_html.innerHTML = v_value.firstChild.nodeValue;
				}
				break;
			case 'colors':
				var xml_colors = xml_doc.getElementsByTagName('color');
				var v_colors   = '';

				for (var k = 0, l = xml_colors.length; k < l; k++)
				{
					v_color = xml_colors[k].getElementsByTagName('title')[0];
					v_image = xml_colors[k].getElementsByTagName('image')[0];

					if (v_color.hasChildNodes() && v_image.hasChildNodes())
					{
						v_colors += '<div><img src="' + v_image.firstChild.nodeValue + '" alt="' + v_color.firstChild.nodeValue + '" height="8" width="60" /></div>';
					}
				}
				if (v_colors != '')
				{
					v_html.innerHTML = v_colors;
				}
				else
				{
					v_html.innerHTML = '&nbsp;';
				}
				break;
			case 'c_price':
				if (v_strike == true)
				{
					v_html.innerHTML = '<div class="pro_strike">' + v_value.firstChild.nodeValue + '</div>';
				}
				else
				{
					v_html.innerHTML = '<div>' + v_value.firstChild.nodeValue + '</div>';
				}
				break;
			case 'c_image':
				document.getElementById('pro_details').style.backgroundImage = 'url(' + v_value.firstChild.nodeValue + ')';
				break;
			case 'c_suggestion':
				document.getElementById('pro_xml_suggestion').href = v_value.firstChild.nodeValue;
				break;
			default:
				v_html.innerHTML = v_value.firstChild.nodeValue;
			}
		}
		else
		{
			v_html.innerHTML = '&nbsp;';
		}
	}
}

function ajaxSetStoreValues(a_request)
{
	var v_name, v_value;

	// Pega os dados do objeto AJAX
	var xml_doc = a_request.responseXML;

	if (!xml_doc)
	{
		alert('Loja não encontrada.');
		return;
	}
	var xml_entries = xml_doc.getElementsByTagName('entry');

	for (var i = 0, j = xml_entries.length; i < j; i++)
	{
		v_name	= xml_entries[i].getElementsByTagName('name')[0].firstChild.nodeValue;
		v_value = xml_entries[i].getElementsByTagName('value')[0];
		v_html	= document.getElementById('add_xml_' + v_name);

		if (v_value.hasChildNodes())
		{
			switch (v_name)
			{
			case 'c_name':
				v_html.innerHTML = v_value.firstChild.nodeValue.toUpperCase();
				break;
			case 'map':
				v_html.href = '/enderecos/mapas/' + v_value.firstChild.nodeValue;
				break;
			case 'c_image':
				v_html.src = v_value.firstChild.nodeValue;
				break;
			default:
				v_html.innerHTML = v_value.firstChild.nodeValue;
			}
		}
		else
		{
			v_html.innerHTML = '&nbsp;';
		}
	}
}

function wsValidateCpf(a_cpf)
{
	if (!/^[\d]{11}$/.test(a_cpf))
	{
		return false;
	}
	if (/^0{11}|1{11}|2{11}|3{11}|4{11}|5{11}|6{11}|7{11}|8{11}|9{11}$/.test(a_cpf))
	{
		return false;
	}
	var v_sequence	  = new Array();
	var v_rest, v_sum = new Number;
	var v_multiplier  = 11;

	for (var i = 0; i < 11; i++)
	{
		v_sequence[i] = a_cpf.charAt(i);

		if (i < 9)
		{
			v_sum += (v_sequence[i] * --v_multiplier);
		}
	}
	if ((v_rest = v_sum % 11) < 2)
	{
		v_sequence[9] = 0;
	}
	else
	{
		v_sequence[9] = 11 - v_rest;
	}
	v_sum		 = 0;
	v_multiplier = 11;

	for (var y = 0; y < 10; y++)
	{
		v_sum += (v_sequence[y] * v_multiplier--);
	}
	if ((v_rest = v_sum % 11) < 2)
	{
		v_sequence[10] = 0;
	}
	else
	{
		v_sequence[10] = 11 - v_rest;
	}
	if ((a_cpf.charAt(9) != v_sequence[9]) || (a_cpf.charAt(10) != v_sequence[10]))
	{
		return false;
	}
	return true;
}