/* Initialize
 */
var loaded = false;

function load(xx, yy)
{
	var map = document.getElementById("map_canvas");
	
    if (map && GBrowserIsCompatible())
	{
		loaded = true;
		
 		var y = xx;
		var x = yy;
		var map = new GMap2(map);

		map.addControl(new GSmallMapControl());
		map.addControl(new GMapTypeControl());
		
		GEvent.addListener(map, "click", function() {
  			window.location = 'http://maps.google.com/maps?f=q&hl=PT&geocode=&q=pra%C3%A7a+dos+descobrimentos,+93,+2870-091+Montijo&sll=38.705807,-8.949738&sspn=0.007485,0.014462&ie=UTF8&ll=38.705807,-8.949738&spn=0.007485,0.014462&z=16';
		});
		
		map.setCenter(new GLatLng(y, x), 13);
		
		var marker = new GMarker(new GLatLng(y, x));
		map.addOverlay(marker);
		
		GEvent.addListener(marker, 'click', function() {
			window.location = 'http://maps.google.com/maps?f=q&hl=PT&geocode=&q=pra%C3%A7a+dos+descobrimentos,+93,+2870-091+Montijo&sll=38.705807,-8.949738&sspn=0.007485,0.014462&ie=UTF8&ll=38.705807,-8.949738&spn=0.007485,0.014462&z=16';
		});
	}
	
	if(document.getElementById("selection-ids") && document.getElementById("selection-ids"))
	{
		micoxUpload('translate-form', 'iframe/traducoes_texto.php', 'selection-ids', 'carregando', 'ocorreu um erro');	
	}
	
	if(document.getElementById("translate-form") && document.getElementById("selection"))
	{
		micoxUpload('translate-form', 'iframe/traduzir_produto.php', 'selection', 'carregando', 'ocorreu um erro');
	}
	
	if(document.getElementById("cart-form") && document.getElementById("selection-categories"))
	{
		micoxUpload('cart-form', 'iframe/chart.php', 'selection-categories', 'carregando', 'ocorreu um erro');
	}
	
	if(document.getElementById("cart-form") && document.getElementById("chart"))
	{
		micoxUpload('cart-form', 'iframe/chart.php', 'chart', 'carregando', 'ocorreu um erro');
	}
	
	if(document.getElementById("locale-form") && document.getElementById("selection"))
	{
		micoxUpload('locale-form', 'iframe/add_locales.php', 'selection', 'carregando', 'ocorreu um erro');
	}
	
	if(document.getElementById("adicionar-produto-form") && document.getElementById("uploaded_images"))
	{
		micoxUpload('adicionar-produto-form', 'iframe/upload_image.php', 'uploaded_images', '&lt;img src=&quot;pix/loader_bar.gif&quot; /&gt;', 'erro', null);
	}
} // function



function unload()
{
	if( loaded )
	{
		GUnload();
	}
}

var duvidas_t = 0;
function duvidas(t, p, f)
{
	var te = document.getElementById(t);
	var pe = document.getElementById(p);
	
	if(te.value.length != 0) 
	{ 
		pe.style.display = 'none'; 
	}
	else
	{
		pe.style.display = 'block';
	}
	
	if( f > 0 &&  duvidas_t < 1)
	{
		setTimeout('duvidas("' + t + '", "' + p + '", 0)', 1000);
		duvidas_t = 1;
	}
}

function bigthumb(id)
{
	var elem = document.getElementById(id);
	elem.style.width = '120px';
	elem.style.height = '120px';
	elem.style.display = 'block';
	elem.style.zIndex = '99999999';
	elem.style.position = 'absolute';
	elem.style.overflow = 'visible';
	elem.style.left = '-10px';
	elem.style.top = '0';
	
	window.setTimeout('outbigthumb("' + id + '")', 3000);
}

function outbigthumb(id)
{
	var elem = document.getElementById(id);
	elem.style.width = '0';
	elem.style.height = '0';
	elem.style.display = 'none'; 
	elem.style.overflow = 'hidden';
}

function setbigthumb(id, f)
{
	var elem = document.getElementById(id);
	elem.src = f;
}

function loadEditorContent()
{
	iview.contentWindow.document.body.innerHTML = txt;
}

