/* fun&ccedil;&otilde;es de apoio */
function pegaValorNo(no) {
	try{
		if(no.firstChild){
			return no.firstChild.nodeValue;
		}else{
			return "";
		}
	}
	catch(e){
		return "";
	}
}

function createDOM (xml) {
	var dom;
    try {
		dom = new ActiveXObject("Microsoft.XMLDOM");
        dom.async = false;
        dom.loadXML(xml);
    } catch (error) {
        try {
            var parser = new DOMParser();
            dom = parser.parseFromString(xml, "text/xml");
            delete parser;
        } catch (error2) {
            if (debug) alert("XML parsing is not supported.");
        }
    }
	return dom;
}

var isIE = navigator.appName.indexOf("Microsoft") != -1;
var connId = Math.round(Math.random()*10000);

function flashRequest_DoFSCommand(command, args) {
	switch (command){
		case "success":
			if (isIE) document.body.removeChild(myDiv);
			myDiv.style.display = "none";
			flashRequestResult(unescape(args));
			break;
		
		case "result_error":
			alert("Error loading XML.");
			myDiv.style.display = "none";
			break;
	}
}

//if (isIE)
{
	document.write('<div style="position:absolute;">\n');
	document.write('<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0" id="flashRequest" width="1" height="1" align="middle">');
	document.write('<param name="allowScriptAccess" value="sameDomain" /> ');
	document.write('<param name="flashVars" value="connId='+connId+'" /> ');
	document.write('<param name="movie" value="/NOKIA_BRAZIL_69/Get_Support/Repair/repair_and_recycle/MAIN/Diagnostics_&_repair/swf/flashrequest_lc_receiver.swf" /><param name="quality" value="high" /><param name="bgcolor" value="#00ff00" /><embed src="/NOKIA_BRAZIL_69/Get_Support/Repair/repair_and_recycle/MAIN/Diagnostics_&_repair/swf/flashrequest_lc_receiver.swf" flashVars="connId='+connId+'" quality="high" bgcolor="#00ff00" width="1" height="1" swLiveConnect=true id="flashRequest" name="flashRequest" align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />');
	document.write('</object>');
	document.write('<script language=\"VBScript\"\>\n');
	document.write('On Error Resume Next\n');
	document.write('Sub flashRequest_FSCommand(ByVal command, ByVal args)\n');
	document.write('	Call flashRequest_DoFSCommand(command, args)\n');
	document.write('End Sub\n');
	document.write('</script\>\n');
	document.write('</div>');
}

function writeFlashObject (width,height,movie,bg,flashVars){
	if (flashVars==undefined) flashVars = "";
	
	var tmp = "";
	tmp+='<div style="position:absolute;">';
	tmp+='<object id="flashRequest" classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0" width="'+width+'" height="'+height+'" align="middle">';
	tmp+='<param name="allowScriptAccess" value="sameDomain" />';
	tmp+='<param name="flashVars" value="'+flashVars+'" />';
	tmp+='<param name="movie" value="'+movie+'" />';
	tmp+='<param name="quality" value="high" />';
	tmp+='<param name="bgcolor" value="#'+bg+'" />';
	tmp+='<param name="menu" value="false" />';
	tmp+='<embed id="flashRequest" name="flashRequest" src="'+movie+'" flashVars="'+flashVars+'" quality="high" bgcolor="#'+bg+'" width="'+width+'" height="'+height+'" align="middle" menu="false" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />';
	tmp+='</object>';
	tmp+='</div>';
	return tmp;
}

function createFlashRequest(url){
	url = url.substring(0,url.indexOf("?")+1)+escape(url.substring(url.indexOf("?")+1,url.length));
	myDiv = document.createElement("div");
	document.body.appendChild(myDiv);
	myDiv.innerHTML = writeFlashObject(1,1,"/NOKIA_BRAZIL_69/Get_Support/Repair/repair_and_recycle/MAIN/Diagnostics_&_repair/swf/flashrequest_lc_sender.swf","a5200a","url="+url+"&connId="+connId);
}

function flashRequestResult(txt) {	
	var xmlDoc = createDOM(txt);

	var products = xmlDoc.getElementsByTagName("products");
	var product = xmlDoc.getElementsByTagName("product");
	var precos = [];
	var isAvailable = [];
	
	if(products.length>0){
		if(product.length>0){
			if($(products[0]).attr('status')=='success'){
				for(var i=0; i<product.length; i++) {
					//mostrar pre&ccedil;o do produto determinado
					isAvailable[i]= $(product[i]).attr('isAvailable');
					precos[i] = $(product[i]).attr('price');	
				
				}
					
				$('.produtos li .preco').each(function(i){
					if(isAvailable[i]=='true'){
						$(this).html('R$ ' + precos[i]);
					}
					else{
						$(this).html('Indispon&iacute;vel');
					}
				});
				
				$('.loading').hide();
				$('.produtos').show();
			}	
		}
	}
}
