/**
 * DOTCUSTOMS.COM SOLUÇÕES WEB LTDA.
 * CNPJ: 08.678.712/0001-76
 * www.dotcustoms.com - Tel: +55 11 2122-4213
 * SOLUÇÕES CUSTOMIZADAS
 * 
 * CRIADO EM: Sun Dec 16 19:28:19 GST 2007
 * 
 * @author Fábio Matavelli <fabio@dotcustoms.com>
 * @copyright Todos os Direitos Reservados (c) 2007, dotCustoms.com
 */


function flash(arqflash,largura,altura) {
	document.write('<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0" width="' + largura + '" height="' + altura + '">');
	document.write('<param name="movie" value="' + arqflash + '" />');
	document.write('<param name="quality" value="high" />');
	document.write('<param name="menu" value="false" />');
	document.write('<param name="wmode" value="transparent" />');
	document.write('<embed src="' + arqflash + '" width="' + largura + '" height="' + altura + '" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" menu="false" wmode="transparent"></embed>');
document.write('</object>');
}

function launchJavascript(responseText) {
  // RegExp from prototype.sonio.net
  var ScriptFragment = '(?:<script.*?>)((\n|.)*?)(?:</script>)';
           
  var match    = new RegExp(ScriptFragment, 'img');
  var scripts  = responseText.match(match);

    if(scripts) {
        var js = '';
        for(var s = 0; s < scripts.length; s++) {
            var match = new RegExp(ScriptFragment, 'im');
            js += scripts[s].match(match)[1];
        }
        eval(js);
    }
}

function appendAndLaunchJs(div) {
    //if(!isRequest()) return;
   
    var inner = document.getElementById(div);

    var node = document.createElement('div'); // create a new div element
    node.innerHTML = xmlRequest.responseText; // append the text to node
    inner.innerHTML = '';                     // clear the destination node
    inner.appendChild(node);                  // append the node as a child and ...
                                             // ... at this point the JS is executed
}

function ajax() {
	this.Updater = carrega;

	function carrega(url,idDiv,mth,msg,param) {
		var content = document.getElementById(idDiv);
		
		if(msg != '') {
			content.innerHTML = msg;
		}

		var xmlHttp = getXmlHttp();
		xmlHttp.open(mth.toUpperCase(),url,true);
		if(mth.toLowerCase() == 'post') {
			xmlHttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");
			xmlHttp.setRequestHeader("Content-length",param.length);
			xmlHttp.setRequestHeader("Connection","close");
			xmlHttp.send(param);
		}
		
		xmlHttp.onreadystatechange = function() {
			var content = document.getElementById(idDiv);
			if(xmlHttp.readyState == 4) {
				var txt = xmlHttp.responseText;
				//txt = txt.replace(/\+/g,'');
				//txt = unescape(txt);
				if(content) {
					content.innerHTML = txt;
					if(navigator.appName != 'Netscape') {
						launchJavascript(txt);
					} else {
						//if(!isRequest()) return;
						
						var inner = document.getElementById(idDiv);
						var node = document.createElement('div');
						
						node.innerHTML = xmlHttp.responseText;
						inner.innerHTML = '';
						inner.appendChild(node);
					}
					
					/**
					 * Google Analytics
					 */
					if(mth.toLowerCase() != 'post') {
						//urchinTracker(url);
					}
				}
			}
		}
		if(mth.toLowerCase() != 'post') {
			xmlHttp.send(null);
		}
	}
}

function getXmlHttp() {
	var xmlHttp;
	try	{
		xmlHttp = new XMLHttpRequest();
	} catch (ee) {
		try	{
			xmlHttp = new ActiveXObject('Msxml2.XMLHTTP');
		} catch (e) {
			try	{
				xmlHttp = new ActiveXObject('Microsoft.XMLHTTP');
			} catch (E) {
				xmlHttp = false;
			}
		}
	}
	return xmlHttp;
}

function ajaxGET(url,div,msg) {
	var aj = new ajax();
    aj.Updater(url,div,'GET',msg,'');
}

function ajaxPOST(url,div,param,msg) {
	var aj = new ajax();
	aj.Updater(url,div,'POST',msg,param);
}