function sel_price(sel, id)
{
	var elem = document.getElementById(id);
	if(sel.value == 0)
	{
		elem.style.visibility = 'visible';
	}
	else
	{
		elem.style.visibility = 'hidden';
	}
}

function hide(id)
{
	var elem = document.getElementById(id);
	elem.style.display = 'none';
}

function show(id)
{
	var elem = document.getElementById(id);
	elem.style.display = 'block';
}

function show_price()
{
	wg_iframe('show_price', 'iframe/price.php', 'form_product', 
              function(name) 
              {
              	var elem = document.getElementById(name);
              	var oDoc = elem.contentWindow ||
				elem.contentDocument;
				if (oDoc.document)
				{
					oDoc = oDoc.document;
				}
				var val = oDoc.getElementById('price');
				if(!val)
				{
					alert('Couldn\'t find the price.');
					return false;
				}
				var elem = document.getElementById('input_price');
				wg_set_html(elem, val.value);
				return true;
              }, 
              function() {}, null);
}

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

var st = 0;
function translationeditor(textos_id)
{
	var e2 = document.getElementById('xxx-editor');
	var e1 = document.getElementById('xxx-editor2');
	
	var iframe = document.getElementById('xxx-editor_iframe');
	var iframe2 = document.getElementById('xxx-editor2_iframe');
	
	var t1 = document.getElementById('xxxlocale_id');
	var t2 = document.getElementById('xxxsection_id');
	var t3 = document.getElementById('xxxtranslate_id');
	var tb = document.getElementById('t_button');
	if( !t3 )
	{
		st = 2;
		e2.style.display = 'none';
		e1.style.display = 'none';
		tb.style.display = 'none';
	}
	
	if(textos_id == 'paginas' || textos_id == 'faqs')
	{
		st = 2;
		e1.style.display = 'block';
		e2.style.display = 'none';
		tb.style.display = 'block';	
		
		if(t3)
		{
			iframe.src = 'iframe/traducao.php?locale_id=' + t1.value + 
			             '&section_id=' + t2.value + '&translate_id=' + t3.value;
			iframe2.src = 'iframe/editor.php?locale_id=' + t1.value + 
			              '&section_id=' + t2.value + '&translate_id=' + t3.value;
		}
	}
	else if(textos_id == '')
	{
		st = 0;
		e2.style.display = 'none';
		e1.style.display = 'none';
		tb.style.display = 'none';
	}
	else
	{
		st = 1;
		e2.style.display = 'block';
		e1.style.display = 'none';
		tb.style.display = 'block';
		
		if(t3)
		{
			iframe.src = 'iframe/traducao.php?locale_id=' + t1.value + 
				         '&section_id=' + t2.value + '&translate_id=' + t3.value;
		}
	}
}

function submitForm() 
{
	if( st == 2 )
	{
		//make sure hidden and iframe values are in sync for all rtes before submitting form
		var elem = document.getElementById('xxx-editor2_iframe');
		var oDoc = elem.contentWindow ||
		           elem.contentDocument;
		if (oDoc.document)
		{
			oDoc = oDoc.document;
		}
		var fxxx = oDoc.getElementById('button');
		fxxx.click();
		
		setTimeout('editor2html()', 1000);
		return true;
	}
	
	micoxUpload('translate-form', 'iframe/translate_action.php', 'translate-action', 'carregando', 'ocorreu um erro');
	return true;
}

function editorhtml()
{     
	var elem = document.getElementById('xxx-editor_iframe');
	var oDoc = elem.contentWindow ||
	           elem.contentDocument;
	if (oDoc.document)
	{
		oDoc = oDoc.document;
	}
	var val = oDoc.getElementById('xxxtranslate_text');
	if(!val)
	{
		return false;
	}
	var elem = document.getElementById('xxxtranslate_text');
	elem.value = val.value;
}

function editor2html()
{  
	var elem = document.getElementById('xxx-editor2_iframe');
	var oDoc = elem.contentWindow ||
	           elem.contentDocument;
	if (oDoc.document)
	{
		oDoc = oDoc.document;
	}
	var val = oDoc.getElementById('value');
	if(!val)
	{
		return false;
	}
	var elem = document.getElementById('xxxtranslate_text');
	elem.value = val.value;
	
	micoxUpload('translate-form', 'iframe/translate_action.php', 'translate-action', 'carregando', 'ocorreu um erro');
}
